Skip to contentSkip to conversation

tools: fixes inspired by Coverity scan

PATCH Superseded Wei Liu 5 participants 23 messages Jul 27, 2015 – Jul 28, 2015 Arm/actions semi architecture

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

v2 cover tools: fixes inspired by Coverity scan

Wei Liu (8):
libxl: properly clean up array in libxl_list_cpupool failure path
xl: lockdir should be lockfile in error message
xl: call libxl_dominfo_init in main_list
xl: valid fd can be 0 in main_loadpolicy
xl: call libxl_dominfo_{init,dispose} in main_cpupoolnumasplit
libxlu: free buffer in failure path for PCI related functions python/xc: reinstate original implementation of next_bdf
libxl: remove dead code libxl__domain_shutdown_reason

 tools/libxl/libxl.c               | 31 +++++++++++++++++++++----------
 tools/libxl/libxl_dom.c           | 17 -----------------
 tools/libxl/libxl_internal.h      |  1 -
 tools/libxl/libxlu_pci.c          |  2 ++
 tools/libxl/xl.c                  |  2 +-
 tools/libxl/xl_cmdimpl.c          | 23 +++++++++++++++++------
 tools/python/xen/lowlevel/xc/xc.c | 30 ++++++++++--------------------
 7 files changed, 51 insertions(+), 55 deletions(-)
Signature · 1 line
2.1.4
author
#1 lore raw

PATCH v2 1/8 libxl: properly clean up array in libxl_list_cpupool failure path

Document how cpupool_info works. Distinguish success (ERROR_FAIL + ENOENT) vs failure in libxl_list_cpupool and properly clean up the array in failure path.

Also switch to libxl__realloc and call libxl_cpupool_{init,dispose} where appropriate.

There is change of behaviour. Previously if memory allocation fails the said function returns NULL. Now memory allocation failure is fatal. This is in line with how we deal with memory allocation failure in other places in libxl though.

---
Cc: Dario Faggioli <[email protected]>

---
 tools/libxl/libxl.c | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)
tools/libxl/libxl.c +21 -10
index ff0d616..c3a13f6 100644
@@ -682,6 +682,11 @@ int libxl_domain_info(libxl_ctx *ctx, libxl_dominfo *info_r,
     return 0;
 }
 
+/* Returns:
+ *   0 - success
+ *   ERROR_FAIL + errno == ENOENT - no entry found
+ *   ERROR_$FOO + errno != ENOENT - other failure
+ */
 static int cpupool_info(libxl__gc *gc,
                         libxl_cpupoolinfo *info,
                         uint32_t poolid,
@@ -737,7 +742,8 @@ int libxl_cpupool_info(libxl_ctx *ctx,
 libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx *ctx, int *nb_pool_out)
 {
     GC_INIT(ctx);
-    libxl_cpupoolinfo info, *ptr, *tmp;
+    libxl_cpupoolinfo info, *ptr;
+
     int i;
     uint32_t poolid;
 
@@ -745,24 +751,29 @@ libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx *ctx, int *nb_pool_out)
 
     poolid = 0;
     for (i = 0;; i++) {
-        if (cpupool_info(gc, &info, poolid, false))
+        libxl_cpupoolinfo_init(&info);
+        if (cpupool_info(gc, &info, poolid, false)) {
+            libxl_cpupoolinfo_dispose(&info);
+            if (errno != ENOENT) goto out;
             break;
-        tmp = realloc(ptr, (i + 1) * sizeof(libxl_cpupoolinfo));
-        if (!tmp) {
-            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "allocating cpupool info");
-            libxl_cpupoolinfo_list_free(ptr, i);
-            ptr = NULL;
-            goto out;
         }
-        ptr = tmp;
+
+        ptr = libxl__realloc(NOGC, ptr, (i+1) * sizeof(libxl_cpupoolinfo));
         ptr[i] = info;
         poolid = info.poolid + 1;
+        /* Don't dispose of info because it will be returned to caller */
     }
 
     *nb_pool_out = i;
-out:
+
     GC_FREE;
     return ptr;
+
+out:
+    libxl_cpupoolinfo_list_free(ptr, i);
+    *nb_pool_out = 0;
+    GC_FREE;
+    return NULL;
 }
 
 /* this API call only list VM running on this host. A VM can
Signature · 1 line
2.1.4
Reviewed-by on v2 1/8
#2 lore raw

Re: [PATCH for-4.6 v2 1/8] libxl: properly clean up array in libxl_list_cpupool failure path

Quoted 7 lines · Wei Liu

Document how cpupool_info works. Distinguish success (ERROR_FAIL + ENOENT) vs failure in libxl_list_cpupool and properly clean up the array in failure path.

Also switch to libxl__realloc and call libxl_cpupool_{init,dispose} where appropriate.

Quoted 7 lines

There is change of behaviour. Previously if memory allocation fails the said function returns NULL. Now memory allocation failure is fatal. This is in line with how we deal with memory allocation failure in other places in libxl though.

Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by on v2 1/8
#3 lore raw

Re: [PATCH for-4.6 v2 1/8] libxl: properly clean up array in libxl_list_cpupool failure path

In reply to Wei Liu
Quoted 7 lines · Wei Liu

Document how cpupool_info works. Distinguish success (ERROR_FAIL + ENOENT) vs failure in libxl_list_cpupool and properly clean up the array in failure path.

Also switch to libxl__realloc and call libxl_cpupool_{init,dispose} where appropriate.

Quoted 6 lines

There is change of behaviour. Previously if memory allocation fails the said function returns NULL. Now memory allocation failure is fatal. This is in line with how we deal with memory allocation failure in other places in libxl though.

author
#4 lore raw

PATCH v2 2/8 xl: lockdir should be lockfile in error message

In reply to Wei Liu
---
 tools/libxl/xl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/xl.c +1 -1
index f014306..5316ad9 100644
@@ -118,7 +118,7 @@ static void parse_global_config(const char *configfile,
     }
 
     if (!lockfile) {
-        fprintf(stderr, "failed to allocate lockdir\n");
+        fprintf(stderr, "failed to allocate lockfile\n");
         exit(1);
     }
 
Signature · 1 line
2.1.4
author
#6 lore raw

PATCH v2 3/8 xl: call libxl_dominfo_init in main_list

In reply to Wei Liu

Always call init and dispose function on info_buf though it's not always used.

---
 tools/libxl/xl_cmdimpl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/libxl/xl_cmdimpl.c +4 -2
index d0bf0cb..63f80de 100644
@@ -4860,6 +4860,8 @@ int main_list(int argc, char **argv)
         break;
     }
 
+    libxl_dominfo_init(&info_buf);
+
     if (optind >= argc) {
         info = libxl_list_domain(ctx, &nb_domain);
         if (!info) {
@@ -4894,8 +4896,8 @@ int main_list(int argc, char **argv)
 
     if (info_free)
         libxl_dominfo_list_free(info, nb_domain);
-    else
-        libxl_dominfo_dispose(info);
+
+    libxl_dominfo_dispose(&info_buf);
 
     return 0;
 }
Signature · 1 line
2.1.4
author
#8 lore raw

PATCH v2 4/8 xl: valid fd can be 0 in main_loadpolicy

In reply to Wei Liu

Initialise polFd to -1 before hand to avoid closing 0 by accident.

Also fixed some style problems while I was there.

---
 tools/libxl/xl_cmdimpl.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/libxl/xl_cmdimpl.c +4 -4
index 63f80de..77cf603 100644
@@ -7859,7 +7859,7 @@ int main_setenforce(int argc, char **argv)
 int main_loadpolicy(int argc, char **argv)
 {
     const char *polFName;
-    int polFd = 0;
+    int polFd = -1;
     void *polMemCp = NULL;
     struct stat info;
     int ret;
@@ -7871,7 +7871,7 @@ int main_loadpolicy(int argc, char **argv)
 
     polFName = argv[optind];
     polFd = open(polFName, O_RDONLY);
-    if ( polFd < 0 ) {
+    if (polFd < 0) {
         fprintf(stderr, "Error occurred opening policy file '%s': %s\n",
                 polFName, strerror(errno));
         ret = -1;
@@ -7879,7 +7879,7 @@ int main_loadpolicy(int argc, char **argv)
     }
 
     ret = stat(polFName, &info);
-    if ( ret < 0 ) {
+    if (ret < 0) {
         fprintf(stderr, "Error occurred retrieving information about"
                 "policy file '%s': %s\n", polFName, strerror(errno));
         goto done;
@@ -7911,7 +7911,7 @@ int main_loadpolicy(int argc, char **argv)
 
 done:
     free(polMemCp);
-    if ( polFd > 0 )
+    if (polFd >= 0)
         close(polFd);
 
     return ret;
Signature · 1 line
2.1.4
author
#10 lore raw

PATCH v2 5/8 xl: call libxl_dominfo_{init, dispose} in main_cpupoolnumasplit

In reply to Wei Liu
---
 tools/libxl/xl_cmdimpl.c | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/libxl/xl_cmdimpl.c +9 -0
index 77cf603..70ed675 100644
@@ -7685,6 +7685,8 @@ int main_cpupoolnumasplit(int argc, char **argv)
         /* No options */
     }
 
+    libxl_dominfo_init(&info);
+
     rc = 1;
 
     libxl_bitmap_init(&cpumap);
@@ -7741,6 +7743,12 @@ int main_cpupoolnumasplit(int argc, char **argv)
         goto out;
     }
     for (c = 0; c < 10; c++) {
+        /* We've called libxl_dominfo_init before the loop and will
+         * call libxl_dominfo_dispose after the loop when we're done
+         * with info.
+         */
+        libxl_dominfo_dispose(&info);
+        libxl_dominfo_init(&info);
         if (libxl_domain_info(ctx, &info, 0)) {
             fprintf(stderr, "error on getting info for Domain-0\n");
             goto out;
@@ -7793,6 +7801,7 @@ int main_cpupoolnumasplit(int argc, char **argv)
 out:
     libxl_cputopology_list_free(topology, n_cpus);
     libxl_bitmap_dispose(&cpumap);
+    libxl_dominfo_dispose(&info);
     free(name);
 
     return rc;
Signature · 1 line
2.1.4
Reviewed-by on v2 5/8
#11 lore raw

Re: [PATCH for-4.6 v2 5/8] xl: call libxl_dominfo_{init, dispose} in main_cpupoolnumasplit

Quoted 2 lines · Wei Liu

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by on v2 5/8
#12 lore raw

Re: [PATCH for-4.6 v2 5/8] xl: call libxl_dominfo_{init, dispose} in main_cpupoolnumasplit

In reply to Wei Liu
Quoted 1 line · Wei Liu
Quoted 9 lines
---
 tools/libxl/xl_cmdimpl.c | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/libxl/xl_cmdimpl.c +0 -0
index 77cf603..70ed675 100644

tools/libxl/xl_cmdimpl.c int main_cpupoolnumasplit(int argc, char **argv) · line 7692

Quoted 8 lines
tools/libxl/xl_cmdimpl.c +2 -0
@@ -7685,6 +7685,8 @@ int main_cpupoolnumasplit(int argc, char **argv)
         /* No options */
     }
 
+    libxl_dominfo_init(&info);
+
     rc = 1;
 
     libxl_bitmap_init(&cpumap);

I'd have been inclined to init everything in one block, but nevermind.

author
#13 lore raw

PATCH v2 6/8 libxlu: free buffer in failure path for PCI related functions

In reply to Wei Liu
---
 tools/libxl/libxlu_pci.c | 2 ++
 1 file changed, 2 insertions(+)
tools/libxl/libxlu_pci.c +2 -0
index 026413b..16ddaf7 100644
@@ -178,6 +178,7 @@ int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_device_pci *pcidev, const char *str
     return 0;
 
 parse_error:
+    free(buf2);
     return ERROR_INVAL;
 }
 
