]> Git Repo - linux.git/blame - fs/xfs/xfs_dquot_item.c
Merge tag 'kgdb-6.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/danielt...
[linux.git] / fs / xfs / xfs_dquot_item.c
CommitLineData
0b61f8a4 1// SPDX-License-Identifier: GPL-2.0
1da177e4 2/*
4ce3121f
NS
3 * Copyright (c) 2000-2003 Silicon Graphics, Inc.
4 * All Rights Reserved.
1da177e4 5 */
1da177e4
LT
6#include "xfs.h"
7#include "xfs_fs.h"
5467b34b 8#include "xfs_shared.h"
6ca1c906 9#include "xfs_format.h"
239880ef
DC
10#include "xfs_log_format.h"
11#include "xfs_trans_resv.h"
1da177e4 12#include "xfs_mount.h"
1da177e4 13#include "xfs_inode.h"
a4fbe6ab 14#include "xfs_quota.h"
239880ef 15#include "xfs_trans.h"
1da177e4
LT
16#include "xfs_buf_item.h"
17#include "xfs_trans_priv.h"
1da177e4 18#include "xfs_qm.h"
239880ef 19#include "xfs_log.h"
150bb10a 20#include "xfs_error.h"
1da177e4 21
7bfa31d8
CH
22static inline struct xfs_dq_logitem *DQUOT_ITEM(struct xfs_log_item *lip)
23{
24 return container_of(lip, struct xfs_dq_logitem, qli_item);
25}
26
1da177e4
LT
27/*
28 * returns the number of iovecs needed to log the given dquot item.
29 */
166d1368 30STATIC void
1da177e4 31xfs_qm_dquot_logitem_size(
166d1368
DC
32 struct xfs_log_item *lip,
33 int *nvecs,
34 int *nbytes)
1da177e4 35{
166d1368
DC
36 *nvecs += 2;
37 *nbytes += sizeof(struct xfs_dq_logformat) +
38 sizeof(struct xfs_disk_dquot);
1da177e4
LT
39}
40
41/*
42 * fills in the vector of log iovecs for the given dquot log item.
43 */
44STATIC void
45xfs_qm_dquot_logitem_format(
7bfa31d8 46 struct xfs_log_item *lip,
bde7cff6 47 struct xfs_log_vec *lv)
1da177e4 48{
0b0fa1d1 49 struct xfs_disk_dquot ddq;
7bfa31d8 50 struct xfs_dq_logitem *qlip = DQUOT_ITEM(lip);
bde7cff6 51 struct xfs_log_iovec *vecp = NULL;
ce8e9629 52 struct xfs_dq_logformat *qlf;
1da177e4 53
ce8e9629
CH
54 qlf = xlog_prepare_iovec(lv, &vecp, XLOG_REG_TYPE_QFORMAT);
55 qlf->qlf_type = XFS_LI_DQUOT;
56 qlf->qlf_size = 2;
c51df733 57 qlf->qlf_id = qlip->qli_dquot->q_id;
ce8e9629
CH
58 qlf->qlf_blkno = qlip->qli_dquot->q_blkno;
59 qlf->qlf_len = 1;
60 qlf->qlf_boffset = qlip->qli_dquot->q_bufoffset;
61 xlog_finish_iovec(lv, vecp, sizeof(struct xfs_dq_logformat));
bde7cff6 62
0b0fa1d1
DW
63 xfs_dquot_to_disk(&ddq, qlip->qli_dquot);
64
65 xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_DQUOT, &ddq,
1234351c 66 sizeof(struct xfs_disk_dquot));
1da177e4
LT
67}
68
69/*
70 * Increment the pin count of the given dquot.
1da177e4
LT
71 */
72STATIC void
73xfs_qm_dquot_logitem_pin(
7bfa31d8 74 struct xfs_log_item *lip)
1da177e4 75{
7bfa31d8 76 struct xfs_dquot *dqp = DQUOT_ITEM(lip)->qli_dquot;
1da177e4 77
1da177e4 78 ASSERT(XFS_DQ_IS_LOCKED(dqp));
d1de8021 79 atomic_inc(&dqp->q_pincount);
1da177e4
LT
80}
81
82/*
83 * Decrement the pin count of the given dquot, and wake up
84 * anyone in xfs_dqwait_unpin() if the count goes to 0. The
bc3048e3
PL
85 * dquot must have been previously pinned with a call to
86 * xfs_qm_dquot_logitem_pin().
1da177e4 87 */
1da177e4
LT
88STATIC void
89xfs_qm_dquot_logitem_unpin(
7bfa31d8 90 struct xfs_log_item *lip,
9412e318 91 int remove)
1da177e4 92{
7bfa31d8 93 struct xfs_dquot *dqp = DQUOT_ITEM(lip)->qli_dquot;
1da177e4 94
bc3048e3
PL
95 ASSERT(atomic_read(&dqp->q_pincount) > 0);
96 if (atomic_dec_and_test(&dqp->q_pincount))
97 wake_up(&dqp->q_pinwait);
1da177e4
LT
98}
99
1da177e4
LT
100/*
101 * This is called to wait for the given dquot to be unpinned.
102 * Most of these pin/unpin routines are plagiarized from inode code.
103 */
104void
105xfs_qm_dqunpin_wait(
7bfa31d8 106 struct xfs_dquot *dqp)
1da177e4 107{
1da177e4 108 ASSERT(XFS_DQ_IS_LOCKED(dqp));
bc3048e3 109 if (atomic_read(&dqp->q_pincount) == 0)
1da177e4 110 return;
1da177e4
LT
111
112 /*
113 * Give the log a push so we don't wait here too long.
114 */
a14a348b 115 xfs_log_force(dqp->q_mount, 0);
bc3048e3 116 wait_event(dqp->q_pinwait, (atomic_read(&dqp->q_pincount) == 0));
1da177e4
LT
117}
118
1da177e4 119STATIC uint
43ff2122
CH
120xfs_qm_dquot_logitem_push(
121 struct xfs_log_item *lip,
57e80956
MW
122 struct list_head *buffer_list)
123 __releases(&lip->li_ailp->ail_lock)
124 __acquires(&lip->li_ailp->ail_lock)
1da177e4 125{
7bfa31d8 126 struct xfs_dquot *dqp = DQUOT_ITEM(lip)->qli_dquot;
373b0589 127 struct xfs_buf *bp = lip->li_buf;
43ff2122
CH
128 uint rval = XFS_ITEM_SUCCESS;
129 int error;
1da177e4 130
bc3048e3 131 if (atomic_read(&dqp->q_pincount) > 0)
d808f617 132 return XFS_ITEM_PINNED;
1da177e4 133
800b484e 134 if (!xfs_dqlock_nowait(dqp))
d808f617 135 return XFS_ITEM_LOCKED;
1da177e4 136
fe7257fd
CH
137 /*
138 * Re-check the pincount now that we stabilized the value by
139 * taking the quota lock.
140 */
141 if (atomic_read(&dqp->q_pincount) > 0) {
43ff2122
CH
142 rval = XFS_ITEM_PINNED;
143 goto out_unlock;
fe7257fd
CH
144 }
145
43ff2122
CH
146 /*
147 * Someone else is already flushing the dquot. Nothing we can do
148 * here but wait for the flush to finish and remove the item from
149 * the AIL.
150 */
e1f49cf2 151 if (!xfs_dqflock_nowait(dqp)) {
43ff2122
CH
152 rval = XFS_ITEM_FLUSHING;
153 goto out_unlock;
154 }
155
57e80956 156 spin_unlock(&lip->li_ailp->ail_lock);
43ff2122
CH
157
158 error = xfs_qm_dqflush(dqp, &bp);
609001bc 159 if (!error) {
43ff2122
CH
160 if (!xfs_buf_delwri_queue(bp, buffer_list))
161 rval = XFS_ITEM_FLUSHING;
162 xfs_buf_relse(bp);
8d3d7e2b
BF
163 } else if (error == -EAGAIN)
164 rval = XFS_ITEM_LOCKED;
1da177e4 165
57e80956 166 spin_lock(&lip->li_ailp->ail_lock);
43ff2122
CH
167out_unlock:
168 xfs_dqunlock(dqp);
169 return rval;
1da177e4
LT
170}
171
1da177e4 172STATIC void
ddf92053 173xfs_qm_dquot_logitem_release(
7bfa31d8 174 struct xfs_log_item *lip)
1da177e4 175{
7bfa31d8 176 struct xfs_dquot *dqp = DQUOT_ITEM(lip)->qli_dquot;
1da177e4 177
1da177e4
LT
178 ASSERT(XFS_DQ_IS_LOCKED(dqp));
179
1da177e4
LT
180 /*
181 * dquots are never 'held' from getting unlocked at the end of
182 * a transaction. Their locking and unlocking is hidden inside the
183 * transaction layer, within trans_commit. Hence, no LI_HOLD flag
184 * for the logitem.
185 */
186 xfs_dqunlock(dqp);
187}
188
ddf92053
CH
189STATIC void
190xfs_qm_dquot_logitem_committing(
191 struct xfs_log_item *lip,
5f9b4b0d 192 xfs_csn_t seq)
ddf92053
CH
193{
194 return xfs_qm_dquot_logitem_release(lip);
195}
196
150bb10a
DW
197#ifdef DEBUG_EXPENSIVE
198static int
199xfs_qm_dquot_logitem_precommit(
200 struct xfs_trans *tp,
201 struct xfs_log_item *lip)
202{
203 struct xfs_dquot *dqp = DQUOT_ITEM(lip)->qli_dquot;
204 struct xfs_mount *mp = dqp->q_mount;
205 struct xfs_disk_dquot ddq = { };
206 xfs_failaddr_t fa;
207
208 xfs_dquot_to_disk(&ddq, dqp);
209 fa = xfs_dquot_verify(mp, &ddq, dqp->q_id);
210 if (fa) {
211 XFS_CORRUPTION_ERROR("Bad dquot during logging",
212 XFS_ERRLEVEL_LOW, mp, &ddq, sizeof(ddq));
213 xfs_alert(mp,
214 "Metadata corruption detected at %pS, dquot 0x%x",
215 fa, dqp->q_id);
216 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
217 ASSERT(fa == NULL);
218 }
219
220 return 0;
221}
222#else
223# define xfs_qm_dquot_logitem_precommit NULL
224#endif
225
272e42b2 226static const struct xfs_item_ops xfs_dquot_item_ops = {
7bfa31d8 227 .iop_size = xfs_qm_dquot_logitem_size,
150bb10a 228 .iop_precommit = xfs_qm_dquot_logitem_precommit,
7bfa31d8
CH
229 .iop_format = xfs_qm_dquot_logitem_format,
230 .iop_pin = xfs_qm_dquot_logitem_pin,
231 .iop_unpin = xfs_qm_dquot_logitem_unpin,
ddf92053
CH
232 .iop_release = xfs_qm_dquot_logitem_release,
233 .iop_committing = xfs_qm_dquot_logitem_committing,
7bfa31d8 234 .iop_push = xfs_qm_dquot_logitem_push,
1da177e4
LT
235};
236
237/*
238 * Initialize the dquot log item for a newly allocated dquot.
239 * The dquot isn't locked at this point, but it isn't on any of the lists
240 * either, so we don't care.
241 */
242void
243xfs_qm_dquot_logitem_init(
7bfa31d8 244 struct xfs_dquot *dqp)
1da177e4 245{
7bfa31d8 246 struct xfs_dq_logitem *lp = &dqp->q_logitem;
1da177e4 247
43f5efc5
DC
248 xfs_log_item_init(dqp->q_mount, &lp->qli_item, XFS_LI_DQUOT,
249 &xfs_dquot_item_ops);
1da177e4 250 lp->qli_dquot = dqp;
1da177e4 251}
This page took 1.319261 seconds and 4 git commands to generate.