Skip to content

Commit 533574c

Browse files
JoePerchestorvalds
authored andcommitted
btrfs: use printk_get_level and printk_skip_level, add __printf, fix fallout
Use the generic printk_get_level() to search a message for a kern_level. Add __printf to verify format and arguments. Fix a few messages that had mismatches in format and arguments. Add #ifdef CONFIG_PRINTK blocks to shrink the object size a bit when not using printk. [[email protected]: whitespace tweak] Signed-off-by: Joe Perches <[email protected]> Cc: Kay Sievers <[email protected]> Cc: Chris Mason <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 0cc41e4 commit 533574c

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

fs/btrfs/ctree.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3342,10 +3342,22 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
33423342
/* super.c */
33433343
int btrfs_parse_options(struct btrfs_root *root, char *options);
33443344
int btrfs_sync_fs(struct super_block *sb, int wait);
3345+
3346+
#ifdef CONFIG_PRINTK
3347+
__printf(2, 3)
33453348
void btrfs_printk(struct btrfs_fs_info *fs_info, const char *fmt, ...);
3349+
#else
3350+
static inline __printf(2, 3)
3351+
void btrfs_printk(struct btrfs_fs_info *fs_info, const char *fmt, ...)
3352+
{
3353+
}
3354+
#endif
3355+
3356+
__printf(5, 6)
33463357
void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
33473358
unsigned int line, int errno, const char *fmt, ...);
33483359

3360+
33493361
void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
33503362
struct btrfs_root *root, const char *function,
33513363
unsigned int line, int errno);
@@ -3386,6 +3398,7 @@ do { \
33863398
(errno), fmt, ##args); \
33873399
} while (0)
33883400

3401+
__printf(5, 6)
33893402
void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
33903403
unsigned int line, int errno, const char *fmt, ...);
33913404

fs/btrfs/disk-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ void clean_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
11141114
spin_unlock(&root->fs_info->delalloc_lock);
11151115
btrfs_panic(root->fs_info, -EOVERFLOW,
11161116
"Can't clear %lu bytes from "
1117-
" dirty_mdatadata_bytes (%lu)",
1117+
" dirty_mdatadata_bytes (%llu)",
11181118
buf->len,
11191119
root->fs_info->dirty_metadata_bytes);
11201120
}

fs/btrfs/relocation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ static int __must_check __add_reloc_root(struct btrfs_root *root)
12411241
if (rb_node) {
12421242
btrfs_panic(root->fs_info, -EEXIST, "Duplicate root found "
12431243
"for start=%llu while inserting into relocation "
1244-
"tree\n");
1244+
"tree\n", node->bytenr);
12451245
kfree(node);
12461246
return -EEXIST;
12471247
}

fs/btrfs/super.c

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ static void btrfs_handle_error(struct btrfs_fs_info *fs_info)
125125
}
126126
}
127127

128+
#ifdef CONFIG_PRINTK
128129
/*
129130
* __btrfs_std_error decodes expected errors from the caller and
130131
* invokes the approciate error response.
@@ -167,7 +168,7 @@ void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
167168
va_end(args);
168169
}
169170

170-
const char *logtypes[] = {
171+
static const char * const logtypes[] = {
171172
"emergency",
172173
"alert",
173174
"critical",
@@ -185,22 +186,50 @@ void btrfs_printk(struct btrfs_fs_info *fs_info, const char *fmt, ...)
185186
struct va_format vaf;
186187
va_list args;
187188
const char *type = logtypes[4];
189+
int kern_level;
188190

189191
va_start(args, fmt);
190192

191-
if (fmt[0] == '<' && isdigit(fmt[1]) && fmt[2] == '>') {
192-
memcpy(lvl, fmt, 3);
193-
lvl[3] = '\0';
194-
fmt += 3;
195-
type = logtypes[fmt[1] - '0'];
193+
kern_level = printk_get_level(fmt);
194+
if (kern_level) {
195+
size_t size = printk_skip_level(fmt) - fmt;
196+
memcpy(lvl, fmt, size);
197+
lvl[size] = '\0';
198+
fmt += size;
199+
type = logtypes[kern_level - '0'];
196200
} else
197201
*lvl = '\0';
198202

199203
vaf.fmt = fmt;
200204
vaf.va = &args;
205+
201206
printk("%sBTRFS %s (device %s): %pV", lvl, type, sb->s_id, &vaf);
207+
208+
va_end(args);
202209
}
203210

211+
#else
212+
213+
void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
214+
unsigned int line, int errno, const char *fmt, ...)
215+
{
216+
struct super_block *sb = fs_info->sb;
217+
218+
/*
219+
* Special case: if the error is EROFS, and we're already
220+
* under MS_RDONLY, then it is safe here.
221+
*/
222+
if (errno == -EROFS && (sb->s_flags & MS_RDONLY))
223+
return;
224+
225+
/* Don't go through full error handling during mount */
226+
if (sb->s_flags & MS_BORN) {
227+
save_error_info(fs_info);
228+
btrfs_handle_error(fs_info);
229+
}
230+
}
231+
#endif
232+
204233
/*
205234
* We only mark the transaction aborted and then set the file system read-only.
206235
* This will prevent new transactions from starting or trying to join this

0 commit comments

Comments
 (0)