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

TOMOYO Linux Cross Reference
Linux/fs/xfs/xfs_fsops.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_fsops.c (Version linux-6.12-rc7) and /fs/xfs/xfs_fsops.c (Version linux-5.0.21)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 /*                                                  2 /*
  3  * Copyright (c) 2000-2005 Silicon Graphics, I      3  * Copyright (c) 2000-2005 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_sb.h"                                12 #include "xfs_sb.h"
 13 #include "xfs_mount.h"                             13 #include "xfs_mount.h"
                                                   >>  14 #include "xfs_defer.h"
 14 #include "xfs_trans.h"                             15 #include "xfs_trans.h"
 15 #include "xfs_error.h"                             16 #include "xfs_error.h"
                                                   >>  17 #include "xfs_btree.h"
 16 #include "xfs_alloc.h"                             18 #include "xfs_alloc.h"
 17 #include "xfs_fsops.h"                             19 #include "xfs_fsops.h"
 18 #include "xfs_trans_space.h"                       20 #include "xfs_trans_space.h"
                                                   >>  21 #include "xfs_rtalloc.h"
                                                   >>  22 #include "xfs_trace.h"
 19 #include "xfs_log.h"                               23 #include "xfs_log.h"
 20 #include "xfs_log_priv.h"                      << 
 21 #include "xfs_ag.h"                                24 #include "xfs_ag.h"
 22 #include "xfs_ag_resv.h"                           25 #include "xfs_ag_resv.h"
 23 #include "xfs_trace.h"                         << 
 24                                                << 
 25 /*                                             << 
 26  * Write new AG headers to disk. Non-transacti << 
 27  * written and completed prior to the growfs t << 
 28  * To do this, we use a delayed write buffer l << 
 29  * submission and IO completion of the list as << 
 30  * IO subsystem to merge all the AG headers in << 
 31  * IO and hide most of the latency of the IO f << 
 32  *                                             << 
 33  * This also means that if we get an error whi << 
 34  * list to write, we can cancel the entire lis << 
 35  * anything.                                   << 
 36  */                                            << 
 37 static int                                     << 
 38 xfs_resizefs_init_new_ags(                     << 
 39         struct xfs_trans        *tp,           << 
 40         struct aghdr_init_data  *id,           << 
 41         xfs_agnumber_t          oagcount,      << 
 42         xfs_agnumber_t          nagcount,      << 
 43         xfs_rfsblock_t          delta,         << 
 44         struct xfs_perag        *last_pag,     << 
 45         bool                    *lastag_extend << 
 46 {                                              << 
 47         struct xfs_mount        *mp = tp->t_mo << 
 48         xfs_rfsblock_t          nb = mp->m_sb. << 
 49         int                     error;         << 
 50                                                << 
 51         *lastag_extended = false;              << 
 52                                                << 
 53         INIT_LIST_HEAD(&id->buffer_list);      << 
 54         for (id->agno = nagcount - 1;          << 
 55              id->agno >= oagcount;             << 
 56              id->agno--, delta -= id->agsize)  << 
 57                                                << 
 58                 if (id->agno == nagcount - 1)  << 
 59                         id->agsize = nb - (id- << 
 60                                         (xfs_r << 
 61                 else                           << 
 62                         id->agsize = mp->m_sb. << 
 63                                                << 
 64                 error = xfs_ag_init_headers(mp << 
 65                 if (error) {                   << 
 66                         xfs_buf_delwri_cancel( << 
 67                         return error;          << 
 68                 }                              << 
 69         }                                      << 
 70                                                << 
 71         error = xfs_buf_delwri_submit(&id->buf << 
 72         if (error)                             << 
 73                 return error;                  << 
 74                                                << 
 75         if (delta) {                           << 
 76                 *lastag_extended = true;       << 
 77                 error = xfs_ag_extend_space(la << 
 78         }                                      << 
 79         return error;                          << 
 80 }                                              << 
 81                                                    26 
 82 /*                                                 27 /*
 83  * growfs operations                               28  * growfs operations
 84  */                                                29  */
 85 static int                                         30 static int
 86 xfs_growfs_data_private(                           31 xfs_growfs_data_private(
 87         struct xfs_mount        *mp,           !!  32         xfs_mount_t             *mp,            /* mount point for filesystem */
 88         struct xfs_growfs_data  *in)           !!  33         xfs_growfs_data_t       *in)            /* growfs data input struct */
 89 {                                                  34 {
 90         xfs_agnumber_t          oagcount = mp- !!  35         xfs_buf_t               *bp;
 91         struct xfs_buf          *bp;           << 
 92         int                     error;             36         int                     error;
 93         xfs_agnumber_t          nagcount;          37         xfs_agnumber_t          nagcount;
 94         xfs_agnumber_t          nagimax = 0;       38         xfs_agnumber_t          nagimax = 0;
 95         xfs_rfsblock_t          nb, nb_div, nb !!  39         xfs_rfsblock_t          nb, nb_mod;
 96         int64_t                 delta;         !!  40         xfs_rfsblock_t          new;
 97         bool                    lastag_extende !!  41         xfs_agnumber_t          oagcount;
 98         struct xfs_trans        *tp;           !!  42         xfs_trans_t             *tp;
 99         struct aghdr_init_data  id = {};           43         struct aghdr_init_data  id = {};
100         struct xfs_perag        *last_pag;     << 
101                                                    44 
102         nb = in->newblocks;                        45         nb = in->newblocks;
103         error = xfs_sb_validate_fsb_count(&mp- !!  46         if (nb < mp->m_sb.sb_dblocks)
104         if (error)                             !!  47                 return -EINVAL;
                                                   >>  48         if ((error = xfs_sb_validate_fsb_count(&mp->m_sb, nb)))
105                 return error;                      49                 return error;
106                                                !!  50         error = xfs_buf_read_uncached(mp->m_ddev_targp,
107         if (nb > mp->m_sb.sb_dblocks) {        << 
108                 error = xfs_buf_read_uncached( << 
109                                 XFS_FSB_TO_BB(     51                                 XFS_FSB_TO_BB(mp, nb) - XFS_FSS_TO_BB(mp, 1),
110                                 XFS_FSS_TO_BB(     52                                 XFS_FSS_TO_BB(mp, 1), 0, &bp, NULL);
                                                   >>  53         if (error)
                                                   >>  54                 return error;
                                                   >>  55         xfs_buf_relse(bp);
                                                   >>  56 
                                                   >>  57         new = nb;       /* use new as a temporary here */
                                                   >>  58         nb_mod = do_div(new, mp->m_sb.sb_agblocks);
                                                   >>  59         nagcount = new + (nb_mod != 0);
                                                   >>  60         if (nb_mod && nb_mod < XFS_MIN_AG_BLOCKS) {
                                                   >>  61                 nagcount--;
                                                   >>  62                 nb = (xfs_rfsblock_t)nagcount * mp->m_sb.sb_agblocks;
                                                   >>  63                 if (nb < mp->m_sb.sb_dblocks)
                                                   >>  64                         return -EINVAL;
                                                   >>  65         }
                                                   >>  66         new = nb - mp->m_sb.sb_dblocks;
                                                   >>  67         oagcount = mp->m_sb.sb_agcount;
                                                   >>  68 
                                                   >>  69         /* allocate the new per-ag structures */
                                                   >>  70         if (nagcount > oagcount) {
                                                   >>  71                 error = xfs_initialize_perag(mp, nagcount, &nagimax);
111                 if (error)                         72                 if (error)
112                         return error;              73                         return error;
113                 xfs_buf_relse(bp);             << 
114         }                                          74         }
115                                                    75 
116         nb_div = nb;                           !!  76         error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growdata,
117         nb_mod = do_div(nb_div, mp->m_sb.sb_ag !!  77                         XFS_GROWFS_SPACE_RES(mp), 0, XFS_TRANS_RESERVE, &tp);
118         if (nb_mod && nb_mod >= XFS_MIN_AG_BLO !!  78         if (error)
119                 nb_div++;                      !!  79                 return error;
120         else if (nb_mod)                       << 
121                 nb = nb_div * mp->m_sb.sb_agbl << 
122                                                    80 
123         if (nb_div > XFS_MAX_AGNUMBER + 1) {   << 
124                 nb_div = XFS_MAX_AGNUMBER + 1; << 
125                 nb = nb_div * mp->m_sb.sb_agbl << 
126         }                                      << 
127         nagcount = nb_div;                     << 
128         delta = nb - mp->m_sb.sb_dblocks;      << 
129         /*                                         81         /*
130          * Reject filesystems with a single AG !!  82          * Write new AG headers to disk. Non-transactional, but need to be
131          * supported, and reject a shrink oper !!  83          * written and completed prior to the growfs transaction being logged.
132          * filesystem to become unsupported.   !!  84          * To do this, we use a delayed write buffer list and wait for
                                                   >>  85          * submission and IO completion of the list as a whole. This allows the
                                                   >>  86          * IO subsystem to merge all the AG headers in a single AG into a single
                                                   >>  87          * IO and hide most of the latency of the IO from us.
                                                   >>  88          *
                                                   >>  89          * This also means that if we get an error whilst building the buffer
                                                   >>  90          * list to write, we can cancel the entire list without having written
                                                   >>  91          * anything.
133          */                                        92          */
134         if (delta < 0 && nagcount < 2)         !!  93         INIT_LIST_HEAD(&id.buffer_list);
135                 return -EINVAL;                !!  94         for (id.agno = nagcount - 1;
136                                                !!  95              id.agno >= oagcount;
137         /* No work to do */                    !!  96              id.agno--, new -= id.agsize) {
138         if (delta == 0)                        !!  97 
139                 return 0;                      !!  98                 if (id.agno == nagcount - 1)
140                                                !!  99                         id.agsize = nb -
141         /* TODO: shrinking the entire AGs hasn !! 100                                 (id.agno * (xfs_rfsblock_t)mp->m_sb.sb_agblocks);
142         if (nagcount < oagcount)               !! 101                 else
143                 return -EINVAL;                !! 102                         id.agsize = mp->m_sb.sb_agblocks;
144                                                << 
145         /* allocate the new per-ag structures  << 
146         error = xfs_initialize_perag(mp, oagco << 
147         if (error)                             << 
148                 return error;                  << 
149                                                   103 
150         if (delta > 0)                         !! 104                 error = xfs_ag_init_headers(mp, &id);
151                 error = xfs_trans_alloc(mp, &M !! 105                 if (error) {
152                                 XFS_GROWFS_SPA !! 106                         xfs_buf_delwri_cancel(&id.buffer_list);
153                                 &tp);          !! 107                         goto out_trans_cancel;
154         else                                   !! 108                 }
155                 error = xfs_trans_alloc(mp, &M !! 109         }
156                                 0, &tp);       !! 110         error = xfs_buf_delwri_submit(&id.buffer_list);
157         if (error)                                111         if (error)
158                 goto out_free_unused_perag;    !! 112                 goto out_trans_cancel;
159                                                   113 
160         last_pag = xfs_perag_get(mp, oagcount  !! 114         xfs_trans_agblocks_delta(tp, id.nfree);
161         if (delta > 0) {                       << 
162                 error = xfs_resizefs_init_new_ << 
163                                 delta, last_pa << 
164         } else {                               << 
165                 xfs_warn_mount(mp, XFS_OPSTATE << 
166         "EXPERIMENTAL online shrink feature in << 
167                                                   115 
168                 error = xfs_ag_shrink_space(la !! 116         /* If there are new blocks in the old last AG, extend it. */
                                                   >> 117         if (new) {
                                                   >> 118                 error = xfs_ag_extend_space(mp, tp, &id, new);
                                                   >> 119                 if (error)
                                                   >> 120                         goto out_trans_cancel;
169         }                                         121         }
170         xfs_perag_put(last_pag);               << 
171         if (error)                             << 
172                 goto out_trans_cancel;         << 
173                                                   122 
174         /*                                        123         /*
175          * Update changed superblock fields tr    124          * Update changed superblock fields transactionally. These are not
176          * seen by the rest of the world until    125          * seen by the rest of the world until the transaction commit applies
177          * them atomically to the superblock.     126          * them atomically to the superblock.
178          */                                       127          */
179         if (nagcount > oagcount)                  128         if (nagcount > oagcount)
180                 xfs_trans_mod_sb(tp, XFS_TRANS    129                 xfs_trans_mod_sb(tp, XFS_TRANS_SB_AGCOUNT, nagcount - oagcount);
181         if (delta)                             !! 130         if (nb > mp->m_sb.sb_dblocks)
182                 xfs_trans_mod_sb(tp, XFS_TRANS !! 131                 xfs_trans_mod_sb(tp, XFS_TRANS_SB_DBLOCKS,
                                                   >> 132                                  nb - mp->m_sb.sb_dblocks);
183         if (id.nfree)                             133         if (id.nfree)
184                 xfs_trans_mod_sb(tp, XFS_TRANS    134                 xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, id.nfree);
185                                                << 
186         /*                                     << 
187          * Sync sb counters now to reflect the << 
188          * particularly important for shrink b << 
189          * will fail if sb_fdblocks is ever la << 
190          */                                    << 
191         if (xfs_has_lazysbcount(mp))           << 
192                 xfs_log_sb(tp);                << 
193                                                << 
194         xfs_trans_set_sync(tp);                   135         xfs_trans_set_sync(tp);
195         error = xfs_trans_commit(tp);             136         error = xfs_trans_commit(tp);
196         if (error)                                137         if (error)
197                 return error;                     138                 return error;
198                                                   139 
199         /* New allocation groups fully initial    140         /* New allocation groups fully initialized, so update mount struct */
200         if (nagimax)                              141         if (nagimax)
201                 mp->m_maxagi = nagimax;           142                 mp->m_maxagi = nagimax;
202         xfs_set_low_space_thresholds(mp);         143         xfs_set_low_space_thresholds(mp);
203         mp->m_alloc_set_aside = xfs_alloc_set_    144         mp->m_alloc_set_aside = xfs_alloc_set_aside(mp);
204                                                   145 
205         if (delta > 0) {                       !! 146         /*
206                 /*                             !! 147          * If we expanded the last AG, free the per-AG reservation
207                  * If we expanded the last AG, !! 148          * so we can reinitialize it with the new size.
208                  * so we can reinitialize it w !! 149          */
209                  */                            !! 150         if (new) {
210                 if (lastag_extended) {         !! 151                 struct xfs_perag        *pag;
211                         struct xfs_perag       << 
212                                                   152 
213                         pag = xfs_perag_get(mp !! 153                 pag = xfs_perag_get(mp, id.agno);
214                         xfs_ag_resv_free(pag); !! 154                 error = xfs_ag_resv_free(pag);
215                         xfs_perag_put(pag);    !! 155                 xfs_perag_put(pag);
216                 }                              !! 156                 if (error)
217                 /*                             !! 157                         return error;
218                  * Reserve AG metadata blocks. << 
219                  * was a growfs failure, just  << 
220                  * new user data after the gro << 
221                  */                            << 
222                 error = xfs_fs_reserve_ag_bloc << 
223                 if (error == -ENOSPC)          << 
224                         error = 0;             << 
225         }                                         158         }
                                                   >> 159 
                                                   >> 160         /*
                                                   >> 161          * Reserve AG metadata blocks. ENOSPC here does not mean there was a
                                                   >> 162          * growfs failure, just that there still isn't space for new user data
                                                   >> 163          * after the grow has been run.
                                                   >> 164          */
                                                   >> 165         error = xfs_fs_reserve_ag_blocks(mp);
                                                   >> 166         if (error == -ENOSPC)
                                                   >> 167                 error = 0;
226         return error;                             168         return error;
227                                                   169 
228 out_trans_cancel:                                 170 out_trans_cancel:
229         xfs_trans_cancel(tp);                     171         xfs_trans_cancel(tp);
230 out_free_unused_perag:                         << 
231         if (nagcount > oagcount)               << 
232                 xfs_free_perag_range(mp, oagco << 
233         return error;                             172         return error;
234 }                                                 173 }
235                                                   174 
236 static int                                        175 static int
237 xfs_growfs_log_private(                           176 xfs_growfs_log_private(
238         struct xfs_mount        *mp,    /* mou !! 177         xfs_mount_t             *mp,    /* mount point for filesystem */
239         struct xfs_growfs_log   *in)    /* gro !! 178         xfs_growfs_log_t        *in)    /* growfs log input struct */
240 {                                                 179 {
241         xfs_extlen_t            nb;               180         xfs_extlen_t            nb;
242                                                   181 
243         nb = in->newblocks;                       182         nb = in->newblocks;
244         if (nb < XFS_MIN_LOG_BLOCKS || nb < XF    183         if (nb < XFS_MIN_LOG_BLOCKS || nb < XFS_B_TO_FSB(mp, XFS_MIN_LOG_BYTES))
245                 return -EINVAL;                   184                 return -EINVAL;
246         if (nb == mp->m_sb.sb_logblocks &&        185         if (nb == mp->m_sb.sb_logblocks &&
247             in->isint == (mp->m_sb.sb_logstart    186             in->isint == (mp->m_sb.sb_logstart != 0))
248                 return -EINVAL;                   187                 return -EINVAL;
249         /*                                        188         /*
250          * Moving the log is hard, need new in    189          * Moving the log is hard, need new interfaces to sync
251          * the log first, hold off all activit    190          * the log first, hold off all activity while moving it.
252          * Can have shorter or longer log in t    191          * Can have shorter or longer log in the same space,
253          * or transform internal to external l    192          * or transform internal to external log or vice versa.
254          */                                       193          */
255         return -ENOSYS;                           194         return -ENOSYS;
256 }                                                 195 }
257                                                   196 
258 static int                                        197 static int
259 xfs_growfs_imaxpct(                               198 xfs_growfs_imaxpct(
260         struct xfs_mount        *mp,              199         struct xfs_mount        *mp,
261         __u32                   imaxpct)          200         __u32                   imaxpct)
262 {                                                 201 {
263         struct xfs_trans        *tp;              202         struct xfs_trans        *tp;
264         int                     dpct;             203         int                     dpct;
265         int                     error;            204         int                     error;
266                                                   205 
267         if (imaxpct > 100)                        206         if (imaxpct > 100)
268                 return -EINVAL;                   207                 return -EINVAL;
269                                                   208 
270         error = xfs_trans_alloc(mp, &M_RES(mp)    209         error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growdata,
271                         XFS_GROWFS_SPACE_RES(m    210                         XFS_GROWFS_SPACE_RES(mp), 0, XFS_TRANS_RESERVE, &tp);
272         if (error)                                211         if (error)
273                 return error;                     212                 return error;
274                                                   213 
275         dpct = imaxpct - mp->m_sb.sb_imax_pct;    214         dpct = imaxpct - mp->m_sb.sb_imax_pct;
276         xfs_trans_mod_sb(tp, XFS_TRANS_SB_IMAX    215         xfs_trans_mod_sb(tp, XFS_TRANS_SB_IMAXPCT, dpct);
277         xfs_trans_set_sync(tp);                   216         xfs_trans_set_sync(tp);
278         return xfs_trans_commit(tp);              217         return xfs_trans_commit(tp);
279 }                                                 218 }
280                                                   219 
281 /*                                                220 /*
282  * protected versions of growfs function acqui    221  * protected versions of growfs function acquire and release locks on the mount
283  * point - exported through ioctls: XFS_IOC_FS    222  * point - exported through ioctls: XFS_IOC_FSGROWFSDATA, XFS_IOC_FSGROWFSLOG,
284  * XFS_IOC_FSGROWFSRT                             223  * XFS_IOC_FSGROWFSRT
285  */                                               224  */
286 int                                               225 int
287 xfs_growfs_data(                                  226 xfs_growfs_data(
288         struct xfs_mount        *mp,              227         struct xfs_mount        *mp,
289         struct xfs_growfs_data  *in)              228         struct xfs_growfs_data  *in)
290 {                                                 229 {
291         int                     error = 0;        230         int                     error = 0;
292                                                   231 
293         if (!capable(CAP_SYS_ADMIN))              232         if (!capable(CAP_SYS_ADMIN))
294                 return -EPERM;                    233                 return -EPERM;
295         if (!mutex_trylock(&mp->m_growlock))      234         if (!mutex_trylock(&mp->m_growlock))
296                 return -EWOULDBLOCK;              235                 return -EWOULDBLOCK;
297                                                   236 
298         /* update imaxpct separately to the ph    237         /* update imaxpct separately to the physical grow of the filesystem */
299         if (in->imaxpct != mp->m_sb.sb_imax_pc    238         if (in->imaxpct != mp->m_sb.sb_imax_pct) {
300                 error = xfs_growfs_imaxpct(mp,    239                 error = xfs_growfs_imaxpct(mp, in->imaxpct);
301                 if (error)                        240                 if (error)
302                         goto out_error;           241                         goto out_error;
303         }                                         242         }
304                                                   243 
305         if (in->newblocks != mp->m_sb.sb_dbloc    244         if (in->newblocks != mp->m_sb.sb_dblocks) {
306                 error = xfs_growfs_data_privat    245                 error = xfs_growfs_data_private(mp, in);
307                 if (error)                        246                 if (error)
308                         goto out_error;           247                         goto out_error;
309         }                                         248         }
310                                                   249 
311         /* Post growfs calculations needed to     250         /* Post growfs calculations needed to reflect new state in operations */
312         if (mp->m_sb.sb_imax_pct) {               251         if (mp->m_sb.sb_imax_pct) {
313                 uint64_t icount = mp->m_sb.sb_    252                 uint64_t icount = mp->m_sb.sb_dblocks * mp->m_sb.sb_imax_pct;
314                 do_div(icount, 100);              253                 do_div(icount, 100);
315                 M_IGEO(mp)->maxicount = XFS_FS !! 254                 mp->m_maxicount = XFS_FSB_TO_INO(mp, icount);
316         } else                                    255         } else
317                 M_IGEO(mp)->maxicount = 0;     !! 256                 mp->m_maxicount = 0;
318                                                   257 
319         /* Update secondary superblocks now th    258         /* Update secondary superblocks now the physical grow has completed */
320         error = xfs_update_secondary_sbs(mp);     259         error = xfs_update_secondary_sbs(mp);
321                                                   260 
322 out_error:                                        261 out_error:
323         /*                                        262         /*
324          * Increment the generation unconditio    263          * Increment the generation unconditionally, the error could be from
325          * updating the secondary superblocks,    264          * updating the secondary superblocks, in which case the new size
326          * is live already.                       265          * is live already.
327          */                                       266          */
328         mp->m_generation++;                       267         mp->m_generation++;
329         mutex_unlock(&mp->m_growlock);            268         mutex_unlock(&mp->m_growlock);
330         return error;                             269         return error;
331 }                                                 270 }
332                                                   271 
333 int                                               272 int
334 xfs_growfs_log(                                   273 xfs_growfs_log(
335         xfs_mount_t             *mp,              274         xfs_mount_t             *mp,
336         struct xfs_growfs_log   *in)           !! 275         xfs_growfs_log_t        *in)
337 {                                                 276 {
338         int error;                                277         int error;
339                                                   278 
340         if (!capable(CAP_SYS_ADMIN))              279         if (!capable(CAP_SYS_ADMIN))
341                 return -EPERM;                    280                 return -EPERM;
342         if (!mutex_trylock(&mp->m_growlock))      281         if (!mutex_trylock(&mp->m_growlock))
343                 return -EWOULDBLOCK;              282                 return -EWOULDBLOCK;
344         error = xfs_growfs_log_private(mp, in)    283         error = xfs_growfs_log_private(mp, in);
345         mutex_unlock(&mp->m_growlock);            284         mutex_unlock(&mp->m_growlock);
346         return error;                             285         return error;
347 }                                                 286 }
348                                                   287 
349 /*                                                288 /*
                                                   >> 289  * exported through ioctl XFS_IOC_FSCOUNTS
                                                   >> 290  */
                                                   >> 291 
                                                   >> 292 int
                                                   >> 293 xfs_fs_counts(
                                                   >> 294         xfs_mount_t             *mp,
                                                   >> 295         xfs_fsop_counts_t       *cnt)
                                                   >> 296 {
                                                   >> 297         cnt->allocino = percpu_counter_read_positive(&mp->m_icount);
                                                   >> 298         cnt->freeino = percpu_counter_read_positive(&mp->m_ifree);
                                                   >> 299         cnt->freedata = percpu_counter_read_positive(&mp->m_fdblocks) -
                                                   >> 300                                                 mp->m_alloc_set_aside;
                                                   >> 301 
                                                   >> 302         spin_lock(&mp->m_sb_lock);
                                                   >> 303         cnt->freertx = mp->m_sb.sb_frextents;
                                                   >> 304         spin_unlock(&mp->m_sb_lock);
                                                   >> 305         return 0;
                                                   >> 306 }
                                                   >> 307 
                                                   >> 308 /*
                                                   >> 309  * exported through ioctl XFS_IOC_SET_RESBLKS & XFS_IOC_GET_RESBLKS
                                                   >> 310  *
                                                   >> 311  * xfs_reserve_blocks is called to set m_resblks
                                                   >> 312  * in the in-core mount table. The number of unused reserved blocks
                                                   >> 313  * is kept in m_resblks_avail.
                                                   >> 314  *
350  * Reserve the requested number of blocks if a    315  * Reserve the requested number of blocks if available. Otherwise return
351  * as many as possible to satisfy the request.    316  * as many as possible to satisfy the request. The actual number
352  * reserved are returned in outval.            !! 317  * reserved are returned in outval
                                                   >> 318  *
                                                   >> 319  * A null inval pointer indicates that only the current reserved blocks
                                                   >> 320  * available  should  be returned no settings are changed.
353  */                                               321  */
                                                   >> 322 
354 int                                               323 int
355 xfs_reserve_blocks(                               324 xfs_reserve_blocks(
356         struct xfs_mount        *mp,           !! 325         xfs_mount_t             *mp,
357         uint64_t                request)       !! 326         uint64_t              *inval,
                                                   >> 327         xfs_fsop_resblks_t      *outval)
358 {                                                 328 {
359         int64_t                 lcounter, delt    329         int64_t                 lcounter, delta;
360         int64_t                 fdblks_delta =    330         int64_t                 fdblks_delta = 0;
                                                   >> 331         uint64_t                request;
361         int64_t                 free;             332         int64_t                 free;
362         int                     error = 0;        333         int                     error = 0;
363                                                   334 
                                                   >> 335         /* If inval is null, report current values and return */
                                                   >> 336         if (inval == (uint64_t *)NULL) {
                                                   >> 337                 if (!outval)
                                                   >> 338                         return -EINVAL;
                                                   >> 339                 outval->resblks = mp->m_resblks;
                                                   >> 340                 outval->resblks_avail = mp->m_resblks_avail;
                                                   >> 341                 return 0;
                                                   >> 342         }
                                                   >> 343 
                                                   >> 344         request = *inval;
                                                   >> 345 
364         /*                                        346         /*
365          * With per-cpu counters, this becomes    347          * With per-cpu counters, this becomes an interesting problem. we need
366          * to work out if we are freeing or al    348          * to work out if we are freeing or allocation blocks first, then we can
367          * do the modification as necessary.      349          * do the modification as necessary.
368          *                                        350          *
369          * We do this under the m_sb_lock so t    351          * We do this under the m_sb_lock so that if we are near ENOSPC, we will
370          * hold out any changes while we work     352          * hold out any changes while we work out what to do. This means that
371          * the amount of free space can change    353          * the amount of free space can change while we do this, so we need to
372          * retry if we end up trying to reserv    354          * retry if we end up trying to reserve more space than is available.
373          */                                       355          */
374         spin_lock(&mp->m_sb_lock);                356         spin_lock(&mp->m_sb_lock);
375                                                   357 
376         /*                                        358         /*
377          * If our previous reservation was lar    359          * If our previous reservation was larger than the current value,
378          * then move any unused blocks back to    360          * then move any unused blocks back to the free pool. Modify the resblks
379          * counters directly since we shouldn'    361          * counters directly since we shouldn't have any problems unreserving
380          * space.                                 362          * space.
381          */                                       363          */
382         if (mp->m_resblks > request) {            364         if (mp->m_resblks > request) {
383                 lcounter = mp->m_resblks_avail    365                 lcounter = mp->m_resblks_avail - request;
384                 if (lcounter > 0) {            !! 366                 if (lcounter  > 0) {            /* release unused blocks */
385                         fdblks_delta = lcounte    367                         fdblks_delta = lcounter;
386                         mp->m_resblks_avail -=    368                         mp->m_resblks_avail -= lcounter;
387                 }                                 369                 }
388                 mp->m_resblks = request;          370                 mp->m_resblks = request;
389                 if (fdblks_delta) {               371                 if (fdblks_delta) {
390                         spin_unlock(&mp->m_sb_    372                         spin_unlock(&mp->m_sb_lock);
391                         xfs_add_fdblocks(mp, f !! 373                         error = xfs_mod_fdblocks(mp, fdblks_delta, 0);
392                         spin_lock(&mp->m_sb_lo    374                         spin_lock(&mp->m_sb_lock);
393                 }                                 375                 }
394                                                   376 
395                 goto out;                         377                 goto out;
396         }                                         378         }
397                                                   379 
398         /*                                        380         /*
399          * If the request is larger than the c    381          * If the request is larger than the current reservation, reserve the
400          * blocks before we update the reserve    382          * blocks before we update the reserve counters. Sample m_fdblocks and
401          * perform a partial reservation if th    383          * perform a partial reservation if the request exceeds free space.
402          *                                     !! 384          */
403          * The code below estimates how many b !! 385         error = -ENOSPC;
404          * fdblocks to stash in the reserve po !! 386         do {
405          * race since fdblocks updates are not !! 387                 free = percpu_counter_sum(&mp->m_fdblocks) -
406          * m_sb_lock.  Set the reserve size ev !! 388                                                 mp->m_alloc_set_aside;
407          * space to fill it because mod_fdbloc !! 389                 if (free <= 0)
408          * reserve when it can.                !! 390                         break;
409          */                                    !! 391 
410         free = percpu_counter_sum(&mp->m_fdblo !! 392                 delta = request - mp->m_resblks;
411                                                !! 393                 lcounter = free - delta;
412         delta = request - mp->m_resblks;       !! 394                 if (lcounter < 0)
413         mp->m_resblks = request;               !! 395                         /* We can't satisfy the request, just get what we can */
414         if (delta > 0 && free > 0) {           !! 396                         fdblks_delta = free;
                                                   >> 397                 else
                                                   >> 398                         fdblks_delta = delta;
                                                   >> 399 
415                 /*                                400                 /*
416                  * We'll either succeed in get    401                  * We'll either succeed in getting space from the free block
417                  * count or we'll get an ENOSP !! 402                  * count or we'll get an ENOSPC. If we get a ENOSPC, it means
418                  * here - we don't want to res !! 403                  * things changed while we were calculating fdblks_delta and so
419                  * from the reserve.           !! 404                  * we should try again to see if there is anything left to
                                                   >> 405                  * reserve.
420                  *                                406                  *
421                  * The desired reserve size ca !! 407                  * Don't set the reserved flag here - we don't want to reserve
422                  * Use mod_fdblocks to put the !! 408                  * the extra reserve blocks from the reserve.....
423                  * fdblocks as appropriate.    << 
424                  */                               409                  */
425                 fdblks_delta = min(free, delta << 
426                 spin_unlock(&mp->m_sb_lock);      410                 spin_unlock(&mp->m_sb_lock);
427                 error = xfs_dec_fdblocks(mp, f !! 411                 error = xfs_mod_fdblocks(mp, -fdblks_delta, 0);
428                 if (!error)                    << 
429                         xfs_add_fdblocks(mp, f << 
430                 spin_lock(&mp->m_sb_lock);        412                 spin_lock(&mp->m_sb_lock);
                                                   >> 413         } while (error == -ENOSPC);
                                                   >> 414 
                                                   >> 415         /*
                                                   >> 416          * Update the reserve counters if blocks have been successfully
                                                   >> 417          * allocated.
                                                   >> 418          */
                                                   >> 419         if (!error && fdblks_delta) {
                                                   >> 420                 mp->m_resblks += fdblks_delta;
                                                   >> 421                 mp->m_resblks_avail += fdblks_delta;
431         }                                         422         }
                                                   >> 423 
432 out:                                              424 out:
                                                   >> 425         if (outval) {
                                                   >> 426                 outval->resblks = mp->m_resblks;
                                                   >> 427                 outval->resblks_avail = mp->m_resblks_avail;
                                                   >> 428         }
                                                   >> 429 
433         spin_unlock(&mp->m_sb_lock);              430         spin_unlock(&mp->m_sb_lock);
434         return error;                             431         return error;
435 }                                                 432 }
436                                                   433 
437 int                                               434 int
438 xfs_fs_goingdown(                                 435 xfs_fs_goingdown(
439         xfs_mount_t     *mp,                      436         xfs_mount_t     *mp,
440         uint32_t        inflags)                  437         uint32_t        inflags)
441 {                                                 438 {
442         switch (inflags) {                        439         switch (inflags) {
443         case XFS_FSOP_GOING_FLAGS_DEFAULT: {      440         case XFS_FSOP_GOING_FLAGS_DEFAULT: {
444                 if (!bdev_freeze(mp->m_super-> !! 441                 struct super_block *sb = freeze_bdev(mp->m_super->s_bdev);
                                                   >> 442 
                                                   >> 443                 if (sb && !IS_ERR(sb)) {
445                         xfs_force_shutdown(mp,    444                         xfs_force_shutdown(mp, SHUTDOWN_FORCE_UMOUNT);
446                         bdev_thaw(mp->m_super- !! 445                         thaw_bdev(sb->s_bdev, sb);
447                 }                                 446                 }
                                                   >> 447 
448                 break;                            448                 break;
449         }                                         449         }
450         case XFS_FSOP_GOING_FLAGS_LOGFLUSH:       450         case XFS_FSOP_GOING_FLAGS_LOGFLUSH:
451                 xfs_force_shutdown(mp, SHUTDOW    451                 xfs_force_shutdown(mp, SHUTDOWN_FORCE_UMOUNT);
452                 break;                            452                 break;
453         case XFS_FSOP_GOING_FLAGS_NOLOGFLUSH:     453         case XFS_FSOP_GOING_FLAGS_NOLOGFLUSH:
454                 xfs_force_shutdown(mp,            454                 xfs_force_shutdown(mp,
455                                 SHUTDOWN_FORCE    455                                 SHUTDOWN_FORCE_UMOUNT | SHUTDOWN_LOG_IO_ERROR);
456                 break;                            456                 break;
457         default:                                  457         default:
458                 return -EINVAL;                   458                 return -EINVAL;
459         }                                         459         }
460                                                   460 
461         return 0;                                 461         return 0;
462 }                                                 462 }
463                                                   463 
464 /*                                                464 /*
465  * Force a shutdown of the filesystem instantl    465  * Force a shutdown of the filesystem instantly while keeping the filesystem
466  * consistent. We don't do an unmount here; ju    466  * consistent. We don't do an unmount here; just shutdown the shop, make sure
467  * that absolutely nothing persistent happens     467  * that absolutely nothing persistent happens to this filesystem after this
468  * point.                                         468  * point.
469  *                                             << 
470  * The shutdown state change is atomic, result << 
471  * first shutdown call processing the shutdown << 
472  * log once as it requires, and we don't spam  << 
473  * shutdowns race to set the shutdown flags.   << 
474  */                                               469  */
475 void                                              470 void
476 xfs_do_force_shutdown(                            471 xfs_do_force_shutdown(
477         struct xfs_mount *mp,                     472         struct xfs_mount *mp,
478         uint32_t        flags,                 !! 473         int             flags,
479         char            *fname,                   474         char            *fname,
480         int             lnnum)                    475         int             lnnum)
481 {                                                 476 {
482         int             tag;                   !! 477         bool            logerror = flags & SHUTDOWN_LOG_IO_ERROR;
483         const char      *why;                  !! 478 
                                                   >> 479         /*
                                                   >> 480          * No need to duplicate efforts.
                                                   >> 481          */
                                                   >> 482         if (XFS_FORCED_SHUTDOWN(mp) && !logerror)
                                                   >> 483                 return;
484                                                   484 
                                                   >> 485         /*
                                                   >> 486          * This flags XFS_MOUNT_FS_SHUTDOWN, makes sure that we don't
                                                   >> 487          * queue up anybody new on the log reservations, and wakes up
                                                   >> 488          * everybody who's sleeping on log reservations to tell them
                                                   >> 489          * the bad news.
                                                   >> 490          */
                                                   >> 491         if (xfs_log_force_umount(mp, logerror))
                                                   >> 492                 return;
485                                                   493 
486         if (xfs_set_shutdown(mp)) {            !! 494         if (flags & SHUTDOWN_FORCE_UMOUNT) {
487                 xlog_shutdown_wait(mp->m_log); !! 495                 xfs_alert(mp,
                                                   >> 496 "User initiated shutdown received. Shutting down filesystem");
488                 return;                           497                 return;
489         }                                         498         }
490         if (mp->m_sb_bp)                       << 
491                 mp->m_sb_bp->b_flags |= XBF_DO << 
492                                                   499 
493         if (flags & SHUTDOWN_FORCE_UMOUNT)     !! 500         xfs_notice(mp,
494                 xfs_alert(mp, "User initiated  !! 501 "%s(0x%x) called from line %d of file %s. Return address = "PTR_FMT,
                                                   >> 502                 __func__, flags, lnnum, fname, __return_address);
                                                   >> 503 
                                                   >> 504         if (flags & SHUTDOWN_CORRUPT_INCORE) {
                                                   >> 505                 xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_CORRUPT,
                                                   >> 506 "Corruption of in-memory data detected.  Shutting down filesystem");
                                                   >> 507                 if (XFS_ERRLEVEL_HIGH <= xfs_error_level)
                                                   >> 508                         xfs_stack_trace();
                                                   >> 509         } else if (logerror) {
                                                   >> 510                 xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_LOGERROR,
                                                   >> 511                         "Log I/O Error Detected. Shutting down filesystem");
                                                   >> 512         } else if (flags & SHUTDOWN_DEVICE_REQ) {
                                                   >> 513                 xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_IOERROR,
                                                   >> 514                         "All device paths lost. Shutting down filesystem");
                                                   >> 515         } else if (!(flags & SHUTDOWN_REMOTE_REQ)) {
                                                   >> 516                 xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_IOERROR,
                                                   >> 517                         "I/O Error Detected. Shutting down filesystem");
                                                   >> 518         }
495                                                   519 
496         if (xlog_force_shutdown(mp->m_log, fla << 
497                 tag = XFS_PTAG_SHUTDOWN_LOGERR << 
498                 why = "Log I/O Error";         << 
499         } else if (flags & SHUTDOWN_CORRUPT_IN << 
500                 tag = XFS_PTAG_SHUTDOWN_CORRUP << 
501                 why = "Corruption of in-memory << 
502         } else if (flags & SHUTDOWN_CORRUPT_ON << 
503                 tag = XFS_PTAG_SHUTDOWN_CORRUP << 
504                 why = "Corruption of on-disk m << 
505         } else if (flags & SHUTDOWN_DEVICE_REM << 
506                 tag = XFS_PTAG_SHUTDOWN_IOERRO << 
507                 why = "Block device removal";  << 
508         } else {                               << 
509                 tag = XFS_PTAG_SHUTDOWN_IOERRO << 
510                 why = "Metadata I/O Error";    << 
511         }                                      << 
512                                                << 
513         trace_xfs_force_shutdown(mp, tag, flag << 
514                                                << 
515         xfs_alert_tag(mp, tag,                 << 
516 "%s (0x%x) detected at %pS (%s:%d).  Shutting  << 
517                         why, flags, __return_a << 
518         xfs_alert(mp,                             520         xfs_alert(mp,
519                 "Please unmount the filesystem    521                 "Please unmount the filesystem and rectify the problem(s)");
520         if (xfs_error_level >= XFS_ERRLEVEL_HI << 
521                 xfs_stack_trace();             << 
522 }                                                 522 }
523                                                   523 
524 /*                                                524 /*
525  * Reserve free space for per-AG metadata.        525  * Reserve free space for per-AG metadata.
526  */                                               526  */
527 int                                               527 int
528 xfs_fs_reserve_ag_blocks(                         528 xfs_fs_reserve_ag_blocks(
529         struct xfs_mount        *mp)              529         struct xfs_mount        *mp)
530 {                                                 530 {
531         xfs_agnumber_t          agno;             531         xfs_agnumber_t          agno;
532         struct xfs_perag        *pag;             532         struct xfs_perag        *pag;
533         int                     error = 0;        533         int                     error = 0;
534         int                     err2;             534         int                     err2;
535                                                   535 
536         mp->m_finobt_nores = false;            !! 536         for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) {
537         for_each_perag(mp, agno, pag) {        !! 537                 pag = xfs_perag_get(mp, agno);
538                 err2 = xfs_ag_resv_init(pag, N    538                 err2 = xfs_ag_resv_init(pag, NULL);
                                                   >> 539                 xfs_perag_put(pag);
539                 if (err2 && !error)               540                 if (err2 && !error)
540                         error = err2;             541                         error = err2;
541         }                                         542         }
542                                                   543 
543         if (error && error != -ENOSPC) {          544         if (error && error != -ENOSPC) {
544                 xfs_warn(mp,                      545                 xfs_warn(mp,
545         "Error %d reserving per-AG metadata re    546         "Error %d reserving per-AG metadata reserve pool.", error);
546                 xfs_force_shutdown(mp, SHUTDOW    547                 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
547         }                                         548         }
548                                                   549 
549         return error;                             550         return error;
550 }                                                 551 }
551                                                   552 
552 /*                                                553 /*
553  * Free space reserved for per-AG metadata.       554  * Free space reserved for per-AG metadata.
554  */                                               555  */
555 void                                           !! 556 int
556 xfs_fs_unreserve_ag_blocks(                       557 xfs_fs_unreserve_ag_blocks(
557         struct xfs_mount        *mp)              558         struct xfs_mount        *mp)
558 {                                                 559 {
559         xfs_agnumber_t          agno;             560         xfs_agnumber_t          agno;
560         struct xfs_perag        *pag;             561         struct xfs_perag        *pag;
                                                   >> 562         int                     error = 0;
                                                   >> 563         int                     err2;
561                                                   564 
562         for_each_perag(mp, agno, pag)          !! 565         for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) {
563                 xfs_ag_resv_free(pag);         !! 566                 pag = xfs_perag_get(mp, agno);
                                                   >> 567                 err2 = xfs_ag_resv_free(pag);
                                                   >> 568                 xfs_perag_put(pag);
                                                   >> 569                 if (err2 && !error)
                                                   >> 570                         error = err2;
                                                   >> 571         }
                                                   >> 572 
                                                   >> 573         if (error)
                                                   >> 574                 xfs_warn(mp,
                                                   >> 575         "Error %d freeing per-AG metadata reserve pool.", error);
                                                   >> 576 
                                                   >> 577         return error;
564 }                                                 578 }
565                                                   579 

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