From 43404fee3727e91dc8cd72abea123e0496e495f0 Mon Sep 17 00:00:00 2001 From: Osier Yang Date: Fri, 5 Apr 2013 03:37:58 +0800 Subject: [PATCH] Support startupPolicy for 'volume' disk "startupPolicy" is only valid for file type storage volume, otherwise it fails on starting the domain. --- docs/formatdomain.html.in | 7 ++++--- docs/schemas/domaincommon.rng | 3 +++ src/conf/domain_conf.c | 9 +++++++-- src/qemu/qemu_command.c | 7 +++++++ tests/qemuxml2argvdata/qemuxml2argv-disk-source-pool.xml | 2 +- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index ae3d95a4c4..00a61be232 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -1467,11 +1467,12 @@ 0.7.5; type='network' since 0.8.7; protocol='iscsi' since 1.0.4; type='volume' since 1.0.5;
- For a "file" disk type which represents a cdrom or floppy + For a "file" or "volume" disk type which represents a cdrom or floppy (the device attribute), it is possible to define policy what to do with the disk if the source file is not accessible. - This is done by the startupPolicy attribute, accepting - these values: + (NB, startupPolicy is not valid for "volume" disk unless + the specified storage volume is of "file" type). This is done by the + startupPolicy attribute, accepting these values: diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 5ee3261bd9..39376f90df 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -1120,6 +1120,9 @@ + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8f0d872973..2d95200924 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4402,6 +4402,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, case VIR_DOMAIN_DISK_TYPE_VOLUME: if (virDomainDiskSourcePoolDefParse(cur, def) < 0) goto error; + startupPolicy = virXMLPropString(cur, "startupPolicy"); break; default: virReportError(VIR_ERR_INTERNAL_ERROR, @@ -13022,9 +13023,13 @@ virDomainDiskSourceDefFormat(virBufferPtr buf, /* Parsing guarantees the def->srcpool->volume cannot be NULL * if def->srcpool->pool is not NULL. */ - if (def->srcpool->pool) - virBufferAsprintf(buf, " \n", + if (def->srcpool) + virBufferAsprintf(buf, " srcpool->pool, def->srcpool->volume); + if (def->startupPolicy) + virBufferEscapeString(buf, " startupPolicy='%s'/>\n", startupPolicy); + else + virBufferAddLit(buf, "/>\n"); break; default: virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 8eb4054c9e..a98d21c60d 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2703,6 +2703,13 @@ qemuTranslateDiskSourcePool(virConnectPtr conn, if (virStorageVolGetInfo(vol, &info) < 0) goto cleanup; + if (def->startupPolicy && + info.type != VIR_STORAGE_VOL_FILE) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("'startupPolicy' is only valid for 'file' type volume")); + goto cleanup; + } + switch (info.type) { case VIR_STORAGE_VOL_FILE: case VIR_STORAGE_VOL_BLOCK: diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-source-pool.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-source-pool.xml index 876eebeee4..a218e78700 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-disk-source-pool.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-source-pool.xml @@ -15,7 +15,7 @@ /usr/bin/qemu - +
mandatory