~ [ 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-5.13.19)


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

~ [ 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