]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
58bb3b37 SW |
2 | #ifndef __FS_CEPH_PAGELIST_H |
3 | #define __FS_CEPH_PAGELIST_H | |
4 | ||
84a1d2d1 | 5 | #include <asm/byteorder.h> |
0e1a5ee6 | 6 | #include <linux/refcount.h> |
84a1d2d1 ID |
7 | #include <linux/list.h> |
8 | #include <linux/types.h> | |
58bb3b37 SW |
9 | |
10 | struct ceph_pagelist { | |
11 | struct list_head head; | |
12 | void *mapped_tail; | |
13 | size_t length; | |
14 | size_t room; | |
ac0b74d8 GF |
15 | struct list_head free_list; |
16 | size_t num_pages_free; | |
0e1a5ee6 | 17 | refcount_t refcnt; |
ac0b74d8 GF |
18 | }; |
19 | ||
20 | struct ceph_pagelist_cursor { | |
21 | struct ceph_pagelist *pl; /* pagelist, for error checking */ | |
22 | struct list_head *page_lru; /* page in list */ | |
23 | size_t room; /* room remaining to reset to */ | |
58bb3b37 SW |
24 | }; |
25 | ||
26 | static inline void ceph_pagelist_init(struct ceph_pagelist *pl) | |
27 | { | |
28 | INIT_LIST_HEAD(&pl->head); | |
29 | pl->mapped_tail = NULL; | |
30 | pl->length = 0; | |
31 | pl->room = 0; | |
ac0b74d8 GF |
32 | INIT_LIST_HEAD(&pl->free_list); |
33 | pl->num_pages_free = 0; | |
0e1a5ee6 | 34 | refcount_set(&pl->refcnt, 1); |
58bb3b37 | 35 | } |
ac0b74d8 | 36 | |
e4339d28 | 37 | extern void ceph_pagelist_release(struct ceph_pagelist *pl); |
58bb3b37 | 38 | |
68b4476b | 39 | extern int ceph_pagelist_append(struct ceph_pagelist *pl, const void *d, size_t l); |
58bb3b37 | 40 | |
ac0b74d8 GF |
41 | extern int ceph_pagelist_reserve(struct ceph_pagelist *pl, size_t space); |
42 | ||
43 | extern int ceph_pagelist_free_reserve(struct ceph_pagelist *pl); | |
44 | ||
45 | extern void ceph_pagelist_set_cursor(struct ceph_pagelist *pl, | |
46 | struct ceph_pagelist_cursor *c); | |
47 | ||
48 | extern int ceph_pagelist_truncate(struct ceph_pagelist *pl, | |
49 | struct ceph_pagelist_cursor *c); | |
50 | ||
58bb3b37 SW |
51 | static inline int ceph_pagelist_encode_64(struct ceph_pagelist *pl, u64 v) |
52 | { | |
53 | __le64 ev = cpu_to_le64(v); | |
54 | return ceph_pagelist_append(pl, &ev, sizeof(ev)); | |
55 | } | |
56 | static inline int ceph_pagelist_encode_32(struct ceph_pagelist *pl, u32 v) | |
57 | { | |
58 | __le32 ev = cpu_to_le32(v); | |
59 | return ceph_pagelist_append(pl, &ev, sizeof(ev)); | |
60 | } | |
61 | static inline int ceph_pagelist_encode_16(struct ceph_pagelist *pl, u16 v) | |
62 | { | |
63 | __le16 ev = cpu_to_le16(v); | |
64 | return ceph_pagelist_append(pl, &ev, sizeof(ev)); | |
65 | } | |
66 | static inline int ceph_pagelist_encode_8(struct ceph_pagelist *pl, u8 v) | |
67 | { | |
68 | return ceph_pagelist_append(pl, &v, 1); | |
69 | } | |
70 | static inline int ceph_pagelist_encode_string(struct ceph_pagelist *pl, | |
71 | char *s, size_t len) | |
72 | { | |
73 | int ret = ceph_pagelist_encode_32(pl, len); | |
74 | if (ret) | |
75 | return ret; | |
76 | if (len) | |
77 | return ceph_pagelist_append(pl, s, len); | |
78 | return 0; | |
79 | } | |
80 | ||
81 | #endif |