quota.c 28 KB

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