From patchwork Wed Oct 2 12:33:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Beno=C3=AEt_Canet?= X-Patchwork-Id: 279721 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CD75B2C00A6 for ; Wed, 2 Oct 2013 22:34:33 +1000 (EST) Received: from localhost ([::1]:35785 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VRLdP-00032W-I8 for incoming@patchwork.ozlabs.org; Wed, 02 Oct 2013 08:34:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54409) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VRLcy-0002wy-Tf for qemu-devel@nongnu.org; Wed, 02 Oct 2013 08:34:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VRLct-0005JP-Ks for qemu-devel@nongnu.org; Wed, 02 Oct 2013 08:34:04 -0400 Received: from nodalink.pck.nerim.net ([62.212.105.220]:42198 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VRLct-0005IM-43 for qemu-devel@nongnu.org; Wed, 02 Oct 2013 08:33:59 -0400 Received: by paradis.irqsave.net (Postfix, from userid 1002) id 5829F8746C4; Wed, 2 Oct 2013 14:33:58 +0200 (CEST) Received: from Laure.example.org (unknown [192.168.77.20]) by paradis.irqsave.net (Postfix) with ESMTP id C251D8746C0; Wed, 2 Oct 2013 14:33:49 +0200 (CEST) From: =?UTF-8?q?Beno=C3=AEt=20Canet?= To: qemu-devel@nongnu.org Date: Wed, 2 Oct 2013 14:33:48 +0200 Message-Id: <1380717228-10135-2-git-send-email-benoit@irqsave.net> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1380717228-10135-1-git-send-email-benoit@irqsave.net> References: <1380717228-10135-1-git-send-email-benoit@irqsave.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 62.212.105.220 Cc: kwolf@redhat.com, jcody@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@redhat.com Subject: [Qemu-devel] [PATCH V4] block: Add BlockDriver.bdrv_check_ext_snapshot. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This field is used by blkverify to disable external snapshots creation. I will also be used by block filters like quorum to disable external snapshots creation. Signed-off-by: Benoit Canet Reviewed-by: Max Reitz --- block.c | 17 +++++++++++++++++ block/blkverify.c | 2 ++ blockdev.c | 5 +++++ include/block/block.h | 14 ++++++++++++++ include/block/block_int.h | 6 ++++++ 5 files changed, 44 insertions(+) diff --git a/block.c b/block.c index 93e113a..e891522 100644 --- a/block.c +++ b/block.c @@ -4632,3 +4632,20 @@ int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options) } return bs->drv->bdrv_amend_options(bs, options); } + +ExtSnapshotPerm bdrv_check_ext_snapshot(BlockDriverState *bs) +{ + /* external snashots are allowed by defaults */ + if (bs->drv->bdrv_check_ext_snapshot) { + return bs->drv->bdrv_check_ext_snapshot(bs); + } + if (bs->file && bs->file->drv && bs->file->drv->bdrv_check_ext_snapshot) { + return bs->file->drv->bdrv_check_ext_snapshot(bs); + } + return EXT_SNAPSHOT_ALLOWED; +} + +ExtSnapshotPerm bdrv_check_ext_snapshot_forbidden(BlockDriverState *bs) +{ + return EXT_SNAPSHOT_FORBIDDEN; +} diff --git a/block/blkverify.c b/block/blkverify.c index 2077d8a..b64c638 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -313,6 +313,8 @@ static BlockDriver bdrv_blkverify = { .bdrv_aio_readv = blkverify_aio_readv, .bdrv_aio_writev = blkverify_aio_writev, .bdrv_aio_flush = blkverify_aio_flush, + + .bdrv_check_ext_snapshot = bdrv_check_ext_snapshot_forbidden, }; static void bdrv_blkverify_init(void) diff --git a/blockdev.c b/blockdev.c index 8aa66a9..92029d8 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1131,6 +1131,11 @@ static void external_snapshot_prepare(BlkTransactionState *common, } } + if (bdrv_check_ext_snapshot(state->old_bs) != EXT_SNAPSHOT_ALLOWED) { + error_set(errp, QERR_FEATURE_DISABLED, "snapshot"); + return; + } + flags = state->old_bs->open_flags; /* create new image w/backing file */ diff --git a/include/block/block.h b/include/block/block.h index f808550..2bf0e12 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -244,6 +244,20 @@ int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix); int bdrv_amend_options(BlockDriverState *bs_new, QEMUOptionParameter *options); +/* external snapshots */ + +typedef enum { + EXT_SNAPSHOT_ALLOWED, + EXT_SNAPSHOT_FORBIDDEN, +} ExtSnapshotPerm; + +/* return EXT_SNAPSHOT_ALLOWED if external snapshot is allowed + * return EXT_SNAPSHOT_FORBIDEN if external snapshot is forbiden + */ +ExtSnapshotPerm bdrv_check_ext_snapshot(BlockDriverState *bs); +/* helper used to forbid external snapshots like in blkverify */ +ExtSnapshotPerm bdrv_check_ext_snapshot_forbidden(BlockDriverState *bs); + /* async block I/O */ typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector, int sector_num); diff --git a/include/block/block_int.h b/include/block/block_int.h index 211087a..e6a14ae 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -67,6 +67,12 @@ typedef struct BdrvTrackedRequest { struct BlockDriver { const char *format_name; int instance_size; + + /* if not defined external snapshots are allowed + * future block filters will query their children to build the response + */ + ExtSnapshotPerm (*bdrv_check_ext_snapshot)(BlockDriverState *bs); + int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename); int (*bdrv_probe_device)(const char *filename);