diff mbox series

[RFC,2/2] tools/cpupools: Give a name to unnamed cpupools

Message ID 20211117095711.26596-3-luca.fancellu@arm.com (mailing list archive)
State Superseded
Headers show
Series Boot time cpupools | expand

Commit Message

Luca Fancellu Nov. 17, 2021, 9:57 a.m. UTC
With the introduction of boot time cpupools, Xen can
create at boot time many cpupools different from the
cpupool with id 0.

Since these newly created cpupools can't have an
entry in Xenstore, name them with the same convention
used for the cpupool 0: Pool-<cpupool id>.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
---
 tools/libs/light/libxl_utils.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

Jürgen Groß Nov. 17, 2021, 11:10 a.m. UTC | #1
On 17.11.21 10:57, Luca Fancellu wrote:
> With the introduction of boot time cpupools, Xen can
> create at boot time many cpupools different from the
> cpupool with id 0.
> 
> Since these newly created cpupools can't have an
> entry in Xenstore, name them with the same convention
> used for the cpupool 0: Pool-<cpupool id>.
> 
> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
> ---
>   tools/libs/light/libxl_utils.c | 13 ++++++++-----
>   1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/libs/light/libxl_utils.c b/tools/libs/light/libxl_utils.c
> index 4699c4a0a3..d97d91ca98 100644
> --- a/tools/libs/light/libxl_utils.c
> +++ b/tools/libs/light/libxl_utils.c
> @@ -147,13 +147,16 @@ int libxl_cpupool_qualifier_to_cpupoolid(libxl_ctx *ctx, const char *p,
>   char *libxl_cpupoolid_to_name(libxl_ctx *ctx, uint32_t poolid)
>   {
>       unsigned int len;
> -    char path[strlen("/local/pool") + 12];
> +    char buffer[strlen("/local/pool") + 12];
>       char *s;
>   
> -    snprintf(path, sizeof(path), "/local/pool/%d/name", poolid);
> -    s = xs_read(ctx->xsh, XBT_NULL, path, &len);
> -    if (!s && (poolid == 0))
> -        return strdup("Pool-0");
> +    snprintf(buffer, sizeof(buffer), "/local/pool/%d/name", poolid);
> +    s = xs_read(ctx->xsh, XBT_NULL, buffer, &len);
> +    if (!s)
> +    {
> +        snprintf(buffer, sizeof(buffer), "Pool-%d", poolid);
> +        return strdup(buffer);
> +    }
>       return s;
>   }
>   
> 

This breaks libxl_cpupoolid_is_valid(), as it will now return always
true, regardless whether the poolid is existing or not.


Juergen
Luca Fancellu Nov. 17, 2021, 11:52 a.m. UTC | #2
> On 17 Nov 2021, at 11:10, Juergen Gross <jgross@suse.com> wrote:
> 
> On 17.11.21 10:57, Luca Fancellu wrote:
>> With the introduction of boot time cpupools, Xen can
>> create at boot time many cpupools different from the
>> cpupool with id 0.
>> Since these newly created cpupools can't have an
>> entry in Xenstore, name them with the same convention
>> used for the cpupool 0: Pool-<cpupool id>.
>> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
>> ---
>>  tools/libs/light/libxl_utils.c | 13 ++++++++-----
>>  1 file changed, 8 insertions(+), 5 deletions(-)
>> diff --git a/tools/libs/light/libxl_utils.c b/tools/libs/light/libxl_utils.c
>> index 4699c4a0a3..d97d91ca98 100644
>> --- a/tools/libs/light/libxl_utils.c
>> +++ b/tools/libs/light/libxl_utils.c
>> @@ -147,13 +147,16 @@ int libxl_cpupool_qualifier_to_cpupoolid(libxl_ctx *ctx, const char *p,
>>  char *libxl_cpupoolid_to_name(libxl_ctx *ctx, uint32_t poolid)
>>  {
>>      unsigned int len;
>> -    char path[strlen("/local/pool") + 12];
>> +    char buffer[strlen("/local/pool") + 12];
>>      char *s;
>>  -    snprintf(path, sizeof(path), "/local/pool/%d/name", poolid);
>> -    s = xs_read(ctx->xsh, XBT_NULL, path, &len);
>> -    if (!s && (poolid == 0))
>> -        return strdup("Pool-0");
>> +    snprintf(buffer, sizeof(buffer), "/local/pool/%d/name", poolid);
>> +    s = xs_read(ctx->xsh, XBT_NULL, buffer, &len);
>> +    if (!s)
>> +    {
>> +        snprintf(buffer, sizeof(buffer), "Pool-%d", poolid);
>> +        return strdup(buffer);
>> +    }
>>      return s;
>>  }
>>  
> 
> This breaks libxl_cpupoolid_is_valid(), as it will now return always
> true, regardless whether the poolid is existing or not.

Hi Juergen,

Yes right, do you think I can use safely xc_cpupool_getinfo(…) when there is no entry
in xenstore?
I would check that the returned cpupool id is the same and if it isn’t or if I get a null
result, then I will return NULL to ensure libxl_cpupoolid_is_valid(…) works again.

Cheers,
Luca

> 
> 
> Juergen
> <OpenPGP_0xB0DE9DD628BF132F.asc>
Jürgen Groß Nov. 17, 2021, 12:06 p.m. UTC | #3
On 17.11.21 12:52, Luca Fancellu wrote:
> 
> 
>> On 17 Nov 2021, at 11:10, Juergen Gross <jgross@suse.com> wrote:
>>
>> On 17.11.21 10:57, Luca Fancellu wrote:
>>> With the introduction of boot time cpupools, Xen can
>>> create at boot time many cpupools different from the
>>> cpupool with id 0.
>>> Since these newly created cpupools can't have an
>>> entry in Xenstore, name them with the same convention
>>> used for the cpupool 0: Pool-<cpupool id>.
>>> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
>>> ---
>>>   tools/libs/light/libxl_utils.c | 13 ++++++++-----
>>>   1 file changed, 8 insertions(+), 5 deletions(-)
>>> diff --git a/tools/libs/light/libxl_utils.c b/tools/libs/light/libxl_utils.c
>>> index 4699c4a0a3..d97d91ca98 100644
>>> --- a/tools/libs/light/libxl_utils.c
>>> +++ b/tools/libs/light/libxl_utils.c
>>> @@ -147,13 +147,16 @@ int libxl_cpupool_qualifier_to_cpupoolid(libxl_ctx *ctx, const char *p,
>>>   char *libxl_cpupoolid_to_name(libxl_ctx *ctx, uint32_t poolid)
>>>   {
>>>       unsigned int len;
>>> -    char path[strlen("/local/pool") + 12];
>>> +    char buffer[strlen("/local/pool") + 12];
>>>       char *s;
>>>   -    snprintf(path, sizeof(path), "/local/pool/%d/name", poolid);
>>> -    s = xs_read(ctx->xsh, XBT_NULL, path, &len);
>>> -    if (!s && (poolid == 0))
>>> -        return strdup("Pool-0");
>>> +    snprintf(buffer, sizeof(buffer), "/local/pool/%d/name", poolid);
>>> +    s = xs_read(ctx->xsh, XBT_NULL, buffer, &len);
>>> +    if (!s)
>>> +    {
>>> +        snprintf(buffer, sizeof(buffer), "Pool-%d", poolid);
>>> +        return strdup(buffer);
>>> +    }
>>>       return s;
>>>   }
>>>   
>>
>> This breaks libxl_cpupoolid_is_valid(), as it will now return always
>> true, regardless whether the poolid is existing or not.
> 
> Hi Juergen,
> 
> Yes right, do you think I can use safely xc_cpupool_getinfo(…) when there is no entry
> in xenstore?
> I would check that the returned cpupool id is the same and if it isn’t or if I get a null
> result, then I will return NULL to ensure libxl_cpupoolid_is_valid(…) works again.

An alternative might be to let tools/helpers/xen-init-dom0.c let write
the missing cpupool entries (including for Pool-0) and drop the
poolid == 0 special casing from libxl_cpupoolid_to_name().

This should be rather easy by using xc_cpupool_getinfo() until it finds
no further cpupool.


Juergen
diff mbox series

Patch

diff --git a/tools/libs/light/libxl_utils.c b/tools/libs/light/libxl_utils.c
index 4699c4a0a3..d97d91ca98 100644
--- a/tools/libs/light/libxl_utils.c
+++ b/tools/libs/light/libxl_utils.c
@@ -147,13 +147,16 @@  int libxl_cpupool_qualifier_to_cpupoolid(libxl_ctx *ctx, const char *p,
 char *libxl_cpupoolid_to_name(libxl_ctx *ctx, uint32_t poolid)
 {
     unsigned int len;
-    char path[strlen("/local/pool") + 12];
+    char buffer[strlen("/local/pool") + 12];
     char *s;
 
-    snprintf(path, sizeof(path), "/local/pool/%d/name", poolid);
-    s = xs_read(ctx->xsh, XBT_NULL, path, &len);
-    if (!s && (poolid == 0))
-        return strdup("Pool-0");
+    snprintf(buffer, sizeof(buffer), "/local/pool/%d/name", poolid);
+    s = xs_read(ctx->xsh, XBT_NULL, buffer, &len);
+    if (!s)
+    {
+        snprintf(buffer, sizeof(buffer), "Pool-%d", poolid);
+        return strdup(buffer);
+    }
     return s;
 }