summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Szeredi <miklos@szeredi.hu>2008-12-08 19:26:53 +0000
committerMiklos Szeredi <miklos@szeredi.hu>2008-12-08 19:26:53 +0000
commit5f722fa8f6561c964fd0bd651b4602ac0f7bc3b4 (patch)
tree47a21b51e3d8319b1c929c461a4934d62134164d
parentecfa5263ab5b19a58d53a7116fb079f3b956b918 (diff)
downloadfuse-5f722fa8f6561c964fd0bd651b4602ac0f7bc3b4.tar.gz
* Implement poll support. Patch by Tejun Heo
-rw-r--r--ChangeLog4
-rw-r--r--example/.cvsignore2
-rw-r--r--example/Makefile.am6
-rw-r--r--example/fsel.c276
-rw-r--r--example/fselclient.c72
-rw-r--r--include/fuse.h26
-rw-r--r--include/fuse_common.h8
-rw-r--r--include/fuse_kernel.h31
-rw-r--r--include/fuse_lowlevel.h52
-rw-r--r--lib/fuse.c51
-rw-r--r--lib/fuse_lowlevel.c86
-rw-r--r--lib/fuse_versionscript5
12 files changed, 616 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 5220ff5..8b3a9c7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-12-08 Miklos Szeredi <miklos@szeredi.hu>
+
+ * Implement poll support. Patch by Tejun Heo
+
2008-12-05 Miklos Szeredi <miklos@szeredi.hu>
* Implement ioctl support. On high level interface only
diff --git a/example/.cvsignore b/example/.cvsignore
index 7332bc0..af7dd99 100644
--- a/example/.cvsignore
+++ b/example/.cvsignore
@@ -8,4 +8,6 @@ hello
hello_ll
fioc
fioclient
+fsel
+fselclient
.libs
diff --git a/example/Makefile.am b/example/Makefile.am
index 43b195d..1aa5774 100644
--- a/example/Makefile.am
+++ b/example/Makefile.am
@@ -2,7 +2,8 @@
AM_CPPFLAGS = -I$(top_srcdir)/include -D_FILE_OFFSET_BITS=64 -D_REENTRANT
noinst_HEADERS = fioc.h
-noinst_PROGRAMS = fusexmp fusexmp_fh null hello hello_ll fioc fioclient
+noinst_PROGRAMS = fusexmp fusexmp_fh null hello hello_ll fioc fioclient \
+ fsel fselclient
LDADD = ../lib/libfuse.la @libfuse_libs@
fusexmp_fh_LDADD = ../lib/libfuse.la ../lib/libulockmgr.la @libfuse_libs@
@@ -10,4 +11,7 @@ fusexmp_fh_LDADD = ../lib/libfuse.la ../lib/libulockmgr.la @libfuse_libs@
fioclient_CPPFLAGS =
fioclient_LDFLAGS =
fioclient_LDADD =
+fselclient_CPPFLAGS =
+fselclient_LDFLAGS =
+fselclient_LDADD =
diff --git a/example/fsel.c b/example/fsel.c
new file mode 100644
index 0000000..a3c0c68
--- /dev/null
+++ b/example/fsel.c
@@ -0,0 +1,276 @@
+/*
+ FUSE fsel: FUSE select example
+ Copyright (C) 2008 SUSE Linux Products GmbH
+ Copyright (C) 2008 Tejun Heo <teheo@suse.de>
+
+ This program can be distributed under the terms of the GNU GPL.
+ See the file COPYING.
+
+ gcc -Wall `pkg-config fuse --cflags --libs` fsel.c -o fsel
+*/
+
+#define FUSE_USE_VERSION 29
+
+#include <fuse.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <time.h>
+#include <pthread.h>
+#include <poll.h>
+
+/*
+ * fsel_open_mask is used to limit the number of opens to 1 per file.
+ * This is to use file index (0-F) as fh as poll support requires
+ * unique fh per open file. Lifting this would require proper open
+ * file management.
+ */
+static unsigned fsel_open_mask;
+static const char fsel_hex_map[] = "0123456789ABCDEF";
+static struct fuse *fsel_fuse; /* needed for poll notification */
+
+#define FSEL_CNT_MAX 10 /* each file can store upto 10 chars */
+#define FSEL_FILES 16
+
+static pthread_mutex_t fsel_mutex; /* protects notify_mask and cnt array */
+static unsigned fsel_poll_notify_mask; /* poll notification scheduled? */
+static struct fuse_pollhandle *fsel_poll_handle[FSEL_FILES]; /* poll notify handles */
+static unsigned fsel_cnt[FSEL_FILES]; /* nbytes stored in each file */
+
+static int fsel_path_index(const char *path)
+{
+ char ch = path[1];
+
+ if (strlen(path) != 2 || path[0] != '/' || !isxdigit(ch) || islower(ch))
+ return -1;
+ return ch <= '9' ? ch - '0' : ch - 'A' + 10;
+}
+
+static int fsel_getattr(const char *path, struct stat *stbuf)
+{
+ int idx;
+
+ memset(stbuf, 0, sizeof(struct stat));
+
+ if (strcmp(path, "/") == 0) {
+ stbuf->st_mode = S_IFDIR | 0555;
+ stbuf->st_nlink = 2;
+ return 0;
+ }
+
+ idx = fsel_path_index(path);
+ if (idx < 0)
+ return -ENOENT;
+
+ stbuf->st_mode = S_IFREG | 0444;
+ stbuf->st_nlink = 1;
+ stbuf->st_size = fsel_cnt[idx];
+ return 0;
+}
+
+static int fsel_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
+ off_t offset, struct fuse_file_info *fi)
+{
+ char name[2] = { };
+ int i;
+
+ (void) offset;
+ (void) fi;
+
+ if (strcmp(path, "/") != 0)
+ return -ENOENT;
+
+ for (i = 0; i < FSEL_FILES; i++) {
+ name[0] = fsel_hex_map[i];
+ filler(buf, name, NULL, 0);
+ }
+
+ return 0;
+}
+
+static int fsel_open(const char *path, struct fuse_file_info *fi)
+{
+ int idx = fsel_path_index(path);
+
+ if (idx < 0)
+ return -ENOENT;
+ if ((fi->flags & 3) != O_RDONLY)
+ return -EACCES;
+ if (fsel_open_mask & (1 << idx))
+ return -EBUSY;
+ fsel_open_mask |= (1 << idx);
+
+ /*
+ * fsel files are nonseekable somewhat pipe-like files which
+ * gets filled up periodically by producer thread and consumed
+ * on read. Tell FUSE as such.
+ */
+ fi->fh = idx;
+ fi->direct_io = 1;
+ fi->nonseekable = 1;
+
+ return 0;
+}
+
+static int fsel_release(const char *path, struct fuse_file_info *fi)
+{
+ int idx = fi->fh;
+
+ (void) path;
+
+ fsel_open_mask &= ~(1 << idx);
+ return 0;
+}
+
+static int fsel_read(const char *path, char *buf, size_t size, off_t offset,
+ struct fuse_file_info *fi)
+{
+ int idx = fi->fh;
+
+ (void) path;
+ (void) offset;
+
+ pthread_mutex_lock(&fsel_mutex);
+ if (fsel_cnt[idx] < size)
+ size = fsel_cnt[idx];
+ printf("READ %X transferred=%zu cnt=%u\n", idx, size, fsel_cnt[idx]);
+ fsel_cnt[idx] -= size;
+ pthread_mutex_unlock(&fsel_mutex);
+
+ memset(buf, fsel_hex_map[idx], size);
+ return size;
+}
+
+static int fsel_poll(const char *path, struct fuse_file_info *fi,
+ struct fuse_pollhandle *ph, unsigned *reventsp)
+{
+ static unsigned polled_zero;
+ int idx = fi->fh;
+
+ (void) path;
+
+ /*
+ * Poll notification requires pointer to struct fuse which
+ * can't be obtained when using fuse_main(). As notification
+ * happens only after poll is called, fill it here from
+ * fuse_context.
+ */
+ if (!fsel_fuse) {
+ struct fuse_context *cxt = fuse_get_context();
+ if (cxt)
+ fsel_fuse = cxt->fuse;
+ }
+
+ pthread_mutex_lock(&fsel_mutex);
+
+ if (ph != NULL) {
+ struct fuse_pollhandle *oldph = fsel_poll_handle[idx];
+
+ if (oldph)
+ fuse_pollhandle_destroy(oldph);
+
+ fsel_poll_notify_mask |= (1 << idx);
+ fsel_poll_handle[idx] = ph;
+ }
+
+ if (fsel_cnt[idx]) {
+ *reventsp |= POLLIN;
+ printf("POLL %X cnt=%u polled_zero=%u\n",
+ idx, fsel_cnt[idx], polled_zero);
+ polled_zero = 0;
+ } else
+ polled_zero++;
+
+ pthread_mutex_unlock(&fsel_mutex);
+ return 0;
+}
+
+static struct fuse_operations fsel_oper = {
+ .getattr = fsel_getattr,
+ .readdir = fsel_readdir,
+ .open = fsel_open,
+ .release = fsel_release,
+ .read = fsel_read,
+ .poll = fsel_poll,
+};
+
+static void *fsel_producer(void *data)
+{
+ const struct timespec interval = { 0, 250000000 };
+ unsigned idx = 0, nr = 1;
+
+ (void) data;
+
+ while (1) {
+ int i, t;
+
+ pthread_mutex_lock(&fsel_mutex);
+
+ /*
+ * This is the main producer loop which is executed
+ * ever 500ms. On each iteration, it fills one byte
+ * to 1, 2 or 4 files and sends poll notification if
+ * requested.
+ */
+ for (i = 0, t = idx; i < nr;
+ i++, t = (t + FSEL_FILES / nr) % FSEL_FILES) {
+ if (fsel_cnt[t] == FSEL_CNT_MAX)
+ continue;
+
+ fsel_cnt[t]++;
+ if (fsel_fuse && (fsel_poll_notify_mask & (1 << t))) {
+ struct fuse_pollhandle *ph;
+
+ printf("NOTIFY %X\n", t);
+ ph = fsel_poll_handle[t];
+ fuse_notify_poll(ph);
+ fuse_pollhandle_destroy(ph);
+ fsel_poll_notify_mask &= ~(1 << t);
+ fsel_poll_handle[t] = NULL;
+ }
+ }
+
+ idx = (idx + 1) % FSEL_FILES;
+ if (idx == 0)
+ nr = (nr * 2) % 7; /* cycle through 1, 2 and 4 */
+
+ pthread_mutex_unlock(&fsel_mutex);
+
+ nanosleep(&interval, NULL);
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ pthread_t producer;
+ pthread_attr_t attr;
+ int ret;
+
+ errno = pthread_mutex_init(&fsel_mutex, NULL);
+ if (errno) {
+ perror("pthread_mutex_init");
+ return 1;
+ }
+
+ errno = pthread_attr_init(&attr);
+ if (errno) {
+ perror("pthread_attr_init");
+ return 1;
+ }
+
+ errno = pthread_create(&producer, &attr, fsel_producer, NULL);
+ if (errno) {
+ perror("pthread_create");
+ return 1;
+ }
+
+ ret = fuse_main(argc, argv, &fsel_oper, NULL);
+
+ pthread_cancel(producer);
+ pthread_join(producer, NULL);
+
+ return ret;
+}
diff --git a/example/fselclient.c b/example/fselclient.c
new file mode 100644
index 0000000..7c4b837
--- /dev/null
+++ b/example/fselclient.c
@@ -0,0 +1,72 @@
+/*
+ FUSE fselclient: FUSE select example client
+ Copyright (C) 2008 SUSE Linux Products GmbH
+ Copyright (C) 2008 Tejun Heo <teheo@suse.de>
+
+ This program can be distributed under the terms of the GNU GPL.
+ See the file COPYING.
+
+ gcc -Wall fselclient.c -o fselclient
+*/
+
+#include <sys/select.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#define FSEL_FILES 16
+
+int main(void)
+{
+ static const char hex_map[FSEL_FILES] = "0123456789ABCDEF";
+ int fds[FSEL_FILES];
+ int i, nfds;
+
+ for (i = 0; i < FSEL_FILES; i++) {
+ char name[] = { hex_map[i], '\0' };
+ fds[i] = open(name, O_RDONLY);
+ if (fds[i] < 0) {
+ perror("open");
+ return 1;
+ }
+ }
+ nfds = fds[FSEL_FILES - 1] + 1;
+
+ while (1) {
+ static char buf[4096];
+ fd_set rfds;
+ int rc;
+
+ FD_ZERO(&rfds);
+ for (i = 0; i < FSEL_FILES; i++)
+ FD_SET(fds[i], &rfds);
+
+ rc = select(nfds, &rfds, NULL, NULL, NULL);
+
+ if (rc < 0) {
+ perror("select");
+ return 1;
+ }
+
+ for (i = 0; i < FSEL_FILES; i++) {
+ if (!FD_ISSET(fds[i], &rfds)) {
+ printf("_: ");
+ continue;
+ }
+ printf("%X:", i);
+ rc = read(fds[i], buf, sizeof(buf));
+ if (rc < 0) {
+ perror("read");
+ return 1;
+ }
+ printf("%02d ", rc);
+ }
+ printf("\n");
+ }
+}
diff --git a/include/fuse.h b/include/fuse.h
index 2016ccc..e1b863c 100644
--- a/include/fuse.h
+++ b/include/fuse.h
@@ -469,11 +469,30 @@ struct fuse_operations {
* _IOC_READ in area and if both are set in/out area. In all
* non-NULL cases, the area is of _IOC_SIZE(@cmd) bytes.
*
- * Introduced in version 2.9
+ * Introduced in version 2.8
*/
int (*ioctl) (const char *, int cmd, void *arg,
struct fuse_file_info *, unsigned int flags, void *data);
+ /**
+ * Poll for IO readiness events
+ *
+ * Note: If @ph is non-NULL, the client should notify
+ * when IO readiness events occur by calling
+ * fuse_notify_poll() with the specified @ph.
+ *
+ * Regardless of the number of times poll with a non-NULL @ph
+ * is received, single notification is enough to clear all.
+ * Notifying more times incurs overhead but doesn't harm
+ * correctness.
+ *
+ * The callee is responsible for destroying @ph with
+ * fuse_pollhandle_destroy() when no longer in use.
+ *
+ * Introduced in version 2.8
+ */
+ int (*poll) (const char *, struct fuse_file_info *,
+ struct fuse_pollhandle *ph, unsigned *reventsp);
};
/** Extra context that may be needed by some filesystems
@@ -708,9 +727,14 @@ int fuse_fs_bmap(struct fuse_fs *fs, const char *path, size_t blocksize,
uint64_t *idx);
int fuse_fs_ioctl(struct fuse_fs *fs, const char *path, int cmd, void *arg,
struct fuse_file_info *fi, unsigned int flags, void *data);
+int fuse_fs_poll(struct fuse_fs *fs, const char *path,
+ struct fuse_file_info *fi, struct fuse_pollhandle *ph,
+ unsigned *reventsp);
void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn);
void fuse_fs_destroy(struct fuse_fs *fs);
+int fuse_notify_poll(struct fuse_pollhandle *ph);
+
/**
* Create a new fuse filesystem object
*
diff --git a/include/fuse_common.h b/include/fuse_common.h
index fb18b61..b05ed21 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -159,6 +159,7 @@ struct fuse_conn_info {
struct fuse_session;
struct fuse_chan;
+struct fuse_pollhandle;
/**
* Create a FUSE mountpoint
@@ -219,6 +220,13 @@ int fuse_daemonize(int foreground);
*/
int fuse_version(void);
+/**
+ * Destroy poll handle
+ *
+ * @param ph the poll handle
+ */
+void fuse_pollhandle_destroy(struct fuse_pollhandle *ph);
+
/* ----------------------------------------------------------- *
* Signal handling *
* ----------------------------------------------------------- */
diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index eb28a35..df558e3 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -49,6 +49,8 @@
*
* 7.11
* - add IOCTL message
+ * - add unsolicited notification support
+ * - add POLL message and NOTIFY_POLL notification
*/
#ifndef _LINUX_FUSE_H
@@ -191,6 +193,13 @@ struct fuse_file_lock {
#define FUSE_IOCTL_MAX_IOV 256
+/**
+ * Poll flags
+ *
+ * FUSE_POLL_SCHEDULE_NOTIFY: request poll notify
+ */
+#define FUSE_POLL_SCHEDULE_NOTIFY (1 << 0)
+
enum fuse_opcode {
FUSE_LOOKUP = 1,
FUSE_FORGET = 2, /* no reply */
@@ -229,6 +238,12 @@ enum fuse_opcode {
FUSE_BMAP = 37,
FUSE_DESTROY = 38,
FUSE_IOCTL = 39,
+ FUSE_POLL = 40,
+};
+
+enum fuse_notify_code {
+ FUSE_NOTIFY_POLL = 1,
+ FUSE_NOTIFY_CODE_MAX,
};
/* The read buffer is required to be at least 8k, but may be much larger */
@@ -445,6 +460,22 @@ struct fuse_ioctl_out {
__u32 out_iovs;
};
+struct fuse_poll_in {
+ __u64 fh;
+ __u64 kh;
+ __u32 flags;
+ __u32 padding;
+};
+
+struct fuse_poll_out {
+ __u32 revents;
+ __u32 padding;
+};
+
+struct fuse_notify_poll_wakeup_out {
+ __u64 kh;
+};
+
struct fuse_in_header {
__u32 len;
__u32 opcode;
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index e17274f..0b83214 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -817,7 +817,7 @@ struct fuse_lowlevel_ops {
* restricted ioctls, kernel prepares in/out data area
* according to the information encoded in @cmd.
*
- * Introduced in version 2.9
+ * Introduced in version 2.8
*
* Valid replies:
* fuse_reply_ioctl_retry
@@ -837,6 +837,35 @@ struct fuse_lowlevel_ops {
void (*ioctl) (fuse_req_t req, fuse_ino_t ino, int cmd, void *arg,
struct fuse_file_info *fi, unsigned *flagsp,
const void *in_buf, size_t in_bufsz, size_t out_bufszp);
+
+ /**
+ * Poll for IO readiness
+ *
+ * Introduced in version 2.8
+ *
+ * Note: If @ph is non-NULL, the client should notify
+ * when IO readiness events occur by calling
+ * fuse_lowelevel_notify_poll() with the specified @ph.
+ *
+ * Regardless of the number of times poll with a non-NULL @ph
+ * is received, single notification is enough to clear all.
+ * Notifying more times incurs overhead but doesn't harm
+ * correctness.
+ *
+ * The callee is responsible for destroying @ph with
+ * fuse_pollhandle_destroy() when no longer in use.
+ *
+ * Valid replies:
+ * fuse_reply_poll
+ * fuse_reply_err
+ *
+ * @param req request handle
+ * @param ino the inode number
+ * @param fi file information
+ * @param ph poll handle to be used for notification
+ */
+ void (*poll) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
+ struct fuse_pollhandle *ph);
};
/**
@@ -1084,6 +1113,27 @@ int fuse_reply_ioctl_retry(fuse_req_t req,
*/
int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size);
+/**
+ * Reply with poll result event mask
+ *
+ * @param req request handle
+ * @param revents poll result event mask
+ */
+int fuse_reply_poll(fuse_req_t req, unsigned revents);
+
+/* ----------------------------------------------------------- *
+ * Notification *
+ * ----------------------------------------------------------- */
+
+/**
+ * Notify IO readiness event
+ *
+ * For more information, please read comment for poll operation.
+ *
+ * @param ph poll handle to notify IO readiness event for
+ */
+int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph);
+
/* ----------------------------------------------------------- *
* Utility functions *
* ----------------------------------------------------------- */
diff --git a/lib/fuse.c b/lib/fuse.c
index 453fca5..820557d 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -1667,6 +1667,29 @@ int fuse_fs_ioctl(struct fuse_fs *fs, const char *path, int cmd, void *arg,
return -ENOSYS;
}
+int fuse_fs_poll(struct fuse_fs *fs, const char *path,
+ struct fuse_file_info *fi, struct fuse_pollhandle *ph,
+ unsigned *reventsp)
+{
+ fuse_get_context()->private_data = fs->user_data;
+ if (fs->op.poll) {
+ int res;
+
+ if (fs->debug)
+ fprintf(stderr, "poll[%llu] ph: %p\n",
+ (unsigned long long) fi->fh, ph);
+
+ res = fs->op.poll(path, fi, ph, reventsp);
+
+ if (fs->debug && !res)
+ fprintf(stderr, " poll[%llu] revents: 0x%x\n",
+ (unsigned long long) fi->fh, *reventsp);
+
+ return res;
+ } else
+ return -ENOSYS;
+}
+
static int is_open(struct fuse *f, fuse_ino_t dir, const char *name)
{
struct node *node;
@@ -3235,6 +3258,28 @@ enomem:
goto out;
}
+static void fuse_lib_poll(fuse_req_t req, fuse_ino_t ino,
+ struct fuse_file_info *fi, struct fuse_pollhandle *ph)
+{
+ struct fuse *f = req_fuse_prepare(req);
+ struct fuse_intr_data d;
+ char *path;
+ int ret;
+ unsigned revents = 0;
+
+ ret = get_path(f, ino, &path);
+ if (!ret) {
+ fuse_prepare_interrupt(f, req, &d);
+ ret = fuse_fs_poll(f->fs, path, fi, ph, &revents);
+ fuse_finish_interrupt(f, req, &d);
+ free_path(f, ino, path);
+ }
+ if (!ret)
+ fuse_reply_poll(req, revents);
+ else
+ reply_err(req, ret);
+}
+
static struct fuse_lowlevel_ops fuse_path_ops = {
.init = fuse_lib_init,
.destroy = fuse_lib_destroy,
@@ -3271,8 +3316,14 @@ static struct fuse_lowlevel_ops fuse_path_ops = {
.setlk = fuse_lib_setlk,
.bmap = fuse_lib_bmap,
.ioctl = fuse_lib_ioctl,
+ .poll = fuse_lib_poll,
};
+int fuse_notify_poll(struct fuse_pollhandle *ph)
+{
+ return fuse_lowlevel_notify_poll(ph);
+}
+
static void free_cmd(struct fuse_cmd *cmd)
{
free(cmd->buf);
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 6b5fdce..026de30 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -64,6 +64,12 @@ struct fuse_ll {
int got_destroy;
};
+struct fuse_pollhandle {
+ uint64_t kh;
+ struct fuse_chan *ch;
+ struct fuse_ll *f;
+};
+
static void convert_stat(const struct stat *stbuf, struct fuse_attr *attr)
{
attr->ino = stbuf->st_ino;
@@ -503,6 +509,16 @@ int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size)
return send_reply_iov(req, 0, iov, count);
}
+int fuse_reply_poll(fuse_req_t req, unsigned revents)
+{
+ struct fuse_poll_out arg;
+
+ memset(&arg, 0, sizeof(arg));
+ arg.revents = revents;
+
+ return send_reply_ok(req, &arg, sizeof(arg));
+}
+
static void do_lookup(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
{
char *name = (char *) inarg;
@@ -1075,6 +1091,40 @@ static void do_ioctl(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
fuse_reply_err(req, ENOSYS);
}
+void fuse_pollhandle_destroy(struct fuse_pollhandle *ph)
+{
+ free(ph);
+}
+
+static void do_poll(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
+{
+ struct fuse_poll_in *arg = (struct fuse_poll_in *) inarg;
+ struct fuse_file_info fi;
+
+ memset(&fi, 0, sizeof(fi));
+ fi.fh = arg->fh;
+ fi.fh_old = fi.fh;
+
+ if (req->f->op.poll) {
+ struct fuse_pollhandle *ph = NULL;
+
+ if (arg->flags & FUSE_POLL_SCHEDULE_NOTIFY) {
+ ph = malloc(sizeof(struct fuse_pollhandle));
+ if (ph == NULL) {
+ fuse_reply_err(req, ENOMEM);
+ return;
+ }
+ ph->kh = arg->kh;
+ ph->ch = req->ch;
+ ph->f = req->f;
+ }
+
+ req->f->op.poll(req, nodeid, &fi, ph);
+ } else {
+ fuse_reply_err(req, ENOSYS);
+ }
+}
+
static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
{
struct fuse_init_in *arg = (struct fuse_init_in *) inarg;
@@ -1181,6 +1231,41 @@ static void do_destroy(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
send_reply_ok(req, NULL, 0);
}
+static int send_notify_iov(struct fuse_ll *f, struct fuse_chan *ch,
+ int notify_code, struct iovec *iov, int count)
+{
+ struct fuse_out_header out;
+
+ out.unique = 0;
+ out.error = notify_code;
+ iov[0].iov_base = &out;
+ iov[0].iov_len = sizeof(struct fuse_out_header);
+ out.len = iov_length(iov, count);
+
+ if (f->debug)
+ fprintf(stderr, "NOTIFY: code=%d count=%d length=%u\n",
+ notify_code, count, out.len);
+
+ return fuse_chan_send(ch, iov, count);
+}
+
+int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph)
+{
+ if (ph != NULL) {
+ struct fuse_notify_poll_wakeup_out outarg;
+ struct iovec iov[2];
+
+ outarg.kh = ph->kh;
+
+ iov[1].iov_base = &outarg;
+ iov[1].iov_len = sizeof(outarg);
+
+ return send_notify_iov(ph->f, ph->ch, FUSE_NOTIFY_POLL, iov, 2);
+ } else {
+ return 0;
+ }
+}
+
void *fuse_req_userdata(fuse_req_t req)
{
return req->f->userdata;
@@ -1255,6 +1340,7 @@ static struct {
[FUSE_INTERRUPT] = { do_interrupt, "INTERRUPT" },
[FUSE_BMAP] = { do_bmap, "BMAP" },
[FUSE_IOCTL] = { do_ioctl, "IOCTL" },
+ [FUSE_POLL] = { do_poll, "POLL" },
[FUSE_DESTROY] = { do_destroy, "DESTROY" },
};
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index 4aa1c0b..4b5c8f3 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -156,10 +156,15 @@ FUSE_2.7 {
FUSE_2.8 {
global:
fuse_fs_ioctl;
+ fuse_fs_poll;
+ fuse_lowlevel_notify_poll;
+ fuse_notify_poll;
fuse_opt_add_opt_escaped;
+ fuse_pollhandle_destroy;
fuse_reply_bmap;
fuse_reply_ioctl;
fuse_reply_ioctl_retry;
+ fuse_reply_poll;
local:
*;