diff options
author | Harshavardhana <harsha@harshavardhana.net> | 2014-06-21 02:00:23 -0700 |
---|---|---|
committer | Harshavardhana <harsha@harshavardhana.net> | 2014-07-02 17:20:34 -0700 |
commit | 1b74cf992986287a510fe3b28a8ee7554e8b0992 (patch) | |
tree | a5fad911274080947f5874b4d90cc4f67b6f4473 /contrib/fuse-lib | |
parent | e4a3566681acbadfe0f7bd879443116885ada4eb (diff) |
porting: Port for FreeBSD rebased from Mike Ma's efforts
- Provides a working Gluster Management Daemon, CLI
- Provides a working GlusterFS server, GlusterNFS server
- Provides a working GlusterFS client
- execinfo port from FreeBSD is moved into ./contrib/libexecinfo
for ease of portability on NetBSD. (FreeBSD 10 and OSX provide
execinfo natively)
- More portability cleanups for Darwin, FreeBSD and NetBSD
- Provides a new rc script for FreeBSD
Change-Id: I8dff336f97479ca5a7f9b8c6b730051c0f8ac46f
BUG: 1111774
Original-Author: Mike Ma <mikemandarine@gmail.com>
Signed-off-by: Harshavardhana <harsha@harshavardhana.net>
Reviewed-on: http://review.gluster.org/8141
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Diffstat (limited to 'contrib/fuse-lib')
-rw-r--r-- | contrib/fuse-lib/mount-common.c | 15 | ||||
-rw-r--r-- | contrib/fuse-lib/mount-gluster-compat.h | 11 | ||||
-rw-r--r-- | contrib/fuse-lib/mount.c | 87 |
3 files changed, 96 insertions, 17 deletions
diff --git a/contrib/fuse-lib/mount-common.c b/contrib/fuse-lib/mount-common.c index fd6cce44e3d..cd226fa3141 100644 --- a/contrib/fuse-lib/mount-common.c +++ b/contrib/fuse-lib/mount-common.c @@ -23,7 +23,7 @@ * see the commit log and per-function comments. */ -#ifndef __NetBSD__ +#ifdef GF_LINUX_HOST_OS /* FUSE: cherry-picked bd99f9cf */ static int mtab_needs_update (const char *mnt) @@ -69,9 +69,9 @@ mtab_needs_update (const char *mnt) return 1; } -#else /* __NetBSD__ */ +#else /* GF_LINUX_HOST_OS */ #define mtab_needs_update(x) 1 -#endif /* __NetBSD__ */ +#endif /* GF_LINUX_HOST_OS */ /* FUSE: called add_mount_legacy(); R.I.P. as of cbd3a2a8 */ int @@ -246,10 +246,17 @@ fuse_mnt_umount (const char *progname, const char *abs_mnt, if (res == 0) { sigprocmask (SIG_SETMASK, &oldmask, NULL); setuid (geteuid ()); +#ifdef GF_LINUX_HOST_OS execl ("/bin/umount", "/bin/umount", "-i", rel_mnt, - lazy ? "-l" : NULL, NULL); + lazy ? "-l" : NULL, NULL); GFFUSE_LOGERR ("%s: failed to execute /bin/umount: %s", progname, strerror (errno)); +#else + execl ("/sbin/umount", "/sbin/umount", rel_mnt, + lazy ? "-l" : NULL, NULL); + GFFUSE_LOGERR ("%s: failed to execute /sbin/umount: %s", + progname, strerror (errno)); +#endif /* GF_LINUX_HOST_OS */ exit (1); } res = waitpid (res, &status, 0); diff --git a/contrib/fuse-lib/mount-gluster-compat.h b/contrib/fuse-lib/mount-gluster-compat.h index 1f76241ab1c..562f089dd1f 100644 --- a/contrib/fuse-lib/mount-gluster-compat.h +++ b/contrib/fuse-lib/mount-gluster-compat.h @@ -21,32 +21,31 @@ #include <errno.h> #include <dirent.h> #include <signal.h> -#if !defined(__NetBSD__) && !defined(GF_DARWIN_HOST_OS) +#if defined(GF_LINUX_HOST_OS) #include <mntent.h> -#endif /* __NetBSD__ */ +#endif /* GF_LINUX_HOST_OS */ #include <sys/stat.h> #include <sys/poll.h> #include <sys/un.h> #include <sys/wait.h> #include <sys/mount.h> -#ifdef __NetBSD__ +#if defined(__NetBSD__) #include <perfuse.h> #define umount2(dir, flags) unmount(dir, ((flags) != 0) ? MNT_FORCE : 0) #define MS_RDONLY MNT_RDONLY #endif -#ifdef GF_DARWIN_HOST_OS +#if defined(GF_DARWIN_HOST_OS) || defined(__FreeBSD__) #include <sys/param.h> #include <sys/mount.h> #define umount2(dir, flags) unmount(dir, ((flags) != 0) ? MNT_FORCE : 0) #define MS_RDONLY MNT_RDONLY #endif - #ifdef GF_LINUX_HOST_OS #define _PATH_MOUNT "/bin/mount" -#else /* NetBSD, MacOS X */ +#else /* FreeBSD, NetBSD, MacOS X */ #define _PATH_MOUNT "/sbin/mount" #endif diff --git a/contrib/fuse-lib/mount.c b/contrib/fuse-lib/mount.c index 922d9e464db..a7fd94de464 100644 --- a/contrib/fuse-lib/mount.c +++ b/contrib/fuse-lib/mount.c @@ -17,6 +17,11 @@ #endif #define FUSE_DEVFD_ENV "_FUSE_DEVFD" +#ifdef __FreeBSD__ +#include <sys/types.h> +#include <sys/uio.h> +#include <unistd.h> +#endif /* __FreeBSD__ */ /* FUSE: function is called fuse_kern_unmount() */ void @@ -170,6 +175,55 @@ fuse_mount_fusermount (const char *mountpoint, char *fsname, return ret; } +#if defined(__FreeBSD__) +void +build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, + size_t len) +{ + int i; + if (*iovlen < 0) + return; + i = *iovlen; + + *iov = realloc(*iov, sizeof **iov * (i + 2)); + if (*iov == NULL) { + *iovlen = -1; + return; + } + + (*iov)[i].iov_base = strdup(name); + (*iov)[i].iov_len = strlen(name) + 1; + + i++; + (*iov)[i].iov_base = val; + if (len == (size_t) -1) { + if (val != NULL) + len = strlen(val) + 1; + else + len = 0; + } + (*iov)[i].iov_len = (int)len; + *iovlen = ++i; +} + +/* + * This function is needed for compatibility with parameters + * which used to use the mount_argf() command for the old mount() syscall. + */ +void +build_iovec_argf(struct iovec **iov, int *iovlen, const char *name, + const char *fmt, ...) +{ + va_list ap; + char val[255] = { 0 }; + + va_start(ap, fmt); + vsnprintf(val, sizeof(val), fmt, ap); + va_end(ap); + build_iovec(iov, iovlen, name, strdup(val), (size_t)-1); +} +#endif /* __FreeBSD__ */ + static int fuse_mount_sys (const char *mountpoint, char *fsname, unsigned long mountflags, char *mnt_param, int fd) @@ -188,8 +242,24 @@ fuse_mount_sys (const char *mountpoint, char *fsname, goto out; } + +#ifdef __FreeBSD__ + struct iovec *iov = NULL; + int iovlen = 0; + build_iovec (&iov, &iovlen, "fstype", "fusefs", -1); + build_iovec (&iov, &iovlen, "subtype", "glusterfs", -1); + build_iovec (&iov, &iovlen, "fspath", mountpoint, -1); + build_iovec (&iov, &iovlen, "from", "/dev/fuse", -1); + build_iovec (&iov, &iovlen, "volname", source, -1); + build_iovec_argf (&iov, &iovlen, "fd", "%d", fd); + build_iovec_argf (&iov, &iovlen, "user_id", "%d", getuid()); + build_iovec_argf (&iov, &iovlen, "group_id", "%d", getgid()); + ret = nmount (iov, iovlen, mountflags); +#else ret = mount (source, mountpoint, fstype, mountflags, mnt_param_mnt); +#endif /* __FreeBSD__ */ +#ifdef GF_LINUX_HOST_OS if (ret == -1 && errno == ENODEV) { /* fs subtype support was added by 79c0b2df aka v2.6.21-3159-g79c0b2d. Probably we have an @@ -204,12 +274,13 @@ fuse_mount_sys (const char *mountpoint, char *fsname, ret = mount (source, mountpoint, fstype, mountflags, mnt_param_mnt); } +#endif /* GF_LINUX_HOST_OS */ if (ret == -1) goto out; else mounted = 1; -#ifndef __NetBSD__ +#ifdef GF_LINUX_HOST_OS if (geteuid () == 0) { char *newmnt = fuse_mnt_resolve_path ("fuse", mountpoint); char *mnt_param_mtab = NULL; @@ -238,10 +309,11 @@ fuse_mount_sys (const char *mountpoint, char *fsname, goto out; } } -#endif /* __NetBSD__ */ +#endif /* GF_LINUX_HOST_OS */ out: if (ret == -1) { + GFFUSE_LOGERR("ret = -1\n"); if (mounted) umount2 (mountpoint, 2); /* lazy umount */ } @@ -282,15 +354,16 @@ gf_fuse_mount (const char *mountpoint, char *fsname, exit (pid == -1 ? 1 : 0); } - ret = fuse_mount_sys (mountpoint, fsname, mountflags, 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), " + "direct mount failed (%s) errno %d, " "retry to mount via fusermount", - strerror (errno)); + strerror (errno), errno); - ret = fuse_mount_fusermount (mountpoint, fsname, mountflags, - mnt_param, fd); + ret = fuse_mount_fusermount (mountpoint, fsname, + mountflags, mnt_param, fd); } if (ret == -1) |