[libvirt] [PATCHv2 00/14] virjsontest: separate some tests into files
by Ján Tomko
v1:
cover.1549987014.git.jtomko(a)redhat.com
v2:
prettify output, use VIR_AUTO and better-looking commit messages
Ján Tomko (14):
virjsontest: switch AddAndRemove tests to work with files
testJSONFromString: regroup if blocks
virjsontest: reword error messages in testJSONFromString
virjsontest: use VIR_AUTOPTR for virJSONValues
virjsontest: use VIR_AUTOFREE for strings
virjsontest: remove unnecessary cleanup labels
virjsontest: introduce DO_TEST_PARSE_FILE
virjsontest: switch DO_TEST_PARSE_FILE to use output files
virjsontest: reformat add-remove test input data
vvv--- squash into: json_reformat add-remove output data
virjsontest: prettify AddRemove test
virjsondata: json_reformat input data
vvv SQUASH HERE: reformat parseFile output data
virjsontest: prettify JSONFromFile test
tests/virjsondata/add-remove-failure-in.json | 3 +
tests/virjsondata/add-remove-success-in.json | 4 +
tests/virjsondata/add-remove-success-out.json | 4 +
tests/virjsondata/parse-Harder-in.json | 13 +
tests/virjsondata/parse-Harder-out.json | 13 +
tests/virjsondata/parse-NotSoSimple-in.json | 15 +
tests/virjsondata/parse-NotSoSimple-out.json | 15 +
tests/virjsondata/parse-Simple-in.json | 6 +
tests/virjsondata/parse-Simple-out.json | 6 +
tests/virjsondata/parse-VeryHard-in.json | 143 +++++++
tests/virjsondata/parse-VeryHard-out.json | 143 +++++++
tests/virjsontest.c | 370 ++++++++----------
12 files changed, 531 insertions(+), 204 deletions(-)
create mode 100644 tests/virjsondata/add-remove-failure-in.json
create mode 100644 tests/virjsondata/add-remove-success-in.json
create mode 100644 tests/virjsondata/add-remove-success-out.json
create mode 100644 tests/virjsondata/parse-Harder-in.json
create mode 100644 tests/virjsondata/parse-Harder-out.json
create mode 100644 tests/virjsondata/parse-NotSoSimple-in.json
create mode 100644 tests/virjsondata/parse-NotSoSimple-out.json
create mode 100644 tests/virjsondata/parse-Simple-in.json
create mode 100644 tests/virjsondata/parse-Simple-out.json
create mode 100644 tests/virjsondata/parse-VeryHard-in.json
create mode 100644 tests/virjsondata/parse-VeryHard-out.json
--
2.19.2
5 years, 7 months
[libvirt] [PATCH 00/14] virsh: introduce a password completer
by Ján Tomko
Ján Tomko (14):
virsh: fix indentation of info_managed_save_edit
virsh-completer: fix typo
virsh-completer: reword documentation
virsh-completer: switch to using tmp instead of ret
virsh-completer: add a cleanup label everywhere
virsh-completer: unify cleanup of items in name completers
virsh-completer: virStringListFree where possible
virsh-completer: use VIR_AUTOSTRINGLIST for tmp
use VIR_AUTOFREE for xmlNodePtr* variables
virsh-completer: use VIR_AUTOPTR for xml* variables
virsh-completer: use VIR_AUTOFREE for char* variables
virsh-completer: remove excessive labels
virsh-completer: introduce virshPagesizeNodeToString
virsh-completer: introduce virshPasswordCompleter
tools/virsh-completer.c | 611 +++++++++++++++++++---------------------
tools/virsh-completer.h | 4 +
tools/virsh-domain.c | 15 +-
3 files changed, 295 insertions(+), 335 deletions(-)
--
2.20.1
5 years, 7 months
[libvirt] [PATCH 0/7] qemu: Improve JSON handling in monitor interactions
by Peter Krempa
Remove a few unnecessary copies of the JSON string as well as duplicate
and unneeded debug logs.
Peter Krempa (7):
util: buffer: Remove struct member munging
util: buffer: Use 'size_t' for buffer size variables
util: json: Use virBuffer in JSON->string conversion
util: json: Don't bother logging output string in virJSONValueToString
util: json: Export virJSONValueToBuffer
qemu: monitor: Remove few debug statements
qemu: monitor: Avoid unnecessary copies of command string
src/libvirt_private.syms | 1 +
src/qemu/qemu_monitor_json.c | 19 ++++++++-----------
src/util/virbuffer.c | 14 +-------------
src/util/virbuffer.h | 18 +++++++-----------
src/util/virjson.c | 33 ++++++++++++++++++++++++---------
src/util/virjson.h | 5 +++++
tests/virbuftest.c | 4 +++-
7 files changed, 49 insertions(+), 45 deletions(-)
--
2.20.1
5 years, 7 months
[libvirt] [PATCH v6 00/33] BaselineHypervisorCPU using QEMU QMP exchanges
by Chris Venteicher
Some architectures (S390) depend on QEMU to compute baseline CPU model and
expand a models feature set.
Interacting with QEMU requires starting the QEMU process and completing one or
more query-cpu-model-baseline QMP exchanges with QEMU in addition to a
query-cpu-model-expansion QMP exchange to expand all features in the model.
See "s390x CPU models: exposing features" patch set on Qemu-devel for discussion
of QEMU aspects.
This is part of resolution of: https://bugzilla.redhat.com/show_bug.cgi?id=1511999
-----
v6 addresses these issues from v5:
qemu_process: Move process code from qemu_capabilities to qemu_process
[x] Remove exception statement from commit message
qemu_process: Use qemuProcessQmp prefix
[x] s/ProcessQmp/ProcessQMP/ in this and all subsequent patches
qemu_process: Refer to proc not cmd in process code
[x] Back port indentation fix in qemuProcessQMPRun
qemu_capabilities: Stop QEMU process before freeing
[x] Back port !proc check in qemuProcessQmpStop
qemu_process: Use qemuProcessQmp struct for a single process
[x] Remove extra empty lines
qemu_process: All ProcessQMP errors are fatal
[x] Split into multiple patches
qemu_process: Introduce qemuProcessQmpStart
[x] Log function parameters separately in the first function debug message
[x] Removed NULLSTR check on proc-binary (would fail previously on proc activate)
[x] Back port referring to stderr rather than qmperr in comment
[ ] Combine qemuProcessQmpStop and qemuProcessQmpFree (See reply to v5 email)
emu_process: Collect monitor code in single function
[x] Back port qemuMonitorOpen indent fix to earlier patch
qemu_process: Don't open monitor if process failed
[x] Drop patch
qemu_process: Cleanup qemuProcessQmp alloc function
[x] s/Qemu/QEMU/ in comments for qemuProcessQMPNew
[x] Remove unneeded use of NULLSTR and NULL check before calling qemuProcessQmpFree
qemu_process: Cleanup qemuProcessQmpStop function
[x] Remove lines from from commit message
[x] Remove capitalization from comment
[x] Fix func def to match coding style
[x] Back port !proc check to earlier patch
qemu_process: Catch process free before process stop
[x] Remove capitalization from comment
[x] Don't do proc NULL check in VIR_DEBUG
[ ] Combine qemuProcessQmpStop and qemuProcessQmpFree (See reply to v5 email)
qemu_monitor: Make monitor callbacks optional
[x] Drop patch
qemu_process: Enter QMP command mode when starting QEMU Process
[ ] Don't call qemuMonitorSetCapabilities in qemuProcessQMPConnectMonitor (See reply to v5 email)
qemu_process: Use unique directories for QMP processes
[x] s/qemu./qmp-/ for QMP process directory name prefix
[x] Catch mkdtemp returns NULL
qemu_process: Stop locking QMP process monitor immediately
[x] Drop patch
qemu_monitor: Introduce qemuMonitorCPUModelInfoNew
[x] Use qemuMonitorCPUModelInfoNew to set model name
[x] Drop variable initialization
[x] Use qemuMonitorCPUModelInfoNew in qemuMonitorJSONGetCPUModelExpansion (Pull forward)
[ ] Remove orig NULL check (Unit tests fail if I do this)
qemu_monitor: Introduce qemuMonitorCPUModelInfo / JSON conversion
[x] Make variable initialization easier to read in PropAdd
[x] Require at least one "prop" (don't allow zero in this commit)
qemu_capabilities: Introduce virQEMuCapsMigratablePropsDiff
[x] Remove template txt in commit message
[x] Change function name
[x] Distinguish nmProp from mProp
[x] Don't set cpuData->info to NULL
[ ] Don't use tmp (defer to next patch set... out of time)
qemu_monitor: qemuMonitorGetCPUModelExpansion inputs and outputs CPUModelInfo
[x] Remove extra line from commit message
[x] Change parameter order
[x] Don't use VIR_STEAL_PTR
qemu_capabilities: Introduce CPUModelInfo to virCPUDef function
[x] Change comment
[x] Change parameter order
[x] Separate lines
[x] Move debug message before alloc
[x] Back port function spacing fix from next patch
qemu_capabilities: Introduce virCPUDef to CPUModelInfo function
[x] Change comment
[x] Move debug message before alloc
[x] Remove NULL check on feature->name
[x] Document prop value semantics
Reviewed in v5 but no changes required:
qemu_process: Limit qemuProcessQmpNew to const input strings
qemu_process: Use consistent name for stop process function
qemu_process: Persist stderr in qemuProcessQmp struct
qemu_process: Store libDir in qemuProcessQmp struct
qemu_process: Setup paths within qemuProcessQmpInit
qemu_process: Stop retaining Monitor config in qemuProcessQmp
Not reviewed in v5:
qemu_monitor: Support query-cpu-model-baseline QMP command
qemu_driver: Consolidate code to baseline using libvirt
qemu_driver: Decouple code for baseline using libvirt
qemu_driver: Identify using libvirt as a distinct way to compute baseline
qemu_driver: Support baseline calculation using QEMU
qemu_driver: Support feature expansion via QEMU when baselining cpu
qemu_driver: Remove unsupported props in expanded hypervisor baseline output
qemu_monitor: Default props to migratable when expanding cpu model
-----
v5:
Fixes all process issues identified here:
https://www.redhat.com/archives/libvir-list/2018-November/msg00349.html
- Make the process code generic (not capabilities specific) for use by
BaselineHypervisorCPU
- Many of the process patches are simple code moves with implementation
changes in other distinct patches
- A thread safe library function creates a unique directory under libDir for each QEMU
process (for QMP messaging) to decouple processes in terms of sockets and
file system footprint.
The remaining (non-process) patches in v4 address all issues in v1-v4 of
'BaselineHypervisorCPU using QEMU QMP exchanges'
Thanks,
Chris
*** BLURB HERE ***
Chris Venteicher (33):
qEmu_process: Move process code from qemu_capabilities to qemu_process
qemu_process: Use qemuProcessQMP prefix
qemu_process: Limit qemuProcessQMPNew to const input strings
qemu_process: Refer to proc not cmd in process code
qemu_process: Use consistent name for stop process function
qemu_capabilities: Stop QEMU process before freeing
qemu_process: Use qemuProcessQMP struct for a single process
qemu_process: All ProcessQMP errors are fatal
qemu_process: Expose process exit status code
qemu_process: Persist stderr in qemuProcessQMP struct
qemu_process: Introduce qemuProcessQMPStart
qemu_process: Collect monitor code in single function
qemu_process: Store libDir in qemuProcessQMP struct
qemu_process: Setup paths within qemuProcessQMPInit
qemu_process: Stop retaining Monitor config in qemuProcessQMP
qemu_process: Cleanup qemuProcessQMP alloc function
qemu_process: Cleanup qemuProcessQMPStop function
qemu_process: Catch process free before process stop
qemu_process: Enter QMP command mode when starting QEMU Process
qemu_process: Use unique directories for QMP processes
qemu_monitor: Introduce qemuMonitorCPUModelInfoNew
qemu_monitor: Introduce qemuMonitorCPUModelInfo / JSON conversion
qemu_capabilities: Introduce virQEMuCapsMigratablePropsCalc
qemu_monitor: qemuMonitorGetCPUModelExpansion inputs and outputs
CPUModelInfo
qemu_capabilities: Introduce CPUModelInfo to virCPUDef function
qemu_capabilities: Introduce virCPUDef to CPUModelInfo function
qemu_monitor: Support query-cpu-model-baseline QMP command
qemu_driver: Consolidate code to baseline using libvirt
qemu_driver: Decouple code for baseline using libvirt
qemu_driver: Identify using libvirt as a distinct way to compute
baseline
qemu_driver: Support baseline calculation using QEMU
qemu_driver: Support feature expansion via QEMU when baselining cpu
qemu_monitor: Default props to migratable when expanding cpu model
src/qemu/qemu_capabilities.c | 631 ++++++++----------
src/qemu/qemu_capabilities.h | 4 +
src/qemu/qemu_driver.c | 216 +++++-
src/qemu/qemu_monitor.c | 165 ++++-
src/qemu/qemu_monitor.h | 29 +-
src/qemu/qemu_monitor_json.c | 223 +++++--
src/qemu/qemu_monitor_json.h | 10 +-
src/qemu/qemu_process.c | 345 ++++++++++
src/qemu/qemu_process.h | 32 +
tests/cputest.c | 11 +-
.../caps_2.10.0.s390x.xml | 60 +-
.../caps_2.11.0.s390x.xml | 58 +-
.../caps_2.12.0.s390x.xml | 56 +-
.../qemucapabilitiesdata/caps_2.8.0.s390x.xml | 32 +-
.../qemucapabilitiesdata/caps_2.9.0.s390x.xml | 34 +-
.../qemucapabilitiesdata/caps_3.0.0.s390x.xml | 64 +-
tests/qemucapabilitiestest.c | 7 +
17 files changed, 1375 insertions(+), 602 deletions(-)
--
2.17.1
5 years, 7 months
[libvirt] [PATCH 0/5] qemu: caps: Always assume most of block job capabilities
by Peter Krempa
Peter Krempa (5):
qemu: capabilities: Always assume QEMU_CAPS_BLOCKJOB_ASYNC
qemu: domain: drop qemuDomainSupportsBlockJobs
qemu: capabilities: Always assume QEMU_CAPS_BLOCK_COMMIT
qemu: capabilities: Always assume QEMU_CAPS_DRIVE_MIRROR
qemu: capabilities: Always assume disk snapshot caps
src/qemu/qemu_capabilities.c | 13 +----
src/qemu/qemu_capabilities.h | 10 ++--
src/qemu/qemu_domain.c | 23 --------
src/qemu/qemu_domain.h | 2 -
src/qemu/qemu_driver.c | 34 ------------
src/qemu/qemu_migration.c | 53 ++++++++-----------
.../caps_1.5.3.x86_64.xml | 5 --
.../caps_1.6.0.x86_64.xml | 5 --
.../caps_1.7.0.x86_64.xml | 5 --
.../caps_2.1.1.x86_64.xml | 5 --
.../caps_2.10.0.aarch64.xml | 5 --
.../caps_2.10.0.ppc64.xml | 5 --
.../caps_2.10.0.s390x.xml | 5 --
.../caps_2.10.0.x86_64.xml | 5 --
.../caps_2.11.0.s390x.xml | 5 --
.../caps_2.11.0.x86_64.xml | 5 --
.../caps_2.12.0.aarch64.xml | 5 --
.../caps_2.12.0.ppc64.xml | 5 --
.../caps_2.12.0.s390x.xml | 5 --
.../caps_2.12.0.x86_64.xml | 5 --
.../caps_2.4.0.x86_64.xml | 5 --
.../caps_2.5.0.x86_64.xml | 5 --
.../caps_2.6.0.aarch64.xml | 5 --
.../qemucapabilitiesdata/caps_2.6.0.ppc64.xml | 5 --
.../caps_2.6.0.x86_64.xml | 5 --
.../qemucapabilitiesdata/caps_2.7.0.s390x.xml | 5 --
.../caps_2.7.0.x86_64.xml | 5 --
.../qemucapabilitiesdata/caps_2.8.0.s390x.xml | 5 --
.../caps_2.8.0.x86_64.xml | 5 --
.../qemucapabilitiesdata/caps_2.9.0.ppc64.xml | 5 --
.../qemucapabilitiesdata/caps_2.9.0.s390x.xml | 5 --
.../caps_2.9.0.x86_64.xml | 5 --
.../qemucapabilitiesdata/caps_3.0.0.ppc64.xml | 5 --
.../caps_3.0.0.riscv32.xml | 5 --
.../caps_3.0.0.riscv64.xml | 5 --
.../qemucapabilitiesdata/caps_3.0.0.s390x.xml | 5 --
.../caps_3.0.0.x86_64.xml | 5 --
.../qemucapabilitiesdata/caps_3.1.0.ppc64.xml | 5 --
.../caps_3.1.0.x86_64.xml | 5 --
.../caps_4.0.0.riscv32.xml | 5 --
.../caps_4.0.0.riscv64.xml | 5 --
.../caps_4.0.0.x86_64.xml | 5 --
42 files changed, 27 insertions(+), 288 deletions(-)
--
2.20.1
5 years, 7 months
[libvirt] [PATCH 0/4] Fix various test portability problems
by Daniel P. Berrangé
This includes a slight tweak to the stat/lstat patch wrt logging and
fixes use of the dirent d_type field.
Daniel P. Berrangé (4):
tests: fix mocking of stat() / lstat() functions
qemu: don't rely on the non-portable d_type field in dirent
security: avoid use of dirent d_type field
cfg.mk: block use of d_type from dirent by default
build-aux/mock-noinline.pl | 3 +
cfg.mk | 20 +-
src/qemu/qemu_firmware.c | 12 +-
src/security/security_selinux.c | 6 +-
tests/Makefile.am | 1 +
tests/qemusecuritymock.c | 131 ++++---------
tests/vircgroupmock.c | 146 ++------------
tests/virfilewrapper.c | 85 ++-------
tests/virmock.h | 11 --
tests/virmockstathelpers.c | 326 ++++++++++++++++++++++++++++++++
tests/virpcimock.c | 93 +--------
tests/virtestmock.c | 140 +-------------
12 files changed, 440 insertions(+), 534 deletions(-)
create mode 100644 tests/virmockstathelpers.c
--
2.20.1
5 years, 7 months
[libvirt] [PATCH 00/10] Improve handling of secrets in memory
by Peter Krempa
Peter Krempa (10):
qemu: conf: Clear spice/vnc passwords from memory when freeing conf
object
util: alloc: Add automatic cleanup/disposal of strings
Use VIR_AUTODISPOSE_STR instead of VIR_DISPOSE_STRING where possible
util: buffer: Remove struct member munging
util: alloc: Clean also stack'd data with VIR_AUTOCLEAN
util: alloc: Introduce VIR_TMP
qemu: Use VIR_TMP to stop leaking pointer to VNC password pointer to
stack
util: Introduce 'virpin' module for dealing with PIN numbers
util: json: Make sure that Jano's pin is not leaked to the heap
util: json: Nuke strings when freeing JSON objects
cfg.mk | 2 +-
src/Makefile.am | 3 +
src/libvirt_private.syms | 6 +
src/libxl/libxl_conf.c | 3 +-
src/qemu/qemu_command.c | 3 +-
src/qemu/qemu_conf.c | 4 +-
src/qemu/qemu_hotplug.c | 2 +-
src/rpc/virnetlibsshsession.c | 10 +-
src/storage/storage_backend_rbd.c | 3 +-
src/util/Makefile.inc.am | 2 +
src/util/viralloc.c | 23 +
src/util/viralloc.h | 32 +-
src/util/virbuffer.c | 12 -
src/util/virbuffer.h | 16 +-
src/util/virjson.c | 8 +-
src/util/virpin.c | 1053 +++++++++++++++++++++++++++++
src/util/virpin.h | 30 +
tests/utiltest.c | 30 +
tests/virbuftest.c | 2 +-
tools/virsh-secret.c | 3 +-
20 files changed, 1200 insertions(+), 47 deletions(-)
create mode 100644 src/util/virpin.c
create mode 100644 src/util/virpin.h
--
2.20.1
5 years, 7 months
[libvirt] [PATCH 0/5] qemu: Fix memfd with default hugetlbfs mount
by Michal Privoznik
Michal Prívozník (5):
qemuxml2argvdata: Drop useless spaces at the beginning of lines
qemuxml2xmltest: Move virObjectUnref() call
qemuxml2xmltest: Add memfd tests
virfile: Introduce and use virFileGetDefaultHugepage
qemuBuildMemoryBackendProps: Get pagesize early
src/libvirt_private.syms | 1 +
src/qemu/qemu_command.c | 14 ++++
src/qemu/qemu_conf.c | 12 +--
src/util/virfile.c | 25 ++++++
src/util/virfile.h | 3 +
.../fd-memory-no-numa-topology.xml | 14 +++-
.../fd-memory-numa-topology.xml | 12 ++-
.../fd-memory-numa-topology2.xml | 70 +++++++++-------
.../fd-memory-numa-topology3.xml | 72 +++++++++--------
...memory-default-hugepage.x86_64-latest.args | 37 +++++++++
.../memfd-memory-default-hugepage.xml | 42 ++++++++++
.../memfd-memory-numa.x86_64-latest.args | 2 +-
tests/qemuxml2argvdata/memfd-memory-numa.xml | 80 ++++++++++---------
tests/qemuxml2argvtest.c | 1 +
.../fd-memory-no-numa-topology.xml | 1 +
.../fd-memory-numa-topology.xml | 1 +
.../fd-memory-numa-topology2.xml | 1 +
.../fd-memory-numa-topology3.xml | 1 +
.../memfd-memory-default-hugepage.xml | 1 +
.../qemuxml2xmloutdata/memfd-memory-numa.xml | 1 +
tests/qemuxml2xmltest.c | 18 ++++-
21 files changed, 295 insertions(+), 114 deletions(-)
create mode 100644 tests/qemuxml2argvdata/memfd-memory-default-hugepage.x86_64-latest.args
create mode 100644 tests/qemuxml2argvdata/memfd-memory-default-hugepage.xml
create mode 120000 tests/qemuxml2xmloutdata/fd-memory-no-numa-topology.xml
create mode 120000 tests/qemuxml2xmloutdata/fd-memory-numa-topology.xml
create mode 120000 tests/qemuxml2xmloutdata/fd-memory-numa-topology2.xml
create mode 120000 tests/qemuxml2xmloutdata/fd-memory-numa-topology3.xml
create mode 120000 tests/qemuxml2xmloutdata/memfd-memory-default-hugepage.xml
create mode 120000 tests/qemuxml2xmloutdata/memfd-memory-numa.xml
--
2.21.0
5 years, 7 months
[libvirt] [PATCH 0/3] maint: Drop ChangeLog*
by Andrea Bolognani
Rationale in the respective commit messages.
Patch 2/3 has been snipped quite extensively so that it would
make it to the mailing list: the unabridged version of this
series can be fetched from
https://github.com/andreabolognani/libvirt/tree/changelog
Andrea Bolognani (3):
maint: Stop generating ChangeLog from git
maint: Drop ChangeLog-old
maint: Update references to ChangeLog*
.gitignore | 1 -
ChangeLog | 15 +
ChangeLog-old | 16699 ------------------------------------------
Makefile.am | 15 +-
bootstrap.conf | 4 +-
cfg.mk | 2 +-
docs/news-ascii.xsl | 3 +-
7 files changed, 21 insertions(+), 16718 deletions(-)
create mode 100644 ChangeLog
delete mode 100644 ChangeLog-old
--
2.20.1
5 years, 7 months
[libvirt] [PATCH] virDirRead: Fix d_type if needed
by Michal Privoznik
Some of our code iterates over a directory and does some
decisions based on entry type (e.g. if it's not a regular file
continue with next iteration). This is done by looking at
ent->d_type struct member. However, in some cases (e.g. for some
filesystems) the d_type can be set to DT_UNKNOWN which
effectively defeats the aforementioned checks. For instance, some
XFS' (depending on how they were created) might not bother
filling the member.
Fix this by running stat() and filling in the member ourselves.
If needed.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
With Dan's patch that fixes stat() mocking, I'm passing tests
successfully everywhere I tried (32bit fedora and gentoo on RPi, RHEL-7,
amd64 gentoo, fedora rawhide on x86_64)
src/util/virfile.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/src/util/virfile.c b/src/util/virfile.c
index ec8d85929c..7d7c27a7d2 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -2893,6 +2893,39 @@ virDirOpenQuiet(DIR **dirp, const char *name)
return virDirOpenInternal(dirp, name, false, true);
}
+static int
+virDirReadFixDType(DIR *dirp, struct dirent *ent)
+{
+ /* DO NOT CLOSE THIS FD */
+ const int fd = dirfd(dirp);
+ struct stat sb;
+
+ if (fd < 0)
+ return -1;
+
+ if (fstatat(fd, ent->d_name, &sb, AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW) < 0)
+ return -1;
+
+ if (S_ISDIR(sb.st_mode))
+ ent->d_type = DT_DIR;
+ else if (S_ISCHR(sb.st_mode))
+ ent->d_type = DT_CHR;
+ else if (S_ISBLK(sb.st_mode))
+ ent->d_type = DT_BLK;
+ else if (S_ISREG(sb.st_mode))
+ ent->d_type = DT_REG;
+ else if (S_ISFIFO(sb.st_mode))
+ ent->d_type = DT_FIFO;
+ else if (S_ISLNK(sb.st_mode))
+ ent->d_type = DT_LNK;
+ else if (S_ISSOCK(sb.st_mode))
+ ent->d_type = DT_SOCK;
+ else
+ return -1;
+
+ return 0;
+}
+
/**
* virDirRead:
* @dirp: directory to read
@@ -2926,6 +2959,17 @@ int virDirRead(DIR *dirp, struct dirent **ent, const char *name)
}
} while (*ent && (STREQ((*ent)->d_name, ".") ||
STREQ((*ent)->d_name, "..")));
+
+ if (*ent &&
+ (*ent)->d_type == DT_UNKNOWN &&
+ virDirReadFixDType(dirp, *ent) < 0) {
+ if (name)
+ virReportSystemError(errno,
+ _("Unable to fix d_type of '%s/%s'"),
+ name, (*ent)->d_name);
+ return -1;
+ }
+
return !!*ent;
}
--
2.21.0
5 years, 7 months