Support startupPolicy for 'volume' disk

"startupPolicy" is only valid for file type storage volume, otherwise
it fails on starting the domain.
This commit is contained in:
Osier Yang 2013-04-05 03:37:58 +08:00
parent db94a1d3a0
commit 43404fee37
5 changed files with 22 additions and 6 deletions

View File

@ -1467,11 +1467,12 @@
0.7.5; <code>type='network'</code> since 0.7.5; <code>type='network'</code> since
0.8.7; <code>protocol='iscsi'</code> since 1.0.4; 0.8.7; <code>protocol='iscsi'</code> since 1.0.4;
<code>type='volume'</code> since 1.0.5;</span><br/> <code>type='volume'</code> since 1.0.5;</span><br/>
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 <code>device</code> attribute), it is possible to define (the <code>device</code> attribute), it is possible to define
policy what to do with the disk if the source file is not accessible. policy what to do with the disk if the source file is not accessible.
This is done by the <code>startupPolicy</code> attribute, accepting (NB, <code>startupPolicy</code> is not valid for "volume" disk unless
these values: the specified storage volume is of "file" type). This is done by the
<code>startupPolicy</code> attribute, accepting these values:
<table class="top_table"> <table class="top_table">
<tr> <tr>
<td> mandatory </td> <td> mandatory </td>

View File

@ -1120,6 +1120,9 @@
<attribute name="volume"> <attribute name="volume">
<ref name="volName"/> <ref name="volName"/>
</attribute> </attribute>
<optional>
<ref name="startupPolicy"/>
</optional>
</element> </element>
</optional> </optional>
<ref name="diskspec"/> <ref name="diskspec"/>

View File

@ -4402,6 +4402,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
case VIR_DOMAIN_DISK_TYPE_VOLUME: case VIR_DOMAIN_DISK_TYPE_VOLUME:
if (virDomainDiskSourcePoolDefParse(cur, def) < 0) if (virDomainDiskSourcePoolDefParse(cur, def) < 0)
goto error; goto error;
startupPolicy = virXMLPropString(cur, "startupPolicy");
break; break;
default: default:
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
@ -13022,9 +13023,13 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
/* Parsing guarantees the def->srcpool->volume cannot be NULL /* Parsing guarantees the def->srcpool->volume cannot be NULL
* if def->srcpool->pool is not NULL. * if def->srcpool->pool is not NULL.
*/ */
if (def->srcpool->pool) if (def->srcpool)
virBufferAsprintf(buf, " <source pool='%s' volume='%s'/>\n", virBufferAsprintf(buf, " <source pool='%s' volume='%s'",
def->srcpool->pool, def->srcpool->volume); def->srcpool->pool, def->srcpool->volume);
if (def->startupPolicy)
virBufferEscapeString(buf, " startupPolicy='%s'/>\n", startupPolicy);
else
virBufferAddLit(buf, "/>\n");
break; break;
default: default:
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,

View File

@ -2703,6 +2703,13 @@ qemuTranslateDiskSourcePool(virConnectPtr conn,
if (virStorageVolGetInfo(vol, &info) < 0) if (virStorageVolGetInfo(vol, &info) < 0)
goto cleanup; 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) { switch (info.type) {
case VIR_STORAGE_VOL_FILE: case VIR_STORAGE_VOL_FILE:
case VIR_STORAGE_VOL_BLOCK: case VIR_STORAGE_VOL_BLOCK:

View File

@ -15,7 +15,7 @@
<devices> <devices>
<emulator>/usr/bin/qemu</emulator> <emulator>/usr/bin/qemu</emulator>
<disk type='volume' device='cdrom'> <disk type='volume' device='cdrom'>
<source pool='blk-pool0' volume='blk-pool0-vol0'/> <source pool='blk-pool0' volume='blk-pool0-vol0' startupPolicy='optional'/>
<target dev='hda' bus='ide'/> <target dev='hda' bus='ide'/>
<readonly/> <readonly/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/> <address type='drive' controller='0' bus='0' target='0' unit='1'/>