提交 7183d7d2 编写于 作者: P Peter Krempa

qemu: snapshot: Use new APIs to detect presence of existing storage files

Use the new storage driver based "stat" api to detect exiting files just
as we did with local files.
上级 8f4091d6
...@@ -12367,7 +12367,6 @@ qemuDomainSnapshotPrepareDiskExternalOverlayInactive(virDomainSnapshotDiskDefPtr ...@@ -12367,7 +12367,6 @@ qemuDomainSnapshotPrepareDiskExternalOverlayInactive(virDomainSnapshotDiskDefPtr
} }
static int static int
qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn, qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn,
virDomainDiskDefPtr disk, virDomainDiskDefPtr disk,
...@@ -12375,7 +12374,8 @@ qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn, ...@@ -12375,7 +12374,8 @@ qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn,
bool active, bool active,
bool reuse) bool reuse)
{ {
int actualType; virStorageFilePtr snapfile = NULL;
int ret = -1;
struct stat st; struct stat st;
if (qemuTranslateSnapshotDiskSourcePool(conn, snapdisk) < 0) if (qemuTranslateSnapshotDiskSourcePool(conn, snapdisk) < 0)
...@@ -12398,40 +12398,34 @@ qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn, ...@@ -12398,40 +12398,34 @@ qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn,
return -1; return -1;
} }
actualType = virDomainSnapshotDiskGetActualType(snapdisk); if (!(snapfile = virStorageFileInitFromSnapshotDef(snapdisk)))
return -1;
switch ((enum virDomainDiskType) actualType) { if (virStorageFileStat(snapfile, &st) < 0) {
case VIR_DOMAIN_DISK_TYPE_BLOCK: if (errno != ENOENT) {
case VIR_DOMAIN_DISK_TYPE_FILE: virReportSystemError(errno,
if (stat(snapdisk->file, &st) < 0) { _("unable to stat for disk %s: %s"),
if (errno != ENOENT) { snapdisk->name, snapdisk->file);
virReportSystemError(errno, goto cleanup;
_("unable to stat for disk %s: %s"), } else if (reuse) {
snapdisk->name, snapdisk->file); virReportSystemError(errno,
return -1; _("missing existing file for disk %s: %s"),
} else if (reuse) { snapdisk->name, snapdisk->file);
virReportSystemError(errno, goto cleanup;
_("missing existing file for disk %s: %s"),
snapdisk->name, snapdisk->file);
return -1;
}
} 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);
return -1;
} }
break; } else if (!S_ISBLK(st.st_mode) && st.st_size && !reuse) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
case VIR_DOMAIN_DISK_TYPE_NETWORK: _("external snapshot file for disk %s already "
case VIR_DOMAIN_DISK_TYPE_DIR: "exists and is not a block device: %s"),
case VIR_DOMAIN_DISK_TYPE_VOLUME: snapdisk->name, snapdisk->file);
case VIR_DOMAIN_DISK_TYPE_LAST: goto cleanup;
break;
} }
return 0; ret = 0;
cleanup:
virStorageFileFree(snapfile);
return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册