Merge tag 'fbdev-for-6.4-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/deller...
[linux-block.git] / include / linux / nfs_page.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2/*
3 * linux/include/linux/nfs_page.h
4 *
5 * Copyright (C) 2000 Trond Myklebust
6 *
7 * NFS page cache wrapper.
8 */
9
10#ifndef _LINUX_NFS_PAGE_H
11#define _LINUX_NFS_PAGE_H
12
13
14#include <linux/list.h>
15#include <linux/pagemap.h>
16#include <linux/wait.h>
1da177e4
LT
17#include <linux/sunrpc/auth.h>
18#include <linux/nfs_xdr.h>
19
c03b4024 20#include <linux/kref.h>
1da177e4
LT
21
22/*
23 * Valid flags for a dirty buffer
24 */
e468bae9 25enum {
12c05792
WAA
26 PG_BUSY = 0, /* nfs_{un}lock_request */
27 PG_MAPPED, /* page private set for buffered io */
35c5db0e 28 PG_FOLIO, /* Tracking a folio (unset for O_DIRECT) */
12c05792
WAA
29 PG_CLEAN, /* write succeeded */
30 PG_COMMIT_TO_DS, /* used by pnfs layouts */
b412ddf0 31 PG_INODE_REF, /* extra ref held by inode when in writeback */
2bfc6e56
WAA
32 PG_HEADLOCK, /* page group lock of wb_head */
33 PG_TEARDOWN, /* page group sync for destroy */
67d0338e
WAA
34 PG_UNLOCKPAGE, /* page group sync bit in read path */
35 PG_UPTODATE, /* page group sync bit in read path */
20633f04
WAA
36 PG_WB_END, /* page group sync bit in write path */
37 PG_REMOVE, /* page group sync bit in write path */
b4f937cf
TM
38 PG_CONTENDED1, /* Is someone waiting for a lock? */
39 PG_CONTENDED2, /* Is someone waiting for a lock? */
e468bae9 40};
1da177e4 41
3da28eb1 42struct nfs_inode;
1da177e4 43struct nfs_page {
d6d6dc7c 44 struct list_head wb_list; /* Defines state of page: */
35c5db0e
TM
45 union {
46 struct page *wb_page; /* page to read in/write out */
47 struct folio *wb_folio;
48 };
f11ac8db 49 struct nfs_lock_context *wb_lock_context; /* lock context info */
ea1754a0
KS
50 pgoff_t wb_index; /* Offset >> PAGE_SHIFT */
51 unsigned int wb_offset, /* Offset & ~PAGE_MASK */
1da177e4
LT
52 wb_pgbase, /* Start of page data */
53 wb_bytes; /* Length of request */
c03b4024 54 struct kref wb_kref; /* reference count */
1da177e4 55 unsigned long wb_flags;
2f2c63bc 56 struct nfs_write_verifier wb_verf; /* Commit cookie */
2bfc6e56
WAA
57 struct nfs_page *wb_this_page; /* list of reqs for this page */
58 struct nfs_page *wb_head; /* head pointer for req list */
33344e0f 59 unsigned short wb_nio; /* Number of I/O attempts */
1da177e4
LT
60};
61
63e2fffa 62struct nfs_pgio_mirror;
1751c363
TM
63struct nfs_pageio_descriptor;
64struct nfs_pageio_ops {
d8007d4d 65 void (*pg_init)(struct nfs_pageio_descriptor *, struct nfs_page *);
b4fdac1a
WAA
66 size_t (*pg_test)(struct nfs_pageio_descriptor *, struct nfs_page *,
67 struct nfs_page *);
1751c363 68 int (*pg_doio)(struct nfs_pageio_descriptor *);
a7d42ddb
WAA
69 unsigned int (*pg_get_mirror_count)(struct nfs_pageio_descriptor *,
70 struct nfs_page *);
2176bf42 71 void (*pg_cleanup)(struct nfs_pageio_descriptor *);
63e2fffa
TM
72 struct nfs_pgio_mirror *
73 (*pg_get_mirror)(struct nfs_pageio_descriptor *, u32);
74 u32 (*pg_set_mirror)(struct nfs_pageio_descriptor *, u32);
1751c363
TM
75};
76
4a0de55c 77struct nfs_rw_ops {
1e7f3a48
WAA
78 struct nfs_pgio_header *(*rw_alloc_header)(void);
79 void (*rw_free_header)(struct nfs_pgio_header *);
d45f60c6
WAA
80 int (*rw_done)(struct rpc_task *, struct nfs_pgio_header *,
81 struct inode *);
82 void (*rw_result)(struct rpc_task *, struct nfs_pgio_header *);
83 void (*rw_initiate)(struct nfs_pgio_header *, struct rpc_message *,
abde71f4 84 const struct nfs_rpc_ops *,
1ed26f33 85 struct rpc_task_setup *, int);
4a0de55c
AS
86};
87
a7d42ddb 88struct nfs_pgio_mirror {
d8a5ad75 89 struct list_head pg_list;
bcb71bba 90 unsigned long pg_bytes_written;
d8a5ad75
TM
91 size_t pg_count;
92 size_t pg_bsize;
93 unsigned int pg_base;
a7d42ddb
WAA
94 unsigned char pg_recoalesce : 1;
95};
bcb71bba 96
a7d42ddb 97struct nfs_pageio_descriptor {
bcb71bba 98 struct inode *pg_inode;
1751c363 99 const struct nfs_pageio_ops *pg_ops;
4a0de55c 100 const struct nfs_rw_ops *pg_rw_ops;
bcb71bba
TM
101 int pg_ioflags;
102 int pg_error;
50828d7e 103 const struct rpc_call_ops *pg_rpc_callops;
061ae2ed 104 const struct nfs_pgio_completion_ops *pg_completion_ops;
94ad1c80 105 struct pnfs_layout_segment *pg_lseg;
919e3bd9 106 struct nfs_io_completion *pg_io_completion;
584aa810 107 struct nfs_direct_req *pg_dreq;
000dbe0b
DW
108#ifdef CONFIG_NFS_FSCACHE
109 void *pg_netfs;
110#endif
a7d42ddb
WAA
111 unsigned int pg_bsize; /* default bsize for mirrors */
112
113 u32 pg_mirror_count;
114 struct nfs_pgio_mirror *pg_mirrors;
115 struct nfs_pgio_mirror pg_mirrors_static[1];
116 struct nfs_pgio_mirror *pg_mirrors_dynamic;
117 u32 pg_mirror_idx; /* current mirror */
33344e0f
TM
118 unsigned short pg_maxretrans;
119 unsigned char pg_moreio : 1;
d8a5ad75
TM
120};
121
a7d42ddb
WAA
122/* arbitrarily selected limit to number of mirrors */
123#define NFS_PAGEIO_DESCRIPTOR_MIRROR_MAX 16
124
1da177e4 125#define NFS_WBACK_BUSY(req) (test_bit(PG_BUSY,&(req)->wb_flags))
1da177e4 126
70e9db69
TM
127extern struct nfs_page *nfs_page_create_from_page(struct nfs_open_context *ctx,
128 struct page *page,
129 unsigned int pgbase,
130 loff_t offset,
131 unsigned int count);
ab75bff1
TM
132extern struct nfs_page *nfs_page_create_from_folio(struct nfs_open_context *ctx,
133 struct folio *folio,
134 unsigned int offset,
135 unsigned int count);
2bfc6e56 136extern void nfs_release_request(struct nfs_page *);
1da177e4
LT
137
138
bcb71bba
TM
139extern void nfs_pageio_init(struct nfs_pageio_descriptor *desc,
140 struct inode *inode,
1751c363 141 const struct nfs_pageio_ops *pg_ops,
061ae2ed 142 const struct nfs_pgio_completion_ops *compl_ops,
4a0de55c 143 const struct nfs_rw_ops *rw_ops,
bcb71bba 144 size_t bsize,
3bde7afd 145 int how);
8b09bee3
TM
146extern int nfs_pageio_add_request(struct nfs_pageio_descriptor *,
147 struct nfs_page *);
53113ad3
WAA
148extern int nfs_pageio_resend(struct nfs_pageio_descriptor *,
149 struct nfs_pgio_header *);
bcb71bba 150extern void nfs_pageio_complete(struct nfs_pageio_descriptor *desc);
7fe7f848 151extern void nfs_pageio_cond_complete(struct nfs_pageio_descriptor *, pgoff_t);
b4fdac1a 152extern size_t nfs_generic_pg_test(struct nfs_pageio_descriptor *desc,
19345cb2
BH
153 struct nfs_page *prev,
154 struct nfs_page *req);
1da177e4
LT
155extern int nfs_wait_on_request(struct nfs_page *);
156extern void nfs_unlock_request(struct nfs_page *req);
2bfc6e56 157extern void nfs_unlock_and_release_request(struct nfs_page *);
e00ed89d 158extern struct nfs_page *nfs_page_group_lock_head(struct nfs_page *req);
a62f8e3b 159extern int nfs_page_group_lock_subrequests(struct nfs_page *head);
ed5d588f 160extern void nfs_join_page_group(struct nfs_page *head, struct inode *inode);
1344b7ea 161extern int nfs_page_group_lock(struct nfs_page *);
2bfc6e56
WAA
162extern void nfs_page_group_unlock(struct nfs_page *);
163extern bool nfs_page_group_sync_on_bit(struct nfs_page *, unsigned int);
08ca8b21
TM
164extern int nfs_page_set_headlock(struct nfs_page *req);
165extern void nfs_page_clear_headlock(struct nfs_page *req);
7d6ddf88 166extern bool nfs_async_iocounter_wait(struct rpc_task *, struct nfs_lock_context *);
c6a556b8 167
35c5db0e
TM
168/**
169 * nfs_page_to_folio - Retrieve a struct folio for the request
170 * @req: pointer to a struct nfs_page
171 *
172 * If a folio was assigned to @req, then return it, otherwise return NULL.
173 */
174static inline struct folio *nfs_page_to_folio(const struct nfs_page *req)
175{
176 if (test_bit(PG_FOLIO, &req->wb_flags))
177 return req->wb_folio;
178 return NULL;
179}
180
181/**
182 * nfs_page_to_page - Retrieve a struct page for the request
183 * @req: pointer to a struct nfs_page
184 * @pgbase: folio byte offset
185 *
186 * Return the page containing the byte that is at offset @pgbase relative
187 * to the start of the folio.
188 * Note: The request starts at offset @req->wb_pgbase.
189 */
190static inline struct page *nfs_page_to_page(const struct nfs_page *req,
191 size_t pgbase)
192{
193 struct folio *folio = nfs_page_to_folio(req);
194
195 if (folio == NULL)
196 return req->wb_page;
197 return folio_page(folio, pgbase >> PAGE_SHIFT);
198}
199
6dd85e83
TM
200/**
201 * nfs_page_to_inode - Retrieve an inode for the request
202 * @req: pointer to a struct nfs_page
203 */
204static inline struct inode *nfs_page_to_inode(const struct nfs_page *req)
205{
206 struct folio *folio = nfs_page_to_folio(req);
207
208 if (folio == NULL)
209 return page_file_mapping(req->wb_page)->host;
210 return folio_file_mapping(folio)->host;
211}
212
8e0bdc70
TM
213/**
214 * nfs_page_max_length - Retrieve the maximum possible length for a request
215 * @req: pointer to a struct nfs_page
216 *
217 * Returns the maximum possible length of a request
218 */
219static inline size_t nfs_page_max_length(const struct nfs_page *req)
220{
221 struct folio *folio = nfs_page_to_folio(req);
222
223 if (folio == NULL)
224 return PAGE_SIZE;
225 return folio_size(folio);
226}
227
1da177e4 228/*
7ad84aa9 229 * Lock the page of an asynchronous request
1da177e4 230 */
8dd37758
TM
231static inline int
232nfs_lock_request(struct nfs_page *req)
233{
7ad84aa9 234 return !test_and_set_bit(PG_BUSY, &req->wb_flags);
8dd37758
TM
235}
236
3da28eb1
TM
237/**
238 * nfs_list_add_request - Insert a request into a list
239 * @req: request
240 * @head: head of list into which to insert the request.
241 */
242static inline void
243nfs_list_add_request(struct nfs_page *req, struct list_head *head)
244{
245 list_add_tail(&req->wb_list, head);
3da28eb1
TM
246}
247
078b5fd9
TM
248/**
249 * nfs_list_move_request - Move a request to a new list
250 * @req: request
251 * @head: head of list into which to insert the request.
252 */
253static inline void
254nfs_list_move_request(struct nfs_page *req, struct list_head *head)
255{
256 list_move_tail(&req->wb_list, head);
257}
1da177e4
LT
258
259/**
260 * nfs_list_remove_request - Remove a request from its wb_list
261 * @req: request
262 */
263static inline void
264nfs_list_remove_request(struct nfs_page *req)
265{
266 if (list_empty(&req->wb_list))
267 return;
1da177e4 268 list_del_init(&req->wb_list);
1da177e4
LT
269}
270
1da177e4
LT
271static inline struct nfs_page *
272nfs_list_entry(struct list_head *head)
273{
274 return list_entry(head, struct nfs_page, wb_list);
275}
276
af887e43 277static inline loff_t req_offset(const struct nfs_page *req)
1da177e4 278{
09cbfeaf 279 return (((loff_t)req->wb_index) << PAGE_SHIFT) + req->wb_offset;
1da177e4
LT
280}
281
9fcd5960
TM
282static inline struct nfs_open_context *
283nfs_req_openctx(struct nfs_page *req)
284{
c79d183e 285 return req->wb_lock_context->open_context;
9fcd5960
TM
286}
287
1da177e4 288#endif /* _LINUX_NFS_PAGE_H */