~ [ 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.12.19)


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

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