diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2011-06-22 13:55:14 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2011-06-22 15:24:05 +0100 |
commit | 14bb3b5ae75f41af05ca6d26ebbb5e85aacf2e20 (patch) | |
tree | 3983965987dcccec2d9eb91494eb31c867f231bb /daemon/9p.c | |
parent | 5f10c3350338bbca735a74db26f98da968957bd9 (diff) | |
download | libguestfs-14bb3b5ae75f41af05ca6d26ebbb5e85aacf2e20.tar.gz libguestfs-14bb3b5ae75f41af05ca6d26ebbb5e85aacf2e20.tar.xz libguestfs-14bb3b5ae75f41af05ca6d26ebbb5e85aacf2e20.zip |
New API: mount-9p lets you mount 9p filesystems (RHBZ#714981).
The updated patch makes 'options' into an optional parameter.
Diffstat (limited to 'daemon/9p.c')
-rw-r--r-- | daemon/9p.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/daemon/9p.c b/daemon/9p.c index bc958035..9e89e080 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; +} |