blob: 5f871d84ddcea591418825f4bf863ea587e3b38d [file] [log] [blame]
Sage Weil58bb3b32009-12-23 12:12:31 -08001#ifndef __FS_CEPH_PAGELIST_H
2#define __FS_CEPH_PAGELIST_H
3
4#include <linux/list.h>
Yan, Zhenge4339d282014-09-16 17:50:45 +08005#include <linux/atomic.h>
Sage Weil58bb3b32009-12-23 12:12:31 -08006
7struct ceph_pagelist {
8 struct list_head head;
9 void *mapped_tail;
10 size_t length;
11 size_t room;
Greg Farnumac0b74d2010-09-17 10:10:55 -070012 struct list_head free_list;
13 size_t num_pages_free;
Yan, Zhenge4339d282014-09-16 17:50:45 +080014 atomic_t refcnt;
Greg Farnumac0b74d2010-09-17 10:10:55 -070015};
16
17struct 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 */
Sage Weil58bb3b32009-12-23 12:12:31 -080021};
22
23static 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;
Greg Farnumac0b74d2010-09-17 10:10:55 -070029 INIT_LIST_HEAD(&pl->free_list);
30 pl->num_pages_free = 0;
Yan, Zhenge4339d282014-09-16 17:50:45 +080031 atomic_set(&pl->refcnt, 1);
Sage Weil58bb3b32009-12-23 12:12:31 -080032}
Greg Farnumac0b74d2010-09-17 10:10:55 -070033
Yan, Zhenge4339d282014-09-16 17:50:45 +080034extern void ceph_pagelist_release(struct ceph_pagelist *pl);
Sage Weil58bb3b32009-12-23 12:12:31 -080035
Yehuda Sadeh68b44762010-04-06 15:01:27 -070036extern int ceph_pagelist_append(struct ceph_pagelist *pl, const void *d, size_t l);
Sage Weil58bb3b32009-12-23 12:12:31 -080037
Greg Farnumac0b74d2010-09-17 10:10:55 -070038extern int ceph_pagelist_reserve(struct ceph_pagelist *pl, size_t space);
39
40extern int ceph_pagelist_free_reserve(struct ceph_pagelist *pl);
41
42extern void ceph_pagelist_set_cursor(struct ceph_pagelist *pl,
43 struct ceph_pagelist_cursor *c);
44
45extern int ceph_pagelist_truncate(struct ceph_pagelist *pl,
46 struct ceph_pagelist_cursor *c);
47
Sage Weil58bb3b32009-12-23 12:12:31 -080048static 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}
53static 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}
58static 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}
63static inline int ceph_pagelist_encode_8(struct ceph_pagelist *pl, u8 v)
64{
65 return ceph_pagelist_append(pl, &v, 1);
66}
67static 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