quota.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  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. 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, block, &new, &dblock, NULL);
  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 = ip->i_sbd;
  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 = ip->i_sbd;
  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 = sdp->sd_qc_inode->u.generic_ip;
  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_vnode;
  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 = sdp->sd_quota_inode->u.generic_ip;
  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_vnode->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 = sdp->sd_quota_inode->u.generic_ip;
  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 = ip->i_sbd;
  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 = ip->i_sbd;
  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(ip->i_sbd, 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. int gfs2_quota_read(struct gfs2_sbd *sdp, int user, uint32_t id,
  884. struct gfs2_quota *q)
  885. {
  886. struct gfs2_quota_data *qd;
  887. struct gfs2_holder q_gh;
  888. int error;
  889. if (((user) ? (id != current->fsuid) : (!in_group_p(id))) &&
  890. !capable(CAP_SYS_ADMIN))
  891. return -EACCES;
  892. error = qd_get(sdp, user, id, CREATE, &qd);
  893. if (error)
  894. return error;
  895. error = do_glock(qd, NO_FORCE, &q_gh);
  896. if (error)
  897. goto out;
  898. memset(q, 0, sizeof(struct gfs2_quota));
  899. q->qu_limit = qd->qd_qb.qb_limit;
  900. q->qu_warn = qd->qd_qb.qb_warn;
  901. q->qu_value = qd->qd_qb.qb_value;
  902. spin_lock(&sdp->sd_quota_spin);
  903. q->qu_value += qd->qd_change;
  904. spin_unlock(&sdp->sd_quota_spin);
  905. gfs2_glock_dq_uninit(&q_gh);
  906. out:
  907. qd_put(qd);
  908. return error;
  909. }
  910. int gfs2_quota_init(struct gfs2_sbd *sdp)
  911. {
  912. struct gfs2_inode *ip = sdp->sd_qc_inode->u.generic_ip;
  913. unsigned int blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift;
  914. unsigned int x, slot = 0;
  915. unsigned int found = 0;
  916. uint64_t dblock;
  917. uint32_t extlen = 0;
  918. int error;
  919. if (!ip->i_di.di_size ||
  920. ip->i_di.di_size > (64 << 20) ||
  921. ip->i_di.di_size & (sdp->sd_sb.sb_bsize - 1)) {
  922. gfs2_consist_inode(ip);
  923. return -EIO;
  924. }
  925. sdp->sd_quota_slots = blocks * sdp->sd_qc_per_block;
  926. sdp->sd_quota_chunks = DIV_ROUND_UP(sdp->sd_quota_slots, 8 * PAGE_SIZE);
  927. error = -ENOMEM;
  928. sdp->sd_quota_bitmap = kcalloc(sdp->sd_quota_chunks,
  929. sizeof(unsigned char *), GFP_KERNEL);
  930. if (!sdp->sd_quota_bitmap)
  931. return error;
  932. for (x = 0; x < sdp->sd_quota_chunks; x++) {
  933. sdp->sd_quota_bitmap[x] = kzalloc(PAGE_SIZE, GFP_KERNEL);
  934. if (!sdp->sd_quota_bitmap[x])
  935. goto fail;
  936. }
  937. for (x = 0; x < blocks; x++) {
  938. struct buffer_head *bh;
  939. unsigned int y;
  940. if (!extlen) {
  941. int new = 0;
  942. error = gfs2_block_map(ip, x, &new, &dblock, &extlen);
  943. if (error)
  944. goto fail;
  945. }
  946. gfs2_meta_ra(ip->i_gl, dblock, extlen);
  947. error = gfs2_meta_read(ip->i_gl, dblock, DIO_START | DIO_WAIT,
  948. &bh);
  949. if (error)
  950. goto fail;
  951. error = -EIO;
  952. if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_QC)) {
  953. brelse(bh);
  954. goto fail;
  955. }
  956. for (y = 0;
  957. y < sdp->sd_qc_per_block && slot < sdp->sd_quota_slots;
  958. y++, slot++) {
  959. struct gfs2_quota_change qc;
  960. struct gfs2_quota_data *qd;
  961. gfs2_quota_change_in(&qc, bh->b_data +
  962. sizeof(struct gfs2_meta_header) +
  963. y * sizeof(struct gfs2_quota_change));
  964. if (!qc.qc_change)
  965. continue;
  966. error = qd_alloc(sdp, (qc.qc_flags & GFS2_QCF_USER),
  967. qc.qc_id, &qd);
  968. if (error) {
  969. brelse(bh);
  970. goto fail;
  971. }
  972. set_bit(QDF_CHANGE, &qd->qd_flags);
  973. qd->qd_change = qc.qc_change;
  974. qd->qd_slot = slot;
  975. qd->qd_slot_count = 1;
  976. qd->qd_last_touched = jiffies;
  977. spin_lock(&sdp->sd_quota_spin);
  978. gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, slot, 1);
  979. list_add(&qd->qd_list, &sdp->sd_quota_list);
  980. atomic_inc(&sdp->sd_quota_count);
  981. spin_unlock(&sdp->sd_quota_spin);
  982. found++;
  983. }
  984. brelse(bh);
  985. dblock++;
  986. extlen--;
  987. }
  988. if (found)
  989. fs_info(sdp, "found %u quota changes\n", found);
  990. return 0;
  991. fail:
  992. gfs2_quota_cleanup(sdp);
  993. return error;
  994. }
  995. void gfs2_quota_scan(struct gfs2_sbd *sdp)
  996. {
  997. struct gfs2_quota_data *qd, *safe;
  998. LIST_HEAD(dead);
  999. spin_lock(&sdp->sd_quota_spin);
  1000. list_for_each_entry_safe(qd, safe, &sdp->sd_quota_list, qd_list) {
  1001. if (!qd->qd_count &&
  1002. time_after_eq(jiffies, qd->qd_last_touched +
  1003. gfs2_tune_get(sdp, gt_quota_cache_secs) * HZ)) {
  1004. list_move(&qd->qd_list, &dead);
  1005. gfs2_assert_warn(sdp,
  1006. atomic_read(&sdp->sd_quota_count) > 0);
  1007. atomic_dec(&sdp->sd_quota_count);
  1008. }
  1009. }
  1010. spin_unlock(&sdp->sd_quota_spin);
  1011. while (!list_empty(&dead)) {
  1012. qd = list_entry(dead.next, struct gfs2_quota_data, qd_list);
  1013. list_del(&qd->qd_list);
  1014. gfs2_assert_warn(sdp, !qd->qd_change);
  1015. gfs2_assert_warn(sdp, !qd->qd_slot_count);
  1016. gfs2_assert_warn(sdp, !qd->qd_bh_count);
  1017. gfs2_lvb_unhold(qd->qd_gl);
  1018. kfree(qd);
  1019. }
  1020. }
  1021. void gfs2_quota_cleanup(struct gfs2_sbd *sdp)
  1022. {
  1023. struct list_head *head = &sdp->sd_quota_list;
  1024. struct gfs2_quota_data *qd;
  1025. unsigned int x;
  1026. spin_lock(&sdp->sd_quota_spin);
  1027. while (!list_empty(head)) {
  1028. qd = list_entry(head->prev, struct gfs2_quota_data, qd_list);
  1029. if (qd->qd_count > 1 ||
  1030. (qd->qd_count && !test_bit(QDF_CHANGE, &qd->qd_flags))) {
  1031. list_move(&qd->qd_list, head);
  1032. spin_unlock(&sdp->sd_quota_spin);
  1033. schedule();
  1034. spin_lock(&sdp->sd_quota_spin);
  1035. continue;
  1036. }
  1037. list_del(&qd->qd_list);
  1038. atomic_dec(&sdp->sd_quota_count);
  1039. spin_unlock(&sdp->sd_quota_spin);
  1040. if (!qd->qd_count) {
  1041. gfs2_assert_warn(sdp, !qd->qd_change);
  1042. gfs2_assert_warn(sdp, !qd->qd_slot_count);
  1043. } else
  1044. gfs2_assert_warn(sdp, qd->qd_slot_count == 1);
  1045. gfs2_assert_warn(sdp, !qd->qd_bh_count);
  1046. gfs2_lvb_unhold(qd->qd_gl);
  1047. kfree(qd);
  1048. spin_lock(&sdp->sd_quota_spin);
  1049. }
  1050. spin_unlock(&sdp->sd_quota_spin);
  1051. gfs2_assert_warn(sdp, !atomic_read(&sdp->sd_quota_count));
  1052. if (sdp->sd_quota_bitmap) {
  1053. for (x = 0; x < sdp->sd_quota_chunks; x++)
  1054. kfree(sdp->sd_quota_bitmap[x]);
  1055. kfree(sdp->sd_quota_bitmap);
  1056. }
  1057. }