Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src - if perfused is not already started (cannot connect to /dev...
details: https://anonhg.NetBSD.org/src/rev/9fdeade322c2
branches: trunk
changeset: 757382:9fdeade322c2
user: manu <manu%NetBSD.org@localhost>
date: Fri Aug 27 09:58:17 2010 +0000
description:
- if perfused is not already started (cannot connect to /dev/fuse),
FUSE filesystems will attempt to start it on their own, and will
communicate using a socketpair
- do not advertise NULL file handle as being valid when sending themback to the FUSE filesystem.
- unmount if we cannot talk to the FUSE process anymore
- set calling process gid properly
- debug message cleanup
diffstat:
lib/libperfuse/ops.c | 7 ++-
lib/libperfuse/perfuse.c | 79 ++++++++++++++++++++++++++++++++++--------
lib/libperfuse/perfuse_if.h | 4 +-
lib/libperfuse/perfuse_priv.h | 6 +--
usr.sbin/perfused/msg.c | 32 ++++++++++++++++-
usr.sbin/perfused/perfused.8 | 12 +++++-
usr.sbin/perfused/perfused.c | 77 +++++++++++++++++++++++++----------------
usr.sbin/perfused/perfused.h | 3 +-
8 files changed, 163 insertions(+), 57 deletions(-)
diffs (truncated from 515 to 300 lines):
diff -r daf4d061fe09 -r 9fdeade322c2 lib/libperfuse/ops.c
--- a/lib/libperfuse/ops.c Fri Aug 27 09:56:40 2010 +0000
+++ b/lib/libperfuse/ops.c Fri Aug 27 09:58:17 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ops.c,v 1.2 2010/08/26 13:29:01 manu Exp $ */
+/* $NetBSD: ops.c,v 1.3 2010/08/27 09:58:17 manu Exp $ */
/*-
* Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -667,7 +667,7 @@
svfsb->f_fsidx.__fsid_val[1] = 0;
svfsb->f_fsid = ps->ps_fsid;
svfsb->f_namemax = MAXPATHLEN; /* XXX */
- svfsb->f_owner = ps->ps_uid;
+ svfsb->f_owner = ps->ps_owner_uid;
(void)strlcpy(svfsb->f_mntonname, ps->ps_target, _VFS_NAMELEN);
@@ -1206,7 +1206,8 @@
if (PERFUSE_NODE_DATA(opc)->pnd_flags & PND_OPEN) {
fh = perfuse_get_fh(opc);
fsi->fh = fh;
- fsi->valid |= FUSE_FATTR_FH;
+ if (fh != FUSE_UNKNOWN_FH)
+ fsi->valid |= FUSE_FATTR_FH;
}
if (vap->va_size != (u_quad_t)PUFFS_VNOVAL) {
diff -r daf4d061fe09 -r 9fdeade322c2 lib/libperfuse/perfuse.c
--- a/lib/libperfuse/perfuse.c Fri Aug 27 09:56:40 2010 +0000
+++ b/lib/libperfuse/perfuse.c Fri Aug 27 09:58:17 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: perfuse.c,v 1.1 2010/08/25 07:16:00 manu Exp $ */
+/* $NetBSD: perfuse.c,v 1.2 2010/08/27 09:58:17 manu Exp $ */
/*-
* Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -101,16 +101,21 @@
int flags;
mode_t mode;
{
- int s;
+ int sv[2];
struct sockaddr_un sun;
struct sockaddr *sa;
+ char progname[] = _PATH_PERFUSED;
+ char minus_i[] = "-i";
+ char fdstr[16];
+ char *const argv[] = { progname, minus_i, fdstr, NULL};
+ char *const envp[] = { NULL };
if (strcmp(path, _PATH_FUSE) != 0)
return open(path, flags, mode);
- if ((s = socket(PF_LOCAL, SOCK_STREAM, 0)) == -1) {
+ if ((sv[0] = socket(PF_LOCAL, SOCK_STREAM, 0)) == -1) {
#ifdef PERFUSE_DEBUG
- printf("%s:%d socket failed: %s",
+ printf("%s:%d socket failed: %s\n",
__func__, __LINE__, strerror(errno));
#endif
return -1;
@@ -121,16 +126,49 @@
sun.sun_family = AF_LOCAL;
(void)strcpy(sun.sun_path, path);
- if (connect(s, sa, (socklen_t)sun.sun_len) == -1) {
+ if (connect(sv[0], sa, (socklen_t)sun.sun_len) == 0)
+ return sv[0];
+
+
+ /*
+ * Attempt to run perfused on our own
+ * if it does not run yet; In that case
+ * we will talk using a socketpair
+ * instead of /dev/fuse.
+ */
+ if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) != 0) {
#ifdef PERFUSE_DEBUG
- printf("%s:%d connect failed: %s",
+ printf("%s:%d: socketpair failed: %s\n",
__func__, __LINE__, strerror(errno));
#endif
- close(s);
return -1;
}
- return s;
+ (void)sprintf(fdstr, "%d", sv[1]);
+
+ switch(fork()) {
+ case -1:
+#ifdef PERFUSE_DEBUG
+ printf("%s:%d: fork failed: %s\n",
+ __func__, __LINE__, strerror(errno));
+#endif
+ return -1;
+ /* NOTREACHED */
+ break;
+ case 0:
+ (void)execve(argv[0], argv, envp);
+#ifdef PERFUSE_DEBUG
+ printf("%s:%d: execve failed: %s\n",
+ __func__, __LINE__, strerror(errno));
+#endif
+ return -1;
+ /* NOTREACHED */
+ break;
+ default:
+ break;
+ }
+
+ return sv[0];
}
@@ -188,7 +226,7 @@
if (write(s, &pmo, sizeof(pmo)) != sizeof(pmo)) {
#ifdef PERFUSE_DEBUG
- printf("%s:%d short write", __func__, __LINE__);
+ printf("%s:%d short write\n", __func__, __LINE__);
#endif
return -1;
}
@@ -197,7 +235,7 @@
len = pmo.pmo_source_len;
if (write(s, source, len) != (ssize_t)len) {
#ifdef PERFUSE_DEBUG
- printf("%s:%d short write", __func__, __LINE__);
+ printf("%s:%d short write\n", __func__, __LINE__);
#endif
return -1;
}
@@ -207,7 +245,7 @@
len = pmo.pmo_target_len;
if (write(s, target, len) != (ssize_t)len) {
#ifdef PERFUSE_DEBUG
- printf("%s:%d short write", __func__, __LINE__);
+ printf("%s:%d short write\n", __func__, __LINE__);
#endif
return -1;
}
@@ -217,7 +255,7 @@
len = pmo.pmo_filesystemtype_len;
if (write(s, filesystemtype, len) != (ssize_t)len) {
#ifdef PERFUSE_DEBUG
- printf("%s:%d short write", __func__, __LINE__);
+ printf("%s:%d short write\n", __func__, __LINE__);
#endif
return -1;
}
@@ -227,7 +265,7 @@
len = pmo.pmo_data_len;
if (write(s, data, len) != (ssize_t)len) {
#ifdef PERFUSE_DEBUG
- printf("%s:%d short write", __func__, __LINE__);
+ printf("%s:%d short write\n", __func__, __LINE__);
#endif
return -1;
}
@@ -262,7 +300,7 @@
struct puffs_pathobj *po_root;
ps = init_state();
- ps->ps_uid = pmi->pmi_uid;
+ ps->ps_owner_uid = pmi->pmi_uid;
if (pmi->pmi_source)
ps->ps_source = strdup(pmi->pmi_source);
@@ -274,7 +312,7 @@
/*
* Some options are forbidden for non root users
*/
- if (ps->ps_uid != 0)
+ if (ps->ps_owner_uid != 0)
ps->ps_mountflags |= MNT_NOSUID|MNT_NODEV;
PUFFSOP_INIT(pops);
@@ -414,3 +452,14 @@
{
return PERFUSE_NODE_DATA(opc)->pnd_ino;
}
+
+int
+perfuse_unmount(pu)
+ struct puffs_usermount *pu;
+{
+ struct perfuse_state *ps;
+
+ ps = puffs_getspecific(pu);
+
+ return unmount(ps->ps_target, MNT_FORCE);
+}
diff -r daf4d061fe09 -r 9fdeade322c2 lib/libperfuse/perfuse_if.h
--- a/lib/libperfuse/perfuse_if.h Fri Aug 27 09:56:40 2010 +0000
+++ b/lib/libperfuse/perfuse_if.h Fri Aug 27 09:58:17 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: perfuse_if.h,v 1.2 2010/08/26 13:29:01 manu Exp $ */
+/* $NetBSD: perfuse_if.h,v 1.3 2010/08/27 09:58:17 manu Exp $ */
/*-
* Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -29,6 +29,7 @@
#define _REFUSE_PERFUSE_H
#define _PATH_FUSE "/dev/fuse"
+#define _PATH_PERFUSED "/usr/sbin/perfused"
#define FUSE_COMMFD_ENV "_FUSE_COMMFD"
#define PERFUSE_MOUNT_MAGIC "noFuseRq"
#define PERFUSE_UNKNOWN_INO 0xffffffff
@@ -201,5 +202,6 @@
const char *perfuse_opname(int);
void perfuse_fs_init(struct puffs_usermount *);
int perfuse_mainloop(struct puffs_usermount *);
+int perfuse_unmount(struct puffs_usermount *);
#endif /* _REFUSE_PERFUSE_H */
diff -r daf4d061fe09 -r 9fdeade322c2 lib/libperfuse/perfuse_priv.h
--- a/lib/libperfuse/perfuse_priv.h Fri Aug 27 09:56:40 2010 +0000
+++ b/lib/libperfuse/perfuse_priv.h Fri Aug 27 09:58:17 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: perfuse_priv.h,v 1.2 2010/08/26 13:29:01 manu Exp $ */
+/* $NetBSD: perfuse_priv.h,v 1.3 2010/08/27 09:58:17 manu Exp $ */
/*-
* Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -41,9 +41,7 @@
void *ps_private; /* Private field for libperfuse user */
struct puffs_usermount *ps_pu;
struct puffs_node *ps_root;
- uid_t ps_uid;
- gid_t ps_gid;
- pid_t ps_pid;
+ uid_t ps_owner_uid;
int ps_flags;
#define PS_NO_ACCESS 0x0001 /* access is unimplemented; */
#define PS_NO_FSYNC 0x0002 /* fsync is unimplemented */
diff -r daf4d061fe09 -r 9fdeade322c2 usr.sbin/perfused/msg.c
--- a/usr.sbin/perfused/msg.c Fri Aug 27 09:56:40 2010 +0000
+++ b/usr.sbin/perfused/msg.c Fri Aug 27 09:58:17 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg.c,v 1.1 2010/08/25 07:18:01 manu Exp $ */
+/* $NetBSD: msg.c,v 1.2 2010/08/27 09:58:17 manu Exp $ */
/*-
* Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -137,7 +137,7 @@
fih->pid = 0;
if (cred != NULL) {
(void)puffs_cred_getuid(cred, &fih->uid);
- (void)puffs_cred_getuid(cred, &fih->uid);
+ (void)puffs_cred_getgid(cred, &fih->gid);
}
if ((pcc = puffs_cc_getcc(pu)) != NULL)
(void)puffs_cc_getcaller(pcc, (pid_t *)&fih->pid, NULL);
@@ -597,3 +597,31 @@
return;
}
+void
+perfuse_fdnotify(pu, fd, what)
+ struct puffs_usermount *pu;
+ int fd;
+ int what;
+{
+ if (fd != (int)perfuse_getspecific(pu))
+ DERRX(EX_SOFTWARE, "%s: unexpected notification for fd = %d",
+ __func__, fd);
+
+ if ((what != PUFFS_FBIO_READ) && (what != PUFFS_FBIO_WRITE))
+ DERRX(EX_SOFTWARE, "%s: unexpected notification what = 0x%x",
+ __func__, what);
+
+ if (perfuse_unmount(pu) != 0)
+ DWARN("unmount() failed");
+
+ if (shutdown(fd, SHUT_RDWR) != 0)
+ DWARN("shutdown() failed");
+
+ if (perfuse_diagflags & PDF_MISC)
+ DPRINTF("Exit");
+
+ exit(0);
+
+ /* NOTREACHED */
+ return;
+}
diff -r daf4d061fe09 -r 9fdeade322c2 usr.sbin/perfused/perfused.8
--- a/usr.sbin/perfused/perfused.8 Fri Aug 27 09:56:40 2010 +0000
+++ b/usr.sbin/perfused/perfused.8 Fri Aug 27 09:58:17 2010 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: perfused.8,v 1.2 2010/08/26 13:29:02 manu Exp $
+.\" $NetBSD: perfused.8,v 1.3 2010/08/27 09:58:17 manu Exp $
.\"
.\" Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
.\"
@@ -34,6 +34,7 @@
.Op Fl f
.Op Fl d Ar types
Home |
Main Index |
Thread Index |
Old Index