reservations.h 5.1 KB

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