Blame SOURCES/0008-New-API-remount-Allow-rw-flag-to-be-adjusted-on-moun.patch

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