[PATCH] node_device: Enclose Linux specific code in ifdef __linux__

Michal Privoznik posted 1 patch 9 months, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/9dcb6d10eafdc73122f751c9bb5f366b2bb1b970.1689086353.git.mprivozn@redhat.com
src/node_device/node_device_udev.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
[PATCH] node_device: Enclose Linux specific code in ifdef __linux__
Posted by Michal Privoznik 9 months, 3 weeks ago
Our CI started to enable udev backend on FreeBSD. And while there
is udev on FreeBSD some parts of our code are highly Linux
specific, e.g. translating SCSI device type to string (from an
integer obtained from the sysfs). Obviously, this doesn't work
anywhere else. This is the reason why we need to include
scsi/scsi.h header file (which actually comes from the Linux
kernel source tree but for some reason glibc started to
distribute it, followed by musl).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/node_device/node_device_udev.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 4c37ec3189..960f3fd942 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -22,7 +22,9 @@
 #include <gio/gio.h>
 #include <libudev.h>
 #include <pciaccess.h>
-#include <scsi/scsi.h>
+#ifdef __linux__
+# include <scsi/scsi.h>
+#endif
 
 #include "node_device_conf.h"
 #include "node_device_event.h"
@@ -678,6 +680,8 @@ udevGetSCSIType(virNodeDeviceDef *def G_GNUC_UNUSED,
 
     *typestring = NULL;
 
+#ifdef __linux__
+    /* These values are Linux specific. */
     switch (type) {
     case TYPE_DISK:
         *typestring = g_strdup("disk");
@@ -714,6 +718,10 @@ udevGetSCSIType(virNodeDeviceDef *def G_GNUC_UNUSED,
         foundtype = 0;
         break;
     }
+#else
+    /* Implement me. */
+    foundtype = 0;
+#endif
 
     if (*typestring == NULL) {
         if (foundtype == 1) {
-- 
2.41.0
Re: [PATCH] node_device: Enclose Linux specific code in ifdef __linux__
Posted by Kristina Hanicova 9 months, 3 weeks ago
On Tue, Jul 11, 2023 at 4:39 PM Michal Privoznik <mprivozn@redhat.com>
wrote:

> Our CI started to enable udev backend on FreeBSD. And while there
> is udev on FreeBSD some parts of our code are highly Linux
> specific, e.g. translating SCSI device type to string (from an
> integer obtained from the sysfs). Obviously, this doesn't work
> anywhere else. This is the reason why we need to include
> scsi/scsi.h header file (which actually comes from the Linux
> kernel source tree but for some reason glibc started to
> distribute it, followed by musl).
>
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/node_device/node_device_udev.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>

Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
Kristina