]> xenbits.xensource.com Git - libvirt.git/commitdiff
cleanup: Kill usage of access(PATH, F_OK) in favor of virFileExists()
authorPeter Krempa <pkrempa@redhat.com>
Fri, 13 Sep 2013 13:32:43 +0000 (15:32 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 16 Sep 2013 08:37:39 +0000 (10:37 +0200)
Semantics of the libvirt helper are more clear. This change also allows
to clean up some pieces of code.

14 files changed:
src/openvz/openvz_conf.c
src/parallels/parallels_storage.c
src/qemu/qemu_capabilities.c
src/qemu/qemu_cgroup.c
src/qemu/qemu_process.c
src/storage/storage_backend_fs.c
src/storage/storage_backend_logical.c
src/storage/storage_backend_mpath.c
src/storage/storage_backend_scsi.c
src/util/vircgroup.c
src/util/virfile.c
src/util/virpci.c
src/util/virscsi.c
src/util/virutil.c

index 93f23774135992c92f647694a2e65618a942defc..0dbaa4a8779b70945d8219821ba8aab9d55bf44f 100644 (file)
@@ -940,7 +940,7 @@ openvzLocateConfDir(void)
     char *ret = NULL;
 
     while (conf_dir_list[i]) {
-        if (!access(conf_dir_list[i], F_OK)) {
+        if (virFileExists(conf_dir_list[i])) {
             ignore_value(VIR_STRDUP(ret, conf_dir_list[i]));
             goto cleanup;
         }
index 44246a7b43a40009e49b535be0260d83b24db984..bb5066f5290c5bf8b96639b770f644c501fd586b 100644 (file)
@@ -362,7 +362,7 @@ static int parallelsFindVmVolumes(virStoragePoolObjPtr pool,
                                               "DiskDescriptor", ".xml")))
             goto cleanup;
 
-        if (access(diskDescPath, F_OK))
+        if (!virFileExists(diskDescPath))
             continue;
 
         /* here we know, that ent->d_name is a disk image directory */
index d94188a461488a04e0e44333230b748ad9404dd3..d830e2ab2fb73ae3c216baeba403a78233d24254 100644 (file)
@@ -731,13 +731,13 @@ virQEMUCapsInitGuest(virCapsPtr caps,
     if (!binary)
         return 0;
 
-    if (access("/dev/kvm", F_OK) == 0 &&
+    if (virFileExists("/dev/kvm") &&
         (virQEMUCapsGet(qemubinCaps, QEMU_CAPS_KVM) ||
          virQEMUCapsGet(qemubinCaps, QEMU_CAPS_ENABLE_KVM) ||
          kvmbin))
         haskvm = true;
 
-    if (access("/dev/kqemu", F_OK) == 0 &&
+    if (virFileExists("/dev/kqemu") &&
         virQEMUCapsGet(qemubinCaps, QEMU_CAPS_KQEMU))
         haskqemu = true;
 
index cf41c3324705dfd2ddf65be7ef1bed80dea8ddee..f95c7f2e678f0bc090aa765480c41fa5fa87ce04 100644 (file)
@@ -33,6 +33,7 @@
 #include "domain_audit.h"
 #include "virscsi.h"
 #include "virstring.h"
+#include "virfile.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -501,9 +502,8 @@ qemuSetupDevicesCgroup(virQEMUDriverPtr driver,
     }
 
     for (i = 0; deviceACL[i] != NULL; i++) {
-        if (access(deviceACL[i], F_OK) < 0) {
-            VIR_DEBUG("Ignoring non-existant device %s",
-                      deviceACL[i]);
+        if (!virFileExists(deviceACL[i])) {
+            VIR_DEBUG("Ignoring non-existant device %s", deviceACL[i]);
             continue;
         }
 
index c7cec5aab156af2a1147aaba53d524aa3cedf3b0..dd16f6ccbeba2fdb2970d2e4f5416e62e0ae4580 100644 (file)
@@ -3632,7 +3632,7 @@ int qemuProcessStart(virConnectPtr conn,
 
     if (vm->def->virtType == VIR_DOMAIN_VIRT_KVM) {
         VIR_DEBUG("Checking for KVM availability");
-        if (access("/dev/kvm", F_OK) != 0) {
+        if (!virFileExists("/dev/kvm")) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("Domain requires KVM, but it is not available. "
                              "Check that virtualization is enabled in the host BIOS, "
index d305b063ffd9dd01683e9105cfc6902948537ca4..f9b0326561c32954781bff7f08890bc37fb20de9 100644 (file)
@@ -501,13 +501,12 @@ virStorageBackendFileSystemCheck(virConnectPtr conn ATTRIBUTE_UNUSED,
                                  virStoragePoolObjPtr pool,
                                  bool *isActive)
 {
-    *isActive = false;
     if (pool->def->type == VIR_STORAGE_POOL_DIR) {
-        if (access(pool->def->target.path, F_OK) == 0)
-            *isActive = true;
+        *isActive = virFileExists(pool->def->target.path);
 #if WITH_STORAGE_FS
     } else {
         int ret;
+        *isActive = false;
         if ((ret = virStorageBackendFileSystemIsMounted(pool)) != 0) {
             if (ret < 0)
                 return -1;
index 0b146793e8190de4ea251dc6671b9b313a15b3ff..a1a37a1428470263b6b88c9b618834111eb69ed2 100644 (file)
@@ -453,7 +453,7 @@ virStorageBackendLogicalCheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
                                   virStoragePoolObjPtr pool,
                                   bool *isActive)
 {
-    *isActive = (access(pool->def->target.path, F_OK) == 0);
+    *isActive = virFileExists(pool->def->target.path);
     return 0;
 }
 
index 8333f18087ca2ccfe06346883b629df28108f94a..9a194842924c301fd834c85a00d94c4862a36f30 100644 (file)
@@ -287,13 +287,7 @@ virStorageBackendMpathCheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
                                 virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
                                 bool *isActive)
 {
-    const char *path = "/dev/mpath";
-
-    *isActive = false;
-
-    if (access(path, F_OK) == 0)
-        *isActive = true;
-
+    *isActive = virFileExists("/dev/mpath");
     return 0;
 }
 
index 8cb762a9f9191e3716105950e44d964952a235a4..57697997245207576e99468252016bab91488f06 100644 (file)
@@ -700,8 +700,7 @@ virStorageBackendSCSICheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
     if (virAsprintf(&path, "/sys/class/scsi_host/host%d", host) < 0)
         goto cleanup;
 
-    if (access(path, F_OK) == 0)
-        *isActive = true;
+    *isActive = virFileExists(path);
 
     ret = 0;
 cleanup:
index 626bbc6b870ef16803c1b7e735d88900b3b929da..a615f28fe846cf632085e7920d2cb4f60e5fd5ee 100644 (file)
@@ -905,7 +905,7 @@ virCgroupMakeGroup(virCgroupPtr parent,
         sa_assert(group->controllers[i].mountPoint);
 
         VIR_DEBUG("Make controller %s", path);
-        if (access(path, F_OK) != 0) {
+        if (!virFileExists(path)) {
             if (!create ||
                 mkdir(path, 0755) < 0) {
                 /* With a kernel that doesn't support multi-level directory
index a7635f45b6589470f033072ba42cdc4088582e7a..20ca89fd564db2d982608d8df619c0215a41ea0e 100644 (file)
@@ -735,7 +735,7 @@ virFileNBDDeviceIsBusy(const char *devname)
                     devname) < 0)
         return -1;
 
-    if (access(path, F_OK) < 0) {
+    if (!virFileExists(path)) {
         if (errno == ENOENT)
             ret = 0;
         else
index 92927aa58f964e1190b2e163568705576a8ff454..65d716879ab62633c4765d366724f80f1085805e 100644 (file)
@@ -1501,7 +1501,7 @@ virPCIDeviceNew(unsigned int domain,
                     dev->name) < 0)
         goto error;
 
-    if (access(dev->path, F_OK) != 0) {
+    if (!virFileExists(dev->path)) {
         virReportSystemError(errno,
                              _("Device %s not found: could not access %s"),
                              dev->name, dev->path);
index 32e438bd5bc3b0b45df7ce31fbe54dd129fdd741..43658c0ed973ec7818d5fdcebb0b9f99bf1a16b7 100644 (file)
@@ -216,7 +216,7 @@ virSCSIDeviceNew(const char *adapter,
         virAsprintf(&dev->sg_path, "/dev/%s", sg) < 0)
         goto cleanup;
 
-    if (access(dev->sg_path, F_OK) != 0) {
+    if (!virFileExists(dev->sg_path)) {
         virReportSystemError(errno,
                              _("SCSI device '%s': could not access %s"),
                              dev->name, dev->sg_path);
index 39d47171b6b421975d29db3035da5650a765d601..d9e0bc4a42b814c6539c8f85a554854e065d1684 100644 (file)
@@ -1711,7 +1711,7 @@ virIsCapableFCHost(const char *sysfs_prefix,
                     host) < 0)
         return false;
 
-    if (access(sysfs_path, F_OK) == 0)
+    if (virFileExists(sysfs_path))
         ret = true;
 
     VIR_FREE(sysfs_path);
@@ -1740,8 +1740,8 @@ virIsCapableVport(const char *sysfs_prefix,
                     "vport_create") < 0)
         goto cleanup;
 
-    if ((access(fc_host_path, F_OK) == 0) ||
-        (access(scsi_host_path, F_OK) == 0))
+    if (virFileExists(fc_host_path) ||
+        virFileExists(scsi_host_path))
         ret = true;
 
 cleanup: