pagelist.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef __FS_CEPH_PAGELIST_H
  2. #define __FS_CEPH_PAGELIST_H
  3. #include <linux/list.h>
  4. struct ceph_pagelist {
  5. struct list_head head;
  6. void *mapped_tail;
  7. size_t length;
  8. size_t room;
  9. };
  10. static inline void ceph_pagelist_init(struct ceph_pagelist *pl)
  11. {
  12. INIT_LIST_HEAD(&pl->head);
  13. pl->mapped_tail = NULL;
  14. pl->length = 0;
  15. pl->room = 0;
  16. }
  17. extern int ceph_pagelist_release(struct ceph_pagelist *pl);
  18. extern int ceph_pagelist_append(struct ceph_pagelist *pl, void *d, size_t l);
  19. static inline int ceph_pagelist_encode_64(struct ceph_pagelist *pl, u64 v)
  20. {
  21. __le64 ev = cpu_to_le64(v);
  22. return ceph_pagelist_append(pl, &ev, sizeof(ev));
  23. }
  24. static inline int ceph_pagelist_encode_32(struct ceph_pagelist *pl, u32 v)
  25. {
  26. __le32 ev = cpu_to_le32(v);
  27. return ceph_pagelist_append(pl, &ev, sizeof(ev));
  28. }
  29. static inline int ceph_pagelist_encode_16(struct ceph_pagelist *pl, u16 v)
  30. {
  31. __le16 ev = cpu_to_le16(v);
  32. return ceph_pagelist_append(pl, &ev, sizeof(ev));
  33. }
  34. static inline int ceph_pagelist_encode_8(struct ceph_pagelist *pl, u8 v)
  35. {
  36. return ceph_pagelist_append(pl, &v, 1);
  37. }
  38. static inline int ceph_pagelist_encode_string(struct ceph_pagelist *pl,
  39. char *s, size_t len)
  40. {
  41. int ret = ceph_pagelist_encode_32(pl, len);
  42. if (ret)
  43. return ret;
  44. if (len)
  45. return ceph_pagelist_append(pl, s, len);
  46. return 0;
  47. }
  48. #endif