gfs2-utils: RHEL7 - gfs2_grow/jadd: Use a matching context mount option in mount_gfs2_meta

Andrew Price andyp at fedoraproject.org
Tue Apr 7 21:24:14 UTC 2015


Gitweb:        http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=554ab685599e08d0543d218d529dbb0925040b95
Commit:        554ab685599e08d0543d218d529dbb0925040b95
Parent:        439b337f0ce36cf960b2331e6fa7f000120a3f01
Author:        Andrew Price <anprice at redhat.com>
AuthorDate:    Mon Feb 23 17:36:12 2015 +0000
Committer:     Andrew Price <anprice at redhat.com>
CommitterDate: Wed Apr 1 16:51:35 2015 +0100

gfs2_grow/jadd: Use a matching context mount option in mount_gfs2_meta

On a system with SELinux enabled, if a gfs2 file system is mounted with
a context= option, the tools gfs2_grow and gfs2_jadd will fail with
"Invalid argument". This is due to SELinux failing the mount due to an
mismatched context ("SELinux: mount invalid.  Same superblock, different
security settings").

In order to work around this, parse the context option of the mntent
relating to the gfs2 mount point and use it in mount_gfs2_meta().

Signed-off-by: Andrew Price <anprice at redhat.com>
---
 gfs2/mkfs/main_grow.c |    1 +
 gfs2/mkfs/main_jadd.c |    2 +-
 gfs2/mkfs/metafs.c    |   23 ++++++++++++++++++++++-
 gfs2/mkfs/metafs.h    |    2 ++
 4 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index c3ae4b7..6ba14b0 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -396,6 +396,7 @@ int main(int argc, char *argv[])
 			exit(EXIT_FAILURE);
 		}
 		fix_device_geometry(sdp);
+		mfs.context = copy_context_opt(mnt);
 		if (mount_gfs2_meta(&mfs, mnt->mnt_dir, (print_level > MSG_NOTICE))) {
 			perror(_("Failed to mount GFS2 meta file system"));
 			exit(EXIT_FAILURE);
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index d83ec2b..9190d44 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -520,7 +520,7 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 	}
 	gather_info(sdp, &opts);
-
+	mfs.context = copy_context_opt(mnt);
 	if (mount_gfs2_meta(&mfs, mnt->mnt_dir, opts.debug)) {
 		perror("GFS2 metafs");
 		exit(EXIT_FAILURE);
diff --git a/gfs2/mkfs/metafs.c b/gfs2/mkfs/metafs.c
index 12b1cdb..112ce2d 100644
--- a/gfs2/mkfs/metafs.c
+++ b/gfs2/mkfs/metafs.c
@@ -9,6 +9,7 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <signal.h>
+#include <mntent.h>
 #include <libintl.h>
 #include <locale.h>
 #define _(String) gettext(String)
@@ -70,7 +71,7 @@ int mount_gfs2_meta(struct metafs *mfs, const char *path, int debug)
 
 	setsigs(sighandler);
 
-	ret = mount(path, mfs->path, "gfs2meta", 0, NULL);
+	ret = mount(path, mfs->path, "gfs2meta", 0, mfs->context);
 	if (ret)
 		goto err_rmdir;
 
@@ -115,4 +116,24 @@ void cleanup_metafs(struct metafs *mfs)
 
 	free(mfs->path);
 	mfs->path = NULL;
+	free(mfs->context);
+	mfs->context = NULL;
+}
+
+/**
+ * Returns a duplicate of the 'context' mount option, or NULL if not found.
+ */
+char *copy_context_opt(struct mntent *mnt)
+{
+	char *ctx, *end;
+
+	ctx = hasmntopt(mnt, "context");
+	if (ctx == NULL)
+		return NULL;
+
+	end = strchr(ctx, ',');
+	if (end == NULL)
+		return NULL;
+
+	return strndup(ctx, end - ctx);
 }
diff --git a/gfs2/mkfs/metafs.h b/gfs2/mkfs/metafs.h
index a765634..1372977 100644
--- a/gfs2/mkfs/metafs.h
+++ b/gfs2/mkfs/metafs.h
@@ -6,9 +6,11 @@ extern int metafs_interrupted;
 struct metafs {
 	int fd;
 	char *path;
+	char *context; /* 'context=' mount option */
 };
 
 extern int mount_gfs2_meta(struct metafs *mfs, const char *path, int debug);
 extern void cleanup_metafs(struct metafs *mfs);
+extern char *copy_context_opt(struct mntent *mnt);
 
 #endif /* METAFS_H */


More information about the cluster-commits mailing list