conf: Format and parse backing chains in domain XML

This patch implements formating and parsing code for the backing store
schema defined and documented by the previous patch.

This patch does not aim at providing full persistent storage of disk
backing chains yet. The formatter is supposed to provide the backing
chain detected when starting a domain and thus it is not formatted into
an inactive domain XML. The parser is implemented mainly for the purpose
of testing the XML generated by the formatter and thus it does not
distinguish between no backingStore element and an empty backingStore
element. This will have to change once we fully implement support for
user-supplied backing chains.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Jiri Denemark 2014-04-17 15:22:32 +02:00
parent a2e369bc00
commit 546154e3d4
54 changed files with 211 additions and 0 deletions

View File

@ -5084,6 +5084,74 @@ virDomainDiskSourceParse(xmlNodePtr node,
}
static int
virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
virStorageSourcePtr src)
{
virStorageSourcePtr backingStore = NULL;
xmlNodePtr save_ctxt = ctxt->node;
xmlNodePtr source;
char *type = NULL;
char *format = NULL;
int ret = -1;
if (!(ctxt->node = virXPathNode("./backingStore[*]", ctxt))) {
ret = 0;
goto cleanup;
}
if (VIR_ALLOC(backingStore) < 0)
goto cleanup;
if (!(type = virXMLPropString(ctxt->node, "type"))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing disk backing store type"));
goto cleanup;
}
backingStore->type = virStorageTypeFromString(type);
if (backingStore->type < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown disk backing store type '%s'"), type);
goto cleanup;
}
if (!(format = virXPathString("string(./format/@type)", ctxt))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing disk backing store format"));
goto cleanup;
}
backingStore->format = virStorageFileFormatTypeFromString(format);
if (backingStore->format < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown disk backing store format '%s'"), format);
goto cleanup;
}
if (!(source = virXPathNode("./source", ctxt))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing disk backing store source"));
goto cleanup;
}
if (virDomainDiskSourceParse(source, backingStore) < 0 ||
virDomainDiskBackingStoreParse(ctxt, backingStore) < 0)
goto cleanup;
src->backingStore = backingStore;
ret = 0;
cleanup:
if (ret < 0)
virStorageSourceFree(backingStore);
VIR_FREE(type);
VIR_FREE(format);
ctxt->node = save_ctxt;
return ret;
}
#define VENDOR_LEN 8
#define PRODUCT_LEN 16
@ -5842,6 +5910,9 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
&& virDomainDiskDefAssignAddress(xmlopt, def) < 0)
goto error;
if (virDomainDiskBackingStoreParse(ctxt, &def->src) < 0)
goto error;
cleanup:
VIR_FREE(bus);
VIR_FREE(type);
@ -14862,6 +14933,55 @@ virDomainDiskSourceFormat(virBufferPtr buf,
}
static int
virDomainDiskBackingStoreFormat(virBufferPtr buf,
virStorageSourcePtr backingStore,
const char *backingStoreRaw,
unsigned int index)
{
const char *type;
const char *format;
if (!backingStore) {
if (!backingStoreRaw)
virBufferAddLit(buf, "<backingStore/>\n");
return 0;
}
if (!backingStore->type ||
!(type = virStorageTypeToString(backingStore->type))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected disk backing store type %d"),
backingStore->type);
return -1;
}
if (backingStore->format <= 0 ||
!(format = virStorageFileFormatTypeToString(backingStore->format))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected disk backing store format %d"),
backingStore->format);
return -1;
}
virBufferAsprintf(buf, "<backingStore type='%s' index='%u'>\n",
type, index);
virBufferAdjustIndent(buf, 2);
virBufferAsprintf(buf, "<format type='%s'/>\n", format);
if (virDomainDiskSourceFormat(buf, backingStore, 0, 0) < 0 ||
virDomainDiskBackingStoreFormat(buf,
backingStore->backingStore,
backingStore->backingStoreRaw,
index + 1) < 0)
return -1;
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</backingStore>\n");
return 0;
}
static int
virDomainDiskDefFormat(virBufferPtr buf,
virDomainDiskDefPtr def,
@ -14988,6 +15108,14 @@ virDomainDiskDefFormat(virBufferPtr buf,
if (virDomainDiskSourceFormat(buf, &def->src, def->startupPolicy,
flags) < 0)
return -1;
/* Don't format backingStore to inactive XMLs until the code for
* persistent storage of backing chains is ready. */
if (!(flags & VIR_DOMAIN_XML_INACTIVE) &&
virDomainDiskBackingStoreFormat(buf, def->src.backingStore,
def->src.backingStoreRaw, 1) < 0)
return -1;
virDomainDiskGeometryDefFormat(buf, def);
virDomainDiskBlockIoDefFormat(buf, def);

View File

@ -16,23 +16,27 @@
<emulator>/usr/bin/qemu</emulator>
<disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest1'/>
<backingStore/>
<mirror file='/dev/HostVG/QEMUGuest1Copy' ready='yes'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='block' device='cdrom'>
<source dev='/dev/HostVG/QEMUGuest2'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='1' target='0' unit='0'/>
</disk>
<disk type='file' device='disk'>
<source file='/tmp/data.img'/>
<backingStore/>
<mirror file='/tmp/copy.img' format='qcow2'/>
<target dev='vda' bus='virtio'/>
</disk>
<disk type='file' device='disk'>
<source file='/tmp/logs.img'/>
<backingStore/>
<target dev='vdb' bus='virtio'/>
</disk>
<controller type='usb' index='0'/>

View File

@ -18,6 +18,7 @@
<source dev='/dev/HostVG/QEMUGuest1'>
<seclabel model='selinux' labelskip='yes'/>
</source>
<backingStore/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>

View File

@ -17,6 +17,7 @@
<disk type='block' device='disk'>
<driver name='phy'/>
<source dev='/dev/MainVG/GuestVG'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<console type='pty'>

View File

@ -18,6 +18,7 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/some.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<interface type='bridge'>

View File

@ -19,6 +19,7 @@
<disk type='file' device='disk'>
<driver name='tap' type='raw'/>
<source file='/xen/rhel5.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<interface type='bridge'>

View File

@ -16,6 +16,7 @@
<disk type='file' device='disk'>
<driver name='tap' type='raw'/>
<source file='/var/lib/xen/images/rhel5pv.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
<shareable/>
</disk>

View File

@ -18,6 +18,7 @@
<disk type='block' device='disk'>
<driver name='phy'/>
<source dev='/dev/MainVG/GuestVG'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<console type='pty'>

View File

@ -18,6 +18,7 @@
<disk type='file' device='disk'>
<driver name='tap' type='qcow'/>
<source file='/root/some.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<console type='pty'>

View File

@ -18,6 +18,7 @@
<disk type='file' device='disk'>
<driver name='tap' type='raw'/>
<source file='/root/some.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<console type='pty'>

View File

@ -18,6 +18,7 @@
<disk type='file' device='disk'>
<driver name='tap2' type='raw'/>
<source file='/root/some.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<console type='pty'>

View File

@ -18,6 +18,7 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/some.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<console type='pty'>

View File

@ -21,11 +21,13 @@
<disk type='block' device='disk'>
<driver name='phy'/>
<source dev='/iscsi/winxp'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/net/heaped/export/netimage/windows/xp-sp2-vol.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -23,11 +23,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -23,11 +23,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -19,6 +19,7 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/some.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<serial type='pty'>

View File

@ -26,6 +26,7 @@
<disk type='block' device='disk'>
<driver name='phy'/>
<source dev='/dev/zvol/dsk/export/s10u4-root'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<input type='mouse' bus='ps2'/>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -21,11 +21,13 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/foo.img'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='file'/>
<source file='/root/boot.iso'/>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -18,6 +18,7 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/some.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<interface type='bridge'>

View File

@ -18,6 +18,7 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/some.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<interface type='bridge'>

View File

@ -18,6 +18,7 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/some.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<interface type='ethernet'>

View File

@ -23,9 +23,11 @@
<disk type='block' device='disk'>
<driver name='phy'/>
<source dev='/dev/sda8'/>
<backingStore/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<backingStore/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

View File

@ -18,6 +18,7 @@
<disk type='block' device='disk'>
<driver name='phy'/>
<source dev='/dev/MainVG/GuestVG'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<console type='pty'>

View File

@ -18,6 +18,7 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/some.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<console type='pty'>

View File

@ -17,6 +17,7 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/some.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<console type='pty'>

View File

@ -18,6 +18,7 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/some.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<console type='pty'>

View File

@ -18,6 +18,7 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/some.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<console type='pty'>

View File

@ -18,6 +18,7 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/some.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<console type='pty'>

View File

@ -18,6 +18,7 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/some.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<console type='pty'>

View File

@ -18,6 +18,7 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/some.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<console type='pty'>

View File

@ -17,6 +17,7 @@
<disk type='block' device='disk'>
<driver name='phy'/>
<source dev='/dev/vg_dom0test/test2vm'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<interface type='bridge'>

View File

@ -18,6 +18,7 @@
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/some.img'/>
<backingStore/>
<target dev='xvda' bus='xen'/>
</disk>
<console type='pty'>