quota.c 28 KB

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