* @src: storage source data
* @ret_fd: pointer to return open'd file descriptor
* @ret_sb: pointer to return stat buffer (local or remote)
+ * @skipInaccessible: Don't report error if files are not accessible
*
* For local storage, open the file using qemuOpenFile and then use
* fstat() to grab the stat struct data for the caller.
* For remote storage, attempt to access the file and grab the stat
* struct data if the remote connection supports it.
*
- * Returns 0 on success with @ret_fd and @ret_sb populated, -1 on failure
+ * Returns 1 if @src was successfully opened (@ret_fd and @ret_sb is populated),
+ * 0 if @src can't be opened and @skipInaccessible is true (no errors are
+ * reported) or -1 otherwise (errors are reported).
*/
static int
qemuDomainStorageOpenStat(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virStorageSourcePtr src,
int *ret_fd,
- struct stat *ret_sb)
+ struct stat *ret_sb,
+ bool skipInaccessible)
{
if (virStorageSourceIsLocalStorage(src)) {
+ if (skipInaccessible && !virFileExists(src->path))
+ return 0;
+
if ((*ret_fd = qemuOpenFile(driver, vm, src->path, O_RDONLY,
NULL)) < 0)
return -1;
return -1;
}
} else {
+ if (skipInaccessible && virStorageFileSupportsBackingChainTraversal(src) <= 0)
+ return 0;
+
if (virStorageFileInitAs(src, cfg->user, cfg->group) < 0)
return -1;
}
}
- return 0;
+ return 1;
}
if (virStorageSourceIsEmpty(src))
return 0;
- if (qemuDomainStorageOpenStat(driver, cfg, vm, src, &fd, &sb) < 0)
+ if (qemuDomainStorageOpenStat(driver, cfg, vm, src, &fd, &sb, false) < 0)
return -1;
ret = virStorageSourceUpdatePhysicalSize(src, fd, &sb);
char *buf = NULL;
ssize_t len;
- if (qemuDomainStorageOpenStat(driver, cfg, vm, src, &fd, &sb) < 0)
+ if (qemuDomainStorageOpenStat(driver, cfg, vm, src, &fd, &sb, false) < 0)
goto cleanup;
if (virStorageSourceIsLocalStorage(src)) {