From nobody Mon May 6 02:50:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=163.com ARC-Seal: i=1; a=rsa-sha256; t=1676974924; cv=none; d=zohomail.com; s=zohoarc; b=dPwJ8AgvCbCC6gthqlbh6SuJ37XTNOn2rPJ34MESYsKjuFbjCLM0yCcykNYELienckOhYJ5fluTnUhIpCzatHczOC/Fak7JiCbqFsytqzANdsGaYwov0QyT2mrH+zmg7SzhU0Zr58W5xT/bII8IrpI6FowgNZq6fktCjVslFHBI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676974924; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=3/ChhGXenaeVLAj30jmiwaO95THG5ANW3DaSSd73xR4=; b=POX911ZsWaSpxDtBxCJ8EE+D0OWxqLZR6tU8kOk62PLiEl74IRI7uiFF7655Fi/9HBLdzecJL3lcu7CUMYWBoeQ+O+lNDFr0WdmjIJKwmPyjlvOIQlxQUl1+WWlz1F9oOlGiSFTgP1AEq5adO75a4y/IcDchqzAFU49tzgieOBM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1676974924967859.4150335873871; Tue, 21 Feb 2023 02:22:04 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-263--1BGyCg5Px2B7GIfhkIdkA-1; Tue, 21 Feb 2023 05:22:01 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F2C7E1C04192; Tue, 21 Feb 2023 10:21:58 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DFE04015308; Tue, 21 Feb 2023 10:21:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id ED2B41946588; Tue, 21 Feb 2023 10:21:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 27A7D194658C for ; Tue, 21 Feb 2023 10:21:46 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id C9BB8492B04; Tue, 21 Feb 2023 10:21:46 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast09.extmail.prod.ext.rdu2.redhat.com [10.11.55.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BDFE7492C3C for ; Tue, 21 Feb 2023 10:21:46 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 89D0A29DD98B for ; Tue, 21 Feb 2023 10:21:46 +0000 (UTC) Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.199]) by relay.mimecast.com with ESMTP id us-mta-76-Zv9NBsc_P7-bSn-wk1bVew-1; Tue, 21 Feb 2023 05:21:44 -0500 Received: from localhost.localdomain (unknown [113.128.80.191]) by zwqz-smtp-mta-g4-3 (Coremail) with SMTP id _____wAHpWErm_RjKxWCAg--.56909S2; Tue, 21 Feb 2023 18:21:41 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676974924; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:content-type:content-type:list-id: list-help:list-unsubscribe:list-subscribe:list-post; bh=3/ChhGXenaeVLAj30jmiwaO95THG5ANW3DaSSd73xR4=; b=SVXoBUBQrCpYu+n9zqa1qenZSnSf9izCjAyxZuRZdh2WnfoiLPIjHYragBjVpQPK0dj18R Xgki79UwmBOjJ9xc2PW9uwh5q10urK6L4dT8eCO2EJslHRXq8+L1FpBl9nAnNgpoWwrzRn ndv8BCGC6BaV+i1iZDNNsImNBQqK8nY= X-MC-Unique: -1BGyCg5Px2B7GIfhkIdkA-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: Zv9NBsc_P7-bSn-wk1bVew-1 From: jshen28 To: libvirt-list@redhat.com Subject: [v2 PATCH] QEMU: allow update more disk properties Date: Tue, 21 Feb 2023 18:21:29 +0800 Message-Id: <20230221102129.14830-1-yshxxsjt715@163.com> X-CM-TRANSID: _____wAHpWErm_RjKxWCAg--.56909S2 X-Coremail-Antispam: 1Uf129KBjvJXoW3JryrAF13Xw1DAF1ruFyUZFb_yoW3JrW5pF W3Jas8Ary8urWxZFs3GF47ZF1rW348Jr48taySgw1FqrW3WF4DWrnIvryrX3Z7JrZxJry3 urW3JFZI9ws7taDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jcF4NUUUUU= X-Originating-IP: [113.128.80.191] X-CM-SenderInfo: h1vk555vmwliqv6rljoofrz/1tbiLhUdL2I0iB7OtwAAsw X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ushen Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676974925830100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8"; x-default="true" From: ushen QEMU has provided QMP blockdev-reopen to allow reconfigure some driver properties while virtual machine is running. Such properties are including cachmode, detect-zeroes and discard. This PS modifies update-device a little bit to allow updating those properties. Some cachemode types could be switched from using blockdev-reopen without affect frontend device prameters. This PS will compare the writeback flag between new and origin domain disk object and continue blockdev reopen if writeback flag is the same. Signed-off-by: shenjiatong --- src/qemu/qemu_block.c | 69 ++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_block.h | 9 ++++++ src/qemu/qemu_domain.c | 30 ++++++++++++++++-- src/qemu/qemu_driver.c | 41 +++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 5e700eff99..3c45d8d7c7 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -2970,6 +2970,38 @@ qemuBlockReopenFormatMon(qemuMonitor *mon, return 0; } =20 +int +qemuBlockReopenMon(qemuMonitor *mon, + virStorageSource *src) +{ + g_autoptr(virJSONValue) reopenprops =3D NULL; + g_autoptr(virJSONValue) srcprops =3D NULL; + g_autoptr(virJSONValue) srcstorprops =3D NULL; + g_autoptr(virJSONValue) reopenoptions =3D virJSONValueNewArray(); + + if (!(srcprops =3D qemuBlockStorageSourceGetBlockdevProps(src, src->ba= ckingStore))) + return -1; + + if (!(srcstorprops =3D qemuBlockStorageSourceGetBackendProps(src, 0))) + return -1; + + if (virJSONValueArrayAppend(reopenoptions, &srcprops) < 0) + return -1; + + if (virJSONValueArrayAppend(reopenoptions, &srcstorprops) < 0) + return -1; + + if (virJSONValueObjectAdd(&reopenprops, + "a:options", &reopenoptions, + NULL) < 0) + return -1; + + if (qemuMonitorBlockdevReopen(mon, &reopenprops) < 0) + return -1; + + return 0; +} + =20 /** * qemuBlockReopenFormat: @@ -3010,6 +3042,43 @@ qemuBlockReopenFormat(virDomainObj *vm, } =20 =20 +/** + * qemuBlockReopen: + * @vm: domain object + * @src: storage source to reopen + * @asyncJob: qemu async job type + * + * Same as qemuBlockReopenFormat, but both reopens storage and format node + */ +int +qemuBlockReopen(virDomainObj *vm, + virStorageSource *src, + virDomainAsyncJob asyncJob) +{ + qemuDomainObjPrivate *priv =3D vm->privateData; + int rc; + + /* If we are lacking the object here, qemu might have opened an image = with + * a node name unknown to us */ + if (!src->backingStore) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("can't reopen image with unknown presence of back= ing store")); + return -1; + } + + if (qemuDomainObjEnterMonitorAsync(vm, asyncJob) < 0) + return -1; + + rc =3D qemuBlockReopenMon(priv->mon, src); + + qemuDomainObjExitMonitor(vm); + if (rc < 0) + return -1; + + return 0; +} + + /** * qemuBlockReopenReadWrite: * @vm: domain object diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index 5a61a19da2..28f9b6cc61 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -245,6 +245,15 @@ int qemuBlockReopenFormatMon(qemuMonitor *mon, virStorageSource *src); =20 + +int +qemuBlockReopenMon(qemuMonitor *mon, virStorageSource *src); + +int +qemuBlockReopen(virDomainObj *vm, + virStorageSource *src, + virDomainAsyncJob asyncJob); + int qemuBlockReopenReadWrite(virDomainObj *vm, virStorageSource *src, diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e9bc0f375d..d5d768c9b2 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8129,6 +8129,28 @@ qemuDomainStorageSourceAccessAllow(virQEMUDriver *dr= iver, } =20 =20 +static bool +qemuCacheModeChangeSupported(virDomainDiskDef *disk, + virDomainDiskDef *orig_disk) +{ + bool new_wt, orig_wt; + + if (qemuDomainDiskCachemodeFlags(disk->cachemode, &new_wt, NULL, NULL)= < 0) { + return false; + } + + if (qemuDomainDiskCachemodeFlags(orig_disk->cachemode, &orig_wt, NULL,= NULL) < 0) { + return false; + } + + if (new_wt !=3D orig_wt) { + return false; + } + + return true; +} + + /* * Makes sure the @disk differs from @orig_disk only by the source * path and nothing else. Fields that are being checked and the @@ -8239,7 +8261,12 @@ qemuDomainDiskChangeSupported(virDomainDiskDef *disk, CHECK_STREQ_NULLABLE(product, "product"); =20 - CHECK_EQ(cachemode, "cache", true); + if (!qemuCacheModeChangeSupported(disk, orig_disk)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("cannot modify field '%s' of the disk"), + "cachemode"); + return false; + } CHECK_EQ(error_policy, "error_policy", true); CHECK_EQ(rerror_policy, "rerror_policy", true); CHECK_EQ(iomode, "io", true); @@ -8267,7 +8294,6 @@ qemuDomainDiskChangeSupported(virDomainDiskDef *disk, CHECK_EQ(info.bootIndex, "boot order", true); CHECK_EQ(rawio, "rawio", true); CHECK_EQ(sgio, "sgio", true); - CHECK_EQ(discard, "discard", true); CHECK_EQ(iothread, "iothread", true); =20 CHECK_STREQ_NULLABLE(domain_name, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6154fe9bfe..10c76a3af6 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6802,6 +6802,8 @@ qemuDomainChangeDiskLive(virDomainObj *vm, virDomainDiskDef *orig_disk =3D NULL; virDomainStartupPolicy origStartupPolicy; virDomainDeviceDef oldDev =3D { .type =3D dev->type }; + virStorageSource *n =3D NULL; + int ret, detect_zeroes, discard, cachemode; =20 if (!(orig_disk =3D virDomainDiskByTarget(vm->def, disk->dst))) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -6840,8 +6842,47 @@ qemuDomainChangeDiskLive(virDomainObj *vm, } =20 dev->data.disk->src =3D NULL; + } else { + + // reopen disk device with more parameters + detect_zeroes =3D orig_disk->detect_zeroes; + discard =3D orig_disk->discard; + cachemode =3D orig_disk->cachemode; + + if (detect_zeroes =3D=3D disk->detect_zeroes && + discard =3D=3D disk->discard && + discard =3D=3D disk->cachemode) { + goto out; + } + + orig_disk->detect_zeroes =3D disk->detect_zeroes; + orig_disk->discard =3D disk->discard; + orig_disk->cachemode =3D disk->cachemode; + + for (n =3D orig_disk->src; virStorageSourceIsBacking(n); n =3D n->= backingStore) { + if (n =3D=3D orig_disk->src && detect_zeroes !=3D disk->detect= _zeroes) { + n->detect_zeroes =3D disk->detect_zeroes; + } + n->discard =3D disk->discard; + n->cachemode =3D disk->cachemode; + ret =3D qemuBlockReopen(vm, n, VIR_ASYNC_JOB_NONE); + if (ret < 0) { + if (n =3D=3D orig_disk->src) { + orig_disk->detect_zeroes =3D detect_zeroes; + orig_disk->src->detect_zeroes =3D detect_zeroes; + orig_disk->discard =3D discard; + orig_disk->src->discard =3D discard; + orig_disk->cachemode =3D cachemode; + orig_disk->src->cachemode =3D cachemode; + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("failed to blockreopen disk")); + return -1; + } + } + } } =20 + out: /* in case when we aren't updating disk source we update startup polic= y here */ orig_disk->startupPolicy =3D dev->data.disk->startupPolicy; orig_disk->snapshot =3D dev->data.disk->snapshot; --=20 2.17.1