Re: [PATCH v2.1 16/21] Add a new function vshPrintPinInfo.

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

 



On Tue, Aug 21, 2012 at 05:18:39PM +0800, Hu Tao wrote:
> This is a helper function to print vcpu pin info.
> ---
>  tools/virsh-domain.c |   65 ++++++++++++++++++++++++++++++++------------------
>  1 file changed, 42 insertions(+), 23 deletions(-)
> 
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index 94ac1aa..047d374 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -4525,6 +4525,45 @@ static const vshCmdOptDef opts_vcpupin[] = {
>      {NULL, 0, 0, NULL}
>  };
>  
> +/*
> + * Helper function to print vcpupin info.
> + */
> +static bool
> +vshPrintPinInfo(unsigned char *cpumaps, size_t cpumaplen,
> +                int maxcpu, int vcpuindex)
> +{
> +    int cpu, lastcpu;
> +    bool bit, lastbit, isInvert;
> +
> +    if (!cpumaps || cpumaplen <= 0 || maxcpu <= 0 || vcpuindex < 0) {
> +        return false;
> +    }
> +
> +    bit = lastbit = isInvert = false;
> +    lastcpu = -1;
> +
> +    for (cpu = 0; cpu < maxcpu; cpu++) {
> +        bit = VIR_CPU_USABLE(cpumaps, cpumaplen, vcpuindex, cpu);
> +
> +        isInvert = (bit ^ lastbit);
> +        if (bit && isInvert) {
> +            if (lastcpu == -1)
> +                vshPrint(ctl, "%d", cpu);
> +            else
> +                vshPrint(ctl, ",%d", cpu);
> +            lastcpu = cpu;
> +        }
> +        if (!bit && isInvert && lastcpu != cpu - 1)
> +            vshPrint(ctl, "-%d", cpu - 1);
> +        lastbit = bit;
> +    }
> +    if (bit && !isInvert) {
> +        vshPrint(ctl, "-%d", maxcpu - 1);
> +    }
> +
> +    return true;
> +}
> +
>  static bool
>  cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
>  {
> @@ -4537,7 +4576,6 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
>      unsigned char *cpumap = NULL;
>      unsigned char *cpumaps = NULL;
>      size_t cpumaplen;
> -    bool bit, lastbit, isInvert;
>      int i, cpu, lastcpu, maxcpu, ncpus;
>      bool unuse = false;
>      const char *cur;
> @@ -4622,30 +4660,11 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
>                 if (vcpu != -1 && i != vcpu)
>                     continue;
>  
> -               bit = lastbit = isInvert = false;
> -               lastcpu = -1;
> -
>                 vshPrint(ctl, "%4d: ", i);
> -               for (cpu = 0; cpu < maxcpu; cpu++) {
> -
> -                   bit = VIR_CPU_USABLE(cpumaps, cpumaplen, i, cpu);
> -
> -                   isInvert = (bit ^ lastbit);
> -                   if (bit && isInvert) {
> -                       if (lastcpu == -1)
> -                           vshPrint(ctl, "%d", cpu);
> -                       else
> -                           vshPrint(ctl, ",%d", cpu);
> -                       lastcpu = cpu;
> -                   }
> -                   if (!bit && isInvert && lastcpu != cpu - 1)
> -                       vshPrint(ctl, "-%d", cpu - 1);
> -                   lastbit = bit;
> -               }
> -               if (bit && !isInvert) {
> -                  vshPrint(ctl, "-%d", maxcpu - 1);
> -               }
> +               ret = vshPrintPinInfo(cpumaps, cpumaplen, maxcpu, i);
>                 vshPrint(ctl, "\n");
> +               if (!ret)
> +                   break;
>              }
>  
>          } else {

  Okay, just a bit of refactoring, ACK

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel@xxxxxxxxxxxx  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

--
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]