summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
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), "