xfs_dquot_item.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /*
  2. * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * Further, this software is distributed without any warranty that it is
  13. * free of the rightful claim of any third person regarding infringement
  14. * or the like. Any license provided herein, whether implied or
  15. * otherwise, applies only to this software file. Patent licenses, if
  16. * any, provided herein do not apply to combinations of this program with
  17. * other software, or any other product whatsoever.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22. *
  23. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. * Mountain View, CA 94043, or:
  25. *
  26. * http://www.sgi.com
  27. *
  28. * For further information regarding this notice, see:
  29. *
  30. * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  31. */
  32. #include "xfs.h"
  33. #include "xfs_fs.h"
  34. #include "xfs_inum.h"
  35. #include "xfs_log.h"
  36. #include "xfs_trans.h"
  37. #include "xfs_sb.h"
  38. #include "xfs_ag.h"
  39. #include "xfs_dir.h"
  40. #include "xfs_dir2.h"
  41. #include "xfs_alloc.h"
  42. #include "xfs_dmapi.h"
  43. #include "xfs_quota.h"
  44. #include "xfs_mount.h"
  45. #include "xfs_alloc_btree.h"
  46. #include "xfs_bmap_btree.h"
  47. #include "xfs_ialloc_btree.h"
  48. #include "xfs_btree.h"
  49. #include "xfs_ialloc.h"
  50. #include "xfs_attr_sf.h"
  51. #include "xfs_dir_sf.h"
  52. #include "xfs_dir2_sf.h"
  53. #include "xfs_dinode.h"
  54. #include "xfs_inode.h"
  55. #include "xfs_bmap.h"
  56. #include "xfs_bit.h"
  57. #include "xfs_rtalloc.h"
  58. #include "xfs_error.h"
  59. #include "xfs_itable.h"
  60. #include "xfs_rw.h"
  61. #include "xfs_acl.h"
  62. #include "xfs_cap.h"
  63. #include "xfs_mac.h"
  64. #include "xfs_attr.h"
  65. #include "xfs_buf_item.h"
  66. #include "xfs_trans_priv.h"
  67. #include "xfs_qm.h"
  68. /*
  69. * returns the number of iovecs needed to log the given dquot item.
  70. */
  71. /* ARGSUSED */
  72. STATIC uint
  73. xfs_qm_dquot_logitem_size(
  74. xfs_dq_logitem_t *logitem)
  75. {
  76. /*
  77. * we need only two iovecs, one for the format, one for the real thing
  78. */
  79. return (2);
  80. }
  81. /*
  82. * fills in the vector of log iovecs for the given dquot log item.
  83. */
  84. STATIC void
  85. xfs_qm_dquot_logitem_format(
  86. xfs_dq_logitem_t *logitem,
  87. xfs_log_iovec_t *logvec)
  88. {
  89. ASSERT(logitem);
  90. ASSERT(logitem->qli_dquot);
  91. logvec->i_addr = (xfs_caddr_t)&logitem->qli_format;
  92. logvec->i_len = sizeof(xfs_dq_logformat_t);
  93. logvec++;
  94. logvec->i_addr = (xfs_caddr_t)&logitem->qli_dquot->q_core;
  95. logvec->i_len = sizeof(xfs_disk_dquot_t);
  96. ASSERT(2 == logitem->qli_item.li_desc->lid_size);
  97. logitem->qli_format.qlf_size = 2;
  98. }
  99. /*
  100. * Increment the pin count of the given dquot.
  101. * This value is protected by pinlock spinlock in the xQM structure.
  102. */
  103. STATIC void
  104. xfs_qm_dquot_logitem_pin(
  105. xfs_dq_logitem_t *logitem)
  106. {
  107. unsigned long s;
  108. xfs_dquot_t *dqp;
  109. dqp = logitem->qli_dquot;
  110. ASSERT(XFS_DQ_IS_LOCKED(dqp));
  111. s = XFS_DQ_PINLOCK(dqp);
  112. dqp->q_pincount++;
  113. XFS_DQ_PINUNLOCK(dqp, s);
  114. }
  115. /*
  116. * Decrement the pin count of the given dquot, and wake up
  117. * anyone in xfs_dqwait_unpin() if the count goes to 0. The
  118. * dquot must have been previously pinned with a call to xfs_dqpin().
  119. */
  120. /* ARGSUSED */
  121. STATIC void
  122. xfs_qm_dquot_logitem_unpin(
  123. xfs_dq_logitem_t *logitem,
  124. int stale)
  125. {
  126. unsigned long s;
  127. xfs_dquot_t *dqp;
  128. dqp = logitem->qli_dquot;
  129. ASSERT(dqp->q_pincount > 0);
  130. s = XFS_DQ_PINLOCK(dqp);
  131. dqp->q_pincount--;
  132. if (dqp->q_pincount == 0) {
  133. sv_broadcast(&dqp->q_pinwait);
  134. }
  135. XFS_DQ_PINUNLOCK(dqp, s);
  136. }
  137. /* ARGSUSED */
  138. STATIC void
  139. xfs_qm_dquot_logitem_unpin_remove(
  140. xfs_dq_logitem_t *logitem,
  141. xfs_trans_t *tp)
  142. {
  143. xfs_qm_dquot_logitem_unpin(logitem, 0);
  144. }
  145. /*
  146. * Given the logitem, this writes the corresponding dquot entry to disk
  147. * asynchronously. This is called with the dquot entry securely locked;
  148. * we simply get xfs_qm_dqflush() to do the work, and unlock the dquot
  149. * at the end.
  150. */
  151. STATIC void
  152. xfs_qm_dquot_logitem_push(
  153. xfs_dq_logitem_t *logitem)
  154. {
  155. xfs_dquot_t *dqp;
  156. dqp = logitem->qli_dquot;
  157. ASSERT(XFS_DQ_IS_LOCKED(dqp));
  158. ASSERT(XFS_DQ_IS_FLUSH_LOCKED(dqp));
  159. /*
  160. * Since we were able to lock the dquot's flush lock and
  161. * we found it on the AIL, the dquot must be dirty. This
  162. * is because the dquot is removed from the AIL while still
  163. * holding the flush lock in xfs_dqflush_done(). Thus, if
  164. * we found it in the AIL and were able to obtain the flush
  165. * lock without sleeping, then there must not have been
  166. * anyone in the process of flushing the dquot.
  167. */
  168. xfs_qm_dqflush(dqp, XFS_B_DELWRI);
  169. xfs_dqunlock(dqp);
  170. }
  171. /*ARGSUSED*/
  172. STATIC xfs_lsn_t
  173. xfs_qm_dquot_logitem_committed(
  174. xfs_dq_logitem_t *l,
  175. xfs_lsn_t lsn)
  176. {
  177. /*
  178. * We always re-log the entire dquot when it becomes dirty,
  179. * so, the latest copy _is_ the only one that matters.
  180. */
  181. return (lsn);
  182. }
  183. /*
  184. * This is called to wait for the given dquot to be unpinned.
  185. * Most of these pin/unpin routines are plagiarized from inode code.
  186. */
  187. void
  188. xfs_qm_dqunpin_wait(
  189. xfs_dquot_t *dqp)
  190. {
  191. SPLDECL(s);
  192. ASSERT(XFS_DQ_IS_LOCKED(dqp));
  193. if (dqp->q_pincount == 0) {
  194. return;
  195. }
  196. /*
  197. * Give the log a push so we don't wait here too long.
  198. */
  199. xfs_log_force(dqp->q_mount, (xfs_lsn_t)0, XFS_LOG_FORCE);
  200. s = XFS_DQ_PINLOCK(dqp);
  201. if (dqp->q_pincount == 0) {
  202. XFS_DQ_PINUNLOCK(dqp, s);
  203. return;
  204. }
  205. sv_wait(&(dqp->q_pinwait), PINOD,
  206. &(XFS_DQ_TO_QINF(dqp)->qi_pinlock), s);
  207. }
  208. /*
  209. * This is called when IOP_TRYLOCK returns XFS_ITEM_PUSHBUF to indicate that
  210. * the dquot is locked by us, but the flush lock isn't. So, here we are
  211. * going to see if the relevant dquot buffer is incore, waiting on DELWRI.
  212. * If so, we want to push it out to help us take this item off the AIL as soon
  213. * as possible.
  214. *
  215. * We must not be holding the AIL_LOCK at this point. Calling incore() to
  216. * search the buffercache can be a time consuming thing, and AIL_LOCK is a
  217. * spinlock.
  218. */
  219. STATIC void
  220. xfs_qm_dquot_logitem_pushbuf(
  221. xfs_dq_logitem_t *qip)
  222. {
  223. xfs_dquot_t *dqp;
  224. xfs_mount_t *mp;
  225. xfs_buf_t *bp;
  226. uint dopush;
  227. dqp = qip->qli_dquot;
  228. ASSERT(XFS_DQ_IS_LOCKED(dqp));
  229. /*
  230. * The qli_pushbuf_flag keeps others from
  231. * trying to duplicate our effort.
  232. */
  233. ASSERT(qip->qli_pushbuf_flag != 0);
  234. ASSERT(qip->qli_push_owner == get_thread_id());
  235. /*
  236. * If flushlock isn't locked anymore, chances are that the
  237. * inode flush completed and the inode was taken off the AIL.
  238. * So, just get out.
  239. */
  240. if ((valusema(&(dqp->q_flock)) > 0) ||
  241. ((qip->qli_item.li_flags & XFS_LI_IN_AIL) == 0)) {
  242. qip->qli_pushbuf_flag = 0;
  243. xfs_dqunlock(dqp);
  244. return;
  245. }
  246. mp = dqp->q_mount;
  247. bp = xfs_incore(mp->m_ddev_targp, qip->qli_format.qlf_blkno,
  248. XFS_QI_DQCHUNKLEN(mp),
  249. XFS_INCORE_TRYLOCK);
  250. if (bp != NULL) {
  251. if (XFS_BUF_ISDELAYWRITE(bp)) {
  252. dopush = ((qip->qli_item.li_flags & XFS_LI_IN_AIL) &&
  253. (valusema(&(dqp->q_flock)) <= 0));
  254. qip->qli_pushbuf_flag = 0;
  255. xfs_dqunlock(dqp);
  256. if (XFS_BUF_ISPINNED(bp)) {
  257. xfs_log_force(mp, (xfs_lsn_t)0,
  258. XFS_LOG_FORCE);
  259. }
  260. if (dopush) {
  261. #ifdef XFSRACEDEBUG
  262. delay_for_intr();
  263. delay(300);
  264. #endif
  265. xfs_bawrite(mp, bp);
  266. } else {
  267. xfs_buf_relse(bp);
  268. }
  269. } else {
  270. qip->qli_pushbuf_flag = 0;
  271. xfs_dqunlock(dqp);
  272. xfs_buf_relse(bp);
  273. }
  274. return;
  275. }
  276. qip->qli_pushbuf_flag = 0;
  277. xfs_dqunlock(dqp);
  278. }
  279. /*
  280. * This is called to attempt to lock the dquot associated with this
  281. * dquot log item. Don't sleep on the dquot lock or the flush lock.
  282. * If the flush lock is already held, indicating that the dquot has
  283. * been or is in the process of being flushed, then see if we can
  284. * find the dquot's buffer in the buffer cache without sleeping. If
  285. * we can and it is marked delayed write, then we want to send it out.
  286. * We delay doing so until the push routine, though, to avoid sleeping
  287. * in any device strategy routines.
  288. */
  289. STATIC uint
  290. xfs_qm_dquot_logitem_trylock(
  291. xfs_dq_logitem_t *qip)
  292. {
  293. xfs_dquot_t *dqp;
  294. uint retval;
  295. dqp = qip->qli_dquot;
  296. if (dqp->q_pincount > 0)
  297. return (XFS_ITEM_PINNED);
  298. if (! xfs_qm_dqlock_nowait(dqp))
  299. return (XFS_ITEM_LOCKED);
  300. retval = XFS_ITEM_SUCCESS;
  301. if (! xfs_qm_dqflock_nowait(dqp)) {
  302. /*
  303. * The dquot is already being flushed. It may have been
  304. * flushed delayed write, however, and we don't want to
  305. * get stuck waiting for that to complete. So, we want to check
  306. * to see if we can lock the dquot's buffer without sleeping.
  307. * If we can and it is marked for delayed write, then we
  308. * hold it and send it out from the push routine. We don't
  309. * want to do that now since we might sleep in the device
  310. * strategy routine. We also don't want to grab the buffer lock
  311. * here because we'd like not to call into the buffer cache
  312. * while holding the AIL_LOCK.
  313. * Make sure to only return PUSHBUF if we set pushbuf_flag
  314. * ourselves. If someone else is doing it then we don't
  315. * want to go to the push routine and duplicate their efforts.
  316. */
  317. if (qip->qli_pushbuf_flag == 0) {
  318. qip->qli_pushbuf_flag = 1;
  319. ASSERT(qip->qli_format.qlf_blkno == dqp->q_blkno);
  320. #ifdef DEBUG
  321. qip->qli_push_owner = get_thread_id();
  322. #endif
  323. /*
  324. * The dquot is left locked.
  325. */
  326. retval = XFS_ITEM_PUSHBUF;
  327. } else {
  328. retval = XFS_ITEM_FLUSHING;
  329. xfs_dqunlock_nonotify(dqp);
  330. }
  331. }
  332. ASSERT(qip->qli_item.li_flags & XFS_LI_IN_AIL);
  333. return (retval);
  334. }
  335. /*
  336. * Unlock the dquot associated with the log item.
  337. * Clear the fields of the dquot and dquot log item that
  338. * are specific to the current transaction. If the
  339. * hold flags is set, do not unlock the dquot.
  340. */
  341. STATIC void
  342. xfs_qm_dquot_logitem_unlock(
  343. xfs_dq_logitem_t *ql)
  344. {
  345. xfs_dquot_t *dqp;
  346. ASSERT(ql != NULL);
  347. dqp = ql->qli_dquot;
  348. ASSERT(XFS_DQ_IS_LOCKED(dqp));
  349. /*
  350. * Clear the transaction pointer in the dquot
  351. */
  352. dqp->q_transp = NULL;
  353. /*
  354. * dquots are never 'held' from getting unlocked at the end of
  355. * a transaction. Their locking and unlocking is hidden inside the
  356. * transaction layer, within trans_commit. Hence, no LI_HOLD flag
  357. * for the logitem.
  358. */
  359. xfs_dqunlock(dqp);
  360. }
  361. /*
  362. * The transaction with the dquot locked has aborted. The dquot
  363. * must not be dirty within the transaction. We simply unlock just
  364. * as if the transaction had been cancelled.
  365. */
  366. STATIC void
  367. xfs_qm_dquot_logitem_abort(
  368. xfs_dq_logitem_t *ql)
  369. {
  370. xfs_qm_dquot_logitem_unlock(ql);
  371. }
  372. /*
  373. * this needs to stamp an lsn into the dquot, I think.
  374. * rpc's that look at user dquot's would then have to
  375. * push on the dependency recorded in the dquot
  376. */
  377. /* ARGSUSED */
  378. STATIC void
  379. xfs_qm_dquot_logitem_committing(
  380. xfs_dq_logitem_t *l,
  381. xfs_lsn_t lsn)
  382. {
  383. return;
  384. }
  385. /*
  386. * This is the ops vector for dquots
  387. */
  388. STATIC struct xfs_item_ops xfs_dquot_item_ops = {
  389. .iop_size = (uint(*)(xfs_log_item_t*))xfs_qm_dquot_logitem_size,
  390. .iop_format = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
  391. xfs_qm_dquot_logitem_format,
  392. .iop_pin = (void(*)(xfs_log_item_t*))xfs_qm_dquot_logitem_pin,
  393. .iop_unpin = (void(*)(xfs_log_item_t*, int))
  394. xfs_qm_dquot_logitem_unpin,
  395. .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t*))
  396. xfs_qm_dquot_logitem_unpin_remove,
  397. .iop_trylock = (uint(*)(xfs_log_item_t*))
  398. xfs_qm_dquot_logitem_trylock,
  399. .iop_unlock = (void(*)(xfs_log_item_t*))xfs_qm_dquot_logitem_unlock,
  400. .iop_committed = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
  401. xfs_qm_dquot_logitem_committed,
  402. .iop_push = (void(*)(xfs_log_item_t*))xfs_qm_dquot_logitem_push,
  403. .iop_abort = (void(*)(xfs_log_item_t*))xfs_qm_dquot_logitem_abort,
  404. .iop_pushbuf = (void(*)(xfs_log_item_t*))
  405. xfs_qm_dquot_logitem_pushbuf,
  406. .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
  407. xfs_qm_dquot_logitem_committing
  408. };
  409. /*
  410. * Initialize the dquot log item for a newly allocated dquot.
  411. * The dquot isn't locked at this point, but it isn't on any of the lists
  412. * either, so we don't care.
  413. */
  414. void
  415. xfs_qm_dquot_logitem_init(
  416. struct xfs_dquot *dqp)
  417. {
  418. xfs_dq_logitem_t *lp;
  419. lp = &dqp->q_logitem;
  420. lp->qli_item.li_type = XFS_LI_DQUOT;
  421. lp->qli_item.li_ops = &xfs_dquot_item_ops;
  422. lp->qli_item.li_mountp = dqp->q_mount;
  423. lp->qli_dquot = dqp;
  424. lp->qli_format.qlf_type = XFS_LI_DQUOT;
  425. lp->qli_format.qlf_id = INT_GET(dqp->q_core.d_id, ARCH_CONVERT);
  426. lp->qli_format.qlf_blkno = dqp->q_blkno;
  427. lp->qli_format.qlf_len = 1;
  428. /*
  429. * This is just the offset of this dquot within its buffer
  430. * (which is currently 1 FSB and probably won't change).
  431. * Hence 32 bits for this offset should be just fine.
  432. * Alternatively, we can store (bufoffset / sizeof(xfs_dqblk_t))
  433. * here, and recompute it at recovery time.
  434. */
  435. lp->qli_format.qlf_boffset = (__uint32_t)dqp->q_bufoffset;
  436. }
  437. /*------------------ QUOTAOFF LOG ITEMS -------------------*/
  438. /*
  439. * This returns the number of iovecs needed to log the given quotaoff item.
  440. * We only need 1 iovec for an quotaoff item. It just logs the
  441. * quotaoff_log_format structure.
  442. */
  443. /*ARGSUSED*/
  444. STATIC uint
  445. xfs_qm_qoff_logitem_size(xfs_qoff_logitem_t *qf)
  446. {
  447. return (1);
  448. }
  449. /*
  450. * This is called to fill in the vector of log iovecs for the
  451. * given quotaoff log item. We use only 1 iovec, and we point that
  452. * at the quotaoff_log_format structure embedded in the quotaoff item.
  453. * It is at this point that we assert that all of the extent
  454. * slots in the quotaoff item have been filled.
  455. */
  456. STATIC void
  457. xfs_qm_qoff_logitem_format(xfs_qoff_logitem_t *qf,
  458. xfs_log_iovec_t *log_vector)
  459. {
  460. ASSERT(qf->qql_format.qf_type == XFS_LI_QUOTAOFF);
  461. log_vector->i_addr = (xfs_caddr_t)&(qf->qql_format);
  462. log_vector->i_len = sizeof(xfs_qoff_logitem_t);
  463. XLOG_VEC_SET_TYPE(log_vector, XLOG_REG_TYPE_QUOTAOFF);
  464. qf->qql_format.qf_size = 1;
  465. }
  466. /*
  467. * Pinning has no meaning for an quotaoff item, so just return.
  468. */
  469. /*ARGSUSED*/
  470. STATIC void
  471. xfs_qm_qoff_logitem_pin(xfs_qoff_logitem_t *qf)
  472. {
  473. return;
  474. }
  475. /*
  476. * Since pinning has no meaning for an quotaoff item, unpinning does
  477. * not either.
  478. */
  479. /*ARGSUSED*/
  480. STATIC void
  481. xfs_qm_qoff_logitem_unpin(xfs_qoff_logitem_t *qf, int stale)
  482. {
  483. return;
  484. }
  485. /*ARGSUSED*/
  486. STATIC void
  487. xfs_qm_qoff_logitem_unpin_remove(xfs_qoff_logitem_t *qf, xfs_trans_t *tp)
  488. {
  489. return;
  490. }
  491. /*
  492. * Quotaoff items have no locking, so just return success.
  493. */
  494. /*ARGSUSED*/
  495. STATIC uint
  496. xfs_qm_qoff_logitem_trylock(xfs_qoff_logitem_t *qf)
  497. {
  498. return XFS_ITEM_LOCKED;
  499. }
  500. /*
  501. * Quotaoff items have no locking or pushing, so return failure
  502. * so that the caller doesn't bother with us.
  503. */
  504. /*ARGSUSED*/
  505. STATIC void
  506. xfs_qm_qoff_logitem_unlock(xfs_qoff_logitem_t *qf)
  507. {
  508. return;
  509. }
  510. /*
  511. * The quotaoff-start-item is logged only once and cannot be moved in the log,
  512. * so simply return the lsn at which it's been logged.
  513. */
  514. /*ARGSUSED*/
  515. STATIC xfs_lsn_t
  516. xfs_qm_qoff_logitem_committed(xfs_qoff_logitem_t *qf, xfs_lsn_t lsn)
  517. {
  518. return (lsn);
  519. }
  520. /*
  521. * The transaction of which this QUOTAOFF is a part has been aborted.
  522. * Just clean up after ourselves.
  523. * Shouldn't this never happen in the case of qoffend logitems? XXX
  524. */
  525. STATIC void
  526. xfs_qm_qoff_logitem_abort(xfs_qoff_logitem_t *qf)
  527. {
  528. kmem_free(qf, sizeof(xfs_qoff_logitem_t));
  529. }
  530. /*
  531. * There isn't much you can do to push on an quotaoff item. It is simply
  532. * stuck waiting for the log to be flushed to disk.
  533. */
  534. /*ARGSUSED*/
  535. STATIC void
  536. xfs_qm_qoff_logitem_push(xfs_qoff_logitem_t *qf)
  537. {
  538. return;
  539. }
  540. /*ARGSUSED*/
  541. STATIC xfs_lsn_t
  542. xfs_qm_qoffend_logitem_committed(
  543. xfs_qoff_logitem_t *qfe,
  544. xfs_lsn_t lsn)
  545. {
  546. xfs_qoff_logitem_t *qfs;
  547. SPLDECL(s);
  548. qfs = qfe->qql_start_lip;
  549. AIL_LOCK(qfs->qql_item.li_mountp,s);
  550. /*
  551. * Delete the qoff-start logitem from the AIL.
  552. * xfs_trans_delete_ail() drops the AIL lock.
  553. */
  554. xfs_trans_delete_ail(qfs->qql_item.li_mountp, (xfs_log_item_t *)qfs, s);
  555. kmem_free(qfs, sizeof(xfs_qoff_logitem_t));
  556. kmem_free(qfe, sizeof(xfs_qoff_logitem_t));
  557. return (xfs_lsn_t)-1;
  558. }
  559. /*
  560. * XXX rcc - don't know quite what to do with this. I think we can
  561. * just ignore it. The only time that isn't the case is if we allow
  562. * the client to somehow see that quotas have been turned off in which
  563. * we can't allow that to get back until the quotaoff hits the disk.
  564. * So how would that happen? Also, do we need different routines for
  565. * quotaoff start and quotaoff end? I suspect the answer is yes but
  566. * to be sure, I need to look at the recovery code and see how quota off
  567. * recovery is handled (do we roll forward or back or do something else).
  568. * If we roll forwards or backwards, then we need two separate routines,
  569. * one that does nothing and one that stamps in the lsn that matters
  570. * (truly makes the quotaoff irrevocable). If we do something else,
  571. * then maybe we don't need two.
  572. */
  573. /* ARGSUSED */
  574. STATIC void
  575. xfs_qm_qoff_logitem_committing(xfs_qoff_logitem_t *qip, xfs_lsn_t commit_lsn)
  576. {
  577. return;
  578. }
  579. /* ARGSUSED */
  580. STATIC void
  581. xfs_qm_qoffend_logitem_committing(xfs_qoff_logitem_t *qip, xfs_lsn_t commit_lsn)
  582. {
  583. return;
  584. }
  585. STATIC struct xfs_item_ops xfs_qm_qoffend_logitem_ops = {
  586. .iop_size = (uint(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_size,
  587. .iop_format = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
  588. xfs_qm_qoff_logitem_format,
  589. .iop_pin = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_pin,
  590. .iop_unpin = (void(*)(xfs_log_item_t* ,int))
  591. xfs_qm_qoff_logitem_unpin,
  592. .iop_unpin_remove = (void(*)(xfs_log_item_t*,xfs_trans_t*))
  593. xfs_qm_qoff_logitem_unpin_remove,
  594. .iop_trylock = (uint(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_trylock,
  595. .iop_unlock = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_unlock,
  596. .iop_committed = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
  597. xfs_qm_qoffend_logitem_committed,
  598. .iop_push = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_push,
  599. .iop_abort = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_abort,
  600. .iop_pushbuf = NULL,
  601. .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
  602. xfs_qm_qoffend_logitem_committing
  603. };
  604. /*
  605. * This is the ops vector shared by all quotaoff-start log items.
  606. */
  607. STATIC struct xfs_item_ops xfs_qm_qoff_logitem_ops = {
  608. .iop_size = (uint(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_size,
  609. .iop_format = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
  610. xfs_qm_qoff_logitem_format,
  611. .iop_pin = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_pin,
  612. .iop_unpin = (void(*)(xfs_log_item_t*, int))
  613. xfs_qm_qoff_logitem_unpin,
  614. .iop_unpin_remove = (void(*)(xfs_log_item_t*,xfs_trans_t*))
  615. xfs_qm_qoff_logitem_unpin_remove,
  616. .iop_trylock = (uint(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_trylock,
  617. .iop_unlock = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_unlock,
  618. .iop_committed = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
  619. xfs_qm_qoff_logitem_committed,
  620. .iop_push = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_push,
  621. .iop_abort = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_abort,
  622. .iop_pushbuf = NULL,
  623. .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
  624. xfs_qm_qoff_logitem_committing
  625. };
  626. /*
  627. * Allocate and initialize an quotaoff item of the correct quota type(s).
  628. */
  629. xfs_qoff_logitem_t *
  630. xfs_qm_qoff_logitem_init(
  631. struct xfs_mount *mp,
  632. xfs_qoff_logitem_t *start,
  633. uint flags)
  634. {
  635. xfs_qoff_logitem_t *qf;
  636. qf = (xfs_qoff_logitem_t*) kmem_zalloc(sizeof(xfs_qoff_logitem_t), KM_SLEEP);
  637. qf->qql_item.li_type = XFS_LI_QUOTAOFF;
  638. if (start)
  639. qf->qql_item.li_ops = &xfs_qm_qoffend_logitem_ops;
  640. else
  641. qf->qql_item.li_ops = &xfs_qm_qoff_logitem_ops;
  642. qf->qql_item.li_mountp = mp;
  643. qf->qql_format.qf_type = XFS_LI_QUOTAOFF;
  644. qf->qql_format.qf_flags = flags;
  645. qf->qql_start_lip = start;
  646. return (qf);
  647. }