diff options
author | Miklos Szeredi <miklos@szeredi.hu> | 2008-12-08 19:26:53 +0000 |
---|---|---|
committer | Miklos Szeredi <miklos@szeredi.hu> | 2008-12-08 19:26:53 +0000 |
commit | 5f722fa8f6561c964fd0bd651b4602ac0f7bc3b4 (patch) | |
tree | 47a21b51e3d8319b1c929c461a4934d62134164d /lib | |
parent | ecfa5263ab5b19a58d53a7116fb079f3b956b918 (diff) | |
download | libfuse-5f722fa8f6561c964fd0bd651b4602ac0f7bc3b4.tar.gz |
* Implement poll support. Patch by Tejun Heo
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fuse.c | 51 | ||||
-rw-r--r-- | lib/fuse_lowlevel.c | 86 | ||||
-rw-r--r-- | lib/fuse_versionscript | 5 |
3 files changed, 142 insertions, 0 deletions
@@ -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: *; |