Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Nathan Scott | 4ce3121 | 2005-11-02 14:59:41 +1100 | [diff] [blame] | 3 | * Copyright (c) 2000-2003 Silicon Graphics, Inc. |
| 4 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include "xfs.h" |
| 7 | #include "xfs_fs.h" |
Darrick J. Wong | 5467b34 | 2019-06-28 19:25:35 -0700 | [diff] [blame] | 8 | #include "xfs_shared.h" |
Dave Chinner | 6ca1c90 | 2013-08-12 20:49:26 +1000 | [diff] [blame] | 9 | #include "xfs_format.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 10 | #include "xfs_log_format.h" |
| 11 | #include "xfs_trans_resv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include "xfs_mount.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include "xfs_inode.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 14 | #include "xfs_quota.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 15 | #include "xfs_trans.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include "xfs_buf_item.h" |
| 17 | #include "xfs_trans_priv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "xfs_qm.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 19 | #include "xfs_log.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 21 | static inline struct xfs_dq_logitem *DQUOT_ITEM(struct xfs_log_item *lip) |
| 22 | { |
| 23 | return container_of(lip, struct xfs_dq_logitem, qli_item); |
| 24 | } |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | /* |
| 27 | * returns the number of iovecs needed to log the given dquot item. |
| 28 | */ |
Dave Chinner | 166d136 | 2013-08-12 20:50:04 +1000 | [diff] [blame] | 29 | STATIC void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | xfs_qm_dquot_logitem_size( |
Dave Chinner | 166d136 | 2013-08-12 20:50:04 +1000 | [diff] [blame] | 31 | struct xfs_log_item *lip, |
| 32 | int *nvecs, |
| 33 | int *nbytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
Dave Chinner | 166d136 | 2013-08-12 20:50:04 +1000 | [diff] [blame] | 35 | *nvecs += 2; |
| 36 | *nbytes += sizeof(struct xfs_dq_logformat) + |
| 37 | sizeof(struct xfs_disk_dquot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | /* |
| 41 | * fills in the vector of log iovecs for the given dquot log item. |
| 42 | */ |
| 43 | STATIC void |
| 44 | xfs_qm_dquot_logitem_format( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 45 | struct xfs_log_item *lip, |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 46 | struct xfs_log_vec *lv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
Darrick J. Wong | 0b0fa1d | 2020-07-14 10:37:22 -0700 | [diff] [blame] | 48 | struct xfs_disk_dquot ddq; |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 49 | struct xfs_dq_logitem *qlip = DQUOT_ITEM(lip); |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 50 | struct xfs_log_iovec *vecp = NULL; |
Christoph Hellwig | ce8e962 | 2013-12-13 11:34:07 +1100 | [diff] [blame] | 51 | struct xfs_dq_logformat *qlf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Christoph Hellwig | ce8e962 | 2013-12-13 11:34:07 +1100 | [diff] [blame] | 53 | qlf = xlog_prepare_iovec(lv, &vecp, XLOG_REG_TYPE_QFORMAT); |
| 54 | qlf->qlf_type = XFS_LI_DQUOT; |
| 55 | qlf->qlf_size = 2; |
Darrick J. Wong | c51df73 | 2020-07-14 10:37:30 -0700 | [diff] [blame] | 56 | qlf->qlf_id = qlip->qli_dquot->q_id; |
Christoph Hellwig | ce8e962 | 2013-12-13 11:34:07 +1100 | [diff] [blame] | 57 | qlf->qlf_blkno = qlip->qli_dquot->q_blkno; |
| 58 | qlf->qlf_len = 1; |
| 59 | qlf->qlf_boffset = qlip->qli_dquot->q_bufoffset; |
| 60 | xlog_finish_iovec(lv, vecp, sizeof(struct xfs_dq_logformat)); |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 61 | |
Darrick J. Wong | 0b0fa1d | 2020-07-14 10:37:22 -0700 | [diff] [blame] | 62 | xfs_dquot_to_disk(&ddq, qlip->qli_dquot); |
| 63 | |
| 64 | xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_DQUOT, &ddq, |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 65 | sizeof(struct xfs_disk_dquot)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /* |
| 69 | * Increment the pin count of the given dquot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | */ |
| 71 | STATIC void |
| 72 | xfs_qm_dquot_logitem_pin( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 73 | struct xfs_log_item *lip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 75 | struct xfs_dquot *dqp = DQUOT_ITEM(lip)->qli_dquot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | ASSERT(XFS_DQ_IS_LOCKED(dqp)); |
Peter Leckie | d1de802 | 2008-10-30 17:05:18 +1100 | [diff] [blame] | 78 | atomic_inc(&dqp->q_pincount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /* |
| 82 | * Decrement the pin count of the given dquot, and wake up |
| 83 | * anyone in xfs_dqwait_unpin() if the count goes to 0. The |
Peter Leckie | bc3048e | 2008-10-30 17:05:04 +1100 | [diff] [blame] | 84 | * dquot must have been previously pinned with a call to |
| 85 | * xfs_qm_dquot_logitem_pin(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | STATIC void |
| 88 | xfs_qm_dquot_logitem_unpin( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 89 | struct xfs_log_item *lip, |
Christoph Hellwig | 9412e31 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 90 | int remove) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 92 | struct xfs_dquot *dqp = DQUOT_ITEM(lip)->qli_dquot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Peter Leckie | bc3048e | 2008-10-30 17:05:04 +1100 | [diff] [blame] | 94 | ASSERT(atomic_read(&dqp->q_pincount) > 0); |
| 95 | if (atomic_dec_and_test(&dqp->q_pincount)) |
| 96 | wake_up(&dqp->q_pinwait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | /* |
| 100 | * This is called to wait for the given dquot to be unpinned. |
| 101 | * Most of these pin/unpin routines are plagiarized from inode code. |
| 102 | */ |
| 103 | void |
| 104 | xfs_qm_dqunpin_wait( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 105 | struct xfs_dquot *dqp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | ASSERT(XFS_DQ_IS_LOCKED(dqp)); |
Peter Leckie | bc3048e | 2008-10-30 17:05:04 +1100 | [diff] [blame] | 108 | if (atomic_read(&dqp->q_pincount) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | /* |
| 112 | * Give the log a push so we don't wait here too long. |
| 113 | */ |
Christoph Hellwig | a14a348 | 2010-01-19 09:56:46 +0000 | [diff] [blame] | 114 | xfs_log_force(dqp->q_mount, 0); |
Peter Leckie | bc3048e | 2008-10-30 17:05:04 +1100 | [diff] [blame] | 115 | wait_event(dqp->q_pinwait, (atomic_read(&dqp->q_pincount) == 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | STATIC uint |
Christoph Hellwig | 43ff212 | 2012-04-23 15:58:39 +1000 | [diff] [blame] | 119 | xfs_qm_dquot_logitem_push( |
| 120 | struct xfs_log_item *lip, |
Matthew Wilcox | 57e8095 | 2018-03-07 14:59:39 -0800 | [diff] [blame] | 121 | struct list_head *buffer_list) |
| 122 | __releases(&lip->li_ailp->ail_lock) |
| 123 | __acquires(&lip->li_ailp->ail_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 125 | struct xfs_dquot *dqp = DQUOT_ITEM(lip)->qli_dquot; |
Carlos Maiolino | 373b058 | 2017-11-28 08:54:10 -0800 | [diff] [blame] | 126 | struct xfs_buf *bp = lip->li_buf; |
Christoph Hellwig | 43ff212 | 2012-04-23 15:58:39 +1000 | [diff] [blame] | 127 | uint rval = XFS_ITEM_SUCCESS; |
| 128 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Peter Leckie | bc3048e | 2008-10-30 17:05:04 +1100 | [diff] [blame] | 130 | if (atomic_read(&dqp->q_pincount) > 0) |
Dave Chinner | d808f61 | 2010-02-02 10:13:42 +1100 | [diff] [blame] | 131 | return XFS_ITEM_PINNED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Christoph Hellwig | 800b484 | 2011-12-06 21:58:14 +0000 | [diff] [blame] | 133 | if (!xfs_dqlock_nowait(dqp)) |
Dave Chinner | d808f61 | 2010-02-02 10:13:42 +1100 | [diff] [blame] | 134 | return XFS_ITEM_LOCKED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Christoph Hellwig | fe7257f | 2012-04-23 15:58:37 +1000 | [diff] [blame] | 136 | /* |
| 137 | * Re-check the pincount now that we stabilized the value by |
| 138 | * taking the quota lock. |
| 139 | */ |
| 140 | if (atomic_read(&dqp->q_pincount) > 0) { |
Christoph Hellwig | 43ff212 | 2012-04-23 15:58:39 +1000 | [diff] [blame] | 141 | rval = XFS_ITEM_PINNED; |
| 142 | goto out_unlock; |
Christoph Hellwig | fe7257f | 2012-04-23 15:58:37 +1000 | [diff] [blame] | 143 | } |
| 144 | |
Christoph Hellwig | 43ff212 | 2012-04-23 15:58:39 +1000 | [diff] [blame] | 145 | /* |
| 146 | * Someone else is already flushing the dquot. Nothing we can do |
| 147 | * here but wait for the flush to finish and remove the item from |
| 148 | * the AIL. |
| 149 | */ |
David Chinner | e1f49cf | 2008-08-13 16:41:43 +1000 | [diff] [blame] | 150 | if (!xfs_dqflock_nowait(dqp)) { |
Christoph Hellwig | 43ff212 | 2012-04-23 15:58:39 +1000 | [diff] [blame] | 151 | rval = XFS_ITEM_FLUSHING; |
| 152 | goto out_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Matthew Wilcox | 57e8095 | 2018-03-07 14:59:39 -0800 | [diff] [blame] | 155 | spin_unlock(&lip->li_ailp->ail_lock); |
Christoph Hellwig | 43ff212 | 2012-04-23 15:58:39 +1000 | [diff] [blame] | 156 | |
| 157 | error = xfs_qm_dqflush(dqp, &bp); |
Darrick J. Wong | 609001b | 2018-05-04 15:30:20 -0700 | [diff] [blame] | 158 | if (!error) { |
Christoph Hellwig | 43ff212 | 2012-04-23 15:58:39 +1000 | [diff] [blame] | 159 | if (!xfs_buf_delwri_queue(bp, buffer_list)) |
| 160 | rval = XFS_ITEM_FLUSHING; |
| 161 | xfs_buf_relse(bp); |
Brian Foster | 8d3d7e2 | 2020-03-27 08:29:45 -0700 | [diff] [blame] | 162 | } else if (error == -EAGAIN) |
| 163 | rval = XFS_ITEM_LOCKED; |
Christoph Hellwig | 43ff212 | 2012-04-23 15:58:39 +1000 | [diff] [blame] | 164 | |
Matthew Wilcox | 57e8095 | 2018-03-07 14:59:39 -0800 | [diff] [blame] | 165 | spin_lock(&lip->li_ailp->ail_lock); |
Christoph Hellwig | 43ff212 | 2012-04-23 15:58:39 +1000 | [diff] [blame] | 166 | out_unlock: |
| 167 | xfs_dqunlock(dqp); |
| 168 | return rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | STATIC void |
Christoph Hellwig | ddf9205 | 2019-06-28 19:27:32 -0700 | [diff] [blame] | 172 | xfs_qm_dquot_logitem_release( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 173 | struct xfs_log_item *lip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 175 | struct xfs_dquot *dqp = DQUOT_ITEM(lip)->qli_dquot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | ASSERT(XFS_DQ_IS_LOCKED(dqp)); |
| 178 | |
| 179 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | * dquots are never 'held' from getting unlocked at the end of |
| 181 | * a transaction. Their locking and unlocking is hidden inside the |
| 182 | * transaction layer, within trans_commit. Hence, no LI_HOLD flag |
| 183 | * for the logitem. |
| 184 | */ |
| 185 | xfs_dqunlock(dqp); |
| 186 | } |
| 187 | |
Christoph Hellwig | ddf9205 | 2019-06-28 19:27:32 -0700 | [diff] [blame] | 188 | STATIC void |
| 189 | xfs_qm_dquot_logitem_committing( |
| 190 | struct xfs_log_item *lip, |
| 191 | xfs_lsn_t commit_lsn) |
| 192 | { |
| 193 | return xfs_qm_dquot_logitem_release(lip); |
| 194 | } |
| 195 | |
Christoph Hellwig | 272e42b | 2011-10-28 09:54:24 +0000 | [diff] [blame] | 196 | static const struct xfs_item_ops xfs_dquot_item_ops = { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 197 | .iop_size = xfs_qm_dquot_logitem_size, |
| 198 | .iop_format = xfs_qm_dquot_logitem_format, |
| 199 | .iop_pin = xfs_qm_dquot_logitem_pin, |
| 200 | .iop_unpin = xfs_qm_dquot_logitem_unpin, |
Christoph Hellwig | ddf9205 | 2019-06-28 19:27:32 -0700 | [diff] [blame] | 201 | .iop_release = xfs_qm_dquot_logitem_release, |
| 202 | .iop_committing = xfs_qm_dquot_logitem_committing, |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 203 | .iop_push = xfs_qm_dquot_logitem_push, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | /* |
| 207 | * Initialize the dquot log item for a newly allocated dquot. |
| 208 | * The dquot isn't locked at this point, but it isn't on any of the lists |
| 209 | * either, so we don't care. |
| 210 | */ |
| 211 | void |
| 212 | xfs_qm_dquot_logitem_init( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 213 | struct xfs_dquot *dqp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 215 | struct xfs_dq_logitem *lp = &dqp->q_logitem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
Dave Chinner | 43f5efc | 2010-03-23 10:10:00 +1100 | [diff] [blame] | 217 | xfs_log_item_init(dqp->q_mount, &lp->qli_item, XFS_LI_DQUOT, |
| 218 | &xfs_dquot_item_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | lp->qli_dquot = dqp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /*------------------ QUOTAOFF LOG ITEMS -------------------*/ |
| 223 | |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 224 | static inline struct xfs_qoff_logitem *QOFF_ITEM(struct xfs_log_item *lip) |
| 225 | { |
| 226 | return container_of(lip, struct xfs_qoff_logitem, qql_item); |
| 227 | } |
| 228 | |
| 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | /* |
| 231 | * This returns the number of iovecs needed to log the given quotaoff item. |
| 232 | * We only need 1 iovec for an quotaoff item. It just logs the |
| 233 | * quotaoff_log_format structure. |
| 234 | */ |
Dave Chinner | 166d136 | 2013-08-12 20:50:04 +1000 | [diff] [blame] | 235 | STATIC void |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 236 | xfs_qm_qoff_logitem_size( |
Dave Chinner | 166d136 | 2013-08-12 20:50:04 +1000 | [diff] [blame] | 237 | struct xfs_log_item *lip, |
| 238 | int *nvecs, |
| 239 | int *nbytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | { |
Dave Chinner | 166d136 | 2013-08-12 20:50:04 +1000 | [diff] [blame] | 241 | *nvecs += 1; |
| 242 | *nbytes += sizeof(struct xfs_qoff_logitem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | STATIC void |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 246 | xfs_qm_qoff_logitem_format( |
| 247 | struct xfs_log_item *lip, |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 248 | struct xfs_log_vec *lv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 250 | struct xfs_qoff_logitem *qflip = QOFF_ITEM(lip); |
Christoph Hellwig | bde7cff | 2013-12-13 11:34:02 +1100 | [diff] [blame] | 251 | struct xfs_log_iovec *vecp = NULL; |
Christoph Hellwig | ffda4e8 | 2013-12-13 11:34:08 +1100 | [diff] [blame] | 252 | struct xfs_qoff_logformat *qlf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
Christoph Hellwig | ffda4e8 | 2013-12-13 11:34:08 +1100 | [diff] [blame] | 254 | qlf = xlog_prepare_iovec(lv, &vecp, XLOG_REG_TYPE_QUOTAOFF); |
| 255 | qlf->qf_type = XFS_LI_QUOTAOFF; |
| 256 | qlf->qf_size = 1; |
| 257 | qlf->qf_flags = qflip->qql_flags; |
| 258 | xlog_finish_iovec(lv, vecp, sizeof(struct xfs_qoff_logitem)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | /* |
Christoph Hellwig | 43ff212 | 2012-04-23 15:58:39 +1000 | [diff] [blame] | 262 | * There isn't much you can do to push a quotaoff item. It is simply |
| 263 | * stuck waiting for the log to be flushed to disk. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | STATIC uint |
Christoph Hellwig | 43ff212 | 2012-04-23 15:58:39 +1000 | [diff] [blame] | 266 | xfs_qm_qoff_logitem_push( |
| 267 | struct xfs_log_item *lip, |
| 268 | struct list_head *buffer_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | { |
| 270 | return XFS_ITEM_LOCKED; |
| 271 | } |
| 272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | STATIC xfs_lsn_t |
| 274 | xfs_qm_qoffend_logitem_committed( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 275 | struct xfs_log_item *lip, |
| 276 | xfs_lsn_t lsn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 278 | struct xfs_qoff_logitem *qfe = QOFF_ITEM(lip); |
| 279 | struct xfs_qoff_logitem *qfs = qfe->qql_start_lip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
Brian Foster | 854f82b | 2020-03-16 14:26:09 -0700 | [diff] [blame] | 281 | xfs_qm_qoff_logitem_relse(qfs); |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 282 | |
Dave Chinner | b1c5ebb | 2016-07-22 09:52:35 +1000 | [diff] [blame] | 283 | kmem_free(lip->li_lv_shadow); |
Denys Vlasenko | f0e2d93 | 2008-05-19 16:31:57 +1000 | [diff] [blame] | 284 | kmem_free(qfe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | return (xfs_lsn_t)-1; |
| 286 | } |
| 287 | |
Brian Foster | 8a62714 | 2020-03-16 14:26:09 -0700 | [diff] [blame] | 288 | STATIC void |
| 289 | xfs_qm_qoff_logitem_release( |
| 290 | struct xfs_log_item *lip) |
| 291 | { |
| 292 | struct xfs_qoff_logitem *qoff = QOFF_ITEM(lip); |
| 293 | |
| 294 | if (test_bit(XFS_LI_ABORTED, &lip->li_flags)) { |
| 295 | if (qoff->qql_start_lip) |
| 296 | xfs_qm_qoff_logitem_relse(qoff->qql_start_lip); |
| 297 | xfs_qm_qoff_logitem_relse(qoff); |
| 298 | } |
| 299 | } |
| 300 | |
Christoph Hellwig | 272e42b | 2011-10-28 09:54:24 +0000 | [diff] [blame] | 301 | static const struct xfs_item_ops xfs_qm_qoffend_logitem_ops = { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 302 | .iop_size = xfs_qm_qoff_logitem_size, |
| 303 | .iop_format = xfs_qm_qoff_logitem_format, |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 304 | .iop_committed = xfs_qm_qoffend_logitem_committed, |
| 305 | .iop_push = xfs_qm_qoff_logitem_push, |
Brian Foster | 8a62714 | 2020-03-16 14:26:09 -0700 | [diff] [blame] | 306 | .iop_release = xfs_qm_qoff_logitem_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | }; |
| 308 | |
Christoph Hellwig | 272e42b | 2011-10-28 09:54:24 +0000 | [diff] [blame] | 309 | static const struct xfs_item_ops xfs_qm_qoff_logitem_ops = { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 310 | .iop_size = xfs_qm_qoff_logitem_size, |
| 311 | .iop_format = xfs_qm_qoff_logitem_format, |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 312 | .iop_push = xfs_qm_qoff_logitem_push, |
Brian Foster | 8a62714 | 2020-03-16 14:26:09 -0700 | [diff] [blame] | 313 | .iop_release = xfs_qm_qoff_logitem_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | }; |
| 315 | |
| 316 | /* |
Brian Foster | 854f82b | 2020-03-16 14:26:09 -0700 | [diff] [blame] | 317 | * Delete the quotaoff intent from the AIL and free it. On success, |
| 318 | * this should only be called for the start item. It can be used for |
| 319 | * either on shutdown or abort. |
| 320 | */ |
| 321 | void |
| 322 | xfs_qm_qoff_logitem_relse( |
| 323 | struct xfs_qoff_logitem *qoff) |
| 324 | { |
| 325 | struct xfs_log_item *lip = &qoff->qql_item; |
| 326 | |
| 327 | ASSERT(test_bit(XFS_LI_IN_AIL, &lip->li_flags) || |
| 328 | test_bit(XFS_LI_ABORTED, &lip->li_flags) || |
| 329 | XFS_FORCED_SHUTDOWN(lip->li_mountp)); |
Brian Foster | 2b3cf09 | 2020-05-06 13:27:04 -0700 | [diff] [blame] | 330 | xfs_trans_ail_delete(lip, 0); |
Brian Foster | 854f82b | 2020-03-16 14:26:09 -0700 | [diff] [blame] | 331 | kmem_free(lip->li_lv_shadow); |
| 332 | kmem_free(qoff); |
| 333 | } |
| 334 | |
| 335 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | * Allocate and initialize an quotaoff item of the correct quota type(s). |
| 337 | */ |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 338 | struct xfs_qoff_logitem * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | xfs_qm_qoff_logitem_init( |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 340 | struct xfs_mount *mp, |
| 341 | struct xfs_qoff_logitem *start, |
| 342 | uint flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 344 | struct xfs_qoff_logitem *qf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
Tetsuo Handa | 707e0dd | 2019-08-26 12:06:22 -0700 | [diff] [blame] | 346 | qf = kmem_zalloc(sizeof(struct xfs_qoff_logitem), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
Dave Chinner | 43f5efc | 2010-03-23 10:10:00 +1100 | [diff] [blame] | 348 | xfs_log_item_init(mp, &qf->qql_item, XFS_LI_QUOTAOFF, start ? |
| 349 | &xfs_qm_qoffend_logitem_ops : &xfs_qm_qoff_logitem_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | qf->qql_item.li_mountp = mp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | qf->qql_start_lip = start; |
Christoph Hellwig | ffda4e8 | 2013-12-13 11:34:08 +1100 | [diff] [blame] | 352 | qf->qql_flags = flags; |
Christoph Hellwig | 7bfa31d | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 353 | return qf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | } |