]> xenbits.xensource.com Git - libvirt.git/commitdiff
Use virDirOpen
authorJán Tomko <jtomko@redhat.com>
Tue, 21 Jun 2016 14:34:08 +0000 (16:34 +0200)
committerJán Tomko <jtomko@redhat.com>
Fri, 24 Jun 2016 12:20:57 +0000 (14:20 +0200)
Switch from opendir to virDirOpen everywhere we need to report an error.

16 files changed:
src/storage/storage_backend_fs.c
src/storage/storage_backend_iscsi.c
src/storage/storage_backend_scsi.c
src/util/vircgroup.c
src/util/virfile.c
src/util/virhostcpu.c
src/util/virnetdev.c
src/util/virnetdevtap.c
src/util/virpci.c
src/util/virprocess.c
src/util/virscsi.c
src/util/virusb.c
src/util/virutil.c
src/xen/xen_inotify.c
src/xen/xm_internal.c
tests/virschematest.c

index 33cf90d5702aaf20ccb0142d216d22e897321159..44dabf4774276044fc76e44c30c21523e83ec23e 100644 (file)
@@ -900,12 +900,8 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
     int direrr;
     int fd = -1, ret = -1;
 
-    if (!(dir = opendir(pool->def->target.path))) {
-        virReportSystemError(errno,
-                             _("cannot open path '%s'"),
-                             pool->def->target.path);
+    if (virDirOpen(&dir, pool->def->target.path) < 0)
         goto cleanup;
-    }
 
     while ((direrr = virDirRead(dir, &ent, pool->def->target.path)) > 0) {
         int err;
index ad8633e3eab8e84be99c7edd0ddf040e2620d87f..4a16d2b7e3bf420c4416f07d73cd139dc1bd9af4 100644 (file)
@@ -100,9 +100,7 @@ virStorageBackendISCSIGetHostNumber(const char *sysfs_path,
 
     virFileWaitForDevices();
 
-    sysdir = opendir(sysfs_path);
-
-    if (sysdir == NULL) {
+    if (virDirOpen(&sysdir, sysfs_path) < 0)
         virReportSystemError(errno,
                              _("Failed to opendir path '%s'"), sysfs_path);
         retval = -1;
index d05f013ceefb4e4cfa75d62ad0e1c529f505ce16..558b3cf49c7e6e5d6c508d8ffb163a4db7146565 100644 (file)
@@ -265,12 +265,8 @@ getNewStyleBlockDevice(const char *lun_path,
 
     VIR_DEBUG("Looking for block device in '%s'", block_path);
 
-    if (!(block_dir = opendir(block_path))) {
-        virReportSystemError(errno,
-                             _("Failed to opendir sysfs path '%s'"),
-                             block_path);
+    if (virDirOpen(&block_dir, block_path) < 0)
         goto cleanup;
-    }
 
     while ((direrr = virDirRead(block_dir, &block_dirent, block_path)) > 0) {
         if (VIR_STRDUP(*block_device, block_dirent->d_name) < 0)
@@ -350,12 +346,8 @@ getBlockDevice(uint32_t host,
                     host, bus, target, lun) < 0)
         goto cleanup;
 
-    if (!(lun_dir = opendir(lun_path))) {
-        virReportSystemError(errno,
-                             _("Failed to opendir sysfs path '%s'"),
-                             lun_path);
+    if (virDirOpen(&lun_dir, lun_path) < 0)
         goto cleanup;
-    }
 
     while ((direrr = virDirRead(lun_dir, &lun_dirent, lun_path)) > 0) {
         if (STREQLEN(lun_dirent->d_name, "block", 5)) {
@@ -467,13 +459,8 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
 
     virFileWaitForDevices();
 
-    devicedir = opendir(device_path);
-
-    if (devicedir == NULL) {
-        virReportSystemError(errno,
-                             _("Failed to opendir path '%s'"), device_path);
+    if (virDirOpen(&devicedir, device_path) < 0)
         return -1;
-    }
 
     snprintf(devicepattern, sizeof(devicepattern), "%u:%%u:%%u:%%u\n", scanhost);
 
index e91f5f6d4ddde4845b98452a5c0f06aceea1e929..e90cceee222b9cdbf384a61e5909aa3f990bdd30 100644 (file)
@@ -3952,11 +3952,8 @@ int virCgroupSetOwner(virCgroupPtr cgroup,
                         cgroup->controllers[i].placement) < 0)
             goto cleanup;
 
-        if (!(dh = opendir(base))) {
-            virReportSystemError(errno,
-                                 _("Unable to open dir '%s'"), base);
+        if (virDirOpen(&dh, base) < 0)
             goto cleanup;
-        }
 
         while ((direrr = virDirRead(dh, &de, base)) > 0) {
             if (virAsprintf(&entry, "%s/%s", base, de->d_name) < 0)
index 697ebc0f60d32d2a001f6e140aa1b9f481e7b3df..bf5e2b3a0c57498e0554af691d4a7512809f1c7a 100644 (file)
@@ -614,11 +614,8 @@ static int virFileLoopDeviceOpenSearch(char **dev_name)
 
     VIR_DEBUG("Looking for loop devices in /dev");
 
-    if (!(dh = opendir("/dev"))) {
-        virReportSystemError(errno, "%s",
-                             _("Unable to read /dev"));
+    if (virDirOpen(&dh, "/dev") < 0)
         goto cleanup;
-    }
 
     while ((direrr = virDirRead(dh, &de, "/dev")) > 0) {
         /* Checking 'loop' prefix is insufficient, since
@@ -782,12 +779,8 @@ virFileNBDDeviceFindUnused(void)
     struct dirent *de;
     int direrr;
 
-    if (!(dh = opendir(SYSFS_BLOCK_DIR))) {
-        virReportSystemError(errno,
-                             _("Cannot read directory %s"),
-                             SYSFS_BLOCK_DIR);
+    if (virDirOpen(&dh, SYSFS_BLOCK_DIR) < 0)
         return NULL;
-    }
 
     while ((direrr = virDirRead(dh, &de, SYSFS_BLOCK_DIR)) > 0) {
         if (STRPREFIX(de->d_name, "nbd")) {
@@ -942,11 +935,8 @@ int virFileDeleteTree(const char *dir)
     if (!dir || !virFileExists(dir))
         return 0;
 
-    if (!(dh = opendir(dir))) {
-        virReportSystemError(errno, _("Cannot open dir '%s'"),
-                             dir);
+    if (virDirOpen(&dh, dir) < 0)
         return -1;
-    }
 
     while ((direrr = virDirRead(dh, &de, dir)) > 0) {
         struct stat sb;
index 6883466b70f86d3870c3425f33681d1b8c6e04d1..087ce225847d7c64681c01196bd7791e5c6966f5 100644 (file)
@@ -339,10 +339,8 @@ virHostCPUParseNode(const char *node,
     *cores = 0;
     *sockets = 0;
 
-    if (!(cpudir = opendir(node))) {
-        virReportSystemError(errno, _("cannot opendir %s"), node);
+    if (virDirOpen(&cpudir, node) < 0)
         goto cleanup;
-    }
 
     /* Keep track of the CPUs that belong to the current node */
     if (!(node_cpus_map = virBitmapNew(npresent_cpus)))
index 2a5fe159b61feb7305677b5d5ef153b1bbbe0436..cdbc41b175702a0b00952f3bb7cc994fc4879a3e 100644 (file)
@@ -3157,12 +3157,8 @@ virNetDevRDMAFeature(const char *ifname,
     if (!virFileExists(SYSFS_INFINIBAND_DIR))
         return 0;
 
-    if (!(dirp = opendir(SYSFS_INFINIBAND_DIR))) {
-        virReportSystemError(errno,
-                             _("Failed to opendir path '%s'"),
-                             SYSFS_INFINIBAND_DIR);
+    if (virDirOpen(&dirp, SYSFS_INFINIBAND_DIR) < 0)
         return -1;
-    }
 
     if (virAsprintf(&eth_devpath, SYSFS_NET_DIR "%s/device/resource", ifname) < 0)
         goto cleanup;
index eec7614f54c04f97b2414f8df259a109b38d879f..98e27bb26852719b7dd9d4935bd4637699bf9c31 100644 (file)
@@ -98,13 +98,8 @@ virNetDevTapGetRealDeviceName(char *ifname ATTRIBUTE_UNUSED)
     char *devpath = NULL;
     int fd;
 
-    DIR *dirp = opendir("/dev");
-    if (dirp == NULL) {
-        virReportSystemError(errno,
-                             _("Failed to opendir path '%s'"),
-                             "/dev");
+    if (virDirOpen(&dirp, "/dev") < 0)
         return NULL;
-    }
 
     while (virDirRead(dirp, &dp, "/dev") > 0) {
         if (STRPREFIX(dp->d_name, "tap")) {
index 7273327b3c8f60d37f3580d4ef8cc08cd118a130..98951119d759960b0b6397654430e4eec452b05b 100644 (file)
@@ -460,11 +460,8 @@ virPCIDeviceIterDevices(virPCIDeviceIterPredicate predicate,
 
     VIR_DEBUG("%s %s: iterating over " PCI_SYSFS "devices", dev->id, dev->name);
 
-    dir = opendir(PCI_SYSFS "devices");
-    if (!dir) {
-        VIR_WARN("Failed to open " PCI_SYSFS "devices");
+    if (virDirOpen(&dir, PCI_SYSFS "devices") < 0)
         return -1;
-    }
 
     while ((ret = virDirRead(dir, &entry, PCI_SYSFS "devices")) > 0) {
         unsigned int domain, bus, slot, function;
@@ -1958,11 +1955,8 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev,
                     dev->address.slot, dev->address.function) < 0)
         goto cleanup;
 
-    if (!(dir = opendir(pcidir))) {
-        virReportSystemError(errno,
-                             _("cannot open %s"), pcidir);
+    if (virDirOpen(&dir, pcidir) < 0)
         goto cleanup;
-    }
 
     while ((direrr = virDirRead(dir, &ent, pcidir)) > 0) {
         /* Device assignment requires:
index 5541a4f1cc488b0d523efb3205e1066acedc25bc..09dd3c90f47181a88a8f33f72a87cc2a629d787f 100644 (file)
@@ -612,7 +612,7 @@ int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids)
                     (unsigned long long)pid) < 0)
         goto cleanup;
 
-    if (!(dir = opendir(taskPath)))
+    if (virDirOpen(&dir, taskPath) < 0)
         goto cleanup;
 
     while ((value = virDirRead(dir, &ent, taskPath)) > 0) {
index ec5e017883025e7557619dd84b57283dd99a4c96..4843367e06de48217d5e290c8dd258715d8fb817 100644 (file)
@@ -127,11 +127,8 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix,
                     prefix, adapter_id, bus, target, unit) < 0)
         return NULL;
 
-    if (!(dir = opendir(path))) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Failed to open %s"), path);
+    if (virDirOpen(&dir, path) < 0)
         goto cleanup;
-    }
 
     while (virDirRead(dir, &entry, path) > 0) {
         /* Assume a single directory entry */
@@ -170,11 +167,8 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix,
                     prefix, adapter_id, bus, target, unit) < 0)
         return NULL;
 
-    if (!(dir = opendir(path))) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Failed to open %s"), path);
+    if (virDirOpen(&dir, path) < 0)
         goto cleanup;
-    }
 
     while (virDirRead(dir, &entry, path) > 0) {
         ignore_value(VIR_STRDUP(name, entry->d_name));
index 5a95dcb5a195358f137fd20a058618ea23226fa7..6a001a77bea04455bd5ed2646155cf07dbef0851 100644 (file)
@@ -138,13 +138,8 @@ virUSBDeviceSearch(unsigned int vendor,
     if (!(list = virUSBDeviceListNew()))
         goto cleanup;
 
-    dir = opendir(USB_SYSFS "/devices");
-    if (!dir) {
-        virReportSystemError(errno,
-                             _("Could not open directory %s"),
-                             USB_SYSFS "/devices");
+    if (virDirOpen(&dir, USB_SYSFS "/devices") < 0)
         goto cleanup;
-    }
 
     while ((direrr = virDirRead(dir, &de, USB_SYSFS "/devices")) > 0) {
         unsigned int found_prod, found_vend, found_bus, found_devno;
index 1bd7db82cee488d8a2ebb45933ef1dc35ba74bc0..170dd59a2b14aabb0d6ef0c3ba2d243c9d4a9f44 100644 (file)
@@ -1860,12 +1860,8 @@ virFindSCSIHostByPCI(const char *sysfs_prefix,
     char *unique_path = NULL;
     unsigned int read_unique_id;
 
-    if (!(dir = opendir(prefix))) {
-        virReportSystemError(errno,
-                             _("Failed to opendir path '%s'"),
-                             prefix);
+    if (virDirOpen(&dir, prefix) < 0)
         return NULL;
-    }
 
     while (virDirRead(dir, &entry, prefix) > 0) {
         if (!virFileIsLink(entry->d_name))
@@ -2198,12 +2194,8 @@ virGetFCHostNameByWWN(const char *sysfs_prefix,
     char *p;
     char *ret = NULL;
 
-    if (!(dir = opendir(prefix))) {
-        virReportSystemError(errno,
-                             _("Failed to opendir path '%s'"),
-                             prefix);
+    if (virDirOpen(&dir, prefix) < 0)
         return NULL;
-    }
 
 # define READ_WWN(wwn_path, buf)                      \
     do {                                              \
@@ -2289,12 +2281,8 @@ virFindFCHostCapableVport(const char *sysfs_prefix)
     char *state = NULL;
     char *ret = NULL;
 
-    if (!(dir = opendir(prefix))) {
-        virReportSystemError(errno,
-                             _("Failed to opendir path '%s'"),
-                             prefix);
+    if (virDirOpen(&dir, prefix) < 0)
         return NULL;
-    }
 
     while (virDirRead(dir, &entry, prefix) > 0) {
         unsigned int host;
index cd169e01e1f21dce9d7e89e611d09099d889772b..ac4070c9179c1d680e52b14c768b7c054518da8c 100644 (file)
@@ -360,12 +360,9 @@ xenInotifyOpen(virConnectPtr conn,
             return -1;
 
         /* populate initial list */
-        if (!(dh = opendir(priv->configDir))) {
-            virReportSystemError(errno,
-                                 _("cannot open directory: %s"),
-                                 priv->configDir);
+        if (virDirOpen(&dh, priv->configDir) < 0)
             return -1;
-        }
+
         while ((direrr = virDirRead(dh, &ent, priv->configDir)) > 0) {
             if (STRPREFIX(ent->d_name, "."))
                 continue;
index e7ac57e659cb3470782c49743c7ed55eed5087b9..3c34652c89e58371e0a913c242df00968f6e6e51 100644 (file)
@@ -319,12 +319,8 @@ xenXMConfigCacheRefresh(virConnectPtr conn)
     priv->lastRefresh = now;
 
     /* Process the files in the config dir */
-    if (!(dh = opendir(priv->configDir))) {
-        virReportSystemError(errno,
-                             _("cannot read directory %s"),
-                             priv->configDir);
+    if (virDirOpen(&dh, priv->configDir) < 0)
         return -1;
-    }
 
     while ((ret = virDirRead(dh, &ent, priv->configDir)) > 0) {
         struct stat st;
index 14a9e2031b78048005966faec814b2a04dd4e5cd..c372c4373dc6d6e4532a3397aa64a46c4ba836dd 100644 (file)
@@ -80,12 +80,8 @@ testSchemaDir(const char *schema,
         .validator = validator,
     };
 
-    if (!(dir = opendir(dir_path))) {
-        virReportSystemError(errno,
-                             "Failed to opendir path '%s'",
-                             dir_path);
+    if (virDirOpen(&dir, dir_path) < 0)
         return -1;
-    }
 
     while ((rc = virDirRead(dir, &ent, dir_path)) > 0) {
         if (!virFileHasSuffix(ent->d_name, ".xml"))