Skip to content

util: Introduce qemu_get_runtime_dir()

Akihiko Odaki kvm qemu-devel 5 versions – New

Get series with b4
b4 am [email protected] change-id 20240218-run-6f0d91ec7439

Versions newest first

  1. v5 Latest8 patches 0 repliesNew
  2. v47 patches 14 repliesApplied inferred link
  3. v38 patches 1 replySuperseded inferred link
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v210 patches5 repliesSuperseded inferred link
v110 patches1 replySuperseded

Changes in v5 from the cover letter

- Expanded the patch message.
- Link to v4: https://lore.kernel.org/r/[email protected]

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8util: Introduce qemu_get_runtime_dir()include/qemu/osdep.h util/oslib-posix.c util/oslib-win32.c+51 -00 replies
2/8ivshmem-server: Use qemu_get_runtime_dir()contrib/ivshmem-server/main.c+16 -40 replies
3/8qga: Use qemu_get_runtime_dir()docs/conf.py docs/interop/qemu-ga.rst docs/meson.build +1 more+14 -70 replies
4/8scsi: Use qemu_get_runtime_dir()docs/tools/qemu-pr-helper.rst scsi/qemu-pr-helper.c+7 -70 replies
5/8i386/vmsr: Stop using qemu_get_local_state_dir()target/i386/kvm/vmsr_energy.c tools/i386/qemu-vmsr-helper.c+6 -60 replies
6/8module: Use qemu_get_runtime_dir()include/qemu/module.h util/module.c+3 -20 replies
7/8util: Remove qemu_get_local_state_dir()include/qemu/osdep.h util/oslib-posix.c util/oslib-win32.c+0 -240 replies
8/8spice-app: Use qemu_get_runtime_dir()ui/spice-app.c+2 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v5 yet.

Read the v5 thread

Cover letter [PATCH v5 0/8] util: Introduce qemu_get_runtime_dir()

qemu_get_runtime_dir() returns a dynamically allocated directory path that is appropriate for storing runtime files. It corresponds to "run" directory in Unix.

With a tree-wide search, it was found that there are several cases where such a functionality is implemented so let's have one as a common utlity function.

A notable feature of qemu_get_runtime_dir() is that it uses $XDG_RUNTIME_DIR if available. While the function is often called by executables which requires root privileges, it is still possible that they are called from a user without privilege to write the system runtime directory. In fact, I decided to write this patch when I ran virtiofsd in a Linux namespace created by a normal user and realized it tries to write the system runtime directory, not writable in this case. $XDG_RUNTIME_DIR should provide a writable directory in such cases.

This function does not use qemu_get_local_state_dir() or its logic for Windows. Actually the implementation of qemu_get_local_state_dir() for Windows seems not right as it calls g_get_system_data_dirs(), which refers to $XDG_DATA_DIRS. In Unix terminology, it is basically "/usr/share", not "/var", which qemu_get_local_state_dir() is intended to provide. Instead, this function try to use the following in order:
- $XDG_RUNTIME_DIR
- LocalAppData folder
- get_relocated_path(CONFIG_QEMU_LOCALSTATEDIR "/run")

This function does not use g_get_user_runtime_dir() either as it falls back to g_get_user_cache_dir() when $XDG_DATA_DIRS is not available. In the case, we rather use:
get_relocated_path(CONFIG_QEMU_LOCALSTATEDIR "/run")

All current callers pass the returned path to g_build_filename(), but this series does not add a helper to combine those operations. Such a helper would be complicated due to variadic arguments, and keeping that out of scope keeps this series focused.

V2 -> V3:
Rebase to the current master.
Dropped patch "qga: Remove platform GUID definitions" since it is irrelevant.

V1 -> V2:
Rebased to the current master since Patchew complains.

---
Changes in v5:
- Expanded the patch message.
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Rebased.
- Link to v3: https://lore.kernel.org/r/[email protected]

---
Akihiko Odaki (8):
util: Introduce qemu_get_runtime_dir()
ivshmem-server: Use qemu_get_runtime_dir()
qga: Use qemu_get_runtime_dir()
scsi: Use qemu_get_runtime_dir() i386/vmsr: Stop using qemu_get_local_state_dir()
module: Use qemu_get_runtime_dir()
util: Remove qemu_get_local_state_dir()
spice-app: Use qemu_get_runtime_dir()

 docs/conf.py                  |  2 ++
 docs/interop/qemu-ga.rst      |  5 +++--
 docs/meson.build              |  6 +++++-
 docs/tools/qemu-pr-helper.rst |  8 ++++----
 include/qemu/module.h         |  2 +-
 include/qemu/osdep.h          | 10 +++++++---
 contrib/ivshmem-server/main.c | 20 ++++++++++++++++----
 qga/main.c                    |  8 ++++----
 scsi/qemu-pr-helper.c         |  6 +++---
 target/i386/kvm/vmsr_energy.c |  6 +++---
 tools/i386/qemu-vmsr-helper.c |  6 +++---
 ui/spice-app.c                |  4 ++--
 util/module.c                 |  3 ++-
 util/oslib-posix.c            |  9 +++++++--
 util/oslib-win32.c            | 26 ++++++++++++++++++++++----
 15 files changed, 84 insertions(+), 37 deletions(-)

---
base-commit: b83371668192a705b878e909c5ae9c1233cbd5fb
change-id: 20240218-run-6f0d91ec7439

Best regards,

Signature · 1 line
Akihiko Odaki <[email protected]>