[libvirt] [PATCH 4/4] Report one error less when getting net dev speed
Michal Privoznik
mprivozn at redhat.com
Tue Jul 1 14:15:21 UTC 2014
On 30.06.2014 15:38, Ján Tomko wrote:
> virFileReadAll already logs an error. If reading the 'speed' file
> fails with EINVAL, we log an error even though we ignore it. If it
> fails with other errors, we log two errors.
>
> Use virFileReadAllQuiet - ignore EINVAL and report just one error
> in other cases.
>
> Fixes this error on libvirtd startup:
> 2014-06-30 12:47:14.583+0000: 20971: error : virFileReadAll:1297 :
> Failed to read file '/sys/class/net/wlan0/speed': Invalid argument
> ---
> src/util/virnetdev.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
> index a551f98..c3a7384 100644
> --- a/src/util/virnetdev.c
> +++ b/src/util/virnetdev.c
> @@ -1844,6 +1844,7 @@ virNetDevGetLinkInfo(const char *ifname,
> char *tmp;
> int tmp_state;
> unsigned int tmp_speed;
> + int rc;
There's no need for this new variable, virFileReadAAllQuiet will set
errno too.
>
> if (virNetDevSysfsFile(&path, ifname, "operstate") < 0)
> goto cleanup;
> @@ -1891,13 +1892,13 @@ virNetDevGetLinkInfo(const char *ifname,
> if (virNetDevSysfsFile(&path, ifname, "speed") < 0)
> goto cleanup;
>
> - if (virFileReadAll(path, 1024, &buf) < 0) {
In fact, simple s/virFileReadAll/virFileReadAllQuiet/ would suffice as well.
> + if ((rc = virFileReadAllQuiet(path, 1024, &buf)) < 0) {
> /* Some devices doesn't report speed, in which case we get EINVAL */
> - if (errno == EINVAL) {
> + if (-rc == EINVAL) {
> ret = 0;
> goto cleanup;
> }
> - virReportSystemError(errno,
> + virReportSystemError(-rc,
> _("unable to read: %s"),
> path);
> goto cleanup;
>
Michal
More information about the libvir-list
mailing list