From d108926463da19a2b025c845c60cfd78da850291 Mon Sep 17 00:00:00 2001 Message-Id: From: Peter Krempa Date: Fri, 16 Aug 2019 14:36:54 +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 (cherry picked from commit ba6c12df2ceb4df9bfb7ce95deef04f96bf29462) https: //bugzilla.redhat.com/show_bug.cgi?id=1724808 Message-Id: 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 8ecdcf3440..91eeb05319 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11778,6 +11778,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. @@ -11785,7 +11786,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, @@ -11793,9 +11796,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; @@ -11806,6 +11813,9 @@ qemuDomainStorageOpenStat(virQEMUDriverPtr driver, return -1; } } else { + if (skipInaccessible && virStorageFileSupportsBackingChainTraversal(src) <= 0) + return 0; + if (virStorageFileInitAs(src, cfg->user, cfg->group) < 0) return -1; @@ -11817,7 +11827,7 @@ qemuDomainStorageOpenStat(virQEMUDriverPtr driver, } } - return 0; + return 1; } @@ -11852,7 +11862,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); @@ -11903,7 +11913,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)) { -- 2.22.1