]> xenbits.xensource.com Git - libvirt.git/commitdiff
drivers: use virDirRead API
authorEric Blake <eblake@redhat.com>
Sat, 26 Apr 2014 04:11:05 +0000 (22:11 -0600)
committerEric Blake <eblake@redhat.com>
Mon, 28 Apr 2014 23:52:45 +0000 (17:52 -0600)
Convert all remaining clients of readdir to use the new
interface, so that we can ensure (unlikely) errors while
reading a directory are reported.

* src/openvz/openvz_conf.c (openvzAssignUUIDs): Use new
interface.
* src/parallels/parallels_storage.c (parallelsFindVolumes)
(parallelsFindVmVolumes): Report readdir failures.
* src/qemu/qemu_driver.c (qemuDomainSnapshotLoad): Ignore readdir
failures.
* src/secret/secret_driver.c (loadSecrets): Likewise.
* src/qemu/qemu_hostdev.c
(qemuHostdevHostSupportsPassthroughVFIO): Report readdir failures.
* src/xen/xen_inotify.c (xenInotifyOpen): Likewise.
* src/xen/xm_internal.c (xenXMConfigCacheRefresh): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
src/openvz/openvz_conf.c
src/parallels/parallels_storage.c
src/qemu/qemu_driver.c
src/qemu/qemu_hostdev.c
src/secret/secret_driver.c
src/xen/xen_inotify.c
src/xen/xm_internal.c

index a7aff2a5ccae2828b7c7a5fae521f9c2b69a7ed9..dc84b298606d29e6d7b0c8bfbd247b92b65b1e89 100644 (file)
@@ -1105,20 +1105,13 @@ static int openvzAssignUUIDs(void)
         return 0;
     }
 
-    errno = 0;
-    while ((dent = readdir(dp))) {
+    while ((ret = virDirRead(dp, &dent, conf_dir)) > 0) {
         if (virStrToLong_i(dent->d_name, &ext, 10, &vpsid) < 0 ||
             *ext++ != '.' ||
             STRNEQ(ext, "conf"))
             continue;
         if (vpsid > 0) /* '0.conf' belongs to the host, ignore it */
             openvzSetUUID(vpsid);
-        errno = 0;
-    }
-    if (errno) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Failed to scan configuration directory"));
-        ret = -1;
     }
 
     closedir(dp);
index 736d0600cad633d980284183e5bea8a662bdb884..4dbaed18caa5bd19749e77cac229c520ce7b2cc5 100644 (file)
@@ -93,6 +93,7 @@ parallelsFindVolumes(virStoragePoolObjPtr pool)
     struct dirent *ent;
     char *path = NULL;
     int ret = -1;
