All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 5/5] gfs2_grow/jadd: Use a matching context mount option in mount_gfs2_meta
Date: Mon, 23 Feb 2015 18:43:26 +0000	[thread overview]
Message-ID: <1424717006-20839-5-git-send-email-anprice@redhat.com> (raw)
In-Reply-To: <1424717006-20839-1-git-send-email-anprice@redhat.com>

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@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 */
-- 
1.9.3



  parent reply	other threads:[~2015-02-23 18:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-23 18:43 [Cluster-devel] [PATCH 1/5] fsck.gfs2: Fix memory leaks in pass1_process_rgrp Andrew Price
2015-02-23 18:43 ` [Cluster-devel] [PATCH 2/5] libgfs2: Use the correct parent for rgrp tree insertion Andrew Price
2015-02-23 18:43 ` [Cluster-devel] [PATCH 3/5] libgfs2: Remove some obsolete function declarations Andrew Price
2015-02-23 18:43 ` [Cluster-devel] [PATCH 4/5] gfs2-utils: Move metafs handling into gfs2/mkfs/ Andrew Price
2015-02-23 18:43 ` Andrew Price [this message]
2015-02-23 19:17 ` [Cluster-devel] [PATCH 1/5] fsck.gfs2: Fix memory leaks in pass1_process_rgrp Bob Peterson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1424717006-20839-5-git-send-email-anprice@redhat.com \
    --to=anprice@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.