* [PATCH v2 01/10] qga: Remove platform GUID definitions
2022-11-10 10:06 [PATCH v2 00/10] util: Introduce qemu_get_runtime_dir() Akihiko Odaki
@ 2022-11-10 10:06 ` Akihiko Odaki
2022-11-17 9:45 ` Konstantin Kostiuk
2022-11-10 10:06 ` [PATCH v2 02/10] util: Introduce qemu_get_runtime_dir() Akihiko Odaki
` (8 subsequent siblings)
9 siblings, 1 reply; 16+ messages in thread
From: Akihiko Odaki @ 2022-11-10 10:06 UTC (permalink / raw)
Cc: qemu-devel, qemu-block, virtio-fs, Yuval Shaia, Marcel Apfelbaum,
Konstantin Kostiuk, Michael Roth, Paolo Bonzini, Fam Zheng,
Dr. David Alan Gilbert, Stefan Hajnoczi, Gerd Hoffmann,
Stefan Weil, Yan Vugenfirer, Akihiko Odaki
GUID_DEVINTERFACE_DISK and GUID_DEVINTERFACE_STORAGEPORT are already
defined by MinGW-w64. They are not only unnecessary, but can lead to
duplicate definition errors at link time with some unknown condition.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
qga/commands-win32.c | 7 -------
1 file changed, 7 deletions(-)
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index ec9f55b453..dde5d401bb 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -506,13 +506,6 @@ static GuestDiskBusType find_bus_type(STORAGE_BUS_TYPE bus)
return win2qemu[(int)bus];
}
-DEFINE_GUID(GUID_DEVINTERFACE_DISK,
- 0x53f56307L, 0xb6bf, 0x11d0, 0x94, 0xf2,
- 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
-DEFINE_GUID(GUID_DEVINTERFACE_STORAGEPORT,
- 0x2accfe60L, 0xc130, 0x11d2, 0xb0, 0x82,
- 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
-
static void get_pci_address_for_device(GuestPCIAddress *pci,
HDEVINFO dev_info)
{
--
2.38.1
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH v2 01/10] qga: Remove platform GUID definitions
2022-11-10 10:06 ` [PATCH v2 01/10] qga: Remove platform GUID definitions Akihiko Odaki
@ 2022-11-17 9:45 ` Konstantin Kostiuk
2023-09-21 7:58 ` Akihiko Odaki
0 siblings, 1 reply; 16+ messages in thread
From: Konstantin Kostiuk @ 2022-11-17 9:45 UTC (permalink / raw)
To: Akihiko Odaki
Cc: qemu-devel, qemu-block, virtio-fs, Yuval Shaia, Marcel Apfelbaum,
Michael Roth, Paolo Bonzini, Fam Zheng, Dr. David Alan Gilbert,
Stefan Hajnoczi, Gerd Hoffmann, Stefan Weil, Yan Vugenfirer
[-- Attachment #1: Type: text/plain, Size: 1244 bytes --]
Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>
Will merge this patch in QGA series
On Thu, Nov 10, 2022 at 12:06 PM Akihiko Odaki <akihiko.odaki@daynix.com>
wrote:
> GUID_DEVINTERFACE_DISK and GUID_DEVINTERFACE_STORAGEPORT are already
> defined by MinGW-w64. They are not only unnecessary, but can lead to
> duplicate definition errors at link time with some unknown condition.
>
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> ---
> qga/commands-win32.c | 7 -------
> 1 file changed, 7 deletions(-)
>
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index ec9f55b453..dde5d401bb 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -506,13 +506,6 @@ static GuestDiskBusType
> find_bus_type(STORAGE_BUS_TYPE bus)
> return win2qemu[(int)bus];
> }
>
> -DEFINE_GUID(GUID_DEVINTERFACE_DISK,
> - 0x53f56307L, 0xb6bf, 0x11d0, 0x94, 0xf2,
> - 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
> -DEFINE_GUID(GUID_DEVINTERFACE_STORAGEPORT,
> - 0x2accfe60L, 0xc130, 0x11d2, 0xb0, 0x82,
> - 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
> -
> static void get_pci_address_for_device(GuestPCIAddress *pci,
> HDEVINFO dev_info)
> {
> --
> 2.38.1
>
>
[-- Attachment #2: Type: text/html, Size: 1834 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH v2 01/10] qga: Remove platform GUID definitions
2022-11-17 9:45 ` Konstantin Kostiuk
@ 2023-09-21 7:58 ` Akihiko Odaki
2023-09-21 9:52 ` Konstantin Kostiuk
0 siblings, 1 reply; 16+ messages in thread
From: Akihiko Odaki @ 2023-09-21 7:58 UTC (permalink / raw)
To: Konstantin Kostiuk
Cc: qemu-devel, qemu-block, virtio-fs, Yuval Shaia, Marcel Apfelbaum,
Michael Roth, Paolo Bonzini, Fam Zheng, Dr. David Alan Gilbert,
Stefan Hajnoczi, Gerd Hoffmann, Stefan Weil, Yan Vugenfirer
On 2022/11/17 18:45, Konstantin Kostiuk wrote:
> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com
> <mailto:kkostiuk@redhat.com>>
>
> Will merge this patch in QGA series
>
> On Thu, Nov 10, 2022 at 12:06 PM Akihiko Odaki <akihiko.odaki@daynix.com
> <mailto:akihiko.odaki@daynix.com>> wrote:
>
> GUID_DEVINTERFACE_DISK and GUID_DEVINTERFACE_STORAGEPORT are already
> defined by MinGW-w64. They are not only unnecessary, but can lead to
> duplicate definition errors at link time with some unknown condition.
>
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com
> <mailto:akihiko.odaki@daynix.com>>
> ---
> qga/commands-win32.c | 7 -------
> 1 file changed, 7 deletions(-)
>
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index ec9f55b453..dde5d401bb 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -506,13 +506,6 @@ static GuestDiskBusType
> find_bus_type(STORAGE_BUS_TYPE bus)
> return win2qemu[(int)bus];
> }
>
> -DEFINE_GUID(GUID_DEVINTERFACE_DISK,
> - 0x53f56307L, 0xb6bf, 0x11d0, 0x94, 0xf2,
> - 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
> -DEFINE_GUID(GUID_DEVINTERFACE_STORAGEPORT,
> - 0x2accfe60L, 0xc130, 0x11d2, 0xb0, 0x82,
> - 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
> -
> static void get_pci_address_for_device(GuestPCIAddress *pci,
> HDEVINFO dev_info)
> {
> --
> 2.38.1
>
Hi Konstantin,
This patch seems missed since then. Can you merge it?
Regards,
Akihiko Odaki
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH v2 01/10] qga: Remove platform GUID definitions
2023-09-21 7:58 ` Akihiko Odaki
@ 2023-09-21 9:52 ` Konstantin Kostiuk
0 siblings, 0 replies; 16+ messages in thread
From: Konstantin Kostiuk @ 2023-09-21 9:52 UTC (permalink / raw)
To: Akihiko Odaki
Cc: qemu-devel, qemu-block, virtio-fs, Yuval Shaia, Marcel Apfelbaum,
Michael Roth, Paolo Bonzini, Fam Zheng, Dr. David Alan Gilbert,
Stefan Hajnoczi, Gerd Hoffmann, Stefan Weil, Yan Vugenfirer
[-- Attachment #1: Type: text/plain, Size: 1972 bytes --]
Hi Akihiko,
Thanks for ping.
I will merge this commit with other qga fixes.
Best Regards,
Konstantin Kostiuk.
On Thu, Sep 21, 2023 at 10:58 AM Akihiko Odaki <akihiko.odaki@daynix.com>
wrote:
> On 2022/11/17 18:45, Konstantin Kostiuk wrote:
> > Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com
> > <mailto:kkostiuk@redhat.com>>
> >
> > Will merge this patch in QGA series
> >
> > On Thu, Nov 10, 2022 at 12:06 PM Akihiko Odaki <akihiko.odaki@daynix.com
> > <mailto:akihiko.odaki@daynix.com>> wrote:
> >
> > GUID_DEVINTERFACE_DISK and GUID_DEVINTERFACE_STORAGEPORT are already
> > defined by MinGW-w64. They are not only unnecessary, but can lead to
> > duplicate definition errors at link time with some unknown condition.
> >
> > Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com
> > <mailto:akihiko.odaki@daynix.com>>
> > ---
> > qga/commands-win32.c | 7 -------
> > 1 file changed, 7 deletions(-)
> >
> > diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> > index ec9f55b453..dde5d401bb 100644
> > --- a/qga/commands-win32.c
> > +++ b/qga/commands-win32.c
> > @@ -506,13 +506,6 @@ static GuestDiskBusType
> > find_bus_type(STORAGE_BUS_TYPE bus)
> > return win2qemu[(int)bus];
> > }
> >
> > -DEFINE_GUID(GUID_DEVINTERFACE_DISK,
> > - 0x53f56307L, 0xb6bf, 0x11d0, 0x94, 0xf2,
> > - 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
> > -DEFINE_GUID(GUID_DEVINTERFACE_STORAGEPORT,
> > - 0x2accfe60L, 0xc130, 0x11d2, 0xb0, 0x82,
> > - 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
> > -
> > static void get_pci_address_for_device(GuestPCIAddress *pci,
> > HDEVINFO dev_info)
> > {
> > --
> > 2.38.1
> >
>
> Hi Konstantin,
>
> This patch seems missed since then. Can you merge it?
>
> Regards,
> Akihiko Odaki
>
>
[-- Attachment #2: Type: text/html, Size: 3222 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 02/10] util: Introduce qemu_get_runtime_dir()
2022-11-10 10:06 [PATCH v2 00/10] util: Introduce qemu_get_runtime_dir() Akihiko Odaki
2022-11-10 10:06 ` [PATCH v2 01/10] qga: Remove platform GUID definitions Akihiko Odaki
@ 2022-11-10 10:06 ` Akihiko Odaki
2022-11-10 10:06 ` [PATCH v2 03/10] ivshmem-server: Use qemu_get_runtime_dir() Akihiko Odaki
` (7 subsequent siblings)
9 siblings, 0 replies; 16+ messages in thread
From: Akihiko Odaki @ 2022-11-10 10:06 UTC (permalink / raw)
Cc: qemu-devel, qemu-block, virtio-fs, Yuval Shaia, Marcel Apfelbaum,
Konstantin Kostiuk, Michael Roth, Paolo Bonzini, Fam Zheng,
Dr. David Alan Gilbert, Stefan Hajnoczi, Gerd Hoffmann,
Stefan Weil, Yan Vugenfirer, Akihiko Odaki
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")
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
include/qemu/osdep.h | 12 ++++++++++++
util/oslib-posix.c | 11 +++++++++++
util/oslib-win32.c | 26 ++++++++++++++++++++++++++
3 files changed, 49 insertions(+)
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index b9c4307779..86445aad25 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -565,6 +565,18 @@ void qemu_set_cloexec(int fd);
*/
char *qemu_get_local_state_dir(void);
+/**
+ * qemu_get_runtime_dir:
+ *
+ * Return a dynamically allocated directory path that is appropriate for storing
+ * runtime files. It corresponds to "run" directory in Unix, and uses
+ * $XDG_RUNTIME_DIR if available.
+ *
+ * The caller is responsible for releasing the value returned with g_free()
+ * after use.
+ */
+char *qemu_get_runtime_dir(void);
+
/**
* qemu_getauxval:
* @type: the auxiliary vector key to lookup
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 59a891b6a8..9a0b3913ff 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -279,6 +279,17 @@ qemu_get_local_state_dir(void)
return get_relocated_path(CONFIG_QEMU_LOCALSTATEDIR);
}
+char *
+qemu_get_runtime_dir(void)
+{
+ char *env = getenv("XDG_RUNTIME_DIR");
+ if (env) {
+ return g_strdup(env);
+ }
+
+ return get_relocated_path(CONFIG_QEMU_LOCALSTATEDIR "/run");
+}
+
void qemu_set_tty_echo(int fd, bool echo)
{
struct termios tty;
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index a67cb3822e..6ad1bb4bac 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -31,6 +31,8 @@
*/
#include "qemu/osdep.h"
+#include <shlobj.h>
+#include <wchar.h>
#include <windows.h>
#include "qapi/error.h"
#include "qemu/main-loop.h"
@@ -241,6 +243,30 @@ qemu_get_local_state_dir(void)
return g_strdup(data_dirs[0]);
}
+char *
+qemu_get_runtime_dir(void)
+{
+ size_t size = GetEnvironmentVariableA("XDG_RUNTIME_DIR", NULL, 0);
+ if (size) {
+ char *env = g_malloc(size);
+ GetEnvironmentVariableA("XDG_RUNTIME_DIR", env, size);
+ return env;
+ }
+
+ PWSTR wpath;
+ const wchar_t *cwpath;
+ if (!SHGetKnownFolderPath(&FOLDERID_LocalAppData, KF_FLAG_DEFAULT, NULL, &wpath)) {
+ cwpath = wpath;
+ size = wcsrtombs(NULL, &cwpath, 0, &(mbstate_t){0}) + 1;
+ char *path = g_malloc(size);
+ wcsrtombs(path, &cwpath, size, &(mbstate_t){0});
+ CoTaskMemFree(wpath);
+ return path;
+ }
+
+ return get_relocated_path(CONFIG_QEMU_LOCALSTATEDIR "/run");
+}
+
void qemu_set_tty_echo(int fd, bool echo)
{
HANDLE handle = (HANDLE)_get_osfhandle(fd);
--
2.38.1
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v2 03/10] ivshmem-server: Use qemu_get_runtime_dir()
2022-11-10 10:06 [PATCH v2 00/10] util: Introduce qemu_get_runtime_dir() Akihiko Odaki
2022-11-10 10:06 ` [PATCH v2 01/10] qga: Remove platform GUID definitions Akihiko Odaki
2022-11-10 10:06 ` [PATCH v2 02/10] util: Introduce qemu_get_runtime_dir() Akihiko Odaki
@ 2022-11-10 10:06 ` Akihiko Odaki
2022-11-10 10:06 ` [PATCH v2 04/10] contrib/rdmacm-mux: " Akihiko Odaki
` (6 subsequent siblings)
9 siblings, 0 replies; 16+ messages in thread
From: Akihiko Odaki @ 2022-11-10 10:06 UTC (permalink / raw)
Cc: qemu-devel, qemu-block, virtio-fs, Yuval Shaia, Marcel Apfelbaum,
Konstantin Kostiuk, Michael Roth, Paolo Bonzini, Fam Zheng,
Dr. David Alan Gilbert, Stefan Hajnoczi, Gerd Hoffmann,
Stefan Weil, Yan Vugenfirer, Akihiko Odaki
qemu_get_runtime_dir() is used to construct the default PID file path.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
contrib/ivshmem-server/main.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/contrib/ivshmem-server/main.c b/contrib/ivshmem-server/main.c
index 224dbeb547..16abbe2f5a 100644
--- a/contrib/ivshmem-server/main.c
+++ b/contrib/ivshmem-server/main.c
@@ -14,7 +14,6 @@
#define IVSHMEM_SERVER_DEFAULT_VERBOSE 0
#define IVSHMEM_SERVER_DEFAULT_FOREGROUND 0
-#define IVSHMEM_SERVER_DEFAULT_PID_FILE "/var/run/ivshmem-server.pid"
#define IVSHMEM_SERVER_DEFAULT_UNIX_SOCK_PATH "/tmp/ivshmem_socket"
#define IVSHMEM_SERVER_DEFAULT_SHM_PATH "ivshmem"
#define IVSHMEM_SERVER_DEFAULT_SHM_SIZE (4 * 1024 * 1024)
@@ -35,15 +34,23 @@ typedef struct IvshmemServerArgs {
unsigned n_vectors;
} IvshmemServerArgs;
+static char *ivshmem_server_get_default_pid_file(void)
+{
+ g_autofree char *run = qemu_get_runtime_dir();
+ return g_build_filename(run, "ivshmem-server.pid", NULL);
+}
+
static void
ivshmem_server_usage(const char *progname)
{
+ g_autofree char *pid_file = ivshmem_server_get_default_pid_file();
+
printf("Usage: %s [OPTION]...\n"
" -h: show this help\n"
" -v: verbose mode\n"
" -F: foreground mode (default is to daemonize)\n"
" -p <pid-file>: path to the PID file (used in daemon mode only)\n"
- " default " IVSHMEM_SERVER_DEFAULT_PID_FILE "\n"
+ " default %s\n"
" -S <unix-socket-path>: path to the unix socket to listen to\n"
" default " IVSHMEM_SERVER_DEFAULT_UNIX_SOCK_PATH "\n"
" -M <shm-name>: POSIX shared memory object to use\n"
@@ -54,7 +61,7 @@ ivshmem_server_usage(const char *progname)
" default %u\n"
" -n <nvectors>: number of vectors\n"
" default %u\n",
- progname, IVSHMEM_SERVER_DEFAULT_SHM_SIZE,
+ progname, pid_file, IVSHMEM_SERVER_DEFAULT_SHM_SIZE,
IVSHMEM_SERVER_DEFAULT_N_VECTORS);
}
@@ -189,10 +196,10 @@ main(int argc, char *argv[])
{
IvshmemServer server;
struct sigaction sa, sa_quit;
+ g_autofree char *default_pid_file = NULL;
IvshmemServerArgs args = {
.verbose = IVSHMEM_SERVER_DEFAULT_VERBOSE,
.foreground = IVSHMEM_SERVER_DEFAULT_FOREGROUND,
- .pid_file = IVSHMEM_SERVER_DEFAULT_PID_FILE,
.unix_socket_path = IVSHMEM_SERVER_DEFAULT_UNIX_SOCK_PATH,
.shm_path = IVSHMEM_SERVER_DEFAULT_SHM_PATH,
.use_shm_open = true,
@@ -207,6 +214,11 @@ main(int argc, char *argv[])
*/
printf("*** Example code, do not use in production ***\n");
+ qemu_init_exec_dir(argv[0]);
+
+ default_pid_file = ivshmem_server_get_default_pid_file();
+ args.pid_file = default_pid_file;
+
/* parse arguments, will exit on error */
ivshmem_server_parse_args(&args, argc, argv);
--
2.38.1
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v2 04/10] contrib/rdmacm-mux: Use qemu_get_runtime_dir()
2022-11-10 10:06 [PATCH v2 00/10] util: Introduce qemu_get_runtime_dir() Akihiko Odaki
` (2 preceding siblings ...)
2022-11-10 10:06 ` [PATCH v2 03/10] ivshmem-server: Use qemu_get_runtime_dir() Akihiko Odaki
@ 2022-11-10 10:06 ` Akihiko Odaki
2022-11-10 10:06 ` [PATCH v2 05/10] qga: " Akihiko Odaki
` (5 subsequent siblings)
9 siblings, 0 replies; 16+ messages in thread
From: Akihiko Odaki @ 2022-11-10 10:06 UTC (permalink / raw)
Cc: qemu-devel, qemu-block, virtio-fs, Yuval Shaia, Marcel Apfelbaum,
Konstantin Kostiuk, Michael Roth, Paolo Bonzini, Fam Zheng,
Dr. David Alan Gilbert, Stefan Hajnoczi, Gerd Hoffmann,
Stefan Weil, Yan Vugenfirer, Akihiko Odaki
qemu_get_runtime_dir() is used to construct the default Unix socket
path.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
contrib/rdmacm-mux/main.c | 22 ++++++++++++++--------
contrib/rdmacm-mux/meson.build | 2 +-
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/contrib/rdmacm-mux/main.c b/contrib/rdmacm-mux/main.c
index 771ca01e03..00c14031ca 100644
--- a/contrib/rdmacm-mux/main.c
+++ b/contrib/rdmacm-mux/main.c
@@ -14,6 +14,7 @@
*/
#include "qemu/osdep.h"
+#include "qemu/cutils.h"
#include <sys/poll.h>
#include <sys/ioctl.h>
#include <pthread.h>
@@ -40,8 +41,6 @@
#define CM_REQ_DGID_POS 80
#define CM_SIDR_REQ_DGID_POS 44
-/* The below can be override by command line parameter */
-#define UNIX_SOCKET_PATH "/var/run/rdmacm-mux"
/* Has format %s-%s-%d" <path>-<rdma-dev--name>-<port> */
#define SOCKET_PATH_MAX (PATH_MAX - NAME_MAX - sizeof(int) - 2)
#define RDMA_PORT_NUM 1
@@ -77,7 +76,13 @@ typedef struct RdmaCmServer {
static RdmaCMServer server = {0};
-static void usage(const char *progname)
+static char *get_default_unix_socket_path(void)
+{
+ g_autofree char *run = qemu_get_runtime_dir();
+ return g_build_filename(run, "rdmacm-mux", NULL);
+}
+
+static void usage(const char *progname, const char *default_unix_socket_path)
{
printf("Usage: %s [OPTION]...\n"
"Start a RDMA-CM multiplexer\n"
@@ -86,7 +91,7 @@ static void usage(const char *progname)
"\t-d rdma-device-name Name of RDMA device to register with\n"
"\t-s unix-socket-path Path to unix socket to listen on (default %s)\n"
"\t-p rdma-device-port Port number of RDMA device to register with (default %d)\n",
- progname, UNIX_SOCKET_PATH, RDMA_PORT_NUM);
+ progname, default_unix_socket_path, RDMA_PORT_NUM);
}
static void help(const char *progname)
@@ -97,16 +102,16 @@ static void help(const char *progname)
static void parse_args(int argc, char *argv[])
{
int c;
- char unix_socket_path[SOCKET_PATH_MAX];
+ g_autofree char *default_unix_socket_path = get_default_unix_socket_path();
+ char *unix_socket_path = default_unix_socket_path;
strcpy(server.args.rdma_dev_name, "");
- strcpy(unix_socket_path, UNIX_SOCKET_PATH);
server.args.rdma_port_num = RDMA_PORT_NUM;
while ((c = getopt(argc, argv, "hs:d:p:")) != -1) {
switch (c) {
case 'h':
- usage(argv[0]);
+ usage(argv[0], default_unix_socket_path);
exit(0);
case 'd':
@@ -115,7 +120,7 @@ static void parse_args(int argc, char *argv[])
case 's':
/* This is temporary, final name will build below */
- strncpy(unix_socket_path, optarg, SOCKET_PATH_MAX - 1);
+ unix_socket_path = optarg;
break;
case 'p':
@@ -811,6 +816,7 @@ int main(int argc, char *argv[])
{
int rc;
+ qemu_init_exec_dir(argv[0]);
memset(&server, 0, sizeof(server));
parse_args(argc, argv);
diff --git a/contrib/rdmacm-mux/meson.build b/contrib/rdmacm-mux/meson.build
index 36c9c89630..59f60f9cac 100644
--- a/contrib/rdmacm-mux/meson.build
+++ b/contrib/rdmacm-mux/meson.build
@@ -1,7 +1,7 @@
if have_pvrdma
# FIXME: broken on big endian architectures
executable('rdmacm-mux', files('main.c'), genh,
- dependencies: [glib, libumad],
+ dependencies: [glib, libumad, qemuutil],
build_by_default: false,
install: false)
endif
--
2.38.1
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v2 05/10] qga: Use qemu_get_runtime_dir()
2022-11-10 10:06 [PATCH v2 00/10] util: Introduce qemu_get_runtime_dir() Akihiko Odaki
` (3 preceding siblings ...)
2022-11-10 10:06 ` [PATCH v2 04/10] contrib/rdmacm-mux: " Akihiko Odaki
@ 2022-11-10 10:06 ` Akihiko Odaki
2022-11-10 10:06 ` [PATCH v2 06/10] scsi: " Akihiko Odaki
` (4 subsequent siblings)
9 siblings, 0 replies; 16+ messages in thread
From: Akihiko Odaki @ 2022-11-10 10:06 UTC (permalink / raw)
Cc: qemu-devel, qemu-block, virtio-fs, Yuval Shaia, Marcel Apfelbaum,
Konstantin Kostiuk, Michael Roth, Paolo Bonzini, Fam Zheng,
Dr. David Alan Gilbert, Stefan Hajnoczi, Gerd Hoffmann,
Stefan Weil, Yan Vugenfirer, Akihiko Odaki
qemu_get_runtime_dir() is used to construct the default state directory.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
qga/main.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/qga/main.c b/qga/main.c
index b3580508fa..dc875079f0 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -46,12 +46,11 @@
#define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0"
#endif /* __FreeBSD__ */
#define QGA_SERIAL_PATH_DEFAULT "/dev/ttyS0"
-#define QGA_STATE_RELATIVE_DIR "run"
#else
#define QGA_VIRTIO_PATH_DEFAULT "\\\\.\\Global\\org.qemu.guest_agent.0"
-#define QGA_STATE_RELATIVE_DIR "qemu-ga"
#define QGA_SERIAL_PATH_DEFAULT "COM1"
#endif
+#define QGA_STATE_RELATIVE_DIR "qemu-ga"
#ifdef CONFIG_FSFREEZE
#define QGA_FSFREEZE_HOOK_DEFAULT CONFIG_QEMU_CONFDIR "/fsfreeze-hook"
#endif
@@ -128,12 +127,12 @@ static void stop_agent(GAState *s, bool requested);
static void
init_dfl_pathnames(void)
{
- g_autofree char *state = qemu_get_local_state_dir();
+ g_autofree char *run = qemu_get_runtime_dir();
g_assert(dfl_pathnames.state_dir == NULL);
g_assert(dfl_pathnames.pidfile == NULL);
- dfl_pathnames.state_dir = g_build_filename(state, QGA_STATE_RELATIVE_DIR, NULL);
- dfl_pathnames.pidfile = g_build_filename(state, QGA_STATE_RELATIVE_DIR, "qemu-ga.pid", NULL);
+ dfl_pathnames.state_dir = g_build_filename(run, QGA_STATE_RELATIVE_DIR, NULL);
+ dfl_pathnames.pidfile = g_build_filename(run, QGA_STATE_RELATIVE_DIR, "qemu-ga.pid", NULL);
}
static void quit_handler(int sig)
--
2.38.1
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v2 06/10] scsi: Use qemu_get_runtime_dir()
2022-11-10 10:06 [PATCH v2 00/10] util: Introduce qemu_get_runtime_dir() Akihiko Odaki
` (4 preceding siblings ...)
2022-11-10 10:06 ` [PATCH v2 05/10] qga: " Akihiko Odaki
@ 2022-11-10 10:06 ` Akihiko Odaki
2022-11-10 10:06 ` [PATCH v2 07/10] virtiofsd: " Akihiko Odaki
` (3 subsequent siblings)
9 siblings, 0 replies; 16+ messages in thread
From: Akihiko Odaki @ 2022-11-10 10:06 UTC (permalink / raw)
Cc: qemu-devel, qemu-block, virtio-fs, Yuval Shaia, Marcel Apfelbaum,
Konstantin Kostiuk, Michael Roth, Paolo Bonzini, Fam Zheng,
Dr. David Alan Gilbert, Stefan Hajnoczi, Gerd Hoffmann,
Stefan Weil, Yan Vugenfirer, Akihiko Odaki
qemu_get_runtime_dir() is used to construct the default paths.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
scsi/qemu-pr-helper.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
index 196b78c00d..adb7baecaa 100644
--- a/scsi/qemu-pr-helper.c
+++ b/scsi/qemu-pr-helper.c
@@ -77,10 +77,10 @@ static int gid = -1;
static void compute_default_paths(void)
{
- g_autofree char *state = qemu_get_local_state_dir();
+ g_autofree char *run = qemu_get_runtime_dir();
- socket_path = g_build_filename(state, "run", "qemu-pr-helper.sock", NULL);
- pidfile = g_build_filename(state, "run", "qemu-pr-helper.pid", NULL);
+ socket_path = g_build_filename(run, "qemu-pr-helper.sock", NULL);
+ pidfile = g_build_filename(run, "qemu-pr-helper.pid", NULL);
}
static void usage(const char *name)
--
2.38.1
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v2 07/10] virtiofsd: Use qemu_get_runtime_dir()
2022-11-10 10:06 [PATCH v2 00/10] util: Introduce qemu_get_runtime_dir() Akihiko Odaki
` (5 preceding siblings ...)
2022-11-10 10:06 ` [PATCH v2 06/10] scsi: " Akihiko Odaki
@ 2022-11-10 10:06 ` Akihiko Odaki
2023-09-21 12:58 ` Stefan Hajnoczi
2022-11-10 10:06 ` [PATCH v2 08/10] module: " Akihiko Odaki
` (2 subsequent siblings)
9 siblings, 1 reply; 16+ messages in thread
From: Akihiko Odaki @ 2022-11-10 10:06 UTC (permalink / raw)
Cc: qemu-devel, qemu-block, virtio-fs, Yuval Shaia, Marcel Apfelbaum,
Konstantin Kostiuk, Michael Roth, Paolo Bonzini, Fam Zheng,
Dr. David Alan Gilbert, Stefan Hajnoczi, Gerd Hoffmann,
Stefan Weil, Yan Vugenfirer, Akihiko Odaki
qemu_get_runtime_dir() is used to construct the path to a lock file.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
tools/virtiofsd/fuse_virtio.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
index 9368e292e4..b9eeed85e6 100644
--- a/tools/virtiofsd/fuse_virtio.c
+++ b/tools/virtiofsd/fuse_virtio.c
@@ -901,12 +901,12 @@ static bool fv_socket_lock(struct fuse_session *se)
{
g_autofree gchar *sk_name = NULL;
g_autofree gchar *pidfile = NULL;
- g_autofree gchar *state = NULL;
+ g_autofree gchar *run = NULL;
g_autofree gchar *dir = NULL;
Error *local_err = NULL;
- state = qemu_get_local_state_dir();
- dir = g_build_filename(state, "run", "virtiofsd", NULL);
+ run = qemu_get_runtime_dir();
+ dir = g_build_filename(run, "virtiofsd", NULL);
if (g_mkdir_with_parents(dir, S_IRWXU) < 0) {
fuse_log(FUSE_LOG_ERR, "%s: Failed to create directory %s: %s\n",
--
2.38.1
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH v2 07/10] virtiofsd: Use qemu_get_runtime_dir()
2022-11-10 10:06 ` [PATCH v2 07/10] virtiofsd: " Akihiko Odaki
@ 2023-09-21 12:58 ` Stefan Hajnoczi
2023-09-21 13:56 ` Akihiko Odaki
0 siblings, 1 reply; 16+ messages in thread
From: Stefan Hajnoczi @ 2023-09-21 12:58 UTC (permalink / raw)
To: Akihiko Odaki
Cc: qemu-devel, qemu-block, virtio-fs, Yuval Shaia, Marcel Apfelbaum,
Konstantin Kostiuk, Michael Roth, Paolo Bonzini, Fam Zheng,
Dr. David Alan Gilbert, Gerd Hoffmann, Stefan Weil,
Yan Vugenfirer
[-- Attachment #1: Type: text/plain, Size: 1435 bytes --]
On Thu, Nov 10, 2022 at 07:06:26PM +0900, Akihiko Odaki wrote:
> qemu_get_runtime_dir() is used to construct the path to a lock file.
>
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> ---
> tools/virtiofsd/fuse_virtio.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
> index 9368e292e4..b9eeed85e6 100644
> --- a/tools/virtiofsd/fuse_virtio.c
> +++ b/tools/virtiofsd/fuse_virtio.c
> @@ -901,12 +901,12 @@ static bool fv_socket_lock(struct fuse_session *se)
> {
> g_autofree gchar *sk_name = NULL;
> g_autofree gchar *pidfile = NULL;
> - g_autofree gchar *state = NULL;
> + g_autofree gchar *run = NULL;
> g_autofree gchar *dir = NULL;
> Error *local_err = NULL;
>
> - state = qemu_get_local_state_dir();
> - dir = g_build_filename(state, "run", "virtiofsd", NULL);
> + run = qemu_get_runtime_dir();
> + dir = g_build_filename(run, "virtiofsd", NULL);
>
> if (g_mkdir_with_parents(dir, S_IRWXU) < 0) {
> fuse_log(FUSE_LOG_ERR, "%s: Failed to create directory %s: %s\n",
tools/virtiofsd/ no longer exists. Which version of QEMU did you develop against?
commit e0dc2631ec4ac718ebe22ddea0ab25524eb37b0e
Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
Date: Wed Jan 18 12:11:51 2023 +0000
virtiofsd: Remove source
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH v2 07/10] virtiofsd: Use qemu_get_runtime_dir()
2023-09-21 12:58 ` Stefan Hajnoczi
@ 2023-09-21 13:56 ` Akihiko Odaki
0 siblings, 0 replies; 16+ messages in thread
From: Akihiko Odaki @ 2023-09-21 13:56 UTC (permalink / raw)
To: Stefan Hajnoczi
Cc: qemu-devel, qemu-block, virtio-fs, Yuval Shaia, Marcel Apfelbaum,
Konstantin Kostiuk, Michael Roth, Paolo Bonzini, Fam Zheng,
Dr. David Alan Gilbert, Gerd Hoffmann, Stefan Weil,
Yan Vugenfirer
On 2023/09/21 21:58, Stefan Hajnoczi wrote:
> On Thu, Nov 10, 2022 at 07:06:26PM +0900, Akihiko Odaki wrote:
>> qemu_get_runtime_dir() is used to construct the path to a lock file.
>>
>> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
>> ---
>> tools/virtiofsd/fuse_virtio.c | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
>> index 9368e292e4..b9eeed85e6 100644
>> --- a/tools/virtiofsd/fuse_virtio.c
>> +++ b/tools/virtiofsd/fuse_virtio.c
>> @@ -901,12 +901,12 @@ static bool fv_socket_lock(struct fuse_session *se)
>> {
>> g_autofree gchar *sk_name = NULL;
>> g_autofree gchar *pidfile = NULL;
>> - g_autofree gchar *state = NULL;
>> + g_autofree gchar *run = NULL;
>> g_autofree gchar *dir = NULL;
>> Error *local_err = NULL;
>>
>> - state = qemu_get_local_state_dir();
>> - dir = g_build_filename(state, "run", "virtiofsd", NULL);
>> + run = qemu_get_runtime_dir();
>> + dir = g_build_filename(run, "virtiofsd", NULL);
>>
>> if (g_mkdir_with_parents(dir, S_IRWXU) < 0) {
>> fuse_log(FUSE_LOG_ERR, "%s: Failed to create directory %s: %s\n",
>
> tools/virtiofsd/ no longer exists. Which version of QEMU did you develop against?
>
> commit e0dc2631ec4ac718ebe22ddea0ab25524eb37b0e
> Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Date: Wed Jan 18 12:11:51 2023 +0000
>
> virtiofsd: Remove source
>
> Stefan
It is an old version of the series. You can find the latest version at:
https://patchew.org/QEMU/20230921075425.16738-1-akihiko.odaki@daynix.com/
Regards,
Akihiko Odaki
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 08/10] module: Use qemu_get_runtime_dir()
2022-11-10 10:06 [PATCH v2 00/10] util: Introduce qemu_get_runtime_dir() Akihiko Odaki
` (6 preceding siblings ...)
2022-11-10 10:06 ` [PATCH v2 07/10] virtiofsd: " Akihiko Odaki
@ 2022-11-10 10:06 ` Akihiko Odaki
2022-11-10 10:06 ` [PATCH v2 09/10] util: Remove qemu_get_local_state_dir() Akihiko Odaki
2022-11-10 10:06 ` [PATCH v2 10/10] spice-app: Use qemu_get_runtime_dir() Akihiko Odaki
9 siblings, 0 replies; 16+ messages in thread
From: Akihiko Odaki @ 2022-11-10 10:06 UTC (permalink / raw)
Cc: qemu-devel, qemu-block, virtio-fs, Yuval Shaia, Marcel Apfelbaum,
Konstantin Kostiuk, Michael Roth, Paolo Bonzini, Fam Zheng,
Dr. David Alan Gilbert, Stefan Hajnoczi, Gerd Hoffmann,
Stefan Weil, Yan Vugenfirer, Akihiko Odaki
qemu_get_runtime_dir() is used to construct the path to module upgrades.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
util/module.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/util/module.c b/util/module.c
index 32e263163c..580658edf4 100644
--- a/util/module.c
+++ b/util/module.c
@@ -242,7 +242,8 @@ int module_load(const char *prefix, const char *name, Error **errp)
version_dir = g_strcanon(g_strdup(QEMU_PKGVERSION),
G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "+-.~",
'_');
- dirs[n_dirs++] = g_strdup_printf("/var/run/qemu/%s", version_dir);
+ g_autofree char *run = qemu_get_runtime_dir();
+ dirs[n_dirs++] = g_build_filename(run, "qemu", version_dir, NULL);
#endif
assert(n_dirs <= ARRAY_SIZE(dirs));
--
2.38.1
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v2 09/10] util: Remove qemu_get_local_state_dir()
2022-11-10 10:06 [PATCH v2 00/10] util: Introduce qemu_get_runtime_dir() Akihiko Odaki
` (7 preceding siblings ...)
2022-11-10 10:06 ` [PATCH v2 08/10] module: " Akihiko Odaki
@ 2022-11-10 10:06 ` Akihiko Odaki
2022-11-10 10:06 ` [PATCH v2 10/10] spice-app: Use qemu_get_runtime_dir() Akihiko Odaki
9 siblings, 0 replies; 16+ messages in thread
From: Akihiko Odaki @ 2022-11-10 10:06 UTC (permalink / raw)
Cc: qemu-devel, qemu-block, virtio-fs, Yuval Shaia, Marcel Apfelbaum,
Konstantin Kostiuk, Michael Roth, Paolo Bonzini, Fam Zheng,
Dr. David Alan Gilbert, Stefan Hajnoczi, Gerd Hoffmann,
Stefan Weil, Yan Vugenfirer, Akihiko Odaki
There are no users of the function anymore.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
include/qemu/osdep.h | 8 --------
util/oslib-posix.c | 6 ------
util/oslib-win32.c | 10 ----------
3 files changed, 24 deletions(-)
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 86445aad25..f21ebf2b27 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -557,14 +557,6 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t count)
void qemu_set_cloexec(int fd);
-/* Return a dynamically allocated directory path that is appropriate for storing
- * local state.
- *
- * The caller is responsible for releasing the value returned with g_free()
- * after use.
- */
-char *qemu_get_local_state_dir(void);
-
/**
* qemu_get_runtime_dir:
*
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 9a0b3913ff..b8d79876b2 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -273,12 +273,6 @@ int qemu_socketpair(int domain, int type, int protocol, int sv[2])
return ret;
}
-char *
-qemu_get_local_state_dir(void)
-{
- return get_relocated_path(CONFIG_QEMU_LOCALSTATEDIR);
-}
-
char *
qemu_get_runtime_dir(void)
{
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 6ad1bb4bac..a32cc5b1be 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -233,16 +233,6 @@ int qemu_get_thread_id(void)
return GetCurrentThreadId();
}
-char *
-qemu_get_local_state_dir(void)
-{
- const char * const *data_dirs = g_get_system_data_dirs();
-
- g_assert(data_dirs && data_dirs[0]);
-
- return g_strdup(data_dirs[0]);
-}
-
char *
qemu_get_runtime_dir(void)
{
--
2.38.1
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v2 10/10] spice-app: Use qemu_get_runtime_dir()
2022-11-10 10:06 [PATCH v2 00/10] util: Introduce qemu_get_runtime_dir() Akihiko Odaki
` (8 preceding siblings ...)
2022-11-10 10:06 ` [PATCH v2 09/10] util: Remove qemu_get_local_state_dir() Akihiko Odaki
@ 2022-11-10 10:06 ` Akihiko Odaki
9 siblings, 0 replies; 16+ messages in thread
From: Akihiko Odaki @ 2022-11-10 10:06 UTC (permalink / raw)
Cc: qemu-devel, qemu-block, virtio-fs, Yuval Shaia, Marcel Apfelbaum,
Konstantin Kostiuk, Michael Roth, Paolo Bonzini, Fam Zheng,
Dr. David Alan Gilbert, Stefan Hajnoczi, Gerd Hoffmann,
Stefan Weil, Yan Vugenfirer, Akihiko Odaki
qemu_get_runtime_dir() provides QEMU-specific fallback of runtime
directory.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
ui/spice-app.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/ui/spice-app.c b/ui/spice-app.c
index 7e71e18da9..feb162baa7 100644
--- a/ui/spice-app.c
+++ b/ui/spice-app.c
@@ -145,8 +145,8 @@ static void spice_app_display_early_init(DisplayOptions *opts)
atexit(spice_app_atexit);
if (qemu_name) {
- app_dir = g_build_filename(g_get_user_runtime_dir(),
- "qemu", qemu_name, NULL);
+ g_autofree char *run = qemu_get_runtime_dir();
+ app_dir = g_build_filename(run, "qemu", qemu_name, NULL);
if (g_mkdir_with_parents(app_dir, S_IRWXU) < -1) {
error_report("Failed to create directory %s: %s",
app_dir, strerror(errno));
--
2.38.1
^ permalink raw reply related [flat|nested] 16+ messages in thread