Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Sage Weil | 58bb3b3 | 2009-12-23 12:12:31 -0800 | [diff] [blame] | 2 | #ifndef __FS_CEPH_PAGELIST_H |
| 3 | #define __FS_CEPH_PAGELIST_H |
| 4 | |
Ilya Dryomov | 84a1d2d | 2014-11-17 21:45:24 +0300 | [diff] [blame] | 5 | #include <asm/byteorder.h> |
Elena Reshetova | 0e1a5ee | 2017-03-17 14:10:29 +0200 | [diff] [blame] | 6 | #include <linux/refcount.h> |
Ilya Dryomov | 84a1d2d | 2014-11-17 21:45:24 +0300 | [diff] [blame] | 7 | #include <linux/list.h> |
| 8 | #include <linux/types.h> |
Sage Weil | 58bb3b3 | 2009-12-23 12:12:31 -0800 | [diff] [blame] | 9 | |
| 10 | struct ceph_pagelist { |
| 11 | struct list_head head; |
| 12 | void *mapped_tail; |
| 13 | size_t length; |
| 14 | size_t room; |
Greg Farnum | ac0b74d | 2010-09-17 10:10:55 -0700 | [diff] [blame] | 15 | struct list_head free_list; |
| 16 | size_t num_pages_free; |
Elena Reshetova | 0e1a5ee | 2017-03-17 14:10:29 +0200 | [diff] [blame] | 17 | refcount_t refcnt; |
Greg Farnum | ac0b74d | 2010-09-17 10:10:55 -0700 | [diff] [blame] | 18 | }; |
| 19 | |
| 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 */ |
Sage Weil | 58bb3b3 | 2009-12-23 12:12:31 -0800 | [diff] [blame] | 24 | }; |
| 25 | |
Ilya Dryomov | 33165d4 | 2018-09-28 15:38:34 +0200 | [diff] [blame] | 26 | struct ceph_pagelist *ceph_pagelist_alloc(gfp_t gfp_flags); |
Greg Farnum | ac0b74d | 2010-09-17 10:10:55 -0700 | [diff] [blame] | 27 | |
Yan, Zheng | e4339d28 | 2014-09-16 17:50:45 +0800 | [diff] [blame] | 28 | extern void ceph_pagelist_release(struct ceph_pagelist *pl); |
Sage Weil | 58bb3b3 | 2009-12-23 12:12:31 -0800 | [diff] [blame] | 29 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 30 | extern int ceph_pagelist_append(struct ceph_pagelist *pl, const void *d, size_t l); |
Sage Weil | 58bb3b3 | 2009-12-23 12:12:31 -0800 | [diff] [blame] | 31 | |
Greg Farnum | ac0b74d | 2010-09-17 10:10:55 -0700 | [diff] [blame] | 32 | extern int ceph_pagelist_reserve(struct ceph_pagelist *pl, size_t space); |
| 33 | |
| 34 | extern int ceph_pagelist_free_reserve(struct ceph_pagelist *pl); |
| 35 | |
| 36 | extern void ceph_pagelist_set_cursor(struct ceph_pagelist *pl, |
| 37 | struct ceph_pagelist_cursor *c); |
| 38 | |
| 39 | extern int ceph_pagelist_truncate(struct ceph_pagelist *pl, |
| 40 | struct ceph_pagelist_cursor *c); |
| 41 | |
Sage Weil | 58bb3b3 | 2009-12-23 12:12:31 -0800 | [diff] [blame] | 42 | static inline int ceph_pagelist_encode_64(struct ceph_pagelist *pl, u64 v) |
| 43 | { |
| 44 | __le64 ev = cpu_to_le64(v); |
| 45 | return ceph_pagelist_append(pl, &ev, sizeof(ev)); |
| 46 | } |
| 47 | static inline int ceph_pagelist_encode_32(struct ceph_pagelist *pl, u32 v) |
| 48 | { |
| 49 | __le32 ev = cpu_to_le32(v); |
| 50 | return ceph_pagelist_append(pl, &ev, sizeof(ev)); |
| 51 | } |
| 52 | static inline int ceph_pagelist_encode_16(struct ceph_pagelist *pl, u16 v) |
| 53 | { |
| 54 | __le16 ev = cpu_to_le16(v); |
| 55 | return ceph_pagelist_append(pl, &ev, sizeof(ev)); |
| 56 | } |
| 57 | static inline int ceph_pagelist_encode_8(struct ceph_pagelist *pl, u8 v) |
| 58 | { |
| 59 | return ceph_pagelist_append(pl, &v, 1); |
| 60 | } |
| 61 | static inline int ceph_pagelist_encode_string(struct ceph_pagelist *pl, |
Ilya Dryomov | c9ed51c | 2018-06-27 16:42:51 +0200 | [diff] [blame] | 62 | char *s, u32 len) |
Sage Weil | 58bb3b3 | 2009-12-23 12:12:31 -0800 | [diff] [blame] | 63 | { |
| 64 | int ret = ceph_pagelist_encode_32(pl, len); |
| 65 | if (ret) |
| 66 | return ret; |
| 67 | if (len) |
| 68 | return ceph_pagelist_append(pl, s, len); |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | #endif |