1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __FS_CEPH_PAGELIST_H
3 #define __FS_CEPH_PAGELIST_H
5 #include <asm/byteorder.h>
6 #include <linux/refcount.h>
7 #include <linux/list.h>
8 #include <linux/types.h>
10 struct ceph_pagelist {
11 struct list_head head;
15 struct list_head free_list;
16 size_t num_pages_free;
20 struct ceph_pagelist_cursor {
21 struct ceph_pagelist *pl; /* pagelist, for error checking */
22 struct list_head *page_lru; /* page in list */
23 size_t room; /* room remaining to reset to */
26 struct ceph_pagelist *ceph_pagelist_alloc(gfp_t gfp_flags);
28 extern void ceph_pagelist_release(struct ceph_pagelist *pl);
30 extern int ceph_pagelist_append(struct ceph_pagelist *pl, const void *d, size_t l);
32 extern int ceph_pagelist_reserve(struct ceph_pagelist *pl, size_t space);
34 extern int ceph_pagelist_free_reserve(struct ceph_pagelist *pl);
36 extern void ceph_pagelist_set_cursor(struct ceph_pagelist *pl,
37 struct ceph_pagelist_cursor *c);
39 extern int ceph_pagelist_truncate(struct ceph_pagelist *pl,
40 struct ceph_pagelist_cursor *c);
42 static inline int ceph_pagelist_encode_64(struct ceph_pagelist *pl, u64 v)
44 __le64 ev = cpu_to_le64(v);
45 return ceph_pagelist_append(pl, &ev, sizeof(ev));
47 static inline int ceph_pagelist_encode_32(struct ceph_pagelist *pl, u32 v)
49 __le32 ev = cpu_to_le32(v);
50 return ceph_pagelist_append(pl, &ev, sizeof(ev));
52 static inline int ceph_pagelist_encode_16(struct ceph_pagelist *pl, u16 v)
54 __le16 ev = cpu_to_le16(v);
55 return ceph_pagelist_append(pl, &ev, sizeof(ev));
57 static inline int ceph_pagelist_encode_8(struct ceph_pagelist *pl, u8 v)
59 return ceph_pagelist_append(pl, &v, 1);
61 static inline int ceph_pagelist_encode_string(struct ceph_pagelist *pl,
64 int ret = ceph_pagelist_encode_32(pl, len);
68 return ceph_pagelist_append(pl, s, len);