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

Re: [PATCH v3 1/3] tools: Modify single-domid callers of xc_domain_getinfolist()


  • To: Alejandro Vallejo <alejandro.vallejo@xxxxxxxxx>
  • From: Anthony PERARD <anthony.perard@xxxxxxxxxx>
  • Date: Wed, 3 May 2023 17:36:32 +0100
  • Authentication-results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Christian Lindig <christian.lindig@xxxxxxxxxx>
  • Delivery-date: Wed, 03 May 2023 16:36:54 +0000
  • Ironport-data: A9a23:2+qypa7/vQ6LiBpupMMRbwxRtDjHchMFZxGqfqrLsTDasY5as4F+v jEaXWmFPamLMGP2eNlxb4u/oExQ6seAzNFiGQc6/3wyHi5G8cbLO4+Ufxz6V8+wwm8vb2o8t plDNYOQRCwQZiWBzvt4GuG59RGQ7YnRGvynTraCYnsrLeNdYH9JoQp5nOIkiZJfj9G8Agec0 fv/uMSaM1K+s9JOGjt8B5mr9VU+7ZwehBtC5gZlPa0T5weE/5UoJMl3yZ+ZfiOQrrZ8RoZWd 86bpJml82XQ+QsaC9/Nut4XpWVTH9Y+lSDX4pZnc/DKbipq/0Te4Y5iXBYoUm9Fii3hojxE4 I4lWapc6+seFvakdOw1C3G0GszlVEFM0OevzXOX6aR/w6BaGpdFLjoH4EweZOUlFuhL7W5m3 /s8OTUIUUm/hfOHy52hdsBUm+smFZy+VG8fkikIITDxCP8nRdbIQrnQ5M8e1zA17ixMNa+AP YxDM2MpNUmeJUQVYT/7C7pn9AusrnD5bz1frkPTvact6nLf5AdwzKLsIJzefdniqcB9xx7I/ z+cpTqoav0cHPKw9gLb+UywvMLKzXndSdhCJqK4+sc/1TV/wURMUUZLBDNXu8KRmkO4Ht5SN UEQ0i4vtrQpslymSMHnWB+1q2LCuQQTM/JPF8Uq5QfLzbDbiy6bCXIDVSVpc8E9uYk9QjlC/ laRksngHzBHrLyfQnXb/bCRxQ5eIgBMczVEP3VdC1JYvZ+6+tpbYg/zoshLOqmRn9jwJmjMw SG7pwcku5wrkOEO7vDulbzYuA5AtqQlXyZsuFWMBjv/vlwmDGK2T9f2sAaGtJ6sOK7cFwDc5 yZcxqBy+chUVfmweDqxrPLh9V1Dz9KMK3XijFFmBPHNHBz9qif4Lei8DNyTTXqF0/romhezO ic/QSsLuPdu0IKCNMebmb6ZBcUw1rTHHt/4TP3SZdcmSsEvJFTfoXozPBTKhjCFfK0QrE3CE c3DLZbE4YgyUMyLMwZat89CiOR2l0jSNEvYRIzhzgTP7IdykEW9EO9fWHPXN7BR0U9xiFmNm zqpH5fQmko3vSyXSnW/zLP/2nhTdyhnWcyo9JYLHgNBSyI/cFwc5zbq6etJU+RYc259z48kI lnVtpdk9WfC
  • Ironport-hdrordr: A9a23:8qq0Pa4hEe/l+tfyLQPXwAzXdLJyesId70hD6qkQc3Fom62j5q WTdZEgvyMc5wx/ZJhNo7690cq7MBHhHPxOgbX5VI3KNGXbUQOTR72KhrGSoAEIdReeygZcv5 0QCZSXCrfLfCVHZRCR2njFLz4iquP3j5xBnY3lvhNQpZkBUdAZ0+9+YDzrdXFedU19KrcSMo GT3cZDryrIQwVtUizqbkN1OdQqvrfw5evbXSI=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Tue, May 02, 2023 at 12:13:36PM +0100, Alejandro Vallejo wrote:
