From nobody Sat Feb 7 04:40:33 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=quarantine) header.from=huawei.com ARC-Seal: i=1; a=rsa-sha256; t=1671891716; cv=none; d=zohomail.com; s=zohoarc; b=B8lIaDzHmuvrpS71Fa1NeI9WEepXQZUvFLlcx4pb4ZDYnZSanhhT/ZsNDCyJZILj6WZny4ms9fTiPSG1nsk9gW8GZFYfuqANWAfVRMyPxoj3CCau8048xIdvoIKRpFK9YgqHpiqwpCdHAoqWFtPqqexgzMqujnFu1XfaBCX85uo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671891716; 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=P5k6AVbISdtlOAyEu03YcmXYHwr6HsdmdZxQaZU2Bak=; b=nxca+WDXYwL4UjgN4AJGLE/CzSkUgCdh7ruxCdd6Bha4U1lbnkJ5dDFaMIxXMT6fGO6ANrbEMOJagTWPAeUTWyvK6IgtikmUcZtp3RLVgNZbBFTRSBKDViYTrlv0VrY0OOuGVVywT1ZaVLUTLrhD5HoKA5jriO2qqK51A9gDp4k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=quarantine dis=quarantine) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1671891716501160.1919367536981; Sat, 24 Dec 2022 06:21:56 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-308-bqgwEaw1OUO-ds-W2R1X-g-1; Sat, 24 Dec 2022 09:21:51 -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 9FB5D8F6E8D; Sat, 24 Dec 2022 14:21:48 +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 6042240ED76E; Sat, 24 Dec 2022 14:21:47 +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 CFDE71946A73; Sat, 24 Dec 2022 14:21:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D702F19465B1 for ; Sat, 24 Dec 2022 14:21:43 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 97D972026D68; Sat, 24 Dec 2022 14:21:43 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 904392026D4B for ; Sat, 24 Dec 2022 14:21:43 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (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 704E0185A78B for ; Sat, 24 Dec 2022 14:21:43 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-199-mgZK4BcCN82Gj2TDqKqMSw-1; Sat, 24 Dec 2022 09:21:41 -0500 Received: from dggpeml500022.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NfR6B6GQZzJqV3 for ; Sat, 24 Dec 2022 22:20:34 +0800 (CST) Received: from localhost.localdomain (10.175.124.27) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Sat, 24 Dec 2022 22:21:37 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671891715; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=P5k6AVbISdtlOAyEu03YcmXYHwr6HsdmdZxQaZU2Bak=; b=Om9sUwXx8fmdQ/33IC1y1NxxXXEAzsBwOuQrR1F/AB3YHhpbas2N0R3W+/CdWxRyJa4kE3 REp5L0j6DywmCKgyIRnrkiGeG8qlEMGtBQrwRZrVn/2fNeW5ZKI8K/toIb6xePFO2EIUtA hDp51B20aDqrfT/1J29j4GaPOnPu1ck= X-MC-Unique: bqgwEaw1OUO-ds-W2R1X-g-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: mgZK4BcCN82Gj2TDqKqMSw-1 From: Jiang Jiacheng To: Subject: [PATCH V3 1/7] qemu: Introduce qemuDomainChangeBootIndex to update device's bootindex Date: Sat, 24 Dec 2022 22:09:18 +0800 Message-ID: <20221224140924.581972-2-jiangjiacheng@huawei.com> In-Reply-To: <20221224140924.581972-1-jiangjiacheng@huawei.com> References: <20221224140924.581972-1-jiangjiacheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500022.china.huawei.com (7.185.36.66) X-CFilter-Loop: Reflected 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.4 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: yubihong@huawei.com, zhengchuan@huawei.com, linyilu@huawei.com, jiangjiacheng@huawei.com, xiexiangyou@huawei.com 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: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671891718983100001 Content-Type: text/plain; charset="utf-8" Introduce qemuDomainChangeBootIndex to support update device's bootindex. These function will be used in following patches to support change device's (support cdrom, disk and net) bootindex with virsh command like 'virsh update-device [--flag]'. Signed-off-by: Jiang Jiacheng --- src/qemu/qemu_conf.c | 41 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_conf.h | 5 +++++ src/qemu/qemu_monitor.c | 12 +++++++++++ src/qemu/qemu_monitor.h | 6 ++++++ src/qemu/qemu_monitor_json.c | 22 +++++++++++++++++++ src/qemu/qemu_monitor_json.h | 6 ++++++ 6 files changed, 92 insertions(+) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index ae5bbcd138..601357a7ee 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1641,3 +1641,44 @@ qemuHugepageMakeBasedir(virQEMUDriver *driver, =20 return 0; } + +/** + * qemuDomainChangeBootIndex: + * @vm: domain object + * @devInfo: origin device info + * @newBootIndex: new bootIndex + * + * Update the bootIndex of @devInfo with @newBootIndex. Only the devices + * whose bootIndexSpecified =3D true can be updated with @newBootIndex. + * BootIndex of 0 means cancel the bootindex setting of @devInfo. + * + */ +int +qemuDomainChangeBootIndex(virDomainObj *vm, + virDomainDeviceInfo *devInfo, + int newBootIndex) +{ + int ret =3D -1; + qemuDomainObjPrivate *priv =3D vm->privateData; + + if (!devInfo->alias) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("cannot change boot index: device alias not found= ")); + return -1; + } + + VIR_DEBUG("Change dev: %s boot index from %d to %d", devInfo->alias, + devInfo->bootIndex, newBootIndex); + + /* qemu dosen't support multiple bootIndex =3D 0 and need a negative b= ootIndex + * to delete the device from fw_boot_order. So transmit -1 to qemu whe= n setting + * bootIndex =3D 0 to cancel the bootIndex setting. */ + if (newBootIndex =3D=3D 0) + newBootIndex =3D -1; + + qemuDomainObjEnterMonitor(vm); + ret =3D qemuMonitorSetBootIndex(priv->mon, devInfo->alias, newBootInde= x); + qemuDomainObjExitMonitor(vm); + + return ret; +} diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 8cf2dd2ec5..e7447191df 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -375,3 +375,8 @@ int qemuGetMemoryBackingPath(virQEMUDriver *driver, =20 int qemuHugepageMakeBasedir(virQEMUDriver *driver, virHugeTLBFS *hugepage); + +int qemuDomainChangeBootIndex(virDomainObj *vm, + virDomainDeviceInfo *devInfo, + int newBootIndex) + ATTRIBUTE_NONNULL(2); diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 734364e070..7866347564 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4493,3 +4493,15 @@ qemuMonitorGetStatsByQOMPath(virJSONValue *arr, =20 return NULL; } + +int +qemuMonitorSetBootIndex(qemuMonitor *mon, + const char *alias, + int bootIndex) +{ + VIR_DEBUG("name=3D%s, bootIndex=3D%d", alias, bootIndex); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONSetBootIndex(mon, alias, bootIndex); +} diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 906a919f52..fab6f7bcbf 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1569,3 +1569,9 @@ qemuMonitorExtractQueryStats(virJSONValue *info); virJSONValue * qemuMonitorGetStatsByQOMPath(virJSONValue *arr, char *qom_path); + +int +qemuMonitorSetBootIndex(qemuMonitor *mon, + const char *alias, + int bootIndex) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 9822097bd7..39a84c8ae6 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -8859,3 +8859,25 @@ qemuMonitorJSONQueryStats(qemuMonitor *mon, =20 return virJSONValueObjectStealArray(reply, "return"); } + +int +qemuMonitorJSONSetBootIndex(qemuMonitor *mon, + const char *alias, + int bootIndex) +{ + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("qom-set", "s:path", alias, + "s:property", "bootindex", + "i:value", bootIndex, NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + return -1; + + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + return -1; + + return 0; +} diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 484cb09830..00c04e62d1 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -825,3 +825,9 @@ qemuMonitorJSONQueryStats(qemuMonitor *mon, qemuMonitorQueryStatsTargetType target, char **vcpus, GPtrArray *providers); + +int +qemuMonitorJSONSetBootIndex(qemuMonitor *mon, + const char *alias, + int bootIndex) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); --=20 2.33.0