mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
qemu: blockcopy: Refactor logic checking the target storage file
Use virStorageSource accessors to check the file and call virStorageFileAccess before even attempting to stat the target. This will be helpful once we try to add network destinations for block copy, since there will be no need to stat them.
This commit is contained in:
parent
5f14a0f2fb
commit
703abf1d79
@ -16692,36 +16692,49 @@ qemuDomainBlockCopyValidateMirror(virStorageSourcePtr mirror,
|
||||
int desttype = virStorageSourceGetActualType(mirror);
|
||||
struct stat st;
|
||||
|
||||
if (stat(mirror->path, &st) < 0) {
|
||||
if (virStorageFileAccess(mirror, F_OK) < 0) {
|
||||
if (errno != ENOENT) {
|
||||
virReportSystemError(errno, _("unable to stat for disk %s: %s"),
|
||||
dst, mirror->path);
|
||||
virReportSystemError(errno, "%s",
|
||||
_("unable to verify existance of "
|
||||
"block copy target"));
|
||||
return -1;
|
||||
} else if (*reuse || desttype == VIR_STORAGE_TYPE_BLOCK) {
|
||||
}
|
||||
|
||||
if (*reuse || desttype == VIR_STORAGE_TYPE_BLOCK) {
|
||||
virReportSystemError(errno,
|
||||
_("missing destination file for disk %s: %s"),
|
||||
dst, mirror->path);
|
||||
return -1;
|
||||
}
|
||||
} else if (!S_ISBLK(st.st_mode)) {
|
||||
if (st.st_size && !(*reuse)) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("external destination file for disk %s already "
|
||||
"exists and is not a block device: %s"),
|
||||
dst, mirror->path);
|
||||
return -1;
|
||||
}
|
||||
if (desttype == VIR_STORAGE_TYPE_BLOCK) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("blockdev flag requested for disk %s, but file "
|
||||
"'%s' is not a block device"),
|
||||
dst, mirror->path);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
/* if the target is a block device, assume that we are reusing it, so
|
||||
* there are no attempts to create it */
|
||||
*reuse = true;
|
||||
if (virStorageFileStat(mirror, &st) < 0) {
|
||||
virReportSystemError(errno,
|
||||
_("unable to stat block copy target '%s'"),
|
||||
mirror->path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (S_ISBLK(st.st_mode)) {
|
||||
/* if the target is a block device, assume that we are reusing it,
|
||||
* so there are no attempts to create it */
|
||||
*reuse = true;
|
||||
} else {
|
||||
if (st.st_size && !(*reuse)) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("external destination file for disk %s already "
|
||||
"exists and is not a block device: %s"),
|
||||
dst, mirror->path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (desttype == VIR_STORAGE_TYPE_BLOCK) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("blockdev flag requested for disk %s, but file "
|
||||
"'%s' is not a block device"),
|
||||
dst, mirror->path);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user