>From dd422b9797b2b73764bb04ec46aebbf7b08cb9d8 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 22 Jun 2011 13:55:14 +0100 Subject: [PATCH 2/2] New API: mount-9p lets you mount 9p filesystems (RHBZ#714981). --- daemon/9p.c | 55 ++++++++++++++++++++++++++++++++++++++++ generator/generator_actions.ml | 11 ++++++++ src/MAX_PROC_NR | 2 +- 3 files changed, 67 insertions(+), 1 deletions(-) diff --git a/daemon/9p.c b/daemon/9p.c index bc95803..27b2230 100644 --- a/daemon/9p.c +++ b/daemon/9p.c @@ -168,3 +168,58 @@ read_whole_file (const char *filename) return r; } + +int +do_mount_9p (const char *options, const char *mount_tag, const char *mountpoint) +{ + char *mp = NULL, *opts = NULL, *err = NULL; + struct stat statbuf; + int r = -1; + + ABS_PATH (mountpoint, , return -1); + + mp = sysroot_path (mountpoint); + if (!mp) { + reply_with_perror ("malloc"); + goto out; + } + + /* Check the mountpoint exists and is a directory. */ + if (stat (mp, &statbuf) == -1) { + reply_with_perror ("%s", mountpoint); + goto out; + } + if (!S_ISDIR (statbuf.st_mode)) { + reply_with_perror ("%s: mount point is not a directory", mountpoint); + goto out; + } + + /* Add trans=virtio to the options. */ + if (STREQ (options, "")) { + opts = strdup ("trans=virtio"); + if (opts == NULL) { + reply_with_perror ("strdup"); + goto out; + } + } + else { + if (asprintf (&opts, "trans=virtio,%s", options) == -1) { + reply_with_perror ("asprintf"); + goto out; + } + } + + r = command (NULL, &err, + "mount", "-o", opts, "-t", "9p", mount_tag, mp, NULL); + if (r == -1) { + reply_with_error ("%s on %s: %s", mount_tag, mountpoint, err); + goto out; + } + + r = 0; + out: + free (err); + free (opts); + free (mp); + return r; +} diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index 634ceeb..27a02d0 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -5967,6 +5967,17 @@ Note that for large devices this can take a long time to run."); List all 9p filesystems attached to the guest. A list of mount tags is returned."); + ("mount_9p", (RErr, [String "options"; String "mounttag"; String "mountpoint"], []), 286, [], + [], + "mount 9p filesystem", + "\ +Mount the virtio-9p filesystem with the tag C on the +directory C. + +If required, C will be automatically added to the options. +Any other options required can be passed in the C parameter, +or this can be left as an empty string."); + ] let all_functions = non_daemon_functions @ daemon_functions diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 6cf4452..c20f657 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -285 +286 -- 1.7.5.2