[libvirt] [PATCH 3/6] node device: prepare node_device_linux_sysfs.c to add more functions

Laine Stump laine at laine.org
Fri May 15 15:04:26 UTC 2015


This file contains only a single function, detect_scsi_host_caps(),
which is declared in node_device_driver.h and called from both the hal
and udev backends. Other things common to the hal and udev drivers
can be placed in that file though. As a prelude to adding further
functions, this patch renames the existing function to something
closer in line with other internal libvirt function names
(nodeDeviceSysfsGetSCSIHostCaps()), and puts the declarations into a
separate .h file.
---
 src/Makefile.am                           |  5 +++--
 src/node_device/node_device_driver.c      |  7 ++++---
 src/node_device/node_device_driver.h      |  2 --
 src/node_device/node_device_hal.c         |  7 ++++---
 src/node_device/node_device_linux_sysfs.c |  7 ++++---
 src/node_device/node_device_linux_sysfs.h | 30 ++++++++++++++++++++++++++++++
 src/node_device/node_device_udev.c        |  9 +++++----
 7 files changed, 50 insertions(+), 17 deletions(-)
 create mode 100644 src/node_device/node_device_linux_sysfs.h

diff --git a/src/Makefile.am b/src/Makefile.am
index d28a8ed..579421d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in
 
-## Copyright (C) 2005-2014 Red Hat, Inc.
+## Copyright (C) 2005-2015 Red Hat, Inc.
 ##
 ## This library is free software; you can redistribute it and/or
 ## modify it under the terms of the GNU Lesser General Public
@@ -966,7 +966,8 @@ ACCESS_DRIVER_POLKIT_POLICY = \
 NODE_DEVICE_DRIVER_SOURCES =					\
 		node_device/node_device_driver.c		\
 		node_device/node_device_driver.h		\
-		node_device/node_device_linux_sysfs.c
+		node_device/node_device_linux_sysfs.c           \
+		node_device/node_device_linux_sysfs.h
 
 NODE_DEVICE_DRIVER_HAL_SOURCES =				\
 		node_device/node_device_hal.c			\
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index a6b32fe..c9db00a 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -35,8 +35,9 @@
 #include "virfile.h"
 #include "virstring.h"
 #include "node_device_conf.h"
-#include "node_device_hal.h"
 #include "node_device_driver.h"
+#include "node_device_hal.h"
+#include "node_device_linux_sysfs.h"
 #include "virutil.h"
 #include "viraccessapicheck.h"
 #include "virnetdev.h"
