From nobody Fri May 3 07:27:25 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1642714885; cv=pass; d=zohomail.com; s=zohoarc; b=Yipu4m1YAnGh4m0hgImxn1l3LMyRtl/QlIFbx9FS72M276RWVesRKbh9LRq2rFuEWSsWWBB2sWwNlO+1feBCbWYiC2UsUQ1PO+40oDPS9AAJJEl2p9yMvLu6QB3Zu5w/K7i5EWGGLPTPcXNqqWqsvEzPyKuHNFwhwSVazIKUE50= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642714885; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XphkeIN3GJyD4VhIQzCRKGqlEWSP1GAF6GjlKtgaEVg=; b=X+zoq5fnRH39/UnSuPRgYPUTCfpuGIBuPyyokhsX2cOR9wsMxyMEBPZSn24r21DhMjD0sSUxHvEe/imcalAvUABTd4C5haQnJ66TODbJBUAzM6DcSBDbR2vbdX09Qtq9pCXUCww5ltOsKp8J64hemqDzt1/pjwEhnTVD7tqm9pM= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1642714885084375.7156044977705; Thu, 20 Jan 2022 13:41:25 -0800 (PST) Received: from localhost ([::1]:45310 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAfBL-00017u-CA for importer@patchew.org; Thu, 20 Jan 2022 16:41:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAaBS-0002ab-EP; Thu, 20 Jan 2022 11:21:13 -0500 Received: from mail-eopbgr60119.outbound.protection.outlook.com ([40.107.6.119]:9553 helo=EUR04-DB3-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAaBP-0005q6-8P; Thu, 20 Jan 2022 11:21:09 -0500 Received: from DB9PR08MB6748.eurprd08.prod.outlook.com (2603:10a6:10:2a7::16) by VI1PR0802MB2238.eurprd08.prod.outlook.com (2603:10a6:800:9a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.11; Thu, 20 Jan 2022 16:21:02 +0000 Received: from DB9PR08MB6748.eurprd08.prod.outlook.com ([fe80::f043:6356:ee64:6cc6]) by DB9PR08MB6748.eurprd08.prod.outlook.com ([fe80::f043:6356:ee64:6cc6%6]) with mapi id 15.20.4888.013; Thu, 20 Jan 2022 16:21:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AI7RslUCoLdZtgjSzkldYhhREKul7U/ce/yGbeEaYvw8ImCXfM0JRZC2l6RGvMIicpdb9DFwtfIuUUPWHWYH7lV3pJMkhs/9JDaiaRJrNCoVy1N3nh7JbJj7VUpYJxAsJmpq1KrW3d0jJViyS6Sbc2rX9uNNPJZVMxaopvF31RLgNSnyDMAXEPZ/F13gMoB2PSwxrmi/ZRs9WMmcIM2vj/B+hQFSDh8bXTUqXFPdIw+IQ3Pg0SPp1J2BadnFylgFTGesTj4Oz2Ack12Bjof2Sh3NtklucSs3fM6w0CYegxqadEEbp7hYUJulJhE3yB77r0NAjm2oU8Cv5M+epSH5nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XphkeIN3GJyD4VhIQzCRKGqlEWSP1GAF6GjlKtgaEVg=; b=RIlknJxmjDpb0cnCpWl/xzY1uKQCDktY7DSeNzXR99oJpZ/AVEUdjcJtPoWysS8kdj8oEudeZZ3v6OQpUFuWw/62ZysjQMLCuTQPZrwjUwR3Ew+JdqG4zSj28/w9rhCS/nU//cPXUrDVLTE2FxN2nBjvDyRGMqO2Csf0uuvbgqumSSD0jgetqDfqntueAgbNMR5Jx9+FsH7uB9u6iloWnbGEkoo+pPk1YmooewNheyfm/oqw6bqkOMWwJVAAt8hPbc+xaH+4MtdeLqcKZG+/VvfmSVREUwEAxM2YAOP7lJGhDUiGs65480JoH5klk4//UcUkBs1UwIOjNgsNWZa9SA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XphkeIN3GJyD4VhIQzCRKGqlEWSP1GAF6GjlKtgaEVg=; b=iLeZvlnXPpOi0PlRmBF6iLK63ecaesCSFSm1NtzA1D+sCcdbOh7v8se0UO5YBSCZ6dlyljA810GAh/hTyIWZqEz7Euic4Oyj+XDIDTvGWtPqI2WpTUsY22BI4B5KiLYx22mUhen5L1V0lusavDosxWHOHT+oz/YoUoWaCc7U2+s= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, ktkhai@virtuozzo.com, igor@virtuozzo.com Subject: [PATCH 1/2] qcow2: add keep-dirty open option Date: Thu, 20 Jan 2022 17:20:42 +0100 Message-Id: <20220120162043.2693196-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220120162043.2693196-1-vsementsov@virtuozzo.com> References: <20220120162043.2693196-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM6P193CA0118.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::23) To DB9PR08MB6748.eurprd08.prod.outlook.com (2603:10a6:10:2a7::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a37e6f83-84a2-498e-b65f-08d9dc30d945 X-MS-TrafficTypeDiagnostic: VI1PR0802MB2238:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:121; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pBXWtmpdDtxbnswq1eYCTb2VYL00N1SZKdSHZ7gGRmGXraQnQWsml+AQTwqaJ4te9nz3hcp6/pqiPSU0nyG/2vmBW9pQIidxoWX5HWin+GHo5FYOovdmYk+J3sybf+m7fcxiGnQ05ynQjZauwFJG4CvQuMhN6nFaw1PJrbSxgG/A6I4fkbCBjEAztXdfQmNbs4OUVX8um3pHK7SIrt0atFyDJqsjaWI++EQ0wI1rjg7Qnoe+Uu002/77Y52XaEwwgJBYcR/2ZOdqWBML4AOQ3NIzoGuZSn3oq4wsAHjOGAENKljrYwApFvl88nQmA5MGTQ4zRu6VLp8tHdlG1SRFH2mHfW2uKmzkepKKx3cd6Inr2WYYDnF1lVEN/O+LPb+jjfCH4Ems7lEdxtXJ+lChMQKyMIxs7TIAmR7Qwr0XHOL2SUhG1TlsJDDScFlxTQnjfz7ZhVMyVDb4XNzyEXN1dieNWeXQMWfv60JForpK1vBUPR+aj5kPoFaNHhUN2NO9pg8Qy/R3CuclF2Kot+NqGZ+HIFsA01ucnBbnKZ48cErdZUKrscWb+PGKhuFckjwni/ATb+rAIXpKmoECAW0F/v9n92epZK6Dr29P7kVnTEBRKGOpEIosSPLRSC2OQVs+XrgIU/hZZXvb4km4VbCvA26QW7KPu13RS0nScZItEWEA98Nkws/OuPAdxVwHYStIOS0kDPzIqV/15+Bza2cKGIob5rtklzgP6klP6gHbJKs= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR08MB6748.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(66476007)(83380400001)(36756003)(66556008)(6916009)(2906002)(8936002)(316002)(26005)(8676002)(4326008)(107886003)(2616005)(6506007)(508600001)(66946007)(86362001)(6666004)(19627235002)(38100700002)(52116002)(6486002)(1076003)(38350700002)(186003)(5660300002)(6512007)(14143004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?ufoDhjNrjnIOcZjDypZh2Mqd1oca4x1jzEmBsyIdUQUW4mX+/xpp9/EctzJ3?= =?us-ascii?Q?SeS2ND6oZbiAxCV4/0EEGfRqhfnvcnrn6pLc0BQHdNldk340bROh1hKp9whj?= =?us-ascii?Q?gUBnrU/cwhT8wsTihhVDHIOKws7c9Ya+GIaAEA4l8kHHm4QqSnnzm2ogsNs7?= =?us-ascii?Q?RdGSH016ejGT3/nIqYSsYzK2aTQAC0PuqGPJu6dkih9OO4iUIDcXPgcrAh+1?= =?us-ascii?Q?d8Gr+/l70oyReze6Au6574XTce92GZ1+/zvphecnnHfNVY9QFNZIg3HBBO5o?= =?us-ascii?Q?V9ppw8cbUr5V9C3YNv4/LkWgMXs7zRMTNbV2xD9fonL59g6nUv8ZGcGibGZU?= =?us-ascii?Q?YZZeiolIY+zjtLBH9ZykANt1udtNvpXtIVrDTSem99M44kqy+qJ4S1D74mi5?= =?us-ascii?Q?xpidnoX/Y+O+mNBSQRt9J71rNCmRpF0lFWB5J7ZZobttOIa+QgsmT0j0E4xT?= =?us-ascii?Q?smk6M+gfV8emLVRZT8lE6dLbMrVIFb/Nkn/HAH1xAsvQtuYZ6+fblRdNUpl7?= =?us-ascii?Q?hAxeJlpUzue0ggWb6Y/8veh7mZyysh3u7Pdpf70CTNjr6KMt1+jT2KZmWx0p?= =?us-ascii?Q?qoVWI5q4fJysvvv0y0fmFLkH6kZ8SLRwCEox8CVNjZSnRAGANotFrAibgjhl?= =?us-ascii?Q?s66QIaGvO5FyqVHwI6vC2WosFrfd+FmS3+F/1E1E7KxbknCGlFNzwRwkFXcR?= =?us-ascii?Q?e8MFANg4IWTCnhEpwrGf9Gr73DxVqxpN/6Du3cBAxG6E3YeMPoLGStQyDM/d?= =?us-ascii?Q?Rx7g0QZhGMCzQGzY/vLtrsyu9aWo47nkRSRlBUwbfXwxTBVGYfzWijWl5yil?= =?us-ascii?Q?2P9keIFAwlumOUo8re3kvC/m6qrJ6I3ILgHZqXYROKNhULU1zS2+upkgGkEx?= =?us-ascii?Q?IqcpcuK/Ai0GT8eiYVKtqRliwz8tb3D14vlv/dBmtk4+z3+DmtfvYzberje5?= =?us-ascii?Q?iIRdPFF61huaWo2KECMdXODVbqUuZCleuGoCDJ+A0niNAORTFXb7nJ9YSYug?= =?us-ascii?Q?v21uDXP/ayifHe+I8GLeCtyN1+24tDIwlBnc3poY+/HrVwHuMZNN3r/tg9sA?= =?us-ascii?Q?4NERMTyGVsxfd7xcIQ5PY0o+i7lczpdH6QpgvOfE56GfHznPHg/AAfGZUme2?= =?us-ascii?Q?6txJepDD4D563OKi4K77CCe8mLNCsTBvSS10bP5mmUo8H9tKsi1qDWWdR8xu?= =?us-ascii?Q?/YPb+Vi3QQajp6xSpZJ+QjyjlG48epvyqzrI24lgk9X2GbeAVT9zlq30+RRE?= =?us-ascii?Q?w71573pt4wVPpNGmzybdx+axCYCS28zU0fbH3d6iDiT7ravAvB6MiIQWOUg1?= =?us-ascii?Q?hAHwH9WC9rOAKLaFL+RB5JnHirZC9bIDcNbjxQ5DKVzoudpv5tJFpiK6VQoG?= =?us-ascii?Q?SMiW8fpAXEKB1g+B6llaR01MBvhN5GZWdeZVY4mmaEvPw95myS98d5AXnBUE?= =?us-ascii?Q?cUe0hHFFNCCVF//ZsZpJszbLvokxMz/gC3bs5L2mTsoCyAJutyTnzOmGgVff?= =?us-ascii?Q?fXKsyvDhkVN5zB3+wc14WT6+Ts0BAfEinczZ2P8gIaotx/FFNIW7u0BPDM69?= =?us-ascii?Q?E8v7n2oPO2vNB2GrAIwjGkIqxJSldqODgPKGQm/8GZ4BvuJjFxvJMDXKAJhG?= =?us-ascii?Q?aDg3ZorqZz7O2kWp+kHQiVQidNxSyYjRSmJpqV8p3XxMGMlfGa/N6eQ1LucI?= =?us-ascii?Q?gvhptbiK2Ki2GZMCqm/jRUoVMCU=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: a37e6f83-84a2-498e-b65f-08d9dc30d945 X-MS-Exchange-CrossTenant-AuthSource: DB9PR08MB6748.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2022 16:21:01.8587 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UVrLNuf/bM/J8sU/UhSFpYI7E0u86+bsZsLMVWsoZxynQk0vVFhNS9fEbR1owSheWT5mZlFKUXPq9ZOvMqLMx4SJy53ioTzRxEDOfhfnBFw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2238 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=40.107.6.119; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-DB3-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, 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_PASS=-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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1642714886941100001 Content-Type: text/plain; charset="utf-8" Consider the case: Thirdparty component works with qcow2 image, and dirty bit is set. Thirdparty component want to start qemu-img to do some manipulation. Ofcourse, third party component flushes refcounts and other metadata before starting QEMU. But the component don't want to clear dirty bit, as this breaks transactionability of the operation: we'll have to set it again but it may fail. Clearing the dirty bit is unrecoverable action and can't be transactional. That's a problem. The solution is a new qcow2 open option: keep-dirty. When set: 1. On qcow2 open, ignore dirty bit and don't do check: caller is responsible for refcounts being valid. 2. Never clear dirty bit during QEMU execution, including close. Details: 1. For simplicity let's just not allow keep-dirty without lazy refcounts. 2. Don't allow to open with keep-dirty when dirty bit is unset. This may mean some error in user logic. 3. For implementation do the following: dirty flag in s->incompatible_features behaves same way as without keep-dirty option: it actually designate status of refcounts dirtiness. But we never clear the flag in the image, and we remember that it is always set. Signed-off-by: Vladimir Sementsov-Ogievskiy --- qapi/block-core.json | 5 ++++ block/qcow2.h | 2 ++ block/qcow2.c | 66 ++++++++++++++++++++++++++++++++++++-------- 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 9a5a3641d0..3e35357182 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3228,6 +3228,10 @@ # @lazy-refcounts: whether to enable the lazy refcounts # feature (default is taken from the image file) # +# @keep-dirty: whether to not touch dirty bit. When set, QEMU doesn't +# check refcounts on qcow2 open (ignoring dirty bit) and does= n't +# clear dirty bit on qcow2 close. (since 7.0) +# # @pass-discard-request: whether discard requests to the qcow2 # device should be forwarded to the data source # @@ -3276,6 +3280,7 @@ { 'struct': 'BlockdevOptionsQcow2', 'base': 'BlockdevOptionsGenericCOWFormat', 'data': { '*lazy-refcounts': 'bool', + '*keep-dirty': 'bool', '*pass-discard-request': 'bool', '*pass-discard-snapshot': 'bool', '*pass-discard-other': 'bool', diff --git a/block/qcow2.h b/block/qcow2.h index fd48a89d45..696e13377a 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -130,6 +130,7 @@ =20 #define QCOW2_OPT_DATA_FILE "data-file" #define QCOW2_OPT_LAZY_REFCOUNTS "lazy-refcounts" +#define QCOW2_OPT_KEEP_DIRTY "keep-dirty" #define QCOW2_OPT_DISCARD_REQUEST "pass-discard-request" #define QCOW2_OPT_DISCARD_SNAPSHOT "pass-discard-snapshot" #define QCOW2_OPT_DISCARD_OTHER "pass-discard-other" @@ -376,6 +377,7 @@ typedef struct BDRVQcow2State { int flags; int qcow_version; bool use_lazy_refcounts; + bool keep_dirty; int refcount_order; int refcount_bits; uint64_t refcount_max; diff --git a/block/qcow2.c b/block/qcow2.c index d509016756..1c42103fb9 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -514,15 +514,17 @@ int qcow2_mark_dirty(BlockDriverState *bs) return 0; /* already dirty */ } =20 - val =3D cpu_to_be64(s->incompatible_features | QCOW2_INCOMPAT_DIRTY); - ret =3D bdrv_pwrite(bs->file, offsetof(QCowHeader, incompatible_featur= es), - &val, sizeof(val)); - if (ret < 0) { - return ret; - } - ret =3D bdrv_flush(bs->file->bs); - if (ret < 0) { - return ret; + if (!s->keep_dirty) { + val =3D cpu_to_be64(s->incompatible_features | QCOW2_INCOMPAT_DIRT= Y); + ret =3D bdrv_pwrite(bs->file, offsetof(QCowHeader, incompatible_fe= atures), + &val, sizeof(val)); + if (ret < 0) { + return ret; + } + ret =3D bdrv_flush(bs->file->bs); + if (ret < 0) { + return ret; + } } =20 /* Only treat image as dirty if the header was updated successfully */ @@ -549,7 +551,13 @@ static int qcow2_mark_clean(BlockDriverState *bs) return ret; } =20 - return qcow2_update_header(bs); + if (!s->keep_dirty) { + /* + * No reason to update the header if we don't want to clear di= rty + * bit. + */ + return qcow2_update_header(bs); + } } return 0; } @@ -709,6 +717,11 @@ static QemuOptsList qcow2_runtime_opts =3D { .type =3D QEMU_OPT_BOOL, .help =3D "Postpone refcount updates", }, + { + .name =3D QCOW2_OPT_KEEP_DIRTY, + .type =3D QEMU_OPT_BOOL, + .help =3D "Keep dirty bit untouched", + }, { .name =3D QCOW2_OPT_DISCARD_REQUEST, .type =3D QEMU_OPT_BOOL, @@ -966,6 +979,7 @@ typedef struct Qcow2ReopenState { Qcow2Cache *refcount_block_cache; int l2_slice_size; /* Number of entries in a slice of the L2 table */ bool use_lazy_refcounts; + bool keep_dirty; int overlap_check; bool discard_passthrough[QCOW2_DISCARD_MAX]; uint64_t cache_clean_interval; @@ -1088,6 +1102,13 @@ static int qcow2_update_options_prepare(BlockDriverS= tate *bs, } } =20 + r->keep_dirty =3D qemu_opt_get_bool(opts, QCOW2_OPT_KEEP_DIRTY, false); + if (r->keep_dirty && !r->use_lazy_refcounts) { + error_setg(errp, "keep-dirty requires lazy refcounts"); + ret =3D -EINVAL; + goto fail; + } + /* Overlap check options */ opt_overlap_check =3D qemu_opt_get(opts, QCOW2_OPT_OVERLAP); opt_overlap_check_template =3D qemu_opt_get(opts, QCOW2_OPT_OVERLAP_TE= MPLATE); @@ -1214,6 +1235,7 @@ static void qcow2_update_options_commit(BlockDriverSt= ate *bs, =20 s->overlap_check =3D r->overlap_check; s->use_lazy_refcounts =3D r->use_lazy_refcounts; + s->keep_dirty =3D r->keep_dirty; =20 for (i =3D 0; i < QCOW2_DISCARD_MAX; i++) { s->discard_passthrough[i] =3D r->discard_passthrough[i]; @@ -1810,7 +1832,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverStat= e *bs, QDict *options, bs->supported_truncate_flags =3D BDRV_REQ_ZERO_WRITE; =20 /* Repair image if dirty */ - if (!(flags & BDRV_O_CHECK) && bdrv_is_writable(bs) && + if (!s->keep_dirty && !(flags & BDRV_O_CHECK) && bdrv_is_writable(bs) = && (s->incompatible_features & QCOW2_INCOMPAT_DIRTY)) { BdrvCheckResult result =3D {0}; =20 @@ -1825,6 +1847,20 @@ static int coroutine_fn qcow2_do_open(BlockDriverSta= te *bs, QDict *options, } } =20 + if (s->keep_dirty) { + if (!(s->incompatible_features & QCOW2_INCOMPAT_DIRTY)) { + error_setg(errp, "keep-dirty behaviour is requested but image " + "is not dirty"); + ret =3D -EINVAL; + goto fail; + } + /* + * User guarantees that refcounts are valid. So, consider them val= id, + * keeping dirty bit set in the header. + */ + s->incompatible_features &=3D ~QCOW2_INCOMPAT_DIRTY; + } + #ifdef DEBUG_ALLOC { BdrvCheckResult result =3D {0}; @@ -2826,6 +2862,7 @@ int qcow2_update_header(BlockDriverState *bs) uint32_t refcount_table_clusters; size_t header_length; Qcow2UnknownHeaderExtension *uext; + uint64_t incompatible_features; =20 buf =3D qemu_blockalign(bs, buflen); =20 @@ -2846,6 +2883,11 @@ int qcow2_update_header(BlockDriverState *bs) goto fail; } =20 + incompatible_features =3D s->incompatible_features; + if (s->keep_dirty) { + incompatible_features |=3D QCOW2_INCOMPAT_DIRTY; + } + *header =3D (QCowHeader) { /* Version 2 fields */ .magic =3D cpu_to_be32(QCOW_MAGIC), @@ -2863,7 +2905,7 @@ int qcow2_update_header(BlockDriverState *bs) .snapshots_offset =3D cpu_to_be64(s->snapshots_offset), =20 /* Version 3 fields */ - .incompatible_features =3D cpu_to_be64(s->incompatible_features), + .incompatible_features =3D cpu_to_be64(incompatible_features), .compatible_features =3D cpu_to_be64(s->compatible_features), .autoclear_features =3D cpu_to_be64(s->autoclear_features), .refcount_order =3D cpu_to_be32(s->refcount_order), --=20 2.31.1 From nobody Fri May 3 07:27:25 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1642715872; cv=pass; d=zohomail.com; s=zohoarc; b=gO4Li0UUulW0GaWlmLe1aVV9703F52vVbeexEQ9D5k/eAsy0nkKPRz2NA5ykpUWVGsLmYXPVZJ4u9I5gxZIHMDkFw5VEzugDGUaVh0Yt4D1ENs2gCx4VsUl9+yRBDBG2ml+yJ0+YbvLLOMujwQgkMwWcMj7273+RjNiF7u/jo8A= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642715872; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f4yFBWYA2eBiw8TMf4ht5LiCmJD4yEqKq27odNNN+k4=; b=AbA8AFjaJHl8XLQk1s1X14LMZ7ItYc6wSPjUSI+HzCR2d9mB3chKF8aTLMBO9oaqF5BRDNaqdOzjg0Q9zwvLBJ+ZBX5OB7mbyqLh0jj+F176tOgYhuxmobUJgvoqtZNdRInu1yLRxZ7YKKvpdq/sc0VDs/JqhXlcpEae5RVp+/o= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1642715872929263.6578910855857; Thu, 20 Jan 2022 13:57:52 -0800 (PST) Received: from localhost ([::1]:34670 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAfRH-0005XP-Bp for importer@patchew.org; Thu, 20 Jan 2022 16:57:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40378) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAaBf-0002iG-T8; Thu, 20 Jan 2022 11:21:25 -0500 Received: from mail-eopbgr50102.outbound.protection.outlook.com ([40.107.5.102]:22990 helo=EUR03-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAaBd-0005rq-8P; Thu, 20 Jan 2022 11:21:23 -0500 Received: from DB9PR08MB6748.eurprd08.prod.outlook.com (2603:10a6:10:2a7::16) by VE1PR08MB4942.eurprd08.prod.outlook.com (2603:10a6:803:10f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.12; Thu, 20 Jan 2022 16:21:03 +0000 Received: from DB9PR08MB6748.eurprd08.prod.outlook.com ([fe80::f043:6356:ee64:6cc6]) by DB9PR08MB6748.eurprd08.prod.outlook.com ([fe80::f043:6356:ee64:6cc6%6]) with mapi id 15.20.4888.013; Thu, 20 Jan 2022 16:21:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fJLQOELl0S46b1qJnbOwLDwpbT0HSRIdrLSMJG96DCxziDahhkXUlQANqt570d4wru8mtHszd27QZ1hZLliBZn82u+Tdx6XYGL/M8C31xKByzc9Wti/gRP682AS1ztCfobdCpDIx22ocMIxOCoKWNjOZwl96RExmcsBqZs9TIC6NUUdAkZDculy2sCRc5oKw7QWx4f8DfxfmMjIzQ862uqNBShfn2+DeQ6Pe4eFZkDBOGwb/2sRc3RXcNKo557AMOiBf1fezrl3LmhyLUfG31QAr2mahobjiL9P7OJmhg6ZvTvvPadohO2XvxvSGus+fll0mxQ9zxcadZVhwDA7PBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=f4yFBWYA2eBiw8TMf4ht5LiCmJD4yEqKq27odNNN+k4=; b=JHnpV4CNhMxM7MzvOromCaj0TJmNSBYma9p6tjVdtA72cneiLFFVwvJsDee0UfcGxGNUMD/sOl9kO3YFxqcvW13giahQ+lJg6aBwyiL+wzdIN/LgwiQMDSLOhEib0j5EbLz1GTsTaHEZ7qsSeJjFrlvgWJ37ba9r/5Rw1g9ND+RiLviYY9POMtllTbi/iZP0tWx4I1QXW4kZy1hd6ZFzksfgR0hoXvI6a3zqk8TVHFAwC/uj7tRM28oxapo03+gigIjrV8lp472mY8+/vWFDFe4zd/9Vw/PNFQrg4/W9oO+ZSY/dzjktNRr1oqVvw7bFSAVXAhZ/s0l7nwK7JAzX+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=f4yFBWYA2eBiw8TMf4ht5LiCmJD4yEqKq27odNNN+k4=; b=s1cong/xJZ+TqDh0I/tbWWhvaD1OSnTNez9CxK86dKiNipE+itk+UZ7KpfBfzCvtmBPbfcQ3+BWBI+3upP3pC6KVPtoPZkyEzERiJ0E7nkZ3b5zcXhfYu9y6UUlmBBiQvXF5bv1F8wD07p842NYt7jszzofBLgQu7yqeM7yJYzQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, ktkhai@virtuozzo.com, igor@virtuozzo.com Subject: [PATCH 2/2] iotests: add qcow2-keep-dirty Date: Thu, 20 Jan 2022 17:20:43 +0100 Message-Id: <20220120162043.2693196-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220120162043.2693196-1-vsementsov@virtuozzo.com> References: <20220120162043.2693196-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM6P193CA0118.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::23) To DB9PR08MB6748.eurprd08.prod.outlook.com (2603:10a6:10:2a7::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 03c24bb8-6c0f-49da-070f-08d9dc30da02 X-MS-TrafficTypeDiagnostic: VE1PR08MB4942:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2958; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VsxuNC0H8mzSuYayQ7QdOZzhyAsZviav5dQbYU6DKrdHJ4WQjmi4wEzkQS771McF/zsiBRUthAlFMoA9p1ShNolIkOVSQCOiVMfikEz3vLnhvFQSj3brDN7fXhIAcNz0wtO1I+NrSvD3h9mJ9N4JT5Yn+drZZDUhVZPmAhgva9IDsRfx4pxZg0eWuwkHJiaCeBCrL/93shp7i5DR4bmrhC2oqiZlSbD9ogr9yZR5kJERvhvGE9QD5OP5WzJQIZ/qSnVNwDOmuxHu5STzKEjXEQiSs3I86FSylQcBONkJy5vMFyvYL7kKuoPkJXW9Hyb1D2aVphPKzYZSZHtKzg+FAnP+pOXn7pMkNlKKnvvt3I3Fi4V5RVTHmlMY3VDRtHY1jahqKdLhEHMPusk9eTZoHmgt9QsnHGChHwD5NQNKMftawOJgIyylE5BRah+OIwDdc2sUnyElZXwoAcZw6LQL3YwCfnJUb9eTMnNLQWlYVn2oY36eoHe/FrAaQIVrR8KAGUnhuDyfTz3bXHMkYTlt4o7YpRSeVVDE6i4PdNsRHCJ0O/b6fHQW/yxawOMeaZ6bE9IJjI3DyV+O/V2kBjDVe5mnWVK13Ph75pdQNVnnIa8LvQeUkZY0jUw57epDB093++R8mr84oHPXHgtwUI3wbdnnhaz/xpMsn9zpVaXwI1xtMR0cn/bsvwGfcw7dR9ieNWNGNDaSpCZEhx4e3ZjzTw61H2nisrwIH3tLc9w2R8R9yI4TOe/NTC690N08SJ4F8FCtcoc/QmdMXpd+5mhfVK7a/mw9jwxjm4hjllesxM4gcqRqqAUV4fEmiAWLrIXdJitKzVQEBeCwVPtYOgDSHw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR08MB6748.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(2616005)(38100700002)(508600001)(8936002)(6506007)(1076003)(5660300002)(86362001)(6666004)(83380400001)(26005)(66946007)(2906002)(186003)(66476007)(66556008)(107886003)(6512007)(8676002)(38350700002)(4326008)(6916009)(52116002)(36756003)(6486002)(316002)(2004002)(14143004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?WSe53JzVG0coDsCJe/i5i8XMtE0ITiN7Mkkb+SnED14TInOkJ+Aix3hbrFjt?= =?us-ascii?Q?kPA06Yr1NloaQve2IABB435WyAL+zHYlpsFQJhSX9TFPltCn/6oE35N+hHza?= =?us-ascii?Q?JB8OAo6kzJd0jj+s7EK/XfW3WiXNt6x/LnLUhBuy5NeYP538hpT/iZB7iPI0?= =?us-ascii?Q?RGuH9zaZHId/Shu9GqX1IaYUyLn7X2m4LJqgNt+Y04AzCqGDErYSje3Y5EbW?= =?us-ascii?Q?gDk1nPDo4eUrEYcNuRUYKdD9CBaZc2OGBMRMN4Bok2glQy5Uy/NtvtX6mjop?= =?us-ascii?Q?HMfFb3bdtYnVHfU1rmlSrcZVaJ0AvipXIJAO/d5hTmNhhfzajxD0Hutmie4Q?= =?us-ascii?Q?+HGxiOVIwSaroDq454+vPijjbTz7N48LrXSWbGwIkY+3rU2EwjvNaOjp9aa8?= =?us-ascii?Q?cg/hw42ujTdohHCeIW5Fb/b+Ufx+WJRS6gplxfcYsSbodljD/XAjEVtkxrGg?= =?us-ascii?Q?oTKOnZf6cu9xhdhkX1Tv1ELblZxiPPiXDdnss3vNR2BRGt2F8CE4B8ybd+k9?= =?us-ascii?Q?Mgw7st3i6ODRFcy6lMEgC09R8FwttVi0P5QPriQcwdxlB2WA9mmcUFiN/CAE?= =?us-ascii?Q?B7mfe8oB2Q008YIq2mPj+Sk43FUbKEes9kQHIcIezNYQ9+wnFpfaGAeZ8nBv?= =?us-ascii?Q?iUIsWIgdeN5kYPvS7Ldr2qXu9UBv6G2VWMzBlcKPYXUFks4K4BV4VsZv4dF/?= =?us-ascii?Q?gTktazJIHmxFQS7zQZKEH5voBahgX+x7/jtUDLBEaNSxMoOAaW5Ja4pXdGO6?= =?us-ascii?Q?rii2lBP78JNVVksHD8OKusJGzePVyQWJL4ib/w39o1G8y5g0r4XqhqmksVVk?= =?us-ascii?Q?zREf5BdrokMIAzKz4kAXdb+lUMhTFLOj+qOxgeQO7Q+mhgw+kjFLPiepavTD?= =?us-ascii?Q?ZhXCteN1JfCF+F3mxrJuInfvCWpvtg8wYmJTt8uZwUjU4+my6i3hvkpuXjWB?= =?us-ascii?Q?4aY1aHepMzE9n2E7DgaWJds/XbbQurKLHrV9QWo77GqlZH4tfZkmqcVAkQqi?= =?us-ascii?Q?rhqrliC47JjJ7ypu5U0ovm3FDJ+49FDI6ylenJcdDVgQ40TpvLUrj0hlJTgD?= =?us-ascii?Q?FaemlYcCiHVttFS4HZpM/eXKcIwjA+QjRlu/Cz6B50EAl45juAy9/LUQYrvv?= =?us-ascii?Q?4ymAdeVDNLsseFm6HB+b6Z7Ck+gpzTXQF2zsbxxBKA5/86itdZ4l3Xnnoxaa?= =?us-ascii?Q?FJ5zn+uQi/QT1G6kYVKuhmC29U21aBB+qXpcOGYlgbi6Qk+WEKR/VOX5BLQN?= =?us-ascii?Q?Lbpyr36nXR8QJmq7r8OgtyTeA0019+w8QjUNsKG9z5qaPXUt+FOu9wrBB5OC?= =?us-ascii?Q?a8OflnMdymPespD3Hnnb1hv4vcwNBEtKwUI9SrHJjnl6awfyjm5x7HgOzqF8?= =?us-ascii?Q?D6SYVNdA8ISPvVQrqySwr/fEyaeEiO9ubbBMCvOIUMQ2T/QhHTuqC3V8KRFJ?= =?us-ascii?Q?e9KY5pc7gpeOelunO6s5RAF7ibcmSZofwxJ4uS03eDe9Wzato3akhxnI4JWA?= =?us-ascii?Q?1YWuS0o7RYzwYmKDujn27Nvf5ZTuI8IY4O9Ba/4eDV1A/wXhOXX2Zmq/vZFk?= =?us-ascii?Q?jc7va/SDe+rdWtixB5s+Phu4BAg1Ie+Gbgtiz/eggsFiVUVOgciqfeoF6GZO?= =?us-ascii?Q?8ZM9IIsX3ygfeIGUXQ2muyLAYVlZBJVHeLvjEYsGKrDjP2XuB9cBu71lb6Ps?= =?us-ascii?Q?RQLlmLXG+uXGooZE2ExBjC6qrGQ=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 03c24bb8-6c0f-49da-070f-08d9dc30da02 X-MS-Exchange-CrossTenant-AuthSource: DB9PR08MB6748.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2022 16:21:03.2182 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XZQq30AJEQo7uteAUgr8WR53HiojCj5b15DSH14/v/LT3H4fDJR+fT1BUqrSOi/xpydX6FUc6qJJscYNvHfRPik0lDKCmedS5OlmDt6TMfw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB4942 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=40.107.5.102; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-VE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, 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_PASS=-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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1642715875501100001 Content-Type: text/plain; charset="utf-8" Test new qcow2 open option: keep-dirty. Signed-off-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/tests/qcow2-keep-dirty | 104 ++++++++++++++++++ tests/qemu-iotests/tests/qcow2-keep-dirty.out | 34 ++++++ 2 files changed, 138 insertions(+) create mode 100755 tests/qemu-iotests/tests/qcow2-keep-dirty create mode 100644 tests/qemu-iotests/tests/qcow2-keep-dirty.out diff --git a/tests/qemu-iotests/tests/qcow2-keep-dirty b/tests/qemu-iotests= /tests/qcow2-keep-dirty new file mode 100755 index 0000000000..101a82bd28 --- /dev/null +++ b/tests/qemu-iotests/tests/qcow2-keep-dirty @@ -0,0 +1,104 @@ +#!/usr/bin/env bash +# group: rw quick +# +# Test qcow2 keep-dirty option +# +# Copyright (c) 2022 Virtuozzo International GmbH. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dvsementsov@virtuozzo.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ../common.rc +. ../common.filter +. ../common.qemu + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux +# This test does not make much sense with external data files +_unsupported_imgopts data_file + +check_dirty_bit() { + $QEMU_IMG info --output=3Djson "$TEST_IMG" | grep 'dirty-flag' +} + +set_dirty_bit() { + echo Set dirty bit + $PYTHON ../qcow2.py "$TEST_IMG" set-feature-bit incompatible 0 + check_dirty_bit +} + +QEMU_IO_OPTIONS=3D$QEMU_IO_OPTIONS_NO_FMT + +keep_dirty_opts=3D"driver=3Dqcow2,keep-dirty=3Dtrue,file.filename=3D$TEST_= IMG" + +size=3D10M + +_make_test_img $size + +echo Check that keep-dirty not allowed without lazy refcounts +$QEMU_IO -c 'quit' --image-opts "$keep_dirty_opts" + +_make_test_img -o "lazy_refcounts=3Don" $size + +echo +echo Check that keep-dirty not allowed without dirty bit +$QEMU_IO -c 'quit' --image-opts "$keep_dirty_opts" + +echo +echo Check that usual access clears dirty bit +set_dirty_bit +$QEMU_IO -c 'quit' "$TEST_IMG" +check_dirty_bit + +echo +echo Check keep-dirty +set_dirty_bit +$QEMU_IO -c 'quit' --image-opts "$keep_dirty_opts" +check_dirty_bit + +echo +echo Check that usual qemu-img check clears dirty bit +set_dirty_bit +$QEMU_IMG check -r all "$TEST_IMG" +check_dirty_bit + +echo +echo Test qemu-img check with keep-dirty +set_dirty_bit +# also set corrupt bit +$PYTHON ../qcow2.py "$TEST_IMG" set-feature-bit incompatible 1 +$PYTHON ../qcow2.py "$TEST_IMG" dump-header | grep incompatible +$QEMU_IMG check -r all --image-opts "$keep_dirty_opts" +$PYTHON ../qcow2.py "$TEST_IMG" dump-header | grep incompatible + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/tests/qcow2-keep-dirty.out b/tests/qemu-iot= ests/tests/qcow2-keep-dirty.out new file mode 100644 index 0000000000..4d2bf40521 --- /dev/null +++ b/tests/qemu-iotests/tests/qcow2-keep-dirty.out @@ -0,0 +1,34 @@ +QA output created by qcow2-keep-dirty +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D10485760 +Check that keep-dirty not allowed without lazy refcounts +qemu-io: can't open: keep-dirty requires lazy refcounts +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D10485760 + +Check that keep-dirty not allowed without dirty bit +qemu-io: can't open: keep-dirty behaviour is requested but image is not di= rty + +Check that usual access clears dirty bit +Set dirty bit + "dirty-flag": true + "dirty-flag": false + +Check keep-dirty +Set dirty bit + "dirty-flag": true + "dirty-flag": true + +Check that usual qemu-img check clears dirty bit +Set dirty bit + "dirty-flag": true +No errors were found on the image. +Image end offset: 262144 + "dirty-flag": false + +Test qemu-img check with keep-dirty +Set dirty bit + "dirty-flag": true +incompatible_features [0, 1] +No errors were found on the image. +Image end offset: 262144 +incompatible_features [0] +*** done --=20 2.31.1