Re: [PATCH 06/18] virpcimock: Eliminate use of @fakesysfspcidir

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Reviewed-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>

On 8/14/19 8:57 AM, Michal Privoznik wrote:
The @fakesysfspcidir is derived from @fakerootdir. We don't need
two global variables that contain nearly the same content,
especially when we construct the actual path anyways.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
  tests/virpcimock.c | 41 ++++++++++++++++++++---------------------
  1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/tests/virpcimock.c b/tests/virpcimock.c
index 0950f3ba00..296da9b453 100644
--- a/tests/virpcimock.c
+++ b/tests/virpcimock.c
@@ -41,7 +41,6 @@ static char *(*real_virFileCanonicalizePath)(const char *path);
   * vircgroupmock.c:462:22: error: static variable 'fakesysfsdir' is used in an inline function with external linkage [-Werror,-Wstatic-in-inline]
   */
  char *fakerootdir;
-char *fakesysfspcidir;
# define SYSFS_PCI_PREFIX "/sys/bus/pci/" @@ -212,9 +211,7 @@ pci_read_file(const char *path,
      int fd = -1;
      VIR_AUTOFREE(char *) newpath = NULL;
- if (virAsprintfQuiet(&newpath, "%s/%s",
-                         fakesysfspcidir,
-                         path + strlen(SYSFS_PCI_PREFIX)) < 0) {
+    if (virAsprintfQuiet(&newpath, "%s/%s", fakerootdir, path) < 0) {
          errno = ENOMEM;
          goto cleanup;
      }
@@ -245,8 +242,8 @@ getrealpath(char **newpath,
      init_env();
if (STRPREFIX(path, SYSFS_PCI_PREFIX)) {
-        if (virAsprintfQuiet(newpath, "%s/%s",
-                             fakesysfspcidir,
+        if (virAsprintfQuiet(newpath, "%s/sys/bus/pci/%s",
+                             fakerootdir,
                               path + strlen(SYSFS_PCI_PREFIX)) < 0) {
              errno = ENOMEM;
              return -1;
@@ -356,7 +353,7 @@ pci_device_new_from_stub(const struct pciDevice *data)
      if (VIR_ALLOC_QUIET(dev) < 0 ||
          virAsprintfQuiet(&configSrc, "%s/virpcitestdata/%s.config",
                           abs_srcdir, id) < 0 ||
-        virAsprintfQuiet(&devpath, "%s/devices/%s", fakesysfspcidir, data->id) < 0)
+        virAsprintfQuiet(&devpath, "%s/sys/bus/pci/devices/%s", fakerootdir, data->id) < 0)
          ABORT_OOM();
memcpy(dev, data, sizeof(*dev));
@@ -478,7 +475,7 @@ pci_driver_new(const char *name, int fail, ...)
if (VIR_ALLOC_QUIET(driver) < 0 ||
          VIR_STRDUP_QUIET(driver->name, name) < 0 ||
-        virAsprintfQuiet(&driverpath, "%s/drivers/%s", fakesysfspcidir, name) < 0)
+        virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s", fakerootdir, name) < 0)
          ABORT_OOM();
driver->fail = fail;
@@ -585,10 +582,10 @@ pci_driver_bind(struct pciDriver *driver,
      }
/* Make symlink under device tree */
-    if (virAsprintfQuiet(&devpath, "%s/devices/%s/driver",
-                         fakesysfspcidir, dev->id) < 0 ||
-        virAsprintfQuiet(&driverpath, "%s/drivers/%s",
-                         fakesysfspcidir, driver->name) < 0) {
+    if (virAsprintfQuiet(&devpath, "%s/sys/bus/pci/devices/%s/driver",
+                         fakerootdir, dev->id) < 0 ||
+        virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s",
+                         fakerootdir, driver->name) < 0) {
          errno = ENOMEM;
          return -1;
      }
@@ -599,10 +596,10 @@ pci_driver_bind(struct pciDriver *driver,
      /* Make symlink under driver tree */
      VIR_FREE(devpath);
      VIR_FREE(driverpath);
-    if (virAsprintfQuiet(&devpath, "%s/devices/%s",
-                         fakesysfspcidir, dev->id) < 0 ||
-        virAsprintfQuiet(&driverpath, "%s/drivers/%s/%s",
-                         fakesysfspcidir, driver->name, dev->id) < 0) {
+    if (virAsprintfQuiet(&devpath, "%s/sys/bus/pci/devices/%s",
+                         fakerootdir, dev->id) < 0 ||
+        virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s/%s",
+                         fakerootdir, driver->name, dev->id) < 0) {
          errno = ENOMEM;
          return -1;
      }
@@ -628,10 +625,10 @@ pci_driver_unbind(struct pciDriver *driver,
      }
/* Make symlink under device tree */
-    if (virAsprintfQuiet(&devpath, "%s/devices/%s/driver",
-                         fakesysfspcidir, dev->id) < 0 ||
-        virAsprintfQuiet(&driverpath, "%s/drivers/%s/%s",
-                         fakesysfspcidir, driver->name, dev->id) < 0) {
+    if (virAsprintfQuiet(&devpath, "%s/sys/bus/pci/devices/%s/driver",
+                         fakerootdir, dev->id) < 0 ||
+        virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s/%s",
+                         fakerootdir, driver->name, dev->id) < 0) {
          errno = ENOMEM;
          return -1;
      }
@@ -834,7 +831,9 @@ init_syms(void)
  static void
  init_env(void)
  {
-    if (fakerootdir && fakesysfspcidir)
+    VIR_AUTOFREE(char *) fakesysfspcidir = NULL;
+
+    if (fakerootdir)
          return;
if (!(fakerootdir = getenv("LIBVIRT_FAKE_ROOT_DIR")))

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux