Re: [PATCH] util: Fix a bug in virResctrlMonitorGetStats

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 11/19/18 9:10 PM, Wang Huaqiang wrote:
> The path argument of virFileIsDir should be a full name
> of file, pathname and filename. Fixed it by passing the
> full path name to virFileIsDir.
> 
> Signed-off-by: Wang Huaqiang <huaqiang.wang@xxxxxxxxx>
> ---
>  src/util/virresctrl.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
> index 7aeca9d..e0ad460 100644
> --- a/src/util/virresctrl.c
> +++ b/src/util/virresctrl.c
> @@ -2665,6 +2665,7 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
>      int ret = -1;
>      DIR *dirp = NULL;
>      char *datapath = NULL;
> +    char *filepath = NULL;
>      struct dirent *ent = NULL;
>      virResctrlMonitorStatsPtr stat = NULL;
>  
> @@ -2684,13 +2685,18 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
>      while (virDirRead(dirp, &ent, datapath) > 0) {
>          char *node_id = NULL;
>  
> +        VIR_FREE(filepath);
> +
>          /* Looking for directory that contains resource utilization
>           * information file. The directory name is arranged in format
>           * "mon_<node_name>_<node_id>". For example, "mon_L3_00" and
>           * "mon_L3_01" are two target directories for a two nodes system
>           * with resource utilization data file for each node respectively.
>           */
> -        if (!virFileIsDir(ent->d_name))
> +        if (virAsprintf(&filepath, "%s/%s", datapath, ent->d_name) < 0);

This didn't compile...  But easily fixed. when removing the ;

> +            goto cleanup;
> +
> +        if (!virFileIsDir(filepath))
>              continue;
>  
>          /* Looking for directory has a prefix 'mon_L' */
> @@ -2734,6 +2740,7 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
>      ret = 0;
>   cleanup:
>      VIR_FREE(datapath);
> +    VIR_FREE(filepath);
>      VIR_FREE(stat);
>      VIR_DIR_CLOSE(dirp);
>      return ret;
> 

Usage of virFileIsDir straight is my mistake because of the build error
on some odd platform when using- "if (ent->d_type != DT_DIR)"...

Reviewed-by: John Ferlan <jferlan@xxxxxxxxxx>
(and pushed)

Tks -

John

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux