diff mbox

[v4,13/13] libxl: make pci and usb setdefault function generic

Message ID 1500387930-16317-14-git-send-email-al1img@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Oleksandr Grytsov July 18, 2017, 2:25 p.m. UTC
From: Oleksandr Grytsov <oleksandr_grytsov@epam.com>

Due to changes in device framework setdefault function
should have same format. Otherwise calling devicetype
set_default causes segfault.

Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
---
 tools/libxl/libxl_internal.h | 1 -
 tools/libxl/libxl_pci.c      | 5 +++--
 tools/libxl/libxl_usb.c      | 7 ++++---
 3 files changed, 7 insertions(+), 6 deletions(-)

Comments

Wei Liu Sept. 5, 2017, 1:06 p.m. UTC | #1
On Tue, Jul 18, 2017 at 05:25:30PM +0300, Oleksandr Grytsov wrote:
> From: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
> 
> Due to changes in device framework setdefault function
> should have same format. Otherwise calling devicetype
> set_default causes segfault.
> 
> Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>

Shouldn't this patch be placed before the introduction of the new
framework?
Oleksandr Grytsov Sept. 6, 2017, 3:53 p.m. UTC | #2
On Tue, Sep 5, 2017 at 4:06 PM, Wei Liu <wei.liu2@citrix.com> wrote:
> On Tue, Jul 18, 2017 at 05:25:30PM +0300, Oleksandr Grytsov wrote:
>> From: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
>>
>> Due to changes in device framework setdefault function
>> should have same format. Otherwise calling devicetype
>> set_default causes segfault.
>>
>> Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
>
> Shouldn't this patch be placed before the introduction of the new
> framework?

Wrong function parameters will cause crash if devtype framework
will be used. For example if someone call pci set_default:

libxl__nic_devtype.set_default(...)

So I guess the right place for these changes will be
first patch where changes to devtype are introduced.
I will fix setdefault function parameters for all devtypes.
Does it sounds good?
Wei Liu Sept. 7, 2017, 9:05 a.m. UTC | #3
On Wed, Sep 06, 2017 at 06:53:19PM +0300, Oleksandr Grytsov wrote:
> So I guess the right place for these changes will be
> first patch where changes to devtype are introduced.
> I will fix setdefault function parameters for all devtypes.
> Does it sounds good?

Yes.
diff mbox

Patch

diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 5fd0356..e4799eb 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1242,7 +1242,6 @@  _hidden int libxl__domain_create_info_setdefault(libxl__gc *gc,
                                         libxl_domain_create_info *c_info);
 _hidden int libxl__domain_build_info_setdefault(libxl__gc *gc,
                                         libxl_domain_build_info *b_info);
-_hidden int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci);
 _hidden void libxl__rdm_setdefault(libxl__gc *gc,
                                    libxl_domain_build_info *b_info);
 
diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c
index 159d046..fa86bcf 100644
--- a/tools/libxl/libxl_pci.c
+++ b/tools/libxl/libxl_pci.c
@@ -1158,7 +1158,8 @@  static int libxl__device_pci_reset(libxl__gc *gc, unsigned int domain, unsigned
     return -1;
 }
 
-int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci)
+static int libxl__device_pci_setdefault(libxl__gc *gc, uint32_t domid,
+                                 libxl_device_pci *pci, bool hotplug)
 {
     /* We'd like to force reserve rdm specific to a device by default.*/
     if (pci->rdm_policy == LIBXL_RDM_RESERVE_POLICY_INVALID)
@@ -1214,7 +1215,7 @@  int libxl__device_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcide
         }
     }
 
-    rc = libxl__device_pci_setdefault(gc, pcidev);
+    rc = libxl__device_pci_setdefault(gc, domid, pcidev, false);
     if (rc) goto out;
 
     if (pcidev->seize && !pciback_dev_is_assigned(gc, pcidev)) {
diff --git a/tools/libxl/libxl_usb.c b/tools/libxl/libxl_usb.c
index e526c08..9fdb284 100644
--- a/tools/libxl/libxl_usb.c
+++ b/tools/libxl/libxl_usb.c
@@ -39,7 +39,8 @@  static int usbback_is_loaded(libxl__gc *gc)
 }
 
 static int libxl__device_usbctrl_setdefault(libxl__gc *gc, uint32_t domid,
-                                            libxl_device_usbctrl *usbctrl)
+                                            libxl_device_usbctrl *usbctrl,
+                                            bool update_json)
 {
     int rc;
     libxl_domain_type domtype = libxl__domain_type(gc, domid);
@@ -449,7 +450,7 @@  static void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid,
     libxl__device *device;
     int rc;
 
-    rc = libxl__device_usbctrl_setdefault(gc, domid, usbctrl);
+    rc = libxl__device_usbctrl_setdefault(gc, domid, usbctrl, false);
     if (rc < 0) goto out;
 
     if (usbctrl->devid == -1) {
@@ -1079,7 +1080,7 @@  static int libxl__device_usbdev_setdefault(libxl__gc *gc,
 
             GCNEW(usbctrl);
             libxl_device_usbctrl_init(usbctrl);
-            rc = libxl__device_usbctrl_setdefault(gc, domid, usbctrl);
+            rc = libxl__device_usbctrl_setdefault(gc, domid, usbctrl, update_json);
             if (rc < 0) goto out;
 
             if (usbctrl->devid == -1) {