From nobody Mon Apr 13 12:10:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1772807398; cv=none; d=zohomail.com; s=zohoarc; b=FkXR1gsbt9PirAmW/JMF5WORimypFFPd677lxU7mCbTI+Agv9diHb85xuNsNiubKFNiMvbmzrnROiiO3mAY1eiCo3aB+jOlCmG0t6Q9dfJF6zAfFj/mj046Y7j3wa2O6udi4KEfMzeGpR9pyBriSIis3LTeaaPNy4UyUs/C2LSo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772807398; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YVduhRvlfmWCULF5ggKnw9zwhlMXrPGN+aN1A3qn2Dk=; b=DyThoaRy/yBpPkoBCln5bbF172BFYPFmKzh9pm33SntY/z+tGL97ck2t5KnxD2ZPaPW+MQGquVIBdLXeayJ+sgDdafX/mx8+Zohnx4dlPLccn3xSfKXN8mRT3vSr/tF9dAV8AT7RdzQFKX4jHkyiO2yQuOnBiFsJ5ZZW9NLStvg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772807398220704.1039945414478; Fri, 6 Mar 2026 06:29:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyWAy-00079H-IG; Fri, 06 Mar 2026 09:29:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyWAp-00078J-5a; Fri, 06 Mar 2026 09:29:03 -0500 Received: from mailcow.dlhnet.de ([2a01:b1c0::44ca:22ff:fe9b:798c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyWAi-0004pc-9f; Fri, 06 Mar 2026 09:29:02 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id AFB4946AEA2; Fri, 6 Mar 2026 15:28:51 +0100 (CET) Received: by pkgbuilder.localdomain (Postfix, from userid 0) id 90747402DC; Fri, 06 Mar 2026 14:28:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dlhnet.de; s=dkim; t=1772807332; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding; bh=YVduhRvlfmWCULF5ggKnw9zwhlMXrPGN+aN1A3qn2Dk=; b=aCcq9EouDTbhnVKRTKNtDSW8d3fCeIWgwETmFNgsXKSMM7XZPvy2eBlfUBZPqnlu547a7g 4zGwXcKb38wW5+g+iOzrfKsPJlXVq3qF3244sZDl0tNUxIlF2dMp90UDy3HCRIjqhDctjI WyTGwgavKr69ucus+khlYuU6MTYi2+6D0+1v0f5rP5lG8xwemj2aGfhu7PnH9sO4GT70UQ GDO7Rx1jJxZjC2l0E2eO0CpIGzuVH619bNG+ESAdAX7ixpJ1mlEVAaN9O9wzBTJ/Kf6rig EFX5G0BHJ9fsl66Ptm5o4CgW+1pckrlXWAsP3ad+/hcNbdmboNzrzCocpAq7ZQ== From: Peter Lieven To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, pbonzini@redhat.com, hreitz@redhat.com, marcandre.lureau@redhat.com, berrange@redhat.com, philmd@linaro.org, armbru@redhat.com, jsnow@redhat.com, thuth@redhat.com, Peter Lieven , Ronnie Sahlberg Subject: [PATCH] block/nfs: add support for libnfs v6 Date: Fri, 6 Mar 2026 14:28:40 +0000 Message-ID: <20260306142840.72923-1-pl@dlhnet.de> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a01:b1c0::44ca:22ff:fe9b:798c; envelope-from=pl@dlhnet.de; helo=mailcow.dlhnet.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @dlhnet.de) X-ZM-MESSAGEID: 1772807401377158500 Content-Type: text/plain; charset="utf-8" libnfs v6 added a new api structure for read and write requests. This effectively also adds zero copy read support for cases where the qiov coming from the block layer has only one vector. The .brdv_refresh_limits implementation is needed because libnfs v6 silently dropped support for splitting large read/write request into chunks. Signed-off-by: Ronnie Sahlberg Signed-off-by: Peter Lieven --- block/nfs.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- meson.build | 2 +- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/block/nfs.c b/block/nfs.c index b78f4f86e8..53e267fa75 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -69,7 +69,9 @@ typedef struct NFSClient { typedef struct NFSRPC { BlockDriverState *bs; int ret; +#ifndef LIBNFS_API_V2 QEMUIOVector *iov; +#endif struct stat *st; Coroutine *co; NFSClient *client; @@ -237,6 +239,7 @@ nfs_co_generic_cb(int ret, struct nfs_context *nfs, voi= d *data, NFSRPC *task =3D private_data; task->ret =3D ret; assert(!task->st); +#ifndef LIBNFS_API_V2 if (task->ret > 0 && task->iov) { if (task->ret <=3D task->iov->size) { qemu_iovec_from_buf(task->iov, 0, data, task->ret); @@ -244,6 +247,7 @@ nfs_co_generic_cb(int ret, struct nfs_context *nfs, voi= d *data, task->ret =3D -EIO; } } +#endif if (task->ret < 0) { error_report("NFS Error: %s", nfs_get_error(nfs)); } @@ -266,13 +270,36 @@ static int coroutine_fn nfs_co_preadv(BlockDriverStat= e *bs, int64_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); - task.iov =3D iov; + +#ifdef LIBNFS_API_V2 + if (iov->niov !=3D 1) { + buf =3D g_try_malloc(bytes); + if (bytes && buf =3D=3D NULL) { + return -ENOMEM; + } + my_buffer =3D true; + } else { + buf =3D iov->iov[0].iov_base; + } +#endif =20 WITH_QEMU_LOCK_GUARD(&client->mutex) { +#ifdef LIBNFS_API_V2 + if (nfs_pread_async(client->context, client->fh, + buf, bytes, offset, + nfs_co_generic_cb, &task) !=3D 0) { +#else + task.iov =3D iov; if (nfs_pread_async(client->context, client->fh, offset, bytes, nfs_co_generic_cb, &task) !=3D = 0) { +#endif + if (my_buffer) { + g_free(buf); + } return -ENOMEM; } =20 @@ -280,6 +307,13 @@ static int coroutine_fn nfs_co_preadv(BlockDriverState= *bs, int64_t offset, } qemu_coroutine_yield(); =20 + if (my_buffer) { + if (task.ret > 0) { + qemu_iovec_from_buf(iov, 0, buf, task.ret); + } + g_free(buf); + } + if (task.ret < 0) { return task.ret; } @@ -315,9 +349,15 @@ static int coroutine_fn nfs_co_pwritev(BlockDriverStat= e *bs, int64_t offset, } =20 WITH_QEMU_LOCK_GUARD(&client->mutex) { +#ifdef LIBNFS_API_V2 + if (nfs_pwrite_async(client->context, client->fh, + buf, bytes, offset, + nfs_co_generic_cb, &task) !=3D 0) { +#else if (nfs_pwrite_async(client->context, client->fh, offset, bytes, buf, nfs_co_generic_cb, &task) !=3D 0) { +#endif if (my_buffer) { g_free(buf); } @@ -856,6 +896,13 @@ static void coroutine_fn nfs_co_invalidate_cache(Block= DriverState *bs, } #endif =20 +static void nfs_refresh_limits(BlockDriverState *bs, Error **errp) +{ + NFSClient *client =3D bs->opaque; + bs->bl.max_transfer =3D MIN((uint32_t)nfs_get_readmax(client->context), + (uint32_t)nfs_get_writemax(client->context)); +} + static const char *nfs_strong_runtime_opts[] =3D { "path", "user", @@ -893,6 +940,7 @@ static BlockDriver bdrv_nfs =3D { .bdrv_detach_aio_context =3D nfs_detach_aio_context, .bdrv_attach_aio_context =3D nfs_attach_aio_context, .bdrv_refresh_filename =3D nfs_refresh_filename, + .bdrv_refresh_limits =3D nfs_refresh_limits, .bdrv_dirname =3D nfs_dirname, =20 .strong_runtime_opts =3D nfs_strong_runtime_opts, diff --git a/meson.build b/meson.build index df841e12e2..3bb78c0788 100644 --- a/meson.build +++ b/meson.build @@ -1156,7 +1156,7 @@ endif =20 libnfs =3D not_found if not get_option('libnfs').auto() or have_block - libnfs =3D dependency('libnfs', version: ['>=3D1.9.3', '<6.0.0'], + libnfs =3D dependency('libnfs', version: '>=3D1.9.3', required: get_option('libnfs'), method: 'pkg-config') endif --=20 2.47.3