lkml.org 
[lkml]   [2021]   [Dec]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v1 20/23] cachefiles: implement .poll() for demand read
Date
User daemon needs to poll on the devnode, and will be notified once
there's pending request to process.

Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
---
fs/cachefiles/daemon.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
index 01496fa8c263..311dcd911a85 100644
--- a/fs/cachefiles/daemon.c
+++ b/fs/cachefiles/daemon.c
@@ -29,6 +29,8 @@ static ssize_t cachefiles_daemon_write(struct file *, const char __user *,
size_t, loff_t *);
static __poll_t cachefiles_daemon_poll(struct file *,
struct poll_table_struct *);
+static __poll_t cachefiles_demand_poll(struct file *,
+ struct poll_table_struct *);
static int cachefiles_daemon_frun(struct cachefiles_cache *, char *);
static int cachefiles_daemon_fcull(struct cachefiles_cache *, char *);
static int cachefiles_daemon_fstop(struct cachefiles_cache *, char *);
@@ -62,6 +64,7 @@ const struct file_operations cachefiles_demand_fops = {
.open = cachefiles_daemon_open,
.release = cachefiles_daemon_release,
.write = cachefiles_daemon_write,
+ .poll = cachefiles_demand_poll,
.llseek = noop_llseek,
};

@@ -319,6 +322,21 @@ static __poll_t cachefiles_daemon_poll(struct file *file,
return mask;
}

+static __poll_t cachefiles_demand_poll(struct file *file,
+ struct poll_table_struct *poll)
+{
+ struct cachefiles_cache *cache = file->private_data;
+ __poll_t mask;
+
+ poll_wait(file, &cache->daemon_pollwq, poll);
+ mask = 0;
+
+ if (!idr_is_empty(&cache->reqs))
+ mask |= EPOLLIN;
+
+ return mask;
+}
+
/*
* Give a range error for cache space constraints
* - can be tail-called
--
2.27.0
\
 
 \ /
  Last update: 2021-12-27 13:55    [W:1.637 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site