/*
* xen_sxpr.c: Xen SEXPR parsing functions
*
- * Copyright (C) 2010-2013 Red Hat, Inc.
+ * Copyright (C) 2010-2014 Red Hat, Inc.
* Copyright (C) 2011 Univention GmbH
* Copyright (C) 2005 Anthony Liguori <aliguori@us.ibm.com>
*
if (sexpr_lookup(node, "device/tap2") &&
STRPREFIX(src, "tap:")) {
- if (VIR_STRDUP(disk->driverName, "tap2") < 0)
+ if (virDomainDiskSetDriver(disk, "tap2") < 0)
goto error;
} else {
- if (VIR_ALLOC_N(disk->driverName, (offset-src)+1) < 0)
+ char *tmp;
+ if (VIR_STRNDUP(tmp, src, offset - src) < 0)
goto error;
- if (virStrncpy(disk->driverName, src, offset-src,
- (offset-src)+1) == NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Driver name %s too big for destination"),
- src);
+ if (virDomainDiskSetDriver(disk, tmp) < 0) {
+ VIR_FREE(tmp);
goto error;
}
+ VIR_FREE(tmp);
}
src = offset + 1;
- if (STREQ(disk->driverName, "tap") ||
- STREQ(disk->driverName, "tap2")) {
+ if (STREQ(virDomainDiskGetDriver(disk), "tap") ||
+ STREQ(virDomainDiskGetDriver(disk), "tap2")) {
char *driverType = NULL;
offset = strchr(src, ':');
if (VIR_STRNDUP(driverType, src, offset - src) < 0)
goto error;
if (STREQ(driverType, "aio"))
- disk->format = VIR_STORAGE_FILE_RAW;
+ virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW);
else
- disk->format =
- virStorageFileFormatTypeFromString(driverType);
+ virDomainDiskSetFormat(disk,
+ virStorageFileFormatTypeFromString(driverType));
VIR_FREE(driverType);
- if (disk->format <= 0) {
+ if (virDomainDiskGetFormat(disk) <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unknown driver type %s"), src);
goto error;
so we assume common case here. If blktap becomes
omnipotent, we can revisit this, perhaps stat()'ing
the src file in question */
- disk->type = VIR_DOMAIN_DISK_TYPE_FILE;
- } else if (STREQ(disk->driverName, "phy")) {
- disk->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
- } else if (STREQ(disk->driverName, "file")) {
- disk->type = VIR_DOMAIN_DISK_TYPE_FILE;
+ virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_FILE);
+ } else if (STREQ(virDomainDiskGetDriver(disk), "phy")) {
+ virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_BLOCK);
+ } else if (STREQ(virDomainDiskGetDriver(disk), "file")) {
+ virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_FILE);
}
} else {
/* No CDROM media so can't really tell. We'll just
call if a FILE for now and update when media
is inserted later */
- disk->type = VIR_DOMAIN_DISK_TYPE_FILE;
+ virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_FILE);
}
if (STREQLEN(dst, "ioemu:", 6))
if (VIR_STRDUP(disk->dst, dst) < 0)
goto error;
- if (VIR_STRDUP(disk->src, src) < 0)
+ if (virDomainDiskSetSource(disk, src) < 0)
goto error;
if (STRPREFIX(disk->dst, "xvd"))
virDomainDiskDefPtr disk;
if (VIR_ALLOC(disk) < 0)
goto error;
- if (VIR_STRDUP(disk->src, tmp) < 0) {
+ if (virDomainDiskSetSource(disk, tmp) < 0) {
virDomainDiskDefFree(disk);
goto error;
}
- disk->type = VIR_DOMAIN_DISK_TYPE_FILE;
+ virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_FILE);
disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM;
if (VIR_STRDUP(disk->dst, "hdc") < 0) {
virDomainDiskDefFree(disk);
goto error;
}
- if (VIR_STRDUP(disk->driverName, "file") < 0) {
+ if (virDomainDiskSetDriver(disk, "file") < 0) {
virDomainDiskDefFree(disk);
goto error;
}
virDomainDiskDefPtr disk;
if (VIR_ALLOC(disk) < 0)
goto error;
- if (VIR_STRDUP(disk->src, tmp) < 0) {
+ if (virDomainDiskSetSource(disk, tmp) < 0) {
VIR_FREE(disk);
goto error;
}
- disk->type = VIR_DOMAIN_DISK_TYPE_FILE;
+ virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_FILE);
disk->device = VIR_DOMAIN_DISK_DEVICE_FLOPPY;
if (VIR_STRDUP(disk->dst, fds[i]) < 0) {
virDomainDiskDefFree(disk);
goto error;
}
- if (VIR_STRDUP(disk->driverName, "file") < 0) {
+ if (virDomainDiskSetSource(disk, "file") < 0) {
virDomainDiskDefFree(disk);
goto error;
}
int xendConfigVersion,
int isAttach)
{
+ const char *src = virDomainDiskGetSource(def);
+ const char *driver = virDomainDiskGetDriver(def);
+
/* Xend (all versions) put the floppy device config
* under the hvm (image (os)) block
*/
def->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
if (isAttach) {
virReportError(VIR_ERR_INVALID_ARG,
- _("Cannot directly attach floppy %s"), def->src);
+ _("Cannot directly attach floppy %s"), src);
return -1;
}
return 0;
xendConfigVersion == XEND_CONFIG_VERSION_3_0_2) {
if (isAttach) {
virReportError(VIR_ERR_INVALID_ARG,
- _("Cannot directly attach CDROM %s"), def->src);
+ _("Cannot directly attach CDROM %s"), src);
return -1;
}
return 0;
/* Normally disks are in a (device (vbd ...)) block
* but blktap disks ended up in a differently named
* (device (tap ....)) block.... */
- if (def->driverName && STREQ(def->driverName, "tap")) {
+ if (STREQ_NULLABLE(driver, "tap")) {
virBufferAddLit(buf, "(tap ");
- } else if (def->driverName && STREQ(def->driverName, "tap2")) {
+ } else if (STREQ_NULLABLE(driver, "tap2")) {
virBufferAddLit(buf, "(tap2 ");
} else {
virBufferAddLit(buf, "(vbd ");
virBufferEscapeSexpr(buf, "(dev '%s')", def->dst);
}
- if (def->src) {
- if (def->driverName) {
- if (STREQ(def->driverName, "tap") ||
- STREQ(def->driverName, "tap2")) {
+ if (src) {
+ if (driver) {
+ if (STREQ(driver, "tap") ||
+ STREQ(driver, "tap2")) {
const char *type;
+ int format = virDomainDiskGetFormat(def);
- if (!def->format || def->format == VIR_STORAGE_FILE_RAW)
+ if (!format || format == VIR_STORAGE_FILE_RAW)
type = "aio";
else
- type = virStorageFileFormatTypeToString(def->format);
- virBufferEscapeSexpr(buf, "(uname '%s:", def->driverName);
+ type = virStorageFileFormatTypeToString(format);
+ virBufferEscapeSexpr(buf, "(uname '%s:", driver);
virBufferEscapeSexpr(buf, "%s:", type);
- virBufferEscapeSexpr(buf, "%s')", def->src);
+ virBufferEscapeSexpr(buf, "%s')", src);
} else {
- virBufferEscapeSexpr(buf, "(uname '%s:", def->driverName);
- virBufferEscapeSexpr(buf, "%s')", def->src);
+ virBufferEscapeSexpr(buf, "(uname '%s:", driver);
+ virBufferEscapeSexpr(buf, "%s')", src);
}
} else {
- if (def->type == VIR_DOMAIN_DISK_TYPE_FILE) {
- virBufferEscapeSexpr(buf, "(uname 'file:%s')", def->src);
- } else if (def->type == VIR_DOMAIN_DISK_TYPE_BLOCK) {
- if (def->src[0] == '/')
- virBufferEscapeSexpr(buf, "(uname 'phy:%s')", def->src);
+ int type = virDomainDiskGetType(def);
+
+ if (type == VIR_DOMAIN_DISK_TYPE_FILE) {
+ virBufferEscapeSexpr(buf, "(uname 'file:%s')", src);
+ } else if (type == VIR_DOMAIN_DISK_TYPE_BLOCK) {
+ if (src[0] == '/')
+ virBufferEscapeSexpr(buf, "(uname 'phy:%s')", src);
else
virBufferEscapeSexpr(buf, "(uname 'phy:/dev/%s')",
- def->src);
+ src);
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unsupported disk type %s"),
- virDomainDiskTypeToString(def->type));
+ virDomainDiskTypeToString(type));
return -1;
}
}
/* some disk devices are defined here */
for (i = 0; i < def->ndisks; i++) {
+ const char *src = virDomainDiskGetSource(def->disks[i]);
+
switch (def->disks[i]->device) {
case VIR_DOMAIN_DISK_DEVICE_CDROM:
/* Only xend <= 3.0.2 wants cdrom config here */
if (xendConfigVersion != XEND_CONFIG_VERSION_3_0_2)
break;
- if (!STREQ(def->disks[i]->dst, "hdc") ||
- def->disks[i]->src == NULL)
+ if (!STREQ(def->disks[i]->dst, "hdc") || !src)
break;
- virBufferEscapeSexpr(&buf, "(cdrom '%s')",
- def->disks[i]->src);
+ virBufferEscapeSexpr(&buf, "(cdrom '%s')", src);
break;
case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
/* all xend versions define floppies here */
virBufferEscapeSexpr(&buf, "(%s ", def->disks[i]->dst);
- virBufferEscapeSexpr(&buf, "'%s')", def->disks[i]->src);
+ virBufferEscapeSexpr(&buf, "'%s')", src);
break;
default:
/*
* xen_xm.c: Xen XM parsing functions
*
- * Copyright (C) 2006-2007, 2009-2010, 2012-2014 Red Hat, Inc.
+ * Copyright (C) 2006-2007, 2009-2014 Red Hat, Inc.
* Copyright (C) 2011 Univention GmbH
* Copyright (C) 2006 Daniel P. Berrange
*
char *head;
char *offset;
char *tmp;
+ const char *src;
if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
goto skipdisk;
goto skipdisk;
if (offset == head) {
- disk->src = NULL; /* No source file given, eg CDROM with no media */
+ /* No source file given, eg CDROM with no media */
+ ignore_value(virDomainDiskSetSource(disk, NULL));
} else {
- if (VIR_ALLOC_N(disk->src, (offset - head) + 1) < 0)
+ if (VIR_STRNDUP(tmp, head, offset - head) < 0)
goto cleanup;
- if (virStrncpy(disk->src, head, offset - head,
- (offset - head) + 1) == NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Source file %s too big for destination"),
- head);
+ if (virDomainDiskSetSource(disk, tmp) < 0) {
+ VIR_FREE(tmp);
goto cleanup;
}
+ VIR_FREE(tmp);
}
head = offset + 1;
}
head = offset + 1;
-
/* Extract source driver type */
- if (disk->src) {
+ src = virDomainDiskGetSource(disk);
+ if (src) {
+ size_t len;
/* The main type phy:, file:, tap: ... */
- if ((tmp = strchr(disk->src, ':')) != NULL) {
- if (VIR_ALLOC_N(disk->driverName, (tmp - disk->src) + 1) < 0)
+ if ((tmp = strchr(src, ':')) != NULL) {
+ len = tmp - src;
+ if (VIR_STRNDUP(tmp, src, len) < 0)
goto cleanup;
- if (virStrncpy(disk->driverName, disk->src,
- (tmp - disk->src),
- (tmp - disk->src) + 1) == NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Driver name %s too big for destination"),
- disk->src);
+ if (virDomainDiskSetDriver(disk, tmp) < 0) {
+ VIR_FREE(tmp);
goto cleanup;
}
+ VIR_FREE(tmp);
/* Strip the prefix we found off the source file name */
- memmove(disk->src, disk->src+(tmp-disk->src)+1,
- strlen(disk->src)-(tmp-disk->src));
+ if (virDomainDiskSetSource(disk, src + len + 1) < 0)
+ goto cleanup;
+ src = virDomainDiskGetSource(disk);
}
/* And the sub-type for tap:XXX: type */
- if (disk->driverName &&
- STREQ(disk->driverName, "tap")) {
+ if (STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap")) {
char *driverType;
- if (!(tmp = strchr(disk->src, ':')))
+ if (!(tmp = strchr(src, ':')))
goto skipdisk;
+ len = tmp - src;
- if (VIR_STRNDUP(driverType, disk->src, tmp - disk->src) < 0)
+ if (VIR_STRNDUP(driverType, src, len) < 0)
goto cleanup;
if (STREQ(driverType, "aio"))
- disk->format = VIR_STORAGE_FILE_RAW;
+ virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW);
else
- disk->format =
- virStorageFileFormatTypeFromString(driverType);
+ virDomainDiskSetFormat(disk,
+ virStorageFileFormatTypeFromString(driverType));
VIR_FREE(driverType);
- if (disk->format <= 0) {
+ if (virDomainDiskGetFormat(disk) <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unknown driver type %s"),
- disk->src);
+ src);
goto cleanup;
}
/* Strip the prefix we found off the source file name */
- memmove(disk->src, disk->src+(tmp-disk->src)+1,
- strlen(disk->src)-(tmp-disk->src));
+ if (virDomainDiskSetSource(disk, src + len + 1) < 0)
+ goto cleanup;
+ src = virDomainDiskGetSource(disk);
}
}
/* No source, or driver name, so fix to phy: */
- if (!disk->driverName &&
- VIR_STRDUP(disk->driverName, "phy") < 0)
+ if (!virDomainDiskGetDriver(disk) &&
+ virDomainDiskSetDriver(disk, "phy") < 0)
goto cleanup;
/* phy: type indicates a block device */
- disk->type = STREQ(disk->driverName, "phy") ?
- VIR_DOMAIN_DISK_TYPE_BLOCK : VIR_DOMAIN_DISK_TYPE_FILE;
+ virDomainDiskSetType(disk,
+ STREQ(virDomainDiskGetDriver(disk), "phy") ?
+ VIR_DOMAIN_DISK_TYPE_BLOCK :
+ VIR_DOMAIN_DISK_TYPE_FILE);
/* Check for a :cdrom/:disk postfix */
disk->device = VIR_DOMAIN_DISK_DEVICE_DISK;
if (VIR_ALLOC(disk) < 0)
goto cleanup;
- disk->type = VIR_DOMAIN_DISK_TYPE_FILE;
+ virDomainDiskSetType(disk, VIR_DOMAIN_DISK_TYPE_FILE);
disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM;
- if (VIR_STRDUP(disk->driverName, "file") < 0)
+ if (virDomainDiskSetDriver(disk, "file") < 0)
goto cleanup;
- if (VIR_STRDUP(disk->src, str) < 0)
+ if (virDomainDiskSetSource(disk, str) < 0)
goto cleanup;
if (VIR_STRDUP(disk->dst, "hdc") < 0)
goto cleanup;
}
-static int xenFormatXMDisk(virConfValuePtr list,
- virDomainDiskDefPtr disk,
- int hvm,
- int xendConfigVersion)
+static int
+xenFormatXMDisk(virConfValuePtr list,
+ virDomainDiskDefPtr disk,
+ int hvm,
+ int xendConfigVersion)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
virConfValuePtr val, tmp;
+ const char *src = virDomainDiskGetSource(disk);
+ int format = virDomainDiskGetFormat(disk);
+ const char *driver = virDomainDiskGetDriver(disk);
- if (disk->src) {
- if (disk->format) {
+ if (src) {
+ if (format) {
const char *type;
- if (disk->format == VIR_STORAGE_FILE_RAW)
+ if (format == VIR_STORAGE_FILE_RAW)
type = "aio";
else
- type = virStorageFileFormatTypeToString(disk->format);
- virBufferAsprintf(&buf, "%s:", disk->driverName);
- if (STREQ(disk->driverName, "tap"))
+ type = virStorageFileFormatTypeToString(format);
+ virBufferAsprintf(&buf, "%s:", driver);
+ if (STREQ(driver, "tap"))
virBufferAsprintf(&buf, "%s:", type);
} else {
- switch (disk->type) {
+ switch (virDomainDiskGetType(disk)) {
case VIR_DOMAIN_DISK_TYPE_FILE:
virBufferAddLit(&buf, "file:");
break;
default:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unsupported disk type %s"),
- virDomainDiskTypeToString(disk->type));
+ virDomainDiskTypeToString(virDomainDiskGetType(disk)));
goto cleanup;
}
}
- virBufferAdd(&buf, disk->src, -1);
+ virBufferAdd(&buf, src, -1);
}
virBufferAddLit(&buf, ",");
if (hvm && xendConfigVersion == XEND_CONFIG_VERSION_3_0_2)
if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
def->disks[i]->dst &&
STREQ(def->disks[i]->dst, "hdc") &&
- def->disks[i]->src) {
+ virDomainDiskGetSource(def->disks[i])) {
if (xenXMConfigSetString(conf, "cdrom",
- def->disks[i]->src) < 0)
+ virDomainDiskGetSource(def->disks[i])) < 0)
goto cleanup;
break;
}