@@ -52,7 +53,7 @@ static int update_caps(virNodeDeviceObjPtr dev)
     while (cap) {
         switch (cap->data.type) {
         case VIR_NODE_DEV_CAP_SCSI_HOST:
-            detect_scsi_host_caps(&dev->def->caps->data);
+            nodeDeviceSysfsGetSCSIHostCaps(&dev->def->caps->data);
             break;
         case VIR_NODE_DEV_CAP_NET:
             if (virNetDevGetLinkInfo(cap->data.net.ifname, &cap->data.net.lnk) < 0)
@@ -282,7 +283,7 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
 
         while (cap) {
             if (cap->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) {
-                detect_scsi_host_caps(&cap->data);
+                nodeDeviceSysfsGetSCSIHostCaps(&cap->data);
                 if (cap->data.scsi_host.flags &
                     VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {
                     if (STREQ(cap->data.scsi_host.wwnn, wwnn) &&
diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_device_driver.h
index 81bca98..0f4ea57 100644
--- a/src/node_device/node_device_driver.h
+++ b/src/node_device/node_device_driver.h
@@ -44,8 +44,6 @@ extern virNodeDeviceDriverStatePtr driver;
 
 int nodedevRegister(void);
 
-int detect_scsi_host_caps(virNodeDevCapDataPtr d);
-
 int nodeNumOfDevices(virConnectPtr conn, const char *cap, unsigned int flags);
 int nodeListDevices(virConnectPtr conn, const char *cap, char **const names,
                     int maxnames, unsigned int flags);
diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c
index 38e09c4..2379e88 100644
--- a/src/node_device/node_device_hal.c
+++ b/src/node_device/node_device_hal.c
@@ -1,7 +1,7 @@
 /*
  * node_device_hal.c: node device enumeration - HAL-based implementation
  *
- * Copyright (C) 2011-2014 Red Hat, Inc.
+ * Copyright (C) 2011-2015 Red Hat, Inc.
  * Copyright (C) 2008 Virtual Iron Software, Inc.
  * Copyright (C) 2008 David F. Lively
  *
@@ -29,7 +29,9 @@
 #include <libhal.h>
 
 #include "node_device_conf.h"
+#include "node_device_driver.h"
 #include "node_device_hal.h"
+#include "node_device_linux_sysfs.h"
 #include "virerror.h"
 #include "driver.h"
 #include "datatypes.h"
@@ -37,7 +39,6 @@
 #include "viruuid.h"
 #include "virpci.h"
 #include "virlog.h"
-#include "node_device_driver.h"
 #include "virdbus.h"
 #include "virstring.h"
 
@@ -248,7 +249,7 @@ gather_scsi_host_cap(LibHalContext *ctx, const char *udi,
 
     (void)get_int_prop(ctx, udi, "scsi_host.host", (int *)&d->scsi_host.host);
 
-    retval = detect_scsi_host_caps(d);
+    retval = nodeDeviceSysfsGetSCSIHostCaps(d);
 
     if (retval == -1)
         goto out;
diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/node_device_linux_sysfs.c
index d4c2a3c..fc82b32 100644
--- a/src/node_device/node_device_linux_sysfs.c
+++ b/src/node_device/node_device_linux_sysfs.c
@@ -1,6 +1,6 @@
 /*
  * node_device_linux_sysfs.c: Linux specific code to gather device data
- * not available through HAL.
+ * that is available from sysfs (but not from UDEV or HAL).
  *
  * Copyright (C) 2009-2015 Red Hat, Inc.
  *
@@ -28,6 +28,7 @@
 
 #include "node_device_driver.h"
 #include "node_device_hal.h"
+#include "node_device_linux_sysfs.h"
 #include "virerror.h"
 #include "viralloc.h"
 #include "virlog.h"
@@ -41,7 +42,7 @@
 VIR_LOG_INIT("node_device.node_device_linux_sysfs");
 
 int
-detect_scsi_host_caps(virNodeDevCapDataPtr d)
+nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapDataPtr d)
 {
     char *max_vports = NULL;
     char *vports = NULL;
@@ -139,7 +140,7 @@ detect_scsi_host_caps(virNodeDevCapDataPtr d)
 #else
 
 int
-detect_scsi_host_caps(virNodeDevCapDataPtr d ATTRIBUTE_UNUSED)
+nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapDataPtr d ATTRIBUTE_UNUSED)
 {
     return -1;
 }
diff --git a/src/node_device/node_device_linux_sysfs.h b/src/node_device/node_device_linux_sysfs.h
new file mode 100644
index 0000000..307a8aa
--- /dev/null
+++ b/src/node_device/node_device_linux_sysfs.h
@@ -0,0 +1,30 @@
+/*
+ * node_device_linux_sysfs.h: Linux specific code to gather device data
+ * that is available from sysfs (but not from UDEV or HAL).
+ *
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __VIR_NODE_DEVICE_LINUX_SYSFS_H__
+# define __VIR_NODE_DEVICE_LINUX_SYSFS_H__
+
+# include "node_device_conf.h"
+
+int nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapDataPtr d);
+
+#endif /* __VIR_NODE_DEVICE_LINUX_SYSFS_H__ */
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index b6619bd..29da036 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1,7 +1,7 @@
 /*
  * node_device_udev.c: node device enumeration - libudev implementation
  *
- * Copyright (C) 2009-2014 Red Hat, Inc.
+ * Copyright (C) 2009-2015 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -27,10 +27,11 @@
 #include <c-ctype.h>
 
 #include "dirname.h"
-#include "node_device_udev.h"
-#include "virerror.h"
 #include "node_device_conf.h"
 #include "node_device_driver.h"
+#include "node_device_linux_sysfs.h"
+#include "node_device_udev.h"
+#include "virerror.h"
 #include "driver.h"
 #include "datatypes.h"
 #include "virlog.h"
@@ -749,7 +750,7 @@ static int udevProcessSCSIHost(struct udev_device *device ATTRIBUTE_UNUSED,
         goto out;
     }
 
-    detect_scsi_host_caps(&def->caps->data);
+    nodeDeviceSysfsGetSCSIHostCaps(&def->caps->data);
 
     if (udevGenerateDeviceName(device, def, NULL) != 0)
         goto out;
-- 
2.1.0




More information about the libvir-list mailing list