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