[libvirt] [PATCH 15/23] src: replace mdir_name() with g_path_get_dirname()

Daniel P. Berrangé berrange at redhat.com
Thu Jan 2 14:53:49 UTC 2020


Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
---
 src/conf/node_device_conf.c       |  4 +---
 src/locking/lock_driver_sanlock.c |  6 +-----
 src/qemu/qemu_driver.c            |  7 ++-----
 src/qemu/qemu_tpm.c               | 33 +++----------------------------
 src/security/virt-aa-helper.c     |  4 +---
 src/util/virfile.c                |  6 +-----
 src/util/virstoragefile.c         | 13 ++----------
 src/vmware/vmware_conf.c          |  7 ++-----
 8 files changed, 13 insertions(+), 67 deletions(-)

diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 9b206abadc..4cf5b6e3d7 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -30,7 +30,6 @@
 #include "virstring.h"
 #include "node_device_conf.h"
 #include "device_conf.h"
-#include "dirname.h"
 #include "virxml.h"
 #include "virbuffer.h"
 #include "viruuid.h"
@@ -2445,8 +2444,7 @@ virNodeDeviceGetSCSITargetCaps(const char *sysfsPath,
     VIR_DEBUG("Checking if '%s' is an FC remote port", scsi_target->name);
 
     /* /sys/devices/[...]/host0/rport-0:0-0/target0:0:0 -> rport-0:0-0 */
-    if (!(dir = mdir_name(sysfsPath)))
-        return -1;
+    dir = g_path_get_dirname(sysfsPath);
 
     rport = g_path_get_basename(dir);
 
diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c
index c8936c301c..088255a111 100644
--- a/src/locking/lock_driver_sanlock.c
+++ b/src/locking/lock_driver_sanlock.c
@@ -31,7 +31,6 @@
 #include <sanlock_resource.h>
 #include <sanlock_admin.h>
 
-#include "dirname.h"
 #include "lock_driver.h"
 #include "virlog.h"
 #include "virerror.h"
@@ -239,10 +238,7 @@ virLockManagerSanlockSetupLockspace(virLockManagerSanlockDriverPtr driver)
         int perms = 0600;
         VIR_DEBUG("Lockspace %s does not yet exist", path);
 
-        if (!(dir = mdir_name(path))) {
-            virReportOOMError();
-            goto error;
-        }
+        dir = g_path_get_dirname(path);
         if (stat(dir, &st) < 0 || !S_ISDIR(st.st_mode)) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Unable to create lockspace %s: parent directory"
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ec8faf384c..9dffeefce7 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -99,7 +99,6 @@
 #include "vircgroup.h"
 #include "virperf.h"
 #include "virnuma.h"
-#include "dirname.h"
 #include "netdev_bandwidth_conf.h"
 #include "virqemu.h"
 #include "virdomainsnapshotobjlist.h"
@@ -850,10 +849,8 @@ qemuStateInitialize(bool privileged,
                                  (int)cfg->group);
             goto error;
         }
