summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorCsaba Henk <csaba@redhat.com>2012-05-24 12:25:43 +0530
committerVijay Bellur <vijay@gluster.com>2012-05-27 09:55:05 -0700
commit507a4ebb6ca3704e1a6ee3d1b6511b58ed9f6ba7 (patch)
tree95bc6433f94b7504206ad618cd51d3a457345039 /contrib
parent994c56a185d1f3e0f0f40f4051f82cdf2c7905b9 (diff)
fuse: allow requests during mount (needed for SELinux labels)
Resurrecting Jeff's commit: commit 7d0397c2144810c8a396e00187a6617873c94002 Author: Jeff Darcy <jdarcy@redhat.com> fuse: allow requests during mount (needed for SELinux labels) that was reverted as of: commit 4ab1c326f3862714b960302f06c6323d6291b695 Author: Vijay Bellur <vijay@gluster.com> Revert "fuse: allow requests during mount (needed for SELinux labels)" BUG: 811217 Change-Id: Ia1af402897e6a7290acf79617c34fdc804751729 Signed-off-by: Csaba Henk <csaba@redhat.com> Reviewed-on: http://review.gluster.com/3452 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'contrib')
-rw-r--r--contrib/fuse-include/fuse-mount.h2
-rw-r--r--contrib/fuse-lib/mount.c60
2 files changed, 51 insertions, 11 deletions
diff --git a/contrib/fuse-include/fuse-mount.h b/contrib/fuse-include/fuse-mount.h
index 9f83faf02a0..7a3756d92b8 100644
--- a/contrib/fuse-include/fuse-mount.h
+++ b/contrib/fuse-include/fuse-mount.h
@@ -9,4 +9,4 @@
void gf_fuse_unmount (const char *mountpoint, int fd);
int gf_fuse_mount (const char *mountpoint, char *fsname, char *mnt_param,
- pid_t *mtab_pid);
+ pid_t *mtab_pid, int status_fd);
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), "