diff options
author | Jeff Darcy <jdarcy@redhat.com> | 2012-04-23 11:51:22 -0400 |
---|---|---|
committer | Anand Avati <avati@redhat.com> | 2012-04-23 14:37:24 -0700 |
commit | 7d0397c2144810c8a396e00187a6617873c94002 (patch) | |
tree | 8b9739cd2fda0237be2cbfc68de0eeb0760cd52a /contrib/fuse-lib/mount.c | |
parent | eb9003cdca755980da9ed5a3a3fb0fc52c750131 (diff) |
fuse: allow requests during mount (needed for SELinux labels)
Change-Id: Ia1af402897e6a7290acf79617c34fdc804751729
BUG: 811217
Signed-off-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-on: http://review.gluster.com/3199
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'contrib/fuse-lib/mount.c')
-rw-r--r-- | contrib/fuse-lib/mount.c | 60 |
1 files changed, 50 insertions, 10 deletions
diff --git a/contrib/fuse-lib/mount.c b/contrib/fuse-lib/mount.c index 800fd193e6c..8c5da3d619f 100644 --- a/contrib/fuse-lib/mount.c +++ b/contrib/fuse-lib/mount.c @@ -544,19 +544,25 @@ gf_fuse_unmount (const char *mountpoint, int fd) #ifndef FUSE_UTIL static int -fuse_mount_sys (const char *mountpoint, char *fsname, char *mnt_param, pid_t *mtab_pid) +fuse_mount_sys (const char *mountpoint, char *fsname, char *mnt_param, pid_t *mtab_pid, int in_fd, int status_fd) { int fd = -1, ret = -1; unsigned mounted = 0; char *mnt_param_mnt = NULL; char *fstype = "fuse.glusterfs"; char *source = fsname; + pid_t mypid = -1; - fd = open ("/dev/fuse", O_RDWR); - if (fd == -1) { - GFFUSE_LOGERR ("cannot open /dev/fuse (%s)", strerror (errno)); - - return -1; + if (in_fd >= 0) { + fd = in_fd; + } + else { + fd = open ("/dev/fuse", O_RDWR); + if (fd == -1) { + GFFUSE_LOGERR ("cannot open /dev/fuse (%s)", + strerror (errno)); + return -1; + } } ret = asprintf (&mnt_param_mnt, @@ -567,8 +573,14 @@ fuse_mount_sys (const char *mountpoint, char *fsname, char *mnt_param, pid_t *mt goto out; } + ret = fork(); + if (ret != 0) { + goto parent_out; + } + GFFUSE_LOGERR("calling mount"); ret = mount (source, mountpoint, fstype, 0, mnt_param_mnt); + GFFUSE_LOGERR("mount returned %d",ret); if (ret == -1 && errno == ENODEV) { /* fs subtype support was added by 79c0b2df aka v2.6.21-3159-g79c0b2d. Probably we have an @@ -607,11 +619,31 @@ fuse_mount_sys (const char *mountpoint, char *fsname, char *mnt_param, pid_t *mt } } - out: + ret = 0; +out: + if (status_fd >= 0) { + GFFUSE_LOGERR("writing status"); + (void)write(status_fd,&ret,sizeof(ret)); + mypid = getpid(); + /* + * This seems awkward, but the alternative would be to add + * or change return values for functions in multiple layers, + * just so they can store the value for later retrieval by + * the code already running in the right context at the other + * end of this pipe. That's a lot of disruption for nothing. + */ + (void)write(status_fd,&mypid,sizeof(mypid)); + } + GFFUSE_LOGERR("Mount child exiting"); + exit(0); + +parent_out: if (ret == -1) { if (mounted) umount2 (mountpoint, 2); /* lazy umount */ - close (fd); + if (fd != in_fd) { + close (fd); + } fd = -1; } FREE (mnt_param_mnt); @@ -651,13 +683,21 @@ escape (char *s) int gf_fuse_mount (const char *mountpoint, char *fsname, char *mnt_param, - pid_t *mtab_pid) + pid_t *mtab_pid, int status_fd) { int fd = -1, rv = -1; char *fm_mnt_params = NULL, *p = NULL; char *efsname = NULL; - fd = fuse_mount_sys (mountpoint, fsname, mnt_param, mtab_pid); + fd = open ("/dev/fuse", O_RDWR); + if (fd == -1) { + GFFUSE_LOGERR ("cannot open /dev/fuse (%s)", + strerror (errno)); + return -1; + } + + fd = fuse_mount_sys (mountpoint, fsname, mnt_param, mtab_pid, fd, + status_fd); if (fd == -1) { gf_log ("glusterfs-fuse", GF_LOG_INFO, "direct mount failed (%s), " |