Sage Weil | 58bb3b3 | 2009-12-23 12:12:31 -0800 | [diff] [blame] | 1 | #ifndef __FS_CEPH_PAGELIST_H |
| 2 | #define __FS_CEPH_PAGELIST_H |
| 3 | |
| 4 | #include <linux/list.h> |
| 5 | |
| 6 | struct ceph_pagelist { |
| 7 | struct list_head head; |
| 8 | void *mapped_tail; |
| 9 | size_t length; |
| 10 | size_t room; |
Greg Farnum | ac0b74d | 2010-09-17 10:10:55 -0700 | [diff] [blame] | 11 | struct list_head free_list; |
| 12 | size_t num_pages_free; |
| 13 | }; |
| 14 | |
| 15 | struct ceph_pagelist_cursor { |
| 16 | struct ceph_pagelist *pl; /* pagelist, for error checking */ |
| 17 | struct list_head *page_lru; /* page in list */ |
| 18 | size_t room; /* room remaining to reset to */ |
Sage Weil | 58bb3b3 | 2009-12-23 12:12:31 -0800 | [diff] [blame] | 19 | }; |
| 20 | |
| 21 | static inline void ceph_pagelist_init(struct ceph_pagelist *pl) |
| 22 | { |
| 23 | INIT_LIST_HEAD(&pl->head); |
| 24 | pl->mapped_tail = NULL; |
| 25 | pl->length = 0; |
| 26 | pl->room = 0; |
Greg Farnum | ac0b74d | 2010-09-17 10:10:55 -0700 | [diff] [blame] | 27 | INIT_LIST_HEAD(&pl->free_list); |
| 28 | pl->num_pages_free = 0; |
Sage Weil | 58bb3b3 | 2009-12-23 12:12:31 -0800 | [diff] [blame] | 29 | } |
Greg Farnum | ac0b74d | 2010-09-17 10:10:55 -0700 | [diff] [blame] | 30 | |
Sage Weil | 58bb3b3 | 2009-12-23 12:12:31 -0800 | [diff] [blame] | 31 | extern int ceph_pagelist_release(struct ceph_pagelist *pl); |
| 32 | |
Yehuda Sadeh | 68b4476 | 2010-04-06 15:01:27 -0700 | [diff] [blame] | 33 | 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] | 34 | |
Greg Farnum | ac0b74d | 2010-09-17 10:10:55 -0700 | [diff] [blame] | 35 | extern int ceph_pagelist_reserve(struct ceph_pagelist *pl, size_t space); |
| 36 | |
| 37 | extern int ceph_pagelist_free_reserve(struct ceph_pagelist *pl); |
| 38 | |
| 39 | extern void ceph_pagelist_set_cursor(struct ceph_pagelist *pl, |
| 40 | struct ceph_pagelist_cursor *c); |
| 41 | |
| 42 | extern int ceph_pagelist_truncate(struct ceph_pagelist *pl, |
| 43 | struct ceph_pagelist_cursor *c); |
| 44 | |
Sage Weil | 58bb3b3 | 2009-12-23 12:12:31 -0800 | [diff] [blame] | 45 | static inline int ceph_pagelist_encode_64(struct ceph_pagelist *pl, u64 v) |
| 46 | { |
| 47 | __le64 ev = cpu_to_le64(v); |
| 48 | return ceph_pagelist_append(pl, &ev, sizeof(ev)); |
| 49 | } |
| 50 | static inline int ceph_pagelist_encode_32(struct ceph_pagelist *pl, u32 v) |
| 51 | { |
| 52 | __le32 ev = cpu_to_le32(v); |
| 53 | return ceph_pagelist_append(pl, &ev, sizeof(ev)); |
| 54 | } |
| 55 | static inline int ceph_pagelist_encode_16(struct ceph_pagelist *pl, u16 v) |
| 56 | { |
| 57 | __le16 ev = cpu_to_le16(v); |
| 58 | return ceph_pagelist_append(pl, &ev, sizeof(ev)); |
| 59 | } |
| 60 | static inline int ceph_pagelist_encode_8(struct ceph_pagelist *pl, u8 v) |
| 61 | { |
| 62 | return ceph_pagelist_append(pl, &v, 1); |
| 63 | } |
| 64 | static inline int ceph_pagelist_encode_string(struct ceph_pagelist *pl, |
| 65 | char *s, size_t len) |
| 66 | { |
| 67 | int ret = ceph_pagelist_encode_32(pl, len); |
| 68 | if (ret) |
| 69 | return ret; |
| 70 | if (len) |
| 71 | return ceph_pagelist_append(pl, s, len); |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | #endif |