quota.c 28 KB

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