:17 GMT Expires: Thu, 27 Dec 2035 22:15:17 GMT ETag: "1edde86014a7d724e22708aef075ea40c7e23004" /* FUSE: Filesystem in Userspace Copyright (C) 2001-2007 Miklos Szeredi Copyright (c) 2010 Gluster, Inc. This program can be distributed under the terms of the GNU LGPLv2. See the file COPYING.LIB. */ #include "mount_util.h" #include "mount-gluster-compat.h" #ifdef GF_FUSERMOUNT #define FUSERMOUNT_PROG FUSERMOUNT_DIR "/fusermount-glusterfs" #else #define FUSERMOUNT_PROG "fusermount" #endif #define FUSE_DEVFD_ENV "_FUSE_DEVFD" #ifdef __FreeBSD__ #include #include #include #endif /* __FreeBSD__ */ /* FUSE: function is called fuse_kern_unmount() */ void gf_fuse_unmount (const char *mountpoint, int fd) { int res; int pid; if (!mountpoint) return; if (fd != -1) { struct pollfd pfd; pfd.fd = fd; pfd.events = 0; res = poll (&pfd, 1, 0); /* If file poll returns POLLERR on the device file descriptor, then the filesystem is already unmounted */ if (res == 1 && (pfd.revents & POLLERR)) return; /* Need to close file descriptor, otherwise synchronous umount would recurse into filesystem, and deadlock */ close (fd); } if (geteuid () == 0) { fuse_mnt_umount ("fuse", mountpoint, mountpoint, 1); return; } res = umount2 (mountpoint, 2); if (res == 0) return; pid = fork (); if (pid == -1) return; if (pid == 0) { const char *argv[] = { FUSERMOUNT_PROG, "-u", "-q", "-z", "--", mountpoint, NULL }; execvp (FUSERMOUNT_PROG, (char **)argv); _exit (1); } waitpid (pid, NULL, 0); } /* gluster-specific routines */ static char * escape (char *s) { size_t len = 0; char *p = NULL; char *q = NULL; char *e = NULL; for (p = s; *p; p++) { if (*p == ',') len++; len++; } e = CALLOC (1, len + 1); if (!e) return NULL; for (p = s, q = e; *p; p++, q++) { if (*p == ',') { *q = '\\'; q++; } *q = *p; } return e; } static int fuse_mount_fusermount (const char *mountpoint, char *fsname, unsigned long mountflags, char *mnt_param, int fd) { int pid = -1; int res = 0; int ret = -1; char *fm_mnt_params = NULL; char *efsname = NULL; #ifndef GF_FUSERMOUNT GFFUSE_LOGERR ("Mounting via helper utility " "(unprivileged mounting) is supported " "only if glusterfs is compiled with " "--enable-fusermount"); return -1; #endif efsname = escape (fsname); if (!efsname) { GFFUSE_LOGERR ("Out of memory"); return -1; } ret = asprintf (&fm_mnt_params, "%s%s,fsname=%s,nonempty,subtype=glusterfs", (mountflags & MS_RDONLY) ? "ro," : "", mnt_param, efsname); FREE (efsname); if (ret == -1) { GFFUSE_LOGERR ("Out of memory"); goto out; } /* fork to exec fusermount */ pid = fork