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

TOMOYO Linux Cross Reference
Linux/fs/btrfs/messages.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/btrfs/messages.c (Version linux-6.12-rc7) and /fs/btrfs/messages.c (Version linux-6.1.116)


  1 // SPDX-License-Identifier: GPL-2.0                 1 
  2                                                   
  3 #include "fs.h"                                   
  4 #include "messages.h"                             
  5 #include "discard.h"                              
  6 #include "super.h"                                
  7                                                   
  8 #ifdef CONFIG_PRINTK                              
  9                                                   
 10 #define STATE_STRING_PREFACE    " state "         
 11 #define STATE_STRING_BUF_LEN    (sizeof(STATE_    
 12                                                   
 13 /*                                                
 14  * Characters to print to indicate error condi    
 15  * RO is not an error.                            
 16  */                                               
 17 static const char fs_state_chars[] = {            
 18         [BTRFS_FS_STATE_REMOUNTING]               
 19         [BTRFS_FS_STATE_RO]                       
 20         [BTRFS_FS_STATE_TRANS_ABORTED]            
 21         [BTRFS_FS_STATE_DEV_REPLACING]            
 22         [BTRFS_FS_STATE_DUMMY_FS_INFO]            
 23         [BTRFS_FS_STATE_NO_DATA_CSUMS]            
 24         [BTRFS_FS_STATE_SKIP_META_CSUMS]          
 25         [BTRFS_FS_STATE_LOG_CLEANUP_ERROR]        
 26 };                                                
 27                                                   
 28 static void btrfs_state_to_string(const struct    
 29 {                                                 
 30         unsigned int bit;                         
 31         bool states_printed = false;              
 32         unsigned long fs_state = READ_ONCE(inf    
 33         char *curr = buf;                         
 34                                                   
 35         memcpy(curr, STATE_STRING_PREFACE, siz    
 36         curr += sizeof(STATE_STRING_PREFACE) -    
 37                                                   
 38         if (BTRFS_FS_ERROR(info)) {               
 39                 *curr++ = 'E';                    
 40                 states_printed = true;            
 41         }                                         
 42                                                   
 43         for_each_set_bit(bit, &fs_state, sizeo    
 44                 WARN_ON_ONCE(bit >= BTRFS_FS_S    
 45                 if ((bit < BTRFS_FS_STATE_COUN    
 46                         *curr++ = fs_state_cha    
 47                         states_printed = true;    
 48                 }                                 
 49         }                                         
 50                                                   
 51         /* If no states were printed, reset th    
 52         if (!states_printed)                      
 53                 curr = buf;                       
 54                                                   
 55         *curr++ = 0;                              
 56 }                                                 
 57 #endif                                            
 58                                                   
 59 /*                                                
 60  * Generally the error codes correspond to the    
 61  * are a few special cases.                       
 62  *                                                
 63  * EUCLEAN: Any sort of corruption that we enc    
 64  *          instance will return EUCLEAN if an    
 65  *          a way that is problematic.  We wan    
 66  *          sort of corruptions.                  
 67  *                                                
 68  * EROFS: If we check BTRFS_FS_STATE_ERROR and    
 69  *        need to use EROFS for this case.  We    
 70  *        original failure, that will have bee    
 71  *        over the error.  Each subsequent err    
 72  *        of the original error should use ERO    
 73  */                                               
 74 const char * __attribute_const__ btrfs_decode_    
 75 {                                                 
 76         char *errstr = "unknown";                 
 77                                                   
 78         switch (error) {                          
 79         case -ENOENT:           /* -2 */          
 80                 errstr = "No such entry";         
 81                 break;                            
 82         case -EIO:              /* -5 */          
 83                 errstr = "IO failure";            
 84                 break;                            
 85         case -ENOMEM:           /* -12*/          
 86                 errstr = "Out of memory";         
 87                 break;                            
 88         case -EEXIST:           /* -17 */         
 89                 errstr = "Object already exist    
 90                 break;                            
 91         case -ENOSPC:           /* -28 */         
 92                 errstr = "No space left";         
 93                 break;                            
 94         case -EROFS:            /* -30 */         
 95                 errstr = "Readonly filesystem"    
 96                 break;                            
 97         case -EOPNOTSUPP:       /* -95 */         
 98                 errstr = "Operation not suppor    
 99                 break;                            
100         case -EUCLEAN:          /* -117 */        
101                 errstr = "Filesystem corrupted    
102                 break;                            
103         case -EDQUOT:           /* -122 */        
104                 errstr = "Quota exceeded";        
105                 break;                            
106         }                                         
107                                                   
108         return errstr;                            
109 }                                                 
110                                                   
111 /*                                                
112  * Decodes expected errors from the caller and    
113  * response.                                      
114  */                                               
115 __cold                                            
116 void __btrfs_handle_fs_error(struct btrfs_fs_i    
117                        unsigned int line, int     
118 {                                                 
119         struct super_block *sb = fs_info->sb;     
120 #ifdef CONFIG_PRINTK                              
121         char statestr[STATE_STRING_BUF_LEN];      
122         const char *errstr;                       
123 #endif                                            
124                                                   
125 #ifdef CONFIG_PRINTK_INDEX                        
126         printk_index_subsys_emit(                 
127                 "BTRFS: error (device %s%s) in    
128 #endif                                            
129                                                   
130         /*                                        
131          * Special case: if the error is EROFS    
132          * SB_RDONLY, then it is safe here.       
133          */                                       
134         if (error == -EROFS && sb_rdonly(sb))     
135                 return;                           
136                                                   
137 #ifdef CONFIG_PRINTK                              
138         errstr = btrfs_decode_error(error);       
139         btrfs_state_to_string(fs_info, statest    
140         if (fmt) {                                
141                 struct va_format vaf;             
142                 va_list args;                     
143                                                   
144                 va_start(args, fmt);              
145                 vaf.fmt = fmt;                    
146                 vaf.va = &args;                   
147                                                   
148                 pr_crit("BTRFS: error (device     
149                         sb->s_id, statestr, fu    
150                 va_end(args);                     
151         } else {                                  
152                 pr_crit("BTRFS: error (device     
153                         sb->s_id, statestr, fu    
154         }                                         
155 #endif                                            
156                                                   
157         /*                                        
158          * Today we only save the error info t    
159          * send it down to the disk.              
160          */                                       
161         WRITE_ONCE(fs_info->fs_error, error);     
162                                                   
163         /* Don't go through full error handlin    
164         if (!(sb->s_flags & SB_BORN))             
165                 return;                           
166                                                   
167         if (sb_rdonly(sb))                        
168                 return;                           
169                                                   
170         btrfs_discard_stop(fs_info);              
171                                                   
172         /* Handle error by forcing the filesys    
173         btrfs_set_sb_rdonly(sb);                  
174         btrfs_info(fs_info, "forced readonly")    
175         /*                                        
176          * Note that a running device replace     
177          * although there is no way to update     
178          * risk of a deadlock, therefore the c    
179          * penalty is that some I/O remains ac    
180          * completes. The next time when the f    
181          * again, the device replace operation    
182          */                                       
183 }                                                 
184                                                   
185 #ifdef CONFIG_PRINTK                              
186 static const char * const logtypes[] = {          
187         "emergency",                              
188         "alert",                                  
189         "critical",                               
190         "error",                                  
191         "warning",                                
192         "notice",                                 
193         "info",                                   
194         "debug",                                  
195 };                                                
196                                                   
197 /*                                                
198  * Use one ratelimit state per log level so th    
199  * messages doesn't cause more important ones     
200  */                                               
201 static struct ratelimit_state printk_limits[]     
202         RATELIMIT_STATE_INIT(printk_limits[0],    
203         RATELIMIT_STATE_INIT(printk_limits[1],    
204         RATELIMIT_STATE_INIT(printk_limits[2],    
205         RATELIMIT_STATE_INIT(printk_limits[3],    
206         RATELIMIT_STATE_INIT(printk_limits[4],    
207         RATELIMIT_STATE_INIT(printk_limits[5],    
208         RATELIMIT_STATE_INIT(printk_limits[6],    
209         RATELIMIT_STATE_INIT(printk_limits[7],    
210 };                                                
211                                                   
212 void __cold _btrfs_printk(const struct btrfs_f    
213 {                                                 
214         char lvl[PRINTK_MAX_SINGLE_HEADER_LEN     
215         struct va_format vaf;                     
216         va_list args;                             
217         int kern_level;                           
218         const char *type = logtypes[4];           
219         struct ratelimit_state *ratelimit = &p    
220                                                   
221 #ifdef CONFIG_PRINTK_INDEX                        
222         printk_index_subsys_emit("%sBTRFS %s (    
223 #endif                                            
224                                                   
225         va_start(args, fmt);                      
226                                                   
227         while ((kern_level = printk_get_level(    
228                 size_t size = printk_skip_leve    
229                                                   
230                 if (kern_level >= '' && kern_l    
231                         memcpy(lvl, fmt,  size    
232                         lvl[size] = '\0';         
233                         type = logtypes[kern_l    
234                         ratelimit = &printk_li    
235                 }                                 
236                 fmt += size;                      
237         }                                         
238                                                   
239         vaf.fmt = fmt;                            
240         vaf.va = &args;                           
241                                                   
242         /* Do not ratelimit if CONFIG_BTRFS_DE    
243         if (IS_ENABLED(CONFIG_BTRFS_DEBUG) ||     
244                 if (fs_info) {                    
245                         char statestr[STATE_ST    
246                                                   
247                         btrfs_state_to_string(    
248                         _printk("%sBTRFS %s (d    
249                                 fs_info->sb->s    
250                 } else {                          
251                         _printk("%sBTRFS %s: %    
252                 }                                 
253         }                                         
254                                                   
255         va_end(args);                             
256 }                                                 
257 #endif                                            
258                                                   
259 #if BITS_PER_LONG == 32                           
260 void __cold btrfs_warn_32bit_limit(struct btrf    
261 {                                                 
262         if (!test_and_set_bit(BTRFS_FS_32BIT_W    
263                 btrfs_warn(fs_info, "reaching     
264                 btrfs_warn(fs_info,               
265 "due to page cache limit on 32bit systems, btr    
266                            BTRFS_32BIT_MAX_FIL    
267                 btrfs_warn(fs_info,               
268                            "please consider up    
269         }                                         
270 }                                                 
271                                                   
272 void __cold btrfs_err_32bit_limit(struct btrfs    
273 {                                                 
274         if (!test_and_set_bit(BTRFS_FS_32BIT_E    
275                 btrfs_err(fs_info, "reached 32    
276                 btrfs_err(fs_info,                
277 "due to page cache limit on 32bit systems, met    
278                           BTRFS_32BIT_MAX_FILE    
279                 btrfs_err(fs_info,                
280                            "please consider up    
281         }                                         
282 }                                                 
283 #endif                                            
284                                                   
285 /*                                                
286  * Decode unexpected, fatal errors from the ca    
287  * panic or BUGs, depending on mount options.     
288  */                                               
289 __cold                                            
290 void __btrfs_panic(const struct btrfs_fs_info     
291                    unsigned int line, int erro    
292 {                                                 
293         char *s_id = "<unknown>";                 
294         const char *errstr;                       
295         struct va_format vaf = { .fmt = fmt };    
296         va_list args;                             
297                                                   
298         if (fs_info)                              
299                 s_id = fs_info->sb->s_id;         
300                                                   
301         va_start(args, fmt);                      
302         vaf.va = &args;                           
303                                                   
304         errstr = btrfs_decode_error(error);       
305         if (fs_info && (btrfs_test_opt(fs_info    
306                 panic(KERN_CRIT "BTRFS panic (    
307                         s_id, function, line,     
308                                                   
309         btrfs_crit(fs_info, "panic in %s:%d: %    
310                    function, line, &vaf, error    
311         va_end(args);                             
312         /* Caller calls BUG() */                  
313 }                                                 
314                                                   

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