* Implement poll support. Patch by Tejun Heo
authorMiklos Szeredi <miklos@szeredi.hu>
Mon, 8 Dec 2008 19:26:53 +0000 (19:26 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Mon, 8 Dec 2008 19:26:53 +0000 (19:26 +0000)
12 files changed:
ChangeLog
example/.cvsignore
example/Makefile.am
example/fsel.c [new file with mode: 0644]
example/fselclient.c [new file with mode: 0644]
include/fuse.h
include/fuse_common.h
include/fuse_kernel.h
include/fuse_lowlevel.h
lib/fuse.c
lib/fuse_lowlevel.c
lib/fuse_versionscript

index 5220ff5775050bab02680455dca2cab99f47478d..8b3a9c72a2b5d5d3a337a75dccc8f6088e5730f8 100644 (file)
--- 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
index 7332bc0584fa4ed814acc5cc8b862a7123711ef9..af7dd99a26edead58c3003956e4129782b2f81cd 100644 (file)
@@ -8,4 +8,6 @@ hello
 hello_ll
 fioc
 fioclient
+fsel
+fselclient
 .libs
index 43b195d108668b108662650ae37b44cd4972b5a3..1aa5774319f59021db725426aa34c7542772ea4e 100644 (file)
@@ -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 (file)
index 0000000..a3c0c68
--- /dev/null
@@ -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 (file)
index 0000000..7c4b837
--- /dev/null
@@ -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");
+       }
+}
index 2016ccc66bbe1790235c57e09d3ed81de8649b35..e1b863c24360bd87d4c42a66167d658080120822 100644 (file)
@@ -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
  *
index fb18b61307b71c22a7519f8a8a57bcdc8e05d4d9..b05ed216661905934fbe86fc682b976bbd58179c 100644 (file)
@@ -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                                            *
  * ----------------------------------------------------------- */
index eb28a35616be3aad6ce93456fc78342dee4d4b98..df558e394ff5ac6c3b4b02c9b7932a3b6417ea83 100644 (file)
@@ -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;
index e17274f48bb14f380c2a8769c296bcbcdfe745cf..0b832149b1eadfb99b98c850cb75e9e0fbf2a062 100644 (file)
@@ -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                                          *
  * ----------------------------------------------------------- */
index 453fca51c08c4eb61ccdeb76588bb4e9d55c6ce5..820557d0221f06328c0f107fd2b3d6b2d72055ea 100644 (file)
@@ -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);
index 6b5fdced68dcdd5eed70a013d8da1b54a202bbe5..026de307733498251bddca96f1e42ea844ec4fcd 100644 (file)
@@ -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"     },
 };
 
index 4aa1c0bb20c094090bd19e406bced80f36a29171..4b5c8f377787241ba9afb1d31b360c4e075ffd0a 100644 (file)
@@ -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:
                *;