reservations.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* -*- mode: c; c-basic-offset: 8; -*-
  3. * vim: noexpandtab sw=8 ts=8 sts=0:
  4. *
  5. * reservations.h
  6. *
  7. * Allocation reservations function prototypes and structures.
  8. *
  9. * Copyright (C) 2010 Novell. All rights reserved.
  10. */
  11. #ifndef OCFS2_RESERVATIONS_H
  12. #define OCFS2_RESERVATIONS_H
  13. #include <linux/rbtree.h>
  14. #define OCFS2_DEFAULT_RESV_LEVEL 2
  15. #define OCFS2_MAX_RESV_LEVEL 9
  16. #define OCFS2_MIN_RESV_LEVEL 0
  17. struct ocfs2_alloc_reservation {
  18. struct rb_node r_node;
  19. unsigned int r_start; /* Beginning of current window */
  20. unsigned int r_len; /* Length of the window */
  21. unsigned int r_last_len; /* Length of most recent alloc */
  22. unsigned int r_last_start; /* Start of most recent alloc */
  23. struct list_head r_lru; /* LRU list head */
  24. unsigned int r_flags;
  25. };
  26. #define OCFS2_RESV_FLAG_INUSE 0x01 /* Set when r_node is part of a btree */
  27. #define OCFS2_RESV_FLAG_TMP 0x02 /* Temporary reservation, will be
  28. * destroyed immedately after use */
  29. #define OCFS2_RESV_FLAG_DIR 0x04 /* Reservation is for an unindexed
  30. * directory btree */
  31. struct ocfs2_reservation_map {
  32. struct rb_root m_reservations;
  33. char *m_disk_bitmap;
  34. struct ocfs2_super *m_osb;
  35. /* The following are not initialized to meaningful values until a disk
  36. * bitmap is provided. */
  37. u32 m_bitmap_len; /* Number of valid
  38. * bits available */
  39. struct list_head m_lru; /* LRU of reservations
  40. * structures. */
  41. };
  42. void ocfs2_resv_init_once(struct ocfs2_alloc_reservation *resv);
  43. #define OCFS2_RESV_TYPES (OCFS2_RESV_FLAG_TMP|OCFS2_RESV_FLAG_DIR)
  44. void ocfs2_resv_set_type(struct ocfs2_alloc_reservation *resv,
  45. unsigned int flags);
  46. int ocfs2_dir_resv_allowed(struct ocfs2_super *osb);
  47. /**
  48. * ocfs2_resv_discard() - truncate a reservation
  49. * @resmap:
  50. * @resv: the reservation to truncate.
  51. *
  52. * After this function is called, the reservation will be empty, and
  53. * unlinked from the rbtree.
  54. */
  55. void ocfs2_resv_discard(struct ocfs2_reservation_map *resmap,
  56. struct ocfs2_alloc_reservation *resv);
  57. /**
  58. * ocfs2_resmap_init() - Initialize fields of a reservations bitmap
  59. * @resmap: struct ocfs2_reservation_map to initialize
  60. * @obj: unused for now
  61. * @ops: unused for now
  62. * @max_bitmap_bytes: Maximum size of the bitmap (typically blocksize)
  63. *
  64. * Only possible return value other than '0' is -ENOMEM for failure to
  65. * allocation mirror bitmap.
  66. */
  67. int ocfs2_resmap_init(struct ocfs2_super *osb,
  68. struct ocfs2_reservation_map *resmap);
  69. /**
  70. * ocfs2_resmap_restart() - "restart" a reservation bitmap
  71. * @resmap: reservations bitmap
  72. * @clen: Number of valid bits in the bitmap
  73. * @disk_bitmap: the disk bitmap this resmap should refer to.
  74. *
  75. * Re-initialize the parameters of a reservation bitmap. This is
  76. * useful for local alloc window slides.
  77. *
  78. * This function will call ocfs2_trunc_resv against all existing
  79. * reservations. A future version will recalculate existing
  80. * reservations based on the new bitmap.
  81. */
  82. void ocfs2_resmap_restart(struct ocfs2_reservation_map *resmap,
  83. unsigned int clen, char *disk_bitmap);
  84. /**
  85. * ocfs2_resmap_uninit() - uninitialize a reservation bitmap structure
  86. * @resmap: the struct ocfs2_reservation_map to uninitialize
  87. */
  88. void ocfs2_resmap_uninit(struct ocfs2_reservation_map *resmap);
  89. /**
  90. * ocfs2_resmap_resv_bits() - Return still-valid reservation bits
  91. * @resmap: reservations bitmap
  92. * @resv: reservation to base search from
  93. * @cstart: start of proposed allocation
  94. * @clen: length (in clusters) of proposed allocation
  95. *
  96. * Using the reservation data from resv, this function will compare
  97. * resmap and resmap->m_disk_bitmap to determine what part (if any) of
  98. * the reservation window is still clear to use. If resv is empty,
  99. * this function will try to allocate a window for it.
  100. *
  101. * On success, zero is returned and the valid allocation area is set in cstart
  102. * and clen.
  103. *
  104. * Returns -ENOSPC if reservations are disabled.
  105. */
  106. int ocfs2_resmap_resv_bits(struct ocfs2_reservation_map *resmap,
  107. struct ocfs2_alloc_reservation *resv,
  108. int *cstart, int *clen);
  109. /**
  110. * ocfs2_resmap_claimed_bits() - Tell the reservation code that bits were used.
  111. * @resmap: reservations bitmap
  112. * @resv: optional reservation to recalulate based on new bitmap
  113. * @cstart: start of allocation in clusters
  114. * @clen: end of allocation in clusters.
  115. *
  116. * Tell the reservation code that bits were used to fulfill allocation in
  117. * resmap. The bits don't have to have been part of any existing
  118. * reservation. But we must always call this function when bits are claimed.
  119. * Internally, the reservations code will use this information to mark the
  120. * reservations bitmap. If resv is passed, it's next allocation window will be
  121. * calculated. It also expects that 'cstart' is the same as we passed back
  122. * from ocfs2_resmap_resv_bits().
  123. */
  124. void ocfs2_resmap_claimed_bits(struct ocfs2_reservation_map *resmap,
  125. struct ocfs2_alloc_reservation *resv,
  126. u32 cstart, u32 clen);
  127. #endif /* OCFS2_RESERVATIONS_H */