From nobody Sat May 18 11:46:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1607604729; cv=none; d=zohomail.com; s=zohoarc; b=gcrJQsuMfJgbmTV4W+4snuxMdyjezaL/5ECb+ptIjdTBiLnmEA35TxXmoic4dnRepcfRsgpxVjlqQNQYMAtPzfXgcga1qjhTHlpDODBl6C25mp3kuF6hZCljHBW4JHlE6P+UFqt6eH8cIXsm3CueDRpTUmAMjnO+6/A8GFEkYqU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607604729; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=LD4AGNpIw1YXczLSKVws4EcAyhWjSWHAbR6F2wj+Y9o=; b=m2jpvMHOkn7tbLwEW+3FZC4N3xy1fp7R+7GYGuiu3k2nX7X8VEb3UMsApVTMmwCDujgbrVMdvBPBpwZ2AbB1qoID7tjSYnvrYY7+DcLjwcbyTy2PqiR+kWiiaAaHcBszIrfrg9ZkKG8TCc3OQfuLM4pupm0NDr6sTbBV5cQxYL0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1607604729587652.5845147132663; Thu, 10 Dec 2020 04:52:09 -0800 (PST) Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-478-tsr1G11eNNesr4aJXRONVw-1; Thu, 10 Dec 2020 07:52:06 -0500 Received: by mail-wr1-f70.google.com with SMTP id p16so1908466wrx.4 for ; Thu, 10 Dec 2020 04:52:06 -0800 (PST) Return-Path: Return-Path: Received: from x1w.redhat.com (101.red-88-21-206.staticip.rima-tde.net. [88.21.206.101]) by smtp.gmail.com with ESMTPSA id z64sm8757573wme.10.2020.12.10.04.52.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 04:52:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607604728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LD4AGNpIw1YXczLSKVws4EcAyhWjSWHAbR6F2wj+Y9o=; b=AN8jS6xsyEcIg0XNGFPUdr7QB6hymYvvoaCvk34oAIqFQUPVKR2tKlEi4RZj9qF77GeIhD 7YazI5POLzvxr90JjDpG+XAZ9/CS4FcqKHvr5yD4yKYp/9roJSX2Xymhvj7K3Hc9H8X3hY a4wMtlC0Kgh/QFhspU+WmjlXpEx/fX4= X-MC-Unique: tsr1G11eNNesr4aJXRONVw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LD4AGNpIw1YXczLSKVws4EcAyhWjSWHAbR6F2wj+Y9o=; b=IdE2rNLglgM74XoLxaQavQahh46q30sTQZY23QHchXmcwbaYWA8BQLPTVRyf9iZyhH KrT9x3Qc8CqXC24VpoHGqR4xnpaFG9oBJHjH6Sgz/Cm0fEJpcfXbxC9tBJYarnMZCGdb DFLu319mlHXUl1Jpycghwt+4FHwLvsc6ysISgW17+mPiipeW/VEdrVqF50ZvQVO9Xrl7 gA0AAYnzglSsfFoyPnjAyagi4rqUgs3l+fNGnjqCBXlcQ/GiyZayGLevBIHCFQ41ytUE Pndw59DjZnI3tVJW0AqrWa0oJkdIPs0qouzEJEHlvuAFtlT1S5V5tcwFcSQbzaW5H4Mb kfCg== X-Gm-Message-State: AOAM531LtQDbDyHXn7qjR9M0VvsLknss1B1cUxjQdBav0HO4WlSRlG/l wC30HPgGsMoGBt6mRNAQZjXeD9zbWAaKUG22XubF6nDa7U+XLeW52ACLUpqeZMT/6vrrRqQGbv/ BpcXW52sVLwZeCg== X-Received: by 2002:a5d:67c3:: with SMTP id n3mr8068575wrw.297.1607604725430; Thu, 10 Dec 2020 04:52:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJykYtZce4rsa9A7EvvAqyd3v6leMoaCpFVnL9ntxaGykoN4FgjOEfOPweR4dfFEWvMWDXZwhQ== X-Received: by 2002:a5d:67c3:: with SMTP id n3mr8068562wrw.297.1607604725278; Thu, 10 Dec 2020 04:52:05 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Max Reitz , Stefan Hajnoczi , Maxim Levitsky , qemu-block@nongnu.org, Fam Zheng , Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Xueqiang Wei Subject: [PATCH] block/nvme: Implement fake truncate() coroutine Date: Thu, 10 Dec 2020 13:52:02 +0100 Message-Id: <20201210125202.858656-1-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) NVMe drive can not be shrunk. Since commit c80d8b06cfa we can use the @exact parameter (set to false) to return success if the block device is larger than the requested offset (even if we can not be shrunk). Use this parameter to implement the NVMe truncate() coroutine, similarly how it is done for the iscsi and file-posix drivers (see commit 82325ae5f2f "Evaluate @exact in protocol drivers"). Reported-by: Xueqiang Wei Suggested-by: Max Reitz Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/block/nvme.c b/block/nvme.c index a06a188d530..5a6fbacf4a5 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -1389,6 +1389,29 @@ out: =20 } =20 +static int coroutine_fn nvme_co_truncate(BlockDriverState *bs, int64_t off= set, + bool exact, PreallocMode prealloc, + BdrvRequestFlags flags, Error **e= rrp) +{ + int64_t cur_length; + + if (prealloc !=3D PREALLOC_MODE_OFF) { + error_setg(errp, "Unsupported preallocation mode '%s'", + PreallocMode_str(prealloc)); + return -ENOTSUP; + } + + cur_length =3D nvme_getlength(bs); + if (offset !=3D cur_length && exact) { + error_setg(errp, "Cannot resize NVMe devices"); + return -ENOTSUP; + } else if (offset > cur_length) { + error_setg(errp, "Cannot grow NVMe devices"); + return -EINVAL; + } + + return 0; +} =20 static int nvme_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, Error **errp) @@ -1523,6 +1546,7 @@ static BlockDriver bdrv_nvme =3D { .bdrv_close =3D nvme_close, .bdrv_getlength =3D nvme_getlength, .bdrv_probe_blocksizes =3D nvme_probe_blocksizes, + .bdrv_co_truncate =3D nvme_co_truncate, =20 .bdrv_co_preadv =3D nvme_co_preadv, .bdrv_co_pwritev =3D nvme_co_pwritev, --=20 2.26.2