X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2F9p.c;h=550516eba34833d0b4ea89a816a7a4c87f2e1309;hp=bc95803524a97fb2f19fe6fca5cf7f695ad2c5b8;hb=19005b2cfc6b077aafd16cb5b97a08180e4e39f8;hpb=5f10c3350338bbca735a74db26f98da968957bd9 diff --git a/daemon/9p.c b/daemon/9p.c index bc95803..550516e 100644 --- a/daemon/9p.c +++ b/daemon/9p.c @@ -82,7 +82,6 @@ do_list_9p (void) if (add_string (&r, &size, &alloc, mount_tag) == -1) { free (mount_tag); - free_stringslen (r, size); closedir (dir); return NULL; } @@ -168,3 +167,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; +}