pagelist.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef __FS_CEPH_PAGELIST_H
  2. #define __FS_CEPH_PAGELIST_H
  3. #include <asm/byteorder.h>
  4. #include <linux/atomic.h>
  5. #include <linux/list.h>
  6. #include <linux/types.h>
  7. struct ceph_pagelist {
  8. struct list_head head;
  9. void *mapped_tail;
  10. size_t length;
  11. size_t room;
  12. struct list_head free_list;
  13. size_t num_pages_free;
  14. atomic_t refcnt;
  15. };
  16. struct ceph_pagelist_cursor {
  17. struct ceph_pagelist *pl; /* pagelist, for error checking */
  18. struct list_head *page_lru; /* page in list */
  19. size_t room; /* room remaining to reset to */
  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;
  27. INIT_LIST_HEAD(&pl->free_list);
  28. pl->num_pages_free = 0;
  29. atomic_set(&pl->refcnt, 1);
  30. }
  31. extern void ceph_pagelist_release(struct ceph_pagelist *pl);
  32. extern int ceph_pagelist_append(struct ceph_pagelist *pl, const void *d, size_t l);
  33. extern int ceph_pagelist_reserve(struct ceph_pagelist *pl, size_t space);
  34. extern int ceph_pagelist_free_reserve(struct ceph_pagelist *pl);
  35. extern void ceph_pagelist_set_cursor(struct ceph_pagelist *pl,
  36. struct ceph_pagelist_cursor *c);
  37. extern int ceph_pagelist_truncate(struct ceph_pagelist *pl,
  38. struct ceph_pagelist_cursor *c);
  39. static inline int ceph_pagelist_encode_64(struct ceph_pagelist *pl, u64 v)
  40. {
  41. __le64 ev = cpu_to_le64(v);
  42. return ceph_pagelist_append(pl, &ev, sizeof(ev));
  43. }
  44. static inline int ceph_pagelist_encode_32(struct ceph_pagelist *pl, u32 v)
  45. {
  46. __le32 ev = cpu_to_le32(v);
  47. return ceph_pagelist_append(pl, &ev, sizeof(ev));
  48. }
  49. static inline int ceph_pagelist_encode_16(struct ceph_pagelist *pl, u16 v)
  50. {
  51. __le16 ev = cpu_to_le16(v);
  52. return ceph_pagelist_append(pl, &ev, sizeof(ev));
  53. }
  54. static inline int ceph_pagelist_encode_8(struct ceph_pagelist *pl, u8 v)
  55. {
  56. return ceph_pagelist_append(pl, &v, 1);
  57. }
  58. static inline int ceph_pagelist_encode_string(struct ceph_pagelist *pl,
  59. char *s, size_t len)
  60. {
  61. int ret = ceph_pagelist_encode_32(pl, len);
  62. if (ret)
  63. return ret;
  64. if (len)
  65. return ceph_pagelist_append(pl, s, len);
  66. return 0;
  67. }
  68. #endif