From patchwork Mon Aug 2 20:12:35 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brunner X-Patchwork-Id: 116588 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o72KCmeo001428 for ; Mon, 2 Aug 2010 20:12:48 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755205Ab0HBUMj (ORCPT ); Mon, 2 Aug 2010 16:12:39 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:62366 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754492Ab0HBUMj (ORCPT ); Mon, 2 Aug 2010 16:12:39 -0400 Received: by bwz1 with SMTP id 1so1621689bwz.19 for ; Mon, 02 Aug 2010 13:12:37 -0700 (PDT) Received: by 10.204.53.211 with SMTP id n19mr4524608bkg.66.1280779957828; Mon, 02 Aug 2010 13:12:37 -0700 (PDT) Received: from chb-desktop (e181035128.adsl.alicedsl.de [85.181.35.128]) by mx.google.com with ESMTPS id f10sm4390186bkl.5.2010.08.02.13.12.37 (version=SSLv3 cipher=RC4-MD5); Mon, 02 Aug 2010 13:12:37 -0700 (PDT) Date: Mon, 2 Aug 2010 22:12:35 +0200 From: Christian Brunner To: ceph-devel@vger.kernel.org Subject: [PATCH] rbd: use async write for copy and import Message-ID: <20100802201235.GD4923@chb-desktop> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 02 Aug 2010 20:12:48 +0000 (UTC) diff --git a/src/rbd.cc b/src/rbd.cc index 07849ed..7c71b7d 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -37,6 +37,8 @@ struct pools { typedef struct pools pools_t; +int64_t aiocnt = 0; + static Rados rados; static string dir_oid = RBD_DIRECTORY; static string dir_info_oid = RBD_INFO; @@ -722,6 +724,12 @@ done_img: update_snap_name(*new_img, snap); } +static void aio_write_cb(Rados::AioCompletion comp, void *c) +{ + comp.release(); + aiocnt--; +} + static int do_import(pool_t pool, const char *imgname, int order, const char *path) { int fd = open(path, O_RDONLY); @@ -730,6 +738,7 @@ static int do_import(pool_t pool, const char *imgname, int order, const char *pa uint64_t block_size; struct stat stat_buf; string md_oid; + Rados::AioCompletion *comp; if (fd < 0) { r = -errno; @@ -784,7 +793,9 @@ static int do_import(pool_t pool, const char *imgname, int order, const char *pa bufferlist bl; bl.append(p); string oid = get_block_oid(&header, i); - r = rados.write(pool, oid, 0, bl, len); + comp = rados.aio_create_completion(NULL, NULL, (callback_t) aio_write_cb); + r = rados.aio_write(pool, oid, 0, bl, len, comp); + aiocnt++; if (r < 0) { cerr << "error writing to image block" << std::endl; return r; @@ -796,6 +807,11 @@ static int do_import(pool_t pool, const char *imgname, int order, const char *pa seg_pos += seg_size; } + while(aiocnt > 0) { + cerr << "waiting for " << aiocnt << " async writes" << std::endl; + usleep(100000); + } + return 0; } @@ -805,6 +821,7 @@ static int do_copy(pools_t& pp, const char *imgname, const char *destname) int64_t ret; int r; string md_oid, dest_md_oid; + Rados::AioCompletion *comp; md_oid = imgname; md_oid += RBD_SUFFIX; @@ -843,7 +860,9 @@ static int do_copy(pools_t& pp, const char *imgname, const char *destname) if (bl.length()) { string dest_oid = get_block_oid(&dest_header, i); - r = rados.write(pp.dest, dest_oid, 0, bl, bl.length()); + comp = rados.aio_create_completion(NULL, NULL, (callback_t) aio_write_cb); + r = rados.aio_write(pp.dest, dest_oid, 0, bl, bl.length(), comp); + aiocnt++; if (r < 0) { cerr << "failed to write block " << dest_oid << std::endl; return r; @@ -851,6 +870,11 @@ static int do_copy(pools_t& pp, const char *imgname, const char *destname) } } + while(aiocnt > 0) { + cerr << "waiting for " << aiocnt << " async writes" << std::endl; + usleep(100000); + } + return 0; }