xref: /linux/include/linux/ceph/pagelist.h (revision 9d0ad045533ee37a208991ac5baaf6641e60a9ed)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __FS_CEPH_PAGELIST_H
3 #define __FS_CEPH_PAGELIST_H
4 
5 #include <asm/byteorder.h>
6 #include <linux/refcount.h>
7 #include <linux/list.h>
8 #include <linux/types.h>
9 
10 struct ceph_pagelist {
11 	struct list_head head;
12 	void *mapped_tail;
13 	size_t length;
14 	size_t room;
15 	struct list_head free_list;
16 	size_t num_pages_free;
17 	refcount_t refcnt;
18 };
19 
20 struct ceph_pagelist *ceph_pagelist_alloc(gfp_t gfp_flags);
21 
22 extern void ceph_pagelist_release(struct ceph_pagelist *pl);
23 
24 extern int ceph_pagelist_append(struct ceph_pagelist *pl, const void *d, size_t l);
25 
26 extern int ceph_pagelist_reserve(struct ceph_pagelist *pl, size_t space);
27 
28 extern int ceph_pagelist_free_reserve(struct ceph_pagelist *pl);
29 
ceph_pagelist_encode_64(struct ceph_pagelist * pl,u64 v)30 static inline int ceph_pagelist_encode_64(struct ceph_pagelist *pl, u64 v)
31 {
32 	__le64 ev = cpu_to_le64(v);
33 	return ceph_pagelist_append(pl, &ev, sizeof(ev));
34 }
ceph_pagelist_encode_32(struct ceph_pagelist * pl,u32 v)35 static inline int ceph_pagelist_encode_32(struct ceph_pagelist *pl, u32 v)
36 {
37 	__le32 ev = cpu_to_le32(v);
38 	return ceph_pagelist_append(pl, &ev, sizeof(ev));
39 }
ceph_pagelist_encode_16(struct ceph_pagelist * pl,u16 v)40 static inline int ceph_pagelist_encode_16(struct ceph_pagelist *pl, u16 v)
41 {
42 	__le16 ev = cpu_to_le16(v);
43 	return ceph_pagelist_append(pl, &ev, sizeof(ev));
44 }
ceph_pagelist_encode_8(struct ceph_pagelist * pl,u8 v)45 static inline int ceph_pagelist_encode_8(struct ceph_pagelist *pl, u8 v)
46 {
47 	return ceph_pagelist_append(pl, &v, 1);
48 }
ceph_pagelist_encode_string(struct ceph_pagelist * pl,char * s,u32 len)49 static inline int ceph_pagelist_encode_string(struct ceph_pagelist *pl,
50 					      char *s, u32 len)
51 {
52 	int ret = ceph_pagelist_encode_32(pl, len);
53 	if (ret)
54 		return ret;
55 	if (len)
56 		return ceph_pagelist_append(pl, s, len);
57 	return 0;
58 }
59 
60 #endif
61