| 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 | |
| 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, d: &ev, l: sizeof(ev)); |
| 34 | } |
| 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, d: &ev, l: sizeof(ev)); |
| 39 | } |
| 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, d: &ev, l: sizeof(ev)); |
| 44 | } |
| 45 | static inline int ceph_pagelist_encode_8(struct ceph_pagelist *pl, u8 v) |
| 46 | { |
| 47 | return ceph_pagelist_append(pl, d: &v, l: 1); |
| 48 | } |
| 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, v: len); |
| 53 | if (ret) |
| 54 | return ret; |
| 55 | if (len) |
| 56 | return ceph_pagelist_append(pl, d: s, l: len); |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | #endif |
| 61 | |