mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone
Blob Blame History Raw
From 511c8f0f0d3b51ce3cf37d344566f0a6b2051a21 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Fri, 31 May 2013 14:36:08 +0100
Subject: [PATCH] New API: remount: Allow rw flag to be adjusted on mounted
 filesystem.

(cherry picked from commit 2019d0e9c7cd4b927cb98fe96d97e945dd4847e0)
---
 daemon/mount.c       | 35 +++++++++++++++++++++++++++++++++++
 generator/actions.ml | 22 ++++++++++++++++++++++
 gobject/Makefile.inc |  6 ++++--
 po/POTFILES          |  1 +
 4 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/daemon/mount.c b/daemon/mount.c
index b89bb88..0ad9995 100644
--- a/daemon/mount.c
+++ b/daemon/mount.c
@@ -458,6 +458,41 @@ do_mount_loop (const char *file, const char *mountpoint)
   return 0;
 }
 
+/* Takes optional arguments, consult optargs_bitmask. */
+int
+do_remount (const char *mountpoint, int rw)
+{
+  CLEANUP_FREE char *mp = NULL, *err = NULL;
+  const char *options;
+  int r;
+
+  /* In future we'll allow other flags / parameters to be adjusted.
+   * For now we just have to check rw was passed, but in future it
+   * will genuinely be an optional argument.
+   */
+  if (!(optargs_bitmask & GUESTFS_REMOUNT_RW_BITMASK)) {
+    reply_with_error ("parameter 'rw' must be specified");
+    return -1;
+  }
+  options = rw ? "remount,rw" : "remount,ro";
+
+  mp = sysroot_path (mountpoint);
+  if (!mp) {
+    reply_with_perror ("malloc");
+    return -1;
+  }
+
+  /* XXX Do we need to check the mountpoint exists? */
+
+  r = command (NULL, &err, str_mount, "-o", options, mp, NULL);
+  if (r == -1) {
+    reply_with_error ("%s: %s: %s", mountpoint, options, err);
+    return -1;
+  }
+
+  return 0;
+}
+
 /* Specialized calls mkmountpoint and rmmountpoint are really
  * variations on mkdir and rmdir which do no checking of the
  * is_root_mounted() flag.
diff --git a/generator/actions.ml b/generator/actions.ml
index 3b6e098..302d61b 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -11302,6 +11302,28 @@ the target filesystem does not support it (primarily when
 writing to DOS FAT filesystems)." };
 
   { defaults with
+    name = "remount";
+    style = RErr, [Pathname "mountpoint"], [OBool "rw"];
+    proc_nr = Some 402;
+    tests = [
+      InitScratchFS, Always, TestLastFail (
+        [["remount"; "/"; "false"];
+         ["write"; "/remount1"; "data"]]), [];
+      InitScratchFS, Always, TestRun (
+        [["remount"; "/"; "false"];
+         ["remount"; "/"; "true"];
+         ["write"; "/remount2"; "data"]]), []
+    ];
+    shortdesc = "remount a filesystem with different options";
+    longdesc = "\
+This call allows you to change the C<rw> (readonly/read-write)
+flag on an already mounted filesystem at C<mountpoint>,
+converting a readonly filesystem to be read-write, or vice-versa.
+
+Note that at the moment you must supply the \"optional\" C<rw>
+parameter.  In future we may allow other flags to be adjusted." };
+
+  { defaults with
     name = "set_uuid";
     style = RErr, [Device "device"; String "uuid"], [];
     proc_nr = Some 403;
diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc
index 17da527..19c771f 100644
--- a/gobject/Makefile.inc
+++ b/gobject/Makefile.inc
@@ -91,7 +91,8 @@ guestfs_gobject_headers= \
   include/guestfs-gobject/optargs-xfs_repair.h \
   include/guestfs-gobject/optargs-mke2fs.h \
   include/guestfs-gobject/optargs-mktemp.h \
-  include/guestfs-gobject/optargs-syslinux.h
+  include/guestfs-gobject/optargs-syslinux.h \
+  include/guestfs-gobject/optargs-remount.h
 
 guestfs_gobject_sources= \
   src/session.c \
@@ -164,4 +165,5 @@ guestfs_gobject_sources= \
   src/optargs-xfs_repair.c \
   src/optargs-mke2fs.c \
   src/optargs-mktemp.c \
-  src/optargs-syslinux.c
+  src/optargs-syslinux.c \
+  src/optargs-remount.c
diff --git a/po/POTFILES b/po/POTFILES
index a88707a..53b660d 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -185,6 +185,7 @@ gobject/src/optargs-mount_local.c
 gobject/src/optargs-ntfsclone_out.c
 gobject/src/optargs-ntfsfix.c
 gobject/src/optargs-ntfsresize.c
+gobject/src/optargs-remount.c
 gobject/src/optargs-rsync.c
 gobject/src/optargs-rsync_in.c
 gobject/src/optargs-rsync_out.c
-- 
1.8.3.1