pagelist.h 1.9 KB

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