quota.c 29 KB

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