提交 ddcf4730 编写于 作者: E Eric Blake

drivers: use virDirRead API

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: NEric Blake <eblake@redhat.com>
上级 ac1d42ac
......@@ -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);
......
......@@ -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:
......
......@@ -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"),
......
/*
* 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 */
......
/*
* 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) {
......
......@@ -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) {
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册