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