From nobody Sun Apr 28 21:56:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1567697233; cv=none; d=zoho.com; s=zohoarc; b=PYierRUMBfcs0NAImTcaoCOspjMTNjAHPEYJ5/OeN+tnoknhvwjW6RQoDkBQQhyzFmjcfKWAjMTxovQKfB5raYENRYYCMGZ891rGjzrno9tMdxTj3ubY9fNpjTQWzR12Pa/AC5SYEDlwTeex9nvxEdVyYMoFsst09LBegh2f32s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567697233; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Of8BSSHwOcDoY6RscqMtUUf/bJ4qMcu+jiM1ThcXyQ0=; b=HGsej79nS3UMLoFFYpDCzFAcRvauRXpoBxKiewbQT0xffIolITI4EwMfDvjT8nR3nZcQFg/PheCIlAMm8aZ8IOsxS6+bCqqw4J74lntrAnsFnjJssnOatj4MxszNhyYKurpGjE18IXrwkFGUHeWU+eChjRk0XnUg56bV54jEibo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1567697233359865.8958489967664; Thu, 5 Sep 2019 08:27:13 -0700 (PDT) Received: from localhost ([::1]:47286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5tfD-00068J-W0 for importer@patchew.org; Thu, 05 Sep 2019 11:27:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42784) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5taB-0000D7-0K for qemu-devel@nongnu.org; Thu, 05 Sep 2019 11:22:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i5ta9-0007fu-CT for qemu-devel@nongnu.org; Thu, 05 Sep 2019 11:21:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35714) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i5ta9-0007ff-4U for qemu-devel@nongnu.org; Thu, 05 Sep 2019 11:21:57 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 63F6389AC7; Thu, 5 Sep 2019 15:21:56 +0000 (UTC) Received: from localhost (ovpn-117-222.ams2.redhat.com [10.36.117.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F2845D9CA; Thu, 5 Sep 2019 15:21:48 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org, virtio-fs@redhat.com Date: Thu, 5 Sep 2019 16:21:34 +0100 Message-Id: <20190905152136.30637-2-stefanha@redhat.com> In-Reply-To: <20190905152136.30637-1-stefanha@redhat.com> References: <20190905152136.30637-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 05 Sep 2019 15:21:56 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 1/3] virtiofsd: add org.qemu.Virtiofsd interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eryu Guan , "Dr. David Alan Gilbert" , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Define a DBus interface for virtiofsd management. It only allows querying and changing the log level at the moment. In the future more methods and properties could be added. Signed-off-by: Stefan Hajnoczi --- configure | 7 +++++++ Makefile | 13 +++++++++++++ contrib/virtiofsd/Makefile.objs | 6 +++++- .gitignore | 1 + contrib/virtiofsd/org.qemu.Virtiofsd.xml | 7 +++++++ 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 contrib/virtiofsd/org.qemu.Virtiofsd.xml diff --git a/configure b/configure index 2976e64b9b..17b789d772 100755 --- a/configure +++ b/configure @@ -3674,10 +3674,16 @@ if $pkg_config --atleast-version=3D$glib_req_ver gi= o-2.0; then gio=3Dyes gio_cflags=3D$($pkg_config --cflags gio-2.0) gio_libs=3D$($pkg_config --libs gio-2.0) + gdbus_codegen=3D$($pkg_config --variable=3Dgdbus_codegen gio-2.0) else gio=3Dno fi =20 +if $pkg_config --atleast-version=3D$glib_req_ver gio-unix-2.0; then + gio_cflags=3D"$gio_cflags $($pkg_config --cflags gio-unix-2.0)" + gio_libs=3D"$gio_libs $($pkg_config --libs gio-unix-2.0)" +fi + # Sanity check that the current size_t matches the # size that glib thinks it should be. This catches # problems on multi-arch where people try to build @@ -6856,6 +6862,7 @@ if test "$gio" =3D "yes" ; then echo "CONFIG_GIO=3Dy" >> $config_host_mak echo "GIO_CFLAGS=3D$gio_cflags" >> $config_host_mak echo "GIO_LIBS=3D$gio_libs" >> $config_host_mak + echo "GDBUS_CODEGEN=3D$gdbus_codegen" >> $config_host_mak fi echo "CONFIG_TLS_PRIORITY=3D\"$tls_priority\"" >> $config_host_mak if test "$gnutls" =3D "yes" ; then diff --git a/Makefile b/Makefile index a3dfdd6fa8..6b1af33348 100644 --- a/Makefile +++ b/Makefile @@ -124,6 +124,11 @@ GENERATED_QAPI_FILES +=3D qapi/qapi-doc.texi =20 generated-files-y +=3D $(GENERATED_QAPI_FILES) =20 +ifdef CONFIG_LINUX +generated-files-y +=3D contrib/virtiofsd/gdbus_generated.h +generated-files-y +=3D contrib/virtiofsd/gdbus_generated.c +endif + generated-files-y +=3D trace/generated-tcg-tracers.h =20 generated-files-y +=3D trace/generated-helpers-wrappers.h @@ -646,6 +651,14 @@ rdmacm-mux$(EXESUF): $(rdmacm-mux-obj-y) $(COMMON_LDAD= DS) $(call LINK, $^) =20 ifdef CONFIG_LINUX # relies on Linux-specific syscalls +contrib/virtiofsd/gdbus_generated.h contrib/virtiofsd/gdbus_generated.c: c= ontrib/virtiofsd/gdbus_generated.c-timestamp ; +contrib/virtiofsd/gdbus_generated.c-timestamp: $(SRC_PATH)/contrib/virtiof= sd/org.qemu.Virtiofsd.xml + $(call quiet-command,$(GDBUS_CODEGEN) $< \ + --interface-prefix org.qemu \ + --generate-c-code contrib/virtiofsd/gdbus_generated, \ + "GEN","$(@:%-timestamp=3D%)") + @>$@ + virtiofsd$(EXESUF): $(virtiofsd-obj-y) libvhost-user.a $(COMMON_LDADDS) $(call LINK, $^) endif diff --git a/contrib/virtiofsd/Makefile.objs b/contrib/virtiofsd/Makefile.o= bjs index 25f1e8dd73..9b2af1bc23 100644 --- a/contrib/virtiofsd/Makefile.objs +++ b/contrib/virtiofsd/Makefile.objs @@ -7,9 +7,13 @@ virtiofsd-obj-y =3D buffer.o \ fuse_virtio.o \ helper.o \ passthrough_ll.o \ - seccomp.o + seccomp.o \ + gdbus_generated.o =20 seccomp.o-cflags :=3D $(SECCOMP_CFLAGS) seccomp.o-libs :=3D $(SECCOMP_LIBS) =20 +gdbus_generated.o-cflags :=3D $(GIO_CFLAGS) +gdbus_generated.o-libs :=3D $(GIO_LIBS) + passthrough_ll.o-libs +=3D -lcap diff --git a/.gitignore b/.gitignore index fd6e6c38c7..c04d5dd0b1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /config-target.* /config.status /config-temp +/contrib/virtiofsd/gdbus_generated.* /elf2dmp /trace-events-all /trace/generated-events.h diff --git a/contrib/virtiofsd/org.qemu.Virtiofsd.xml b/contrib/virtiofsd/o= rg.qemu.Virtiofsd.xml new file mode 100644 index 0000000000..efc0c59020 --- /dev/null +++ b/contrib/virtiofsd/org.qemu.Virtiofsd.xml @@ -0,0 +1,7 @@ + + + + + + --=20 2.21.0 From nobody Sun Apr 28 21:56:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1567697049; cv=none; d=zoho.com; s=zohoarc; b=k/0MeAvS7O2ykfmhUgBb+s2KNYcgRpCz1/gAT7RnKN1LS4J+68uh4iuu24ZEddtCgA+i63ORjm+kXRc4qycPIC55eTBivLf6yeRp6+EoaRX4UydtN+TgxyD7d5lM7vFh8utaNZP1HIhUQb4YBFbyfgeOxRSqyMo3By/My89nBGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567697049; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=O05OFEEypY0QlV8xAUf0dxzU6pq580DXhMnzQKjCcsY=; b=dhDbJEAjTc1JeeqmJIibl8PQkKjnAn1W7rr0JQL3vZ8z5GtAgLnAZkzvbfdVRbtsgF0s+f+mjtTN8xfi2mspP+Oe3FEa5XDpl5vX4tfPU1ftgAIUsokHcXCGiEtCzRZpcZ8L9GejEv4sI27Wuh23EwRGpVWXfFNJhV4E1Pu6cZI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1567697049256543.540041886993; Thu, 5 Sep 2019 08:24:09 -0700 (PDT) Received: from localhost ([::1]:47206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5tcF-0002A0-C7 for importer@patchew.org; Thu, 05 Sep 2019 11:24:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42822) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5taK-0000QC-FY for qemu-devel@nongnu.org; Thu, 05 Sep 2019 11:22:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i5taI-0007j8-Ql for qemu-devel@nongnu.org; Thu, 05 Sep 2019 11:22:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60252) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i5taI-0007id-IS for qemu-devel@nongnu.org; Thu, 05 Sep 2019 11:22:06 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D21403082E57; Thu, 5 Sep 2019 15:22:05 +0000 (UTC) Received: from localhost (ovpn-117-222.ams2.redhat.com [10.36.117.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id C57926060D; Thu, 5 Sep 2019 15:21:57 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org, virtio-fs@redhat.com Date: Thu, 5 Sep 2019 16:21:35 +0100 Message-Id: <20190905152136.30637-3-stefanha@redhat.com> In-Reply-To: <20190905152136.30637-1-stefanha@redhat.com> References: <20190905152136.30637-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 05 Sep 2019 15:22:05 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 2/3] virtiofsd: add DBus server to handle log level changes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eryu Guan , "Dr. David Alan Gilbert" , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Introduce a DBus server thread that runs alongside the other virtiofsd threads. It processes changes to the /org/qemu/virtiofsd object which can be accessed at the org.qemu.virtiofsd location on the bus. This code does not use locking because we are the only writer to the int current_log_level variable. More advanced management commands would require locking to prevent race conditions with the other threads. Signed-off-by: Stefan Hajnoczi --- contrib/virtiofsd/Makefile.objs | 3 +- contrib/virtiofsd/dbus.h | 9 ++ contrib/virtiofsd/dbus.c | 162 +++++++++++++++++++++++++++++ contrib/virtiofsd/passthrough_ll.c | 8 +- 4 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 contrib/virtiofsd/dbus.h create mode 100644 contrib/virtiofsd/dbus.c diff --git a/contrib/virtiofsd/Makefile.objs b/contrib/virtiofsd/Makefile.o= bjs index 9b2af1bc23..d59ab60f3d 100644 --- a/contrib/virtiofsd/Makefile.objs +++ b/contrib/virtiofsd/Makefile.objs @@ -8,7 +8,8 @@ virtiofsd-obj-y =3D buffer.o \ helper.o \ passthrough_ll.o \ seccomp.o \ - gdbus_generated.o + gdbus_generated.o \ + dbus.o =20 seccomp.o-cflags :=3D $(SECCOMP_CFLAGS) seccomp.o-libs :=3D $(SECCOMP_LIBS) diff --git a/contrib/virtiofsd/dbus.h b/contrib/virtiofsd/dbus.h new file mode 100644 index 0000000000..aa18e47408 --- /dev/null +++ b/contrib/virtiofsd/dbus.h @@ -0,0 +1,9 @@ +#ifndef DBUS_H +#define DBUS_H + +#include + +bool setup_dbus(void); +void cleanup_dbus(void); + +#endif /* DBUS_H */ diff --git a/contrib/virtiofsd/dbus.c b/contrib/virtiofsd/dbus.c new file mode 100644 index 0000000000..bc2308e34b --- /dev/null +++ b/contrib/virtiofsd/dbus.c @@ -0,0 +1,162 @@ +#include +#include +#include +#include "fuse_log.h" +#include "dbus.h" +#include "gdbus_generated.h" + +static GThread *the_dbus_thread; +static GMainContext *the_dbus_context; +static GMainLoop *the_dbus_loop; + +/* Set the string property based on the current log level */ +static void refresh_log_level(Virtiofsd *virtiofsd) +{ + switch (current_log_level) { + case LOG_ERR: + virtiofsd_set_log_level(virtiofsd, "err"); + break; + case LOG_WARNING: + virtiofsd_set_log_level(virtiofsd, "warning"); + break; + case LOG_INFO: + virtiofsd_set_log_level(virtiofsd, "info"); + break; + case LOG_DEBUG: + virtiofsd_set_log_level(virtiofsd, "debug"); + break; + } +} + +/* Handle changes to Virtiofsd object properties */ +static void notify(GObject *object, GParamSpec *pspec) +{ + Virtiofsd *virtiofsd =3D VIRTIOFSD(object); + + fprintf(stderr, "%s %s\n", __func__, pspec->name); + + if (strcmp(pspec->name, "log-level") =3D=3D 0) { + const char *s =3D virtiofsd_get_log_level(virtiofsd); + + if (strcmp(s, "err") =3D=3D 0) { + current_log_level =3D LOG_ERR; + } else if (strcmp(s, "warning") =3D=3D 0) { + current_log_level =3D LOG_WARNING; + } else if (strcmp(s, "info") =3D=3D 0) { + current_log_level =3D LOG_INFO; + } else if (strcmp(s, "debug") =3D=3D 0) { + current_log_level =3D LOG_DEBUG; + } else { + /* Invalid, reset the log level property */ + refresh_log_level(virtiofsd); + } + } +} + +typedef struct { + Virtiofsd *virtiofsd; + pthread_barrier_t *started; +} GBusOwnNameData; + +static void bus_acquired(GDBusConnection *connection, const gchar *name, + gpointer user_data) +{ + GBusOwnNameData *data =3D user_data; + GError *error =3D NULL; + + if (!g_dbus_interface_skeleton_export( + G_DBUS_INTERFACE_SKELETON(data->virtiofsd), + connection, "/org/qemu/virtiofsd", &error)) { + fuse_err("g_dbus_interface_skeleton_export: %s\n", error->message); + g_error_free(error); + exit(EXIT_FAILURE); + } +} + +static void name_acquired(GDBusConnection *connection, const gchar *name, + gpointer user_data) +{ + GBusOwnNameData *data =3D user_data; + + pthread_barrier_wait(data->started); +} + +static void name_lost(GDBusConnection *connection, const gchar *name, + gpointer user_data) +{ + if (connection) { + fuse_err("unable to own dbus name\n"); + } else { + fuse_err("unable to connect to dbus\n"); + } + exit(EXIT_FAILURE); +} + +static gpointer dbus_thread(gpointer opaque) +{ + GBusOwnNameData data; + Virtiofsd *virtiofsd; + guint owner_id; + + g_main_context_push_thread_default(the_dbus_context); + + virtiofsd =3D virtiofsd_skeleton_new(); + refresh_log_level(virtiofsd); + g_signal_connect(virtiofsd, "notify", G_CALLBACK(notify), NULL); + + data.virtiofsd =3D virtiofsd; + data.started =3D opaque; + + owner_id =3D g_bus_own_name(G_BUS_TYPE_SESSION, "org.qemu.virtiofsd", + G_BUS_NAME_OWNER_FLAGS_DO_NOT_QUEUE, bus_acquired, name_acquir= ed, + name_lost, &data, NULL); + + g_main_loop_run(the_dbus_loop); + g_bus_unown_name(owner_id); + g_object_unref(virtiofsd); + + g_main_context_pop_thread_default(the_dbus_context); + return NULL; +} + +/** + * Start DBus server thread. + * + * Returns: true on success, false on failure + */ +bool setup_dbus(void) +{ + pthread_barrier_t started; + + assert(!the_dbus_thread); + + fuse_info("Using dbus address %s\n", + getenv("DBUS_SESSION_BUS_ADDRESS") ?: "(null)"); + + pthread_barrier_init(&started, NULL, 2); + + the_dbus_context =3D g_main_context_new(); + the_dbus_loop =3D g_main_loop_new(the_dbus_context, FALSE); + the_dbus_thread =3D g_thread_new("dbus-thread", dbus_thread, &started); + + pthread_barrier_wait(&started); + pthread_barrier_destroy(&started); + + return true; +} + +/** + * Stop DBus server thread. + */ +void cleanup_dbus(void) +{ + g_main_loop_quit(the_dbus_loop); + g_thread_join(the_dbus_thread); + the_dbus_thread =3D NULL; + + g_main_loop_unref(the_dbus_loop); + the_dbus_loop =3D NULL; + + g_main_context_unref(the_dbus_context); + the_dbus_context =3D NULL; +} diff --git a/contrib/virtiofsd/passthrough_ll.c b/contrib/virtiofsd/passthr= ough_ll.c index 0ef01b7e3f..0ddd7d280a 100644 --- a/contrib/virtiofsd/passthrough_ll.c +++ b/contrib/virtiofsd/passthrough_ll.c @@ -66,6 +66,7 @@ #include #include "fuse_log.h" #include "seccomp.h" +#include "dbus.h" =20 /* Keep track of inode posix locks for each owner. */ struct lo_inode_plock { @@ -2989,6 +2990,9 @@ int main(int argc, char *argv[]) if (fuse_session_mount(se) !=3D 0) goto err_out3; =20 + if (!setup_dbus()) + goto err_out4; + fuse_daemonize(opts.foreground); =20 if (lo.ireg_sock !=3D -1) { @@ -2998,7 +3002,7 @@ int main(int argc, char *argv[]) if (ret) { warnx("pthread_create: %s", strerror(ret)); ret =3D 1; - goto err_out4; + goto err_out5; } =20 get_shared(&lo, &lo.root); @@ -3014,6 +3018,8 @@ int main(int argc, char *argv[]) /* Block until ctrl+c or fusermount -u */ ret =3D virtio_loop(se); =20 +err_out5: + cleanup_dbus(); err_out4: fuse_session_unmount(se); err_out3: --=20 2.21.0 From nobody Sun Apr 28 21:56:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1567697048; cv=none; d=zoho.com; s=zohoarc; b=Dx6QQ5pS/HW4BJZeChBXHrGOTIbIt/jMeIUI4CqLHqjx/e2AB4WMjHG8vHpmWj3SXYJf0oIbD/6nbU3AlAJ1q7sf8YUPYMm2hl75YgOuEcNc2N5Y6t1k30cvLey7HP36wW5SfZ4PR2YAKmbxm2th/YOpmlfDD3LQxOG5EPbKoYQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567697048; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=DuYDhNXQjR0RXoZH9Vuf8U3uS4V60N08LEGsVr5tEBA=; b=HhnP7ZpuHZORZ486sa24h/GZ//1gdCQhl5inMRVQGxawkXsHhxarnCKpz+yYbdJavJoS5e+LTWhNDl9nSnGLNXkCkU2puriD7brRhs7uJtx6WjLjzxQAafEOOrLc0McJXJms6SjeGOms7pp5pr16QxcY7PYeSq43BUviRFkBBGo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1567697048160373.4206876795687; Thu, 5 Sep 2019 08:24:08 -0700 (PDT) Received: from localhost ([::1]:47208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5tcE-0002Bp-9w for importer@patchew.org; Thu, 05 Sep 2019 11:24:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42841) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5taM-0000Sq-Gq for qemu-devel@nongnu.org; Thu, 05 Sep 2019 11:22:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i5taL-0007k8-0x for qemu-devel@nongnu.org; Thu, 05 Sep 2019 11:22:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50952) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i5taK-0007jq-O8 for qemu-devel@nongnu.org; Thu, 05 Sep 2019 11:22:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13B84862E; Thu, 5 Sep 2019 15:22:08 +0000 (UTC) Received: from localhost (ovpn-117-222.ams2.redhat.com [10.36.117.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 387076060D; Thu, 5 Sep 2019 15:22:07 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org, virtio-fs@redhat.com Date: Thu, 5 Sep 2019 16:21:36 +0100 Message-Id: <20190905152136.30637-4-stefanha@redhat.com> In-Reply-To: <20190905152136.30637-1-stefanha@redhat.com> References: <20190905152136.30637-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 05 Sep 2019 15:22:08 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 3/3] virtiofsd: add virtiofsctl command-line management tool X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eryu Guan , "Dr. David Alan Gilbert" , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" virtiofsctl can control a running virtiofsd process: usage: ./virtiofsctl COMMAND [args...] Commands: get-log-level - show current log level set-log-level LEVEL - set current log level to one of "err", "warning", "info", "debug" Make sure it is running in the same DBus session as virtiofsd. This may require setting the DBUS_SESSION_BUS_ADDRESS environment variable to the same value as used by virtiofsd. Signed-off-by: Stefan Hajnoczi --- Makefile | 3 ++ Makefile.objs | 1 + contrib/virtiofsd/Makefile.objs | 3 ++ contrib/virtiofsd/virtiofsctl.c | 55 +++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 contrib/virtiofsd/virtiofsctl.c diff --git a/Makefile b/Makefile index 6b1af33348..d7ed9e7669 100644 --- a/Makefile +++ b/Makefile @@ -419,6 +419,7 @@ dummy :=3D $(call unnest-vars,, \ ivshmem-client-obj-y \ ivshmem-server-obj-y \ virtiofsd-obj-y \ + virtiofsctl-obj-y \ rdmacm-mux-obj-y \ libvhost-user-obj-y \ vhost-user-scsi-obj-y \ @@ -661,6 +662,8 @@ contrib/virtiofsd/gdbus_generated.c-timestamp: $(SRC_PA= TH)/contrib/virtiofsd/org =20 virtiofsd$(EXESUF): $(virtiofsd-obj-y) libvhost-user.a $(COMMON_LDADDS) $(call LINK, $^) +virtiofsctl$(EXESUF): $(virtiofsctl-obj-y) + $(call LINK, $^) endif =20 vhost-user-gpu$(EXESUF): $(vhost-user-gpu-obj-y) $(libvhost-user-obj-y) li= bqemuutil.a libqemustub.a diff --git a/Makefile.objs b/Makefile.objs index dfdd7d56ea..326a8abb8e 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -126,6 +126,7 @@ rdmacm-mux-obj-y =3D contrib/rdmacm-mux/ vhost-user-input-obj-y =3D contrib/vhost-user-input/ vhost-user-gpu-obj-y =3D contrib/vhost-user-gpu/ virtiofsd-obj-y =3D contrib/virtiofsd/ +virtiofsctl-obj-y =3D contrib/virtiofsd/ =20 ###################################################################### trace-events-subdirs =3D diff --git a/contrib/virtiofsd/Makefile.objs b/contrib/virtiofsd/Makefile.o= bjs index d59ab60f3d..3f944d493e 100644 --- a/contrib/virtiofsd/Makefile.objs +++ b/contrib/virtiofsd/Makefile.objs @@ -11,6 +11,9 @@ virtiofsd-obj-y =3D buffer.o \ gdbus_generated.o \ dbus.o =20 +virtiofsctl-obj-y =3D virtiofsctl.o \ + gdbus_generated.o + seccomp.o-cflags :=3D $(SECCOMP_CFLAGS) seccomp.o-libs :=3D $(SECCOMP_LIBS) =20 diff --git a/contrib/virtiofsd/virtiofsctl.c b/contrib/virtiofsd/virtiofsct= l.c new file mode 100644 index 0000000000..39bee2b881 --- /dev/null +++ b/contrib/virtiofsd/virtiofsctl.c @@ -0,0 +1,55 @@ +#include +#include "gdbus_generated.h" + +static void get_log_level(Virtiofsd *virtiofsd) +{ + const char *value =3D virtiofsd_get_log_level(virtiofsd); + + printf("%s\n", value ? value : "(null)"); +} + +static void set_log_level(Virtiofsd *virtiofsd, const char *value) +{ + virtiofsd_set_log_level(virtiofsd, value); +} + +static void usage(const char *progname) +{ + printf("usage: %s COMMAND [args...]\n", progname); + printf("\n"); + printf("Commands:\n"); + printf(" get-log-level - show current log level\n"); + printf(" set-log-level LEVEL - set current log level to one of\n"); + printf(" \"err\", \"warning\", \"info\", \"debu= g\"\n"); + exit(0); +} + +int main(int argc, char **argv) +{ + Virtiofsd *virtiofsd; + GError *error =3D NULL; + + if (argc < 2) { + usage(argv[0]); + } + + virtiofsd =3D virtiofsd_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, "org.qemu.virtiofsd", + "/org/qemu/virtiofsd", NULL, &error); + if (error) { + fprintf(stderr, "%s\n", error->message); + g_error_free(error); + return 1; + } + + if (strcmp(argv[0], "get-log-level") =3D=3D 0) { + get_log_level(virtiofsd); + } else if (strcmp(argv[0], "set-log-level") =3D=3D 0) { + if (argc !=3D 3) { + usage(argv[0]); + } + set_log_level(virtiofsd, argv[2]); + } + g_object_unref(virtiofsd); + return 0; +} --=20 2.21.0