New API: mount-9p lets you mount 9p filesystems (RHBZ#714981).
authorRichard W.M. Jones <rjones@redhat.com>
Wed, 22 Jun 2011 12:55:14 +0000 (13:55 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Wed, 22 Jun 2011 14:24:05 +0000 (15:24 +0100)
The updated patch makes 'options' into an optional parameter.

daemon/9p.c
generator/generator_actions.ml
src/MAX_PROC_NR

index bc95803..9e89e08 100644 (file)
@@ -168,3 +168,60 @@ read_whole_file (const char *filename)
 
   return r;
 }
 
   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;
+}
index 634ceeb..9130034 100644 (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.");
 
 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
 ]
 
 let all_functions = non_daemon_functions @ daemon_functions
index 6cf4452..c20f657 100644 (file)
@@ -1 +1 @@
-285
+286