All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: virtio-fs@redhat.com,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	qemu-devel@nongnu.org
Subject: Re: [Virtio-fs] [RFC 3/3] virtiofsd: add virtiofsctl command-line management tool
Date: Thu, 5 Sep 2019 18:12:48 +0100	[thread overview]
Message-ID: <20190905171248.GP2700@work-vm> (raw)
In-Reply-To: <20190905152136.30637-4-stefanha@redhat.com>

* Stefan Hajnoczi (stefanha@redhat.com) wrote:
> 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 <stefanha@redhat.com>
> ---
>  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 := $(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_PATH)/contrib/virtiofsd/org
>  
>  virtiofsd$(EXESUF): $(virtiofsd-obj-y) libvhost-user.a $(COMMON_LDADDS)
>  	$(call LINK, $^)
> +virtiofsctl$(EXESUF): $(virtiofsctl-obj-y)
> +	$(call LINK, $^)
>  endif
>  
>  vhost-user-gpu$(EXESUF): $(vhost-user-gpu-obj-y) $(libvhost-user-obj-y) libqemuutil.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 = contrib/rdmacm-mux/
>  vhost-user-input-obj-y = contrib/vhost-user-input/
>  vhost-user-gpu-obj-y = contrib/vhost-user-gpu/
>  virtiofsd-obj-y = contrib/virtiofsd/
> +virtiofsctl-obj-y = contrib/virtiofsd/
>  
>  ######################################################################
>  trace-events-subdirs =
> diff --git a/contrib/virtiofsd/Makefile.objs b/contrib/virtiofsd/Makefile.objs
> index d59ab60f3d..3f944d493e 100644
> --- a/contrib/virtiofsd/Makefile.objs
> +++ b/contrib/virtiofsd/Makefile.objs
> @@ -11,6 +11,9 @@ virtiofsd-obj-y = buffer.o \
>                    gdbus_generated.o \
>                    dbus.o
>  
> +virtiofsctl-obj-y = virtiofsctl.o \
> +                    gdbus_generated.o
> +
>  seccomp.o-cflags := $(SECCOMP_CFLAGS)
>  seccomp.o-libs := $(SECCOMP_LIBS)
>  
> diff --git a/contrib/virtiofsd/virtiofsctl.c b/contrib/virtiofsd/virtiofsctl.c
> new file mode 100644
> index 0000000000..39bee2b881
> --- /dev/null
> +++ b/contrib/virtiofsd/virtiofsctl.c
> @@ -0,0 +1,55 @@
> +#include <stdio.h>
> +#include "gdbus_generated.h"
> +
> +static void get_log_level(Virtiofsd *virtiofsd)
> +{
> +    const char *value = 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\", \"debug\"\n");
> +    exit(0);
> +}
> +
> +int main(int argc, char **argv)
> +{
> +    Virtiofsd *virtiofsd;
> +    GError *error = NULL;
> +
> +    if (argc < 2) {
> +        usage(argv[0]);
> +    }
> +
> +    virtiofsd = 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") == 0) {

This and the one below works a lot better with argv[1] !

(I wonder if a little python script would be better for these type of
wrappers).

Dave

> +        get_log_level(virtiofsd);
> +    } else if (strcmp(argv[0], "set-log-level") == 0) {

> +        if (argc != 3) {
> +            usage(argv[0]);
> +        }
> +        set_log_level(virtiofsd, argv[2]);
> +    }
> +    g_object_unref(virtiofsd);
> +    return 0;
> +}
> -- 
> 2.21.0
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK


WARNING: multiple messages have this Message-ID (diff)
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: virtio-fs@redhat.com,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Eryu Guan" <eguan@linux.alibaba.com>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [RFC 3/3] virtiofsd: add virtiofsctl command-line management tool
Date: Thu, 5 Sep 2019 18:12:48 +0100	[thread overview]
Message-ID: <20190905171248.GP2700@work-vm> (raw)
In-Reply-To: <20190905152136.30637-4-stefanha@redhat.com>

