diff options
author | Niels de Vos <ndevos@redhat.com> | 2012-11-09 14:43:38 +0100 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2012-11-19 00:49:36 -0800 |
commit | 702b2912970e7cc19416aff7d3696d15977efc2f (patch) | |
tree | 7acc75db04d042f4178506c2b1d0c14ee1faac0d /contrib/fuse-lib | |
parent | 474d3e08313acb74633a22e970326fb98b9122d3 (diff) |
fuse: handle mountflags properly
The internal mount API had no access to the generic
mountflags used by mount(2).
Thus the "ro" mount option that needs to be passed down to mount(2) as
as a mountflag was incorrectly mangled into the fuse-specific mount
parameter string (cf. http://review.gluster.com/655).
This commit fixes the internal API and the "ro" issue. It also adds a
check for the "rw" and "ro" mount options in tests/basic/mount.t.
Thanks to Csaba Henk (csaba@) for suggestions and proposing an updated
patch.
Change-Id: I7f7bf49ae44d148f5c16f10736a0e412fb8f5e67
BUG: 853895
Signed-off-by: Niels de Vos <ndevos@redhat.com>
Reviewed-on: http://review.gluster.org/4163
Reviewed-by: Csaba Henk <csaba@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'contrib/fuse-lib')
-rw-r--r-- | contrib/fuse-lib/mount.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/contrib/fuse-lib/mount.c b/contrib/fuse-lib/mount.c index f02a835b3a8..fedde3fceea 100644 --- a/contrib/fuse-lib/mount.c +++ b/contrib/fuse-lib/mount.c @@ -100,7 +100,8 @@ escape (char *s) } static int -fuse_mount_fusermount (const char *mountpoint, char *fsname, char *mnt_param, +fuse_mount_fusermount (const char *mountpoint, char *fsname, + unsigned long mountflags, char *mnt_param, int fd) { int pid = -1; @@ -124,7 +125,8 @@ fuse_mount_fusermount (const char *mountpoint, char *fsname, char *mnt_param, return -1; } ret = asprintf (&fm_mnt_params, - "%s,fsname=%s,nonempty,subtype=glusterfs", + "%s%s,fsname=%s,nonempty,subtype=glusterfs", + (mountflags & MS_RDONLY) ? "ro," : "", mnt_param, efsname); FREE (efsname); if (ret == -1) { @@ -169,7 +171,8 @@ fuse_mount_fusermount (const char *mountpoint, char *fsname, char *mnt_param, } static int -fuse_mount_sys (const char *mountpoint, char *fsname, char *mnt_param, int fd) +fuse_mount_sys (const char *mountpoint, char *fsname, + unsigned long mountflags, char *mnt_param, int fd) { int ret = -1; unsigned mounted = 0; @@ -185,7 +188,7 @@ fuse_mount_sys (const char *mountpoint, char *fsname, char *mnt_param, int fd) goto out; } - ret = mount (source, mountpoint, fstype, 0, + ret = mount (source, mountpoint, fstype, mountflags, mnt_param_mnt); if (ret == -1 && errno == ENODEV) { /* fs subtype support was added by 79c0b2df aka @@ -209,6 +212,7 @@ fuse_mount_sys (const char *mountpoint, char *fsname, char *mnt_param, int fd) #ifndef __NetBSD__ if (geteuid () == 0) { char *newmnt = fuse_mnt_resolve_path ("fuse", mountpoint); + char *mnt_param_mtab = NULL; if (!newmnt) { ret = -1; @@ -216,8 +220,17 @@ fuse_mount_sys (const char *mountpoint, char *fsname, char *mnt_param, int fd) goto out; } - ret = fuse_mnt_add_mount ("fuse", source, newmnt, fstype, - mnt_param); + ret = asprintf (&mnt_param_mtab, "%s%s", + mountflags & MS_RDONLY ? "ro," : "", + mnt_param); + if (ret == -1) + GFFUSE_LOGERR ("Out of memory"); + else { + ret = fuse_mnt_add_mount ("fuse", source, newmnt, + fstype, mnt_param_mtab); + FREE (mnt_param_mtab); + } + FREE (newmnt); if (ret == -1) { GFFUSE_LOGERR ("failed to add mtab entry"); @@ -240,7 +253,8 @@ out: } int -gf_fuse_mount (const char *mountpoint, char *fsname, char *mnt_param, +gf_fuse_mount (const char *mountpoint, char *fsname, + unsigned long mountflags, char *mnt_param, pid_t *mnt_pid, int status_fd) { int fd = -1; @@ -268,14 +282,14 @@ gf_fuse_mount (const char *mountpoint, char *fsname, char *mnt_param, exit (pid == -1 ? 1 : 0); } - ret = fuse_mount_sys (mountpoint, fsname, mnt_param, fd); + ret = fuse_mount_sys (mountpoint, fsname, mountflags, mnt_param, fd); if (ret == -1) { gf_log ("glusterfs-fuse", GF_LOG_INFO, "direct mount failed (%s), " "retry to mount via fusermount", strerror (errno)); - ret = fuse_mount_fusermount (mountpoint, fsname, + ret = fuse_mount_fusermount (mountpoint, fsname, mountflags, mnt_param, fd); } |