]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nodedev: Return the parent for a virNodeDevicePtr struct
authorJohn Ferlan <jferlan@redhat.com>
Tue, 7 Feb 2017 18:04:08 +0000 (13:04 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 16 Feb 2017 17:23:04 +0000 (12:23 -0500)
When the 'parent' was added to the virNodeDevicePtr structure
by commit id 'e8a4ea75a' the 'parent' field was not properly filled
in when a virGetNodeDevice call was made within driver/config code.
Only the device name was ever filled in. Fetching the parent required
a second trip via virNodeDeviceGetParent into the node device lookup
code was required in order to retrieve the specific parent field (and
still the parent field was never filled in although it was free'd).

Since we have the data when we initially call virGetNodeDevice from
within driver/node_config code - let's just fill in the parent field
as well for anyone that wants it without requiring another trip into
the node_device lookup just to get the parent.

This will allow API's such as virConnectListAllNodeDevices,
virNodeDeviceLookupByName, and virNodeDeviceLookupSCSIHostByWWN
to retrieve both name and parent in the returned virNodeDevicePtr.

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/conf/node_device_conf.c
src/node_device/node_device_driver.c
src/test/test_driver.c

index 4d3268f12e30483e91d873169f329a194025f9fb..f6d7692a3c73faed01c373dabbb2e32a5ef1a560 100644 (file)
@@ -2158,8 +2158,8 @@ virNodeDeviceObjListExport(virConnectPtr conn,
         if ((!filter || filter(conn, devobj->def)) &&
             virNodeDeviceMatch(devobj, flags)) {
             if (devices) {
-                if (!(device = virGetNodeDevice(conn,
-                                                devobj->def->name))) {
+                if (!(device = virGetNodeDevice(conn, devobj->def->name)) ||
+                    VIR_STRDUP(device->parent, devobj->def->parent) < 0) {
                     virNodeDeviceObjUnlock(devobj);
                     goto cleanup;
                 }
index 5238e231de0ed521932ee00e27909c9431a737e3..4900e322270d784999b7e85547ec04b9261e7600 100644 (file)
@@ -261,7 +261,10 @@ nodeDeviceLookupByName(virConnectPtr conn, const char *name)
     if (virNodeDeviceLookupByNameEnsureACL(conn, obj->def) < 0)
         goto cleanup;
 
-    ret = virGetNodeDevice(conn, name);
+    if ((ret = virGetNodeDevice(conn, name))) {
+        if (VIR_STRDUP(ret->parent, obj->def->parent) < 0)
+            virObjectUnref(ret);
+    }
 
  cleanup:
     if (obj)
@@ -302,7 +305,10 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
                         if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, obj->def) < 0)
                             goto out;
 
-                        dev = virGetNodeDevice(conn, obj->def->name);
+                        if ((dev = virGetNodeDevice(conn, obj->def->name))) {
+                            if (VIR_STRDUP(dev->parent, obj->def->parent) < 0)
+                                virObjectUnref(dev);
+                        }
                         virNodeDeviceObjUnlock(obj);
                         goto out;
                     }
index 68202983a170895e39ec2bfd3661d65fff08054b..2f687e0e13e50d28180b4d152253abf8ccea9a2d 100644 (file)
@@ -5450,7 +5450,10 @@ testNodeDeviceLookupByName(virConnectPtr conn, const char *name)
         goto cleanup;
     }
 
-    ret = virGetNodeDevice(conn, name);
+    if ((ret = virGetNodeDevice(conn, name))) {
+        if (VIR_STRDUP(ret->parent, obj->def->parent) < 0)
+            virObjectUnref(ret);
+    }
 
  cleanup:
     if (obj)
@@ -5648,6 +5651,7 @@ testNodeDeviceCreateXML(virConnectPtr conn,
                                            0);
 
     dev = virGetNodeDevice(conn, def->name);
+    ignore_value(VIR_STRDUP(dev->parent, def->parent));
     def = NULL;
  cleanup:
     testDriverUnlock(driver);