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

Re: [PATCH v5 1/6] tools/cpupools: Give a name to unnamed cpupools


  • To: Luca Fancellu <luca.fancellu@xxxxxxx>
  • From: Anthony PERARD <anthony.perard@xxxxxxxxxx>
  • Date: Wed, 6 Apr 2022 15:55:43 +0100
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: <xen-devel@xxxxxxxxxxxxxxxxxxxx>, <bertrand.marquis@xxxxxxx>, <wei.chen@xxxxxxx>, Wei Liu <wl@xxxxxxx>, Juergen Gross <jgross@xxxxxxxx>
  • Delivery-date: Wed, 06 Apr 2022 14:56:04 +0000
  • Ironport-data: A9a23:+gYqy6ne+v2w8lBjcK70KXro5gxGJkRdPkR7XQ2eYbSJt1+Wr1Gzt xIXW2+Ha6uOYGb2edB+PNnk904C6JXRztZmTQJo/yE9HiMWpZLJC+rCIxarNUt+DCFioGGLT Sk6QoOdRCzhZiaE/n9BCpC48T8kk/vgqoPUUIYoAAgoLeNfYHpn2EoLd9IR2NYy24DlW13V4 7senuWEULOb828sWo4rw/rrRCNH5JwebxtB4zTSzdgS1LPvvyF94KA3fMldHFOhKmVgJcaoR v6r8V2M1jixEyHBqD+Suu2TnkUiGtY+NOUV45Zcc/DKbhNq/kTe3kunXRa1hIg+ZzihxrhMJ NtxWZOYVgUpA4ucxN0maSJZTydsbZF596eYCC3q2SCT5xWun3rExvxvCAc9PJEC+/YxCmZLn RAaAGlTNFbZ3bvwme/lDLk37iggBJCD0Ic3s3d8zTbfHLA+TIrKWani7t5ExjYgwMtJGJ4yY uJHOWM/NEqeP3WjPH8eS4sYgMGK2kD+bjFahknJnvY68TTcmVkZPL/Fb4OOJ43iqd9utlmVp yTN/2n/KhgAMZqUzj/t2m2orv/Cm2X8Qo16PL+37Plxm3WI23ceThYRUDOTpeSygwiwUtRUJ kgQ5wInt610/0uuJvHtUhv9rHOasxo0X9tLD/Z8+AyL0rDT4QuSGi4DVDEpQNYrrtMsTDomk FqAhcr0BCdHuaeQD3ma89+pQSiaYHZPazVYPGldEFVDs4KLTJwPYgznUdRjLYjl0uTOIwrxn zaY/BQBiK1MpJtev0mkxmzvjzWpr5nPawc64ATLQ26ohj9EiJ6Zi5+AsgaCs6sZRGqNZhzY5 SVfxZDChAwbJcvV/BFhVtnhC11ACxytFDTHyWBiEJA6n9hG0y7yJNsAiN2SyaoADyrlRdMLS BKL0e+yzMUKVJdPUUORS9jvYyjN5fK9fekJrtiOMrJzjmFZLWdrBh1Ga0+KxHzKm0Mxi6w5M przWZ/yUSdDWfg3nGrmGLx1PVoXKsYWnz27qXfTlUrP7FZjTCTNFedt3KWmMIjVE59oUC2Kq o0CZqNmOj1UUfHkYzm/zGLgBQtiEJTPPriv85Y/XrfaemJOQTh9Y9eMkeJJU9E0xMx9y7aXl kxRr2cFkTITc1Wccl7UAp2iAZuyNatCQYUTZnV2Zwv3giR9Ou5CLs43LvMKQFXuz8Q7pdYcc hXPU5/ZahiTYlwrIwggUKQ=
  • Ironport-hdrordr: A9a23:ErGQoakK8SSytw+n7cqRWIkKyq/pDfIC3DAbv31ZSRFFG/Fwz/ re+MjzpiWE7wr5OUtQ4+xoV5PhfZqxz/NICMwqTNKftWrdyRaVxeNZnOjfKlTbckWUnNK1l5 0QEZSWY+eeMbEOt6fHCX6DferIruPqzEniv5a5854kd3ASV0l3hz0JcjpzPHcGPzV7OQ==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Luca,

On Tue, Apr 05, 2022 at 09:57:36AM +0100, Luca Fancellu wrote:
> diff --git a/tools/helpers/xen-init-dom0.c b/tools/helpers/xen-init-dom0.c
> index c99224a4b607..84286617790f 100644
> --- a/tools/helpers/xen-init-dom0.c
> +++ b/tools/helpers/xen-init-dom0.c
> @@ -43,7 +43,9 @@ int main(int argc, char **argv)
>      int rc;
>      struct xs_handle *xsh = NULL;
>      xc_interface *xch = NULL;
> -    char *domname_string = NULL, *domid_string = NULL;
> +    char *domname_string = NULL, *domid_string = NULL, *pool_path, 
> *pool_name;
> +    xc_cpupoolinfo_t *xcinfo;
> +    unsigned int pool_id = 0;
>      libxl_uuid uuid;
>  
>      /* Accept 0 or 1 argument */
> @@ -114,6 +116,37 @@ int main(int argc, char **argv)
>          goto out;
>      }
>  
> +    /* Create an entry in xenstore for each cpupool on the system */
> +    do {
> +        xcinfo = xc_cpupool_getinfo(xch, pool_id);
> +        if (xcinfo != NULL) {
> +            if (xcinfo->cpupool_id != pool_id)
> +                pool_id = xcinfo->cpupool_id;
> +            xc_cpupool_infofree(xch, xcinfo);
> +            if (asprintf(&pool_path, "/local/pool/%d/name", pool_id) <= 0) {
> +                fprintf(stderr, "cannot allocate memory for pool path\n");
> +                rc = 1;
> +                goto out;
> +            }
> +            if (asprintf(&pool_name, "Pool-%d", pool_id) <= 0) {
> +                fprintf(stderr, "cannot allocate memory for pool name\n");
> +                rc = 1;
> +                goto out_err;

Could you rework this loop so that "goto out" is always the right things
to do in case of error? That is the function would always free()
"pool_path" and "pool_name" regardless of their values, and we only need
to make sure both are NULL when they are already free. This is to avoid
having several path in case of error, as this could result in mistake
later. If there's only one error path, there will be less likely to have
mistakes. This loop, at the moment, is using three different error
paths: "goto out", "goto out_err", and no goto followed by a standalone
goto.

> +            }
> +            pool_id++;
> +            if (!xs_write(xsh, XBT_NULL, pool_path, pool_name,
> +                          strlen(pool_name))) {
> +                fprintf(stderr, "cannot set pool name\n");
> +                rc = 1;
> +            }
> +            free(pool_name);
> +out_err:
> +            free(pool_path);
> +            if ( rc )
> +                goto out;
> +        }
> +    } while(xcinfo != NULL);

Thanks,

-- 
Anthony PERARD



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.