From ba6c12df2ceb4df9bfb7ce95deef04f96bf29462 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Wed, 14 Aug 2019 16:00:27 +0200 Subject: [PATCH] qemu: Allow skipping some errors in qemuDomainStorageOpenStat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some callers of this function actually don't care about errors and reset it. The message is still logged which might irritate users in this case. Add a boolean flag which will do few checks whether it actually makes sense to even try opening the storage file. For local files we check whether it exists and for remote files we at first see whether we even have a storage driver backend for it in the first place before trying to open it. Other problems will still report errors but these are the most common scenarios which can happen here. This patch changes the return value of the function so that the caller is able to differentiate the possibilities. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/qemu/qemu_driver.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 48c7b5628b..cc296c1fe3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12247,6 +12247,7 @@ qemuDomainMemoryPeek(virDomainPtr dom, * @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. @@ -12254,7 +12255,9 @@ qemuDomainMemoryPeek(virDomainPtr dom, * 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, @@ -12262,9 +12265,13 @@ 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; @@ -12275,6 +12282,9 @@ qemuDomainStorageOpenStat(virQEMUDriverPtr driver, return -1; } } else { + if (skipInaccessible && virStorageFileSupportsBackingChainTraversal(src) <= 0) + return 0; + if (virStorageFileInitAs(src, cfg->user, cfg->group) < 0) return -1; @@ -12286,7 +12296,7 @@ qemuDomainStorageOpenStat(virQEMUDriverPtr driver, } } - return 0; + return 1; } @@ -12321,7 +12331,7 @@ qemuDomainStorageUpdatePhysical(virQEMUDriverPtr driver, 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); @@ -12372,7 +12382,7 @@ qemuStorageLimitsRefresh(virQEMUDriverPtr driver, 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)) { -- GitLab