reservations.h 4.7 KB

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