[libvirt PATCH 0/2] quieten virSCSIHostGetUniqueId

Suppress some possible errors if the device was unplugged during our probing. https://bugzilla.redhat.com/show_bug.cgi?id=1692100 Ján Tomko (2): util: use g_autofree in virSCSIHostGetUniqueId util: quieten virSCSIHostGetUniqueId src/util/virscsihost.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/virscsihost.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/util/virscsihost.c b/src/util/virscsihost.c index c259e63000..4d314c3ceb 100644 --- a/src/util/virscsihost.c +++ b/src/util/virscsihost.c @@ -46,17 +46,16 @@ int virSCSIHostGetUniqueId(const char *sysfs_prefix, int host) { - char *sysfs_path = NULL; + g_autofree char *sysfs_path = NULL; char *p = NULL; - int ret = -1; - char *buf = NULL; + g_autofree char *buf = NULL; int unique_id; sysfs_path = g_strdup_printf("%s/host%d/unique_id", sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH, host); if (virFileReadAll(sysfs_path, 1024, &buf) < 0) - goto cleanup; + return -1; if ((p = strchr(buf, '\n'))) *p = '\0'; @@ -65,15 +64,10 @@ virSCSIHostGetUniqueId(const char *sysfs_prefix, virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to parse unique_id: %s"), buf); - goto cleanup; + return -1; } - ret = unique_id; - - cleanup: - VIR_FREE(sysfs_path); - VIR_FREE(buf); - return ret; + return unique_id; } -- 2.26.2

The only caller of this function ignores failure and just sets the unique_id to -1. Failing to read the file is likely to the device no longer being present, not a real error. Stop reporting errors in this function. https://bugzilla.redhat.com/show_bug.cgi?id=1692100 Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/virscsihost.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/virscsihost.c b/src/util/virscsihost.c index 4d314c3ceb..969cdd9f79 100644 --- a/src/util/virscsihost.c +++ b/src/util/virscsihost.c @@ -41,6 +41,8 @@ VIR_LOG_INIT("util.scsi_host"); * Read the value of the "scsi_host" unique_id file. * * Returns the value on success or -1 on failure. + * + * No errors are reported. */ int virSCSIHostGetUniqueId(const char *sysfs_prefix, @@ -54,16 +56,14 @@ virSCSIHostGetUniqueId(const char *sysfs_prefix, sysfs_path = g_strdup_printf("%s/host%d/unique_id", sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH, host); - if (virFileReadAll(sysfs_path, 1024, &buf) < 0) + if (virFileReadAllQuiet(sysfs_path, 1024, &buf) < 0) return -1; if ((p = strchr(buf, '\n'))) *p = '\0'; if (virStrToLong_i(buf, NULL, 10, &unique_id) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unable to parse unique_id: %s"), buf); - + VIR_DEBUG("unable to parse unique_id: '%s'", buf); return -1; } -- 2.26.2

On Wed, Nov 04, 2020 at 01:00:59PM +0100, Ján Tomko wrote:
Suppress some possible errors if the device was unplugged during our probing.
Reviewed-by: Erik Skultety <eskultet@redhat.com>
participants (2)
-
Erik Skultety
-
Ján Tomko