@@ -254,6 +255,7 @@ int xlu_rdm_parse(XLU_Config *cfg, libxl_rdm_reserve *rdm, const char *str)
     return 0;
 
 parse_error:
+    free(buf2);
     return ERROR_INVAL;
 }
 
Signature · 1 line
2.1.4
#14 lore raw

Re: [PATCH for-4.6 v2 6/8] libxlu: free buffer in failure path for PCI related functions

Quoted 11 lines · Wei Liu
---
 tools/libxl/libxlu_pci.c | 2 ++
 1 file changed, 2 insertions(+)
tools/libxl/libxlu_pci.c +0 -0
index 026413b..16ddaf7 100644
@@ -178,6 +178,7 @@ int xlu_pci_parse_bdf(XLU_Config *cfg, 

libxl_device_pci *pcidev, const char *str

Quoted 4 lines
     return 0;

parse_error:
+ free(buf2);

There is a path (half a dozen lines above) which can do free(buf2) followed by goto parse_error. That free ought to set buf2=NULL, or the free needs to move after that check on the success path.

tools/libxl/libxlu_pci.c int xlu_rdm_parse(XLU_Config *cfg, libxl_rdm_reserve · line 259

Quoted 9 lines
     return ERROR_INVAL;

}

tools/libxl/libxlu_pci.c +1 -0
@@ -254,6 +255,7 @@ int xlu_rdm_parse(XLU_Config *cfg, libxl_rdm_reserve 
 *rdm, const char *str)
     return 0;
 
 parse_error:
+    free(buf2);

Same here.

Quoted 3 lines
tools/libxl/libxlu_pci.c +0 -0
     return ERROR_INVAL;
 }
author
#15 lore raw

PATCH v2 7/8 python/xc: reinstate original implementation of next_bdf

In reply to Wei Liu

I missed the fact that next_bdf is used to parsed user supplied strings when reviewing. The user supplied string is a NULL-terminated string separated by comma. User can supply several PCI devices in that string. There is, however, no delimiter for different devices, hence we can't change the syntax of that string.

This patch reinstate the original implementation of next_bdf to preserve the original syntax. The last argument for xc_assign_device is always 0.

---
Cc: Tiejun Chen <[email protected]>

Tiejun, are you actually using this python binding? I don't think we have in tree user.

If nobody is using it, I propose we remove this binding in next release.

I don't have live example of that string. My analysis is based on reverse-engineering of original code.

---
 tools/python/xen/lowlevel/xc/xc.c | 30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)
tools/python/xen/lowlevel/xc/xc.c +10 -20
index c8380d1..2c36eb2 100644
@@ -592,8 +592,7 @@ static int token_value(char *token)
     return strtol(token, NULL, 16);
 }
 
-static int next_bdf(char **str, int *seg, int *bus, int *dev, int *func,
-                    int *flag)
+static int next_bdf(char **str, int *seg, int *bus, int *dev, int *func)
 {
     char *token;
 
@@ -608,17 +607,8 @@ static int next_bdf(char **str, int *seg, int *bus, int *dev, int *func,
     *dev  = token_value(token);
     token = strchr(token, ',') + 1;
     *func  = token_value(token);
-    token = strchr(token, ',') + 1;
-    if ( token ) {
-        *flag = token_value(token);
-        *str = token + 1;
-    }
-    else
-    {
-        /* O means we take "strict" as our default policy. */
-        *flag = 0;
-        *str = NULL;
-    }
+    token = strchr(token, ',');
+    *str = token ? token + 1 : NULL;
 
     return 1;
 }
@@ -630,14 +620,14 @@ static PyObject *pyxc_test_assign_device(XcObject *self,
     uint32_t dom;
     char *pci_str;
     int32_t sbdf = 0;
-    int seg, bus, dev, func, flag;
+    int seg, bus, dev, func;
 
     static char *kwd_list[] = { "domid", "pci", NULL };
     if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is", kwd_list,
                                       &dom, &pci_str) )
         return NULL;
 
