From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Price Date: Mon, 23 Feb 2015 18:43:26 +0000 Subject: [Cluster-devel] [PATCH 5/5] gfs2_grow/jadd: Use a matching context mount option in mount_gfs2_meta In-Reply-To: <1424717006-20839-1-git-send-email-anprice@redhat.com> References: <1424717006-20839-1-git-send-email-anprice@redhat.com> Message-ID: <1424717006-20839-5-git-send-email-anprice@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 --- 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 #include #include +#include #include #include #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