From nobody Sat May 4 14:16:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487960940239363.0998004240314; Fri, 24 Feb 2017 10:29:00 -0800 (PST) Received: from localhost ([::1]:39195 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKbz-0000VU-0N for importer@patchew.org; Fri, 24 Feb 2017 13:28:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37883) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chJxW-0006IC-JH for qemu-devel@nongnu.org; Fri, 24 Feb 2017 12:47:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chJxV-0004un-J3 for qemu-devel@nongnu.org; Fri, 24 Feb 2017 12:47:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60526) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chJxS-0004sQ-NO; Fri, 24 Feb 2017 12:47:06 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 550C23D940; Fri, 24 Feb 2017 17:47:04 +0000 (UTC) Received: from localhost (ovpn-116-95.phx2.redhat.com [10.3.116.95]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OHl39N027369 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 24 Feb 2017 12:47:03 -0500 From: Jeff Cody To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 12:46:58 -0500 Message-Id: <20170224174700.30816-2-jcody@redhat.com> In-Reply-To: <20170224174700.30816-1-jcody@redhat.com> References: <20170224174700.30816-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 24 Feb 2017 17:47:04 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/3] block/nfs: convert to preadv / pwritev X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Lieven Signed-off-by: Peter Lieven Reviewed-by: Jeff Cody Message-id: 1487349541-10201-2-git-send-email-pl@kamp.de Signed-off-by: Jeff Cody --- block/nfs.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/block/nfs.c b/block/nfs.c index 0cf115e..c11c4c9 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -263,9 +263,9 @@ nfs_co_generic_cb(int ret, struct nfs_context *nfs, voi= d *data, nfs_co_generic_bh_cb, task); } =20 -static int coroutine_fn nfs_co_readv(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, - QEMUIOVector *iov) +static int coroutine_fn nfs_co_preadv(BlockDriverState *bs, uint64_t offse= t, + uint64_t bytes, QEMUIOVector *iov, + int flags) { NFSClient *client =3D bs->opaque; NFSRPC task; @@ -274,9 +274,7 @@ static int coroutine_fn nfs_co_readv(BlockDriverState *= bs, task.iov =3D iov; =20 if (nfs_pread_async(client->context, client->fh, - sector_num * BDRV_SECTOR_SIZE, - nb_sectors * BDRV_SECTOR_SIZE, - nfs_co_generic_cb, &task) !=3D 0) { + offset, bytes, nfs_co_generic_cb, &task) !=3D 0) { return -ENOMEM; } =20 @@ -297,9 +295,9 @@ static int coroutine_fn nfs_co_readv(BlockDriverState *= bs, return 0; } =20 -static int coroutine_fn nfs_co_writev(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, - QEMUIOVector *iov) +static int coroutine_fn nfs_co_pwritev(BlockDriverState *bs, uint64_t offs= et, + uint64_t bytes, QEMUIOVector *iov, + int flags) { NFSClient *client =3D bs->opaque; NFSRPC task; @@ -307,17 +305,16 @@ static int coroutine_fn nfs_co_writev(BlockDriverStat= e *bs, =20 nfs_co_init_task(bs, &task); =20 - buf =3D g_try_malloc(nb_sectors * BDRV_SECTOR_SIZE); - if (nb_sectors && buf =3D=3D NULL) { + buf =3D g_try_malloc(bytes); + if (bytes && buf =3D=3D NULL) { return -ENOMEM; } =20 - qemu_iovec_to_buf(iov, 0, buf, nb_sectors * BDRV_SECTOR_SIZE); + qemu_iovec_to_buf(iov, 0, buf, bytes); =20 if (nfs_pwrite_async(client->context, client->fh, - sector_num * BDRV_SECTOR_SIZE, - nb_sectors * BDRV_SECTOR_SIZE, - buf, nfs_co_generic_cb, &task) !=3D 0) { + offset, bytes, buf, + nfs_co_generic_cb, &task) !=3D 0) { g_free(buf); return -ENOMEM; } @@ -329,7 +326,7 @@ static int coroutine_fn nfs_co_writev(BlockDriverState = *bs, =20 g_free(buf); =20 - if (task.ret !=3D nb_sectors * BDRV_SECTOR_SIZE) { + if (task.ret !=3D bytes) { return task.ret < 0 ? task.ret : -EIO; } =20 @@ -861,8 +858,8 @@ static BlockDriver bdrv_nfs =3D { .bdrv_create =3D nfs_file_create, .bdrv_reopen_prepare =3D nfs_reopen_prepare, =20 - .bdrv_co_readv =3D nfs_co_readv, - .bdrv_co_writev =3D nfs_co_writev, + .bdrv_co_preadv =3D nfs_co_preadv, + .bdrv_co_pwritev =3D nfs_co_pwritev, .bdrv_co_flush_to_disk =3D nfs_co_flush, =20 .bdrv_detach_aio_context =3D nfs_detach_aio_context, --=20 2.9.3 From nobody Sat May 4 14:16:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487960691613741.8042065935323; Fri, 24 Feb 2017 10:24:51 -0800 (PST) Received: from localhost ([::1]:39168 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKXy-0004SC-4n for importer@patchew.org; Fri, 24 Feb 2017 13:24:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37863) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chJxV-0006Hp-Sh for qemu-devel@nongnu.org; Fri, 24 Feb 2017 12:47:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chJxU-0004uP-Ty for qemu-devel@nongnu.org; Fri, 24 Feb 2017 12:47:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38624) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chJxS-0004sY-NJ; Fri, 24 Feb 2017 12:47:06 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7A6393A7698; Fri, 24 Feb 2017 17:47:05 +0000 (UTC) Received: from localhost (ovpn-116-95.phx2.redhat.com [10.3.116.95]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OHl4IR001040 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 24 Feb 2017 12:47:05 -0500 From: Jeff Cody To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 12:46:59 -0500 Message-Id: <20170224174700.30816-3-jcody@redhat.com> In-Reply-To: <20170224174700.30816-1-jcody@redhat.com> References: <20170224174700.30816-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 24 Feb 2017 17:47:05 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/3] block/nfs: try to avoid the bounce buffer in pwritev X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Lieven if the passed qiov contains exactly one iov we can pass the buffer directly. Signed-off-by: Peter Lieven Reviewed-by: Jeff Cody Message-id: 1487349541-10201-3-git-send-email-pl@kamp.de Signed-off-by: Jeff Cody --- block/nfs.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/block/nfs.c b/block/nfs.c index c11c4c9..ffb54be 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -302,30 +302,39 @@ static int coroutine_fn nfs_co_pwritev(BlockDriverSta= te *bs, uint64_t offset, NFSClient *client =3D bs->opaque; NFSRPC task; char *buf =3D NULL; + bool my_buffer =3D false; =20 nfs_co_init_task(bs, &task); =20 - buf =3D g_try_malloc(bytes); - if (bytes && buf =3D=3D NULL) { - return -ENOMEM; + if (iov->niov !=3D 1) { + buf =3D g_try_malloc(bytes); + if (bytes && buf =3D=3D NULL) { + return -ENOMEM; + } + qemu_iovec_to_buf(iov, 0, buf, bytes); + my_buffer =3D true; + } else { + buf =3D iov->iov[0].iov_base; } =20 - qemu_iovec_to_buf(iov, 0, buf, bytes); - if (nfs_pwrite_async(client->context, client->fh, offset, bytes, buf, nfs_co_generic_cb, &task) !=3D 0) { + if (my_buffer) { + g_free(buf); + } + return -ENOMEM; + } + + nfs_set_events(client); + while (!task.complete) { + qemu_coroutine_yield(); + } + + if (my_buffer) { g_free(buf); - return -ENOMEM; } =20 - nfs_set_events(client); - while (!task.complete) { - qemu_coroutine_yield(); - } - - g_free(buf); - if (task.ret !=3D bytes) { return task.ret < 0 ? task.ret : -EIO; } --=20 2.9.3 From nobody Sat May 4 14:16:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487960292888708.1427305160072; Fri, 24 Feb 2017 10:18:12 -0800 (PST) Received: from localhost ([::1]:39125 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chKRW-0006HZ-EB for importer@patchew.org; Fri, 24 Feb 2017 13:18:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chJxW-0006IR-Ra for qemu-devel@nongnu.org; Fri, 24 Feb 2017 12:47:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chJxV-0004ux-RL for qemu-devel@nongnu.org; Fri, 24 Feb 2017 12:47:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34184) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chJxS-0004si-Qy; Fri, 24 Feb 2017 12:47:07 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D9C0CC05AA61; Fri, 24 Feb 2017 17:47:06 +0000 (UTC) Received: from localhost (ovpn-116-95.phx2.redhat.com [10.3.116.95]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1OHl56I006949 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 24 Feb 2017 12:47:06 -0500 From: Jeff Cody To: qemu-block@nongnu.org Date: Fri, 24 Feb 2017 12:47:00 -0500 Message-Id: <20170224174700.30816-4-jcody@redhat.com> In-Reply-To: <20170224174700.30816-1-jcody@redhat.com> References: <20170224174700.30816-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 24 Feb 2017 17:47:06 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/3] RBD: Add support readv,writev for rbd X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: tianqing Rbd can do readv and writev directly, so wo do not need to transform iov to buf or vice versa any more. Signed-off-by: tianqing Reviewed-by: Jeff Cody Signed-off-by: Jeff Cody --- block/rbd.c | 80 ++++++++++++++++++++++++++++++++++++++++++---------------= ---- 1 file changed, 56 insertions(+), 24 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index a57b3e3..22e8e69 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -62,6 +62,13 @@ #define RBD_MAX_SNAP_NAME_SIZE 128 #define RBD_MAX_SNAPS 100 =20 +/* The LIBRBD_SUPPORTS_IOVEC is defined in librbd.h */ +#ifdef LIBRBD_SUPPORTS_IOVEC +#define LIBRBD_USE_IOVEC 1 +#else +#define LIBRBD_USE_IOVEC 0 +#endif + typedef enum { RBD_AIO_READ, RBD_AIO_WRITE, @@ -310,6 +317,17 @@ static int qemu_rbd_set_conf(rados_t cluster, const ch= ar *conf, return ret; } =20 +static void qemu_rbd_memset(RADOSCB *rcb, int64_t offs) +{ + if (LIBRBD_USE_IOVEC) { + RBDAIOCB *acb =3D rcb->acb; + iov_memset(acb->qiov->iov, acb->qiov->niov, offs, 0, + acb->qiov->size - offs); + } else { + memset(rcb->buf + offs, 0, rcb->size - offs); + } +} + static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **e= rrp) { Error *local_err =3D NULL; @@ -426,11 +444,11 @@ static void qemu_rbd_complete_aio(RADOSCB *rcb) } } else { if (r < 0) { - memset(rcb->buf, 0, rcb->size); + qemu_rbd_memset(rcb, 0); acb->ret =3D r; acb->error =3D 1; } else if (r < rcb->size) { - memset(rcb->buf + r, 0, rcb->size - r); + qemu_rbd_memset(rcb, r); if (!acb->error) { acb->ret =3D rcb->size; } @@ -441,10 +459,13 @@ static void qemu_rbd_complete_aio(RADOSCB *rcb) =20 g_free(rcb); =20 - if (acb->cmd =3D=3D RBD_AIO_READ) { - qemu_iovec_from_buf(acb->qiov, 0, acb->bounce, acb->qiov->size); + if (!LIBRBD_USE_IOVEC) { + if (acb->cmd =3D=3D RBD_AIO_READ) { + qemu_iovec_from_buf(acb->qiov, 0, acb->bounce, acb->qiov->size= ); + } + qemu_vfree(acb->bounce); } - qemu_vfree(acb->bounce); + acb->common.cb(acb->common.opaque, (acb->ret > 0 ? 0 : acb->ret)); =20 qemu_aio_unref(acb); @@ -655,7 +676,6 @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs, RBDAIOCB *acb; RADOSCB *rcb =3D NULL; rbd_completion_t c; - char *buf; int r; =20 BDRVRBDState *s =3D bs->opaque; @@ -664,27 +684,29 @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs, acb->cmd =3D cmd; acb->qiov =3D qiov; assert(!qiov || qiov->size =3D=3D size); - if (cmd =3D=3D RBD_AIO_DISCARD || cmd =3D=3D RBD_AIO_FLUSH) { - acb->bounce =3D NULL; - } else { - acb->bounce =3D qemu_try_blockalign(bs, qiov->size); - if (acb->bounce =3D=3D NULL) { - goto failed; + + rcb =3D g_new(RADOSCB, 1); + + if (!LIBRBD_USE_IOVEC) { + if (cmd =3D=3D RBD_AIO_DISCARD || cmd =3D=3D RBD_AIO_FLUSH) { + acb->bounce =3D NULL; + } else { + acb->bounce =3D qemu_try_blockalign(bs, qiov->size); + if (acb->bounce =3D=3D NULL) { + goto failed; + } } + if (cmd =3D=3D RBD_AIO_WRITE) { + qemu_iovec_to_buf(acb->qiov, 0, acb->bounce, qiov->size); + } + rcb->buf =3D acb->bounce; } + acb->ret =3D 0; acb->error =3D 0; acb->s =3D s; =20 - if (cmd =3D=3D RBD_AIO_WRITE) { - qemu_iovec_to_buf(acb->qiov, 0, acb->bounce, qiov->size); - } - - buf =3D acb->bounce; - - rcb =3D g_new(RADOSCB, 1); rcb->acb =3D acb; - rcb->buf =3D buf; rcb->s =3D acb->s; rcb->size =3D size; r =3D rbd_aio_create_completion(rcb, (rbd_callback_t) rbd_finish_aiocb= , &c); @@ -694,10 +716,18 @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs, =20 switch (cmd) { case RBD_AIO_WRITE: - r =3D rbd_aio_write(s->image, off, size, buf, c); +#ifdef LIBRBD_SUPPORTS_IOVEC + r =3D rbd_aio_writev(s->image, qiov->iov, qiov->niov, off, c); +#else + r =3D rbd_aio_write(s->image, off, size, rcb->buf, c); +#endif break; case RBD_AIO_READ: - r =3D rbd_aio_read(s->image, off, size, buf, c); +#ifdef LIBRBD_SUPPORTS_IOVEC + r =3D rbd_aio_readv(s->image, qiov->iov, qiov->niov, off, c); +#else + r =3D rbd_aio_read(s->image, off, size, rcb->buf, c); +#endif break; case RBD_AIO_DISCARD: r =3D rbd_aio_discard_wrapper(s->image, off, size, c); @@ -712,14 +742,16 @@ static BlockAIOCB *rbd_start_aio(BlockDriverState *bs, if (r < 0) { goto failed_completion; } - return &acb->common; =20 failed_completion: rbd_aio_release(c); failed: g_free(rcb); - qemu_vfree(acb->bounce); + if (!LIBRBD_USE_IOVEC) { + qemu_vfree(acb->bounce); + } + qemu_aio_unref(acb); return NULL; } --=20 2.9.3