xfs_dquot.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  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_bit.h"
  21. #include "xfs_log.h"
  22. #include "xfs_inum.h"
  23. #include "xfs_trans.h"
  24. #include "xfs_sb.h"
  25. #include "xfs_ag.h"
  26. #include "xfs_alloc.h"
  27. #include "xfs_quota.h"
  28. #include "xfs_mount.h"
  29. #include "xfs_bmap_btree.h"
  30. #include "xfs_inode.h"
  31. #include "xfs_bmap.h"
  32. #include "xfs_rtalloc.h"
  33. #include "xfs_error.h"
  34. #include "xfs_itable.h"
  35. #include "xfs_attr.h"
  36. #include "xfs_buf_item.h"
  37. #include "xfs_trans_space.h"
  38. #include "xfs_trans_priv.h"
  39. #include "xfs_qm.h"
  40. #include "xfs_trace.h"
  41. /*
  42. * Lock order:
  43. *
  44. * ip->i_lock
  45. * qh->qh_lock
  46. * qi->qi_dqlist_lock
  47. * dquot->q_qlock (xfs_dqlock() and friends)
  48. * dquot->q_flush (xfs_dqflock() and friends)
  49. * xfs_Gqm->qm_dqfrlist_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. static struct lock_class_key xfs_dquot_other_class;
  61. /*
  62. * This is called to free all the memory associated with a dquot
  63. */
  64. void
  65. xfs_qm_dqdestroy(
  66. xfs_dquot_t *dqp)
  67. {
  68. ASSERT(list_empty(&dqp->q_freelist));
  69. mutex_destroy(&dqp->q_qlock);
  70. kmem_zone_free(xfs_Gqm->qm_dqzone, dqp);
  71. atomic_dec(&xfs_Gqm->qm_totaldquots);
  72. }
  73. /*
  74. * If default limits are in force, push them into the dquot now.
  75. * We overwrite the dquot limits only if they are zero and this
  76. * is not the root dquot.
  77. */
  78. void
  79. xfs_qm_adjust_dqlimits(
  80. xfs_mount_t *mp,
  81. xfs_disk_dquot_t *d)
  82. {
  83. xfs_quotainfo_t *q = mp->m_quotainfo;
  84. ASSERT(d->d_id);
  85. if (q->qi_bsoftlimit && !d->d_blk_softlimit)
  86. d->d_blk_softlimit = cpu_to_be64(q->qi_bsoftlimit);
  87. if (q->qi_bhardlimit && !d->d_blk_hardlimit)
  88. d->d_blk_hardlimit = cpu_to_be64(q->qi_bhardlimit);
  89. if (q->qi_isoftlimit && !d->d_ino_softlimit)
  90. d->d_ino_softlimit = cpu_to_be64(q->qi_isoftlimit);
  91. if (q->qi_ihardlimit && !d->d_ino_hardlimit)
  92. d->d_ino_hardlimit = cpu_to_be64(q->qi_ihardlimit);
  93. if (q->qi_rtbsoftlimit && !d->d_rtb_softlimit)
  94. d->d_rtb_softlimit = cpu_to_be64(q->qi_rtbsoftlimit);
  95. if (q->qi_rtbhardlimit && !d->d_rtb_hardlimit)
  96. d->d_rtb_hardlimit = cpu_to_be64(q->qi_rtbhardlimit);
  97. }
  98. /*
  99. * Check the limits and timers of a dquot and start or reset timers
  100. * if necessary.
  101. * This gets called even when quota enforcement is OFF, which makes our
  102. * life a little less complicated. (We just don't reject any quota
  103. * reservations in that case, when enforcement is off).
  104. * We also return 0 as the values of the timers in Q_GETQUOTA calls, when
  105. * enforcement's off.
  106. * In contrast, warnings are a little different in that they don't
  107. * 'automatically' get started when limits get exceeded. They do
  108. * get reset to zero, however, when we find the count to be under
  109. * the soft limit (they are only ever set non-zero via userspace).
  110. */
  111. void
  112. xfs_qm_adjust_dqtimers(
  113. xfs_mount_t *mp,
  114. xfs_disk_dquot_t *d)
  115. {
  116. ASSERT(d->d_id);
  117. #ifdef DEBUG
  118. if (d->d_blk_hardlimit)
  119. ASSERT(be64_to_cpu(d->d_blk_softlimit) <=
  120. be64_to_cpu(d->d_blk_hardlimit));
  121. if (d->d_ino_hardlimit)
  122. ASSERT(be64_to_cpu(d->d_ino_softlimit) <=
  123. be64_to_cpu(d->d_ino_hardlimit));
  124. if (d->d_rtb_hardlimit)
  125. ASSERT(be64_to_cpu(d->d_rtb_softlimit) <=
  126. be64_to_cpu(d->d_rtb_hardlimit));
  127. #endif
  128. if (!d->d_btimer) {
  129. if ((d->d_blk_softlimit &&
  130. (be64_to_cpu(d->d_bcount) >
  131. be64_to_cpu(d->d_blk_softlimit))) ||
  132. (d->d_blk_hardlimit &&
  133. (be64_to_cpu(d->d_bcount) >
  134. be64_to_cpu(d->d_blk_hardlimit)))) {
  135. d->d_btimer = cpu_to_be32(get_seconds() +
  136. mp->m_quotainfo->qi_btimelimit);
  137. } else {
  138. d->d_bwarns = 0;
  139. }
  140. } else {
  141. if ((!d->d_blk_softlimit ||
  142. (be64_to_cpu(d->d_bcount) <=
  143. be64_to_cpu(d->d_blk_softlimit))) &&
  144. (!d->d_blk_hardlimit ||
  145. (be64_to_cpu(d->d_bcount) <=
  146. be64_to_cpu(d->d_blk_hardlimit)))) {
  147. d->d_btimer = 0;
  148. }
  149. }
  150. if (!d->d_itimer) {
  151. if ((d->d_ino_softlimit &&
  152. (be64_to_cpu(d->d_icount) >
  153. be64_to_cpu(d->d_ino_softlimit))) ||
  154. (d->d_ino_hardlimit &&
  155. (be64_to_cpu(d->d_icount) >
  156. be64_to_cpu(d->d_ino_hardlimit)))) {
  157. d->d_itimer = cpu_to_be32(get_seconds() +
  158. mp->m_quotainfo->qi_itimelimit);
  159. } else {
  160. d->d_iwarns = 0;
  161. }
  162. } else {
  163. if ((!d->d_ino_softlimit ||
  164. (be64_to_cpu(d->d_icount) <=
  165. be64_to_cpu(d->d_ino_softlimit))) &&
  166. (!d->d_ino_hardlimit ||
  167. (be64_to_cpu(d->d_icount) <=
  168. be64_to_cpu(d->d_ino_hardlimit)))) {
  169. d->d_itimer = 0;
  170. }
  171. }
  172. if (!d->d_rtbtimer) {
  173. if ((d->d_rtb_softlimit &&
  174. (be64_to_cpu(d->d_rtbcount) >
  175. be64_to_cpu(d->d_rtb_softlimit))) ||
  176. (d->d_rtb_hardlimit &&
  177. (be64_to_cpu(d->d_rtbcount) >
  178. be64_to_cpu(d->d_rtb_hardlimit)))) {
  179. d->d_rtbtimer = cpu_to_be32(get_seconds() +
  180. mp->m_quotainfo->qi_rtbtimelimit);
  181. } else {
  182. d->d_rtbwarns = 0;
  183. }
  184. } else {
  185. if ((!d->d_rtb_softlimit ||
  186. (be64_to_cpu(d->d_rtbcount) <=
  187. be64_to_cpu(d->d_rtb_softlimit))) &&
  188. (!d->d_rtb_hardlimit ||
  189. (be64_to_cpu(d->d_rtbcount) <=
  190. be64_to_cpu(d->d_rtb_hardlimit)))) {
  191. d->d_rtbtimer = 0;
  192. }
  193. }
  194. }
  195. /*
  196. * initialize a buffer full of dquots and log the whole thing
  197. */
  198. STATIC void
  199. xfs_qm_init_dquot_blk(
  200. xfs_trans_t *tp,
  201. xfs_mount_t *mp,
  202. xfs_dqid_t id,
  203. uint type,
  204. xfs_buf_t *bp)
  205. {
  206. struct xfs_quotainfo *q = mp->m_quotainfo;
  207. xfs_dqblk_t *d;
  208. int curid, i;
  209. ASSERT(tp);
  210. ASSERT(xfs_buf_islocked(bp));
  211. d = bp->b_addr;
  212. /*
  213. * ID of the first dquot in the block - id's are zero based.
  214. */
  215. curid = id - (id % q->qi_dqperchunk);
  216. ASSERT(curid >= 0);
  217. memset(d, 0, BBTOB(q->qi_dqchunklen));
  218. for (i = 0; i < q->qi_dqperchunk; i++, d++, curid++) {
  219. d->dd_diskdq.d_magic = cpu_to_be16(XFS_DQUOT_MAGIC);
  220. d->dd_diskdq.d_version = XFS_DQUOT_VERSION;
  221. d->dd_diskdq.d_id = cpu_to_be32(curid);
  222. d->dd_diskdq.d_flags = type;
  223. }
  224. xfs_trans_dquot_buf(tp, bp,
  225. (type & XFS_DQ_USER ? XFS_BLF_UDQUOT_BUF :
  226. ((type & XFS_DQ_PROJ) ? XFS_BLF_PDQUOT_BUF :
  227. XFS_BLF_GDQUOT_BUF)));
  228. xfs_trans_log_buf(tp, bp, 0, BBTOB(q->qi_dqchunklen) - 1);
  229. }
  230. /*
  231. * Allocate a block and fill it with dquots.
  232. * This is called when the bmapi finds a hole.
  233. */
  234. STATIC int
  235. xfs_qm_dqalloc(
  236. xfs_trans_t **tpp,
  237. xfs_mount_t *mp,
  238. xfs_dquot_t *dqp,
  239. xfs_inode_t *quotip,
  240. xfs_fileoff_t offset_fsb,
  241. xfs_buf_t **O_bpp)
  242. {
  243. xfs_fsblock_t firstblock;
  244. xfs_bmap_free_t flist;
  245. xfs_bmbt_irec_t map;
  246. int nmaps, error, committed;
  247. xfs_buf_t *bp;
  248. xfs_trans_t *tp = *tpp;
  249. ASSERT(tp != NULL);
  250. trace_xfs_dqalloc(dqp);
  251. /*
  252. * Initialize the bmap freelist prior to calling bmapi code.
  253. */
  254. xfs_bmap_init(&flist, &firstblock);
  255. xfs_ilock(quotip, XFS_ILOCK_EXCL);
  256. /*
  257. * Return if this type of quotas is turned off while we didn't
  258. * have an inode lock
  259. */
  260. if (!xfs_this_quota_on(dqp->q_mount, dqp->dq_flags)) {
  261. xfs_iunlock(quotip, XFS_ILOCK_EXCL);
  262. return (ESRCH);
  263. }
  264. xfs_trans_ijoin(tp, quotip, XFS_ILOCK_EXCL);
  265. nmaps = 1;
  266. error = xfs_bmapi_write(tp, quotip, offset_fsb,
  267. XFS_DQUOT_CLUSTER_SIZE_FSB, XFS_BMAPI_METADATA,
  268. &firstblock, XFS_QM_DQALLOC_SPACE_RES(mp),
  269. &map, &nmaps, &flist);
  270. if (error)
  271. goto error0;
  272. ASSERT(map.br_blockcount == XFS_DQUOT_CLUSTER_SIZE_FSB);
  273. ASSERT(nmaps == 1);
  274. ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
  275. (map.br_startblock != HOLESTARTBLOCK));
  276. /*
  277. * Keep track of the blkno to save a lookup later
  278. */
  279. dqp->q_blkno = XFS_FSB_TO_DADDR(mp, map.br_startblock);
  280. /* now we can just get the buffer (there's nothing to read yet) */
  281. bp = xfs_trans_get_buf(tp, mp->m_ddev_targp,
  282. dqp->q_blkno,
  283. mp->m_quotainfo->qi_dqchunklen,
  284. 0);
  285. error = xfs_buf_geterror(bp);
  286. if (error)
  287. goto error1;
  288. /*
  289. * Make a chunk of dquots out of this buffer and log
  290. * the entire thing.
  291. */
  292. xfs_qm_init_dquot_blk(tp, mp, be32_to_cpu(dqp->q_core.d_id),
  293. dqp->dq_flags & XFS_DQ_ALLTYPES, bp);
  294. /*
  295. * xfs_bmap_finish() may commit the current transaction and
  296. * start a second transaction if the freelist is not empty.
  297. *
  298. * Since we still want to modify this buffer, we need to
  299. * ensure that the buffer is not released on commit of
  300. * the first transaction and ensure the buffer is added to the
  301. * second transaction.
  302. *
  303. * If there is only one transaction then don't stop the buffer
  304. * from being released when it commits later on.
  305. */
  306. xfs_trans_bhold(tp, bp);
  307. if ((error = xfs_bmap_finish(tpp, &flist, &committed))) {
  308. goto error1;
  309. }
  310. if (committed) {
  311. tp = *tpp;
  312. xfs_trans_bjoin(tp, bp);
  313. } else {
  314. xfs_trans_bhold_release(tp, bp);
  315. }
  316. *O_bpp = bp;
  317. return 0;
  318. error1:
  319. xfs_bmap_cancel(&flist);
  320. error0:
  321. xfs_iunlock(quotip, XFS_ILOCK_EXCL);
  322. return (error);
  323. }
  324. /*
  325. * Maps a dquot to the buffer containing its on-disk version.
  326. * This returns a ptr to the buffer containing the on-disk dquot
  327. * in the bpp param, and a ptr to the on-disk dquot within that buffer
  328. */
  329. STATIC int
  330. xfs_qm_dqtobp(
  331. xfs_trans_t **tpp,
  332. xfs_dquot_t *dqp,
  333. xfs_disk_dquot_t **O_ddpp,
  334. xfs_buf_t **O_bpp,
  335. uint flags)
  336. {
  337. xfs_bmbt_irec_t map;
  338. int nmaps = 1, error;
  339. xfs_buf_t *bp;
  340. xfs_inode_t *quotip = XFS_DQ_TO_QIP(dqp);
  341. xfs_mount_t *mp = dqp->q_mount;
  342. xfs_disk_dquot_t *ddq;
  343. xfs_dqid_t id = be32_to_cpu(dqp->q_core.d_id);
  344. xfs_trans_t *tp = (tpp ? *tpp : NULL);
  345. dqp->q_fileoffset = (xfs_fileoff_t)id / mp->m_quotainfo->qi_dqperchunk;
  346. xfs_ilock(quotip, XFS_ILOCK_SHARED);
  347. if (!xfs_this_quota_on(dqp->q_mount, dqp->dq_flags)) {
  348. /*
  349. * Return if this type of quotas is turned off while we
  350. * didn't have the quota inode lock.
  351. */
  352. xfs_iunlock(quotip, XFS_ILOCK_SHARED);
  353. return ESRCH;
  354. }
  355. /*
  356. * Find the block map; no allocations yet
  357. */
  358. error = xfs_bmapi_read(quotip, dqp->q_fileoffset,
  359. XFS_DQUOT_CLUSTER_SIZE_FSB, &map, &nmaps, 0);
  360. xfs_iunlock(quotip, XFS_ILOCK_SHARED);
  361. if (error)
  362. return error;
  363. ASSERT(nmaps == 1);
  364. ASSERT(map.br_blockcount == 1);
  365. /*
  366. * Offset of dquot in the (fixed sized) dquot chunk.
  367. */
  368. dqp->q_bufoffset = (id % mp->m_quotainfo->qi_dqperchunk) *
  369. sizeof(xfs_dqblk_t);
  370. ASSERT(map.br_startblock != DELAYSTARTBLOCK);
  371. if (map.br_startblock == HOLESTARTBLOCK) {
  372. /*
  373. * We don't allocate unless we're asked to
  374. */
  375. if (!(flags & XFS_QMOPT_DQALLOC))
  376. return ENOENT;
  377. ASSERT(tp);
  378. error = xfs_qm_dqalloc(tpp, mp, dqp, quotip,
  379. dqp->q_fileoffset, &bp);
  380. if (error)
  381. return error;
  382. tp = *tpp;
  383. } else {
  384. trace_xfs_dqtobp_read(dqp);
  385. /*
  386. * store the blkno etc so that we don't have to do the
  387. * mapping all the time
  388. */
  389. dqp->q_blkno = XFS_FSB_TO_DADDR(mp, map.br_startblock);
  390. error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
  391. dqp->q_blkno,
  392. mp->m_quotainfo->qi_dqchunklen,
  393. 0, &bp);
  394. if (error || !bp)
  395. return XFS_ERROR(error);
  396. }
  397. ASSERT(xfs_buf_islocked(bp));
  398. /*
  399. * calculate the location of the dquot inside the buffer.
  400. */
  401. ddq = bp->b_addr + dqp->q_bufoffset;
  402. /*
  403. * A simple sanity check in case we got a corrupted dquot...
  404. */
  405. error = xfs_qm_dqcheck(mp, ddq, id, dqp->dq_flags & XFS_DQ_ALLTYPES,
  406. flags & (XFS_QMOPT_DQREPAIR|XFS_QMOPT_DOWARN),
  407. "dqtobp");
  408. if (error) {
  409. if (!(flags & XFS_QMOPT_DQREPAIR)) {
  410. xfs_trans_brelse(tp, bp);
  411. return XFS_ERROR(EIO);
  412. }
  413. }
  414. *O_bpp = bp;
  415. *O_ddpp = ddq;
  416. return (0);
  417. }
  418. /*
  419. * Read in the ondisk dquot using dqtobp() then copy it to an incore version,
  420. * and release the buffer immediately.
  421. *
  422. * If XFS_QMOPT_DQALLOC is set, allocate a dquot on disk if it needed.
  423. */
  424. int
  425. xfs_qm_dqread(
  426. struct xfs_mount *mp,
  427. xfs_dqid_t id,
  428. uint type,
  429. uint flags,
  430. struct xfs_dquot **O_dqpp)
  431. {
  432. struct xfs_dquot *dqp;
  433. struct xfs_disk_dquot *ddqp;
  434. struct xfs_buf *bp;
  435. struct xfs_trans *tp = NULL;
  436. int error;
  437. int cancelflags = 0;
  438. dqp = kmem_zone_zalloc(xfs_Gqm->qm_dqzone, KM_SLEEP);
  439. dqp->dq_flags = type;
  440. dqp->q_core.d_id = cpu_to_be32(id);
  441. dqp->q_mount = mp;
  442. INIT_LIST_HEAD(&dqp->q_freelist);
  443. mutex_init(&dqp->q_qlock);
  444. init_waitqueue_head(&dqp->q_pinwait);
  445. /*
  446. * Because we want to use a counting completion, complete
  447. * the flush completion once to allow a single access to
  448. * the flush completion without blocking.
  449. */
  450. init_completion(&dqp->q_flush);
  451. complete(&dqp->q_flush);
  452. /*
  453. * Make sure group quotas have a different lock class than user
  454. * quotas.
  455. */
  456. if (!(type & XFS_DQ_USER))
  457. lockdep_set_class(&dqp->q_qlock, &xfs_dquot_other_class);
  458. atomic_inc(&xfs_Gqm->qm_totaldquots);
  459. trace_xfs_dqread(dqp);
  460. if (flags & XFS_QMOPT_DQALLOC) {
  461. tp = xfs_trans_alloc(mp, XFS_TRANS_QM_DQALLOC);
  462. error = xfs_trans_reserve(tp, XFS_QM_DQALLOC_SPACE_RES(mp),
  463. XFS_WRITE_LOG_RES(mp) +
  464. /*
  465. * Round the chunklen up to the next multiple
  466. * of 128 (buf log item chunk size)).
  467. */
  468. BBTOB(mp->m_quotainfo->qi_dqchunklen) - 1 + 128,
  469. 0,
  470. XFS_TRANS_PERM_LOG_RES,
  471. XFS_WRITE_LOG_COUNT);
  472. if (error)
  473. goto error1;
  474. cancelflags = XFS_TRANS_RELEASE_LOG_RES;
  475. }
  476. /*
  477. * get a pointer to the on-disk dquot and the buffer containing it
  478. * dqp already knows its own type (GROUP/USER).
  479. */
  480. error = xfs_qm_dqtobp(&tp, dqp, &ddqp, &bp, flags);
  481. if (error) {
  482. /*
  483. * This can happen if quotas got turned off (ESRCH),
  484. * or if the dquot didn't exist on disk and we ask to
  485. * allocate (ENOENT).
  486. */
  487. trace_xfs_dqread_fail(dqp);
  488. cancelflags |= XFS_TRANS_ABORT;
  489. goto error1;
  490. }
  491. /* copy everything from disk dquot to the incore dquot */
  492. memcpy(&dqp->q_core, ddqp, sizeof(xfs_disk_dquot_t));
  493. xfs_qm_dquot_logitem_init(dqp);
  494. /*
  495. * Reservation counters are defined as reservation plus current usage
  496. * to avoid having to add every time.
  497. */
  498. dqp->q_res_bcount = be64_to_cpu(ddqp->d_bcount);
  499. dqp->q_res_icount = be64_to_cpu(ddqp->d_icount);
  500. dqp->q_res_rtbcount = be64_to_cpu(ddqp->d_rtbcount);
  501. /* Mark the buf so that this will stay incore a little longer */
  502. xfs_buf_set_ref(bp, XFS_DQUOT_REF);
  503. /*
  504. * We got the buffer with a xfs_trans_read_buf() (in dqtobp())
  505. * So we need to release with xfs_trans_brelse().
  506. * The strategy here is identical to that of inodes; we lock
  507. * the dquot in xfs_qm_dqget() before making it accessible to
  508. * others. This is because dquots, like inodes, need a good level of
  509. * concurrency, and we don't want to take locks on the entire buffers
  510. * for dquot accesses.
  511. * Note also that the dquot buffer may even be dirty at this point, if
  512. * this particular dquot was repaired. We still aren't afraid to
  513. * brelse it because we have the changes incore.
  514. */
  515. ASSERT(xfs_buf_islocked(bp));
  516. xfs_trans_brelse(tp, bp);
  517. if (tp) {
  518. error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
  519. if (error)
  520. goto error0;
  521. }
  522. *O_dqpp = dqp;
  523. return error;
  524. error1:
  525. if (tp)
  526. xfs_trans_cancel(tp, cancelflags);
  527. error0:
  528. xfs_qm_dqdestroy(dqp);
  529. *O_dqpp = NULL;
  530. return error;
  531. }
  532. /*
  533. * Lookup a dquot in the incore dquot hashtable. We keep two separate
  534. * hashtables for user and group dquots; and, these are global tables
  535. * inside the XQM, not per-filesystem tables.
  536. * The hash chain must be locked by caller, and it is left locked
  537. * on return. Returning dquot is locked.
  538. */
  539. STATIC int
  540. xfs_qm_dqlookup(
  541. xfs_mount_t *mp,
  542. xfs_dqid_t id,
  543. xfs_dqhash_t *qh,
  544. xfs_dquot_t **O_dqpp)
  545. {
  546. xfs_dquot_t *dqp;
  547. ASSERT(mutex_is_locked(&qh->qh_lock));
  548. /*
  549. * Traverse the hashchain looking for a match
  550. */
  551. list_for_each_entry(dqp, &qh->qh_list, q_hashlist) {
  552. /*
  553. * We already have the hashlock. We don't need the
  554. * dqlock to look at the id field of the dquot, since the
  555. * id can't be modified without the hashlock anyway.
  556. */
  557. if (be32_to_cpu(dqp->q_core.d_id) != id || dqp->q_mount != mp)
  558. continue;
  559. trace_xfs_dqlookup_found(dqp);
  560. xfs_dqlock(dqp);
  561. if (dqp->dq_flags & XFS_DQ_FREEING) {
  562. *O_dqpp = NULL;
  563. xfs_dqunlock(dqp);
  564. return -1;
  565. }
  566. dqp->q_nrefs++;
  567. /*
  568. * move the dquot to the front of the hashchain
  569. */
  570. list_move(&dqp->q_hashlist, &qh->qh_list);
  571. trace_xfs_dqlookup_done(dqp);
  572. *O_dqpp = dqp;
  573. return 0;
  574. }
  575. *O_dqpp = NULL;
  576. return 1;
  577. }
  578. /*
  579. * Given the file system, inode OR id, and type (UDQUOT/GDQUOT), return a
  580. * a locked dquot, doing an allocation (if requested) as needed.
  581. * When both an inode and an id are given, the inode's id takes precedence.
  582. * That is, if the id changes while we don't hold the ilock inside this
  583. * function, the new dquot is returned, not necessarily the one requested
  584. * in the id argument.
  585. */
  586. int
  587. xfs_qm_dqget(
  588. xfs_mount_t *mp,
  589. xfs_inode_t *ip, /* locked inode (optional) */
  590. xfs_dqid_t id, /* uid/projid/gid depending on type */
  591. uint type, /* XFS_DQ_USER/XFS_DQ_PROJ/XFS_DQ_GROUP */
  592. uint flags, /* DQALLOC, DQSUSER, DQREPAIR, DOWARN */
  593. xfs_dquot_t **O_dqpp) /* OUT : locked incore dquot */
  594. {
  595. xfs_dquot_t *dqp, *dqp1;
  596. xfs_dqhash_t *h;
  597. uint version;
  598. int error;
  599. ASSERT(XFS_IS_QUOTA_RUNNING(mp));
  600. if ((! XFS_IS_UQUOTA_ON(mp) && type == XFS_DQ_USER) ||
  601. (! XFS_IS_PQUOTA_ON(mp) && type == XFS_DQ_PROJ) ||
  602. (! XFS_IS_GQUOTA_ON(mp) && type == XFS_DQ_GROUP)) {
  603. return (ESRCH);
  604. }
  605. h = XFS_DQ_HASH(mp, id, type);
  606. #ifdef DEBUG
  607. if (xfs_do_dqerror) {
  608. if ((xfs_dqerror_target == mp->m_ddev_targp) &&
  609. (xfs_dqreq_num++ % xfs_dqerror_mod) == 0) {
  610. xfs_debug(mp, "Returning error in dqget");
  611. return (EIO);
  612. }
  613. }
  614. ASSERT(type == XFS_DQ_USER ||
  615. type == XFS_DQ_PROJ ||
  616. type == XFS_DQ_GROUP);
  617. if (ip) {
  618. ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
  619. ASSERT(xfs_inode_dquot(ip, type) == NULL);
  620. }
  621. #endif
  622. restart:
  623. mutex_lock(&h->qh_lock);
  624. /*
  625. * Look in the cache (hashtable).
  626. * The chain is kept locked during lookup.
  627. */
  628. switch (xfs_qm_dqlookup(mp, id, h, O_dqpp)) {
  629. case -1:
  630. XQM_STATS_INC(xqmstats.xs_qm_dquot_dups);
  631. mutex_unlock(&h->qh_lock);
  632. delay(1);
  633. goto restart;
  634. case 0:
  635. XQM_STATS_INC(xqmstats.xs_qm_dqcachehits);
  636. /*
  637. * The dquot was found, moved to the front of the chain,
  638. * taken off the freelist if it was on it, and locked
  639. * at this point. Just unlock the hashchain and return.
  640. */
  641. ASSERT(*O_dqpp);
  642. ASSERT(XFS_DQ_IS_LOCKED(*O_dqpp));
  643. mutex_unlock(&h->qh_lock);
  644. trace_xfs_dqget_hit(*O_dqpp);
  645. return 0; /* success */
  646. default:
  647. XQM_STATS_INC(xqmstats.xs_qm_dqcachemisses);
  648. break;
  649. }
  650. /*
  651. * Dquot cache miss. We don't want to keep the inode lock across
  652. * a (potential) disk read. Also we don't want to deal with the lock
  653. * ordering between quotainode and this inode. OTOH, dropping the inode
  654. * lock here means dealing with a chown that can happen before
  655. * we re-acquire the lock.
  656. */
  657. if (ip)
  658. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  659. /*
  660. * Save the hashchain version stamp, and unlock the chain, so that
  661. * we don't keep the lock across a disk read
  662. */
  663. version = h->qh_version;
  664. mutex_unlock(&h->qh_lock);
  665. error = xfs_qm_dqread(mp, id, type, flags, &dqp);
  666. if (ip)
  667. xfs_ilock(ip, XFS_ILOCK_EXCL);
  668. if (error)
  669. return error;
  670. /*
  671. * Dquot lock comes after hashlock in the lock ordering
  672. */
  673. if (ip) {
  674. /*
  675. * A dquot could be attached to this inode by now, since
  676. * we had dropped the ilock.
  677. */
  678. if (xfs_this_quota_on(mp, type)) {
  679. dqp1 = xfs_inode_dquot(ip, type);
  680. if (dqp1) {
  681. xfs_qm_dqdestroy(dqp);
  682. dqp = dqp1;
  683. xfs_dqlock(dqp);
  684. goto dqret;
  685. }
  686. } else {
  687. /* inode stays locked on return */
  688. xfs_qm_dqdestroy(dqp);
  689. return XFS_ERROR(ESRCH);
  690. }
  691. }
  692. /*
  693. * Hashlock comes after ilock in lock order
  694. */
  695. mutex_lock(&h->qh_lock);
  696. if (version != h->qh_version) {
  697. xfs_dquot_t *tmpdqp;
  698. /*
  699. * Now, see if somebody else put the dquot in the
  700. * hashtable before us. This can happen because we didn't
  701. * keep the hashchain lock. We don't have to worry about
  702. * lock order between the two dquots here since dqp isn't
  703. * on any findable lists yet.
  704. */
  705. switch (xfs_qm_dqlookup(mp, id, h, &tmpdqp)) {
  706. case 0:
  707. case -1:
  708. /*
  709. * Duplicate found, either in cache or on its way out.
  710. * Just throw away the new dquot and start over.
  711. */
  712. if (tmpdqp)
  713. xfs_qm_dqput(tmpdqp);
  714. mutex_unlock(&h->qh_lock);
  715. xfs_qm_dqdestroy(dqp);
  716. XQM_STATS_INC(xqmstats.xs_qm_dquot_dups);
  717. goto restart;
  718. default:
  719. break;
  720. }
  721. }
  722. /*
  723. * Put the dquot at the beginning of the hash-chain and mp's list
  724. * LOCK ORDER: hashlock, freelistlock, mplistlock, udqlock, gdqlock ..
  725. */
  726. ASSERT(mutex_is_locked(&h->qh_lock));
  727. dqp->q_hash = h;
  728. list_add(&dqp->q_hashlist, &h->qh_list);
  729. h->qh_version++;
  730. /*
  731. * Attach this dquot to this filesystem's list of all dquots,
  732. * kept inside the mount structure in m_quotainfo field
  733. */
  734. mutex_lock(&mp->m_quotainfo->qi_dqlist_lock);
  735. /*
  736. * We return a locked dquot to the caller, with a reference taken
  737. */
  738. xfs_dqlock(dqp);
  739. dqp->q_nrefs = 1;
  740. list_add(&dqp->q_mplist, &mp->m_quotainfo->qi_dqlist);
  741. mp->m_quotainfo->qi_dquots++;
  742. mutex_unlock(&mp->m_quotainfo->qi_dqlist_lock);
  743. mutex_unlock(&h->qh_lock);
  744. dqret:
  745. ASSERT((ip == NULL) || xfs_isilocked(ip, XFS_ILOCK_EXCL));
  746. trace_xfs_dqget_miss(dqp);
  747. *O_dqpp = dqp;
  748. return (0);
  749. }
  750. /*
  751. * Release a reference to the dquot (decrement ref-count)
  752. * and unlock it. If there is a group quota attached to this
  753. * dquot, carefully release that too without tripping over
  754. * deadlocks'n'stuff.
  755. */
  756. void
  757. xfs_qm_dqput(
  758. struct xfs_dquot *dqp)
  759. {
  760. struct xfs_dquot *gdqp;
  761. ASSERT(dqp->q_nrefs > 0);
  762. ASSERT(XFS_DQ_IS_LOCKED(dqp));
  763. trace_xfs_dqput(dqp);
  764. recurse:
  765. if (--dqp->q_nrefs > 0) {
  766. xfs_dqunlock(dqp);
  767. return;
  768. }
  769. trace_xfs_dqput_free(dqp);
  770. mutex_lock(&xfs_Gqm->qm_dqfrlist_lock);
  771. if (list_empty(&dqp->q_freelist)) {
  772. list_add_tail(&dqp->q_freelist, &xfs_Gqm->qm_dqfrlist);
  773. xfs_Gqm->qm_dqfrlist_cnt++;
  774. }
  775. mutex_unlock(&xfs_Gqm->qm_dqfrlist_lock);
  776. /*
  777. * If we just added a udquot to the freelist, then we want to release
  778. * the gdquot reference that it (probably) has. Otherwise it'll keep
  779. * the gdquot from getting reclaimed.
  780. */
  781. gdqp = dqp->q_gdquot;
  782. if (gdqp) {
  783. xfs_dqlock(gdqp);
  784. dqp->q_gdquot = NULL;
  785. }
  786. xfs_dqunlock(dqp);
  787. /*
  788. * If we had a group quota hint, release it now.
  789. */
  790. if (gdqp) {
  791. dqp = gdqp;
  792. goto recurse;
  793. }
  794. }
  795. /*
  796. * Release a dquot. Flush it if dirty, then dqput() it.
  797. * dquot must not be locked.
  798. */
  799. void
  800. xfs_qm_dqrele(
  801. xfs_dquot_t *dqp)
  802. {
  803. if (!dqp)
  804. return;
  805. trace_xfs_dqrele(dqp);
  806. xfs_dqlock(dqp);
  807. /*
  808. * We don't care to flush it if the dquot is dirty here.
  809. * That will create stutters that we want to avoid.
  810. * Instead we do a delayed write when we try to reclaim
  811. * a dirty dquot. Also xfs_sync will take part of the burden...
  812. */
  813. xfs_qm_dqput(dqp);
  814. }
  815. /*
  816. * This is the dquot flushing I/O completion routine. It is called
  817. * from interrupt level when the buffer containing the dquot is
  818. * flushed to disk. It is responsible for removing the dquot logitem
  819. * from the AIL if it has not been re-logged, and unlocking the dquot's
  820. * flush lock. This behavior is very similar to that of inodes..
  821. */
  822. STATIC void
  823. xfs_qm_dqflush_done(
  824. struct xfs_buf *bp,
  825. struct xfs_log_item *lip)
  826. {
  827. xfs_dq_logitem_t *qip = (struct xfs_dq_logitem *)lip;
  828. xfs_dquot_t *dqp = qip->qli_dquot;
  829. struct xfs_ail *ailp = lip->li_ailp;
  830. /*
  831. * We only want to pull the item from the AIL if its
  832. * location in the log has not changed since we started the flush.
  833. * Thus, we only bother if the dquot's lsn has
  834. * not changed. First we check the lsn outside the lock
  835. * since it's cheaper, and then we recheck while
  836. * holding the lock before removing the dquot from the AIL.
  837. */
  838. if ((lip->li_flags & XFS_LI_IN_AIL) &&
  839. lip->li_lsn == qip->qli_flush_lsn) {
  840. /* xfs_trans_ail_delete() drops the AIL lock. */
  841. spin_lock(&ailp->xa_lock);
  842. if (lip->li_lsn == qip->qli_flush_lsn)
  843. xfs_trans_ail_delete(ailp, lip);
  844. else
  845. spin_unlock(&ailp->xa_lock);
  846. }
  847. /*
  848. * Release the dq's flush lock since we're done with it.
  849. */
  850. xfs_dqfunlock(dqp);
  851. }
  852. /*
  853. * Write a modified dquot to disk.
  854. * The dquot must be locked and the flush lock too taken by caller.
  855. * The flush lock will not be unlocked until the dquot reaches the disk,
  856. * but the dquot is free to be unlocked and modified by the caller
  857. * in the interim. Dquot is still locked on return. This behavior is
  858. * identical to that of inodes.
  859. */
  860. int
  861. xfs_qm_dqflush(
  862. xfs_dquot_t *dqp,
  863. uint flags)
  864. {
  865. struct xfs_mount *mp = dqp->q_mount;
  866. struct xfs_buf *bp;
  867. struct xfs_disk_dquot *ddqp;
  868. int error;
  869. ASSERT(XFS_DQ_IS_LOCKED(dqp));
  870. ASSERT(!completion_done(&dqp->q_flush));
  871. trace_xfs_dqflush(dqp);
  872. /*
  873. * If not dirty, or it's pinned and we are not supposed to block, nada.
  874. */
  875. if (!XFS_DQ_IS_DIRTY(dqp) ||
  876. ((flags & SYNC_TRYLOCK) && atomic_read(&dqp->q_pincount) > 0)) {
  877. xfs_dqfunlock(dqp);
  878. return 0;
  879. }
  880. xfs_qm_dqunpin_wait(dqp);
  881. /*
  882. * This may have been unpinned because the filesystem is shutting
  883. * down forcibly. If that's the case we must not write this dquot
  884. * to disk, because the log record didn't make it to disk!
  885. */
  886. if (XFS_FORCED_SHUTDOWN(mp)) {
  887. dqp->dq_flags &= ~XFS_DQ_DIRTY;
  888. xfs_dqfunlock(dqp);
  889. return XFS_ERROR(EIO);
  890. }
  891. /*
  892. * Get the buffer containing the on-disk dquot
  893. */
  894. error = xfs_trans_read_buf(mp, NULL, mp->m_ddev_targp, dqp->q_blkno,
  895. mp->m_quotainfo->qi_dqchunklen, 0, &bp);
  896. if (error) {
  897. ASSERT(error != ENOENT);
  898. xfs_dqfunlock(dqp);
  899. return error;
  900. }
  901. /*
  902. * Calculate the location of the dquot inside the buffer.
  903. */
  904. ddqp = bp->b_addr + dqp->q_bufoffset;
  905. /*
  906. * A simple sanity check in case we got a corrupted dquot..
  907. */
  908. error = xfs_qm_dqcheck(mp, &dqp->q_core, be32_to_cpu(ddqp->d_id), 0,
  909. XFS_QMOPT_DOWARN, "dqflush (incore copy)");
  910. if (error) {
  911. xfs_buf_relse(bp);
  912. xfs_dqfunlock(dqp);
  913. xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
  914. return XFS_ERROR(EIO);
  915. }
  916. /* This is the only portion of data that needs to persist */
  917. memcpy(ddqp, &dqp->q_core, sizeof(xfs_disk_dquot_t));
  918. /*
  919. * Clear the dirty field and remember the flush lsn for later use.
  920. */
  921. dqp->dq_flags &= ~XFS_DQ_DIRTY;
  922. xfs_trans_ail_copy_lsn(mp->m_ail, &dqp->q_logitem.qli_flush_lsn,
  923. &dqp->q_logitem.qli_item.li_lsn);
  924. /*
  925. * Attach an iodone routine so that we can remove this dquot from the
  926. * AIL and release the flush lock once the dquot is synced to disk.
  927. */
  928. xfs_buf_attach_iodone(bp, xfs_qm_dqflush_done,
  929. &dqp->q_logitem.qli_item);
  930. /*
  931. * If the buffer is pinned then push on the log so we won't
  932. * get stuck waiting in the write for too long.
  933. */
  934. if (xfs_buf_ispinned(bp)) {
  935. trace_xfs_dqflush_force(dqp);
  936. xfs_log_force(mp, 0);
  937. }
  938. if (flags & SYNC_WAIT)
  939. error = xfs_bwrite(bp);
  940. else
  941. xfs_buf_delwri_queue(bp);
  942. xfs_buf_relse(bp);
  943. trace_xfs_dqflush_done(dqp);
  944. /*
  945. * dqp is still locked, but caller is free to unlock it now.
  946. */
  947. return error;
  948. }
  949. void
  950. xfs_dqunlock(
  951. xfs_dquot_t *dqp)
  952. {
  953. xfs_dqunlock_nonotify(dqp);
  954. if (dqp->q_logitem.qli_dquot == dqp) {
  955. xfs_trans_unlocked_item(dqp->q_logitem.qli_item.li_ailp,
  956. &dqp->q_logitem.qli_item);
  957. }
  958. }
  959. /*
  960. * Lock two xfs_dquot structures.
  961. *
  962. * To avoid deadlocks we always lock the quota structure with
  963. * the lowerd id first.
  964. */
  965. void
  966. xfs_dqlock2(
  967. xfs_dquot_t *d1,
  968. xfs_dquot_t *d2)
  969. {
  970. if (d1 && d2) {
  971. ASSERT(d1 != d2);
  972. if (be32_to_cpu(d1->q_core.d_id) >
  973. be32_to_cpu(d2->q_core.d_id)) {
  974. mutex_lock(&d2->q_qlock);
  975. mutex_lock_nested(&d1->q_qlock, XFS_QLOCK_NESTED);
  976. } else {
  977. mutex_lock(&d1->q_qlock);
  978. mutex_lock_nested(&d2->q_qlock, XFS_QLOCK_NESTED);
  979. }
  980. } else if (d1) {
  981. mutex_lock(&d1->q_qlock);
  982. } else if (d2) {
  983. mutex_lock(&d2->q_qlock);
  984. }
  985. }
  986. /*
  987. * Take a dquot out of the mount's dqlist as well as the hashlist. This is
  988. * called via unmount as well as quotaoff, and the purge will always succeed.
  989. */
  990. void
  991. xfs_qm_dqpurge(
  992. struct xfs_dquot *dqp)
  993. {
  994. struct xfs_mount *mp = dqp->q_mount;
  995. struct xfs_dqhash *qh = dqp->q_hash;
  996. xfs_dqlock(dqp);
  997. /*
  998. * If we're turning off quotas, we have to make sure that, for
  999. * example, we don't delete quota disk blocks while dquots are
  1000. * in the process of getting written to those disk blocks.
  1001. * This dquot might well be on AIL, and we can't leave it there
  1002. * if we're turning off quotas. Basically, we need this flush
  1003. * lock, and are willing to block on it.
  1004. */
  1005. if (!xfs_dqflock_nowait(dqp)) {
  1006. /*
  1007. * Block on the flush lock after nudging dquot buffer,
  1008. * if it is incore.
  1009. */
  1010. xfs_dqflock_pushbuf_wait(dqp);
  1011. }
  1012. /*
  1013. * If we are turning this type of quotas off, we don't care
  1014. * about the dirty metadata sitting in this dquot. OTOH, if
  1015. * we're unmounting, we do care, so we flush it and wait.
  1016. */
  1017. if (XFS_DQ_IS_DIRTY(dqp)) {
  1018. int error;
  1019. /*
  1020. * We don't care about getting disk errors here. We need
  1021. * to purge this dquot anyway, so we go ahead regardless.
  1022. */
  1023. error = xfs_qm_dqflush(dqp, SYNC_WAIT);
  1024. if (error)
  1025. xfs_warn(mp, "%s: dquot %p flush failed",
  1026. __func__, dqp);
  1027. xfs_dqflock(dqp);
  1028. }
  1029. ASSERT(atomic_read(&dqp->q_pincount) == 0);
  1030. ASSERT(XFS_FORCED_SHUTDOWN(mp) ||
  1031. !(dqp->q_logitem.qli_item.li_flags & XFS_LI_IN_AIL));
  1032. xfs_dqfunlock(dqp);
  1033. xfs_dqunlock(dqp);
  1034. mutex_lock(&qh->qh_lock);
  1035. list_del_init(&dqp->q_hashlist);
  1036. qh->qh_version++;
  1037. mutex_unlock(&qh->qh_lock);
  1038. mutex_lock(&mp->m_quotainfo->qi_dqlist_lock);
  1039. list_del_init(&dqp->q_mplist);
  1040. mp->m_quotainfo->qi_dqreclaims++;
  1041. mp->m_quotainfo->qi_dquots--;
  1042. mutex_unlock(&mp->m_quotainfo->qi_dqlist_lock);
  1043. /*
  1044. * We move dquots to the freelist as soon as their reference count
  1045. * hits zero, so it really should be on the freelist here.
  1046. */
  1047. mutex_lock(&xfs_Gqm->qm_dqfrlist_lock);
  1048. ASSERT(!list_empty(&dqp->q_freelist));
  1049. list_del_init(&dqp->q_freelist);
  1050. xfs_Gqm->qm_dqfrlist_cnt--;
  1051. mutex_unlock(&xfs_Gqm->qm_dqfrlist_lock);
  1052. xfs_qm_dqdestroy(dqp);
  1053. }
  1054. /*
  1055. * Give the buffer a little push if it is incore and
  1056. * wait on the flush lock.
  1057. */
  1058. void
  1059. xfs_dqflock_pushbuf_wait(
  1060. xfs_dquot_t *dqp)
  1061. {
  1062. xfs_mount_t *mp = dqp->q_mount;
  1063. xfs_buf_t *bp;
  1064. /*
  1065. * Check to see if the dquot has been flushed delayed
  1066. * write. If so, grab its buffer and send it
  1067. * out immediately. We'll be able to acquire
  1068. * the flush lock when the I/O completes.
  1069. */
  1070. bp = xfs_incore(mp->m_ddev_targp, dqp->q_blkno,
  1071. mp->m_quotainfo->qi_dqchunklen, XBF_TRYLOCK);
  1072. if (!bp)
  1073. goto out_lock;
  1074. if (XFS_BUF_ISDELAYWRITE(bp)) {
  1075. if (xfs_buf_ispinned(bp))
  1076. xfs_log_force(mp, 0);
  1077. xfs_buf_delwri_promote(bp);
  1078. wake_up_process(bp->b_target->bt_task);
  1079. }
  1080. xfs_buf_relse(bp);
  1081. out_lock:
  1082. xfs_dqflock(dqp);
  1083. }