From: Nan Li <nli@suse.com>
To: qemu-devel@nongnu.org
Cc: ptesarik@suse.com, Nan Li <nli@suse.com>
Subject: [Qemu-devel] [PATCH 2/2] Dump: add command "fuse-mount"
Date: Sun, 8 May 2016 07:32:48 +0800 [thread overview]
Message-ID: <1462663968-26607-3-git-send-email-nli@suse.com> (raw)
In-Reply-To: <1462663968-26607-1-git-send-email-nli@suse.com>
Add a "fuse-mount" command to support the Filesystem in Userspace (FUSE).
It can mount or unmount the filesystem with both hmp and qmp commands.
It calls the API function qemu_fuse_main(int argc, char *argv[]).
Signed-off-by: Nan Li <nli@suse.com>
---
dump.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
hmp-commands.hx | 19 +++++++++++++++++++
hmp.c | 12 ++++++++++++
hmp.h | 1 +
qapi-schema.json | 15 +++++++++++++++
qmp-commands.hx | 31 +++++++++++++++++++++++++++++++
6 files changed, 126 insertions(+)
diff --git a/dump.c b/dump.c
index 9726f1f..7599f06 100644
--- a/dump.c
+++ b/dump.c
@@ -26,6 +26,10 @@
#include "qapi/qmp/qerror.h"
#include "qmp-commands.h"
#include "qapi-event.h"
+#ifdef CONFIG_FUSE
+#include <sys/mount.h>
+#include "fuse-mem.h"
+#endif
#include <zlib.h>
#ifdef CONFIG_LZO
@@ -1846,3 +1850,47 @@ DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability(Error **errp)
return cap;
}
+
+#ifdef CONFIG_FUSE
+static void *fuse_process(void *data)
+{
+ pid_t pid;
+ int argc = 2;
+ char *argv[2];
+ char programname[] = "fuse-mount-process";
+ argv[0] = programname;
+ argv[1] = (char *)data;
+ int ret;
+
+ if ((pid = fork()) < 0)
+ perror("fork() is failed");
+ else if (pid == 0) {
+ ret = qemu_fuse_main(argc, argv);
+ if ( ret != 0 )
+ perror("qemu_fuse_main() is failed");
+ exit(0);
+ }
+ return NULL;
+}
+
+void qmp_fuse_mount(bool unmount, const char *mountpoint, Error **errp)
+{
+ int ret;
+
+ if (unmount) {
+ ret = umount(mountpoint);
+ if (ret < 0) {
+ error_setg(errp, "umount() is failed");
+ }
+ return;
+ }
+
+ char * prot = g_strdup(mountpoint);
+ fuse_process((void *)prot);
+}
+#else
+void qmp_fuse_mount(bool unmount, const char *mountpoint, Error **errp)
+{
+ abort();
+}
+#endif
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 4f4f60a..746db0c 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1087,6 +1087,25 @@ gdb. Without -z|-l|-s, the dump format is ELF.
together with begin.
ETEXI
+#if defined(CONFIG_FUSE)
+ {
+ .name = "fuse-mount",
+ .args_type = "unmount:-u,mountpoint:s",
+ .params = "[-u] mountpoint",
+ .help = "mount(unmount) fuse system on 'mountpoint'.\n\t\t\t"
+ "-u: unmount.",
+ .mhandler.cmd = hmp_fuse_mount,
+ },
+
+STEXI
+@item fuse-mount [-u] @var{mountpoint}
+@findex fuse-mount
+Mount(unmount) fuse system to @var{mountpoint}.
+ -u: unmount.
+ mountpoint: the mount point (a path) of fuse system.
+ETEXI
+#endif
+
#if defined(TARGET_S390X)
{
.name = "dump-skeys",
diff --git a/hmp.c b/hmp.c
index d510236..884e8a3 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1643,6 +1643,18 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
g_free(prot);
}
+#ifdef CONFIG_FUSE
+void hmp_fuse_mount(Monitor *mon, const QDict *qdict)
+{
+ Error *err = NULL;
+ bool unmount = qdict_get_try_bool(qdict, "unmount", false);
+ const char *mountpoint = qdict_get_str(qdict, "mountpoint");
+
+ qmp_fuse_mount(unmount, mountpoint, &err);
+ hmp_handle_error(mon, &err);
+}
+#endif
+
void hmp_netdev_add(Monitor *mon, const QDict *qdict)
{
Error *err = NULL;
diff --git a/hmp.h b/hmp.h
index 093d65f..f183fe9 100644
--- a/hmp.h
+++ b/hmp.h
@@ -85,6 +85,7 @@ void hmp_migrate(Monitor *mon, const QDict *qdict);
void hmp_device_add(Monitor *mon, const QDict *qdict);
void hmp_device_del(Monitor *mon, const QDict *qdict);
void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict);
+void hmp_fuse_mount(Monitor *mon, const QDict *qdict);
void hmp_netdev_add(Monitor *mon, const QDict *qdict);
void hmp_netdev_del(Monitor *mon, const QDict *qdict);
void hmp_getfd(Monitor *mon, const QDict *qdict);
diff --git a/qapi-schema.json b/qapi-schema.json
index e58f6a9..d268019 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2283,6 +2283,21 @@
'returns': 'DumpGuestMemoryCapability' }
##
+# @fuse-mount:
+#
+# mount(unmount) fuse system on 'mountpoint'.
+#
+# @is_mount: optional if true, umount the fuse system from the mount point
+#
+# @mountpoint: the mount point (a path) of fuse system
+#
+# Returns: Nothing on success
+#
+# Since: 2.6
+##
+{ 'command': 'fuse-mount', 'data': {'unmount': 'bool', 'mountpoint': 'str'} }
+
+##
# @dump-skeys
#
# Dump guest's storage keys
diff --git a/qmp-commands.hx b/qmp-commands.hx
index de896a5..efcf6c1 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -921,6 +921,37 @@ Example:
EQMP
+#if defined(CONFIG_FUSE)
+ {
+ .name = "fuse-mount",
+ .args_type = "unmount:b,mountpoint:s",
+ .params = "[-u] mountpoint",
+ .help = "mount(unmount) fuse system on 'mountpoint'.\n\t\t\t"
+ "-u: unmount.",
+ .mhandler.cmd_new = qmp_marshal_fuse_mount,
+ },
+SQMP
+fuse-mount
+
+mount(unmount) fuse system on 'mountpoint'.
+
+Arguments:
+
+- "unmount": unmount the fuse system (json-bool)
+- "mountpoint": the mount point (a path) of fuse system (json-string)
+
+Example:
+
+-> { "execute": "fuse-mount", "arguments": { "mountpoint": "/etc/qemu/fuse" } }
+<- { "return": {} }
+
+Notes:
+
+(1) All boolean arguments default to false
+
+EQMP
+#endif
+
#if defined TARGET_S390X
{
.name = "dump-skeys",
--
1.8.4.5
next prev parent reply other threads:[~2016-05-09 9:18 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-07 23:32 [Qemu-devel] [PATCH 0/2] Dump: add a Filesystem in Userspace and command "fuse-mount" Nan Li
2016-05-07 23:32 ` [Qemu-devel] [PATCH 1/2] Dump: introduce a Filesystem in Userspace Nan Li
2016-05-09 15:52 ` Eric Blake
2016-05-09 16:13 ` Daniel P. Berrange
2016-05-09 16:20 ` Petr Tesarik
2016-05-09 16:32 ` Daniel P. Berrange
2016-05-10 6:19 ` Petr Tesarik
2016-05-10 8:39 ` Daniel P. Berrange
2016-05-10 5:59 ` Petr Tesarik
2016-05-10 8:48 ` Daniel P. Berrange
2016-05-10 9:42 ` Petr Tesarik
2016-05-10 11:26 ` Nan Li
2016-05-10 9:56 ` Stefan Hajnoczi
2016-05-10 11:02 ` Nan Li
2016-05-10 11:55 ` Petr Tesarik
2016-05-12 10:09 ` Stefan Hajnoczi
2016-05-12 10:30 ` Petr Tesarik
2016-05-07 23:32 ` Nan Li [this message]
2016-05-09 16:30 ` [Qemu-devel] [PATCH 2/2] Dump: add command "fuse-mount" Daniel P. Berrange
2016-05-09 16:48 ` Eric Blake
2016-05-10 11:32 ` Nan Li
2016-05-10 9:47 ` [Qemu-devel] [PATCH 0/2] Dump: add a Filesystem in Userspace and " Stefan Hajnoczi
2016-05-10 9:50 ` 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=1462663968-26607-3-git-send-email-nli@suse.com \
--to=nli@suse.com \
--cc=ptesarik@suse.com \
--cc=qemu-devel@nongnu.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).