Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=60c26b020f5... Commit: 60c26b020f55e079add1f461897b8f8d36b4e769 Parent: 3c2f9a8bf7a03cec32a1e11792a7dc493fb4917b Author: Andrew Price anprice@redhat.com AuthorDate: Mon Feb 23 17:36:12 2015 +0000 Committer: Andrew Price anprice@redhat.com CommitterDate: Mon Feb 23 18:40:57 2015 +0000
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@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 */
cluster-commits@lists.fedorahosted.org