From: Richard W.M. Jones Date: Wed, 22 Jun 2011 12:55:14 +0000 (+0100) Subject: New API: mount-9p lets you mount 9p filesystems (RHBZ#714981). X-Git-Tag: 1.11.12~9 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=14bb3b5ae75f41af05ca6d26ebbb5e85aacf2e20;p=libguestfs.git New API: mount-9p lets you mount 9p filesystems (RHBZ#714981). The updated patch makes 'options' into an optional parameter. --- diff --git a/daemon/9p.c b/daemon/9p.c index bc95803..9e89e08 100644 --- a/daemon/9p.c +++ b/daemon/9p.c @@ -168,3 +168,60 @@ read_whole_file (const char *filename) return r; } + +/* Takes optional arguments, consult optargs_bitmask. */ +int +do_mount_9p (const char *mount_tag, const char *mountpoint, const char *options) +{ + 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 ((optargs_bitmask & GUESTFS_MOUNT_9P_OPTIONS_BITMASK) && + STRNEQ (options, "")) { + if (asprintf (&opts, "trans=virtio,%s", options) == -1) { + reply_with_perror ("asprintf"); + goto out; + } + } + else { + opts = strdup ("trans=virtio"); + if (opts == NULL) { + reply_with_perror ("strdup"); + 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..9130034 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 "mounttag"; String "mountpoint"], [String "options"]), 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 optional C +parameter."); + ] 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