quota.c 28 KB

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