From nobody Sat May 18 06:04:27 2024 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1667046072; cv=none; d=zohomail.com; s=zohoarc; b=SO5m+WuS07EzaSQ86o/Z9gkgbHck3OOBs/5RkRmNdsQBDdut0WBV89kV89UrS+nrYKx4Zl74s9iX2sGEGWLohxVWYYRB0eiQp+8v1etlBGphGiEKUfsyPJ+1TNsC6wHqqjj0gH9NxqjOAyLCs0gELfmIwPgPvaSA3Q3WXPB+IU0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667046072; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=goTTYaFYidCzNhW//N4KcgjA3RQSCDFUzuMCDLpfuac=; b=heA+dnV1kOcuk55oXxiS4TuJUlw2s6+/VUeZy9fWv3wen20/UfIiTtq+QsANrkPanfYNMlglgSP4DUXkMbckxcbSXyZ6nnC8FihxH00xNJRJCMtJJmoMDB7/z261/oR4T0rjWGdTLJh8NnGRZFzQ7ziFZDNPMABif6kfXje9L+Y= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1667046072563865.9878346553651; Sat, 29 Oct 2022 05:21:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ookpO-0006qD-5w; Sat, 29 Oct 2022 08:20:42 -0400 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 1ookpK-0006hh-NX for qemu-devel@nongnu.org; Sat, 29 Oct 2022 08:20:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ookpI-0008B8-QT for qemu-devel@nongnu.org; Sat, 29 Oct 2022 08:20:38 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-176-1jPC-ZqIOo6Gb4QzRCGiAQ-1; Sat, 29 Oct 2022 08:20:34 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E273D1C05159; Sat, 29 Oct 2022 12:20:33 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.39.193.200]) by smtp.corp.redhat.com (Postfix) with ESMTP id A9E66140EBF3; Sat, 29 Oct 2022 12:20:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667046035; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=goTTYaFYidCzNhW//N4KcgjA3RQSCDFUzuMCDLpfuac=; b=PO8CS6D1k+42N4Z+x8uBUe83AEnNiAvEYEj6M25E6ImqJrS6uxtYL/Y8SEoKPsSyOpy2In XPkA9StKMhq2ydkOgXVqsFTPNiEtkdyi3Tns/wXvntaQgzj5xMmWGci8Ox5O8psYBJPsOi PvkvKBPmyd6ntUpkeZ7Um0TlbyQubNE= X-MC-Unique: 1jPC-ZqIOo6Gb4QzRCGiAQ-1 From: Alberto Faria To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , qemu-block@nongnu.org, Hanna Reitz , Alberto Faria Subject: [PATCH] block/blkio: Tolerate device size changes Date: Sat, 29 Oct 2022 13:20:31 +0100 Message-Id: <20221029122031.975273-1-afaria@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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=170.10.133.124; envelope-from=afaria@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.516, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1667046073546100003 Content-Type: text/plain; charset="utf-8" Some libblkio drivers may be able to work with regular files (e.g., io_uring) or otherwise resizable devices. Conservatively set BlockDriver::has_variable_length to true to ensure bdrv_nb_sectors() always gives up-to-date results. Also implement BlockDriver::bdrv_co_truncate for the case where no preallocation is needed and the device already has a size compatible with what was requested. Signed-off-by: Alberto Faria --- This is based on Stefan's block tree: https://gitlab.com/stefanha/qemu/-/commits/block block/blkio.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/block/blkio.c b/block/blkio.c index 82f26eedd2..190454cdbe 100644 --- a/block/blkio.c +++ b/block/blkio.c @@ -845,6 +845,31 @@ static int64_t blkio_getlength(BlockDriverState *bs) return capacity; } =20 +static int coroutine_fn blkio_truncate(BlockDriverState *bs, int64_t offse= t, + bool exact, PreallocMode prealloc, + BdrvRequestFlags flags, Error **err= p) +{ + int64_t current_length; + + if (prealloc !=3D PREALLOC_MODE_OFF) { + error_setg(errp, "Unsupported preallocation mode '%s'", + PreallocMode_str(prealloc)); + return -ENOTSUP; + } + + current_length =3D blkio_getlength(bs); + + if (offset > current_length) { + error_setg(errp, "Cannot grow device"); + return -EINVAL; + } else if (exact && offset !=3D current_length) { + error_setg(errp, "Cannot resize device"); + return -ENOTSUP; + } + + return 0; +} + static int blkio_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { return 0; @@ -960,10 +985,12 @@ static void blkio_refresh_limits(BlockDriverState *bs= , Error **errp) { \ .format_name =3D name, \ .protocol_name =3D name, \ + .has_variable_length =3D true, \ .instance_size =3D sizeof(BDRVBlkioState), \ .bdrv_file_open =3D blkio_file_open, \ .bdrv_close =3D blkio_close, \ .bdrv_getlength =3D blkio_getlength, \ + .bdrv_co_truncate =3D blkio_truncate, \ .bdrv_get_info =3D blkio_get_info, \ .bdrv_attach_aio_context =3D blkio_attach_aio_context, \ .bdrv_detach_aio_context =3D blkio_detach_aio_context, \ --=20 2.38.1