cleanup: Kill usage of access(PATH, F_OK) in favor of virFileExists()

Semantics of the libvirt helper are more clear. This change also allows
to clean up some pieces of code.
This commit is contained in:
Peter Krempa 2013-09-13 15:32:43 +02:00
parent d66e7ce616
commit 4baa8d7637
14 changed files with 20 additions and 28 deletions

View File

@ -940,7 +940,7 @@ openvzLocateConfDir(void)
char *ret = NULL; char *ret = NULL;
while (conf_dir_list[i]) { 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])); ignore_value(VIR_STRDUP(ret, conf_dir_list[i]));
goto cleanup; goto cleanup;
} }

View File

@ -362,7 +362,7 @@ static int parallelsFindVmVolumes(virStoragePoolObjPtr pool,
"DiskDescriptor", ".xml"))) "DiskDescriptor", ".xml")))
goto cleanup; goto cleanup;
if (access(diskDescPath, F_OK)) if (!virFileExists(diskDescPath))
continue; continue;
/* here we know, that ent->d_name is a disk image directory */ /* here we know, that ent->d_name is a disk image directory */

View File

@ -731,13 +731,13 @@ virQEMUCapsInitGuest(virCapsPtr caps,
if (!binary) if (!binary)
return 0; return 0;
if (access("/dev/kvm", F_OK) == 0 && if (virFileExists("/dev/kvm") &&
(virQEMUCapsGet(qemubinCaps, QEMU_CAPS_KVM) || (virQEMUCapsGet(qemubinCaps, QEMU_CAPS_KVM) ||
virQEMUCapsGet(qemubinCaps, QEMU_CAPS_ENABLE_KVM) || virQEMUCapsGet(qemubinCaps, QEMU_CAPS_ENABLE_KVM) ||
kvmbin)) kvmbin))
haskvm = true; haskvm = true;
if (access("/dev/kqemu", F_OK) == 0 && if (virFileExists("/dev/kqemu") &&
virQEMUCapsGet(qemubinCaps, QEMU_CAPS_KQEMU)) virQEMUCapsGet(qemubinCaps, QEMU_CAPS_KQEMU))
haskqemu = true; haskqemu = true;

View File

@ -33,6 +33,7 @@
#include "domain_audit.h" #include "domain_audit.h"
#include "virscsi.h" #include "virscsi.h"
#include "virstring.h" #include "virstring.h"
#include "virfile.h"
#define VIR_FROM_THIS VIR_FROM_QEMU #define VIR_FROM_THIS VIR_FROM_QEMU
@ -501,9 +502,8 @@ qemuSetupDevicesCgroup(virQEMUDriverPtr driver,
} }
for (i = 0; deviceACL[i] != NULL; i++) { for (i = 0; deviceACL[i] != NULL; i++) {
if (access(deviceACL[i], F_OK) < 0) { if (!virFileExists(deviceACL[i])) {
VIR_DEBUG("Ignoring non-existant device %s", VIR_DEBUG("Ignoring non-existant device %s", deviceACL[i]);
deviceACL[i]);
continue; continue;
} }

View File

@ -3632,7 +3632,7 @@ int qemuProcessStart(virConnectPtr conn,
if (vm->def->virtType == VIR_DOMAIN_VIRT_KVM) { if (vm->def->virtType == VIR_DOMAIN_VIRT_KVM) {
VIR_DEBUG("Checking for KVM availability"); VIR_DEBUG("Checking for KVM availability");
if (access("/dev/kvm", F_OK) != 0) { if (!virFileExists("/dev/kvm")) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Domain requires KVM, but it is not available. " _("Domain requires KVM, but it is not available. "
"Check that virtualization is enabled in the host BIOS, " "Check that virtualization is enabled in the host BIOS, "

View File

@ -501,13 +501,12 @@ virStorageBackendFileSystemCheck(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool, virStoragePoolObjPtr pool,
bool *isActive) bool *isActive)
{ {
*isActive = false;
if (pool->def->type == VIR_STORAGE_POOL_DIR) { if (pool->def->type == VIR_STORAGE_POOL_DIR) {
if (access(pool->def->target.path, F_OK) == 0) *isActive = virFileExists(pool->def->target.path);
*isActive = true;
#if WITH_STORAGE_FS #if WITH_STORAGE_FS
} else { } else {
int ret; int ret;
*isActive = false;
if ((ret = virStorageBackendFileSystemIsMounted(pool)) != 0) { if ((ret = virStorageBackendFileSystemIsMounted(pool)) != 0) {
if (ret < 0) if (ret < 0)
return -1; return -1;

View File

@ -453,7 +453,7 @@ virStorageBackendLogicalCheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool, virStoragePoolObjPtr pool,
bool *isActive) bool *isActive)
{ {
*isActive = (access(pool->def->target.path, F_OK) == 0); *isActive = virFileExists(pool->def->target.path);
return 0; return 0;
} }

View File

@ -287,13 +287,7 @@ virStorageBackendMpathCheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
bool *isActive) bool *isActive)
{ {
const char *path = "/dev/mpath"; *isActive = virFileExists("/dev/mpath");
*isActive = false;
if (access(path, F_OK) == 0)
*isActive = true;
return 0; return 0;
} }

View File

@ -700,8 +700,7 @@ virStorageBackendSCSICheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
if (virAsprintf(&path, "/sys/class/scsi_host/host%d", host) < 0) if (virAsprintf(&path, "/sys/class/scsi_host/host%d", host) < 0)
goto cleanup; goto cleanup;
if (access(path, F_OK) == 0) *isActive = virFileExists(path);
*isActive = true;
ret = 0; ret = 0;
cleanup: cleanup:

View File

@ -905,7 +905,7 @@ virCgroupMakeGroup(virCgroupPtr parent,
sa_assert(group->controllers[i].mountPoint); sa_assert(group->controllers[i].mountPoint);
VIR_DEBUG("Make controller %s", path); VIR_DEBUG("Make controller %s", path);
if (access(path, F_OK) != 0) { if (!virFileExists(path)) {
if (!create || if (!create ||
mkdir(path, 0755) < 0) { mkdir(path, 0755) < 0) {
/* With a kernel that doesn't support multi-level directory /* With a kernel that doesn't support multi-level directory

View File

@ -735,7 +735,7 @@ virFileNBDDeviceIsBusy(const char *devname)
devname) < 0) devname) < 0)
return -1; return -1;
if (access(path, F_OK) < 0) { if (!virFileExists(path)) {
if (errno == ENOENT) if (errno == ENOENT)
ret = 0; ret = 0;
else else

View File

@ -1501,7 +1501,7 @@ virPCIDeviceNew(unsigned int domain,
dev->name) < 0) dev->name) < 0)
goto error; goto error;
if (access(dev->path, F_OK) != 0) { if (!virFileExists(dev->path)) {
virReportSystemError(errno, virReportSystemError(errno,
_("Device %s not found: could not access %s"), _("Device %s not found: could not access %s"),
dev->name, dev->path); dev->name, dev->path);

View File

@ -216,7 +216,7 @@ virSCSIDeviceNew(const char *adapter,
virAsprintf(&dev->sg_path, "/dev/%s", sg) < 0) virAsprintf(&dev->sg_path, "/dev/%s", sg) < 0)
goto cleanup; goto cleanup;
if (access(dev->sg_path, F_OK) != 0) { if (!virFileExists(dev->sg_path)) {
virReportSystemError(errno, virReportSystemError(errno,
_("SCSI device '%s': could not access %s"), _("SCSI device '%s': could not access %s"),
dev->name, dev->sg_path); dev->name, dev->sg_path);

View File

@ -1711,7 +1711,7 @@ virIsCapableFCHost(const char *sysfs_prefix,
host) < 0) host) < 0)
return false; return false;
if (access(sysfs_path, F_OK) == 0) if (virFileExists(sysfs_path))
ret = true; ret = true;
VIR_FREE(sysfs_path); VIR_FREE(sysfs_path);
@ -1740,8 +1740,8 @@ virIsCapableVport(const char *sysfs_prefix,
"vport_create") < 0) "vport_create") < 0)
goto cleanup; goto cleanup;
if ((access(fc_host_path, F_OK) == 0) || if (virFileExists(fc_host_path) ||
(access(scsi_host_path, F_OK) == 0)) virFileExists(scsi_host_path))
ret = true; ret = true;
cleanup: cleanup: