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