[PATCH 10/11] mm: add kiocb_wait_page_async_init() helper

2020-05-22 Thread Jens Axboe
Checks if the file supports it, and initializes the values that we need.
Caller passes in 'data' pointer, if any, and the callback function to
be used.

Signed-off-by: Jens Axboe 
---
 include/linux/pagemap.h | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index e260bcd071e4..21ced353310a 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -468,6 +468,24 @@ struct wait_page_async {
struct wait_page_key key;
 };
 
+static inline int kiocb_wait_page_async_init(struct kiocb *kiocb,
+struct wait_page_async *wait,
+wait_queue_func_t func,
+void *data)
+{
+   if (kiocb->ki_filp->f_mode & FMODE_BUF_RASYNC) {
+   wait->wait.func = func;
+   wait->wait.private = data;
+   wait->wait.flags = 0;
+   INIT_LIST_HEAD(>wait.entry);
+   kiocb->ki_flags |= IOCB_WAITQ;
+   kiocb->private = wait;
+   return 0;
+   }
+
+   return -EOPNOTSUPP;
+}
+
 extern void __lock_page(struct page *page);
 extern int __lock_page_killable(struct page *page);
 extern int __lock_page_async(struct page *page, struct wait_page_async *wait);
-- 
2.26.2



[PATCH 10/11] mm: add kiocb_wait_page_async_init() helper

2020-05-22 Thread Jens Axboe
Checks if the file supports it, and initializes the values that we need.
Caller passes in 'data' pointer, if any, and the callback function to
be used.

Signed-off-by: Jens Axboe 
---
 include/linux/pagemap.h | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 39af9f890866..dec61e9e5710 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -468,6 +468,24 @@ struct wait_page_async {
struct wait_page_key key;
 };
 
+static inline int kiocb_wait_page_async_init(struct kiocb *kiocb,
+struct wait_page_async *wait,
+wait_queue_func_t func,
+void *data)
+{
+   if (kiocb->ki_filp->f_mode & FMODE_BUF_RASYNC) {
+   wait->wait.func = func;
+   wait->wait.private = data;
+   wait->wait.flags = 0;
+   INIT_LIST_HEAD(>wait.entry);
+   kiocb->ki_flags |= IOCB_WAITQ;
+   kiocb->private = wait;
+   return 0;
+   }
+
+   return -EOPNOTSUPP;
+}
+
 extern void __lock_page(struct page *page);
 extern int __lock_page_killable(struct page *page);
 extern int __lock_page_async(struct page *page, struct wait_page_async *wait);
-- 
2.26.2