1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
8 #include "xfs_shared.h"
9 #include "xfs_format.h"
10 #include "xfs_log_format.h"
11 #include "xfs_trans_resv.h"
12 #include "xfs_mount.h"
13 #include "xfs_inode.h"
14 #include "xfs_quota.h"
15 #include "xfs_trans.h"
16 #include "xfs_buf_item.h"
17 #include "xfs_trans_priv.h"
20 #include "xfs_log_priv.h"
21 #include "xfs_log_recover.h"
22 #include "xfs_error.h"
25 xlog_recover_dquot_ra_pass2(
27 struct xlog_recover_item
*item
)
29 struct xfs_mount
*mp
= log
->l_mp
;
30 struct xfs_disk_dquot
*recddq
;
31 struct xfs_dq_logformat
*dq_f
;
34 if (mp
->m_qflags
== 0)
37 recddq
= item
->ri_buf
[1].i_addr
;
40 if (item
->ri_buf
[1].i_len
< sizeof(struct xfs_disk_dquot
))
43 type
= recddq
->d_type
& XFS_DQTYPE_REC_MASK
;
45 if (log
->l_quotaoffs_flag
& type
)
48 dq_f
= item
->ri_buf
[0].i_addr
;
50 ASSERT(dq_f
->qlf_len
== 1);
52 xlog_buf_readahead(log
, dq_f
->qlf_blkno
,
53 XFS_FSB_TO_BB(mp
, dq_f
->qlf_len
),
54 &xfs_dquot_buf_ra_ops
);
58 * Recover a dquot record
61 xlog_recover_dquot_commit_pass2(
63 struct list_head
*buffer_list
,
64 struct xlog_recover_item
*item
,
65 xfs_lsn_t current_lsn
)
67 struct xfs_mount
*mp
= log
->l_mp
;
69 struct xfs_dqblk
*dqb
;
70 struct xfs_disk_dquot
*ddq
, *recddq
;
71 struct xfs_dq_logformat
*dq_f
;
77 * Filesystems are required to send in quota flags at mount time.
79 if (mp
->m_qflags
== 0)
82 recddq
= item
->ri_buf
[1].i_addr
;
84 xfs_alert(log
->l_mp
, "NULL dquot in %s.", __func__
);
87 if (item
->ri_buf
[1].i_len
< sizeof(struct xfs_disk_dquot
)) {
88 xfs_alert(log
->l_mp
, "dquot too small (%d) in %s.",
89 item
->ri_buf
[1].i_len
, __func__
);
94 * This type of quotas was turned off, so ignore this record.
96 type
= recddq
->d_type
& XFS_DQTYPE_REC_MASK
;
98 if (log
->l_quotaoffs_flag
& type
)
102 * At this point we know that quota was _not_ turned off.
103 * Since the mount flags are not indicating to us otherwise, this
104 * must mean that quota is on, and the dquot needs to be replayed.
105 * Remember that we may not have fully recovered the superblock yet,
106 * so we can't do the usual trick of looking at the SB quota bits.
108 * The other possibility, of course, is that the quota subsystem was
109 * removed since the last mount - ENOSYS.
111 dq_f
= item
->ri_buf
[0].i_addr
;
113 fa
= xfs_dquot_verify(mp
, recddq
, dq_f
->qlf_id
);
115 xfs_alert(mp
, "corrupt dquot ID 0x%x in log at %pS",
117 return -EFSCORRUPTED
;
119 ASSERT(dq_f
->qlf_len
== 1);
122 * At this point we are assuming that the dquots have been allocated
123 * and hence the buffer has valid dquots stamped in it. It should,
124 * therefore, pass verifier validation. If the dquot is bad, then the
125 * we'll return an error here, so we don't need to specifically check
126 * the dquot in the buffer after the verifier has run.
128 error
= xfs_trans_read_buf(mp
, NULL
, mp
->m_ddev_targp
, dq_f
->qlf_blkno
,
129 XFS_FSB_TO_BB(mp
, dq_f
->qlf_len
), 0, &bp
,
135 dqb
= xfs_buf_offset(bp
, dq_f
->qlf_boffset
);
136 ddq
= &dqb
->dd_diskdq
;
139 * If the dquot has an LSN in it, recover the dquot only if it's less
140 * than the lsn of the transaction we are replaying.
142 if (xfs_has_crc(mp
)) {
143 xfs_lsn_t lsn
= be64_to_cpu(dqb
->dd_lsn
);
145 if (lsn
&& lsn
!= -1 && XFS_LSN_CMP(lsn
, current_lsn
) >= 0) {
150 memcpy(ddq
, recddq
, item
->ri_buf
[1].i_len
);
151 if (xfs_has_crc(mp
)) {
152 xfs_update_cksum((char *)dqb
, sizeof(struct xfs_dqblk
),
156 /* Validate the recovered dquot. */
157 fa
= xfs_dqblk_verify(log
->l_mp
, dqb
, dq_f
->qlf_id
);
159 XFS_CORRUPTION_ERROR("Bad dquot after recovery",
160 XFS_ERRLEVEL_LOW
, mp
, dqb
,
161 sizeof(struct xfs_dqblk
));
163 "Metadata corruption detected at %pS, dquot 0x%x",
165 error
= -EFSCORRUPTED
;
169 ASSERT(dq_f
->qlf_size
== 2);
170 ASSERT(bp
->b_mount
== mp
);
171 bp
->b_flags
|= _XBF_LOGRECOVERY
;
172 xfs_buf_delwri_queue(bp
, buffer_list
);
179 const struct xlog_recover_item_ops xlog_dquot_item_ops
= {
180 .item_type
= XFS_LI_DQUOT
,
181 .ra_pass2
= xlog_recover_dquot_ra_pass2
,
182 .commit_pass2
= xlog_recover_dquot_commit_pass2
,
186 * Recover QUOTAOFF records. We simply make a note of it in the xlog
187 * structure, so that we know not to do any dquot item or dquot buffer recovery,
191 xlog_recover_quotaoff_commit_pass1(
193 struct xlog_recover_item
*item
)
195 struct xfs_qoff_logformat
*qoff_f
= item
->ri_buf
[0].i_addr
;
199 * The logitem format's flag tells us if this was user quotaoff,
200 * group/project quotaoff or both.
202 if (qoff_f
->qf_flags
& XFS_UQUOTA_ACCT
)
203 log
->l_quotaoffs_flag
|= XFS_DQTYPE_USER
;
204 if (qoff_f
->qf_flags
& XFS_PQUOTA_ACCT
)
205 log
->l_quotaoffs_flag
|= XFS_DQTYPE_PROJ
;
206 if (qoff_f
->qf_flags
& XFS_GQUOTA_ACCT
)
207 log
->l_quotaoffs_flag
|= XFS_DQTYPE_GROUP
;
212 const struct xlog_recover_item_ops xlog_quotaoff_item_ops
= {
213 .item_type
= XFS_LI_QUOTAOFF
,
214 .commit_pass1
= xlog_recover_quotaoff_commit_pass1
,
215 /* nothing to commit in pass2 */