+    int direrr;
 
     if (!(dir = opendir(pool->def->target.path))) {
         virReportSystemError(errno,
@@ -101,7 +102,7 @@ parallelsFindVolumes(virStoragePoolObjPtr pool)
         return -1;
     }
 
-    while ((ent = readdir(dir)) != NULL) {
+    while ((direrr = virDirRead(dir, &ent, pool->def->target.path)) > 0) {
         if (!virFileHasSuffix(ent->d_name, ".xml"))
             continue;
 
@@ -113,6 +114,8 @@ parallelsFindVolumes(virStoragePoolObjPtr pool)
 
         VIR_FREE(path);
     }
+    if (direrr < 0)
+        goto cleanup;
 
     ret = 0;
  cleanup:
@@ -331,6 +334,7 @@ static int parallelsFindVmVolumes(virStoragePoolObjPtr pool,
     char *diskPath = NULL, *diskDescPath = NULL;
     struct stat sb;
     int ret = -1;
+    int direrr;
 
     if (!(dir = opendir(pdom->home))) {
         virReportSystemError(errno,
@@ -339,7 +343,7 @@ static int parallelsFindVmVolumes(virStoragePoolObjPtr pool,
         goto cleanup;
     }
 
-    while ((ent = readdir(dir)) != NULL) {
+    while ((direrr = virDirRead(dir, &ent, pdom->home)) > 0) {
         VIR_FREE(diskPath);
         VIR_FREE(diskDescPath);
 
@@ -368,8 +372,9 @@ static int parallelsFindVmVolumes(virStoragePoolObjPtr pool,
         if (parallelsAddDiskVolume(pool, dom, ent->d_name,
                                    diskPath, diskDescPath))
             goto cleanup;
-
     }
+    if (direrr < 0)
+        goto cleanup;
 
     ret = 0;
  cleanup:
index e0b855054d13380606e50ccf903f4cbaa3b1abdb..75cf8cb450d5c13bf44dc370dbab7ee95fa8f1f8 100644 (file)
@@ -417,6 +417,7 @@ qemuDomainSnapshotLoad(virDomainObjPtr vm,
                           VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL);
     int ret = -1;
     virCapsPtr caps = NULL;
+    int direrr;
 
     virObjectLock(vm);
     if (virAsprintf(&snapDir, "%s/%s", baseDir, vm->def->name) < 0) {
@@ -439,7 +440,7 @@ qemuDomainSnapshotLoad(virDomainObjPtr vm,
         goto cleanup;
     }
 
-    while ((entry = readdir(dir))) {
+    while ((direrr = virDirRead(dir, &entry, NULL)) > 0) {
         if (entry->d_name[0] == '.')
             continue;
 
@@ -485,6 +486,8 @@ qemuDomainSnapshotLoad(virDomainObjPtr vm,
         VIR_FREE(fullpath);
         VIR_FREE(xmlStr);
     }
+    if (direrr < 0)
+        VIR_ERROR(_("Failed to fully read directory %s"), snapDir);
 
     if (vm->current_snapshot != current) {
         VIR_ERROR(_("Too many snapshots claiming to be current for domain %s"),
index e9879c4010e5b011947fc99e3930963e8d2fb636..706db0c2beb17109402dec559b5b7d4b0431c33e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * qemu_hostdev.c: QEMU hostdev management
  *
- * Copyright (C) 2006-2007, 2009-2013 Red Hat, Inc.
+ * Copyright (C) 2006-2007, 2009-2014 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -90,12 +90,13 @@ qemuHostdevHostSupportsPassthroughVFIO(void)
     DIR *iommuDir = NULL;
     struct dirent *iommuGroup = NULL;
     bool ret = false;
+    int direrr;
 
     /* condition 1 - /sys/kernel/iommu_groups/ contains entries */
     if (!(iommuDir = opendir("/sys/kernel/iommu_groups/")))
         goto cleanup;
 
-    while ((iommuGroup = readdir(iommuDir))) {
+    while ((direrr = virDirRead(iommuDir, &iommuGroup, NULL)) > 0) {
         /* skip ./ ../ */
         if (STRPREFIX(iommuGroup->d_name, "."))
             continue;
@@ -104,7 +105,7 @@ qemuHostdevHostSupportsPassthroughVFIO(void)
         break;
     }
 
-    if (!iommuGroup)
+    if (direrr < 0 || !iommuGroup)
         goto cleanup;
     /* okay, iommu is on and recognizes groups */
 
index a7dfdf08078faaadfab5714b1ebf089c7023c65b..cd04b20aa4222327cf4eacb482984177c6be33ce 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * secret_driver.c: local driver for secret manipulation API
  *
- * Copyright (C) 2009-2012, 2014 Red Hat, Inc.
+ * Copyright (C) 2009-2014 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -484,7 +484,7 @@ loadSecrets(virSecretDriverStatePtr driver,
                              driver->directory);
         goto cleanup;
     }
-    while ((de = readdir(dir)) != NULL) {
+    while (virDirRead(dir, &de, NULL) > 0) {
         virSecretEntryPtr secret;
 
         if (STREQ(de->d_name, ".") || STREQ(de->d_name, ".."))
@@ -503,7 +503,7 @@ loadSecrets(virSecretDriverStatePtr driver,
         }
         listInsert(&list, secret);
     }
-    /* Ignore error reported by readdir(), if any.  It's better to keep the
+    /* Ignore error reported by readdir, if any.  It's better to keep the
        secrets we managed to find. */
 
     while (list != NULL) {
index 7c2d133d458ce63c1bd772b16a3c5e21abed94d9..cd1e2dfba97655d0720edacff970e0bd1724b60b 100644 (file)
@@ -4,7 +4,7 @@
  *                /etc/xen
  *                /var/lib/xend/domains
  *
- * Copyright (C) 2010-2013 Red Hat, Inc.
+ * Copyright (C) 2010-2014 Red Hat, Inc.
  * Copyright (C) 2008 VirtualIron
  *
  * This library is free software; you can redistribute it and/or
@@ -343,6 +343,7 @@ xenInotifyOpen(virConnectPtr conn,
     struct dirent *ent;
     char *path;
     xenUnifiedPrivatePtr priv = conn->privateData;
+    int direrr;
 
     virCheckFlags(VIR_CONNECT_RO, -1);
 
@@ -363,7 +364,7 @@ xenInotifyOpen(virConnectPtr conn,
                                  priv->configDir);
             return -1;
         }
-        while ((ent = readdir(dh))) {
+        while ((direrr = virDirRead(dh, &ent, priv->configDir)) > 0) {
             if (STRPREFIX(ent->d_name, "."))
                 continue;
 
@@ -384,6 +385,8 @@ xenInotifyOpen(virConnectPtr conn,
             VIR_FREE(path);
         }
         closedir(dh);
+        if (direrr < 0)
+            return -1;
     }
 
     if ((priv->inotifyFD = inotify_init()) < 0) {
index f25a7df6de492b3c9f6b5991c3afccbfdcfd7df7..30985d8929b5c917e859bafbca1537e9038037c0 100644 (file)
@@ -327,7 +327,7 @@ xenXMConfigCacheRefresh(virConnectPtr conn)
         return -1;
     }
 
-    while ((ent = readdir(dh))) {
+    while ((ret = virDirRead(dh, &ent, priv->configDir)) > 0) {
         struct stat st;
         char *path;
 
@@ -386,7 +386,6 @@ xenXMConfigCacheRefresh(virConnectPtr conn)
     args.now = now;
     args.priv = priv;
     virHashRemoveSet(priv->configCache, xenXMConfigReaper, &args);
-    ret = 0;
 
     closedir(dh);