From nobody Wed May 14 06:11:18 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525880354409622.454502706838; Wed, 9 May 2018 08:39:14 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C39BFC015C10; Wed, 9 May 2018 15:39:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 451F15DC1E; Wed, 9 May 2018 15:39:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 51972180BADB; Wed, 9 May 2018 15:39:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w49Fd9he010754 for ; Wed, 9 May 2018 11:39:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id A28A130012CD; Wed, 9 May 2018 15:39:09 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A0FC30001E0 for ; Wed, 9 May 2018 15:39:07 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ACD8C30C4F4B for ; Wed, 9 May 2018 15:39:06 +0000 (UTC) Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w49FYjvf136532 for ; Wed, 9 May 2018 11:39:06 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hv38ttffr-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 09 May 2018 11:39:06 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 9 May 2018 16:39:03 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 9 May 2018 16:39:01 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w49Fd0uq66519262 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 9 May 2018 15:39:00 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E8D90AE276 for ; Wed, 9 May 2018 15:46:34 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BDBECB75C8 for ; Wed, 9 May 2018 15:46:34 +0100 (BST) Received: from marc-ibm.boeblingen.de.ibm.com (unknown [9.152.224.71]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Wed, 9 May 2018 15:46:34 +0100 (BST) From: Marc Hartmayer To: Date: Wed, 9 May 2018 16:56:15 +0200 In-Reply-To: <20180509145622.23049-1-mhartmay@linux.vnet.ibm.com> References: <20180509145622.23049-1-mhartmay@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18050915-0040-0000-0000-00000457C348 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18050915-0041-0000-0000-000020FBCFE7 Message-Id: <20180509145622.23049-6-mhartmay@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-09_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805090146 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 09 May 2018 15:39:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 09 May 2018 15:39:06 +0000 (UTC) for IP:'148.163.156.1' DOMAIN:'mx0a-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'mhartmay@linux.vnet.ibm.com' RCPT:'' X-RedHat-Spam-Score: -0.7 (RCVD_IN_DNSWL_LOW) 148.163.156.1 mx0a-001b2d01.pphosted.com 148.163.156.1 mx0a-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/12] conf: Add functions to change the boot configuration of a domain X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 09 May 2018 15:39:13 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add functions for changing the boot configuration of a domain in preparation for upcoming patches. It's possible to change the used kernel, initrd, cmdline, and the used boot device. Signed-off-by: Marc Hartmayer Reviewed-by: Boris Fiuczynski --- src/conf/domain_conf.c | 226 +++++++++++++++++++++++++++++++++++++++++++= ++++ src/conf/domain_conf.h | 11 +++ src/libvirt_private.syms | 1 + 3 files changed, 238 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f678e26b28fd..326afa196cc6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28712,6 +28712,232 @@ virDomainObjSetMetadata(virDomainObjPtr vm, } =20 =20 +/** + * virDomainDefSetBootDevice: + * @def: domain definition + * @device: set the boot order priority of this device to highest, + * the domain must contain this device + * + * Set @device as the new boot device for @def + * + * Increment all boot indices that are set (bootindex > 0) except for + * @device and all those devices that have a bootindex greater than + * the old bootindex of @device if the index was set. Additionally, it + * disables the boot order defined in the 'os' XML node of a domain + * definition. + * + * E.g. a domain has the following devices + * diskA: boot order 1 + * diskB: boot order 2 + * hostdevA: boot order 3 + * If we now set diskB to the new boot device. It results in + * diskA: boot order 2 + * diskB: boot order 1 + * hostdevA: boot order 3 (note: the boot order value remains the same) + * + * Returns 0 in case of success, -1 in case of error + */ +static int +virDomainDefSetBootDevice(virDomainDefPtr def, + virDomainDeviceDefPtr device) +{ + size_t i; + unsigned int oldBootIndex =3D 0; + virDomainDeviceInfoPtr info; + bool noOldBootIndex; + + /* Set nBootDevs to 0 so the per-device boot configuration will be + * used. def->os.bootDevs does not have to be freed here. */ + def->os.nBootDevs =3D 0; + + switch ((virDomainDeviceType) device->type) { + case VIR_DOMAIN_DEVICE_DISK: + case VIR_DOMAIN_DEVICE_NET: + case VIR_DOMAIN_DEVICE_HOSTDEV: + case VIR_DOMAIN_DEVICE_REDIRDEV: + info =3D virDomainDeviceGetInfo(device); + if (!info) { + virReportError(VIR_ERR_OPERATION_FAILED, + "%s", + _("No device information found for the selected= device")); + return -1; + } + oldBootIndex =3D info->bootIndex; + info->bootIndex =3D 1; + break; + case VIR_DOMAIN_DEVICE_NONE: + case VIR_DOMAIN_DEVICE_LEASE: + case VIR_DOMAIN_DEVICE_FS: + case VIR_DOMAIN_DEVICE_INPUT: + case VIR_DOMAIN_DEVICE_SOUND: + case VIR_DOMAIN_DEVICE_VIDEO: + case VIR_DOMAIN_DEVICE_WATCHDOG: + case VIR_DOMAIN_DEVICE_CONTROLLER: + case VIR_DOMAIN_DEVICE_GRAPHICS: + case VIR_DOMAIN_DEVICE_HUB: + case VIR_DOMAIN_DEVICE_SMARTCARD: + case VIR_DOMAIN_DEVICE_CHR: + case VIR_DOMAIN_DEVICE_MEMBALLOON: + case VIR_DOMAIN_DEVICE_NVRAM: + case VIR_DOMAIN_DEVICE_RNG: + case VIR_DOMAIN_DEVICE_SHMEM: + case VIR_DOMAIN_DEVICE_TPM: + case VIR_DOMAIN_DEVICE_PANIC: + case VIR_DOMAIN_DEVICE_MEMORY: + case VIR_DOMAIN_DEVICE_IOMMU: + case VIR_DOMAIN_DEVICE_LAST: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("It's not supported to boot from the selected dev= ice type '%s'"), + virDomainDeviceTypeToString(device->type)); + return -1; + } + + noOldBootIndex =3D oldBootIndex =3D=3D 0; + + /* A precondition is that all the boot indexes must be numbered + consecutively or not defined. This is the case here. We must + change the boot index only of those devices that are affected + by the change of the old boot index. There are only two cases + were this is true: + + 1. Not the same device and it uses a boot index (> 0) and which + is less than the oldBootIndex + 2. Not the same device and it uses a boot index (> 0) and @device + used no boot index + */ + for (i =3D 0; i < def->ndisks; i++) { + if (device->type =3D=3D VIR_DOMAIN_DEVICE_DISK && + def->disks[i] =3D=3D device->data.disk) + continue; + + if (def->disks[i]->info.bootIndex > 0 && + (def->disks[i]->info.bootIndex < oldBootIndex || + noOldBootIndex)) + def->disks[i]->info.bootIndex++; + } + + for (i =3D 0; i < def->nnets; i++) { + if (device->type =3D=3D VIR_DOMAIN_DEVICE_NET && + def->nets[i] =3D=3D device->data.net) + continue; + + if (def->nets[i]->info.bootIndex > 0 && + (def->nets[i]->info.bootIndex < oldBootIndex || + noOldBootIndex)) + def->nets[i]->info.bootIndex++; + } + + for (i =3D 0; i < def->nhostdevs; i++) { + if (device->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV && + def->hostdevs[i] =3D=3D device->data.hostdev) + continue; + + if (def->hostdevs[i]->info->bootIndex > 0 && + (def->hostdevs[i]->info->bootIndex < oldBootIndex || + noOldBootIndex)) + def->hostdevs[i]->info->bootIndex++; + } + + for (i =3D 0; i < def->nredirdevs; i++) { + if (device->type =3D=3D VIR_DOMAIN_DEVICE_REDIRDEV && + def->redirdevs[i] =3D=3D device->data.redirdev) + continue; + + if (def->redirdevs[i]->info.bootIndex > 0 && + (def->redirdevs[i]->info.bootIndex < oldBootIndex || + noOldBootIndex)) + def->redirdevs[i]->info.bootIndex++; + } + + return 0; +} + + +/** + * virDomainDefSetBootDeviceByIdentifier: + * @def: Domain definition + * @bootDeviceIdentifier: Selector for the device. + * Currently only disk and network devices are supp= orted. + * + * Returns 0 in case of success, -1 in case of error. + */ +static int +virDomainDefSetBootDeviceByIdentifier(virDomainDefPtr def, + const char *bootDeviceIdentifier) +{ + virDomainDiskDefPtr diskDef =3D NULL; + virDomainNetDefPtr netDef =3D NULL; + virDomainDeviceDef bootDevice; + + if (!bootDeviceIdentifier) + return 0; + + /* Look for the correct device. At first try to find a disk with + * this device name, if not found try to find a network device + * with this device name. Disk devices are identified by 'os; + + if (!params) + return 0; + + if (params->bootDeviceIdentifier && + virDomainDefSetBootDeviceByIdentifier(def, params->bootDeviceIdent= ifier) < 0) + return -1; + + if (params->kernel && virStringUpdate(&os->kernel, params->kernel) < 0) + return -1; + + if (params->initrd && virStringUpdate(&os->initrd, params->initrd) < 0) + return -1; + + if (params->cmdline && virStringUpdate(&os->cmdline, params->cmdline) = < 0) + return -1; + + return 0; +} + + bool virDomainDefNeedsPlacementAdvice(virDomainDefPtr def) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 15d228ba9e62..87c14dc9b2e7 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3420,6 +3420,17 @@ int virDomainObjSetMetadata(virDomainObjPtr vm, const char *configDir, unsigned int flags); =20 +typedef struct { + const char *bootDeviceIdentifier; + const char *kernel; + const char *initrd; + const char *cmdline; +} virCreateParams; + +int +virDomainDefOverrideBootConf(virDomainDefPtr def, + const virCreateParams *params); + int virDomainParseMemory(const char *xpath, const char *units_xpath, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c684f21905af..d3e30beb87c0 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -285,6 +285,7 @@ virDomainDefMaybeAddInput; virDomainDefNeedsPlacementAdvice; virDomainDefNew; virDomainDefNewFull; +virDomainDefOverrideBootConf; virDomainDefParseFile; virDomainDefParseNode; virDomainDefParseString; --=20 2.13.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list