}
static int
-qemuParseGlusterString(virDomainDiskDefPtr def)
+qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
+ const char *scheme)
{
int ret = -1;
char *transp = NULL;
char *sock = NULL;
char *volimg = NULL;
- virURIPtr uri = NULL;
-
- if (!(uri = virURIParse(def->src))) {
- return -1;
- }
if (VIR_ALLOC(def->hosts) < 0)
goto no_memory;
- if (STREQ(uri->scheme, "gluster")) {
+ transp = strchr(uri->scheme, '+');
+ if (transp)
+ *transp++ = 0;
+
+ if (!STREQ(uri->scheme, scheme)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Invalid transport/scheme '%s'"), uri->scheme);
+ goto error;
+ }
+
+ if (!transp) {
def->hosts->transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP;
- } else if (STRPREFIX(uri->scheme, "gluster+")) {
- transp = strchr(uri->scheme, '+') + 1;
+ } else {
def->hosts->transport = virDomainDiskProtocolTransportTypeFromString(transp);
if (def->hosts->transport < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Invalid gluster transport type '%s'"), transp);
+ _("Invalid %s transport type '%s'"), scheme, transp);
goto error;
}
- } else {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Invalid transport/scheme '%s'"), uri->scheme);
- goto error;
}
def->nhosts = 0; /* set to 1 once everything succeeds */
}
}
}
- volimg = uri->path + 1; /* skip the prefix slash */
- VIR_FREE(def->src);
- def->src = strdup(volimg);
- if (!def->src)
- goto no_memory;
+ if (uri->path) {
+ volimg = uri->path + 1; /* skip the prefix slash */
+ VIR_FREE(def->src);
+ def->src = strdup(volimg);
+ if (!def->src)
+ goto no_memory;
+ } else {
+ VIR_FREE(def->src);
+ def->src = NULL;
+ }
def->nhosts = 1;
ret = 0;
goto cleanup;
}
+static int
+qemuParseGlusterString(virDomainDiskDefPtr def)
+{
+ virURIPtr uri = NULL;
+
+ if (!(uri = virURIParse(def->src)))
+ return -1;
+
+ return qemuParseDriveURIString(def, uri, "gluster");
+}
+
static int
qemuParseNBDString(virDomainDiskDefPtr disk)
{
char *host, *port;
char *src;
+ virURIPtr uri = NULL;
+
+ if (strstr(disk->src, "://")) {
+ uri = virURIParse(disk->src);
+ if (uri)
+ return qemuParseDriveURIString(disk, uri, "nbd");
+ }
+
if (VIR_ALLOC(h) < 0)
goto no_memory;
}
static int
-qemuBuildGlusterString(virDomainDiskDefPtr disk, virBufferPtr opt)
+qemuBuildDriveURIString(virDomainDiskDefPtr disk, virBufferPtr opt,
+ const char *scheme)
{
int ret = -1;
int port = 0;
};
if (disk->nhosts != 1) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("gluster accepts only one host"));
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("%s accepts only one host"), scheme);
return -1;
}
virBufferAddLit(opt, "file=");
transp = virDomainDiskProtocolTransportTypeToString(disk->hosts->transport);
- if (virAsprintf(&tmpscheme, "gluster+%s", transp) < 0)
+ if (virAsprintf(&tmpscheme, "%s+%s", scheme, transp) < 0)
goto no_memory;
- if (virAsprintf(&volimg, "/%s", disk->src) < 0)
+ if (disk->src && virAsprintf(&volimg, "/%s", disk->src) < 0)
goto no_memory;
if (disk->hosts->port) {
goto cleanup;
}
+static int
+qemuBuildGlusterString(virDomainDiskDefPtr disk, virBufferPtr opt)
+{
+ return qemuBuildDriveURIString(disk, opt, "gluster");
+}
+
#define QEMU_DEFAULT_NBD_PORT "10809"
static int
return -1;
}
+ if ((disk->hosts->name && strchr(disk->hosts->name, ':'))
+ || (disk->hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_TCP
+ && !disk->hosts->name)
+ || (disk->hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_UNIX
+ && disk->hosts->socket && disk->hosts->socket[0] != '/'))
+ return qemuBuildDriveURIString(disk, opt, "nbd");
+
virBufferAddLit(opt, "file=nbd:");
switch (disk->hosts->transport) {
values[i] = NULL;
if (STRPREFIX(def->src, "/dev/"))
def->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
- else if (STRPREFIX(def->src, "nbd:")) {
+ else if (STRPREFIX(def->src, "nbd:") ||
+ STRPREFIX(def->src, "nbd+")) {
def->type = VIR_DOMAIN_DISK_TYPE_NETWORK;
def->protocol = VIR_DOMAIN_DISK_PROTOCOL_NBD;
goto cleanup;
VIR_FREE(p);
- } else if (STRPREFIX(def->src, "gluster")) {
+ } else if (STRPREFIX(def->src, "gluster:") ||
+ STRPREFIX(def->src, "gluster+")) {
def->type = VIR_DOMAIN_DISK_TYPE_NETWORK;
def->protocol = VIR_DOMAIN_DISK_PROTOCOL_GLUSTER;
--- /dev/null
+<domain type='qemu'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219136</memory>
+ <currentMemory unit='KiB'>219136</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='i686' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu</emulator>
+ <disk type='block' device='disk'>
+ <source dev='/dev/HostVG/QEMUGuest1'/>
+ <target dev='hda' bus='ide'/>
+ <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+ </disk>
+ <disk type='network' device='disk'>
+ <driver name='qemu' type='raw'/>
+ <source protocol='nbd' name='bar'>
+ <host name='::1' port='6000'/>
+ </source>
+ <target dev='vda' bus='virtio'/>
+ </disk>
+ <controller type='usb' index='0'/>
+ <controller type='ide' index='0'/>
+ <memballoon model='virtio'/>
+ </devices>
+</domain>
--- /dev/null
+<domain type='qemu'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219136</memory>
+ <currentMemory unit='KiB'>219136</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='i686' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu</emulator>
+ <disk type='block' device='disk'>
+ <source dev='/dev/HostVG/QEMUGuest1'/>
+ <target dev='hda' bus='ide'/>
+ <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+ </disk>
+ <disk type='network' device='disk'>
+ <driver name='qemu' type='raw'/>
+ <source protocol='nbd'>
+ <host name='::1' port='6000'/>
+ </source>
+ <target dev='vda' bus='virtio'/>
+ </disk>
+ <controller type='usb' index='0'/>
+ <controller type='ide' index='0'/>
+ <memballoon model='virtio'/>
+ </devices>
+</domain>