From nobody Fri May 3 04:12:26 2024 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 152941718279555.914800030258675; Tue, 19 Jun 2018 07:06:22 -0700 (PDT) Received: from localhost ([::1]:42830 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVHGz-0005r1-EL for importer@patchew.org; Tue, 19 Jun 2018 10:06:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56037) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVGvO-0004gS-04 for qemu-devel@nongnu.org; Tue, 19 Jun 2018 09:43:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVGvI-0005dy-6j for qemu-devel@nongnu.org; Tue, 19 Jun 2018 09:43:58 -0400 Received: from mx1.mpynet.fi ([82.197.21.84]:13425) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fVGvD-0005V7-I4; Tue, 19 Jun 2018 09:43:47 -0400 From: Ari Sundholm To: Date: Tue, 19 Jun 2018 16:43:33 +0300 Message-ID: <1529415820-7750-2-git-send-email-ari@tuxera.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529415820-7750-1-git-send-email-ari@tuxera.com> References: <1529415820-7750-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.84 Subject: [Qemu-devel] [PATCH v5 1/8] block: Move two block permission constants to the relevant enum 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 , "open list:Block layer core" , Ari Sundholm , Max Reitz 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" This allows using the two constants outside of block.c, which will happen in a subsequent patch. Signed-off-by: Ari Sundholm --- block.c | 6 ------ include/block/block.h | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index afe30ca..20d54fe 100644 --- a/block.c +++ b/block.c @@ -1926,12 +1926,6 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t p= erm, uint64_t shared, return 0; } =20 -#define DEFAULT_PERM_PASSTHROUGH (BLK_PERM_CONSISTENT_READ \ - | BLK_PERM_WRITE \ - | BLK_PERM_WRITE_UNCHANGED \ - | BLK_PERM_RESIZE) -#define DEFAULT_PERM_UNCHANGED (BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH) - void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, const BdrvChildRole *role, BlockReopenQueue *reopen_queue, diff --git a/include/block/block.h b/include/block/block.h index e677080..6466ce0 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -225,6 +225,13 @@ enum { BLK_PERM_GRAPH_MOD =3D 0x10, =20 BLK_PERM_ALL =3D 0x1f, + + DEFAULT_PERM_PASSTHROUGH =3D BLK_PERM_CONSISTENT_READ + | BLK_PERM_WRITE + | BLK_PERM_WRITE_UNCHANGED + | BLK_PERM_RESIZE, + + DEFAULT_PERM_UNCHANGED =3D BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROU= GH, }; =20 char *bdrv_perm_names(uint64_t perm); --=20 2.7.4 From nobody Fri May 3 04:12:26 2024 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 1529416629731823.6529247109148; Tue, 19 Jun 2018 06:57:09 -0700 (PDT) Received: from localhost ([::1]:42766 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVH88-0006XR-Sp for importer@patchew.org; Tue, 19 Jun 2018 09:57:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56008) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVGvJ-0004b8-S2 for qemu-devel@nongnu.org; Tue, 19 Jun 2018 09:43:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVGvI-0005eo-O5 for qemu-devel@nongnu.org; Tue, 19 Jun 2018 09:43:53 -0400 Received: from mx1.mpynet.fi ([82.197.21.84]:26778) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fVGvE-0005W7-6T; Tue, 19 Jun 2018 09:43:48 -0400 From: Ari Sundholm To: Date: Tue, 19 Jun 2018 16:43:34 +0300 Message-ID: <1529415820-7750-3-git-send-email-ari@tuxera.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529415820-7750-1-git-send-email-ari@tuxera.com> References: <1529415820-7750-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.84 Subject: [Qemu-devel] [PATCH v5 2/8] 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 cf0eb82..607b4fc 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -25,7 +25,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; } @@ -39,6 +39,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 6466ce0..358127a 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; @@ -652,4 +653,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 327e478..74c470e 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -465,6 +465,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 e9f9e22..de74d4f 100644 --- a/include/hw/block/block.h +++ b/include/hw/block/block.h @@ -76,6 +76,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 From nobody Fri May 3 04:12:26 2024 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 1529416269725580.4876560617319; Tue, 19 Jun 2018 06:51:09 -0700 (PDT) Received: from localhost ([::1]:42729 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVH2L-0001tL-0Q for importer@patchew.org; Tue, 19 Jun 2018 09:51:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55907) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVGvH-0004YC-14 for qemu-devel@nongnu.org; Tue, 19 Jun 2018 09:43:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVGvE-0005YX-IU for qemu-devel@nongnu.org; Tue, 19 Jun 2018 09:43:50 -0400 Received: from mx1.mpynet.fi ([82.197.21.84]:34709) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fVGvE-0005WM-AN for qemu-devel@nongnu.org; Tue, 19 Jun 2018 09:43:48 -0400 From: Ari Sundholm To: Date: Tue, 19 Jun 2018 16:43:35 +0300 Message-ID: <1529415820-7750-4-git-send-email-ari@tuxera.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529415820-7750-1-git-send-email-ari@tuxera.com> References: <1529415820-7750-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.84 Subject: [Qemu-devel] [PATCH v5 3/8] hw/scsi/scsi-disk: Always apply block configuration to block driver 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: Paolo Bonzini , Fam Zheng , 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" This allows the block driver to use the block configuration of the new SCSI device. One use for this information is to set request limits using this information. Signed-off-by: Ari Sundholm --- hw/scsi/scsi-disk.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index aeaf611..c6efc4e 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2412,6 +2412,7 @@ static void scsi_realize(SCSIDevice *dev, Error **err= p) blk_set_dev_ops(s->qdev.conf.blk, &scsi_disk_block_ops, s); } blk_set_guest_block_size(s->qdev.conf.blk, s->qdev.blocksize); + blkconf_apply_to_blkdrv(&s->qdev.conf); =20 blk_iostatus_enable(s->qdev.conf.blk); } --=20 2.7.4 From nobody Fri May 3 04:12:26 2024 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 152941678361037.49305026794741; Tue, 19 Jun 2018 06:59:43 -0700 (PDT) Received: from localhost ([::1]:42782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVHAc-0000Iz-RK for importer@patchew.org; Tue, 19 Jun 2018 09:59:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55973) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVGvJ-0004aM-2u for qemu-devel@nongnu.org; Tue, 19 Jun 2018 09:43:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVGvI-0005e9-Ai for qemu-devel@nongnu.org; Tue, 19 Jun 2018 09:43:53 -0400 Received: from mx1.mpynet.fi ([82.197.21.84]:30525) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fVGvE-0005Wf-Ic; Tue, 19 Jun 2018 09:43:48 -0400 From: Ari Sundholm To: Date: Tue, 19 Jun 2018 16:43:36 +0300 Message-ID: <1529415820-7750-5-git-send-email-ari@tuxera.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529415820-7750-1-git-send-email-ari@tuxera.com> References: <1529415820-7750-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.84 Subject: [Qemu-devel] [PATCH v5 4/8] hw/ide/qdev: Always apply block configuration to block driver 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: John Snow , "open list:IDE" , 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" This allows the block driver to use the block configuration of the new IDE device. One use for this information is to set request limits using this information. Signed-off-by: Ari Sundholm --- hw/ide/qdev.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index 573b022..65d862a 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -213,6 +213,8 @@ static void ide_dev_initfn(IDEDevice *dev, IDEDriveKind= kind, Error **errp) dev->serial =3D g_strdup(s->drive_serial_str); } =20 + blkconf_apply_to_blkdrv(&dev->conf); + add_boot_device_path(dev->conf.bootindex, &dev->qdev, dev->unit ? "/disk@1" : "/disk@0"); } --=20 2.7.4 From nobody Fri May 3 04:12:26 2024 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 1529416506278131.20328602691256; Tue, 19 Jun 2018 06:55:06 -0700 (PDT) Received: from localhost ([::1]:42750 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVH69-0004fi-Fu for importer@patchew.org; Tue, 19 Jun 2018 09:55:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55968) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVGvI-0004aB-TF for qemu-devel@nongnu.org; Tue, 19 Jun 2018 09:43:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVGvI-0005dj-51 for qemu-devel@nongnu.org; Tue, 19 Jun 2018 09:43:52 -0400 Received: from mx1.mpynet.fi ([82.197.21.84]:40930) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fVGvF-0005Xb-3y; Tue, 19 Jun 2018 09:43:49 -0400 From: Ari Sundholm To: Date: Tue, 19 Jun 2018 16:43:37 +0300 Message-ID: <1529415820-7750-6-git-send-email-ari@tuxera.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529415820-7750-1-git-send-email-ari@tuxera.com> References: <1529415820-7750-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.84 Subject: [Qemu-devel] [PATCH v5 5/8] hw/block/virtio-blk: Always apply block configuration to block driver 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 , "open list:virtio-blk" , "Michael S. Tsirkin" , Max Reitz , Stefan Hajnoczi , 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" This allows the block driver to use the block configuration of the new VirtIO block device. One use for this information is to set request limits using this information. Signed-off-by: Ari Sundholm --- hw/block/virtio-blk.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 225fe44..d5fb43b 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -974,6 +974,7 @@ static void virtio_blk_device_realize(DeviceState *dev,= Error **errp) s->change =3D qemu_add_vm_change_state_handler(virtio_blk_dma_restart_= cb, s); blk_set_dev_ops(s->blk, &virtio_block_ops, s); blk_set_guest_block_size(s->blk, s->conf.conf.logical_block_size); + blkconf_apply_to_blkdrv(&s->conf.conf); =20 blk_iostatus_enable(s->blk); } --=20 2.7.4 From nobody Fri May 3 04:12:26 2024 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 1529416992454847.5882101257075; Tue, 19 Jun 2018 07:03:12 -0700 (PDT) Received: from localhost ([::1]:42810 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVHDz-0003DN-Lo for importer@patchew.org; Tue, 19 Jun 2018 10:03:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55970) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVGvI-0004aE-Um for qemu-devel@nongnu.org; Tue, 19 Jun 2018 09:43:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVGvI-0005dq-4o for qemu-devel@nongnu.org; Tue, 19 Jun 2018 09:43:52 -0400 Received: from mx1.mpynet.fi ([82.197.21.84]:24238) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fVGvF-0005Xk-6f; Tue, 19 Jun 2018 09:43:49 -0400 From: Ari Sundholm To: Date: Tue, 19 Jun 2018 16:43:38 +0300 Message-ID: <1529415820-7750-7-git-send-email-ari@tuxera.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529415820-7750-1-git-send-email-ari@tuxera.com> References: <1529415820-7750-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.84 Subject: [Qemu-devel] [PATCH v5 6/8] hw/block/nvme: Always apply block configuration to block driver 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: Keith Busch , Kevin Wolf , "open list:nvme" , Ari Sundholm , Max Reitz 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" This allows the block driver to use the block configuration of the new NVMe device. One use for this information is to set request limits using this information. Signed-off-by: Ari Sundholm --- hw/block/nvme.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index d5bf95b..21c3191 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1224,6 +1224,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **= errp) false, errp)) { return; } + blkconf_apply_to_blkdrv(&n->conf); =20 pci_conf =3D pci_dev->config; pci_conf[PCI_INTERRUPT_PIN] =3D 1; --=20 2.7.4 From nobody Fri May 3 04:12:26 2024 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 1529416683514824.5868558413807; Tue, 19 Jun 2018 06:58:03 -0700 (PDT) Received: from localhost ([::1]:42768 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVH90-0007IJ-KZ for importer@patchew.org; Tue, 19 Jun 2018 09:58:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55977) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVGvJ-0004aO-4G for qemu-devel@nongnu.org; Tue, 19 Jun 2018 09:43:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVGvI-0005eI-DI for qemu-devel@nongnu.org; Tue, 19 Jun 2018 09:43:53 -0400 Received: from mx1.mpynet.fi ([82.197.21.84]:52811) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fVGvF-0005YM-IT; Tue, 19 Jun 2018 09:43:49 -0400 From: Ari Sundholm To: Date: Tue, 19 Jun 2018 16:43:39 +0300 Message-ID: <1529415820-7750-8-git-send-email-ari@tuxera.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529415820-7750-1-git-send-email-ari@tuxera.com> References: <1529415820-7750-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.84 Subject: [Qemu-devel] [PATCH v5 7/8] hw/block/fdc: Always apply block configuration to block driver 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 , John Snow , "open list:Floppy" , Ari Sundholm , Max Reitz 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" This allows the block driver to use the block configuration of the new floppy device. One use for this information is to set request limits using this information. Signed-off-by: Ari Sundholm --- hw/block/fdc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/block/fdc.c b/hw/block/fdc.c index cd29e27..b11eeda 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -482,6 +482,8 @@ static void fd_change_cb(void *opaque, bool load, Error= **errp) errp)) { return; } + + blkconf_apply_to_blkdrv(drive->conf); } =20 drive->media_changed =3D 1; @@ -594,6 +596,8 @@ static void floppy_drive_realize(DeviceState *qdev, Err= or **errp) pick_drive_type(drive); dev->type =3D drive->drive; =20 + blkconf_apply_to_blkdrv(&dev->conf); + fd_revalidate(drive); } =20 --=20 2.7.4 From nobody Fri May 3 04:12:26 2024 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 1529416978720541.7924063679344; Tue, 19 Jun 2018 07:02:58 -0700 (PDT) Received: from localhost ([::1]:42809 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVHDl-00032p-Nh for importer@patchew.org; Tue, 19 Jun 2018 10:02:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56047) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVGvP-0004iH-AB for qemu-devel@nongnu.org; Tue, 19 Jun 2018 09:44:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVGvM-0005it-4j for qemu-devel@nongnu.org; Tue, 19 Jun 2018 09:43:59 -0400 Received: from mx1.mpynet.fi ([82.197.21.84]:36634) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fVGvG-0005ZN-AL; Tue, 19 Jun 2018 09:43:50 -0400 From: Ari Sundholm To: Date: Tue, 19 Jun 2018 16:43:40 +0300 Message-ID: <1529415820-7750-9-git-send-email-ari@tuxera.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529415820-7750-1-git-send-email-ari@tuxera.com> References: <1529415820-7750-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.84 Subject: [Qemu-devel] [PATCH v5 8/8] block: Add blklogwrites 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 , "open list:Block layer core" , Markus Armbruster , Max Reitz , Aapo Vienamo , 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" From: Aapo Vienamo Implements a block device write logging system, similar to Linux kernel device mapper dm-log-writes. The write operations that are performed on a block device are logged to a file or another block device. The write log format is identical to the dm-log-writes format. Currently, log markers are not supported. This functionality can be used for crash consistency and fs consistency testing. By implementing it in qemu, tests utilizing write logs can be be used to test non-Linux drivers and older kernels. The driver requires all requests to be aligned to the logical sector size of the block backend of the guest block device being logged. This is important because the dm-log-writes log format has a granularity of one sector for both the offset and the size of each write. Also, using the logical sector size as a basis for logging allows for faithful logging of writes when testing drivers with block devices that have unusual sector sizes. The implementation is based on the blkverify and blkdebug block drivers. Signed-off-by: Aapo Vienamo Signed-off-by: Ari Sundholm --- MAINTAINERS | 6 + block/Makefile.objs | 1 + block/blklogwrites.c | 426 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ qapi/block-core.json | 30 +++- 4 files changed, 457 insertions(+), 6 deletions(-) create mode 100644 block/blklogwrites.c diff --git a/MAINTAINERS b/MAINTAINERS index 0fb5f38..f824d2a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2021,6 +2021,12 @@ S: Supported F: block/quorum.c L: qemu-block@nongnu.org =20 +blklogwrites +M: Ari Sundholm +L: qemu-block@nongnu.org +S: Supported +F: block/blklogwrites.c + blkverify M: Stefan Hajnoczi L: qemu-block@nongnu.org diff --git a/block/Makefile.objs b/block/Makefile.objs index 899bfb5..c8337bf 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -5,6 +5,7 @@ block-obj-y +=3D qed-check.o block-obj-y +=3D vhdx.o vhdx-endian.o vhdx-log.o block-obj-y +=3D quorum.o block-obj-y +=3D parallels.o blkdebug.o blkverify.o blkreplay.o +block-obj-y +=3D blklogwrites.o block-obj-y +=3D block-backend.o snapshot.o qapi.o block-obj-$(CONFIG_WIN32) +=3D file-win32.o win32-aio.o block-obj-$(CONFIG_POSIX) +=3D file-posix.o diff --git a/block/blklogwrites.c b/block/blklogwrites.c new file mode 100644 index 0000000..decf5e5 --- /dev/null +++ b/block/blklogwrites.c @@ -0,0 +1,426 @@ +/* + * Write logging blk driver based on blkverify and blkdebug. + * + * Copyright (c) 2017 Tuomas Tynkkynen + * Copyright (c) 2018 Aapo Vienamo + * Copyright (c) 2018 Ari Sundholm + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/sockets.h" /* for EINPROGRESS on Windows */ +#include "block/block_int.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qstring.h" +#include "qemu/cutils.h" +#include "qemu/option.h" + +/* Disk format stuff - taken from Linux drivers/md/dm-log-writes.c */ + +#define LOG_FLUSH_FLAG (1 << 0) +#define LOG_FUA_FLAG (1 << 1) +#define LOG_DISCARD_FLAG (1 << 2) +#define LOG_MARK_FLAG (1 << 3) + +#define WRITE_LOG_VERSION 1ULL +#define WRITE_LOG_MAGIC 0x6a736677736872ULL + +/* All fields are little-endian. */ +struct log_write_super { + uint64_t magic; + uint64_t version; + uint64_t nr_entries; + uint32_t sectorsize; +}; + +struct log_write_entry { + uint64_t sector; + uint64_t nr_sectors; + uint64_t flags; + uint64_t data_len; +}; + +/* End of disk format structures. */ + +typedef struct { + BdrvChild *log_file; + uint32_t sectorsize; + uint32_t sectorbits; + uint64_t cur_log_sector; + uint64_t nr_entries; +} BDRVBlkLogWritesState; + +static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int f= lags, + Error **errp) +{ + BDRVBlkLogWritesState *s =3D bs->opaque; + Error *local_err =3D NULL; + int ret; + + /* Open the raw file */ + bs->file =3D bdrv_open_child(NULL, options, "raw", bs, &child_file, fa= lse, + &local_err); + if (local_err) { + ret =3D -EINVAL; + error_propagate(errp, local_err); + goto fail; + } + + s->sectorsize =3D BDRV_SECTOR_SIZE; /* May be updated later */ + s->sectorbits =3D BDRV_SECTOR_BITS; + s->cur_log_sector =3D 1; + s->nr_entries =3D 0; + + /* Open the log file */ + s->log_file =3D bdrv_open_child(NULL, options, "log", bs, &child_file,= false, + &local_err); + if (local_err) { + ret =3D -EINVAL; + error_propagate(errp, local_err); + goto fail; + } + + ret =3D 0; +fail: + if (ret < 0) { + bdrv_unref_child(bs, bs->file); + bs->file =3D NULL; + } + return ret; +} + +static void blk_log_writes_close(BlockDriverState *bs) +{ + BDRVBlkLogWritesState *s =3D bs->opaque; + + bdrv_unref_child(bs, s->log_file); + s->log_file =3D NULL; +} + +static int64_t blk_log_writes_getlength(BlockDriverState *bs) +{ + return bdrv_getlength(bs->file->bs); +} + +static void blk_log_writes_refresh_filename(BlockDriverState *bs, + QDict *options) +{ + BDRVBlkLogWritesState *s =3D bs->opaque; + + /* bs->file->bs has already been refreshed */ + bdrv_refresh_filename(s->log_file->bs); + + if (bs->file->bs->full_open_options + && s->log_file->bs->full_open_options) + { + QDict *opts =3D qdict_new(); + qdict_put_obj(opts, "driver", + QOBJECT(qstring_from_str("blklogwrites"))); + + qobject_ref(bs->file->bs->full_open_options); + qdict_put_obj(opts, "raw", QOBJECT(bs->file->bs->full_open_options= )); + qobject_ref(s->log_file->bs->full_open_options); + qdict_put_obj(opts, "log", + QOBJECT(s->log_file->bs->full_open_options)); + + bs->full_open_options =3D opts; + } + + if (bs->file->bs->exact_filename[0] + && s->log_file->bs->exact_filename[0]) + { + int ret =3D snprintf(bs->exact_filename, sizeof(bs->exact_filename= ), + "blklogwrites:%s:%s", + bs->file->bs->exact_filename, + s->log_file->bs->exact_filename); + + if (ret >=3D sizeof(bs->exact_filename)) { + /* An overflow makes the filename unusable, so do not report a= ny */ + bs->exact_filename[0] =3D '\0'; + } + } +} + +static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, + const BdrvChildRole *role, + BlockReopenQueue *ro_q, + uint64_t perm, uint64_t shrd, + uint64_t *nperm, uint64_t *nshrd) +{ + if (!c) { + *nperm =3D perm & DEFAULT_PERM_PASSTHROUGH; + *nshrd =3D (shrd & DEFAULT_PERM_PASSTHROUGH) | DEFAULT_PERM_UNCHAN= GED; + return; + } + + if (!strcmp(c->name, "log")) { + bdrv_format_default_perms(bs, c, role, ro_q, perm, shrd, nperm, ns= hrd); + } else { + bdrv_filter_default_perms(bs, c, role, ro_q, perm, shrd, nperm, ns= hrd); + } +} + +static void blk_log_writes_refresh_limits(BlockDriverState *bs, Error **er= rp) +{ + if (bs->bl.request_alignment < BDRV_SECTOR_SIZE) { + bs->bl.request_alignment =3D BDRV_SECTOR_SIZE; + + if (bs->bl.pdiscard_alignment && + bs->bl.pdiscard_alignment < bs->bl.request_alignment) + bs->bl.pdiscard_alignment =3D bs->bl.request_alignment; + if (bs->bl.pwrite_zeroes_alignment && + bs->bl.pwrite_zeroes_alignment < bs->bl.request_alignment) + bs->bl.pwrite_zeroes_alignment =3D bs->bl.request_alignment; + } +} + +static inline uint32_t blk_log_writes_log2(uint32_t value) +{ + assert(value > 0); + return 31 - clz32(value); +} + +static void blk_log_writes_apply_blkconf(BlockDriverState *bs, BlockConf *= conf) +{ + BDRVBlkLogWritesState *s =3D bs->opaque; + assert(bs && conf && conf->blk && s); + + s->sectorsize =3D conf->logical_block_size; + s->sectorbits =3D blk_log_writes_log2(s->sectorsize); + bs->bl.request_alignment =3D s->sectorsize; + if (conf->discard_granularity !=3D (uint32_t)-1) { + bs->bl.pdiscard_alignment =3D conf->discard_granularity; + } + + if (bs->bl.pdiscard_alignment && + bs->bl.pdiscard_alignment < bs->bl.request_alignment) { + bs->bl.pdiscard_alignment =3D bs->bl.request_alignment; + } + if (bs->bl.pwrite_zeroes_alignment && + bs->bl.pwrite_zeroes_alignment < bs->bl.request_alignment) { + bs->bl.pwrite_zeroes_alignment =3D bs->bl.request_alignment; + } +} + +static int coroutine_fn +blk_log_writes_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t b= ytes, + QEMUIOVector *qiov, int flags) +{ + return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); +} + +typedef struct BlkLogWritesFileReq { + BlockDriverState *bs; + uint64_t offset; + uint64_t bytes; + int file_flags; + QEMUIOVector *qiov; + int (*func)(struct BlkLogWritesFileReq *r); + int file_ret; +} BlkLogWritesFileReq; + +typedef struct { + BlockDriverState *bs; + QEMUIOVector *qiov; + struct log_write_entry entry; + uint64_t zero_size; + int log_ret; +} BlkLogWritesLogReq; + +static void coroutine_fn blk_log_writes_co_do_log(BlkLogWritesLogReq *lr) +{ + BDRVBlkLogWritesState *s =3D lr->bs->opaque; + uint64_t cur_log_offset =3D s->cur_log_sector << s->sectorbits; + + s->nr_entries++; + s->cur_log_sector +=3D + ROUND_UP(lr->qiov->size, s->sectorsize) >> s->sectorbits; + + lr->log_ret =3D bdrv_co_pwritev(s->log_file, cur_log_offset, lr->qiov-= >size, + lr->qiov, 0); + + /* Logging for the "write zeroes" operation */ + if (lr->log_ret =3D=3D 0 && lr->zero_size) { + cur_log_offset =3D s->cur_log_sector << s->sectorbits; + s->cur_log_sector +=3D + ROUND_UP(lr->zero_size, s->sectorsize) >> s->sectorbits; + + lr->log_ret =3D bdrv_co_pwrite_zeroes(s->log_file, cur_log_offset, + lr->zero_size, 0); + } + + /* Update super block on flush */ + if (lr->log_ret =3D=3D 0 && lr->entry.flags & LOG_FLUSH_FLAG) { + struct log_write_super super =3D { + .magic =3D cpu_to_le64(WRITE_LOG_MAGIC), + .version =3D cpu_to_le64(WRITE_LOG_VERSION), + .nr_entries =3D cpu_to_le64(s->nr_entries), + .sectorsize =3D cpu_to_le32(s->sectorsize), + }; + void *zeroes =3D g_malloc0(s->sectorsize - sizeof(super)); + QEMUIOVector qiov; + + qemu_iovec_init(&qiov, 2); + qemu_iovec_add(&qiov, &super, sizeof(super)); + qemu_iovec_add(&qiov, zeroes, s->sectorsize - sizeof(super)); + + lr->log_ret =3D + bdrv_co_pwritev(s->log_file, 0, s->sectorsize, &qiov, 0); + if (lr->log_ret =3D=3D 0) { + lr->log_ret =3D bdrv_co_flush(s->log_file->bs); + } + qemu_iovec_destroy(&qiov); + g_free(zeroes); + } +} + +static void coroutine_fn blk_log_writes_co_do_file(BlkLogWritesFileReq *fr) +{ + fr->file_ret =3D fr->func(fr); +} + +static int coroutine_fn +blk_log_writes_co_log(BlockDriverState *bs, uint64_t offset, uint64_t byte= s, + QEMUIOVector *qiov, int flags, + int (*file_func)(BlkLogWritesFileReq *r), + uint64_t entry_flags, bool is_zero_write) +{ + QEMUIOVector log_qiov; + size_t niov =3D qiov ? qiov->niov : 0; + size_t i; + BDRVBlkLogWritesState *s =3D bs->opaque; + BlkLogWritesFileReq fr =3D { + .bs =3D bs, + .offset =3D offset, + .bytes =3D bytes, + .file_flags =3D flags, + .qiov =3D qiov, + .func =3D file_func, + }; + BlkLogWritesLogReq lr =3D { + .bs =3D bs, + .qiov =3D &log_qiov, + .entry =3D { + .sector =3D cpu_to_le64(offset >> s->sectorbits), + .nr_sectors =3D cpu_to_le64(bytes >> s->sectorbits), + .flags =3D cpu_to_le64(entry_flags), + .data_len =3D 0, + }, + .zero_size =3D is_zero_write ? bytes : 0, + }; + void *zeroes =3D g_malloc0(s->sectorsize - sizeof(lr.entry)); + + assert((1 << s->sectorbits) =3D=3D s->sectorsize); + assert(bs->bl.request_alignment =3D=3D s->sectorsize); + assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment)); + assert(QEMU_IS_ALIGNED(bytes, bs->bl.request_alignment)); + + qemu_iovec_init(&log_qiov, niov + 2); + qemu_iovec_add(&log_qiov, &lr.entry, sizeof(lr.entry)); + qemu_iovec_add(&log_qiov, zeroes, s->sectorsize - sizeof(lr.entry)); + for (i =3D 0; i < niov; ++i) { + qemu_iovec_add(&log_qiov, qiov->iov[i].iov_base, qiov->iov[i].iov_= len); + } + + blk_log_writes_co_do_file(&fr); + blk_log_writes_co_do_log(&lr); + + qemu_iovec_destroy(&log_qiov); + g_free(zeroes); + + if (lr.log_ret < 0) { + return lr.log_ret; + } + + return fr.file_ret; +} + +static int coroutine_fn +blk_log_writes_co_do_file_pwritev(BlkLogWritesFileReq *fr) +{ + return bdrv_co_pwritev(fr->bs->file, fr->offset, fr->bytes, + fr->qiov, fr->file_flags); +} + +static int coroutine_fn +blk_log_writes_co_do_file_pwrite_zeroes(BlkLogWritesFileReq *fr) +{ + return bdrv_co_pwrite_zeroes(fr->bs->file, fr->offset, fr->bytes, + fr->file_flags); +} + +static int coroutine_fn blk_log_writes_co_do_file_flush(BlkLogWritesFileRe= q *fr) +{ + return bdrv_co_flush(fr->bs->file->bs); +} + +static int coroutine_fn +blk_log_writes_co_do_file_pdiscard(BlkLogWritesFileReq *fr) +{ + return bdrv_co_pdiscard(fr->bs->file->bs, fr->offset, fr->bytes); +} + +static int coroutine_fn +blk_log_writes_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t = bytes, + QEMUIOVector *qiov, int flags) +{ + return blk_log_writes_co_log(bs, offset, bytes, qiov, flags, + blk_log_writes_co_do_file_pwritev, 0, fal= se); +} + +static int coroutine_fn +blk_log_writes_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int = bytes, + BdrvRequestFlags flags) +{ + return blk_log_writes_co_log(bs, offset, bytes, NULL, flags, + blk_log_writes_co_do_file_pwrite_zeroes, = 0, + true); +} + +static int coroutine_fn blk_log_writes_co_flush_to_disk(BlockDriverState *= bs) +{ + return blk_log_writes_co_log(bs, 0, 0, NULL, 0, + blk_log_writes_co_do_file_flush, + LOG_FLUSH_FLAG, false); +} + +static int coroutine_fn +blk_log_writes_co_pdiscard(BlockDriverState *bs, int64_t offset, int count) +{ + return blk_log_writes_co_log(bs, offset, count, NULL, 0, + blk_log_writes_co_do_file_pdiscard, + LOG_DISCARD_FLAG, false); +} + +static BlockDriver bdrv_blk_log_writes =3D { + .format_name =3D "blklogwrites", + .protocol_name =3D "blklogwrites", + .instance_size =3D sizeof(BDRVBlkLogWritesState), + + .bdrv_file_open =3D blk_log_writes_open, + .bdrv_close =3D blk_log_writes_close, + .bdrv_getlength =3D blk_log_writes_getlength, + .bdrv_refresh_filename =3D blk_log_writes_refresh_filename, + .bdrv_child_perm =3D blk_log_writes_child_perm, + .bdrv_refresh_limits =3D blk_log_writes_refresh_limits, + .bdrv_apply_blkconf =3D blk_log_writes_apply_blkconf, + + .bdrv_co_preadv =3D blk_log_writes_co_preadv, + .bdrv_co_pwritev =3D blk_log_writes_co_pwritev, + .bdrv_co_pwrite_zeroes =3D blk_log_writes_co_pwrite_zeroes, + .bdrv_co_flush_to_disk =3D blk_log_writes_co_flush_to_disk, + .bdrv_co_pdiscard =3D blk_log_writes_co_pdiscard, + .bdrv_co_block_status =3D bdrv_co_block_status_from_file, + + .is_filter =3D true, +}; + +static void bdrv_blk_log_writes_init(void) +{ + bdrv_register(&bdrv_blk_log_writes); +} + +block_init(bdrv_blk_log_writes_init); diff --git a/qapi/block-core.json b/qapi/block-core.json index ab629d1..b4255d2 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2509,16 +2509,17 @@ # @throttle: Since 2.11 # @nvme: Since 2.12 # @copy-on-read: Since 3.0 +# @blklogwrites: Since 3.0 # # Since: 2.9 ## { 'enum': 'BlockdevDriver', - 'data': [ 'blkdebug', 'blkverify', 'bochs', 'cloop', 'copy-on-read', - 'dmg', 'file', 'ftp', 'ftps', 'gluster', 'host_cdrom', - 'host_device', 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs', - 'null-aio', 'null-co', 'nvme', 'parallels', 'qcow', 'qcow2', '= qed', - 'quorum', 'raw', 'rbd', 'replication', 'sheepdog', 'ssh', - 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] } + 'data': [ 'blkdebug', 'blklogwrites', 'blkverify', 'bochs', 'cloop', + 'copy-on-read', 'dmg', 'file', 'ftp', 'ftps', 'gluster', + 'host_cdrom', 'host_device', 'http', 'https', 'iscsi', 'luks', + 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels', 'qco= w', + 'qcow2', 'qed', 'quorum', 'raw', 'rbd', 'replication', 'sheepd= og', + 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxh= s' ] } =20 ## # @BlockdevOptionsFile: @@ -3033,6 +3034,21 @@ '*set-state': ['BlkdebugSetStateOptions'] } } =20 ## +# @BlockdevOptionsBlklogwrites: +# +# Driver specific block device options for blklogwrites. +# +# @raw: block device +# +# @log: block device used to log writes on @raw +# +# Since: 3.0 +## +{ 'struct': 'BlockdevOptionsBlklogwrites', + 'data': { 'raw': 'BlockdevRef', + 'log': 'BlockdevRef' } } + +## # @BlockdevOptionsBlkverify: # # Driver specific block device options for blkverify. @@ -3546,6 +3562,7 @@ 'discriminator': 'driver', 'data': { 'blkdebug': 'BlockdevOptionsBlkdebug', + 'blklogwrites': 'BlockdevOptionsBlklogwrites', 'blkverify': 'BlockdevOptionsBlkverify', 'bochs': 'BlockdevOptionsGenericFormat', 'cloop': 'BlockdevOptionsGenericFormat', @@ -4074,6 +4091,7 @@ 'discriminator': 'driver', 'data': { 'blkdebug': 'BlockdevCreateNotSupported', + 'blklogwrites': 'BlockdevCreateNotSupported', 'blkverify': 'BlockdevCreateNotSupported', 'bochs': 'BlockdevCreateNotSupported', 'cloop': 'BlockdevCreateNotSupported', --=20 2.7.4