virDomainSnapshotDiskDefClear(virDomainSnapshotDiskDefPtr disk)
{
VIR_FREE(disk->name);
- VIR_FREE(disk->file);
- virStorageNetHostDefFree(disk->nhosts, disk->hosts);
- disk->nhosts = 0;
+ virStorageSourceClear(&disk->src);
}
void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def)
}
if ((type = virXMLPropString(node, "type"))) {
- if ((def->type = virStorageTypeFromString(type)) < 0 ||
- def->type == VIR_STORAGE_TYPE_VOLUME ||
- def->type == VIR_STORAGE_TYPE_DIR) {
+ if ((def->src.type = virStorageTypeFromString(type)) < 0 ||
+ def->src.type == VIR_STORAGE_TYPE_VOLUME ||
+ def->src.type == VIR_STORAGE_TYPE_DIR) {
virReportError(VIR_ERR_XML_ERROR,
_("unknown disk snapshot type '%s'"), type);
goto cleanup;
}
} else {
- def->type = VIR_STORAGE_TYPE_FILE;
+ def->src.type = VIR_STORAGE_TYPE_FILE;
}
for (cur = node->children; cur; cur = cur->next) {
if (cur->type != XML_ELEMENT_NODE)
continue;
- if (!def->file &&
+ if (!def->src.path &&
xmlStrEqual(cur->name, BAD_CAST "source")) {
if (virDomainDiskSourceDefParse(cur,
- def->type,
- &def->file,
- &def->protocol,
- &def->nhosts,
- &def->hosts,
+ def->src.type,
+ &def->src.path,
+ &def->src.protocol,
+ &def->src.nhosts,
+ &def->src.hosts,
NULL) < 0)
goto cleanup;
- } else if (!def->format &&
+ } else if (!def->src.format &&
xmlStrEqual(cur->name, BAD_CAST "driver")) {
char *driver = virXMLPropString(cur, "type");
if (driver) {
- def->format = virStorageFileFormatTypeFromString(driver);
- if (def->format <= 0) {
+ def->src.format = virStorageFileFormatTypeFromString(driver);
+ if (def->src.format <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown disk snapshot driver '%s'"),
driver);
}
}
- if (!def->snapshot && (def->file || def->format))
+ if (!def->snapshot && (def->src.path || def->src.format))
def->snapshot = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
ret = 0;
disk->name, tmp);
goto cleanup;
}
- if (disk->file &&
+ if (disk->src.path &&
disk->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("file '%s' for disk '%s' requires "
"use of external snapshot mode"),
- disk->file, disk->name);
+ disk->src.path, disk->name);
goto cleanup;
}
if (STRNEQ(disk->name, def->dom->disks[idx]->dst)) {
goto cleanup;
disk->index = i;
disk->snapshot = def->dom->disks[i]->snapshot;
- disk->type = VIR_STORAGE_TYPE_FILE;
+ disk->src.type = VIR_STORAGE_TYPE_FILE;
if (!disk->snapshot)
disk->snapshot = default_snapshot;
}
virDomainSnapshotDiskDefPtr disk = &def->disks[i];
if (disk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL &&
- !disk->file) {
+ !disk->src.path) {
const char *original = virDomainDiskGetSource(def->dom->disks[i]);
const char *tmp;
struct stat sb;
- if (disk->type != VIR_STORAGE_TYPE_FILE) {
+ if (disk->src.type != VIR_STORAGE_TYPE_FILE) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("cannot generate external snapshot name "
"for disk '%s' on a '%s' device"),
- disk->name, virStorageTypeToString(disk->type));
+ disk->name,
+ virStorageTypeToString(disk->src.type));
goto cleanup;
}
tmp = strrchr(original, '.');
if (!tmp || strchr(tmp, '/')) {
- if (virAsprintf(&disk->file, "%s.%s", original, def->name) < 0)
+ if (virAsprintf(&disk->src.path, "%s.%s", original,
+ def->name) < 0)
goto cleanup;
} else {
if ((tmp - original) > INT_MAX) {
_("integer overflow"));
goto cleanup;
}
- if (virAsprintf(&disk->file, "%.*s.%s",
+ if (virAsprintf(&disk->src.path, "%.*s.%s",
(int) (tmp - original), original,
def->name) < 0)
goto cleanup;
virDomainSnapshotDiskDefFormat(virBufferPtr buf,
virDomainSnapshotDiskDefPtr disk)
{
- int type = disk->type;
+ int type = disk->src.type;
if (!disk->name)
return;
virBufferAsprintf(buf, " snapshot='%s'",
virDomainSnapshotLocationTypeToString(disk->snapshot));
- if (!disk->file && disk->format == 0) {
+ if (!disk->src.path && disk->src.format == 0) {
virBufferAddLit(buf, "/>\n");
return;
}
virBufferAsprintf(buf, " type='%s'>\n", virStorageTypeToString(type));
virBufferAdjustIndent(buf, 2);
- if (disk->format > 0)
+ if (disk->src.format > 0)
virBufferEscapeString(buf, "<driver type='%s'/>\n",
- virStorageFileFormatTypeToString(disk->format));
+ virStorageFileFormatTypeToString(disk->src.format));
virDomainDiskSourceDefFormatInternal(buf,
type,
- disk->file,
+ disk->src.path,
0,
- disk->protocol,
- disk->nhosts,
- disk->hosts,
+ disk->src.protocol,
+ disk->src.nhosts,
+ disk->src.hosts,
0, NULL, NULL, 0);
virBufferAdjustIndent(buf, -2);
int
virDomainSnapshotDiskGetActualType(virDomainSnapshotDiskDefPtr def)
{
- return def->type;
+ return def->src.type;
}
*source = NULL;
return qemuGetDriveSourceString(virDomainSnapshotDiskGetActualType(disk),
- disk->file,
- disk->protocol,
- disk->nhosts,
- disk->hosts,
+ disk->src.path,
+ disk->src.protocol,
+ disk->src.nhosts,
+ disk->src.hosts,
NULL,
NULL,
source);
if (snapdisk->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL)
continue;
- if (!snapdisk->format)
- snapdisk->format = VIR_STORAGE_FILE_QCOW2;
+ if (!snapdisk->src.format)
+ snapdisk->src.format = VIR_STORAGE_FILE_QCOW2;
/* creates cmd line args: qemu-img create -f qcow2 -o */
if (!(cmd = virCommandNewArgList(qemuImgPath,
"create",
"-f",
- virStorageFileFormatTypeToString(snapdisk->format),
+ virStorageFileFormatTypeToString(snapdisk->src.format),
"-o",
NULL)))
goto cleanup;
}
/* adds cmd line args: /path/to/target/file */
- virCommandAddArg(cmd, snapdisk->file);
+ virCommandAddArg(cmd, snapdisk->src.path);
/* If the target does not exist, we're going to create it possibly */
- if (!virFileExists(snapdisk->file))
+ if (!virFileExists(snapdisk->src.path))
ignore_value(virBitmapSetBit(created, i));
if (virCommandRun(cmd, NULL) < 0)
if (snapdisk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
VIR_FREE(defdisk->src.path);
- if (VIR_STRDUP(defdisk->src.path, snapdisk->file) < 0) {
+ if (VIR_STRDUP(defdisk->src.path, snapdisk->src.path) < 0) {
/* we cannot rollback here in a sane way */
goto cleanup;
}
- defdisk->src.format = snapdisk->format;
+ defdisk->src.format = snapdisk->src.format;
}
}
ssize_t bit = -1;
while ((bit = virBitmapNextSetBit(created, bit)) >= 0) {
snapdisk = &(snap->def->disks[bit]);
- if (unlink(snapdisk->file) < 0)
+ if (unlink(snapdisk->src.path) < 0)
VIR_WARN("Failed to remove snapshot image '%s'",
- snapdisk->file);
+ snapdisk->src.path);
}
}
virBitmapFree(created);
return 0;
case VIR_STORAGE_TYPE_NETWORK:
- switch ((enum virStorageNetProtocol) disk->protocol) {
+ switch ((enum virStorageNetProtocol) disk->src.protocol) {
case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
return 0;
virReportError(VIR_ERR_INTERNAL_ERROR,
_("external active snapshots are not supported on "
"'network' disks using '%s' protocol"),
- virStorageNetProtocolTypeToString(disk->protocol));
+ virStorageNetProtocolTypeToString(disk->src.protocol));
return -1;
}
if (errno != ENOENT) {
virReportSystemError(errno,
_("unable to stat for disk %s: %s"),
- snapdisk->name, snapdisk->file);
+ snapdisk->name, snapdisk->src.path);
goto cleanup;
} else if (reuse) {
virReportSystemError(errno,
_("missing existing file for disk %s: %s"),
- snapdisk->name, snapdisk->file);
+ snapdisk->name, snapdisk->src.path);
goto cleanup;
}
} else if (!S_ISBLK(st.st_mode) && st.st_size && !reuse) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("external snapshot file for disk %s already "
"exists and is not a block device: %s"),
- snapdisk->name, snapdisk->file);
+ snapdisk->name, snapdisk->src.path);
goto cleanup;
}
break;
case VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL:
- if (!disk->format) {
- disk->format = VIR_STORAGE_FILE_QCOW2;
- } else if (disk->format != VIR_STORAGE_FILE_QCOW2 &&
- disk->format != VIR_STORAGE_FILE_QED) {
+ if (!disk->src.format) {
+ disk->src.format = VIR_STORAGE_FILE_QCOW2;
+ } else if (disk->src.format != VIR_STORAGE_FILE_QCOW2 &&
+ disk->src.format != VIR_STORAGE_FILE_QED) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("external snapshot format for disk %s "
"is unsupported: %s"),
disk->name,
- virStorageFileFormatTypeToString(disk->format));
+ virStorageFileFormatTypeToString(disk->src.format));
goto cleanup;
}
char *newsource = NULL;
virStorageNetHostDefPtr newhosts = NULL;
virStorageNetHostDefPtr persistHosts = NULL;
- int format = snap->format;
+ int format = snap->src.format;
const char *formatStr = NULL;
char *persistSource = NULL;
int ret = -1;
if (qemuDomainSnapshotDiskGetSourceString(snap, &source) < 0)
goto cleanup;
- if (VIR_STRDUP(newsource, snap->file) < 0)
+ if (VIR_STRDUP(newsource, snap->src.path) < 0)
goto cleanup;
if (persistDisk &&
- VIR_STRDUP(persistSource, snap->file) < 0)
+ VIR_STRDUP(persistSource, snap->src.path) < 0)
goto cleanup;
- switch (snap->type) {
+ switch (snap->src.type) {
case VIR_STORAGE_TYPE_BLOCK:
reuse = true;
/* fallthrough */
break;
case VIR_STORAGE_TYPE_NETWORK:
- switch (snap->protocol) {
+ switch (snap->src.protocol) {
case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
- if (!(newhosts = virStorageNetHostDefCopy(snap->nhosts, snap->hosts)))
+ if (!(newhosts = virStorageNetHostDefCopy(snap->src.nhosts,
+ snap->src.hosts)))
goto cleanup;
if (persistDisk &&
- !(persistHosts = virStorageNetHostDefCopy(snap->nhosts, snap->hosts)))
+ !(persistHosts = virStorageNetHostDefCopy(snap->src.nhosts,
+ snap->src.hosts)))
goto cleanup;
break;
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("snapshots on volumes using '%s' protocol "
"are not supported"),
- virStorageNetProtocolTypeToString(snap->protocol));
+ virStorageNetProtocolTypeToString(snap->src.protocol));
goto cleanup;
}
break;
default:
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("snapshots are not supported on '%s' volumes"),
- virStorageTypeToString(snap->type));
+ virStorageTypeToString(snap->src.type));
goto cleanup;
}
/* create the actual snapshot */
- if (snap->format)
- formatStr = virStorageFileFormatTypeToString(snap->format);
+ if (snap->src.format)
+ formatStr = virStorageFileFormatTypeToString(snap->src.format);
/* The monitor is only accessed if qemu doesn't support transactions.
* Otherwise the following monitor command only constructs the command.
disk->src.path = newsource;
disk->src.format = format;
- disk->src.type = snap->type;
- disk->src.protocol = snap->protocol;
- disk->src.nhosts = snap->nhosts;
+ disk->src.type = snap->src.type;
+ disk->src.protocol = snap->src.protocol;
+ disk->src.nhosts = snap->src.nhosts;
disk->src.hosts = newhosts;
newsource = NULL;
persistDisk->src.path = persistSource;
persistDisk->src.format = format;
- persistDisk->src.type = snap->type;
- persistDisk->src.protocol = snap->protocol;
- persistDisk->src.nhosts = snap->nhosts;
+ persistDisk->src.type = snap->src.type;
+ persistDisk->src.protocol = snap->src.protocol;
+ persistDisk->src.nhosts = snap->src.nhosts;
persistDisk->src.hosts = persistHosts;
persistSource = NULL;
VIR_FREE(source);
VIR_FREE(newsource);
VIR_FREE(persistSource);
- virStorageNetHostDefFree(snap->nhosts, newhosts);
- virStorageNetHostDefFree(snap->nhosts, persistHosts);
+ virStorageNetHostDefFree(snap->src.nhosts, newhosts);
+ virStorageNetHostDefFree(snap->src.nhosts, persistHosts);
return ret;
}