~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/xfs/xfs_dquot_item_recover.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/xfs/xfs_dquot_item_recover.c (Version linux-6.12-rc7) and /fs/xfs/xfs_dquot_item_recover.c (Version linux-6.11.7)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 /*                                                  2 /*
  3  * Copyright (c) 2000-2006 Silicon Graphics, I      3  * Copyright (c) 2000-2006 Silicon Graphics, Inc.
  4  * All Rights Reserved.                             4  * All Rights Reserved.
  5  */                                                 5  */
  6 #include "xfs.h"                                    6 #include "xfs.h"
  7 #include "xfs_fs.h"                                 7 #include "xfs_fs.h"
  8 #include "xfs_shared.h"                             8 #include "xfs_shared.h"
  9 #include "xfs_format.h"                             9 #include "xfs_format.h"
 10 #include "xfs_log_format.h"                        10 #include "xfs_log_format.h"
 11 #include "xfs_trans_resv.h"                        11 #include "xfs_trans_resv.h"
 12 #include "xfs_mount.h"                             12 #include "xfs_mount.h"
 13 #include "xfs_inode.h"                             13 #include "xfs_inode.h"
 14 #include "xfs_quota.h"                             14 #include "xfs_quota.h"
 15 #include "xfs_trans.h"                             15 #include "xfs_trans.h"
 16 #include "xfs_buf_item.h"                          16 #include "xfs_buf_item.h"
 17 #include "xfs_trans_priv.h"                        17 #include "xfs_trans_priv.h"
 18 #include "xfs_qm.h"                                18 #include "xfs_qm.h"
 19 #include "xfs_log.h"                               19 #include "xfs_log.h"
 20 #include "xfs_log_priv.h"                          20 #include "xfs_log_priv.h"
 21 #include "xfs_log_recover.h"                       21 #include "xfs_log_recover.h"
 22 #include "xfs_error.h"                             22 #include "xfs_error.h"
 23                                                    23 
 24 STATIC void                                        24 STATIC void
 25 xlog_recover_dquot_ra_pass2(                       25 xlog_recover_dquot_ra_pass2(
 26         struct xlog                     *log,      26         struct xlog                     *log,
 27         struct xlog_recover_item        *item)     27         struct xlog_recover_item        *item)
 28 {                                                  28 {
 29         struct xfs_mount        *mp = log->l_m     29         struct xfs_mount        *mp = log->l_mp;
 30         struct xfs_disk_dquot   *recddq;           30         struct xfs_disk_dquot   *recddq;
 31         struct xfs_dq_logformat *dq_f;             31         struct xfs_dq_logformat *dq_f;
 32         uint                    type;              32         uint                    type;
 33                                                    33 
 34         if (mp->m_qflags == 0)                     34         if (mp->m_qflags == 0)
 35                 return;                            35                 return;
 36                                                    36 
 37         recddq = item->ri_buf[1].i_addr;           37         recddq = item->ri_buf[1].i_addr;
 38         if (recddq == NULL)                        38         if (recddq == NULL)
 39                 return;                            39                 return;
 40         if (item->ri_buf[1].i_len < sizeof(str     40         if (item->ri_buf[1].i_len < sizeof(struct xfs_disk_dquot))
 41                 return;                            41                 return;
 42                                                    42 
 43         type = recddq->d_type & XFS_DQTYPE_REC     43         type = recddq->d_type & XFS_DQTYPE_REC_MASK;
 44         ASSERT(type);                              44         ASSERT(type);
 45         if (log->l_quotaoffs_flag & type)          45         if (log->l_quotaoffs_flag & type)
 46                 return;                            46                 return;
 47                                                    47 
 48         dq_f = item->ri_buf[0].i_addr;             48         dq_f = item->ri_buf[0].i_addr;
 49         ASSERT(dq_f);                              49         ASSERT(dq_f);
 50         ASSERT(dq_f->qlf_len == 1);                50         ASSERT(dq_f->qlf_len == 1);
 51                                                    51 
 52         xlog_buf_readahead(log, dq_f->qlf_blkn     52         xlog_buf_readahead(log, dq_f->qlf_blkno,
 53                         XFS_FSB_TO_BB(mp, dq_f     53                         XFS_FSB_TO_BB(mp, dq_f->qlf_len),
 54                         &xfs_dquot_buf_ra_ops)     54                         &xfs_dquot_buf_ra_ops);
 55 }                                                  55 }
 56                                                    56 
 57 /*                                                 57 /*
 58  * Recover a dquot record                          58  * Recover a dquot record
 59  */                                                59  */
 60 STATIC int                                         60 STATIC int
 61 xlog_recover_dquot_commit_pass2(                   61 xlog_recover_dquot_commit_pass2(
 62         struct xlog                     *log,      62         struct xlog                     *log,
 63         struct list_head                *buffe     63         struct list_head                *buffer_list,
 64         struct xlog_recover_item        *item,     64         struct xlog_recover_item        *item,
 65         xfs_lsn_t                       curren     65         xfs_lsn_t                       current_lsn)
 66 {                                                  66 {
 67         struct xfs_mount                *mp =      67         struct xfs_mount                *mp = log->l_mp;
 68         struct xfs_buf                  *bp;       68         struct xfs_buf                  *bp;
 69         struct xfs_dqblk                *dqb;      69         struct xfs_dqblk                *dqb;
 70         struct xfs_disk_dquot           *ddq,      70         struct xfs_disk_dquot           *ddq, *recddq;
 71         struct xfs_dq_logformat         *dq_f;     71         struct xfs_dq_logformat         *dq_f;
 72         xfs_failaddr_t                  fa;        72         xfs_failaddr_t                  fa;
 73         int                             error;     73         int                             error;
 74         uint                            type;      74         uint                            type;
 75                                                    75 
 76         /*                                         76         /*
 77          * Filesystems are required to send in     77          * Filesystems are required to send in quota flags at mount time.
 78          */                                        78          */
 79         if (mp->m_qflags == 0)                     79         if (mp->m_qflags == 0)
 80                 return 0;                          80                 return 0;
 81                                                    81 
 82         recddq = item->ri_buf[1].i_addr;           82         recddq = item->ri_buf[1].i_addr;
 83         if (recddq == NULL) {                      83         if (recddq == NULL) {
 84                 xfs_alert(log->l_mp, "NULL dqu     84                 xfs_alert(log->l_mp, "NULL dquot in %s.", __func__);
 85                 return -EFSCORRUPTED;              85                 return -EFSCORRUPTED;
 86         }                                          86         }
 87         if (item->ri_buf[1].i_len < sizeof(str     87         if (item->ri_buf[1].i_len < sizeof(struct xfs_disk_dquot)) {
 88                 xfs_alert(log->l_mp, "dquot to     88                 xfs_alert(log->l_mp, "dquot too small (%d) in %s.",
 89                         item->ri_buf[1].i_len,     89                         item->ri_buf[1].i_len, __func__);
 90                 return -EFSCORRUPTED;              90                 return -EFSCORRUPTED;
 91         }                                          91         }
 92                                                    92 
 93         /*                                         93         /*
 94          * This type of quotas was turned off,     94          * This type of quotas was turned off, so ignore this record.
 95          */                                        95          */
 96         type = recddq->d_type & XFS_DQTYPE_REC     96         type = recddq->d_type & XFS_DQTYPE_REC_MASK;
 97         ASSERT(type);                              97         ASSERT(type);
 98         if (log->l_quotaoffs_flag & type)          98         if (log->l_quotaoffs_flag & type)
 99                 return 0;                          99                 return 0;
100                                                   100 
101         /*                                        101         /*
102          * At this point we know that quota wa    102          * At this point we know that quota was _not_ turned off.
103          * Since the mount flags are not indic    103          * Since the mount flags are not indicating to us otherwise, this
104          * must mean that quota is on, and the    104          * must mean that quota is on, and the dquot needs to be replayed.
105          * Remember that we may not have fully    105          * Remember that we may not have fully recovered the superblock yet,
106          * so we can't do the usual trick of l    106          * so we can't do the usual trick of looking at the SB quota bits.
107          *                                        107          *
108          * The other possibility, of course, i    108          * The other possibility, of course, is that the quota subsystem was
109          * removed since the last mount - ENOS    109          * removed since the last mount - ENOSYS.
110          */                                       110          */
111         dq_f = item->ri_buf[0].i_addr;            111         dq_f = item->ri_buf[0].i_addr;
112         ASSERT(dq_f);                             112         ASSERT(dq_f);
113         fa = xfs_dquot_verify(mp, recddq, dq_f    113         fa = xfs_dquot_verify(mp, recddq, dq_f->qlf_id);
114         if (fa) {                                 114         if (fa) {
115                 xfs_alert(mp, "corrupt dquot I    115                 xfs_alert(mp, "corrupt dquot ID 0x%x in log at %pS",
116                                 dq_f->qlf_id,     116                                 dq_f->qlf_id, fa);
117                 return -EFSCORRUPTED;             117                 return -EFSCORRUPTED;
118         }                                         118         }
119         ASSERT(dq_f->qlf_len == 1);               119         ASSERT(dq_f->qlf_len == 1);
120                                                   120 
121         /*                                        121         /*
122          * At this point we are assuming that     122          * At this point we are assuming that the dquots have been allocated
123          * and hence the buffer has valid dquo    123          * and hence the buffer has valid dquots stamped in it. It should,
124          * therefore, pass verifier validation    124          * therefore, pass verifier validation. If the dquot is bad, then the
125          * we'll return an error here, so we d    125          * we'll return an error here, so we don't need to specifically check
126          * the dquot in the buffer after the v    126          * the dquot in the buffer after the verifier has run.
127          */                                       127          */
128         error = xfs_trans_read_buf(mp, NULL, m    128         error = xfs_trans_read_buf(mp, NULL, mp->m_ddev_targp, dq_f->qlf_blkno,
129                                    XFS_FSB_TO_    129                                    XFS_FSB_TO_BB(mp, dq_f->qlf_len), 0, &bp,
130                                    &xfs_dquot_    130                                    &xfs_dquot_buf_ops);
131         if (error)                                131         if (error)
132                 return error;                     132                 return error;
133                                                   133 
134         ASSERT(bp);                               134         ASSERT(bp);
135         dqb = xfs_buf_offset(bp, dq_f->qlf_bof    135         dqb = xfs_buf_offset(bp, dq_f->qlf_boffset);
136         ddq = &dqb->dd_diskdq;                    136         ddq = &dqb->dd_diskdq;
137                                                   137 
138         /*                                        138         /*
139          * If the dquot has an LSN in it, reco    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     140          * than the lsn of the transaction we are replaying.
141          */                                       141          */
142         if (xfs_has_crc(mp)) {                    142         if (xfs_has_crc(mp)) {
143                 xfs_lsn_t       lsn = be64_to_    143                 xfs_lsn_t       lsn = be64_to_cpu(dqb->dd_lsn);
144                                                   144 
145                 if (lsn && lsn != -1 && XFS_LS    145                 if (lsn && lsn != -1 && XFS_LSN_CMP(lsn, current_lsn) >= 0) {
146                         goto out_release;         146                         goto out_release;
147                 }                                 147                 }
148         }                                         148         }
149                                                   149 
150         memcpy(ddq, recddq, item->ri_buf[1].i_    150         memcpy(ddq, recddq, item->ri_buf[1].i_len);
151         if (xfs_has_crc(mp)) {                    151         if (xfs_has_crc(mp)) {
152                 xfs_update_cksum((char *)dqb,     152                 xfs_update_cksum((char *)dqb, sizeof(struct xfs_dqblk),
153                                  XFS_DQUOT_CRC    153                                  XFS_DQUOT_CRC_OFF);
154         }                                         154         }
155                                                   155 
156         /* Validate the recovered dquot. */       156         /* Validate the recovered dquot. */
157         fa = xfs_dqblk_verify(log->l_mp, dqb,     157         fa = xfs_dqblk_verify(log->l_mp, dqb, dq_f->qlf_id);
158         if (fa) {                                 158         if (fa) {
159                 XFS_CORRUPTION_ERROR("Bad dquo    159                 XFS_CORRUPTION_ERROR("Bad dquot after recovery",
160                                 XFS_ERRLEVEL_L    160                                 XFS_ERRLEVEL_LOW, mp, dqb,
161                                 sizeof(struct     161                                 sizeof(struct xfs_dqblk));
162                 xfs_alert(mp,                     162                 xfs_alert(mp,
163  "Metadata corruption detected at %pS, dquot 0    163  "Metadata corruption detected at %pS, dquot 0x%x",
164                                 fa, dq_f->qlf_    164                                 fa, dq_f->qlf_id);
165                 error = -EFSCORRUPTED;            165                 error = -EFSCORRUPTED;
166                 goto out_release;                 166                 goto out_release;
167         }                                         167         }
168                                                   168 
169         ASSERT(dq_f->qlf_size == 2);              169         ASSERT(dq_f->qlf_size == 2);
170         ASSERT(bp->b_mount == mp);                170         ASSERT(bp->b_mount == mp);
171         bp->b_flags |= _XBF_LOGRECOVERY;          171         bp->b_flags |= _XBF_LOGRECOVERY;
172         xfs_buf_delwri_queue(bp, buffer_list);    172         xfs_buf_delwri_queue(bp, buffer_list);
173                                                   173 
174 out_release:                                      174 out_release:
175         xfs_buf_relse(bp);                        175         xfs_buf_relse(bp);
176         return 0;                                 176         return 0;
177 }                                                 177 }
178                                                   178 
179 const struct xlog_recover_item_ops xlog_dquot_    179 const struct xlog_recover_item_ops xlog_dquot_item_ops = {
180         .item_type              = XFS_LI_DQUOT    180         .item_type              = XFS_LI_DQUOT,
181         .ra_pass2               = xlog_recover    181         .ra_pass2               = xlog_recover_dquot_ra_pass2,
182         .commit_pass2           = xlog_recover    182         .commit_pass2           = xlog_recover_dquot_commit_pass2,
183 };                                                183 };
184                                                   184 
185 /*                                                185 /*
186  * Recover QUOTAOFF records. We simply make a     186  * Recover QUOTAOFF records. We simply make a note of it in the xlog
187  * structure, so that we know not to do any dq    187  * structure, so that we know not to do any dquot item or dquot buffer recovery,
188  * of that type.                                  188  * of that type.
189  */                                               189  */
190 STATIC int                                        190 STATIC int
191 xlog_recover_quotaoff_commit_pass1(               191 xlog_recover_quotaoff_commit_pass1(
192         struct xlog                     *log,     192         struct xlog                     *log,
193         struct xlog_recover_item        *item)    193         struct xlog_recover_item        *item)
194 {                                                 194 {
195         struct xfs_qoff_logformat       *qoff_    195         struct xfs_qoff_logformat       *qoff_f = item->ri_buf[0].i_addr;
196         ASSERT(qoff_f);                           196         ASSERT(qoff_f);
197                                                   197 
198         /*                                        198         /*
199          * The logitem format's flag tells us     199          * The logitem format's flag tells us if this was user quotaoff,
200          * group/project quotaoff or both.        200          * group/project quotaoff or both.
201          */                                       201          */
202         if (qoff_f->qf_flags & XFS_UQUOTA_ACCT    202         if (qoff_f->qf_flags & XFS_UQUOTA_ACCT)
203                 log->l_quotaoffs_flag |= XFS_D    203                 log->l_quotaoffs_flag |= XFS_DQTYPE_USER;
204         if (qoff_f->qf_flags & XFS_PQUOTA_ACCT    204         if (qoff_f->qf_flags & XFS_PQUOTA_ACCT)
205                 log->l_quotaoffs_flag |= XFS_D    205                 log->l_quotaoffs_flag |= XFS_DQTYPE_PROJ;
206         if (qoff_f->qf_flags & XFS_GQUOTA_ACCT    206         if (qoff_f->qf_flags & XFS_GQUOTA_ACCT)
207                 log->l_quotaoffs_flag |= XFS_D    207                 log->l_quotaoffs_flag |= XFS_DQTYPE_GROUP;
208                                                   208 
209         return 0;                                 209         return 0;
210 }                                                 210 }
211                                                   211 
212 const struct xlog_recover_item_ops xlog_quotao    212 const struct xlog_recover_item_ops xlog_quotaoff_item_ops = {
213         .item_type              = XFS_LI_QUOTA    213         .item_type              = XFS_LI_QUOTAOFF,
214         .commit_pass1           = xlog_recover    214         .commit_pass1           = xlog_recover_quotaoff_commit_pass1,
215         /* nothing to commit in pass2 */          215         /* nothing to commit in pass2 */
216 };                                                216 };
217                                                   217 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php