xfs_dquot.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. /*
  2. * Copyright (c) 2000-2003 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include "xfs_fs.h"
  20. #include "xfs_format.h"
  21. #include "xfs_log_format.h"
  22. #include "xfs_shared.h"
  23. #include "xfs_trans_resv.h"
  24. #include "xfs_bit.h"
  25. #include "xfs_mount.h"
  26. #include "xfs_defer.h"
  27. #include "xfs_inode.h"
  28. #include "xfs_bmap.h"
  29. #include "xfs_bmap_util.h"
  30. #include "xfs_alloc.h"
  31. #include "xfs_quota.h"
  32. #include "xfs_error.h"
  33. #include "xfs_trans.h"
  34. #include "xfs_buf_item.h"
  35. #include "xfs_trans_space.h"
  36. #include "xfs_trans_priv.h"
  37. #include "xfs_qm.h"
  38. #include "xfs_cksum.h"
  39. #include "xfs_trace.h"
  40. #include "xfs_log.h"
  41. #include "xfs_bmap_btree.h"
  42. /*
  43. * Lock order:
  44. *
  45. * ip->i_lock
  46. * qi->qi_tree_lock
  47. * dquot->q_qlock (xfs_dqlock() and friends)
  48. * dquot->q_flush (xfs_dqflock() and friends)
  49. * qi->qi_lru_lock
  50. *
  51. * If two dquots need to be locked the order is user before group/project,
  52. * otherwise by the lowest id first, see xfs_dqlock2.
  53. */
  54. #ifdef DEBUG
  55. xfs_buftarg_t *xfs_dqerror_target;
  56. int xfs_do_dqerror;
  57. int xfs_dqreq_num;
  58. int xfs_dqerror_mod = 33;
  59. #endif
  60. struct kmem_zone *xfs_qm_dqtrxzone;
  61. static struct kmem_zone *xfs_qm_dqzone;
  62. static struct lock_class_key xfs_dquot_group_class;
  63. static struct lock_class_key xfs_dquot_project_class;
  64. /*
  65. * This is called to free all the memory associated with a dquot
  66. */
  67. void
  68. xfs_qm_dqdestroy(
  69. xfs_dquot_t *dqp)
  70. {
  71. ASSERT(list_empty(&dqp->q_lru));
  72. kmem_free(dqp->q_logitem.qli_item.li_lv_shadow);
  73. mutex_destroy(&dqp->q_qlock);
  74. XFS_STATS_DEC(dqp->q_mount, xs_qm_dquot);
  75. kmem_zone_free(xfs_qm_dqzone, dqp);
  76. }
  77. /*
  78. * If default limits are in force, push them into the dquot now.
  79. * We overwrite the dquot limits only if they are zero and this
  80. * is not the root dquot.
  81. */
  82. void
  83. xfs_qm_adjust_dqlimits(
  84. struct xfs_mount *mp,
  85. struct xfs_dquot *dq)
  86. {
  87. struct xfs_quotainfo *q = mp->m_quotainfo;
  88. struct xfs_disk_dquot *d = &dq->q_core;
  89. struct xfs_def_quota *defq;
  90. int prealloc = 0;
  91. ASSERT(d->d_id);
  92. defq = xfs_get_defquota(dq, q);
  93. if (defq->bsoftlimit && !d->d_blk_softlimit) {
  94. d->d_blk_softlimit = cpu_to_be64(defq->bsoftlimit);
  95. prealloc = 1;
  96. }
  97. if (defq->bhardlimit && !d->d_blk_hardlimit) {
  98. d->d_blk_hardlimit = cpu_to_be64(defq->bhardlimit);
  99. prealloc = 1;
  100. }
  101. if (defq->isoftlimit && !d->d_ino_softlimit)
  102. d->d_ino_softlimit = cpu_to_be64(defq->isoftlimit);
  103. if (defq->ihardlimit && !d->d_ino_hardlimit)
  104. d->d_ino_hardlimit = cpu_to_be64(defq->ihardlimit);
  105. if (defq->rtbsoftlimit && !d->d_rtb_softlimit)
  106. d->d_rtb_softlimit = cpu_to_be64(defq->rtbsoftlimit);
  107. if (defq->rtbhardlimit && !d->d_rtb_hardlimit)
  108. d->d_rtb_hardlimit = cpu_to_be64(defq->rtbhardlimit);
  109. if (prealloc)
  110. xfs_dquot_set_prealloc_limits(dq);
  111. }
  112. /*
  113. * Check the limits and timers of a dquot and start or reset timers
  114. * if necessary.
  115. * This gets called even when quota enforcement is OFF, which makes our
  116. * life a little less complicated. (We just don't reject any quota
  117. * reservations in that case, when enforcement is off).
  118. * We also return 0 as the values of the timers in Q_GETQUOTA calls, when
  119. * enforcement's off.
  120. * In contrast, warnings are a little different in that they don't
  121. * 'automatically' get started when limits get exceeded. They do
  122. * get reset to zero, however, when we find the count to be under
  123. * the soft limit (they are only ever set non-zero via userspace).
  124. */
  125. void
  126. xfs_qm_adjust_dqtimers(
  127. xfs_mount_t *mp,
  128. xfs_disk_dquot_t *d)
  129. {
  130. ASSERT(d->d_id);
  131. #ifdef DEBUG
  132. if (d->d_blk_hardlimit)
  133. ASSERT(be64_to_cpu(d->d_blk_softlimit) <=
  134. be64_to_cpu(d->d_blk_hardlimit));
  135. if (d->d_ino_hardlimit)
  136. ASSERT(be64_to_cpu(d->d_ino_softlimit) <=
  137. be64_to_cpu(d->d_ino_hardlimit));
  138. if (d->d_rtb_hardlimit)
  139. ASSERT(be64_to_cpu(d->d_rtb_softlimit) <=
  140. be64_to_cpu(d->d_rtb_hardlimit));
  141. #endif
  142. if (!d->d_btimer) {
  143. if ((d->d_blk_softlimit &&
  144. (be64_to_cpu(d->d_bcount) >
  145. be64_to_cpu(d->d_blk_softlimit))) ||
  146. (d->d_blk_hardlimit &&
  147. (be64_to_cpu(d->d_bcount) >
  148. be64_to_cpu(d->d_blk_hardlimit)))) {
  149. d->d_btimer = cpu_to_be32(get_seconds() +
  150. mp->m_quotainfo->qi_btimelimit);
  151. } else {
  152. d->d_bwarns = 0;
  153. }
  154. } else {
  155. if ((!d->d_blk_softlimit ||
  156. (be64_to_cpu(d->d_bcount) <=
  157. be64_to_cpu(d->d_blk_softlimit))) &&
  158. (!d->d_blk_hardlimit ||
  159. (be64_to_cpu(d->d_bcount) <=
  160. be64_to_cpu(d->d_blk_hardlimit)))) {
  161. d->d_btimer = 0;
  162. }
  163. }
  164. if (!d->d_itimer) {
  165. if ((d->d_ino_softlimit &&
  166. (be64_to_cpu(d->d_icount) >
  167. be64_to_cpu(d->d_ino_softlimit))) ||
  168. (d->d_ino_hardlimit &&
  169. (be64_to_cpu(d->d_icount) >
  170. be64_to_cpu(d->d_ino_hardlimit)))) {
  171. d->d_itimer = cpu_to_be32(get_seconds() +
  172. mp->m_quotainfo->qi_itimelimit);
  173. } else {
  174. d->d_iwarns = 0;
  175. }
  176. } else {
  177. if ((!d->d_ino_softlimit ||
  178. (be64_to_cpu(d->d_icount) <=
  179. be64_to_cpu(d->d_ino_softlimit))) &&
  180. (!d->d_ino_hardlimit ||
  181. (be64_to_cpu(d->d_icount) <=
  182. be64_to_cpu(d->d_ino_hardlimit)))) {
  183. d->d_itimer = 0;
  184. }
  185. }
  186. if (!d->d_rtbtimer) {
  187. if ((d->d_rtb_softlimit &&
  188. (be64_to_cpu(d->d_rtbcount) >
  189. be64_to_cpu(d->d_rtb_softlimit))) ||
  190. (d->d_rtb_hardlimit &&
  191. (be64_to_cpu(d->d_rtbcount) >
  192. be64_to_cpu(d->d_rtb_hardlimit)))) {
  193. d->d_rtbtimer = cpu_to_be32(get_seconds() +
  194. mp->m_quotainfo->qi_rtbtimelimit);
  195. } else {
  196. d->d_rtbwarns = 0;
  197. }
  198. } else {
  199. if ((!d->d_rtb_softlimit ||
  200. (be64_to_cpu(d->d_rtbcount) <=
  201. be64_to_cpu(d->d_rtb_softlimit))) &&
  202. (!d->d_rtb_hardlimit ||
  203. (be64_to_cpu(d->d_rtbcount) <=
  204. be64_to_cpu(d->d_rtb_hardlimit)))) {
  205. d->d_rtbtimer = 0;
  206. }
  207. }
  208. }
  209. /*
  210. * initialize a buffer full of dquots and log the whole thing
  211. */
  212. STATIC void
  213. xfs_qm_init_dquot_blk(
  214. xfs_trans_t *tp,
  215. xfs_mount_t *mp,
  216. xfs_dqid_t id,
  217. uint type,
  218. xfs_buf_t *bp)
  219. {
  220. struct xfs_quotainfo *q = mp->m_quotainfo;
  221. xfs_dqblk_t *d;
  222. xfs_dqid_t curid;
  223. int i;
  224. ASSERT(tp);
  225. ASSERT(xfs_buf_islocked(bp));
  226. d = bp->b_addr;
  227. /*
  228. * ID of the first dquot in the block - id's are zero based.
  229. */
  230. curid = id - (id % q->qi_dqperchunk);
  231. memset(d, 0, BBTOB(q->qi_dqchunklen));
  232. for (i = 0; i < q->qi_dqperchunk; i++, d++, curid++) {
  233. d->dd_diskdq.d_magic = cpu_to_be16(XFS_DQUOT_MAGIC);
  234. d->dd_diskdq.d_version = XFS_DQUOT_VERSION;
  235. d->dd_diskdq.d_id = cpu_to_be32(curid);
  236. d->dd_diskdq.d_flags = type;
  237. if (xfs_sb_version_hascrc(&mp->m_sb)) {
  238. uuid_copy(&d->dd_uuid, &mp->m_sb.sb_meta_uuid);
  239. xfs_update_cksum((char *)d, sizeof(struct xfs_dqblk),
  240. XFS_DQUOT_CRC_OFF);
  241. }
  242. }
  243. xfs_trans_dquot_buf(tp, bp,
  244. (type & XFS_DQ_USER ? XFS_BLF_UDQUOT_BUF :
  245. ((type & XFS_DQ_PROJ) ? XFS_BLF_PDQUOT_BUF :
  246. XFS_BLF_GDQUOT_BUF)));
  247. xfs_trans_log_buf(tp, bp, 0, BBTOB(q->qi_dqchunklen) - 1);
  248. }
  249. /*
  250. * Initialize the dynamic speculative preallocation thresholds. The lo/hi
  251. * watermarks correspond to the soft and hard limits by default. If a soft limit
  252. * is not specified, we use 95% of the hard limit.
  253. */
  254. void
  255. xfs_dquot_set_prealloc_limits(struct xfs_dquot *dqp)
  256. {
  257. __uint64_t space;
  258. dqp->q_prealloc_hi_wmark = be64_to_cpu(dqp->q_core.d_blk_hardlimit);
  259. dqp->q_prealloc_lo_wmark = be64_to_cpu(dqp->q_core.d_blk_softlimit);
  260. if (!dqp->q_prealloc_lo_wmark) {
  261. dqp->q_prealloc_lo_wmark = dqp->q_prealloc_hi_wmark;
  262. do_div(dqp->q_prealloc_lo_wmark, 100);
  263. dqp->q_prealloc_lo_wmark *= 95;
  264. }
  265. space = dqp->q_prealloc_hi_wmark;
  266. do_div(space, 100);
  267. dqp->q_low_space[XFS_QLOWSP_1_PCNT] = space;
  268. dqp->q_low_space[XFS_QLOWSP_3_PCNT] = space * 3;
  269. dqp->q_low_space[XFS_QLOWSP_5_PCNT] = space * 5;
  270. }
  271. /*
  272. * Allocate a block and fill it with dquots.
  273. * This is called when the bmapi finds a hole.
  274. */
  275. STATIC int
  276. xfs_qm_dqalloc(
  277. xfs_trans_t **tpp,
  278. xfs_mount_t *mp,
  279. xfs_dquot_t *dqp,
  280. xfs_inode_t *quotip,
  281. xfs_fileoff_t offset_fsb,
  282. xfs_buf_t **O_bpp)
  283. {
  284. xfs_fsblock_t firstblock;
  285. struct xfs_defer_ops dfops;
  286. xfs_bmbt_irec_t map;
  287. int nmaps, error;
  288. xfs_buf_t *bp;
  289. xfs_trans_t *tp = *tpp;
  290. ASSERT(tp != NULL);
  291. trace_xfs_dqalloc(dqp);
  292. /*
  293. * Initialize the bmap freelist prior to calling bmapi code.
  294. */
  295. xfs_defer_init(&dfops, &firstblock);
  296. xfs_ilock(quotip, XFS_ILOCK_EXCL);
  297. /*
  298. * Return if this type of quotas is turned off while we didn't
  299. * have an inode lock
  300. */
  301. if (!xfs_this_quota_on(dqp->q_mount, dqp->dq_flags)) {
  302. xfs_iunlock(quotip, XFS_ILOCK_EXCL);
  303. return -ESRCH;
  304. }
  305. xfs_trans_ijoin(tp, quotip, XFS_ILOCK_EXCL);
  306. nmaps = 1;
  307. error = xfs_bmapi_write(tp, quotip, offset_fsb,
  308. XFS_DQUOT_CLUSTER_SIZE_FSB, XFS_BMAPI_METADATA,
  309. &firstblock, XFS_QM_DQALLOC_SPACE_RES(mp),
  310. &map, &nmaps, &dfops);
  311. if (error)
  312. goto error0;
  313. ASSERT(map.br_blockcount == XFS_DQUOT_CLUSTER_SIZE_FSB);
  314. ASSERT(nmaps == 1);
  315. ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
  316. (map.br_startblock != HOLESTARTBLOCK));
  317. /*
  318. * Keep track of the blkno to save a lookup later
  319. */
  320. dqp->q_blkno = XFS_FSB_TO_DADDR(mp, map.br_startblock);
  321. /* now we can just get the buffer (there's nothing to read yet) */
  322. bp = xfs_trans_get_buf(tp, mp->m_ddev_targp,
  323. dqp->q_blkno,
  324. mp->m_quotainfo->qi_dqchunklen,
  325. 0);
  326. if (!bp) {
  327. error = -ENOMEM;
  328. goto error1;
  329. }
  330. bp->b_ops = &xfs_dquot_buf_ops;
  331. /*
  332. * Make a chunk of dquots out of this buffer and log
  333. * the entire thing.
  334. */
  335. xfs_qm_init_dquot_blk(tp, mp, be32_to_cpu(dqp->q_core.d_id),
  336. dqp->dq_flags & XFS_DQ_ALLTYPES, bp);
  337. /*
  338. * xfs_defer_finish() may commit the current transaction and
  339. * start a second transaction if the freelist is not empty.
  340. *
  341. * Since we still want to modify this buffer, we need to
  342. * ensure that the buffer is not released on commit of
  343. * the first transaction and ensure the buffer is added to the
  344. * second transaction.
  345. *
  346. * If there is only one transaction then don't stop the buffer
  347. * from being released when it commits later on.
  348. */
  349. xfs_trans_bhold(tp, bp);
  350. error = xfs_defer_finish(tpp, &dfops, NULL);
  351. if (error)
  352. goto error1;
  353. /* Transaction was committed? */
  354. if (*tpp != tp) {
  355. tp = *tpp;
  356. xfs_trans_bjoin(tp, bp);
  357. } else {
  358. xfs_trans_bhold_release(tp, bp);
  359. }
  360. *O_bpp = bp;
  361. return 0;
  362. error1:
  363. xfs_defer_cancel(&dfops);
  364. error0:
  365. xfs_iunlock(quotip, XFS_ILOCK_EXCL);
  366. return error;
  367. }
  368. STATIC int
  369. xfs_qm_dqrepair(
  370. struct xfs_mount *mp,
  371. struct xfs_trans *tp,
  372. struct xfs_dquot *dqp,
  373. xfs_dqid_t firstid,
  374. struct xfs_buf **bpp)
  375. {
  376. int error;
  377. struct xfs_disk_dquot *ddq;
  378. struct xfs_dqblk *d;
  379. int i;
  380. /*
  381. * Read the buffer without verification so we get the corrupted
  382. * buffer returned to us. make sure we verify it on write, though.
  383. */
  384. error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, dqp->q_blkno,
  385. mp->m_quotainfo->qi_dqchunklen,
  386. 0, bpp, NULL);
  387. if (error) {
  388. ASSERT(*bpp == NULL);
  389. return error;
  390. }
  391. (*bpp)->b_ops = &xfs_dquot_buf_ops;
  392. ASSERT(xfs_buf_islocked(*bpp));
  393. d = (struct xfs_dqblk *)(*bpp)->b_addr;
  394. /* Do the actual repair of dquots in this buffer */
  395. for (i = 0; i < mp->m_quotainfo->qi_dqperchunk; i++) {
  396. ddq = &d[i].dd_diskdq;
  397. error = xfs_dqcheck(mp, ddq, firstid + i,
  398. dqp->dq_flags & XFS_DQ_ALLTYPES,
  399. XFS_QMOPT_DQREPAIR, "xfs_qm_dqrepair");
  400. if (error) {
  401. /* repair failed, we're screwed */
  402. xfs_trans_brelse(tp, *bpp);
  403. return -EIO;
  404. }
  405. }
  406. return 0;
  407. }
  408. /*
  409. * Maps a dquot to the buffer containing its on-disk version.
  410. * This returns a ptr to the buffer containing the on-disk dquot
  411. * in the bpp param, and a ptr to the on-disk dquot within that buffer
  412. */
  413. STATIC int
  414. xfs_qm_dqtobp(
  415. xfs_trans_t **tpp,
  416. xfs_dquot_t *dqp,
  417. xfs_disk_dquot_t **O_ddpp,
  418. xfs_buf_t **O_bpp,
  419. uint flags)
  420. {
  421. struct xfs_bmbt_irec map;
  422. int nmaps = 1, error;
  423. struct xfs_buf *bp;
  424. struct xfs_inode *quotip;
  425. struct xfs_mount *mp = dqp->q_mount;
  426. xfs_dqid_t id = be32_to_cpu(dqp->q_core.d_id);
  427. struct xfs_trans *tp = (tpp ? *tpp : NULL);
  428. uint lock_mode;
  429. quotip = xfs_quota_inode(dqp->q_mount, dqp->dq_flags);
  430. dqp->q_fileoffset = (xfs_fileoff_t)id / mp->m_quotainfo->qi_dqperchunk;
  431. lock_mode = xfs_ilock_data_map_shared(quotip);
  432. if (!xfs_this_quota_on(dqp->q_mount, dqp->dq_flags)) {
  433. /*
  434. * Return if this type of quotas is turned off while we
  435. * didn't have the quota inode lock.
  436. */
  437. xfs_iunlock(quotip, lock_mode);
  438. return -ESRCH;
  439. }
  440. /*
  441. * Find the block map; no allocations yet
  442. */
  443. error = xfs_bmapi_read(quotip, dqp->q_fileoffset,
  444. XFS_DQUOT_CLUSTER_SIZE_FSB, &map, &nmaps, 0);
  445. xfs_iunlock(quotip, lock_mode);
  446. if (error)
  447. return error;
  448. ASSERT(nmaps == 1);
  449. ASSERT(map.br_blockcount == 1);
  450. /*
  451. * Offset of dquot in the (fixed sized) dquot chunk.
  452. */
  453. dqp->q_bufoffset = (id % mp->m_quotainfo->qi_dqperchunk) *
  454. sizeof(xfs_dqblk_t);
  455. ASSERT(map.br_startblock != DELAYSTARTBLOCK);
  456. if (map.br_startblock == HOLESTARTBLOCK) {
  457. /*
  458. * We don't allocate unless we're asked to
  459. */
  460. if (!(flags & XFS_QMOPT_DQALLOC))
  461. return -ENOENT;
  462. ASSERT(tp);
  463. error = xfs_qm_dqalloc(tpp, mp, dqp, quotip,
  464. dqp->q_fileoffset, &bp);
  465. if (error)
  466. return error;
  467. tp = *tpp;
  468. } else {
  469. trace_xfs_dqtobp_read(dqp);
  470. /*
  471. * store the blkno etc so that we don't have to do the
  472. * mapping all the time
  473. */
  474. dqp->q_blkno = XFS_FSB_TO_DADDR(mp, map.br_startblock);
  475. error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
  476. dqp->q_blkno,
  477. mp->m_quotainfo->qi_dqchunklen,
  478. 0, &bp, &xfs_dquot_buf_ops);
  479. if (error == -EFSCORRUPTED && (flags & XFS_QMOPT_DQREPAIR)) {
  480. xfs_dqid_t firstid = (xfs_dqid_t)map.br_startoff *
  481. mp->m_quotainfo->qi_dqperchunk;
  482. ASSERT(bp == NULL);
  483. error = xfs_qm_dqrepair(mp, tp, dqp, firstid, &bp);
  484. }
  485. if (error) {
  486. ASSERT(bp == NULL);
  487. return error;
  488. }
  489. }
  490. ASSERT(xfs_buf_islocked(bp));
  491. *O_bpp = bp;
  492. *O_ddpp = bp->b_addr + dqp->q_bufoffset;
  493. return 0;
  494. }
  495. /*
  496. * Read in the ondisk dquot using dqtobp() then copy it to an incore version,
  497. * and release the buffer immediately.
  498. *
  499. * If XFS_QMOPT_DQALLOC is set, allocate a dquot on disk if it needed.
  500. */
  501. int
  502. xfs_qm_dqread(
  503. struct xfs_mount *mp,
  504. xfs_dqid_t id,
  505. uint type,
  506. uint flags,
  507. struct xfs_dquot **O_dqpp)
  508. {
  509. struct xfs_dquot *dqp;
  510. struct xfs_disk_dquot *ddqp;
  511. struct xfs_buf *bp;
  512. struct xfs_trans *tp = NULL;
  513. int error;
  514. dqp = kmem_zone_zalloc(xfs_qm_dqzone, KM_SLEEP);
  515. dqp->dq_flags = type;
  516. dqp->q_core.d_id = cpu_to_be32(id);
  517. dqp->q_mount = mp;
  518. INIT_LIST_HEAD(&dqp->q_lru);
  519. mutex_init(&dqp->q_qlock);
  520. init_waitqueue_head(&dqp->q_pinwait);
  521. /*
  522. * Because we want to use a counting completion, complete
  523. * the flush completion once to allow a single access to
  524. * the flush completion without blocking.
  525. */
  526. init_completion(&dqp->q_flush);
  527. complete(&dqp->q_flush);
  528. /*
  529. * Make sure group quotas have a different lock class than user
  530. * quotas.
  531. */
  532. switch (type) {
  533. case XFS_DQ_USER:
  534. /* uses the default lock class */
  535. break;
  536. case XFS_DQ_GROUP:
  537. lockdep_set_class(&dqp->q_qlock, &xfs_dquot_group_class);
  538. break;
  539. case XFS_DQ_PROJ:
  540. lockdep_set_class(&dqp->q_qlock, &xfs_dquot_project_class);
  541. break;
  542. default:
  543. ASSERT(0);
  544. break;
  545. }
  546. XFS_STATS_INC(mp, xs_qm_dquot);
  547. trace_xfs_dqread(dqp);
  548. if (flags & XFS_QMOPT_DQALLOC) {
  549. error = xfs_trans_alloc(mp, &M_RES(mp)->tr_qm_dqalloc,
  550. XFS_QM_DQALLOC_SPACE_RES(mp), 0, 0, &tp);
  551. if (error)
  552. goto error0;
  553. }
  554. /*
  555. * get a pointer to the on-disk dquot and the buffer containing it
  556. * dqp already knows its own type (GROUP/USER).
  557. */
  558. error = xfs_qm_dqtobp(&tp, dqp, &ddqp, &bp, flags);
  559. if (error) {
  560. /*
  561. * This can happen if quotas got turned off (ESRCH),
  562. * or if the dquot didn't exist on disk and we ask to
  563. * allocate (ENOENT).
  564. */
  565. trace_xfs_dqread_fail(dqp);
  566. goto error1;
  567. }
  568. /* copy everything from disk dquot to the incore dquot */
  569. memcpy(&dqp->q_core, ddqp, sizeof(xfs_disk_dquot_t));
  570. xfs_qm_dquot_logitem_init(dqp);
  571. /*
  572. * Reservation counters are defined as reservation plus current usage
  573. * to avoid having to add every time.
  574. */
  575. dqp->q_res_bcount = be64_to_cpu(ddqp->d_bcount);
  576. dqp->q_res_icount = be64_to_cpu(ddqp->d_icount);
  577. dqp->q_res_rtbcount = be64_to_cpu(ddqp->d_rtbcount);
  578. /* initialize the dquot speculative prealloc thresholds */
  579. xfs_dquot_set_prealloc_limits(dqp);
  580. /* Mark the buf so that this will stay incore a little longer */
  581. xfs_buf_set_ref(bp, XFS_DQUOT_REF);
  582. /*
  583. * We got the buffer with a xfs_trans_read_buf() (in dqtobp())
  584. * So we need to release with xfs_trans_brelse().
  585. * The strategy here is identical to that of inodes; we lock
  586. * the dquot in xfs_qm_dqget() before making it accessible to
  587. * others. This is because dquots, like inodes, need a good level of
  588. * concurrency, and we don't want to take locks on the entire buffers
  589. * for dquot accesses.
  590. * Note also that the dquot buffer may even be dirty at this point, if
  591. * this particular dquot was repaired. We still aren't afraid to
  592. * brelse it because we have the changes incore.
  593. */
  594. ASSERT(xfs_buf_islocked(bp));
  595. xfs_trans_brelse(tp, bp);
  596. if (tp) {
  597. error = xfs_trans_commit(tp);
  598. if (error)
  599. goto error0;
  600. }
  601. *O_dqpp = dqp;
  602. return error;
  603. error1:
  604. if (tp)
  605. xfs_trans_cancel(tp);
  606. error0:
  607. xfs_qm_dqdestroy(dqp);
  608. *O_dqpp = NULL;
  609. return error;
  610. }
  611. /*
  612. * Advance to the next id in the current chunk, or if at the
  613. * end of the chunk, skip ahead to first id in next allocated chunk
  614. * using the SEEK_DATA interface.
  615. */
  616. static int
  617. xfs_dq_get_next_id(
  618. xfs_mount_t *mp,
  619. uint type,
  620. xfs_dqid_t *id,
  621. loff_t eof)
  622. {
  623. struct xfs_inode *quotip;
  624. xfs_fsblock_t start;
  625. loff_t offset;
  626. uint lock;
  627. xfs_dqid_t next_id;
  628. int error = 0;
  629. /* Simple advance */
  630. next_id = *id + 1;
  631. /* If we'd wrap past the max ID, stop */
  632. if (next_id < *id)
  633. return -ENOENT;
  634. /* If new ID is within the current chunk, advancing it sufficed */
  635. if (next_id % mp->m_quotainfo->qi_dqperchunk) {
  636. *id = next_id;
  637. return 0;
  638. }
  639. /* Nope, next_id is now past the current chunk, so find the next one */
  640. start = (xfs_fsblock_t)next_id / mp->m_quotainfo->qi_dqperchunk;
  641. quotip = xfs_quota_inode(mp, type);
  642. lock = xfs_ilock_data_map_shared(quotip);
  643. offset = __xfs_seek_hole_data(VFS_I(quotip), XFS_FSB_TO_B(mp, start),
  644. eof, SEEK_DATA);
  645. if (offset < 0)
  646. error = offset;
  647. xfs_iunlock(quotip, lock);
  648. /* -ENXIO is essentially "no more data" */
  649. if (error)
  650. return (error == -ENXIO ? -ENOENT: error);
  651. /* Convert next data offset back to a quota id */
  652. *id = XFS_B_TO_FSB(mp, offset) * mp->m_quotainfo->qi_dqperchunk;
  653. return 0;
  654. }
  655. /*
  656. * Given the file system, inode OR id, and type (UDQUOT/GDQUOT), return a
  657. * a locked dquot, doing an allocation (if requested) as needed.
  658. * When both an inode and an id are given, the inode's id takes precedence.
  659. * That is, if the id changes while we don't hold the ilock inside this
  660. * function, the new dquot is returned, not necessarily the one requested
  661. * in the id argument.
  662. */
  663. int
  664. xfs_qm_dqget(
  665. xfs_mount_t *mp,
  666. xfs_inode_t *ip, /* locked inode (optional) */
  667. xfs_dqid_t id, /* uid/projid/gid depending on type */
  668. uint type, /* XFS_DQ_USER/XFS_DQ_PROJ/XFS_DQ_GROUP */
  669. uint flags, /* DQALLOC, DQSUSER, DQREPAIR, DOWARN */
  670. xfs_dquot_t **O_dqpp) /* OUT : locked incore dquot */
  671. {
  672. struct xfs_quotainfo *qi = mp->m_quotainfo;
  673. struct radix_tree_root *tree = xfs_dquot_tree(qi, type);
  674. struct xfs_dquot *dqp;
  675. loff_t eof = 0;
  676. int error;
  677. ASSERT(XFS_IS_QUOTA_RUNNING(mp));
  678. if ((! XFS_IS_UQUOTA_ON(mp) && type == XFS_DQ_USER) ||
  679. (! XFS_IS_PQUOTA_ON(mp) && type == XFS_DQ_PROJ) ||
  680. (! XFS_IS_GQUOTA_ON(mp) && type == XFS_DQ_GROUP)) {
  681. return -ESRCH;
  682. }
  683. #ifdef DEBUG
  684. if (xfs_do_dqerror) {
  685. if ((xfs_dqerror_target == mp->m_ddev_targp) &&
  686. (xfs_dqreq_num++ % xfs_dqerror_mod) == 0) {
  687. xfs_debug(mp, "Returning error in dqget");
  688. return -EIO;
  689. }
  690. }
  691. ASSERT(type == XFS_DQ_USER ||
  692. type == XFS_DQ_PROJ ||
  693. type == XFS_DQ_GROUP);
  694. if (ip) {
  695. ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
  696. ASSERT(xfs_inode_dquot(ip, type) == NULL);
  697. }
  698. #endif
  699. /* Get the end of the quota file if we need it */
  700. if (flags & XFS_QMOPT_DQNEXT) {
  701. struct xfs_inode *quotip;
  702. xfs_fileoff_t last;
  703. uint lock_mode;
  704. quotip = xfs_quota_inode(mp, type);
  705. lock_mode = xfs_ilock_data_map_shared(quotip);
  706. error = xfs_bmap_last_offset(quotip, &last, XFS_DATA_FORK);
  707. xfs_iunlock(quotip, lock_mode);
  708. if (error)
  709. return error;
  710. eof = XFS_FSB_TO_B(mp, last);
  711. }
  712. restart:
  713. mutex_lock(&qi->qi_tree_lock);
  714. dqp = radix_tree_lookup(tree, id);
  715. if (dqp) {
  716. xfs_dqlock(dqp);
  717. if (dqp->dq_flags & XFS_DQ_FREEING) {
  718. xfs_dqunlock(dqp);
  719. mutex_unlock(&qi->qi_tree_lock);
  720. trace_xfs_dqget_freeing(dqp);
  721. delay(1);
  722. goto restart;
  723. }
  724. /* uninit / unused quota found in radix tree, keep looking */
  725. if (flags & XFS_QMOPT_DQNEXT) {
  726. if (XFS_IS_DQUOT_UNINITIALIZED(dqp)) {
  727. xfs_dqunlock(dqp);
  728. mutex_unlock(&qi->qi_tree_lock);
  729. error = xfs_dq_get_next_id(mp, type, &id, eof);
  730. if (error)
  731. return error;
  732. goto restart;
  733. }
  734. }
  735. dqp->q_nrefs++;
  736. mutex_unlock(&qi->qi_tree_lock);
  737. trace_xfs_dqget_hit(dqp);
  738. XFS_STATS_INC(mp, xs_qm_dqcachehits);
  739. *O_dqpp = dqp;
  740. return 0;
  741. }
  742. mutex_unlock(&qi->qi_tree_lock);
  743. XFS_STATS_INC(mp, xs_qm_dqcachemisses);
  744. /*
  745. * Dquot cache miss. We don't want to keep the inode lock across
  746. * a (potential) disk read. Also we don't want to deal with the lock
  747. * ordering between quotainode and this inode. OTOH, dropping the inode
  748. * lock here means dealing with a chown that can happen before
  749. * we re-acquire the lock.
  750. */
  751. if (ip)
  752. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  753. error = xfs_qm_dqread(mp, id, type, flags, &dqp);
  754. if (ip)
  755. xfs_ilock(ip, XFS_ILOCK_EXCL);
  756. /* If we are asked to find next active id, keep looking */
  757. if (error == -ENOENT && (flags & XFS_QMOPT_DQNEXT)) {
  758. error = xfs_dq_get_next_id(mp, type, &id, eof);
  759. if (!error)
  760. goto restart;
  761. }
  762. if (error)
  763. return error;
  764. if (ip) {
  765. /*
  766. * A dquot could be attached to this inode by now, since
  767. * we had dropped the ilock.
  768. */
  769. if (xfs_this_quota_on(mp, type)) {
  770. struct xfs_dquot *dqp1;
  771. dqp1 = xfs_inode_dquot(ip, type);
  772. if (dqp1) {
  773. xfs_qm_dqdestroy(dqp);
  774. dqp = dqp1;
  775. xfs_dqlock(dqp);
  776. goto dqret;
  777. }
  778. } else {
  779. /* inode stays locked on return */
  780. xfs_qm_dqdestroy(dqp);
  781. return -ESRCH;
  782. }
  783. }
  784. mutex_lock(&qi->qi_tree_lock);
  785. error = radix_tree_insert(tree, id, dqp);
  786. if (unlikely(error)) {
  787. WARN_ON(error != -EEXIST);
  788. /*
  789. * Duplicate found. Just throw away the new dquot and start
  790. * over.
  791. */
  792. mutex_unlock(&qi->qi_tree_lock);
  793. trace_xfs_dqget_dup(dqp);
  794. xfs_qm_dqdestroy(dqp);
  795. XFS_STATS_INC(mp, xs_qm_dquot_dups);
  796. goto restart;
  797. }
  798. /*
  799. * We return a locked dquot to the caller, with a reference taken
  800. */
  801. xfs_dqlock(dqp);
  802. dqp->q_nrefs = 1;
  803. qi->qi_dquots++;
  804. mutex_unlock(&qi->qi_tree_lock);
  805. /* If we are asked to find next active id, keep looking */
  806. if (flags & XFS_QMOPT_DQNEXT) {
  807. if (XFS_IS_DQUOT_UNINITIALIZED(dqp)) {
  808. xfs_qm_dqput(dqp);
  809. error = xfs_dq_get_next_id(mp, type, &id, eof);
  810. if (error)
  811. return error;
  812. goto restart;
  813. }
  814. }
  815. dqret:
  816. ASSERT((ip == NULL) || xfs_isilocked(ip, XFS_ILOCK_EXCL));
  817. trace_xfs_dqget_miss(dqp);
  818. *O_dqpp = dqp;
  819. return 0;
  820. }
  821. /*
  822. * Release a reference to the dquot (decrement ref-count) and unlock it.
  823. *
  824. * If there is a group quota attached to this dquot, carefully release that
  825. * too without tripping over deadlocks'n'stuff.
  826. */
  827. void
  828. xfs_qm_dqput(
  829. struct xfs_dquot *dqp)
  830. {
  831. ASSERT(dqp->q_nrefs > 0);
  832. ASSERT(XFS_DQ_IS_LOCKED(dqp));
  833. trace_xfs_dqput(dqp);
  834. if (--dqp->q_nrefs == 0) {
  835. struct xfs_quotainfo *qi = dqp->q_mount->m_quotainfo;
  836. trace_xfs_dqput_free(dqp);
  837. if (list_lru_add(&qi->qi_lru, &dqp->q_lru))
  838. XFS_STATS_INC(dqp->q_mount, xs_qm_dquot_unused);
  839. }
  840. xfs_dqunlock(dqp);
  841. }
  842. /*
  843. * Release a dquot. Flush it if dirty, then dqput() it.
  844. * dquot must not be locked.
  845. */
  846. void
  847. xfs_qm_dqrele(
  848. xfs_dquot_t *dqp)
  849. {
  850. if (!dqp)
  851. return;
  852. trace_xfs_dqrele(dqp);
  853. xfs_dqlock(dqp);
  854. /*
  855. * We don't care to flush it if the dquot is dirty here.
  856. * That will create stutters that we want to avoid.
  857. * Instead we do a delayed write when we try to reclaim
  858. * a dirty dquot. Also xfs_sync will take part of the burden...
  859. */
  860. xfs_qm_dqput(dqp);
  861. }
  862. /*
  863. * This is the dquot flushing I/O completion routine. It is called
  864. * from interrupt level when the buffer containing the dquot is
  865. * flushed to disk. It is responsible for removing the dquot logitem
  866. * from the AIL if it has not been re-logged, and unlocking the dquot's
  867. * flush lock. This behavior is very similar to that of inodes..
  868. */
  869. STATIC void
  870. xfs_qm_dqflush_done(
  871. struct xfs_buf *bp,
  872. struct xfs_log_item *lip)
  873. {
  874. xfs_dq_logitem_t *qip = (struct xfs_dq_logitem *)lip;
  875. xfs_dquot_t *dqp = qip->qli_dquot;
  876. struct xfs_ail *ailp = lip->li_ailp;
  877. /*
  878. * We only want to pull the item from the AIL if its
  879. * location in the log has not changed since we started the flush.
  880. * Thus, we only bother if the dquot's lsn has
  881. * not changed. First we check the lsn outside the lock
  882. * since it's cheaper, and then we recheck while
  883. * holding the lock before removing the dquot from the AIL.
  884. */
  885. if ((lip->li_flags & XFS_LI_IN_AIL) &&
  886. ((lip->li_lsn == qip->qli_flush_lsn) ||
  887. (lip->li_flags & XFS_LI_FAILED))) {
  888. /* xfs_trans_ail_delete() drops the AIL lock. */
  889. spin_lock(&ailp->xa_lock);
  890. if (lip->li_lsn == qip->qli_flush_lsn) {
  891. xfs_trans_ail_delete(ailp, lip, SHUTDOWN_CORRUPT_INCORE);
  892. } else {
  893. /*
  894. * Clear the failed state since we are about to drop the
  895. * flush lock
  896. */
  897. if (lip->li_flags & XFS_LI_FAILED)
  898. xfs_clear_li_failed(lip);
  899. spin_unlock(&ailp->xa_lock);
  900. }
  901. }
  902. /*
  903. * Release the dq's flush lock since we're done with it.
  904. */
  905. xfs_dqfunlock(dqp);
  906. }
  907. /*
  908. * Write a modified dquot to disk.
  909. * The dquot must be locked and the flush lock too taken by caller.
  910. * The flush lock will not be unlocked until the dquot reaches the disk,
  911. * but the dquot is free to be unlocked and modified by the caller
  912. * in the interim. Dquot is still locked on return. This behavior is
  913. * identical to that of inodes.
  914. */
  915. int
  916. xfs_qm_dqflush(
  917. struct xfs_dquot *dqp,
  918. struct xfs_buf **bpp)
  919. {
  920. struct xfs_mount *mp = dqp->q_mount;
  921. struct xfs_buf *bp;
  922. struct xfs_disk_dquot *ddqp;
  923. int error;
  924. ASSERT(XFS_DQ_IS_LOCKED(dqp));
  925. ASSERT(!completion_done(&dqp->q_flush));
  926. trace_xfs_dqflush(dqp);
  927. *bpp = NULL;
  928. xfs_qm_dqunpin_wait(dqp);
  929. /*
  930. * This may have been unpinned because the filesystem is shutting
  931. * down forcibly. If that's the case we must not write this dquot
  932. * to disk, because the log record didn't make it to disk.
  933. *
  934. * We also have to remove the log item from the AIL in this case,
  935. * as we wait for an emptry AIL as part of the unmount process.
  936. */
  937. if (XFS_FORCED_SHUTDOWN(mp)) {
  938. struct xfs_log_item *lip = &dqp->q_logitem.qli_item;
  939. dqp->dq_flags &= ~XFS_DQ_DIRTY;
  940. xfs_trans_ail_remove(lip, SHUTDOWN_CORRUPT_INCORE);
  941. error = -EIO;
  942. goto out_unlock;
  943. }
  944. /*
  945. * Get the buffer containing the on-disk dquot
  946. */
  947. error = xfs_trans_read_buf(mp, NULL, mp->m_ddev_targp, dqp->q_blkno,
  948. mp->m_quotainfo->qi_dqchunklen, 0, &bp,
  949. &xfs_dquot_buf_ops);
  950. if (error)
  951. goto out_unlock;
  952. /*
  953. * Calculate the location of the dquot inside the buffer.
  954. */
  955. ddqp = bp->b_addr + dqp->q_bufoffset;
  956. /*
  957. * A simple sanity check in case we got a corrupted dquot..
  958. */
  959. error = xfs_dqcheck(mp, &dqp->q_core, be32_to_cpu(ddqp->d_id), 0,
  960. XFS_QMOPT_DOWARN, "dqflush (incore copy)");
  961. if (error) {
  962. xfs_buf_relse(bp);
  963. xfs_dqfunlock(dqp);
  964. xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
  965. return -EIO;
  966. }
  967. /* This is the only portion of data that needs to persist */
  968. memcpy(ddqp, &dqp->q_core, sizeof(xfs_disk_dquot_t));
  969. /*
  970. * Clear the dirty field and remember the flush lsn for later use.
  971. */
  972. dqp->dq_flags &= ~XFS_DQ_DIRTY;
  973. xfs_trans_ail_copy_lsn(mp->m_ail, &dqp->q_logitem.qli_flush_lsn,
  974. &dqp->q_logitem.qli_item.li_lsn);
  975. /*
  976. * copy the lsn into the on-disk dquot now while we have the in memory
  977. * dquot here. This can't be done later in the write verifier as we
  978. * can't get access to the log item at that point in time.
  979. *
  980. * We also calculate the CRC here so that the on-disk dquot in the
  981. * buffer always has a valid CRC. This ensures there is no possibility
  982. * of a dquot without an up-to-date CRC getting to disk.
  983. */
  984. if (xfs_sb_version_hascrc(&mp->m_sb)) {
  985. struct xfs_dqblk *dqb = (struct xfs_dqblk *)ddqp;
  986. dqb->dd_lsn = cpu_to_be64(dqp->q_logitem.qli_item.li_lsn);
  987. xfs_update_cksum((char *)dqb, sizeof(struct xfs_dqblk),
  988. XFS_DQUOT_CRC_OFF);
  989. }
  990. /*
  991. * Attach an iodone routine so that we can remove this dquot from the
  992. * AIL and release the flush lock once the dquot is synced to disk.
  993. */
  994. xfs_buf_attach_iodone(bp, xfs_qm_dqflush_done,
  995. &dqp->q_logitem.qli_item);
  996. /*
  997. * If the buffer is pinned then push on the log so we won't
  998. * get stuck waiting in the write for too long.
  999. */
  1000. if (xfs_buf_ispinned(bp)) {
  1001. trace_xfs_dqflush_force(dqp);
  1002. xfs_log_force(mp, 0);
  1003. }
  1004. trace_xfs_dqflush_done(dqp);
  1005. *bpp = bp;
  1006. return 0;
  1007. out_unlock:
  1008. xfs_dqfunlock(dqp);
  1009. return -EIO;
  1010. }
  1011. /*
  1012. * Lock two xfs_dquot structures.
  1013. *
  1014. * To avoid deadlocks we always lock the quota structure with
  1015. * the lowerd id first.
  1016. */
  1017. void
  1018. xfs_dqlock2(
  1019. xfs_dquot_t *d1,
  1020. xfs_dquot_t *d2)
  1021. {
  1022. if (d1 && d2) {
  1023. ASSERT(d1 != d2);
  1024. if (be32_to_cpu(d1->q_core.d_id) >
  1025. be32_to_cpu(d2->q_core.d_id)) {
  1026. mutex_lock(&d2->q_qlock);
  1027. mutex_lock_nested(&d1->q_qlock, XFS_QLOCK_NESTED);
  1028. } else {
  1029. mutex_lock(&d1->q_qlock);
  1030. mutex_lock_nested(&d2->q_qlock, XFS_QLOCK_NESTED);
  1031. }
  1032. } else if (d1) {
  1033. mutex_lock(&d1->q_qlock);
  1034. } else if (d2) {
  1035. mutex_lock(&d2->q_qlock);
  1036. }
  1037. }
  1038. int __init
  1039. xfs_qm_init(void)
  1040. {
  1041. xfs_qm_dqzone =
  1042. kmem_zone_init(sizeof(struct xfs_dquot), "xfs_dquot");
  1043. if (!xfs_qm_dqzone)
  1044. goto out;
  1045. xfs_qm_dqtrxzone =
  1046. kmem_zone_init(sizeof(struct xfs_dquot_acct), "xfs_dqtrx");
  1047. if (!xfs_qm_dqtrxzone)
  1048. goto out_free_dqzone;
  1049. return 0;
  1050. out_free_dqzone:
  1051. kmem_zone_destroy(xfs_qm_dqzone);
  1052. out:
  1053. return -ENOMEM;
  1054. }
  1055. void
  1056. xfs_qm_exit(void)
  1057. {
  1058. kmem_zone_destroy(xfs_qm_dqtrxzone);
  1059. kmem_zone_destroy(xfs_qm_dqzone);
  1060. }