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);
+ } else {
+ if (virStorageFileStat(mirror, &st) < 0) {
+ virReportSystemError(errno,
+ _("unable to stat block copy target '%s'"),
+ 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;
+
+ 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;
+ }
}
- } else {
- /* if the target is a block device, assume that we are reusing it, so
- * there are no attempts to create it */
- *reuse = true;
}
return 0;