ceph: support inline data feature
[deliverable/linux.git] / include / linux / ceph / pagelist.h
1 #ifndef __FS_CEPH_PAGELIST_H
2 #define __FS_CEPH_PAGELIST_H
3
4 #include <linux/list.h>
5 #include <linux/atomic.h>
6
7 struct ceph_pagelist {
8 struct list_head head;
9 void *mapped_tail;
10 size_t length;
11 size_t room;
12 struct list_head free_list;
13 size_t num_pages_free;
14 atomic_t refcnt;
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 */
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;
29 INIT_LIST_HEAD(&pl->free_list);
30 pl->num_pages_free = 0;
31 atomic_set(&pl->refcnt, 1);
32 }
33
34 extern void ceph_pagelist_release(struct ceph_pagelist *pl);
35
36 extern int ceph_pagelist_append(struct ceph_pagelist *pl, const void *d, size_t l);
37
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
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
This page took 0.038134 seconds and 6 git commands to generate.