1#ifndef __FS_CEPH_PAGELIST_H
2#define __FS_CEPH_PAGELIST_H
3
4#include <asm/byteorder.h>
5#include <linux/refcount.h>
6#include <linux/list.h>
7#include <linux/types.h>
8
9struct ceph_pagelist {
10 struct list_head head;
11 void *mapped_tail;
12 size_t length;
13 size_t room;
14 struct list_head free_list;
15 size_t num_pages_free;
16 refcount_t refcnt;
17};
18
19struct ceph_pagelist_cursor {
20 struct ceph_pagelist *pl;
21 struct list_head *page_lru;
22 size_t room;
23};
24
25static 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;
31 INIT_LIST_HEAD(&pl->free_list);
32 pl->num_pages_free = 0;
33 refcount_set(&pl->refcnt, 1);
34}
35
36extern void ceph_pagelist_release(struct ceph_pagelist *pl);
37
38extern int ceph_pagelist_append(struct ceph_pagelist *pl, const void *d, size_t l);
39
40extern int ceph_pagelist_reserve(struct ceph_pagelist *pl, size_t space);
41
42extern int ceph_pagelist_free_reserve(struct ceph_pagelist *pl);
43
44extern void ceph_pagelist_set_cursor(struct ceph_pagelist *pl,
45 struct ceph_pagelist_cursor *c);
46
47extern int ceph_pagelist_truncate(struct ceph_pagelist *pl,
48 struct ceph_pagelist_cursor *c);
49
50static 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}
55static 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}
60static 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}
65static inline int ceph_pagelist_encode_8(struct ceph_pagelist *pl, u8 v)
66{
67 return ceph_pagelist_append(pl, &v, 1);
68}
69static 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
81