-        if (!(channeldir = mdir_name(cfg->channelTargetDir))) {
-            virReportOOMError();
-            goto error;
-        }
+        channeldir = g_path_get_dirname(cfg->channelTargetDir);
+
         if (chown(channeldir, cfg->user, cfg->group) < 0) {
             virReportSystemError(errno,
                                  _("unable to set ownership of '%s' to %d:%d"),
diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c
index 91ab5bca9e..28800a100c 100644
--- a/src/qemu/qemu_tpm.c
+++ b/src/qemu/qemu_tpm.c
@@ -40,7 +40,6 @@
 #include "virstring.h"
 #include "virpidfile.h"
 #include "configmake.h"
-#include "dirname.h"
 #include "qemu_tpm.h"
 #include "virtpm.h"
 #include "secret_util.h"
@@ -83,26 +82,6 @@ qemuTPMCreateEmulatorStoragePath(const char *swtpmStorageDir,
 }
 
 
-/*
- * virtTPMGetTPMStorageDir:
- *
- * @storagepath: directory for swtpm's persistent state
- *
- * Derive the 'TPMStorageDir' from the storagepath by searching
- * for the last '/'.
- */
-static char *
-qemuTPMGetTPMStorageDir(const char *storagepath)
-{
-    char *ret = mdir_name(storagepath);
-
-    if (!ret)
-        virReportOOMError();
-
-    return ret;
-}
-
-
 /*
  * qemuTPMEmulatorInitStorage
  *
@@ -147,10 +126,7 @@ qemuTPMCreateEmulatorStorage(const char *storagepath,
                              gid_t swtpm_group)
 {
     int ret = -1;
-    char *swtpmStorageDir = qemuTPMGetTPMStorageDir(storagepath);
-
-    if (!swtpmStorageDir)
-        return -1;
+    char *swtpmStorageDir = g_path_get_dirname(storagepath);
 
     if (qemuTPMEmulatorInitStorage(swtpmStorageDir) < 0)
         goto cleanup;
@@ -183,12 +159,9 @@ qemuTPMCreateEmulatorStorage(const char *storagepath,
 static void
 qemuTPMDeleteEmulatorStorage(virDomainTPMDefPtr tpm)
 {
-    char *path = qemuTPMGetTPMStorageDir(tpm->data.emulator.storagepath);
+    g_autofree char *path =  g_path_get_dirname(tpm->data.emulator.storagepath);
 
-    if (path) {
-        ignore_value(virFileDeleteTree(path));
-        VIR_FREE(path);
-    }
+    ignore_value(virFileDeleteTree(path));
 }
 
 
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index feb03b0aa9..9c34ac92c2 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -33,7 +33,6 @@
 #include "viralloc.h"
 #include "vircommand.h"
 #include "virlog.h"
-#include "dirname.h"
 #include "driver.h"
 
 #include "security_driver.h"
@@ -754,8 +753,7 @@ vah_add_path(virBufferPtr buf, const char *path, const char *perms, bool recursi
      */
      pathdir = g_strdup(path);
      while (!virFileExists(pathdir)) {
-         if ((pathtmp = mdir_name(pathdir)) == NULL)
-             goto cleanup;
+         pathtmp = g_path_get_dirname(pathdir);
          VIR_FREE(pathdir);
          pathdir = g_steal_pointer(&pathtmp);
      }
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 1ce909b033..d5e4d0a289 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -37,7 +37,6 @@
 #endif
 #include <unistd.h>
 #include <dirent.h>
-#include <dirname.h>
 #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R
 # include <mntent.h>
 #endif
@@ -1886,10 +1885,7 @@ int virFileIsMountPoint(const char *file)
     int ret;
     struct stat sb1, sb2;
 
-    if (!(parent = mdir_name(file))) {
-        virReportOOMError();
-        return -1;
-    }
+    parent = g_path_get_dirname(file);
 
     VIR_DEBUG("Comparing '%s' to '%s'", file, parent);
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index e280a646b7..c9f3e5f865 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -36,7 +36,6 @@
 #include "virstring.h"
 #include "virutil.h"
 #include "viruri.h"
-#include "dirname.h"
 #include "virbuffer.h"
 #include "virjson.h"
 #include "virstorageencryption.h"
@@ -1690,15 +1689,10 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
 
             if (nameIsFile && virStorageSourceIsLocalStorage(chain)) {
                 if (*parent && virStorageSourceIsLocalStorage(*parent))
-                    parentDir = mdir_name((*parent)->path);
+                    parentDir = g_path_get_dirname((*parent)->path);
                 else
                     parentDir = g_strdup(".");
 
-                if (!parentDir) {
-                    virReportOOMError();
-                    goto error;
-                }
-
                 int result = virFileRelLinkPointsTo(parentDir, name,
                                                     chain->path);
 
@@ -2658,10 +2652,7 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent,
     /* store relative name */
     def->relPath = g_strdup(rel);
 
-    if (!(dirname = mdir_name(parent->path))) {
-        virReportOOMError();
-        return NULL;
-    }
+    dirname = g_path_get_dirname(parent->path);
 
     if (STRNEQ(dirname, "/")) {
         def->path = g_strdup_printf("%s/%s", dirname, rel);
diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c
index 290e0e898d..0256f1832f 100644
--- a/src/vmware/vmware_conf.c
+++ b/src/vmware/vmware_conf.c
@@ -24,7 +24,6 @@
 
 #include "vircommand.h"
 #include "cpu/cpu.h"
-#include "dirname.h"
 #include "viralloc.h"
 #include "virfile.h"
 #include "viruuid.h"
@@ -270,8 +269,7 @@ vmwareExtractVersion(struct vmware_driver *driver)
     char *bin = NULL;
     char *vmwarePath = NULL;
 
-    if ((vmwarePath = mdir_name(driver->vmrun)) == NULL)
-        goto cleanup;
+    vmwarePath = g_path_get_dirname(driver->vmrun);
 
     switch (driver->type) {
         case VMWARE_DRIVER_PLAYER:
@@ -477,8 +475,7 @@ vmwareExtractPid(const char * vmxPath)
     char *tmp = NULL;
     int pid_value = -1;
 
-    if ((vmxDir = mdir_name(vmxPath)) == NULL)
-        goto cleanup;
+    vmxDir = g_path_get_dirname(vmxPath);
 
     logFilePath = g_strdup_printf("%s/vmware.log", vmxDir);
 
-- 
2.24.1




More information about the libvir-list mailing list