From nobody Tue Feb 10 08:27:17 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.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 1528386272041385.27995595531195; Thu, 7 Jun 2018 08:44:32 -0700 (PDT) Received: from localhost ([::1]:58708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQx5O-0004Nm-6y for importer@patchew.org; Thu, 07 Jun 2018 11:44:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35376) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQx02-0007wZ-6L for qemu-devel@nongnu.org; Thu, 07 Jun 2018 11:38:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQx00-00045w-8W for qemu-devel@nongnu.org; Thu, 07 Jun 2018 11:38:54 -0400 Received: from mx2.mpynet.fi ([82.197.21.85]:12639) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fQwzw-00041L-DM; Thu, 07 Jun 2018 11:38:48 -0400 From: Ari Sundholm To: Date: Thu, 7 Jun 2018 18:38:07 +0300 Message-ID: <1528385894-19434-4-git-send-email-ari@tuxera.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528385894-19434-1-git-send-email-ari@tuxera.com> References: <1528385894-19434-1-git-send-email-ari@tuxera.com> MIME-Version: 1.0 X-ClientProxiedBy: tuxera-exch.ad.tuxera.com (10.20.48.11) To tuxera-exch.ad.tuxera.com (10.20.48.11) 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; Received-SPF: none X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 82.197.21.85 Subject: [Qemu-devel] [PATCH v3 03/10] block: Add a mechanism for passing a block driver a block configuration 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: Kevin Wolf , Fam Zheng , "open list:Block I/O path" , Max Reitz , Stefan Hajnoczi , John Snow , Ari Sundholm 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 Content-Type: text/plain; charset="utf-8" A block driver may need to know about the block configuration, most critically the sector sizes, of a block backend for alignment purposes or for some other reason. It doesn't seem like qemu has an existing mechanism for a block backend to convey the required information to the relevant block driver when it is being realized. The need for this mechanism rises from the fact that a drive may not have a backend at the time it is created, as devices are created after drives during qemu startup. Therefore, a driver requiring information about the block configuration can get this information when a backend is created for it at the earliest. The most natural place for this to take place seems to be in the realization functions of the various block device drivers, such as scsi-hd. The interface proposed here allows the block driver to receive information about the block configuration and the associated backend through a new callback. Signed-off-by: Ari Sundholm --- block/io.c | 22 ++++++++++++++++++++++ hw/block/block.c | 12 +++++++++++- include/block/block.h | 10 ++++++++++ include/block/block_int.h | 9 +++++++++ include/hw/block/block.h | 1 + 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/block/io.c b/block/io.c index b7beaee..3a06843 100644 --- a/block/io.c +++ b/block/io.c @@ -2932,3 +2932,25 @@ int coroutine_fn bdrv_co_copy_range(BdrvChild *src, = uint64_t src_offset, bdrv_dec_in_flight(dst_bs); return ret; } + +void bdrv_apply_blkconf(BlockDriverState *bs, BlockConf *conf) +{ + BlockDriver *drv =3D bs->drv; + + if (!drv) { + return; + } + + if (drv->bdrv_apply_blkconf) { + drv->bdrv_apply_blkconf(bs, conf); + return; + } + + if (bs->file && bs->file->bs) { + bdrv_apply_blkconf(bs->file->bs, conf); + } + + if (bs->drv->supports_backing && backing_bs(bs)) { + bdrv_apply_blkconf(backing_bs(bs), conf); + } +} diff --git a/hw/block/block.c b/hw/block/block.c index b91e2b6..8c87dbf 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -38,7 +38,7 @@ void blkconf_blocksizes(BlockConf *conf) /* fill in detected values if they are not defined via qemu command li= ne */ if (!conf->physical_block_size) { if (!backend_ret) { - conf->physical_block_size =3D blocksizes.phys; + conf->physical_block_size =3D blocksizes.phys; } else { conf->physical_block_size =3D BDRV_SECTOR_SIZE; } @@ -52,6 +52,16 @@ void blkconf_blocksizes(BlockConf *conf) } } =20 +void blkconf_apply_to_blkdrv(BlockConf *conf) +{ + BlockBackend *blk =3D conf->blk; + BlockDriverState *bs =3D blk_bs(blk); + + if (bs) { + bdrv_apply_blkconf(bs, conf); + } +} + bool blkconf_apply_backend_options(BlockConf *conf, bool readonly, bool resizable, Error **errp) { diff --git a/include/block/block.h b/include/block/block.h index 312ae01..5d0a8ba 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -10,6 +10,7 @@ #include "block/dirty-bitmap.h" #include "block/blockjob.h" #include "qemu/hbitmap.h" +#include "hw/block/block.h" =20 /* block.c */ typedef struct BlockDriver BlockDriver; @@ -650,4 +651,13 @@ void bdrv_unregister_buf(BlockDriverState *bs, void *h= ost); int coroutine_fn bdrv_co_copy_range(BdrvChild *src, uint64_t src_offset, BdrvChild *dst, uint64_t dst_offset, uint64_t bytes, BdrvRequestFlags flags= ); + +/* + * bdrv_apply_blkconf: + * + * Recursively finds the highest-level block drivers among the files and + * backing files that accept a block configuration and applies the given b= lock + * configuration to them. + */ +void bdrv_apply_blkconf(BlockDriverState *bs, BlockConf *conf); #endif diff --git a/include/block/block_int.h b/include/block/block_int.h index 888b7f7..cb82745 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -464,6 +464,15 @@ struct BlockDriver { void (*bdrv_abort_perm_update)(BlockDriverState *bs); =20 /** + * Called to inform the driver of the block configuration of the virtu= al + * block device. + * + * This function is called by a block device realization function if t= he + * device wants to inform the block driver of its block configuration. + */ + void (*bdrv_apply_blkconf)(BlockDriverState *bs, BlockConf *conf); + + /** * Returns in @nperm and @nshared the permissions that the driver for = @bs * needs on its child @c, based on the cumulative permissions requeste= d by * the parents in @parent_perm and @parent_shared. diff --git a/include/hw/block/block.h b/include/hw/block/block.h index d4f4dff..2861995 100644 --- a/include/hw/block/block.h +++ b/include/hw/block/block.h @@ -77,6 +77,7 @@ bool blkconf_geometry(BlockConf *conf, int *trans, unsigned cyls_max, unsigned heads_max, unsigned secs= _max, Error **errp); void blkconf_blocksizes(BlockConf *conf); +void blkconf_apply_to_blkdrv(BlockConf *conf); bool blkconf_apply_backend_options(BlockConf *conf, bool readonly, bool resizable, Error **errp); =20 --=20 2.7.4