New API: mount-9p lets you mount 9p filesystems (RHBZ#714981).

The updated patch makes 'options' into an optional parameter.
This commit is contained in:
Richard W.M. Jones
2011-06-22 13:55:14 +01:00
parent 5f10c33503
commit 14bb3b5ae7
3 changed files with 69 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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<mounttag> on the
directory C<mountpoint>.
If required, C<trans=virtio> will be automatically added to the options.
Any other options required can be passed in the optional C<options>
parameter.");
]
let all_functions = non_daemon_functions @ daemon_functions

View File

@@ -1 +1 @@
285
286