> diff --git a/tools/libs/light/libxl_domain.c b/tools/libs/light/libxl_domain.c
> index 7f0986c185..5709b3e62f 100644
> --- a/tools/libs/light/libxl_domain.c
> +++ b/tools/libs/light/libxl_domain.c
> @@ -349,16 +349,12 @@ int libxl_domain_info(libxl_ctx *ctx, libxl_dominfo 
> *info_r,
>      int ret;
>      GC_INIT(ctx);
>  
> -    ret = xc_domain_getinfolist(ctx->xch, domid, 1, &xcinfo);
> +    ret = xc_domain_getinfo_single(ctx->xch, domid, &xcinfo);
>      if (ret<0) {
> -        LOGED(ERROR, domid, "Getting domain info list");
> +        LOGED(ERROR, domid, "Getting domain info");
>          GC_FREE;
>          return ERROR_FAIL;
>      }
> -    if (ret==0 || xcinfo.domain != domid) {
> -        GC_FREE;
> -        return ERROR_DOMAIN_NOTFOUND;

I kind of think we should keep returning ERROR_DOMAIN_NOTFOUND on error
as this is the most likely explanation. Also, the comment for this
function in libxl.h explain this:
    /* May be called with info_r == NULL to check for domain's existence.
     * Returns ERROR_DOMAIN_NOTFOUND if domain does not exist (used to return
     * ERROR_INVAL for this scenario). */
    int libxl_domain_info(libxl_ctx*, libxl_dominfo *info_r,
                          uint32_t domid);

Would it be possible to find out from xc_domain_getinfo_single() if it's
a domain not found scenario vs other error (like permission denied)?

> -    }
>  
>      if (info_r)
>          libxl__xcinfo2xlinfo(ctx, &xcinfo, info_r);
> @@ -1657,14 +1653,15 @@ int libxl__resolve_domid(libxl__gc *gc, const char 
> *name, uint32_t *domid)
>  libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
>                                         int *nr_vcpus_out, int *nr_cpus_out)
>  {
> +    int rc;
>      GC_INIT(ctx);
>      libxl_vcpuinfo *ptr, *ret;
>      xc_domaininfo_t domaininfo;
>      xc_vcpuinfo_t vcpuinfo;
>      unsigned int nr_vcpus;
>  
> -    if (xc_domain_getinfolist(ctx->xch, domid, 1, &domaininfo) != 1) {
> -        LOGED(ERROR, domid, "Getting infolist");
> +    if ((rc = xc_domain_getinfo_single(ctx->xch, domid, &domaininfo)) < 0) {

The variable name "rc" is reserved for libxl return code. For syscall
and other external call, we should use the name "r". (I know that in
other part of this patch the name used is "ret", but as it is already
existing in the code base, I'm not asking for a change elsewhere)

Also, assignment to the variable should be done outside of the if(). So
the new code should look like:

    r = xc_domain_getinfolist(...);
    if (r < 0) {

(There's tools/libs/light/CODING_STYLE for all this explained)

> +        LOGED(ERROR, domid, "Getting dominfo");
>          GC_FREE;
>          return NULL;
>      }
> diff --git a/tools/libs/light/libxl_sched.c b/tools/libs/light/libxl_sched.c
> index 7c53dc60e6..21a65442c0 100644
> --- a/tools/libs/light/libxl_sched.c
> +++ b/tools/libs/light/libxl_sched.c
> @@ -219,13 +219,11 @@ static int sched_credit_domain_set(libxl__gc *gc, 
> uint32_t domid,
>      xc_domaininfo_t domaininfo;
>      int rc;
>  
> -    rc = xc_domain_getinfolist(CTX->xch, domid, 1, &domaininfo);
> +    rc = xc_domain_getinfo_single(CTX->xch, domid, &domaininfo);
>      if (rc < 0) {
> -        LOGED(ERROR, domid, "Getting domain info list");
> +        LOGED(ERROR, domid, "Getting domain info");
>          return ERROR_FAIL;
>      }
> -    if (rc != 1 || domaininfo.domain != domid)
> -        return ERROR_INVAL;

We can probably return ERROR_INVAL on error instead of ERROR_FAIL, as I
guess it's more likely that we try to change a non-existing domain
rather than having another error.

>  
>      rc = xc_sched_credit_domain_get(CTX->xch, domid, &sdom);
>      if (rc != 0) {
> @@ -426,13 +424,11 @@ static int sched_credit2_domain_set(libxl__gc *gc, 
> uint32_t domid,
>      xc_domaininfo_t info;
>      int rc;
>  
> -    rc = xc_domain_getinfolist(CTX->xch, domid, 1, &info);
> +    rc = xc_domain_getinfo_single(CTX->xch, domid, &info);
>      if (rc < 0) {
>          LOGED(ERROR, domid, "Getting domain info");
>          return ERROR_FAIL;

dito.

>      }
> -    if (rc != 1 || info.domain != domid)
> -        return ERROR_INVAL;
>  
>      rc = xc_sched_credit2_domain_get(CTX->xch, domid, &sdom);
>      if (rc != 0) {


Thanks,

-- 
Anthony PERARD



 


Rackspace

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