1 #ifndef __FS_CEPH_PAGELIST_H
2 #define __FS_CEPH_PAGELIST_H
4 #include <linux/list.h>
5 #include <linux/atomic.h>
12 struct list_head free_list;
13 size_t num_pages_free;
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 */
23 static inline void ceph_pagelist_init(struct ceph_pagelist *pl)
25 INIT_LIST_HEAD(&pl->head);
26 pl->mapped_tail = NULL;
29 INIT_LIST_HEAD(&pl->free_list);
30 pl->num_pages_free = 0;
31 atomic_set(&pl->refcnt, 1);
34 extern void ceph_pagelist_release(struct ceph_pagelist *pl);
36 extern int ceph_pagelist_append(struct ceph_pagelist *pl, const void *d, size_t l);
38 extern int ceph_pagelist_reserve(struct ceph_pagelist *pl, size_t space);
40 extern int ceph_pagelist_free_reserve(struct ceph_pagelist *pl);
42 extern void ceph_pagelist_set_cursor(struct ceph_pagelist *pl,
43 struct ceph_pagelist_cursor *c);
45 extern int ceph_pagelist_truncate(struct ceph_pagelist *pl,
46 struct ceph_pagelist_cursor *c);
48 static inline int ceph_pagelist_encode_64(struct ceph_pagelist *pl, u64 v)
50 __le64 ev = cpu_to_le64(v);
51 return ceph_pagelist_append(pl, &ev, sizeof(ev));
53 static inline int ceph_pagelist_encode_32(struct ceph_pagelist *pl, u32 v)
55 __le32 ev = cpu_to_le32(v);
56 return ceph_pagelist_append(pl, &ev, sizeof(ev));
58 static inline int ceph_pagelist_encode_16(struct ceph_pagelist *pl, u16 v)
60 __le16 ev = cpu_to_le16(v);
61 return ceph_pagelist_append(pl, &ev, sizeof(ev));
63 static inline int ceph_pagelist_encode_8(struct ceph_pagelist *pl, u8 v)
65 return ceph_pagelist_append(pl, &v, 1);
67 static inline int ceph_pagelist_encode_string(struct ceph_pagelist *pl,
70 int ret = ceph_pagelist_encode_32(pl, len);
74 return ceph_pagelist_append(pl, s, len);