<driver name="qemu" type="raw"/>
<source protocol="rbd" name="image_name2">
<host name="hostname" port="7000"/>
+ <snapshot name="snapname"/>
</source>
<target dev="hdc" bus="ide"/>
<auth username='myuser'>
is only valid when the specified storage volume is of 'file' or
'block' type).
<p>
- When the disk <code>type</code> is "network", the <code>source</code>
- may have zero or more <code>host</code> sub-elements used to
- specify the hosts to connect.
+ The <code>source</code> element may contain the following sub elements:
</p>
<dl>
<dt><code>host</code></dt>
<dd>
<p>
+ When the disk <code>type</code> is "network", the <code>source</code>
+ may have zero or more <code>host</code> sub-elements used to
+ specify the hosts to connect.
+
The <code>host</code> element supports 4 attributes, viz. "name",
"port", "transport" and "socket", which specify the hostname,
the port number, transport type and path to socket, respectively.
AF_UNIX socket.
</p>
</dd>
+ <dt><code>snapshot</code></dt>
+ <dd>
+ The <code>name</code> attribute of <code>snapshot</code> element can
+ optionally specify an internal snapshot name to be used as the
+ source for storage protocols.
+ Supported for 'rbd' <span class="since">since 1.2.11 (QEMU only).</span>
+ </dd>
</dl>
<p>
</choice>
</element>
</zeroOrMore>
+ <optional>
+ <element name="snapshot">
+ <attribute name="name">
+ <ref name="genericName"/>
+ </attribute>
+ <empty/>
+ </element>
+ </optional>
<empty/>
</element>
</interleave>
return -1;
}
+ /* verify disk source */
+ if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
+ virDomainDiskDefPtr disk = dev->data.disk;
+
+ /* internal snapshots are currently supported only with rbd: */
+ if (virStorageSourceGetActualType(disk->src) != VIR_STORAGE_TYPE_NETWORK &&
+ disk->src->protocol != VIR_STORAGE_NET_PROTOCOL_RBD) {
+ if (disk->src->snapshot) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("<snapshot> element is currently supported "
+ "only with 'rbd' disks"));
+ return -1;
+ }
+ }
+ }
+
return 0;
}
int
virDomainDiskSourceParse(xmlNodePtr node,
+ xmlXPathContextPtr ctxt,
virStorageSourcePtr src)
{
int ret = -1;
char *protocol = NULL;
+ xmlNodePtr saveNode = ctxt->node;
+
+ ctxt->node = node;
switch ((virStorageType)src->type) {
case VIR_STORAGE_TYPE_FILE:
tmp[0] = '\0';
}
+ /* snapshot currently works only for remote disks */
+ src->snapshot = virXPathString("string(./snapshot/@name)", ctxt);
+
if (virDomainStorageHostParse(node, &src->hosts, &src->nhosts) < 0)
goto cleanup;
break;
cleanup:
VIR_FREE(protocol);
+ ctxt->node = saveNode;
return ret;
}
goto cleanup;
}
- if (virDomainDiskSourceParse(source, backingStore) < 0 ||
+ if (virDomainDiskSourceParse(source, ctxt, backingStore) < 0 ||
virDomainDiskBackingStoreParse(ctxt, backingStore) < 0)
goto cleanup;
xmlStrEqual(cur->name, BAD_CAST "source")) {
sourceNode = cur;
- if (virDomainDiskSourceParse(cur, def->src) < 0)
+ if (virDomainDiskSourceParse(cur, ctxt, def->src) < 0)
goto error;
source = def->src->path;
_("mirror requires source element"));
goto error;
}
- if (virDomainDiskSourceParse(mirrorNode, def->mirror) < 0)
+ if (virDomainDiskSourceParse(mirrorNode, ctxt,
+ def->mirror) < 0)
goto error;
}
ready = virXMLPropString(cur, "ready");
VIR_FREE(path);
- if (src->nhosts == 0) {
+ if (src->nhosts == 0 && !src->snapshot) {
virBufferAddLit(buf, "/>\n");
} else {
virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 2);
+
for (n = 0; n < src->nhosts; n++) {
virBufferAddLit(buf, "<host");
virBufferEscapeString(buf, " name='%s'",
virBufferAddLit(buf, "/>\n");
}
+
+ virBufferEscapeString(buf, "<snapshot name='%s'/>\n",
+ src->snapshot);
+
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</source>\n");
}
virDomainDiskDefPtr
virDomainDiskRemoveByName(virDomainDefPtr def, const char *name);
int virDomainDiskSourceParse(xmlNodePtr node,
+ xmlXPathContextPtr ctxt,
virStorageSourcePtr src);
bool virDomainHasDiskMirror(virDomainObjPtr vm);
static int
virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
+ xmlXPathContextPtr ctxt,
virDomainSnapshotDiskDefPtr def)
{
int ret = -1;
if (!def->src->path &&
xmlStrEqual(cur->name, BAD_CAST "source")) {
- if (virDomainDiskSourceParse(cur, def->src) < 0)
+ if (virDomainDiskSourceParse(cur, ctxt, def->src) < 0)
goto cleanup;
} else if (!def->src->format &&
goto cleanup;
def->ndisks = n;
for (i = 0; i < def->ndisks; i++) {
- if (virDomainSnapshotDiskDefParseXML(nodes[i], &def->disks[i]) < 0)
+ if (virDomainSnapshotDiskDefParseXML(nodes[i], ctxt,
+ &def->disks[i]) < 0)
goto cleanup;
}
VIR_FREE(nodes);
virBufferStrcat(&buf, "rbd:", src->path, NULL);
+ if (src->snapshot)
+ virBufferEscape(&buf, '\\', ":", "@%s", src->snapshot);
+
if (username) {
virBufferEscape(&buf, '\\', ":", ":id=%s", username);
virBufferEscape(&buf, '\\', ":",
VIR_STRDUP(ret->driverName, src->driverName) < 0 ||
VIR_STRDUP(ret->relPath, src->relPath) < 0 ||
VIR_STRDUP(ret->backingStoreRaw, src->backingStoreRaw) < 0 ||
+ VIR_STRDUP(ret->snapshot, src->snapshot) < 0 ||
VIR_STRDUP(ret->compat, src->compat) < 0)
goto error;
*p = '\0';
}
+ /* snapshot name */
+ if ((p = strchr(src->path, '@'))) {
+ if (VIR_STRDUP(src->snapshot, p + 1) < 0)
+ goto error;
+ *p = '\0';
+ }
+
/* options */
if (!options)
return 0; /* all done */
char *path;
int protocol; /* virStorageNetProtocol */
char *volume; /* volume name for remote storage */
+ char *snapshot; /* for storage systems supporting internal snapshots */
size_t nhosts;
virStorageNetHostDefPtr hosts;
virStorageSourcePoolDefPtr srcpool;
-drive 'file=rbd:pool/image:auth_supported=none:\
mon_host=mon1.example.org\:6321\;mon2.example.org\:6322\;\
mon3.example.org\:6322,if=virtio,format=raw' \
+-drive file=rbd:pool/image@asdf:auth_supported=none,if=virtio,format=raw \
+-drive 'file=rbd:pool/image@foo:auth_supported=none:\
+mon_host=mon1.example.org\:6321\;mon2.example.org\:6322\;\
+mon3.example.org\:6322,if=virtio,format=raw' \
-net none -serial none -parallel none
</source>
<target dev='vda' bus='virtio'/>
</disk>
+ <disk type='network' device='disk'>
+ <driver name='qemu' type='raw'/>
+ <source protocol='rbd' name='pool/image'>
+ <snapshot name='asdf'/>
+ </source>
+ <target dev='vdb' bus='virtio'/>
+ </disk>
+ <disk type='network' device='disk'>
+ <driver name='qemu' type='raw'/>
+ <source protocol='rbd' name='pool/image'>
+ <host name='mon1.example.org' port='6321'/>
+ <host name='mon2.example.org' port='6322'/>
+ <host name='mon3.example.org' port='6322'/>
+ <snapshot name='foo'/>
+ </source>
+ <target dev='vdc' bus='virtio'/>
+ </disk>
<controller type='usb' index='0'/>
<controller type='ide' index='0'/>
<controller type='pci' index='0' model='pci-root'/>