rgrp.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
  4. *
  5. * This copyrighted material is made available to anyone wishing to use,
  6. * modify, copy, or redistribute it subject to the terms and conditions
  7. * of the GNU General Public License version 2.
  8. */
  9. #include <linux/slab.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/completion.h>
  12. #include <linux/buffer_head.h>
  13. #include <linux/fs.h>
  14. #include <linux/gfs2_ondisk.h>
  15. #include <linux/prefetch.h>
  16. #include <linux/blkdev.h>
  17. #include "gfs2.h"
  18. #include "incore.h"
  19. #include "glock.h"
  20. #include "glops.h"
  21. #include "lops.h"
  22. #include "meta_io.h"
  23. #include "quota.h"
  24. #include "rgrp.h"
  25. #include "super.h"
  26. #include "trans.h"
  27. #include "util.h"
  28. #include "log.h"
  29. #include "inode.h"
  30. #define BFITNOENT ((u32)~0)
  31. #define NO_BLOCK ((u64)~0)
  32. #if BITS_PER_LONG == 32
  33. #define LBITMASK (0x55555555UL)
  34. #define LBITSKIP55 (0x55555555UL)
  35. #define LBITSKIP00 (0x00000000UL)
  36. #else
  37. #define LBITMASK (0x5555555555555555UL)
  38. #define LBITSKIP55 (0x5555555555555555UL)
  39. #define LBITSKIP00 (0x0000000000000000UL)
  40. #endif
  41. /*
  42. * These routines are used by the resource group routines (rgrp.c)
  43. * to keep track of block allocation. Each block is represented by two
  44. * bits. So, each byte represents GFS2_NBBY (i.e. 4) blocks.
  45. *
  46. * 0 = Free
  47. * 1 = Used (not metadata)
  48. * 2 = Unlinked (still in use) inode
  49. * 3 = Used (metadata)
  50. */
  51. static const char valid_change[16] = {
  52. /* current */
  53. /* n */ 0, 1, 1, 1,
  54. /* e */ 1, 0, 0, 0,
  55. /* w */ 0, 0, 0, 1,
  56. 1, 0, 0, 0
  57. };
  58. static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
  59. unsigned char old_state, unsigned char new_state,
  60. unsigned int *n);
  61. /**
  62. * gfs2_setbit - Set a bit in the bitmaps
  63. * @buffer: the buffer that holds the bitmaps
  64. * @buflen: the length (in bytes) of the buffer
  65. * @block: the block to set
  66. * @new_state: the new state of the block
  67. *
  68. */
  69. static inline void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buf1,
  70. unsigned char *buf2, unsigned int offset,
  71. unsigned int buflen, u32 block,
  72. unsigned char new_state)
  73. {
  74. unsigned char *byte1, *byte2, *end, cur_state;
  75. const unsigned int bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE;
  76. byte1 = buf1 + offset + (block / GFS2_NBBY);
  77. end = buf1 + offset + buflen;
  78. BUG_ON(byte1 >= end);
  79. cur_state = (*byte1 >> bit) & GFS2_BIT_MASK;
  80. if (unlikely(!valid_change[new_state * 4 + cur_state])) {
  81. gfs2_consist_rgrpd(rgd);
  82. return;
  83. }
  84. *byte1 ^= (cur_state ^ new_state) << bit;
  85. if (buf2) {
  86. byte2 = buf2 + offset + (block / GFS2_NBBY);
  87. cur_state = (*byte2 >> bit) & GFS2_BIT_MASK;
  88. *byte2 ^= (cur_state ^ new_state) << bit;
  89. }
  90. }
  91. /**
  92. * gfs2_testbit - test a bit in the bitmaps
  93. * @buffer: the buffer that holds the bitmaps
  94. * @buflen: the length (in bytes) of the buffer
  95. * @block: the block to read
  96. *
  97. */
  98. static inline unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd,
  99. const unsigned char *buffer,
  100. unsigned int buflen, u32 block)
  101. {
  102. const unsigned char *byte, *end;
  103. unsigned char cur_state;
  104. unsigned int bit;
  105. byte = buffer + (block / GFS2_NBBY);
  106. bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE;
  107. end = buffer + buflen;
  108. gfs2_assert(rgd->rd_sbd, byte < end);
  109. cur_state = (*byte >> bit) & GFS2_BIT_MASK;
  110. return cur_state;
  111. }
  112. /**
  113. * gfs2_bit_search
  114. * @ptr: Pointer to bitmap data
  115. * @mask: Mask to use (normally 0x55555.... but adjusted for search start)
  116. * @state: The state we are searching for
  117. *
  118. * We xor the bitmap data with a patter which is the bitwise opposite
  119. * of what we are looking for, this gives rise to a pattern of ones
  120. * wherever there is a match. Since we have two bits per entry, we
  121. * take this pattern, shift it down by one place and then and it with
  122. * the original. All the even bit positions (0,2,4, etc) then represent
  123. * successful matches, so we mask with 0x55555..... to remove the unwanted
  124. * odd bit positions.
  125. *
  126. * This allows searching of a whole u64 at once (32 blocks) with a
  127. * single test (on 64 bit arches).
  128. */
  129. static inline u64 gfs2_bit_search(const __le64 *ptr, u64 mask, u8 state)
  130. {
  131. u64 tmp;
  132. static const u64 search[] = {
  133. [0] = 0xffffffffffffffffULL,
  134. [1] = 0xaaaaaaaaaaaaaaaaULL,
  135. [2] = 0x5555555555555555ULL,
  136. [3] = 0x0000000000000000ULL,
  137. };
  138. tmp = le64_to_cpu(*ptr) ^ search[state];
  139. tmp &= (tmp >> 1);
  140. tmp &= mask;
  141. return tmp;
  142. }
  143. /**
  144. * gfs2_bitfit - Search an rgrp's bitmap buffer to find a bit-pair representing
  145. * a block in a given allocation state.
  146. * @buffer: the buffer that holds the bitmaps
  147. * @len: the length (in bytes) of the buffer
  148. * @goal: start search at this block's bit-pair (within @buffer)
  149. * @state: GFS2_BLKST_XXX the state of the block we're looking for.
  150. *
  151. * Scope of @goal and returned block number is only within this bitmap buffer,
  152. * not entire rgrp or filesystem. @buffer will be offset from the actual
  153. * beginning of a bitmap block buffer, skipping any header structures, but
  154. * headers are always a multiple of 64 bits long so that the buffer is
  155. * always aligned to a 64 bit boundary.
  156. *
  157. * The size of the buffer is in bytes, but is it assumed that it is
  158. * always ok to to read a complete multiple of 64 bits at the end
  159. * of the block in case the end is no aligned to a natural boundary.
  160. *
  161. * Return: the block number (bitmap buffer scope) that was found
  162. */
  163. static u32 gfs2_bitfit(const u8 *buf, const unsigned int len,
  164. u32 goal, u8 state)
  165. {
  166. u32 spoint = (goal << 1) & ((8*sizeof(u64)) - 1);
  167. const __le64 *ptr = ((__le64 *)buf) + (goal >> 5);
  168. const __le64 *end = (__le64 *)(buf + ALIGN(len, sizeof(u64)));
  169. u64 tmp;
  170. u64 mask = 0x5555555555555555ULL;
  171. u32 bit;
  172. BUG_ON(state > 3);
  173. /* Mask off bits we don't care about at the start of the search */
  174. mask <<= spoint;
  175. tmp = gfs2_bit_search(ptr, mask, state);
  176. ptr++;
  177. while(tmp == 0 && ptr < end) {
  178. tmp = gfs2_bit_search(ptr, 0x5555555555555555ULL, state);
  179. ptr++;
  180. }
  181. /* Mask off any bits which are more than len bytes from the start */
  182. if (ptr == end && (len & (sizeof(u64) - 1)))
  183. tmp &= (((u64)~0) >> (64 - 8*(len & (sizeof(u64) - 1))));
  184. /* Didn't find anything, so return */
  185. if (tmp == 0)
  186. return BFITNOENT;
  187. ptr--;
  188. bit = __ffs64(tmp);
  189. bit /= 2; /* two bits per entry in the bitmap */
  190. return (((const unsigned char *)ptr - buf) * GFS2_NBBY) + bit;
  191. }
  192. /**
  193. * gfs2_bitcount - count the number of bits in a certain state
  194. * @buffer: the buffer that holds the bitmaps
  195. * @buflen: the length (in bytes) of the buffer
  196. * @state: the state of the block we're looking for
  197. *
  198. * Returns: The number of bits
  199. */
  200. static u32 gfs2_bitcount(struct gfs2_rgrpd *rgd, const u8 *buffer,
  201. unsigned int buflen, u8 state)
  202. {
  203. const u8 *byte = buffer;
  204. const u8 *end = buffer + buflen;
  205. const u8 state1 = state << 2;
  206. const u8 state2 = state << 4;
  207. const u8 state3 = state << 6;
  208. u32 count = 0;
  209. for (; byte < end; byte++) {
  210. if (((*byte) & 0x03) == state)
  211. count++;
  212. if (((*byte) & 0x0C) == state1)
  213. count++;
  214. if (((*byte) & 0x30) == state2)
  215. count++;
  216. if (((*byte) & 0xC0) == state3)
  217. count++;
  218. }
  219. return count;
  220. }
  221. /**
  222. * gfs2_rgrp_verify - Verify that a resource group is consistent
  223. * @sdp: the filesystem
  224. * @rgd: the rgrp
  225. *
  226. */
  227. void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd)
  228. {
  229. struct gfs2_sbd *sdp = rgd->rd_sbd;
  230. struct gfs2_bitmap *bi = NULL;
  231. u32 length = rgd->rd_length;
  232. u32 count[4], tmp;
  233. int buf, x;
  234. memset(count, 0, 4 * sizeof(u32));
  235. /* Count # blocks in each of 4 possible allocation states */
  236. for (buf = 0; buf < length; buf++) {
  237. bi = rgd->rd_bits + buf;
  238. for (x = 0; x < 4; x++)
  239. count[x] += gfs2_bitcount(rgd,
  240. bi->bi_bh->b_data +
  241. bi->bi_offset,
  242. bi->bi_len, x);
  243. }
  244. if (count[0] != rgd->rd_free) {
  245. if (gfs2_consist_rgrpd(rgd))
  246. fs_err(sdp, "free data mismatch: %u != %u\n",
  247. count[0], rgd->rd_free);
  248. return;
  249. }
  250. tmp = rgd->rd_data - rgd->rd_free - rgd->rd_dinodes;
  251. if (count[1] + count[2] != tmp) {
  252. if (gfs2_consist_rgrpd(rgd))
  253. fs_err(sdp, "used data mismatch: %u != %u\n",
  254. count[1], tmp);
  255. return;
  256. }
  257. if (count[3] != rgd->rd_dinodes) {
  258. if (gfs2_consist_rgrpd(rgd))
  259. fs_err(sdp, "used metadata mismatch: %u != %u\n",
  260. count[3], rgd->rd_dinodes);
  261. return;
  262. }
  263. if (count[2] > count[3]) {
  264. if (gfs2_consist_rgrpd(rgd))
  265. fs_err(sdp, "unlinked inodes > inodes: %u\n",
  266. count[2]);
  267. return;
  268. }
  269. }
  270. static inline int rgrp_contains_block(struct gfs2_rgrpd *rgd, u64 block)
  271. {
  272. u64 first = rgd->rd_data0;
  273. u64 last = first + rgd->rd_data;
  274. return first <= block && block < last;
  275. }
  276. /**
  277. * gfs2_blk2rgrpd - Find resource group for a given data/meta block number
  278. * @sdp: The GFS2 superblock
  279. * @n: The data block number
  280. *
  281. * Returns: The resource group, or NULL if not found
  282. */
  283. struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, u64 blk)
  284. {
  285. struct gfs2_rgrpd *rgd;
  286. spin_lock(&sdp->sd_rindex_spin);
  287. list_for_each_entry(rgd, &sdp->sd_rindex_mru_list, rd_list_mru) {
  288. if (rgrp_contains_block(rgd, blk)) {
  289. list_move(&rgd->rd_list_mru, &sdp->sd_rindex_mru_list);
  290. spin_unlock(&sdp->sd_rindex_spin);
  291. return rgd;
  292. }
  293. }
  294. spin_unlock(&sdp->sd_rindex_spin);
  295. return NULL;
  296. }
  297. /**
  298. * gfs2_rgrpd_get_first - get the first Resource Group in the filesystem
  299. * @sdp: The GFS2 superblock
  300. *
  301. * Returns: The first rgrp in the filesystem
  302. */
  303. struct gfs2_rgrpd *gfs2_rgrpd_get_first(struct gfs2_sbd *sdp)
  304. {
  305. gfs2_assert(sdp, !list_empty(&sdp->sd_rindex_list));
  306. return list_entry(sdp->sd_rindex_list.next, struct gfs2_rgrpd, rd_list);
  307. }
  308. /**
  309. * gfs2_rgrpd_get_next - get the next RG
  310. * @rgd: A RG
  311. *
  312. * Returns: The next rgrp
  313. */
  314. struct gfs2_rgrpd *gfs2_rgrpd_get_next(struct gfs2_rgrpd *rgd)
  315. {
  316. if (rgd->rd_list.next == &rgd->rd_sbd->sd_rindex_list)
  317. return NULL;
  318. return list_entry(rgd->rd_list.next, struct gfs2_rgrpd, rd_list);
  319. }
  320. static void clear_rgrpdi(struct gfs2_sbd *sdp)
  321. {
  322. struct list_head *head;
  323. struct gfs2_rgrpd *rgd;
  324. struct gfs2_glock *gl;
  325. spin_lock(&sdp->sd_rindex_spin);
  326. sdp->sd_rindex_forward = NULL;
  327. spin_unlock(&sdp->sd_rindex_spin);
  328. head = &sdp->sd_rindex_list;
  329. while (!list_empty(head)) {
  330. rgd = list_entry(head->next, struct gfs2_rgrpd, rd_list);
  331. gl = rgd->rd_gl;
  332. list_del(&rgd->rd_list);
  333. list_del(&rgd->rd_list_mru);
  334. if (gl) {
  335. gl->gl_object = NULL;
  336. gfs2_glock_put(gl);
  337. }
  338. kfree(rgd->rd_bits);
  339. kmem_cache_free(gfs2_rgrpd_cachep, rgd);
  340. }
  341. }
  342. void gfs2_clear_rgrpd(struct gfs2_sbd *sdp)
  343. {
  344. mutex_lock(&sdp->sd_rindex_mutex);
  345. clear_rgrpdi(sdp);
  346. mutex_unlock(&sdp->sd_rindex_mutex);
  347. }
  348. static void gfs2_rindex_print(const struct gfs2_rgrpd *rgd)
  349. {
  350. printk(KERN_INFO " ri_addr = %llu\n", (unsigned long long)rgd->rd_addr);
  351. printk(KERN_INFO " ri_length = %u\n", rgd->rd_length);
  352. printk(KERN_INFO " ri_data0 = %llu\n", (unsigned long long)rgd->rd_data0);
  353. printk(KERN_INFO " ri_data = %u\n", rgd->rd_data);
  354. printk(KERN_INFO " ri_bitbytes = %u\n", rgd->rd_bitbytes);
  355. }
  356. /**
  357. * gfs2_compute_bitstructs - Compute the bitmap sizes
  358. * @rgd: The resource group descriptor
  359. *
  360. * Calculates bitmap descriptors, one for each block that contains bitmap data
  361. *
  362. * Returns: errno
  363. */
  364. static int compute_bitstructs(struct gfs2_rgrpd *rgd)
  365. {
  366. struct gfs2_sbd *sdp = rgd->rd_sbd;
  367. struct gfs2_bitmap *bi;
  368. u32 length = rgd->rd_length; /* # blocks in hdr & bitmap */
  369. u32 bytes_left, bytes;
  370. int x;
  371. if (!length)
  372. return -EINVAL;
  373. rgd->rd_bits = kcalloc(length, sizeof(struct gfs2_bitmap), GFP_NOFS);
  374. if (!rgd->rd_bits)
  375. return -ENOMEM;
  376. bytes_left = rgd->rd_bitbytes;
  377. for (x = 0; x < length; x++) {
  378. bi = rgd->rd_bits + x;
  379. bi->bi_flags = 0;
  380. /* small rgrp; bitmap stored completely in header block */
  381. if (length == 1) {
  382. bytes = bytes_left;
  383. bi->bi_offset = sizeof(struct gfs2_rgrp);
  384. bi->bi_start = 0;
  385. bi->bi_len = bytes;
  386. /* header block */
  387. } else if (x == 0) {
  388. bytes = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_rgrp);
  389. bi->bi_offset = sizeof(struct gfs2_rgrp);
  390. bi->bi_start = 0;
  391. bi->bi_len = bytes;
  392. /* last block */
  393. } else if (x + 1 == length) {
  394. bytes = bytes_left;
  395. bi->bi_offset = sizeof(struct gfs2_meta_header);
  396. bi->bi_start = rgd->rd_bitbytes - bytes_left;
  397. bi->bi_len = bytes;
  398. /* other blocks */
  399. } else {
  400. bytes = sdp->sd_sb.sb_bsize -
  401. sizeof(struct gfs2_meta_header);
  402. bi->bi_offset = sizeof(struct gfs2_meta_header);
  403. bi->bi_start = rgd->rd_bitbytes - bytes_left;
  404. bi->bi_len = bytes;
  405. }
  406. bytes_left -= bytes;
  407. }
  408. if (bytes_left) {
  409. gfs2_consist_rgrpd(rgd);
  410. return -EIO;
  411. }
  412. bi = rgd->rd_bits + (length - 1);
  413. if ((bi->bi_start + bi->bi_len) * GFS2_NBBY != rgd->rd_data) {
  414. if (gfs2_consist_rgrpd(rgd)) {
  415. gfs2_rindex_print(rgd);
  416. fs_err(sdp, "start=%u len=%u offset=%u\n",
  417. bi->bi_start, bi->bi_len, bi->bi_offset);
  418. }
  419. return -EIO;
  420. }
  421. return 0;
  422. }
  423. /**
  424. * gfs2_ri_total - Total up the file system space, according to the rindex.
  425. *
  426. */
  427. u64 gfs2_ri_total(struct gfs2_sbd *sdp)
  428. {
  429. u64 total_data = 0;
  430. struct inode *inode = sdp->sd_rindex;
  431. struct gfs2_inode *ip = GFS2_I(inode);
  432. char buf[sizeof(struct gfs2_rindex)];
  433. struct file_ra_state ra_state;
  434. int error, rgrps;
  435. mutex_lock(&sdp->sd_rindex_mutex);
  436. file_ra_state_init(&ra_state, inode->i_mapping);
  437. for (rgrps = 0;; rgrps++) {
  438. loff_t pos = rgrps * sizeof(struct gfs2_rindex);
  439. if (pos + sizeof(struct gfs2_rindex) >= ip->i_disksize)
  440. break;
  441. error = gfs2_internal_read(ip, &ra_state, buf, &pos,
  442. sizeof(struct gfs2_rindex));
  443. if (error != sizeof(struct gfs2_rindex))
  444. break;
  445. total_data += be32_to_cpu(((struct gfs2_rindex *)buf)->ri_data);
  446. }
  447. mutex_unlock(&sdp->sd_rindex_mutex);
  448. return total_data;
  449. }
  450. static void gfs2_rindex_in(struct gfs2_rgrpd *rgd, const void *buf)
  451. {
  452. const struct gfs2_rindex *str = buf;
  453. rgd->rd_addr = be64_to_cpu(str->ri_addr);
  454. rgd->rd_length = be32_to_cpu(str->ri_length);
  455. rgd->rd_data0 = be64_to_cpu(str->ri_data0);
  456. rgd->rd_data = be32_to_cpu(str->ri_data);
  457. rgd->rd_bitbytes = be32_to_cpu(str->ri_bitbytes);
  458. }
  459. /**
  460. * read_rindex_entry - Pull in a new resource index entry from the disk
  461. * @gl: The glock covering the rindex inode
  462. *
  463. * Returns: 0 on success, error code otherwise
  464. */
  465. static int read_rindex_entry(struct gfs2_inode *ip,
  466. struct file_ra_state *ra_state)
  467. {
  468. struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  469. loff_t pos = sdp->sd_rgrps * sizeof(struct gfs2_rindex);
  470. char buf[sizeof(struct gfs2_rindex)];
  471. int error;
  472. struct gfs2_rgrpd *rgd;
  473. error = gfs2_internal_read(ip, ra_state, buf, &pos,
  474. sizeof(struct gfs2_rindex));
  475. if (!error)
  476. return 0;
  477. if (error != sizeof(struct gfs2_rindex)) {
  478. if (error > 0)
  479. error = -EIO;
  480. return error;
  481. }
  482. rgd = kmem_cache_zalloc(gfs2_rgrpd_cachep, GFP_NOFS);
  483. error = -ENOMEM;
  484. if (!rgd)
  485. return error;
  486. mutex_init(&rgd->rd_mutex);
  487. lops_init_le(&rgd->rd_le, &gfs2_rg_lops);
  488. rgd->rd_sbd = sdp;
  489. list_add_tail(&rgd->rd_list, &sdp->sd_rindex_list);
  490. list_add_tail(&rgd->rd_list_mru, &sdp->sd_rindex_mru_list);
  491. gfs2_rindex_in(rgd, buf);
  492. error = compute_bitstructs(rgd);
  493. if (error)
  494. return error;
  495. error = gfs2_glock_get(sdp, rgd->rd_addr,
  496. &gfs2_rgrp_glops, CREATE, &rgd->rd_gl);
  497. if (error)
  498. return error;
  499. rgd->rd_gl->gl_object = rgd;
  500. rgd->rd_flags &= ~GFS2_RDF_UPTODATE;
  501. return error;
  502. }
  503. /**
  504. * gfs2_ri_update - Pull in a new resource index from the disk
  505. * @ip: pointer to the rindex inode
  506. *
  507. * Returns: 0 on successful update, error code otherwise
  508. */
  509. static int gfs2_ri_update(struct gfs2_inode *ip)
  510. {
  511. struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  512. struct inode *inode = &ip->i_inode;
  513. struct file_ra_state ra_state;
  514. u64 rgrp_count = ip->i_disksize;
  515. int error;
  516. if (do_div(rgrp_count, sizeof(struct gfs2_rindex))) {
  517. gfs2_consist_inode(ip);
  518. return -EIO;
  519. }
  520. clear_rgrpdi(sdp);
  521. file_ra_state_init(&ra_state, inode->i_mapping);
  522. for (sdp->sd_rgrps = 0; sdp->sd_rgrps < rgrp_count; sdp->sd_rgrps++) {
  523. error = read_rindex_entry(ip, &ra_state);
  524. if (error) {
  525. clear_rgrpdi(sdp);
  526. return error;
  527. }
  528. }
  529. sdp->sd_rindex_uptodate = 1;
  530. return 0;
  531. }
  532. /**
  533. * gfs2_ri_update_special - Pull in a new resource index from the disk
  534. *
  535. * This is a special version that's safe to call from gfs2_inplace_reserve_i.
  536. * In this case we know that we don't have any resource groups in memory yet.
  537. *
  538. * @ip: pointer to the rindex inode
  539. *
  540. * Returns: 0 on successful update, error code otherwise
  541. */
  542. static int gfs2_ri_update_special(struct gfs2_inode *ip)
  543. {
  544. struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  545. struct inode *inode = &ip->i_inode;
  546. struct file_ra_state ra_state;
  547. int error;
  548. file_ra_state_init(&ra_state, inode->i_mapping);
  549. for (sdp->sd_rgrps = 0;; sdp->sd_rgrps++) {
  550. /* Ignore partials */
  551. if ((sdp->sd_rgrps + 1) * sizeof(struct gfs2_rindex) >
  552. ip->i_disksize)
  553. break;
  554. error = read_rindex_entry(ip, &ra_state);
  555. if (error) {
  556. clear_rgrpdi(sdp);
  557. return error;
  558. }
  559. }
  560. sdp->sd_rindex_uptodate = 1;
  561. return 0;
  562. }
  563. /**
  564. * gfs2_rindex_hold - Grab a lock on the rindex
  565. * @sdp: The GFS2 superblock
  566. * @ri_gh: the glock holder
  567. *
  568. * We grab a lock on the rindex inode to make sure that it doesn't
  569. * change whilst we are performing an operation. We keep this lock
  570. * for quite long periods of time compared to other locks. This
  571. * doesn't matter, since it is shared and it is very, very rarely
  572. * accessed in the exclusive mode (i.e. only when expanding the filesystem).
  573. *
  574. * This makes sure that we're using the latest copy of the resource index
  575. * special file, which might have been updated if someone expanded the
  576. * filesystem (via gfs2_grow utility), which adds new resource groups.
  577. *
  578. * Returns: 0 on success, error code otherwise
  579. */
  580. int gfs2_rindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ri_gh)
  581. {
  582. struct gfs2_inode *ip = GFS2_I(sdp->sd_rindex);
  583. struct gfs2_glock *gl = ip->i_gl;
  584. int error;
  585. error = gfs2_glock_nq_init(gl, LM_ST_SHARED, 0, ri_gh);
  586. if (error)
  587. return error;
  588. /* Read new copy from disk if we don't have the latest */
  589. if (!sdp->sd_rindex_uptodate) {
  590. mutex_lock(&sdp->sd_rindex_mutex);
  591. if (!sdp->sd_rindex_uptodate) {
  592. error = gfs2_ri_update(ip);
  593. if (error)
  594. gfs2_glock_dq_uninit(ri_gh);
  595. }
  596. mutex_unlock(&sdp->sd_rindex_mutex);
  597. }
  598. return error;
  599. }
  600. static void gfs2_rgrp_in(struct gfs2_rgrpd *rgd, const void *buf)
  601. {
  602. const struct gfs2_rgrp *str = buf;
  603. u32 rg_flags;
  604. rg_flags = be32_to_cpu(str->rg_flags);
  605. rg_flags &= ~GFS2_RDF_MASK;
  606. rgd->rd_flags &= GFS2_RDF_MASK;
  607. rgd->rd_flags |= rg_flags;
  608. rgd->rd_free = be32_to_cpu(str->rg_free);
  609. rgd->rd_dinodes = be32_to_cpu(str->rg_dinodes);
  610. rgd->rd_igeneration = be64_to_cpu(str->rg_igeneration);
  611. }
  612. static void gfs2_rgrp_out(struct gfs2_rgrpd *rgd, void *buf)
  613. {
  614. struct gfs2_rgrp *str = buf;
  615. str->rg_flags = cpu_to_be32(rgd->rd_flags & ~GFS2_RDF_MASK);
  616. str->rg_free = cpu_to_be32(rgd->rd_free);
  617. str->rg_dinodes = cpu_to_be32(rgd->rd_dinodes);
  618. str->__pad = cpu_to_be32(0);
  619. str->rg_igeneration = cpu_to_be64(rgd->rd_igeneration);
  620. memset(&str->rg_reserved, 0, sizeof(str->rg_reserved));
  621. }
  622. /**
  623. * gfs2_rgrp_bh_get - Read in a RG's header and bitmaps
  624. * @rgd: the struct gfs2_rgrpd describing the RG to read in
  625. *
  626. * Read in all of a Resource Group's header and bitmap blocks.
  627. * Caller must eventually call gfs2_rgrp_relse() to free the bitmaps.
  628. *
  629. * Returns: errno
  630. */
  631. int gfs2_rgrp_bh_get(struct gfs2_rgrpd *rgd)
  632. {
  633. struct gfs2_sbd *sdp = rgd->rd_sbd;
  634. struct gfs2_glock *gl = rgd->rd_gl;
  635. unsigned int length = rgd->rd_length;
  636. struct gfs2_bitmap *bi;
  637. unsigned int x, y;
  638. int error;
  639. mutex_lock(&rgd->rd_mutex);
  640. spin_lock(&sdp->sd_rindex_spin);
  641. if (rgd->rd_bh_count) {
  642. rgd->rd_bh_count++;
  643. spin_unlock(&sdp->sd_rindex_spin);
  644. mutex_unlock(&rgd->rd_mutex);
  645. return 0;
  646. }
  647. spin_unlock(&sdp->sd_rindex_spin);
  648. for (x = 0; x < length; x++) {
  649. bi = rgd->rd_bits + x;
  650. error = gfs2_meta_read(gl, rgd->rd_addr + x, 0, &bi->bi_bh);
  651. if (error)
  652. goto fail;
  653. }
  654. for (y = length; y--;) {
  655. bi = rgd->rd_bits + y;
  656. error = gfs2_meta_wait(sdp, bi->bi_bh);
  657. if (error)
  658. goto fail;
  659. if (gfs2_metatype_check(sdp, bi->bi_bh, y ? GFS2_METATYPE_RB :
  660. GFS2_METATYPE_RG)) {
  661. error = -EIO;
  662. goto fail;
  663. }
  664. }
  665. if (!(rgd->rd_flags & GFS2_RDF_UPTODATE)) {
  666. for (x = 0; x < length; x++)
  667. clear_bit(GBF_FULL, &rgd->rd_bits[x].bi_flags);
  668. gfs2_rgrp_in(rgd, (rgd->rd_bits[0].bi_bh)->b_data);
  669. rgd->rd_flags |= (GFS2_RDF_UPTODATE | GFS2_RDF_CHECK);
  670. }
  671. spin_lock(&sdp->sd_rindex_spin);
  672. rgd->rd_free_clone = rgd->rd_free;
  673. rgd->rd_bh_count++;
  674. spin_unlock(&sdp->sd_rindex_spin);
  675. mutex_unlock(&rgd->rd_mutex);
  676. return 0;
  677. fail:
  678. while (x--) {
  679. bi = rgd->rd_bits + x;
  680. brelse(bi->bi_bh);
  681. bi->bi_bh = NULL;
  682. gfs2_assert_warn(sdp, !bi->bi_clone);
  683. }
  684. mutex_unlock(&rgd->rd_mutex);
  685. return error;
  686. }
  687. void gfs2_rgrp_bh_hold(struct gfs2_rgrpd *rgd)
  688. {
  689. struct gfs2_sbd *sdp = rgd->rd_sbd;
  690. spin_lock(&sdp->sd_rindex_spin);
  691. gfs2_assert_warn(rgd->rd_sbd, rgd->rd_bh_count);
  692. rgd->rd_bh_count++;
  693. spin_unlock(&sdp->sd_rindex_spin);
  694. }
  695. /**
  696. * gfs2_rgrp_bh_put - Release RG bitmaps read in with gfs2_rgrp_bh_get()
  697. * @rgd: the struct gfs2_rgrpd describing the RG to read in
  698. *
  699. */
  700. void gfs2_rgrp_bh_put(struct gfs2_rgrpd *rgd)
  701. {
  702. struct gfs2_sbd *sdp = rgd->rd_sbd;
  703. int x, length = rgd->rd_length;
  704. spin_lock(&sdp->sd_rindex_spin);
  705. gfs2_assert_warn(rgd->rd_sbd, rgd->rd_bh_count);
  706. if (--rgd->rd_bh_count) {
  707. spin_unlock(&sdp->sd_rindex_spin);
  708. return;
  709. }
  710. for (x = 0; x < length; x++) {
  711. struct gfs2_bitmap *bi = rgd->rd_bits + x;
  712. kfree(bi->bi_clone);
  713. bi->bi_clone = NULL;
  714. brelse(bi->bi_bh);
  715. bi->bi_bh = NULL;
  716. }
  717. spin_unlock(&sdp->sd_rindex_spin);
  718. }
  719. static void gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset,
  720. const struct gfs2_bitmap *bi)
  721. {
  722. struct super_block *sb = sdp->sd_vfs;
  723. struct block_device *bdev = sb->s_bdev;
  724. const unsigned int sects_per_blk = sdp->sd_sb.sb_bsize /
  725. bdev_hardsect_size(sb->s_bdev);
  726. u64 blk;
  727. sector_t start = 0;
  728. sector_t nr_sects = 0;
  729. int rv;
  730. unsigned int x;
  731. for (x = 0; x < bi->bi_len; x++) {
  732. const u8 *orig = bi->bi_bh->b_data + bi->bi_offset + x;
  733. const u8 *clone = bi->bi_clone + bi->bi_offset + x;
  734. u8 diff = ~(*orig | (*orig >> 1)) & (*clone | (*clone >> 1));
  735. diff &= 0x55;
  736. if (diff == 0)
  737. continue;
  738. blk = offset + ((bi->bi_start + x) * GFS2_NBBY);
  739. blk *= sects_per_blk; /* convert to sectors */
  740. while(diff) {
  741. if (diff & 1) {
  742. if (nr_sects == 0)
  743. goto start_new_extent;
  744. if ((start + nr_sects) != blk) {
  745. rv = blkdev_issue_discard(bdev, start,
  746. nr_sects, GFP_NOFS);
  747. if (rv)
  748. goto fail;
  749. nr_sects = 0;
  750. start_new_extent:
  751. start = blk;
  752. }
  753. nr_sects += sects_per_blk;
  754. }
  755. diff >>= 2;
  756. blk += sects_per_blk;
  757. }
  758. }
  759. if (nr_sects) {
  760. rv = blkdev_issue_discard(bdev, start, nr_sects, GFP_NOFS);
  761. if (rv)
  762. goto fail;
  763. }
  764. return;
  765. fail:
  766. fs_warn(sdp, "error %d on discard request, turning discards off for this filesystem", rv);
  767. sdp->sd_args.ar_discard = 0;
  768. }
  769. void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd)
  770. {
  771. struct gfs2_sbd *sdp = rgd->rd_sbd;
  772. unsigned int length = rgd->rd_length;
  773. unsigned int x;
  774. for (x = 0; x < length; x++) {
  775. struct gfs2_bitmap *bi = rgd->rd_bits + x;
  776. if (!bi->bi_clone)
  777. continue;
  778. if (sdp->sd_args.ar_discard)
  779. gfs2_rgrp_send_discards(sdp, rgd->rd_data0, bi);
  780. clear_bit(GBF_FULL, &bi->bi_flags);
  781. memcpy(bi->bi_clone + bi->bi_offset,
  782. bi->bi_bh->b_data + bi->bi_offset, bi->bi_len);
  783. }
  784. spin_lock(&sdp->sd_rindex_spin);
  785. rgd->rd_free_clone = rgd->rd_free;
  786. spin_unlock(&sdp->sd_rindex_spin);
  787. }
  788. /**
  789. * gfs2_alloc_get - get the struct gfs2_alloc structure for an inode
  790. * @ip: the incore GFS2 inode structure
  791. *
  792. * Returns: the struct gfs2_alloc
  793. */
  794. struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip)
  795. {
  796. BUG_ON(ip->i_alloc != NULL);
  797. ip->i_alloc = kzalloc(sizeof(struct gfs2_alloc), GFP_KERNEL);
  798. return ip->i_alloc;
  799. }
  800. /**
  801. * try_rgrp_fit - See if a given reservation will fit in a given RG
  802. * @rgd: the RG data
  803. * @al: the struct gfs2_alloc structure describing the reservation
  804. *
  805. * If there's room for the requested blocks to be allocated from the RG:
  806. * Sets the $al_rgd field in @al.
  807. *
  808. * Returns: 1 on success (it fits), 0 on failure (it doesn't fit)
  809. */
  810. static int try_rgrp_fit(struct gfs2_rgrpd *rgd, struct gfs2_alloc *al)
  811. {
  812. struct gfs2_sbd *sdp = rgd->rd_sbd;
  813. int ret = 0;
  814. if (rgd->rd_flags & (GFS2_RGF_NOALLOC | GFS2_RDF_ERROR))
  815. return 0;
  816. spin_lock(&sdp->sd_rindex_spin);
  817. if (rgd->rd_free_clone >= al->al_requested) {
  818. al->al_rgd = rgd;
  819. ret = 1;
  820. }
  821. spin_unlock(&sdp->sd_rindex_spin);
  822. return ret;
  823. }
  824. /**
  825. * try_rgrp_unlink - Look for any unlinked, allocated, but unused inodes
  826. * @rgd: The rgrp
  827. *
  828. * Returns: The inode, if one has been found
  829. */
  830. static struct inode *try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked)
  831. {
  832. struct inode *inode;
  833. u32 goal = 0, block;
  834. u64 no_addr;
  835. struct gfs2_sbd *sdp = rgd->rd_sbd;
  836. unsigned int n;
  837. for(;;) {
  838. if (goal >= rgd->rd_data)
  839. break;
  840. down_write(&sdp->sd_log_flush_lock);
  841. n = 1;
  842. block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED,
  843. GFS2_BLKST_UNLINKED, &n);
  844. up_write(&sdp->sd_log_flush_lock);
  845. if (block == BFITNOENT)
  846. break;
  847. /* rgblk_search can return a block < goal, so we need to
  848. keep it marching forward. */
  849. no_addr = block + rgd->rd_data0;
  850. goal++;
  851. if (*last_unlinked != NO_BLOCK && no_addr <= *last_unlinked)
  852. continue;
  853. *last_unlinked = no_addr;
  854. inode = gfs2_inode_lookup(rgd->rd_sbd->sd_vfs, DT_UNKNOWN,
  855. no_addr, -1, 1);
  856. if (!IS_ERR(inode))
  857. return inode;
  858. }
  859. rgd->rd_flags &= ~GFS2_RDF_CHECK;
  860. return NULL;
  861. }
  862. /**
  863. * recent_rgrp_next - get next RG from "recent" list
  864. * @cur_rgd: current rgrp
  865. *
  866. * Returns: The next rgrp in the recent list
  867. */
  868. static struct gfs2_rgrpd *recent_rgrp_next(struct gfs2_rgrpd *cur_rgd)
  869. {
  870. struct gfs2_sbd *sdp = cur_rgd->rd_sbd;
  871. struct list_head *head;
  872. struct gfs2_rgrpd *rgd;
  873. spin_lock(&sdp->sd_rindex_spin);
  874. head = &sdp->sd_rindex_mru_list;
  875. if (unlikely(cur_rgd->rd_list_mru.next == head)) {
  876. spin_unlock(&sdp->sd_rindex_spin);
  877. return NULL;
  878. }
  879. rgd = list_entry(cur_rgd->rd_list_mru.next, struct gfs2_rgrpd, rd_list_mru);
  880. spin_unlock(&sdp->sd_rindex_spin);
  881. return rgd;
  882. }
  883. /**
  884. * forward_rgrp_get - get an rgrp to try next from full list
  885. * @sdp: The GFS2 superblock
  886. *
  887. * Returns: The rgrp to try next
  888. */
  889. static struct gfs2_rgrpd *forward_rgrp_get(struct gfs2_sbd *sdp)
  890. {
  891. struct gfs2_rgrpd *rgd;
  892. unsigned int journals = gfs2_jindex_size(sdp);
  893. unsigned int rg = 0, x;
  894. spin_lock(&sdp->sd_rindex_spin);
  895. rgd = sdp->sd_rindex_forward;
  896. if (!rgd) {
  897. if (sdp->sd_rgrps >= journals)
  898. rg = sdp->sd_rgrps * sdp->sd_jdesc->jd_jid / journals;
  899. for (x = 0, rgd = gfs2_rgrpd_get_first(sdp); x < rg;
  900. x++, rgd = gfs2_rgrpd_get_next(rgd))
  901. /* Do Nothing */;
  902. sdp->sd_rindex_forward = rgd;
  903. }
  904. spin_unlock(&sdp->sd_rindex_spin);
  905. return rgd;
  906. }
  907. /**
  908. * forward_rgrp_set - set the forward rgrp pointer
  909. * @sdp: the filesystem
  910. * @rgd: The new forward rgrp
  911. *
  912. */
  913. static void forward_rgrp_set(struct gfs2_sbd *sdp, struct gfs2_rgrpd *rgd)
  914. {
  915. spin_lock(&sdp->sd_rindex_spin);
  916. sdp->sd_rindex_forward = rgd;
  917. spin_unlock(&sdp->sd_rindex_spin);
  918. }
  919. /**
  920. * get_local_rgrp - Choose and lock a rgrp for allocation
  921. * @ip: the inode to reserve space for
  922. * @rgp: the chosen and locked rgrp
  923. *
  924. * Try to acquire rgrp in way which avoids contending with others.
  925. *
  926. * Returns: errno
  927. */
  928. static struct inode *get_local_rgrp(struct gfs2_inode *ip, u64 *last_unlinked)
  929. {
  930. struct inode *inode = NULL;
  931. struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  932. struct gfs2_rgrpd *rgd, *begin = NULL;
  933. struct gfs2_alloc *al = ip->i_alloc;
  934. int flags = LM_FLAG_TRY;
  935. int skipped = 0;
  936. int loops = 0;
  937. int error, rg_locked;
  938. rgd = gfs2_blk2rgrpd(sdp, ip->i_goal);
  939. while (rgd) {
  940. rg_locked = 0;
  941. if (gfs2_glock_is_locked_by_me(rgd->rd_gl)) {
  942. rg_locked = 1;
  943. error = 0;
  944. } else {
  945. error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE,
  946. LM_FLAG_TRY, &al->al_rgd_gh);
  947. }
  948. switch (error) {
  949. case 0:
  950. if (try_rgrp_fit(rgd, al))
  951. goto out;
  952. if (rgd->rd_flags & GFS2_RDF_CHECK)
  953. inode = try_rgrp_unlink(rgd, last_unlinked);
  954. if (!rg_locked)
  955. gfs2_glock_dq_uninit(&al->al_rgd_gh);
  956. if (inode)
  957. return inode;
  958. /* fall through */
  959. case GLR_TRYFAILED:
  960. rgd = recent_rgrp_next(rgd);
  961. break;
  962. default:
  963. return ERR_PTR(error);
  964. }
  965. }
  966. /* Go through full list of rgrps */
  967. begin = rgd = forward_rgrp_get(sdp);
  968. for (;;) {
  969. rg_locked = 0;
  970. if (gfs2_glock_is_locked_by_me(rgd->rd_gl)) {
  971. rg_locked = 1;
  972. error = 0;
  973. } else {
  974. error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, flags,
  975. &al->al_rgd_gh);
  976. }
  977. switch (error) {
  978. case 0:
  979. if (try_rgrp_fit(rgd, al))
  980. goto out;
  981. if (rgd->rd_flags & GFS2_RDF_CHECK)
  982. inode = try_rgrp_unlink(rgd, last_unlinked);
  983. if (!rg_locked)
  984. gfs2_glock_dq_uninit(&al->al_rgd_gh);
  985. if (inode)
  986. return inode;
  987. break;
  988. case GLR_TRYFAILED:
  989. skipped++;
  990. break;
  991. default:
  992. return ERR_PTR(error);
  993. }
  994. rgd = gfs2_rgrpd_get_next(rgd);
  995. if (!rgd)
  996. rgd = gfs2_rgrpd_get_first(sdp);
  997. if (rgd == begin) {
  998. if (++loops >= 3)
  999. return ERR_PTR(-ENOSPC);
  1000. if (!skipped)
  1001. loops++;
  1002. flags = 0;
  1003. if (loops == 2)
  1004. gfs2_log_flush(sdp, NULL);
  1005. }
  1006. }
  1007. out:
  1008. if (begin) {
  1009. spin_lock(&sdp->sd_rindex_spin);
  1010. list_move(&rgd->rd_list_mru, &sdp->sd_rindex_mru_list);
  1011. spin_unlock(&sdp->sd_rindex_spin);
  1012. rgd = gfs2_rgrpd_get_next(rgd);
  1013. if (!rgd)
  1014. rgd = gfs2_rgrpd_get_first(sdp);
  1015. forward_rgrp_set(sdp, rgd);
  1016. }
  1017. return NULL;
  1018. }
  1019. /**
  1020. * gfs2_inplace_reserve_i - Reserve space in the filesystem
  1021. * @ip: the inode to reserve space for
  1022. *
  1023. * Returns: errno
  1024. */
  1025. int gfs2_inplace_reserve_i(struct gfs2_inode *ip, char *file, unsigned int line)
  1026. {
  1027. struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  1028. struct gfs2_alloc *al = ip->i_alloc;
  1029. struct inode *inode;
  1030. int error = 0;
  1031. u64 last_unlinked = NO_BLOCK;
  1032. if (gfs2_assert_warn(sdp, al->al_requested))
  1033. return -EINVAL;
  1034. try_again:
  1035. /* We need to hold the rindex unless the inode we're using is
  1036. the rindex itself, in which case it's already held. */
  1037. if (ip != GFS2_I(sdp->sd_rindex))
  1038. error = gfs2_rindex_hold(sdp, &al->al_ri_gh);
  1039. else if (!sdp->sd_rgrps) /* We may not have the rindex read in, so: */
  1040. error = gfs2_ri_update_special(ip);
  1041. if (error)
  1042. return error;
  1043. inode = get_local_rgrp(ip, &last_unlinked);
  1044. if (inode) {
  1045. if (ip != GFS2_I(sdp->sd_rindex))
  1046. gfs2_glock_dq_uninit(&al->al_ri_gh);
  1047. if (IS_ERR(inode))
  1048. return PTR_ERR(inode);
  1049. iput(inode);
  1050. gfs2_log_flush(sdp, NULL);
  1051. goto try_again;
  1052. }
  1053. al->al_file = file;
  1054. al->al_line = line;
  1055. return 0;
  1056. }
  1057. /**
  1058. * gfs2_inplace_release - release an inplace reservation
  1059. * @ip: the inode the reservation was taken out on
  1060. *
  1061. * Release a reservation made by gfs2_inplace_reserve().
  1062. */
  1063. void gfs2_inplace_release(struct gfs2_inode *ip)
  1064. {
  1065. struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  1066. struct gfs2_alloc *al = ip->i_alloc;
  1067. if (gfs2_assert_warn(sdp, al->al_alloced <= al->al_requested) == -1)
  1068. fs_warn(sdp, "al_alloced = %u, al_requested = %u "
  1069. "al_file = %s, al_line = %u\n",
  1070. al->al_alloced, al->al_requested, al->al_file,
  1071. al->al_line);
  1072. al->al_rgd = NULL;
  1073. if (al->al_rgd_gh.gh_gl)
  1074. gfs2_glock_dq_uninit(&al->al_rgd_gh);
  1075. if (ip != GFS2_I(sdp->sd_rindex))
  1076. gfs2_glock_dq_uninit(&al->al_ri_gh);
  1077. }
  1078. /**
  1079. * gfs2_get_block_type - Check a block in a RG is of given type
  1080. * @rgd: the resource group holding the block
  1081. * @block: the block number
  1082. *
  1083. * Returns: The block type (GFS2_BLKST_*)
  1084. */
  1085. unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block)
  1086. {
  1087. struct gfs2_bitmap *bi = NULL;
  1088. u32 length, rgrp_block, buf_block;
  1089. unsigned int buf;
  1090. unsigned char type;
  1091. length = rgd->rd_length;
  1092. rgrp_block = block - rgd->rd_data0;
  1093. for (buf = 0; buf < length; buf++) {
  1094. bi = rgd->rd_bits + buf;
  1095. if (rgrp_block < (bi->bi_start + bi->bi_len) * GFS2_NBBY)
  1096. break;
  1097. }
  1098. gfs2_assert(rgd->rd_sbd, buf < length);
  1099. buf_block = rgrp_block - bi->bi_start * GFS2_NBBY;
  1100. type = gfs2_testbit(rgd, bi->bi_bh->b_data + bi->bi_offset,
  1101. bi->bi_len, buf_block);
  1102. return type;
  1103. }
  1104. /**
  1105. * rgblk_search - find a block in @old_state, change allocation
  1106. * state to @new_state
  1107. * @rgd: the resource group descriptor
  1108. * @goal: the goal block within the RG (start here to search for avail block)
  1109. * @old_state: GFS2_BLKST_XXX the before-allocation state to find
  1110. * @new_state: GFS2_BLKST_XXX the after-allocation block state
  1111. * @n: The extent length
  1112. *
  1113. * Walk rgrp's bitmap to find bits that represent a block in @old_state.
  1114. * Add the found bitmap buffer to the transaction.
  1115. * Set the found bits to @new_state to change block's allocation state.
  1116. *
  1117. * This function never fails, because we wouldn't call it unless we
  1118. * know (from reservation results, etc.) that a block is available.
  1119. *
  1120. * Scope of @goal and returned block is just within rgrp, not the whole
  1121. * filesystem.
  1122. *
  1123. * Returns: the block number allocated
  1124. */
  1125. static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
  1126. unsigned char old_state, unsigned char new_state,
  1127. unsigned int *n)
  1128. {
  1129. struct gfs2_bitmap *bi = NULL;
  1130. const u32 length = rgd->rd_length;
  1131. u32 blk = BFITNOENT;
  1132. unsigned int buf, x;
  1133. const unsigned int elen = *n;
  1134. const u8 *buffer = NULL;
  1135. *n = 0;
  1136. /* Find bitmap block that contains bits for goal block */
  1137. for (buf = 0; buf < length; buf++) {
  1138. bi = rgd->rd_bits + buf;
  1139. /* Convert scope of "goal" from rgrp-wide to within found bit block */
  1140. if (goal < (bi->bi_start + bi->bi_len) * GFS2_NBBY) {
  1141. goal -= bi->bi_start * GFS2_NBBY;
  1142. goto do_search;
  1143. }
  1144. }
  1145. buf = 0;
  1146. goal = 0;
  1147. do_search:
  1148. /* Search (up to entire) bitmap in this rgrp for allocatable block.
  1149. "x <= length", instead of "x < length", because we typically start
  1150. the search in the middle of a bit block, but if we can't find an
  1151. allocatable block anywhere else, we want to be able wrap around and
  1152. search in the first part of our first-searched bit block. */
  1153. for (x = 0; x <= length; x++) {
  1154. bi = rgd->rd_bits + buf;
  1155. if (test_bit(GBF_FULL, &bi->bi_flags) &&
  1156. (old_state == GFS2_BLKST_FREE))
  1157. goto skip;
  1158. /* The GFS2_BLKST_UNLINKED state doesn't apply to the clone
  1159. bitmaps, so we must search the originals for that. */
  1160. buffer = bi->bi_bh->b_data + bi->bi_offset;
  1161. if (old_state != GFS2_BLKST_UNLINKED && bi->bi_clone)
  1162. buffer = bi->bi_clone + bi->bi_offset;
  1163. blk = gfs2_bitfit(buffer, bi->bi_len, goal, old_state);
  1164. if (blk != BFITNOENT)
  1165. break;
  1166. if ((goal == 0) && (old_state == GFS2_BLKST_FREE))
  1167. set_bit(GBF_FULL, &bi->bi_flags);
  1168. /* Try next bitmap block (wrap back to rgrp header if at end) */
  1169. skip:
  1170. buf++;
  1171. buf %= length;
  1172. goal = 0;
  1173. }
  1174. if (blk == BFITNOENT)
  1175. return blk;
  1176. *n = 1;
  1177. if (old_state == new_state)
  1178. goto out;
  1179. gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1);
  1180. gfs2_setbit(rgd, bi->bi_bh->b_data, bi->bi_clone, bi->bi_offset,
  1181. bi->bi_len, blk, new_state);
  1182. goal = blk;
  1183. while (*n < elen) {
  1184. goal++;
  1185. if (goal >= (bi->bi_len * GFS2_NBBY))
  1186. break;
  1187. if (gfs2_testbit(rgd, buffer, bi->bi_len, goal) !=
  1188. GFS2_BLKST_FREE)
  1189. break;
  1190. gfs2_setbit(rgd, bi->bi_bh->b_data, bi->bi_clone, bi->bi_offset,
  1191. bi->bi_len, goal, new_state);
  1192. (*n)++;
  1193. }
  1194. out:
  1195. return (bi->bi_start * GFS2_NBBY) + blk;
  1196. }
  1197. /**
  1198. * rgblk_free - Change alloc state of given block(s)
  1199. * @sdp: the filesystem
  1200. * @bstart: the start of a run of blocks to free
  1201. * @blen: the length of the block run (all must lie within ONE RG!)
  1202. * @new_state: GFS2_BLKST_XXX the after-allocation block state
  1203. *
  1204. * Returns: Resource group containing the block(s)
  1205. */
  1206. static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart,
  1207. u32 blen, unsigned char new_state)
  1208. {
  1209. struct gfs2_rgrpd *rgd;
  1210. struct gfs2_bitmap *bi = NULL;
  1211. u32 length, rgrp_blk, buf_blk;
  1212. unsigned int buf;
  1213. rgd = gfs2_blk2rgrpd(sdp, bstart);
  1214. if (!rgd) {
  1215. if (gfs2_consist(sdp))
  1216. fs_err(sdp, "block = %llu\n", (unsigned long long)bstart);
  1217. return NULL;
  1218. }
  1219. length = rgd->rd_length;
  1220. rgrp_blk = bstart - rgd->rd_data0;
  1221. while (blen--) {
  1222. for (buf = 0; buf < length; buf++) {
  1223. bi = rgd->rd_bits + buf;
  1224. if (rgrp_blk < (bi->bi_start + bi->bi_len) * GFS2_NBBY)
  1225. break;
  1226. }
  1227. gfs2_assert(rgd->rd_sbd, buf < length);
  1228. buf_blk = rgrp_blk - bi->bi_start * GFS2_NBBY;
  1229. rgrp_blk++;
  1230. if (!bi->bi_clone) {
  1231. bi->bi_clone = kmalloc(bi->bi_bh->b_size,
  1232. GFP_NOFS | __GFP_NOFAIL);
  1233. memcpy(bi->bi_clone + bi->bi_offset,
  1234. bi->bi_bh->b_data + bi->bi_offset,
  1235. bi->bi_len);
  1236. }
  1237. gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1);
  1238. gfs2_setbit(rgd, bi->bi_bh->b_data, NULL, bi->bi_offset,
  1239. bi->bi_len, buf_blk, new_state);
  1240. }
  1241. return rgd;
  1242. }
  1243. /**
  1244. * gfs2_rgrp_dump - print out an rgrp
  1245. * @seq: The iterator
  1246. * @gl: The glock in question
  1247. *
  1248. */
  1249. int gfs2_rgrp_dump(struct seq_file *seq, const struct gfs2_glock *gl)
  1250. {
  1251. const struct gfs2_rgrpd *rgd = gl->gl_object;
  1252. if (rgd == NULL)
  1253. return 0;
  1254. gfs2_print_dbg(seq, " R: n:%llu f:%02x b:%u/%u i:%u\n",
  1255. (unsigned long long)rgd->rd_addr, rgd->rd_flags,
  1256. rgd->rd_free, rgd->rd_free_clone, rgd->rd_dinodes);
  1257. return 0;
  1258. }
  1259. /**
  1260. * gfs2_alloc_block - Allocate one or more blocks
  1261. * @ip: the inode to allocate the block for
  1262. * @bn: Used to return the starting block number
  1263. * @n: requested number of blocks/extent length (value/result)
  1264. *
  1265. * Returns: 0 or error
  1266. */
  1267. int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n)
  1268. {
  1269. struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  1270. struct buffer_head *dibh;
  1271. struct gfs2_alloc *al = ip->i_alloc;
  1272. struct gfs2_rgrpd *rgd = al->al_rgd;
  1273. u32 goal, blk;
  1274. u64 block;
  1275. int error;
  1276. if (rgrp_contains_block(rgd, ip->i_goal))
  1277. goal = ip->i_goal - rgd->rd_data0;
  1278. else
  1279. goal = rgd->rd_last_alloc;
  1280. blk = rgblk_search(rgd, goal, GFS2_BLKST_FREE, GFS2_BLKST_USED, n);
  1281. /* Since all blocks are reserved in advance, this shouldn't happen */
  1282. if (blk == BFITNOENT)
  1283. goto rgrp_error;
  1284. rgd->rd_last_alloc = blk;
  1285. block = rgd->rd_data0 + blk;
  1286. ip->i_goal = block;
  1287. error = gfs2_meta_inode_buffer(ip, &dibh);
  1288. if (error == 0) {
  1289. struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
  1290. gfs2_trans_add_bh(ip->i_gl, dibh, 1);
  1291. di->di_goal_meta = di->di_goal_data = cpu_to_be64(ip->i_goal);
  1292. brelse(dibh);
  1293. }
  1294. if (rgd->rd_free < *n)
  1295. goto rgrp_error;
  1296. rgd->rd_free -= *n;
  1297. gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1);
  1298. gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data);
  1299. al->al_alloced += *n;
  1300. gfs2_statfs_change(sdp, 0, -(s64)*n, 0);
  1301. gfs2_quota_change(ip, *n, ip->i_inode.i_uid, ip->i_inode.i_gid);
  1302. spin_lock(&sdp->sd_rindex_spin);
  1303. rgd->rd_free_clone -= *n;
  1304. spin_unlock(&sdp->sd_rindex_spin);
  1305. *bn = block;
  1306. return 0;
  1307. rgrp_error:
  1308. fs_warn(sdp, "rgrp %llu has an error, marking it readonly until umount\n",
  1309. (unsigned long long)rgd->rd_addr);
  1310. fs_warn(sdp, "umount on all nodes and run fsck.gfs2 to fix the error\n");
  1311. gfs2_rgrp_dump(NULL, rgd->rd_gl);
  1312. rgd->rd_flags |= GFS2_RDF_ERROR;
  1313. return -EIO;
  1314. }
  1315. /**
  1316. * gfs2_alloc_di - Allocate a dinode
  1317. * @dip: the directory that the inode is going in
  1318. *
  1319. * Returns: the block allocated
  1320. */
  1321. u64 gfs2_alloc_di(struct gfs2_inode *dip, u64 *generation)
  1322. {
  1323. struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
  1324. struct gfs2_alloc *al = dip->i_alloc;
  1325. struct gfs2_rgrpd *rgd = al->al_rgd;
  1326. u32 blk;
  1327. u64 block;
  1328. unsigned int n = 1;
  1329. blk = rgblk_search(rgd, rgd->rd_last_alloc,
  1330. GFS2_BLKST_FREE, GFS2_BLKST_DINODE, &n);
  1331. BUG_ON(blk == BFITNOENT);
  1332. rgd->rd_last_alloc = blk;
  1333. block = rgd->rd_data0 + blk;
  1334. gfs2_assert_withdraw(sdp, rgd->rd_free);
  1335. rgd->rd_free--;
  1336. rgd->rd_dinodes++;
  1337. *generation = rgd->rd_igeneration++;
  1338. gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1);
  1339. gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data);
  1340. al->al_alloced++;
  1341. gfs2_statfs_change(sdp, 0, -1, +1);
  1342. gfs2_trans_add_unrevoke(sdp, block, 1);
  1343. spin_lock(&sdp->sd_rindex_spin);
  1344. rgd->rd_free_clone--;
  1345. spin_unlock(&sdp->sd_rindex_spin);
  1346. return block;
  1347. }
  1348. /**
  1349. * gfs2_free_data - free a contiguous run of data block(s)
  1350. * @ip: the inode these blocks are being freed from
  1351. * @bstart: first block of a run of contiguous blocks
  1352. * @blen: the length of the block run
  1353. *
  1354. */
  1355. void gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen)
  1356. {
  1357. struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  1358. struct gfs2_rgrpd *rgd;
  1359. rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE);
  1360. if (!rgd)
  1361. return;
  1362. rgd->rd_free += blen;
  1363. gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1);
  1364. gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data);
  1365. gfs2_trans_add_rg(rgd);
  1366. gfs2_statfs_change(sdp, 0, +blen, 0);
  1367. gfs2_quota_change(ip, -(s64)blen, ip->i_inode.i_uid, ip->i_inode.i_gid);
  1368. }
  1369. /**
  1370. * gfs2_free_meta - free a contiguous run of data block(s)
  1371. * @ip: the inode these blocks are being freed from
  1372. * @bstart: first block of a run of contiguous blocks
  1373. * @blen: the length of the block run
  1374. *
  1375. */
  1376. void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen)
  1377. {
  1378. struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  1379. struct gfs2_rgrpd *rgd;
  1380. rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE);
  1381. if (!rgd)
  1382. return;
  1383. rgd->rd_free += blen;
  1384. gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1);
  1385. gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data);
  1386. gfs2_trans_add_rg(rgd);
  1387. gfs2_statfs_change(sdp, 0, +blen, 0);
  1388. gfs2_quota_change(ip, -(s64)blen, ip->i_inode.i_uid, ip->i_inode.i_gid);
  1389. gfs2_meta_wipe(ip, bstart, blen);
  1390. }
  1391. void gfs2_unlink_di(struct inode *inode)
  1392. {
  1393. struct gfs2_inode *ip = GFS2_I(inode);
  1394. struct gfs2_sbd *sdp = GFS2_SB(inode);
  1395. struct gfs2_rgrpd *rgd;
  1396. u64 blkno = ip->i_no_addr;
  1397. rgd = rgblk_free(sdp, blkno, 1, GFS2_BLKST_UNLINKED);
  1398. if (!rgd)
  1399. return;
  1400. gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1);
  1401. gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data);
  1402. gfs2_trans_add_rg(rgd);
  1403. }
  1404. static void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, u64 blkno)
  1405. {
  1406. struct gfs2_sbd *sdp = rgd->rd_sbd;
  1407. struct gfs2_rgrpd *tmp_rgd;
  1408. tmp_rgd = rgblk_free(sdp, blkno, 1, GFS2_BLKST_FREE);
  1409. if (!tmp_rgd)
  1410. return;
  1411. gfs2_assert_withdraw(sdp, rgd == tmp_rgd);
  1412. if (!rgd->rd_dinodes)
  1413. gfs2_consist_rgrpd(rgd);
  1414. rgd->rd_dinodes--;
  1415. rgd->rd_free++;
  1416. gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1);
  1417. gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data);
  1418. gfs2_statfs_change(sdp, 0, +1, -1);
  1419. gfs2_trans_add_rg(rgd);
  1420. }
  1421. void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip)
  1422. {
  1423. gfs2_free_uninit_di(rgd, ip->i_no_addr);
  1424. gfs2_quota_change(ip, -1, ip->i_inode.i_uid, ip->i_inode.i_gid);
  1425. gfs2_meta_wipe(ip, ip->i_no_addr, 1);
  1426. }
  1427. /**
  1428. * gfs2_rlist_add - add a RG to a list of RGs
  1429. * @sdp: the filesystem
  1430. * @rlist: the list of resource groups
  1431. * @block: the block
  1432. *
  1433. * Figure out what RG a block belongs to and add that RG to the list
  1434. *
  1435. * FIXME: Don't use NOFAIL
  1436. *
  1437. */
  1438. void gfs2_rlist_add(struct gfs2_sbd *sdp, struct gfs2_rgrp_list *rlist,
  1439. u64 block)
  1440. {
  1441. struct gfs2_rgrpd *rgd;
  1442. struct gfs2_rgrpd **tmp;
  1443. unsigned int new_space;
  1444. unsigned int x;
  1445. if (gfs2_assert_warn(sdp, !rlist->rl_ghs))
  1446. return;
  1447. rgd = gfs2_blk2rgrpd(sdp, block);
  1448. if (!rgd) {
  1449. if (gfs2_consist(sdp))
  1450. fs_err(sdp, "block = %llu\n", (unsigned long long)block);
  1451. return;
  1452. }
  1453. for (x = 0; x < rlist->rl_rgrps; x++)
  1454. if (rlist->rl_rgd[x] == rgd)
  1455. return;
  1456. if (rlist->rl_rgrps == rlist->rl_space) {
  1457. new_space = rlist->rl_space + 10;
  1458. tmp = kcalloc(new_space, sizeof(struct gfs2_rgrpd *),
  1459. GFP_NOFS | __GFP_NOFAIL);
  1460. if (rlist->rl_rgd) {
  1461. memcpy(tmp, rlist->rl_rgd,
  1462. rlist->rl_space * sizeof(struct gfs2_rgrpd *));
  1463. kfree(rlist->rl_rgd);
  1464. }
  1465. rlist->rl_space = new_space;
  1466. rlist->rl_rgd = tmp;
  1467. }
  1468. rlist->rl_rgd[rlist->rl_rgrps++] = rgd;
  1469. }
  1470. /**
  1471. * gfs2_rlist_alloc - all RGs have been added to the rlist, now allocate
  1472. * and initialize an array of glock holders for them
  1473. * @rlist: the list of resource groups
  1474. * @state: the lock state to acquire the RG lock in
  1475. * @flags: the modifier flags for the holder structures
  1476. *
  1477. * FIXME: Don't use NOFAIL
  1478. *
  1479. */
  1480. void gfs2_rlist_alloc(struct gfs2_rgrp_list *rlist, unsigned int state)
  1481. {
  1482. unsigned int x;
  1483. rlist->rl_ghs = kcalloc(rlist->rl_rgrps, sizeof(struct gfs2_holder),
  1484. GFP_NOFS | __GFP_NOFAIL);
  1485. for (x = 0; x < rlist->rl_rgrps; x++)
  1486. gfs2_holder_init(rlist->rl_rgd[x]->rd_gl,
  1487. state, 0,
  1488. &rlist->rl_ghs[x]);
  1489. }
  1490. /**
  1491. * gfs2_rlist_free - free a resource group list
  1492. * @list: the list of resource groups
  1493. *
  1494. */
  1495. void gfs2_rlist_free(struct gfs2_rgrp_list *rlist)
  1496. {
  1497. unsigned int x;
  1498. kfree(rlist->rl_rgd);
  1499. if (rlist->rl_ghs) {
  1500. for (x = 0; x < rlist->rl_rgrps; x++)
  1501. gfs2_holder_uninit(&rlist->rl_ghs[x]);
  1502. kfree(rlist->rl_ghs);
  1503. }
  1504. }