Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __FS_CEPH_PAGELIST_H
0003 #define __FS_CEPH_PAGELIST_H
0004 
0005 #include <asm/byteorder.h>
0006 #include <linux/refcount.h>
0007 #include <linux/list.h>
0008 #include <linux/types.h>
0009 
0010 struct ceph_pagelist {
0011     struct list_head head;
0012     void *mapped_tail;
0013     size_t length;
0014     size_t room;
0015     struct list_head free_list;
0016     size_t num_pages_free;
0017     refcount_t refcnt;
0018 };
0019 
0020 struct ceph_pagelist_cursor {
0021     struct ceph_pagelist *pl;   /* pagelist, for error checking */
0022     struct list_head *page_lru; /* page in list */
0023     size_t room;            /* room remaining to reset to */
0024 };
0025 
0026 struct ceph_pagelist *ceph_pagelist_alloc(gfp_t gfp_flags);
0027 
0028 extern void ceph_pagelist_release(struct ceph_pagelist *pl);
0029 
0030 extern int ceph_pagelist_append(struct ceph_pagelist *pl, const void *d, size_t l);
0031 
0032 extern int ceph_pagelist_reserve(struct ceph_pagelist *pl, size_t space);
0033 
0034 extern int ceph_pagelist_free_reserve(struct ceph_pagelist *pl);
0035 
0036 extern void ceph_pagelist_set_cursor(struct ceph_pagelist *pl,
0037                      struct ceph_pagelist_cursor *c);
0038 
0039 extern int ceph_pagelist_truncate(struct ceph_pagelist *pl,
0040                   struct ceph_pagelist_cursor *c);
0041 
0042 static inline int ceph_pagelist_encode_64(struct ceph_pagelist *pl, u64 v)
0043 {
0044     __le64 ev = cpu_to_le64(v);
0045     return ceph_pagelist_append(pl, &ev, sizeof(ev));
0046 }
0047 static inline int ceph_pagelist_encode_32(struct ceph_pagelist *pl, u32 v)
0048 {
0049     __le32 ev = cpu_to_le32(v);
0050     return ceph_pagelist_append(pl, &ev, sizeof(ev));
0051 }
0052 static inline int ceph_pagelist_encode_16(struct ceph_pagelist *pl, u16 v)
0053 {
0054     __le16 ev = cpu_to_le16(v);
0055     return ceph_pagelist_append(pl, &ev, sizeof(ev));
0056 }
0057 static inline int ceph_pagelist_encode_8(struct ceph_pagelist *pl, u8 v)
0058 {
0059     return ceph_pagelist_append(pl, &v, 1);
0060 }
0061 static inline int ceph_pagelist_encode_string(struct ceph_pagelist *pl,
0062                           char *s, u32 len)
0063 {
0064     int ret = ceph_pagelist_encode_32(pl, len);
0065     if (ret)
0066         return ret;
0067     if (len)
0068         return ceph_pagelist_append(pl, s, len);
0069     return 0;
0070 }
0071 
0072 #endif