* Stefan Hajnoczi (stefanha@redhat.com) wrote:
> 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 <stefanha@redhat.com>
> ---
>  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 := $(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_PATH)/contrib/virtiofsd/org
>  
>  virtiofsd$(EXESUF): $(virtiofsd-obj-y) libvhost-user.a $(COMMON_LDADDS)
>  	$(call LINK, $^)
> +virtiofsctl$(EXESUF): $(virtiofsctl-obj-y)
> +	$(call LINK, $^)
>  endif
>  
>  vhost-user-gpu$(EXESUF): $(vhost-user-gpu-obj-y) $(libvhost-user-obj-y) libqemuutil.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 = contrib/rdmacm-mux/
>  vhost-user-input-obj-y = contrib/vhost-user-input/
>  vhost-user-gpu-obj-y = contrib/vhost-user-gpu/
>  virtiofsd-obj-y = contrib/virtiofsd/
> +virtiofsctl-obj-y = contrib/virtiofsd/
>  
>  ######################################################################
>  trace-events-subdirs =
> diff --git a/contrib/virtiofsd/Makefile.objs b/contrib/virtiofsd/Makefile.objs
> index d59ab60f3d..3f944d493e 100644
> --- a/contrib/virtiofsd/Makefile.objs
> +++ b/contrib/virtiofsd/Makefile.objs
> @@ -11,6 +11,9 @@ virtiofsd-obj-y = buffer.o \
>                    gdbus_generated.o \
>                    dbus.o
>  
> +virtiofsctl-obj-y = virtiofsctl.o \
> +                    gdbus_generated.o
> +
>  seccomp.o-cflags := $(SECCOMP_CFLAGS)
>  seccomp.o-libs := $(SECCOMP_LIBS)
>  
> diff --git a/contrib/virtiofsd/virtiofsctl.c b/contrib/virtiofsd/virtiofsctl.c
> new file mode 100644
> index 0000000000..39bee2b881
> --- /dev/null
> +++ b/contrib/virtiofsd/virtiofsctl.c
> @@ -0,0 +1,55 @@
> +#include <stdio.h>
> +#include "gdbus_generated.h"
> +
> +static void get_log_level(Virtiofsd *virtiofsd)
> +{
> +    const char *value = 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\", \"debug\"\n");
> +    exit(0);
> +}
> +
> +int main(int argc, char **argv)
> +{
> +    Virtiofsd *virtiofsd;
> +    GError *error = NULL;
> +
> +    if (argc < 2) {
> +        usage(argv[0]);
> +    }
> +
> +    virtiofsd = 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") == 0) {

This and the one below works a lot better with argv[1] !

(I wonder if a little python script would be better for these type of
wrappers).

Dave

> +        get_log_level(virtiofsd);
> +    } else if (strcmp(argv[0], "set-log-level") == 0) {

> +        if (argc != 3) {
> +            usage(argv[0]);
> +        }
> +        set_log_level(virtiofsd, argv[2]);
> +    }
> +    g_object_unref(virtiofsd);
> +    return 0;
> +}
> -- 
> 2.21.0
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK


  reply	other threads:[~2019-09-05 17:12 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-05 15:21 [Virtio-fs] [RFC 0/3] virtiofsd: get/set log level via DBus Stefan Hajnoczi
2019-09-05 15:21 ` [Qemu-devel] " Stefan Hajnoczi
2019-09-05 15:21 ` [Virtio-fs] [RFC 1/3] virtiofsd: add org.qemu.Virtiofsd interface Stefan Hajnoczi
2019-09-05 15:21   ` [Qemu-devel] " Stefan Hajnoczi
2019-09-05 15:21 ` [Virtio-fs] [RFC 2/3] virtiofsd: add DBus server to handle log level changes Stefan Hajnoczi
2019-09-05 15:21   ` [Qemu-devel] " Stefan Hajnoczi
2019-09-05 17:27   ` [Virtio-fs] " Dr. David Alan Gilbert
2019-09-05 17:27     ` [Qemu-devel] " Dr. David Alan Gilbert
2019-09-06 10:23     ` [Virtio-fs] " Stefan Hajnoczi
2019-09-06 10:23       ` [Qemu-devel] " Stefan Hajnoczi
2019-09-06 10:49       ` [Virtio-fs] " Daniel P. Berrangé
2019-09-06 10:49         ` Daniel P. Berrangé
2019-09-06 11:12         ` [Virtio-fs] " Dr. David Alan Gilbert
2019-09-06 11:12           ` Dr. David Alan Gilbert
2019-09-06 11:48           ` [Virtio-fs] " Daniel P. Berrangé
2019-09-06 11:48             ` Daniel P. Berrangé
2019-09-05 15:21 ` [Virtio-fs] [RFC 3/3] virtiofsd: add virtiofsctl command-line management tool Stefan Hajnoczi
2019-09-05 15:21   ` [Qemu-devel] " Stefan Hajnoczi
2019-09-05 17:12   ` Dr. David Alan Gilbert [this message]
2019-09-05 17:12     ` Dr. David Alan Gilbert
2019-09-05 20:03     ` [Virtio-fs] " Marc-André Lureau
2019-09-05 20:03       ` [Qemu-devel] " Marc-André Lureau
2019-09-06 10:33       ` [Virtio-fs] " Stefan Hajnoczi
2019-09-06 10:33         ` [Qemu-devel] " Stefan Hajnoczi
2019-09-05 17:40 ` [Virtio-fs] [RFC 0/3] virtiofsd: get/set log level via DBus Dr. David Alan Gilbert
2019-09-05 17:40   ` [Qemu-devel] " Dr. David Alan Gilbert
2019-09-06 10:29   ` [Virtio-fs] " Stefan Hajnoczi
2019-09-06 10:29     ` [Qemu-devel] " Stefan Hajnoczi
2019-09-06 10:35     ` [Virtio-fs] " Dr. David Alan Gilbert
2019-09-06 10:35       ` [Qemu-devel] " Dr. David Alan Gilbert
2019-09-06 11:03     ` [Virtio-fs] " Daniel P. Berrangé
2019-09-06 11:03       ` Daniel P. Berrangé
2019-09-06 10:47 ` [Virtio-fs] " Daniel P. Berrangé
2019-09-06 10:47   ` Daniel P. Berrangé
2019-09-09 12:37 ` [Virtio-fs] " Stefan Hajnoczi
2019-09-09 12:37   ` [Qemu-devel] " Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190905171248.GP2700@work-vm \
    --to=dgilbert@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=virtio-fs@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.