quota.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2007 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. /*
  10. * Quota change tags are associated with each transaction that allocates or
  11. * deallocates space. Those changes are accumulated locally to each node (in a
  12. * per-node file) and then are periodically synced to the quota file. This
  13. * avoids the bottleneck of constantly touching the quota file, but introduces
  14. * fuzziness in the current usage value of IDs that are being used on different
  15. * nodes in the cluster simultaneously. So, it is possible for a user on
  16. * multiple nodes to overrun their quota, but that overrun is controlable.
  17. * Since quota tags are part of transactions, there is no need to a quota check
  18. * program to be run on node crashes or anything like that.
  19. *
  20. * There are couple of knobs that let the administrator manage the quota
  21. * fuzziness. "quota_quantum" sets the maximum time a quota change can be
  22. * sitting on one node before being synced to the quota file. (The default is
  23. * 60 seconds.) Another knob, "quota_scale" controls how quickly the frequency
  24. * of quota file syncs increases as the user moves closer to their limit. The
  25. * more frequent the syncs, the more accurate the quota enforcement, but that
  26. * means that there is more contention between the nodes for the quota file.
  27. * The default value is one. This sets the maximum theoretical quota overrun
  28. * (with infinite node with infinite bandwidth) to twice the user's limit. (In
  29. * practice, the maximum overrun you see should be much less.) A "quota_scale"
  30. * number greater than one makes quota syncs more frequent and reduces the
  31. * maximum overrun. Numbers less than one (but greater than zero) make quota
  32. * syncs less frequent.
  33. *
  34. * GFS quotas also use per-ID Lock Value Blocks (LVBs) to cache the contents of
  35. * the quota file, so it is not being constantly read.
  36. */
  37. #include <linux/sched.h>
  38. #include <linux/slab.h>
  39. #include <linux/spinlock.h>
  40. #include <linux/completion.h>
  41. #include <linux/buffer_head.h>
  42. #include <linux/sort.h>
  43. #include <linux/fs.h>
  44. #include <linux/bio.h>
  45. #include <linux/gfs2_ondisk.h>
  46. #include <linux/lm_interface.h>
  47. #include "gfs2.h"
  48. #include "incore.h"
  49. #include "bmap.h"
  50. #include "glock.h"
  51. #include "glops.h"
  52. #include "log.h"
  53. #include "meta_io.h"
  54. #include "quota.h"
  55. #include "rgrp.h"
  56. #include "super.h"
  57. #include "trans.h"
  58. #include "inode.h"
  59. #include "ops_address.h"
  60. #include "util.h"
  61. #define QUOTA_USER 1
  62. #define QUOTA_GROUP 0
  63. struct gfs2_quota_host {
  64. u64 qu_limit;
  65. u64 qu_warn;
  66. s64 qu_value;
  67. u32 qu_ll_next;
  68. };
  69. struct gfs2_quota_change_host {
  70. u64 qc_change;
  71. u32 qc_flags; /* GFS2_QCF_... */
  72. u32 qc_id;
  73. };
  74. static u64 qd2offset(struct gfs2_quota_data *qd)
  75. {
  76. u64 offset;
  77. offset = 2 * (u64)qd->qd_id + !test_bit(QDF_USER, &qd->qd_flags);
  78. offset *= sizeof(struct gfs2_quota);
  79. return offset;
  80. }
  81. static int qd_alloc(struct gfs2_sbd *sdp, int user, u32 id,
  82. struct gfs2_quota_data **qdp)
  83. {
  84. struct gfs2_quota_data *qd;
  85. int error;
  86. qd = kzalloc(sizeof(struct gfs2_quota_data), GFP_KERNEL);
  87. if (!qd)
  88. return -ENOMEM;
  89. qd->qd_count = 1;
  90. qd->qd_id = id;
  91. if (user)
  92. set_bit(QDF_USER, &qd->qd_flags);
  93. qd->qd_slot = -1;
  94. error = gfs2_glock_get(sdp, 2 * (u64)id + !user,
  95. &gfs2_quota_glops, CREATE, &qd->qd_gl);
  96. if (error)
  97. goto fail;
  98. error = gfs2_lvb_hold(qd->qd_gl);
  99. gfs2_glock_put(qd->qd_gl);
  100. if (error)
  101. goto fail;
  102. *qdp = qd;
  103. return 0;
  104. fail:
  105. kfree(qd);
  106. return error;
  107. }
  108. static int qd_get(struct gfs2_sbd *sdp, int user, u32 id, int create,
  109. struct gfs2_quota_data **qdp)
  110. {
  111. struct gfs2_quota_data *qd = NULL, *new_qd = NULL;
  112. int error, found;
  113. *qdp = NULL;
  114. for (;;) {
  115. found = 0;
  116. spin_lock(&sdp->sd_quota_spin);
  117. list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) {
  118. if (qd->qd_id == id &&
  119. !test_bit(QDF_USER, &qd->qd_flags) == !user) {
  120. qd->qd_count++;
  121. found = 1;
  122. break;
  123. }
  124. }
  125. if (!found)
  126. qd = NULL;
  127. if (!qd && new_qd) {
  128. qd = new_qd;
  129. list_add(&qd->qd_list, &sdp->sd_quota_list);
  130. atomic_inc(&sdp->sd_quota_count);
  131. new_qd = NULL;
  132. }
  133. spin_unlock(&sdp->sd_quota_spin);
  134. if (qd || !create) {
  135. if (new_qd) {
  136. gfs2_lvb_unhold(new_qd->qd_gl);
  137. kfree(new_qd);
  138. }
  139. *qdp = qd;
  140. return 0;
  141. }
  142. error = qd_alloc(sdp, user, id, &new_qd);
  143. if (error)
  144. return error;
  145. }
  146. }
  147. static void qd_hold(struct gfs2_quota_data *qd)
  148. {
  149. struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
  150. spin_lock(&sdp->sd_quota_spin);
  151. gfs2_assert(sdp, qd->qd_count);
  152. qd->qd_count++;
  153. spin_unlock(&sdp->sd_quota_spin);
  154. }
  155. static void qd_put(struct gfs2_quota_data *qd)
  156. {
  157. struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
  158. spin_lock(&sdp->sd_quota_spin);
  159. gfs2_assert(sdp, qd->qd_count);
  160. if (!--qd->qd_count)
  161. qd->qd_last_touched = jiffies;
  162. spin_unlock(&sdp->sd_quota_spin);
  163. }
  164. static int slot_get(struct gfs2_quota_data *qd)
  165. {
  166. struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
  167. unsigned int c, o = 0, b;
  168. unsigned char byte = 0;
  169. spin_lock(&sdp->sd_quota_spin);
  170. if (qd->qd_slot_count++) {
  171. spin_unlock(&sdp->sd_quota_spin);
  172. return 0;
  173. }
  174. for (c = 0; c < sdp->sd_quota_chunks; c++)
  175. for (o = 0; o < PAGE_SIZE; o++) {
  176. byte = sdp->sd_quota_bitmap[c][o];
  177. if (byte != 0xFF)
  178. goto found;
  179. }
  180. goto fail;
  181. found:
  182. for (b = 0; b < 8; b++)
  183. if (!(byte & (1 << b)))
  184. break;
  185. qd->qd_slot = c * (8 * PAGE_SIZE) + o * 8 + b;
  186. if (qd->qd_slot >= sdp->sd_quota_slots)
  187. goto fail;
  188. sdp->sd_quota_bitmap[c][o] |= 1 << b;
  189. spin_unlock(&sdp->sd_quota_spin);
  190. return 0;
  191. fail:
  192. qd->qd_slot_count--;
  193. spin_unlock(&sdp->sd_quota_spin);
  194. return -ENOSPC;
  195. }
  196. static void slot_hold(struct gfs2_quota_data *qd)
  197. {
  198. struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
  199. spin_lock(&sdp->sd_quota_spin);
  200. gfs2_assert(sdp, qd->qd_slot_count);
  201. qd->qd_slot_count++;
  202. spin_unlock(&sdp->sd_quota_spin);
  203. }
  204. static void slot_put(struct gfs2_quota_data *qd)
  205. {
  206. struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
  207. spin_lock(&sdp->sd_quota_spin);
  208. gfs2_assert(sdp, qd->qd_slot_count);
  209. if (!--qd->qd_slot_count) {
  210. gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, qd->qd_slot, 0);
  211. qd->qd_slot = -1;
  212. }
  213. spin_unlock(&sdp->sd_quota_spin);
  214. }
  215. static int bh_get(struct gfs2_quota_data *qd)
  216. {
  217. struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
  218. struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode);
  219. unsigned int block, offset;
  220. struct buffer_head *bh;
  221. int error;
  222. struct buffer_head bh_map = { .b_state = 0, .b_blocknr = 0 };
  223. mutex_lock(&sdp->sd_quota_mutex);
  224. if (qd->qd_bh_count++) {
  225. mutex_unlock(&sdp->sd_quota_mutex);
  226. return 0;
  227. }
  228. block = qd->qd_slot / sdp->sd_qc_per_block;
  229. offset = qd->qd_slot % sdp->sd_qc_per_block;
  230. bh_map.b_size = 1 << ip->i_inode.i_blkbits;
  231. error = gfs2_block_map(&ip->i_inode, block, &bh_map, 0);
  232. if (error)
  233. goto fail;
  234. error = gfs2_meta_read(ip->i_gl, bh_map.b_blocknr, DIO_WAIT, &bh);
  235. if (error)
  236. goto fail;
  237. error = -EIO;
  238. if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_QC))
  239. goto fail_brelse;
  240. qd->qd_bh = bh;
  241. qd->qd_bh_qc = (struct gfs2_quota_change *)
  242. (bh->b_data + sizeof(struct gfs2_meta_header) +
  243. offset * sizeof(struct gfs2_quota_change));
  244. mutex_unlock(&sdp->sd_quota_mutex);
  245. return 0;
  246. fail_brelse:
  247. brelse(bh);
  248. fail:
  249. qd->qd_bh_count--;
  250. mutex_unlock(&sdp->sd_quota_mutex);
  251. return error;
  252. }
  253. static void bh_put(struct gfs2_quota_data *qd)
  254. {
  255. struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
  256. mutex_lock(&sdp->sd_quota_mutex);
  257. gfs2_assert(sdp, qd->qd_bh_count);
  258. if (!--qd->qd_bh_count) {
  259. brelse(qd->qd_bh);
  260. qd->qd_bh = NULL;
  261. qd->qd_bh_qc = NULL;
  262. }
  263. mutex_unlock(&sdp->sd_quota_mutex);
  264. }
  265. static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
  266. {
  267. struct gfs2_quota_data *qd = NULL;
  268. int error;
  269. int found = 0;
  270. *qdp = NULL;
  271. if (sdp->sd_vfs->s_flags & MS_RDONLY)
  272. return 0;
  273. spin_lock(&sdp->sd_quota_spin);
  274. list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) {
  275. if (test_bit(QDF_LOCKED, &qd->qd_flags) ||
  276. !test_bit(QDF_CHANGE, &qd->qd_flags) ||
  277. qd->qd_sync_gen >= sdp->sd_quota_sync_gen)
  278. continue;
  279. list_move_tail(&qd->qd_list, &sdp->sd_quota_list);
  280. set_bit(QDF_LOCKED, &qd->qd_flags);
  281. gfs2_assert_warn(sdp, qd->qd_count);
  282. qd->qd_count++;
  283. qd->qd_change_sync = qd->qd_change;
  284. gfs2_assert_warn(sdp, qd->qd_slot_count);
  285. qd->qd_slot_count++;
  286. found = 1;
  287. break;
  288. }
  289. if (!found)
  290. qd = NULL;
  291. spin_unlock(&sdp->sd_quota_spin);
  292. if (qd) {
  293. gfs2_assert_warn(sdp, qd->qd_change_sync);
  294. error = bh_get(qd);
  295. if (error) {
  296. clear_bit(QDF_LOCKED, &qd->qd_flags);
  297. slot_put(qd);
  298. qd_put(qd);
  299. return error;
  300. }
  301. }
  302. *qdp = qd;
  303. return 0;
  304. }
  305. static int qd_trylock(struct gfs2_quota_data *qd)
  306. {
  307. struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
  308. if (sdp->sd_vfs->s_flags & MS_RDONLY)
  309. return 0;
  310. spin_lock(&sdp->sd_quota_spin);
  311. if (test_bit(QDF_LOCKED, &qd->qd_flags) ||
  312. !test_bit(QDF_CHANGE, &qd->qd_flags)) {
  313. spin_unlock(&sdp->sd_quota_spin);
  314. return 0;
  315. }
  316. list_move_tail(&qd->qd_list, &sdp->sd_quota_list);
  317. set_bit(QDF_LOCKED, &qd->qd_flags);
  318. gfs2_assert_warn(sdp, qd->qd_count);
  319. qd->qd_count++;
  320. qd->qd_change_sync = qd->qd_change;
  321. gfs2_assert_warn(sdp, qd->qd_slot_count);
  322. qd->qd_slot_count++;
  323. spin_unlock(&sdp->sd_quota_spin);
  324. gfs2_assert_warn(sdp, qd->qd_change_sync);
  325. if (bh_get(qd)) {
  326. clear_bit(QDF_LOCKED, &qd->qd_flags);
  327. slot_put(qd);
  328. qd_put(qd);
  329. return 0;
  330. }
  331. return 1;
  332. }
  333. static void qd_unlock(struct gfs2_quota_data *qd)
  334. {
  335. gfs2_assert_warn(qd->qd_gl->gl_sbd,
  336. test_bit(QDF_LOCKED, &qd->qd_flags));
  337. clear_bit(QDF_LOCKED, &qd->qd_flags);
  338. bh_put(qd);
  339. slot_put(qd);
  340. qd_put(qd);
  341. }
  342. static int qdsb_get(struct gfs2_sbd *sdp, int user, u32 id, int create,
  343. struct gfs2_quota_data **qdp)
  344. {
  345. int error;
  346. error = qd_get(sdp, user, id, create, qdp);
  347. if (error)
  348. return error;
  349. error = slot_get(*qdp);
  350. if (error)
  351. goto fail;
  352. error = bh_get(*qdp);
  353. if (error)
  354. goto fail_slot;
  355. return 0;
  356. fail_slot:
  357. slot_put(*qdp);
  358. fail:
  359. qd_put(*qdp);
  360. return error;
  361. }
  362. static void qdsb_put(struct gfs2_quota_data *qd)
  363. {
  364. bh_put(qd);
  365. slot_put(qd);
  366. qd_put(qd);
  367. }
  368. int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
  369. {
  370. struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  371. struct gfs2_alloc *al = ip->i_alloc;
  372. struct gfs2_quota_data **qd = al->al_qd;
  373. int error;
  374. if (gfs2_assert_warn(sdp, !al->al_qd_num) ||
  375. gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags)))
  376. return -EIO;
  377. if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF)
  378. return 0;
  379. error = qdsb_get(sdp, QUOTA_USER, ip->i_inode.i_uid, CREATE, qd);
  380. if (error)
  381. goto out;
  382. al->al_qd_num++;
  383. qd++;
  384. error = qdsb_get(sdp, QUOTA_GROUP, ip->i_inode.i_gid, CREATE, qd);
  385. if (error)
  386. goto out;
  387. al->al_qd_num++;
  388. qd++;
  389. if (uid != NO_QUOTA_CHANGE && uid != ip->i_inode.i_uid) {
  390. error = qdsb_get(sdp, QUOTA_USER, uid, CREATE, qd);
  391. if (error)
  392. goto out;
  393. al->al_qd_num++;
  394. qd++;
  395. }
  396. if (gid != NO_QUOTA_CHANGE && gid != ip->i_inode.i_gid) {
  397. error = qdsb_get(sdp, QUOTA_GROUP, gid, CREATE, qd);
  398. if (error)
  399. goto out;
  400. al->al_qd_num++;
  401. qd++;
  402. }
  403. out:
  404. if (error)
  405. gfs2_quota_unhold(ip);
  406. return error;
  407. }
  408. void gfs2_quota_unhold(struct gfs2_inode *ip)
  409. {
  410. struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  411. struct gfs2_alloc *al = ip->i_alloc;
  412. unsigned int x;
  413. gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags));
  414. for (x = 0; x < al->al_qd_num; x++) {
  415. qdsb_put(al->al_qd[x]);
  416. al->al_qd[x] = NULL;
  417. }
  418. al->al_qd_num = 0;
  419. }
  420. static int sort_qd(const void *a, const void *b)
  421. {
  422. const struct gfs2_quota_data *qd_a = *(const struct gfs2_quota_data **)a;
  423. const struct gfs2_quota_data *qd_b = *(const struct gfs2_quota_data **)b;
  424. if (!test_bit(QDF_USER, &qd_a->qd_flags) !=
  425. !test_bit(QDF_USER, &qd_b->qd_flags)) {
  426. if (test_bit(QDF_USER, &qd_a->qd_flags))
  427. return -1;
  428. else
  429. return 1;
  430. }
  431. if (qd_a->qd_id < qd_b->qd_id)
  432. return -1;
  433. if (qd_a->qd_id > qd_b->qd_id)
  434. return 1;
  435. return 0;
  436. }
  437. static void do_qc(struct gfs2_quota_data *qd, s64 change)
  438. {
  439. struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
  440. struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode);
  441. struct gfs2_quota_change *qc = qd->qd_bh_qc;
  442. s64 x;
  443. mutex_lock(&sdp->sd_quota_mutex);
  444. gfs2_trans_add_bh(ip->i_gl, qd->qd_bh, 1);
  445. if (!test_bit(QDF_CHANGE, &qd->qd_flags)) {
  446. qc->qc_change = 0;
  447. qc->qc_flags = 0;
  448. if (test_bit(QDF_USER, &qd->qd_flags))
  449. qc->qc_flags = cpu_to_be32(GFS2_QCF_USER);
  450. qc->qc_id = cpu_to_be32(qd->qd_id);
  451. }
  452. x = be64_to_cpu(qc->qc_change) + change;
  453. qc->qc_change = cpu_to_be64(x);
  454. spin_lock(&sdp->sd_quota_spin);
  455. qd->qd_change = x;
  456. spin_unlock(&sdp->sd_quota_spin);
  457. if (!x) {
  458. gfs2_assert_warn(sdp, test_bit(QDF_CHANGE, &qd->qd_flags));
  459. clear_bit(QDF_CHANGE, &qd->qd_flags);
  460. qc->qc_flags = 0;
  461. qc->qc_id = 0;
  462. slot_put(qd);
  463. qd_put(qd);
  464. } else if (!test_and_set_bit(QDF_CHANGE, &qd->qd_flags)) {
  465. qd_hold(qd);
  466. slot_hold(qd);
  467. }
  468. mutex_unlock(&sdp->sd_quota_mutex);
  469. }
  470. static void gfs2_quota_in(struct gfs2_quota_host *qu, const void *buf)
  471. {
  472. const struct gfs2_quota *str = buf;
  473. qu->qu_limit = be64_to_cpu(str->qu_limit);
  474. qu->qu_warn = be64_to_cpu(str->qu_warn);
  475. qu->qu_value = be64_to_cpu(str->qu_value);
  476. qu->qu_ll_next = be32_to_cpu(str->qu_ll_next);
  477. }
  478. static void gfs2_quota_out(const struct gfs2_quota_host *qu, void *buf)
  479. {
  480. struct gfs2_quota *str = buf;
  481. str->qu_limit = cpu_to_be64(qu->qu_limit);
  482. str->qu_warn = cpu_to_be64(qu->qu_warn);
  483. str->qu_value = cpu_to_be64(qu->qu_value);
  484. str->qu_ll_next = cpu_to_be32(qu->qu_ll_next);
  485. memset(&str->qu_reserved, 0, sizeof(str->qu_reserved));
  486. }
  487. /**
  488. * gfs2_adjust_quota
  489. *
  490. * This function was mostly borrowed from gfs2_block_truncate_page which was
  491. * in turn mostly borrowed from ext3
  492. */
  493. static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
  494. s64 change, struct gfs2_quota_data *qd)
  495. {
  496. struct inode *inode = &ip->i_inode;
  497. struct address_space *mapping = inode->i_mapping;
  498. unsigned long index = loc >> PAGE_CACHE_SHIFT;
  499. unsigned offset = loc & (PAGE_CACHE_SIZE - 1);
  500. unsigned blocksize, iblock, pos;
  501. struct buffer_head *bh;
  502. struct page *page;
  503. void *kaddr;
  504. char *ptr;
  505. struct gfs2_quota_host qp;
  506. s64 value;
  507. int err = -EIO;
  508. if (gfs2_is_stuffed(ip)) {
  509. struct gfs2_alloc *al = NULL;
  510. al = gfs2_alloc_get(ip);
  511. /* just request 1 blk */
  512. al->al_requested = 1;
  513. gfs2_inplace_reserve(ip);
  514. gfs2_unstuff_dinode(ip, NULL);
  515. gfs2_inplace_release(ip);
  516. gfs2_alloc_put(ip);
  517. }
  518. page = grab_cache_page(mapping, index);
  519. if (!page)
  520. return -ENOMEM;
  521. blocksize = inode->i_sb->s_blocksize;
  522. iblock = index << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits);
  523. if (!page_has_buffers(page))
  524. create_empty_buffers(page, blocksize, 0);
  525. bh = page_buffers(page);
  526. pos = blocksize;
  527. while (offset >= pos) {
  528. bh = bh->b_this_page;
  529. iblock++;
  530. pos += blocksize;
  531. }
  532. if (!buffer_mapped(bh)) {
  533. gfs2_block_map(inode, iblock, bh, 1);
  534. if (!buffer_mapped(bh))
  535. goto unlock;
  536. }
  537. if (PageUptodate(page))
  538. set_buffer_uptodate(bh);
  539. if (!buffer_uptodate(bh)) {
  540. ll_rw_block(READ_META, 1, &bh);
  541. wait_on_buffer(bh);
  542. if (!buffer_uptodate(bh))
  543. goto unlock;
  544. }
  545. gfs2_trans_add_bh(ip->i_gl, bh, 0);
  546. kaddr = kmap_atomic(page, KM_USER0);
  547. ptr = kaddr + offset;
  548. gfs2_quota_in(&qp, ptr);
  549. qp.qu_value += change;
  550. value = qp.qu_value;
  551. gfs2_quota_out(&qp, ptr);
  552. flush_dcache_page(page);
  553. kunmap_atomic(kaddr, KM_USER0);
  554. err = 0;
  555. qd->qd_qb.qb_magic = cpu_to_be32(GFS2_MAGIC);
  556. qd->qd_qb.qb_value = cpu_to_be64(value);
  557. ((struct gfs2_quota_lvb*)(qd->qd_gl->gl_lvb))->qb_magic = cpu_to_be32(GFS2_MAGIC);
  558. ((struct gfs2_quota_lvb*)(qd->qd_gl->gl_lvb))->qb_value = cpu_to_be64(value);
  559. unlock:
  560. unlock_page(page);
  561. page_cache_release(page);
  562. return err;
  563. }
  564. static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
  565. {
  566. struct gfs2_sbd *sdp = (*qda)->qd_gl->gl_sbd;
  567. struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode);
  568. unsigned int data_blocks, ind_blocks;
  569. struct gfs2_holder *ghs, i_gh;
  570. unsigned int qx, x;
  571. struct gfs2_quota_data *qd;
  572. loff_t offset;
  573. unsigned int nalloc = 0;
  574. struct gfs2_alloc *al = NULL;
  575. int error;
  576. gfs2_write_calc_reserv(ip, sizeof(struct gfs2_quota),
  577. &data_blocks, &ind_blocks);
  578. ghs = kcalloc(num_qd, sizeof(struct gfs2_holder), GFP_KERNEL);
  579. if (!ghs)
  580. return -ENOMEM;
  581. sort(qda, num_qd, sizeof(struct gfs2_quota_data *), sort_qd, NULL);
  582. for (qx = 0; qx < num_qd; qx++) {
  583. error = gfs2_glock_nq_init(qda[qx]->qd_gl,
  584. LM_ST_EXCLUSIVE,
  585. GL_NOCACHE, &ghs[qx]);
  586. if (error)
  587. goto out;
  588. }
  589. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
  590. if (error)
  591. goto out;
  592. for (x = 0; x < num_qd; x++) {
  593. int alloc_required;
  594. offset = qd2offset(qda[x]);
  595. error = gfs2_write_alloc_required(ip, offset,
  596. sizeof(struct gfs2_quota),
  597. &alloc_required);
  598. if (error)
  599. goto out_gunlock;
  600. if (alloc_required)
  601. nalloc++;
  602. }
  603. if (nalloc) {
  604. al = gfs2_alloc_get(ip);
  605. al->al_requested = nalloc * (data_blocks + ind_blocks);
  606. error = gfs2_inplace_reserve(ip);
  607. if (error)
  608. goto out_alloc;
  609. error = gfs2_trans_begin(sdp,
  610. al->al_rgd->rd_length +
  611. num_qd * data_blocks +
  612. nalloc * ind_blocks +
  613. RES_DINODE + num_qd +
  614. RES_STATFS, 0);
  615. if (error)
  616. goto out_ipres;
  617. } else {
  618. error = gfs2_trans_begin(sdp,
  619. num_qd * data_blocks +
  620. RES_DINODE + num_qd, 0);
  621. if (error)
  622. goto out_gunlock;
  623. }
  624. for (x = 0; x < num_qd; x++) {
  625. qd = qda[x];
  626. offset = qd2offset(qd);
  627. error = gfs2_adjust_quota(ip, offset, qd->qd_change_sync,
  628. (struct gfs2_quota_data *)
  629. qd);
  630. if (error)
  631. goto out_end_trans;
  632. do_qc(qd, -qd->qd_change_sync);
  633. }
  634. error = 0;
  635. out_end_trans:
  636. gfs2_trans_end(sdp);
  637. out_ipres:
  638. if (nalloc)
  639. gfs2_inplace_release(ip);
  640. out_alloc:
  641. if (nalloc)
  642. gfs2_alloc_put(ip);
  643. out_gunlock:
  644. gfs2_glock_dq_uninit(&i_gh);
  645. out:
  646. while (qx--)
  647. gfs2_glock_dq_uninit(&ghs[qx]);
  648. kfree(ghs);
  649. gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl);
  650. return error;
  651. }
  652. static int do_glock(struct gfs2_quota_data *qd, int force_refresh,
  653. struct gfs2_holder *q_gh)
  654. {
  655. struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
  656. struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode);
  657. struct gfs2_holder i_gh;
  658. struct gfs2_quota_host q;
  659. char buf[sizeof(struct gfs2_quota)];
  660. int error;
  661. struct gfs2_quota_lvb *qlvb;
  662. restart:
  663. error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_SHARED, 0, q_gh);
  664. if (error)
  665. return error;
  666. qd->qd_qb = *(struct gfs2_quota_lvb *)qd->qd_gl->gl_lvb;
  667. if (force_refresh || qd->qd_qb.qb_magic != cpu_to_be32(GFS2_MAGIC)) {
  668. loff_t pos;
  669. gfs2_glock_dq_uninit(q_gh);
  670. error = gfs2_glock_nq_init(qd->qd_gl,
  671. LM_ST_EXCLUSIVE, GL_NOCACHE,
  672. q_gh);
  673. if (error)
  674. return error;
  675. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh);
  676. if (error)
  677. goto fail;
  678. memset(buf, 0, sizeof(struct gfs2_quota));
  679. pos = qd2offset(qd);
  680. error = gfs2_internal_read(ip, NULL, buf, &pos,
  681. sizeof(struct gfs2_quota));
  682. if (error < 0)
  683. goto fail_gunlock;
  684. gfs2_glock_dq_uninit(&i_gh);
  685. gfs2_quota_in(&q, buf);
  686. qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lvb;
  687. qlvb->qb_magic = cpu_to_be32(GFS2_MAGIC);
  688. qlvb->__pad = 0;
  689. qlvb->qb_limit = cpu_to_be64(q.qu_limit);
  690. qlvb->qb_warn = cpu_to_be64(q.qu_warn);
  691. qlvb->qb_value = cpu_to_be64(q.qu_value);
  692. qd->qd_qb = *qlvb;
  693. if (gfs2_glock_is_blocking(qd->qd_gl)) {
  694. gfs2_glock_dq_uninit(q_gh);
  695. force_refresh = 0;
  696. goto restart;
  697. }
  698. }
  699. return 0;
  700. fail_gunlock:
  701. gfs2_glock_dq_uninit(&i_gh);
  702. fail:
  703. gfs2_glock_dq_uninit(q_gh);
  704. return error;
  705. }
  706. int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid)
  707. {
  708. struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  709. struct gfs2_alloc *al = ip->i_alloc;
  710. unsigned int x;
  711. int error = 0;
  712. gfs2_quota_hold(ip, uid, gid);
  713. if (capable(CAP_SYS_RESOURCE) ||
  714. sdp->sd_args.ar_quota != GFS2_QUOTA_ON)
  715. return 0;
  716. sort(al->al_qd, al->al_qd_num, sizeof(struct gfs2_quota_data *),
  717. sort_qd, NULL);
  718. for (x = 0; x < al->al_qd_num; x++) {
  719. error = do_glock(al->al_qd[x], NO_FORCE, &al->al_qd_ghs[x]);
  720. if (error)
  721. break;
  722. }
  723. if (!error)
  724. set_bit(GIF_QD_LOCKED, &ip->i_flags);
  725. else {
  726. while (x--)
  727. gfs2_glock_dq_uninit(&al->al_qd_ghs[x]);
  728. gfs2_quota_unhold(ip);
  729. }
  730. return error;
  731. }
  732. static int need_sync(struct gfs2_quota_data *qd)
  733. {
  734. struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
  735. struct gfs2_tune *gt = &sdp->sd_tune;
  736. s64 value;
  737. unsigned int num, den;
  738. int do_sync = 1;
  739. if (!qd->qd_qb.qb_limit)
  740. return 0;
  741. spin_lock(&sdp->sd_quota_spin);
  742. value = qd->qd_change;
  743. spin_unlock(&sdp->sd_quota_spin);
  744. spin_lock(&gt->gt_spin);
  745. num = gt->gt_quota_scale_num;
  746. den = gt->gt_quota_scale_den;
  747. spin_unlock(&gt->gt_spin);
  748. if (value < 0)
  749. do_sync = 0;
  750. else if ((s64)be64_to_cpu(qd->qd_qb.qb_value) >=
  751. (s64)be64_to_cpu(qd->qd_qb.qb_limit))
  752. do_sync = 0;
  753. else {
  754. value *= gfs2_jindex_size(sdp) * num;
  755. do_div(value, den);
  756. value += (s64)be64_to_cpu(qd->qd_qb.qb_value);
  757. if (value < (s64)be64_to_cpu(qd->qd_qb.qb_limit))
  758. do_sync = 0;
  759. }
  760. return do_sync;
  761. }
  762. void gfs2_quota_unlock(struct gfs2_inode *ip)
  763. {
  764. struct gfs2_alloc *al = ip->i_alloc;
  765. struct gfs2_quota_data *qda[4];
  766. unsigned int count = 0;
  767. unsigned int x;
  768. if (!test_and_clear_bit(GIF_QD_LOCKED, &ip->i_flags))
  769. goto out;
  770. for (x = 0; x < al->al_qd_num; x++) {
  771. struct gfs2_quota_data *qd;
  772. int sync;
  773. qd = al->al_qd[x];
  774. sync = need_sync(qd);
  775. gfs2_glock_dq_uninit(&al->al_qd_ghs[x]);
  776. if (sync && qd_trylock(qd))
  777. qda[count++] = qd;
  778. }
  779. if (count) {
  780. do_sync(count, qda);
  781. for (x = 0; x < count; x++)
  782. qd_unlock(qda[x]);
  783. }
  784. out:
  785. gfs2_quota_unhold(ip);
  786. }
  787. #define MAX_LINE 256
  788. static int print_message(struct gfs2_quota_data *qd, char *type)
  789. {
  790. struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
  791. printk(KERN_INFO "GFS2: fsid=%s: quota %s for %s %u\r\n",
  792. sdp->sd_fsname, type,
  793. (test_bit(QDF_USER, &qd->qd_flags)) ? "user" : "group",
  794. qd->qd_id);
  795. return 0;
  796. }
  797. int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid)
  798. {
  799. struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
  800. struct gfs2_alloc *al = ip->i_alloc;
  801. struct gfs2_quota_data *qd;
  802. s64 value;
  803. unsigned int x;
  804. int error = 0;
  805. if (!test_bit(GIF_QD_LOCKED, &ip->i_flags))
  806. return 0;
  807. if (sdp->sd_args.ar_quota != GFS2_QUOTA_ON)
  808. return 0;
  809. for (x = 0; x < al->al_qd_num; x++) {
  810. qd = al->al_qd[x];
  811. if (!((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) ||
  812. (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags))))
  813. continue;
  814. value = (s64)be64_to_cpu(qd->qd_qb.qb_value);
  815. spin_lock(&sdp->sd_quota_spin);
  816. value += qd->qd_change;
  817. spin_unlock(&sdp->sd_quota_spin);
  818. if (be64_to_cpu(qd->qd_qb.qb_limit) && (s64)be64_to_cpu(qd->qd_qb.qb_limit) < value) {
  819. print_message(qd, "exceeded");
  820. error = -EDQUOT;
  821. break;
  822. } else if (be64_to_cpu(qd->qd_qb.qb_warn) &&
  823. (s64)be64_to_cpu(qd->qd_qb.qb_warn) < value &&
  824. time_after_eq(jiffies, qd->qd_last_warn +
  825. gfs2_tune_get(sdp,
  826. gt_quota_warn_period) * HZ)) {
  827. error = print_message(qd, "warning");
  828. qd->qd_last_warn = jiffies;
  829. }
  830. }
  831. return error;
  832. }
  833. void gfs2_quota_change(struct gfs2_inode *ip, s64 change,
  834. u32 uid, u32 gid)
  835. {
  836. struct gfs2_alloc *al = ip->i_alloc;
  837. struct gfs2_quota_data *qd;
  838. unsigned int x;
  839. if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), change))
  840. return;
  841. if (ip->i_di.di_flags & GFS2_DIF_SYSTEM)
  842. return;
  843. for (x = 0; x < al->al_qd_num; x++) {
  844. qd = al->al_qd[x];
  845. if ((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) ||
  846. (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags))) {
  847. do_qc(qd, change);
  848. }
  849. }
  850. }
  851. int gfs2_quota_sync(struct gfs2_sbd *sdp)
  852. {
  853. struct gfs2_quota_data **qda;
  854. unsigned int max_qd = gfs2_tune_get(sdp, gt_quota_simul_sync);
  855. unsigned int num_qd;
  856. unsigned int x;
  857. int error = 0;
  858. sdp->sd_quota_sync_gen++;
  859. qda = kcalloc(max_qd, sizeof(struct gfs2_quota_data *), GFP_KERNEL);
  860. if (!qda)
  861. return -ENOMEM;
  862. do {
  863. num_qd = 0;
  864. for (;;) {
  865. error = qd_fish(sdp, qda + num_qd);
  866. if (error || !qda[num_qd])
  867. break;
  868. if (++num_qd == max_qd)
  869. break;
  870. }
  871. if (num_qd) {
  872. if (!error)
  873. error = do_sync(num_qd, qda);
  874. if (!error)
  875. for (x = 0; x < num_qd; x++)
  876. qda[x]->qd_sync_gen =
  877. sdp->sd_quota_sync_gen;
  878. for (x = 0; x < num_qd; x++)
  879. qd_unlock(qda[x]);
  880. }
  881. } while (!error && num_qd == max_qd);
  882. kfree(qda);
  883. return error;
  884. }
  885. int gfs2_quota_refresh(struct gfs2_sbd *sdp, int user, u32 id)
  886. {
  887. struct gfs2_quota_data *qd;
  888. struct gfs2_holder q_gh;
  889. int error;
  890. error = qd_get(sdp, user, id, CREATE, &qd);
  891. if (error)
  892. return error;
  893. error = do_glock(qd, FORCE, &q_gh);
  894. if (!error)
  895. gfs2_glock_dq_uninit(&q_gh);
  896. qd_put(qd);
  897. return error;
  898. }
  899. static void gfs2_quota_change_in(struct gfs2_quota_change_host *qc, const void *buf)
  900. {
  901. const struct gfs2_quota_change *str = buf;
  902. qc->qc_change = be64_to_cpu(str->qc_change);
  903. qc->qc_flags = be32_to_cpu(str->qc_flags);
  904. qc->qc_id = be32_to_cpu(str->qc_id);
  905. }
  906. int gfs2_quota_init(struct gfs2_sbd *sdp)
  907. {
  908. struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode);
  909. unsigned int blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift;
  910. unsigned int x, slot = 0;
  911. unsigned int found = 0;
  912. u64 dblock;
  913. u32 extlen = 0;
  914. int error;
  915. if (!ip->i_di.di_size || ip->i_di.di_size > (64 << 20) ||
  916. ip->i_di.di_size & (sdp->sd_sb.sb_bsize - 1)) {
  917. gfs2_consist_inode(ip);
  918. return -EIO;
  919. }
  920. sdp->sd_quota_slots = blocks * sdp->sd_qc_per_block;
  921. sdp->sd_quota_chunks = DIV_ROUND_UP(sdp->sd_quota_slots, 8 * PAGE_SIZE);
  922. error = -ENOMEM;
  923. sdp->sd_quota_bitmap = kcalloc(sdp->sd_quota_chunks,
  924. sizeof(unsigned char *), GFP_KERNEL);
  925. if (!sdp->sd_quota_bitmap)
  926. return error;
  927. for (x = 0; x < sdp->sd_quota_chunks; x++) {
  928. sdp->sd_quota_bitmap[x] = kzalloc(PAGE_SIZE, GFP_KERNEL);
  929. if (!sdp->sd_quota_bitmap[x])
  930. goto fail;
  931. }
  932. for (x = 0; x < blocks; x++) {
  933. struct buffer_head *bh;
  934. unsigned int y;
  935. if (!extlen) {
  936. int new = 0;
  937. error = gfs2_extent_map(&ip->i_inode, x, &new, &dblock, &extlen);
  938. if (error)
  939. goto fail;
  940. }
  941. error = -EIO;
  942. bh = gfs2_meta_ra(ip->i_gl, dblock, extlen);
  943. if (!bh)
  944. goto fail;
  945. if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_QC)) {
  946. brelse(bh);
  947. goto fail;
  948. }
  949. for (y = 0; y < sdp->sd_qc_per_block && slot < sdp->sd_quota_slots;
  950. y++, slot++) {
  951. struct gfs2_quota_change_host qc;
  952. struct gfs2_quota_data *qd;
  953. gfs2_quota_change_in(&qc, bh->b_data +
  954. sizeof(struct gfs2_meta_header) +
  955. y * sizeof(struct gfs2_quota_change));
  956. if (!qc.qc_change)
  957. continue;
  958. error = qd_alloc(sdp, (qc.qc_flags & GFS2_QCF_USER),
  959. qc.qc_id, &qd);
  960. if (error) {
  961. brelse(bh);
  962. goto fail;
  963. }
  964. set_bit(QDF_CHANGE, &qd->qd_flags);
  965. qd->qd_change = qc.qc_change;
  966. qd->qd_slot = slot;
  967. qd->qd_slot_count = 1;
  968. qd->qd_last_touched = jiffies;
  969. spin_lock(&sdp->sd_quota_spin);
  970. gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, slot, 1);
  971. list_add(&qd->qd_list, &sdp->sd_quota_list);
  972. atomic_inc(&sdp->sd_quota_count);
  973. spin_unlock(&sdp->sd_quota_spin);
  974. found++;
  975. }
  976. brelse(bh);
  977. dblock++;
  978. extlen--;
  979. }
  980. if (found)
  981. fs_info(sdp, "found %u quota changes\n", found);
  982. return 0;
  983. fail:
  984. gfs2_quota_cleanup(sdp);
  985. return error;
  986. }
  987. void gfs2_quota_scan(struct gfs2_sbd *sdp)
  988. {
  989. struct gfs2_quota_data *qd, *safe;
  990. LIST_HEAD(dead);
  991. spin_lock(&sdp->sd_quota_spin);
  992. list_for_each_entry_safe(qd, safe, &sdp->sd_quota_list, qd_list) {
  993. if (!qd->qd_count &&
  994. time_after_eq(jiffies, qd->qd_last_touched +
  995. gfs2_tune_get(sdp, gt_quota_cache_secs) * HZ)) {
  996. list_move(&qd->qd_list, &dead);
  997. gfs2_assert_warn(sdp,
  998. atomic_read(&sdp->sd_quota_count) > 0);
  999. atomic_dec(&sdp->sd_quota_count);
  1000. }
  1001. }
  1002. spin_unlock(&sdp->sd_quota_spin);
  1003. while (!list_empty(&dead)) {
  1004. qd = list_entry(dead.next, struct gfs2_quota_data, qd_list);
  1005. list_del(&qd->qd_list);
  1006. gfs2_assert_warn(sdp, !qd->qd_change);
  1007. gfs2_assert_warn(sdp, !qd->qd_slot_count);
  1008. gfs2_assert_warn(sdp, !qd->qd_bh_count);
  1009. gfs2_lvb_unhold(qd->qd_gl);
  1010. kfree(qd);
  1011. }
  1012. }
  1013. void gfs2_quota_cleanup(struct gfs2_sbd *sdp)
  1014. {
  1015. struct list_head *head = &sdp->sd_quota_list;
  1016. struct gfs2_quota_data *qd;
  1017. unsigned int x;
  1018. spin_lock(&sdp->sd_quota_spin);
  1019. while (!list_empty(head)) {
  1020. qd = list_entry(head->prev, struct gfs2_quota_data, qd_list);
  1021. if (qd->qd_count > 1 ||
  1022. (qd->qd_count && !test_bit(QDF_CHANGE, &qd->qd_flags))) {
  1023. list_move(&qd->qd_list, head);
  1024. spin_unlock(&sdp->sd_quota_spin);
  1025. schedule();
  1026. spin_lock(&sdp->sd_quota_spin);
  1027. continue;
  1028. }
  1029. list_del(&qd->qd_list);
  1030. atomic_dec(&sdp->sd_quota_count);
  1031. spin_unlock(&sdp->sd_quota_spin);
  1032. if (!qd->qd_count) {
  1033. gfs2_assert_warn(sdp, !qd->qd_change);
  1034. gfs2_assert_warn(sdp, !qd->qd_slot_count);
  1035. } else
  1036. gfs2_assert_warn(sdp, qd->qd_slot_count == 1);
  1037. gfs2_assert_warn(sdp, !qd->qd_bh_count);
  1038. gfs2_lvb_unhold(qd->qd_gl);
  1039. kfree(qd);
  1040. spin_lock(&sdp->sd_quota_spin);
  1041. }
  1042. spin_unlock(&sdp->sd_quota_spin);
  1043. gfs2_assert_warn(sdp, !atomic_read(&sdp->sd_quota_count));
  1044. if (sdp->sd_quota_bitmap) {
  1045. for (x = 0; x < sdp->sd_quota_chunks; x++)
  1046. kfree(sdp->sd_quota_bitmap[x]);
  1047. kfree(sdp->sd_quota_bitmap);
  1048. }
  1049. }