]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Handle LSI Logic Parallel and BusLogic SCSI on PCI bus 0.
authorOliver Kurth <okurth@vmware.com>
Wed, 4 Mar 2020 20:07:11 +0000 (12:07 -0800)
committerOliver Kurth <okurth@vmware.com>
Wed, 4 Mar 2020 20:07:11 +0000 (12:07 -0800)
When a LSI Logic Parallel or BusLogic SCSI controller appears on PCI
bus 0, the disk device controller name is not present; the "label" file
is missing.  Adding logic to check if disk device is attached to a
SCSI controller on bus 0 (0000:00:10.0) if a "label" file cannot be
found.  If that is the case, setting the device name to "scsi0.n"
where "n" is the device unit number previously determined.

open-vm-tools/services/plugins/guestInfo/diskInfo.c

index c203c159984e3af0bec6e9f4710ce22c8617c6fe..7d68de710754e7e825aca687cfb95a040b90131b 100644 (file)
@@ -29,6 +29,7 @@
 #include "debug.h"
 #include "guestInfoInt.h"
 #include "str.h"
+#include "strutil.h"
 #include "posix.h"
 #include "file.h"
 #include "util.h"
@@ -168,6 +169,46 @@ GuestInfoAddDeviceName(char *devName,
 }
 
 
+/*
+ ******************************************************************************
+ * GuestInfoCheckPci0 --                                                */ /**
+ *
+ * Check if this PCI device path does not contain a "label" file and happens
+ * to be PCI bus 0.
+ *
+ * @param[in]  pciDevPath  Path of the PCI device of interest.
+ * @param[in]  unit        Disk unit or device number (previously determined).
+ * @param[out] devName     Address of the buffer to receive device name.
+ * @param[in]  devMaxLen   Maximum length of the device buffer available.
+ *
+ * @return True if this disk device is on PCI bus 0 and the devName has
+ *         been filled in as scsi0:unit.
+ *
+ ******************************************************************************
+ */
+
+static Bool
+GuestInfoCheckPci0(const char *pciDevPath,
+                   const char *unit,
+                   char *devName,
+                   size_t devMaxLen)
+{
+   char *realPath = NULL;
+   Bool result = FALSE;
+
+   if((realPath = Posix_RealPath(pciDevPath)) == NULL) {
+      goto exit;
+   }
+   if (StrUtil_EndsWith(realPath, "/0000:00:10.0")) {
+      Str_Snprintf (devName, devMaxLen, "scsi0:%s", unit);
+      result = TRUE;
+   }
+   free(realPath);
+exit:
+   return result;
+}
+
+
 /*
  ******************************************************************************
  * GuestInfoGetPCIName --                                                */ /**
@@ -190,7 +231,7 @@ static void
 GuestInfoGetPCIName(const char *pciDevPath,
                     const char *unit,
                     char *devName,
-                    unsigned int devMaxLen)
+                    size_t devMaxLen)
 {
    char labelPath[PATH_MAX];
    FILE *labelFile;
@@ -200,8 +241,15 @@ GuestInfoGetPCIName(const char *pciDevPath,
    Str_Snprintf(labelPath, PATH_MAX, "%s/%s", pciDevPath, "label");
 
    if ((labelFile = fopen(labelPath, "r")) == NULL) {
-      g_debug("%s: unable to open \"label\" file for device %s.\n",
-              __FUNCTION__, pciDevPath);
+      /*
+       * Need to check if this might be the LSI Logic Parallel or BusLogic
+       * SCSI controller on PCI bus 0, in which case "label" is not expected.
+       */
+      if (errno != ENOENT ||
+          !GuestInfoCheckPci0(pciDevPath, unit, devName, devMaxLen)) {
+         g_debug("%s: unable to open \"label\" file for device %s.\n",
+                 __FUNCTION__, pciDevPath);
+      }
       return;
    }
    if (fgets(buffer, sizeof buffer, labelFile) == NULL) {
@@ -968,7 +1016,7 @@ GuestInfoGetDiskInfoWiper(Bool includeReserved,  // IN
    unsigned int partCount = 0;
    uint64 freeBytes = 0;
    uint64 totalBytes = 0;
-   unsigned int partNameSize = 0;
+   size_t partNameSize = 0;
    Bool success = FALSE;
    GuestDiskInfoInt *di;