-    while ( next_bdf(&pci_str, &seg, &bus, &dev, &func, &flag) )
+    while ( next_bdf(&pci_str, &seg, &bus, &dev, &func) )
     {
         sbdf = seg << 16;
         sbdf |= (bus & 0xff) << 8;
@@ -663,21 +653,21 @@ static PyObject *pyxc_assign_device(XcObject *self,
     uint32_t dom;
     char *pci_str;
     int32_t sbdf = 0;
-    int seg, bus, dev, func, flag;
+    int seg, bus, dev, func;
 
     static char *kwd_list[] = { "domid", "pci", NULL };
     if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is", kwd_list,
                                       &dom, &pci_str) )
         return NULL;
 
-    while ( next_bdf(&pci_str, &seg, &bus, &dev, &func, &flag) )
+    while ( next_bdf(&pci_str, &seg, &bus, &dev, &func) )
     {
         sbdf = seg << 16;
         sbdf |= (bus & 0xff) << 8;
         sbdf |= (dev & 0x1f) << 3;
         sbdf |= (func & 0x7);
 
-        if ( xc_assign_device(self->xc_handle, dom, sbdf, flag) != 0 )
+        if ( xc_assign_device(self->xc_handle, dom, sbdf, 0) != 0 )
         {
             if (errno == ENOSYS)
                 sbdf = -1;
@@ -696,14 +686,14 @@ static PyObject *pyxc_deassign_device(XcObject *self,
     uint32_t dom;
     char *pci_str;
     int32_t sbdf = 0;
-    int seg, bus, dev, func, flag;
+    int seg, bus, dev, func;
 
     static char *kwd_list[] = { "domid", "pci", NULL };
     if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is", kwd_list,
                                       &dom, &pci_str) )
         return NULL;
 
-    while ( next_bdf(&pci_str, &seg, &bus, &dev, &func, &flag) )
+    while ( next_bdf(&pci_str, &seg, &bus, &dev, &func) )
     {
         sbdf = seg << 16;
         sbdf |= (bus & 0xff) << 8;
Signature · 1 line
2.1.4
#16 lore raw

Re: [PATCH for-4.6 v2 7/8] python/xc: reinstate original implementation of next_bdf

Quoted 14 lines · Wei Liu

I missed the fact that next_bdf is used to parsed user supplied strings when reviewing. The user supplied string is a NULL-terminated string separated by comma. User can supply several PCI devices in that string. There is, however, no delimiter for different devices, hence we can't change the syntax of that string.

This patch reinstate the original implementation of next_bdf to preserve the original syntax. The last argument for xc_assign_device is always 0.

---
Cc: Tiejun Chen <[email protected]>

Quoted 8 lines

Tiejun, are you actually using this python binding? I don't think we have in tree user.

If nobody is using it, I propose we remove this binding in next release.

I don't have live example of that string. My analysis is based on reverse-engineering of original code.

XenServer still uses a few methods from the lowlevel xc bindings, but this only extends to debug situations (our version of xen-bugtool) and I am not aware of us using this particular bit of the bindings.

~Andrew

#17 lore raw

Re: [PATCH for-4.6 v2 7/8] python/xc: reinstate original implementation of next_bdf

In reply to Wei Liu
Quoted 10 lines · Wei Liu

I missed the fact that next_bdf is used to parsed user supplied strings when reviewing. The user supplied string is a NULL-terminated string separated by comma. User can supply several PCI devices in that string. There is, however, no delimiter for different devices, hence we can't change the syntax of that string.

This patch reinstate the original implementation of next_bdf to preserve the original syntax. The last argument for xc_assign_device is always 0.

Quoted 5 lines

---
Cc: Tiejun Chen <[email protected]>

Tiejun, are you actually using this python binding? I don't think we

This change is just following to RMRR series but currently we don't use this. So its fine if you think this don't break any other usages.

Thanks
Tiejun

Quoted 105 lines

have in tree user.

If nobody is using it, I propose we remove this binding in next release.

I don't have live example of that string. My analysis is based on reverse-engineering of original code.

---
  tools/python/xen/lowlevel/xc/xc.c | 30 ++++++++++--------------------
  1 file changed, 10 insertions(+), 20 deletions(-)
tools/python/xen/lowlevel/xc/xc.c +10 -20
index c8380d1..2c36eb2 100644
@@ -592,8 +592,7 @@ static int token_value(char *token)
      return strtol(token, NULL, 16);
  }
 
-static int next_bdf(char **str, int *seg, int *bus, int *dev, int *func,
-                    int *flag)
+static int next_bdf(char **str, int *seg, int *bus, int *dev, int *func)
  {
      char *token;
 
@@ -608,17 +607,8 @@ static int next_bdf(char **str, int *seg, int *bus, int *dev, int *func,
      *dev  = token_value(token);
      token = strchr(token, ',') + 1;
      *func  = token_value(token);
-    token = strchr(token, ',') + 1;
-    if ( token ) {
-        *flag = token_value(token);
-        *str = token + 1;
-    }
-    else
-    {
-        /* O means we take "strict" as our default policy. */
-        *flag = 0;
-        *str = NULL;
-    }
+    token = strchr(token, ',');
+    *str = token ? token + 1 : NULL;
 
      return 1;
  }
@@ -630,14 +620,14 @@ static PyObject *pyxc_test_assign_device(XcObject *self,
      uint32_t dom;
      char *pci_str;
      int32_t sbdf = 0;
-    int seg, bus, dev, func, flag;
+    int seg, bus, dev, func;
 
      static char *kwd_list[] = { "domid", "pci", NULL };
      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is", kwd_list,
                                        &dom, &pci_str) )
          return NULL;
 
-    while ( next_bdf(&pci_str, &seg, &bus, &dev, &func, &flag) )
+    while ( next_bdf(&pci_str, &seg, &bus, &dev, &func) )
      {
          sbdf = seg << 16;
          sbdf |= (bus & 0xff) << 8;
@@ -663,21 +653,21 @@ static PyObject *pyxc_assign_device(XcObject *self,
      uint32_t dom;
      char *pci_str;
      int32_t sbdf = 0;
-    int seg, bus, dev, func, flag;
+    int seg, bus, dev, func;
 
      static char *kwd_list[] = { "domid", "pci", NULL };
      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is", kwd_list,
                                        &dom, &pci_str) )
          return NULL;
 
-    while ( next_bdf(&pci_str, &seg, &bus, &dev, &func, &flag) )
+    while ( next_bdf(&pci_str, &seg, &bus, &dev, &func) )
      {
          sbdf = seg << 16;
          sbdf |= (bus & 0xff) << 8;
          sbdf |= (dev & 0x1f) << 3;
          sbdf |= (func & 0x7);
 
-        if ( xc_assign_device(self->xc_handle, dom, sbdf, flag) != 0 )
+        if ( xc_assign_device(self->xc_handle, dom, sbdf, 0) != 0 )
          {
              if (errno == ENOSYS)
                  sbdf = -1;
@@ -696,14 +686,14 @@ static PyObject *pyxc_deassign_device(XcObject *self,
      uint32_t dom;
      char *pci_str;
      int32_t sbdf = 0;
-    int seg, bus, dev, func, flag;
+    int seg, bus, dev, func;
 
      static char *kwd_list[] = { "domid", "pci", NULL };
      if ( !PyArg_ParseTupleAndKeywords(args, kwds, "is", kwd_list,
                                        &dom, &pci_str) )
          return NULL;
 
-    while ( next_bdf(&pci_str, &seg, &bus, &dev, &func, &flag) )
+    while ( next_bdf(&pci_str, &seg, &bus, &dev, &func) )
      {
          sbdf = seg << 16;
          sbdf |= (bus & 0xff) << 8;
Acked-by on v2 7/8
#18 lore raw

Re: [PATCH for-4.6 v2 7/8] python/xc: reinstate original implementation of next_bdf

In reply to Wei Liu
Quoted 9 lines · Wei Liu

I missed the fact that next_bdf is used to parsed user supplied strings when reviewing. The user supplied string is a NULL-terminated string separated by comma. User can supply several PCI devices in that string. There is, however, no delimiter for different devices, hence we can't change the syntax of that string.

This patch reinstate the original implementation of next_bdf to preserve the original syntax. The last argument for xc_assign_device is always 0.

Specifically it returns us to exactly the state in 9b34056cb4ca~1, I believe? Plus an extra 0 flags parameter?

Quoted 5 lines

---
Cc: Tiejun Chen <[email protected]>

Quoted 8 lines

Tiejun, are you actually using this python binding? I don't think we have in tree user.

If nobody is using it, I propose we remove this binding in next release.

I don't have live example of that string. My analysis is based on reverse-engineering of original code.

FWIW I've said several times that it is not necessary to plumb new options such as this through the Python bindings, it is sufficient to pass in whatever value means "do as you did before". If a user of the Python bindings wants to then plumb in the ability to actually set the option (i.e. there is a use case for it) then that can be done later.

author
#19 lore raw

Re: [PATCH for-4.6 v2 7/8] python/xc: reinstate original implementation of next_bdf

Quoted 7 lines · Ian Campbell
Quoted 6 lines · Wei Liu

I missed the fact that next_bdf is used to parsed user supplied strings when reviewing. The user supplied string is a NULL-terminated string separated by comma. User can supply several PCI devices in that string. There is, however, no delimiter for different devices, hence we can't change the syntax of that string.

Quoted 7 lines
Quoted 3 lines

This patch reinstate the original implementation of next_bdf to preserve the original syntax. The last argument for xc_assign_device is always 0.

Specifically it returns us to exactly the state in 9b34056cb4ca~1, I believe? Plus an extra 0 flags parameter?

Yes to both questions.

Quoted 21 lines
Quoted 5 lines

---
Cc: Tiejun Chen <[email protected]>

Quoted 8 lines

Tiejun, are you actually using this python binding? I don't think we have in tree user.

If nobody is using it, I propose we remove this binding in next release.

I don't have live example of that string. My analysis is based on reverse-engineering of original code.

FWIW I've said several times that it is not necessary to plumb new options such as this through the Python bindings, it is sufficient to pass in whatever value means "do as you did before". If a user of the Python bindings wants to then plumb in the ability to actually set the option (i.e. there is a use case for it) then that can be done later.

author
#20 lore raw

PATCH v2 8/8 libxl: remove dead code libxl__domain_shutdown_reason

In reply to Wei Liu

There is no user in tree.

---
 tools/libxl/libxl_dom.c      | 17 -----------------
 tools/libxl/libxl_internal.h |  1 -
 2 files changed, 18 deletions(-)
tools/libxl/libxl_dom.c +0 -17
index b3ae5b5..5555fea 100644
@@ -42,23 +42,6 @@ libxl_domain_type libxl__domain_type(libxl__gc *gc, uint32_t domid)
         return LIBXL_DOMAIN_TYPE_PV;
 }
 
-int libxl__domain_shutdown_reason(libxl__gc *gc, uint32_t domid)
-{
-    libxl_ctx *ctx = libxl__gc_owner(gc);
-    xc_domaininfo_t info;
-    int ret;
-
-    ret = xc_domain_getinfolist(ctx->xch, domid, 1, &info);
-    if (ret != 1)
-        return -1;
-    if (info.domain != domid)
-        return -1;
-    if (!(info.flags & XEN_DOMINF_shutdown))
-        return -1;
-
-    return (info.flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask;
-}
-
 int libxl__domain_cpupool(libxl__gc *gc, uint32_t domid)
 {
     xc_domaininfo_t info;
tools/libxl/libxl_internal.h +0 -1
index f2466dc..c7e4709 100644
@@ -1042,7 +1042,6 @@ _hidden int libxl__file_reference_unmap(libxl__file_reference *f);
 
 /* from xl_dom */
 _hidden libxl_domain_type libxl__domain_type(libxl__gc *gc, uint32_t domid);
-_hidden int libxl__domain_shutdown_reason(libxl__gc *gc, uint32_t domid);
 _hidden int libxl__domain_cpupool(libxl__gc *gc, uint32_t domid);
 _hidden libxl_scheduler libxl__domain_scheduler(libxl__gc *gc, uint32_t domid);
 _hidden int libxl__sched_set_params(libxl__gc *gc, uint32_t domid,
Signature · 1 line
2.1.4
Acked-by on v2 8/8
#21 lore raw

Re: [PATCH for-4.6 v2 8/8] libxl: remove dead code libxl__domain_shutdown_reason

Quoted 1 line · Wei Liu

There is no user in tree.

git log -S libxl__domain_shutdown_reason
git log -S get_shutdown_reason

(the later being a rename that the former picks up on) suggests it has _never_ been used!

Quoted 1 line
Quoted 51 lines
---
 tools/libxl/libxl_dom.c      | 17 -----------------
 tools/libxl/libxl_internal.h |  1 -
 2 files changed, 18 deletions(-)
tools/libxl/libxl_dom.c +0 -17
index b3ae5b5..5555fea 100644
@@ -42,23 +42,6 @@ libxl_domain_type libxl__domain_type(libxl__gc *gc, 
 uint32_t domid)
         return LIBXL_DOMAIN_TYPE_PV;
 }
 
-int libxl__domain_shutdown_reason(libxl__gc *gc, uint32_t domid)
-{
-    libxl_ctx *ctx = libxl__gc_owner(gc);
-    xc_domaininfo_t info;
-    int ret;
-
-    ret = xc_domain_getinfolist(ctx->xch, domid, 1, &info);
-    if (ret != 1)
-        return -1;
-    if (info.domain != domid)
-        return -1;
-    if (!(info.flags & XEN_DOMINF_shutdown))
-        return -1;
-
-    return (info.flags >> XEN_DOMINF_shutdownshift) & 
 XEN_DOMINF_shutdownmask;
-}
-
 int libxl__domain_cpupool(libxl__gc *gc, uint32_t domid)
 {
     xc_domaininfo_t info;
tools/libxl/libxl_internal.h +0 -1
index f2466dc..c7e4709 100644
@@ -1042,7 +1042,6 @@ _hidden int 
 libxl__file_reference_unmap(libxl__file_reference *f);
 
 /* from xl_dom */
 _hidden libxl_domain_type libxl__domain_type(libxl__gc *gc, uint32_t 
 domid);
-_hidden int libxl__domain_shutdown_reason(libxl__gc *gc, uint32_t 
 domid);

_hidden int libxl__domain_cpupool(libxl__gc *gc, uint32_t domid); _hidden libxl_scheduler libxl__domain_scheduler(libxl__gc *gc, uint32_t
domid);
_hidden int libxl__sched_set_params(libxl__gc *gc, uint32_t domid,

#22 lore raw
In reply to Wei Liu
Quoted 1 line · Wei Liu

Wei Liu (8):

Applied 7 of these, but not:

Quoted 1 line

libxlu: free buffer in failure path for PCI related functions

which I have commented on.

Ian.