Skip to content

Commit 0874881

Browse files
kdaveJosef Bacik
authored andcommitted
btrfs: clean up transaction abort messages
The transaction abort stacktrace is printed only once per module lifetime, but we'd like to see it each time it happens per mounted filesystem. Introduce a fs_state flag that records it. Tweak the messages around abort: * add error number to the first abort * print the exact negative errno from btrfs_decode_error * clean up btrfs_decode_error and callers * no dots at the end of the messages Signed-off-by: David Sterba <[email protected]> Signed-off-by: Josef Bacik <[email protected]>
1 parent bbece8a commit 0874881

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

fs/btrfs/ctree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes)
340340
*/
341341
#define BTRFS_FS_STATE_ERROR 0
342342
#define BTRFS_FS_STATE_REMOUNTING 1
343+
#define BTRFS_FS_STATE_TRANS_ABORTED 2
343344

344345
/* Super block flags */
345346
/* Errors detected */

fs/btrfs/super.c

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
static const struct super_operations btrfs_super_ops;
6565
static struct file_system_type btrfs_fs_type;
6666

67-
static const char *btrfs_decode_error(int errno, char nbuf[16])
67+
static const char *btrfs_decode_error(int errno)
6868
{
69-
char *errstr = NULL;
69+
char *errstr = "unknown";
7070

7171
switch (errno) {
7272
case -EIO:
@@ -81,12 +81,6 @@ static const char *btrfs_decode_error(int errno, char nbuf[16])
8181
case -EEXIST:
8282
errstr = "Object already exists";
8383
break;
84-
default:
85-
if (nbuf) {
86-
if (snprintf(nbuf, 16, "error %d", -errno) >= 0)
87-
errstr = nbuf;
88-
}
89-
break;
9084
}
9185

9286
return errstr;
@@ -122,7 +116,6 @@ static void btrfs_handle_error(struct btrfs_fs_info *fs_info)
122116
* mounted writeable again, the device replace
123117
* operation continues.
124118
*/
125-
// WARN_ON(1);
126119
}
127120
}
128121

@@ -135,7 +128,6 @@ void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
135128
unsigned int line, int errno, const char *fmt, ...)
136129
{
137130
struct super_block *sb = fs_info->sb;
138-
char nbuf[16];
139131
const char *errstr;
140132

141133
/*
@@ -145,7 +137,7 @@ void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
145137
if (errno == -EROFS && (sb->s_flags & MS_RDONLY))
146138
return;
147139

148-
errstr = btrfs_decode_error(errno, nbuf);
140+
errstr = btrfs_decode_error(errno);
149141
if (fmt) {
150142
struct va_format vaf;
151143
va_list args;
@@ -154,12 +146,12 @@ void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
154146
vaf.fmt = fmt;
155147
vaf.va = &args;
156148

157-
printk(KERN_CRIT "BTRFS error (device %s) in %s:%d: %s (%pV)\n",
158-
sb->s_id, function, line, errstr, &vaf);
149+
printk(KERN_CRIT "BTRFS error (device %s) in %s:%d: errno=%d %s (%pV)\n",
150+
sb->s_id, function, line, errno, errstr, &vaf);
159151
va_end(args);
160152
} else {
161-
printk(KERN_CRIT "BTRFS error (device %s) in %s:%d: %s\n",
162-
sb->s_id, function, line, errstr);
153+
printk(KERN_CRIT "BTRFS error (device %s) in %s:%d: errno=%d %s\n",
154+
sb->s_id, function, line, errno, errstr);
163155
}
164156

165157
/* Don't go through full error handling during mount */
@@ -248,17 +240,23 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
248240
struct btrfs_root *root, const char *function,
249241
unsigned int line, int errno)
250242
{
251-
WARN_ONCE(1, KERN_DEBUG "btrfs: Transaction aborted\n");
243+
/*
244+
* Report first abort since mount
245+
*/
246+
if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED,
247+
&root->fs_info->fs_state)) {
248+
WARN(1, KERN_DEBUG "btrfs: Transaction aborted (error %d)\n",
249+
errno);
250+
}
252251
trans->aborted = errno;
253252
/* Nothing used. The other threads that have joined this
254253
* transaction may be able to continue. */
255254
if (!trans->blocks_used) {
256-
char nbuf[16];
257255
const char *errstr;
258256

259-
errstr = btrfs_decode_error(errno, nbuf);
257+
errstr = btrfs_decode_error(errno);
260258
btrfs_printk(root->fs_info,
261-
"%s:%d: Aborting unused transaction(%s).\n",
259+
"%s:%d: Aborting unused transaction (%s)\n",
262260
function, line, errstr);
263261
return;
264262
}
@@ -272,7 +270,6 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
272270
void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
273271
unsigned int line, int errno, const char *fmt, ...)
274272
{
275-
char nbuf[16];
276273
char *s_id = "<unknown>";
277274
const char *errstr;
278275
struct va_format vaf = { .fmt = fmt };
@@ -284,13 +281,13 @@ void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
284281
va_start(args, fmt);
285282
vaf.va = &args;
286283

287-
errstr = btrfs_decode_error(errno, nbuf);
284+
errstr = btrfs_decode_error(errno);
288285
if (fs_info && (fs_info->mount_opt & BTRFS_MOUNT_PANIC_ON_FATAL_ERROR))
289-
panic(KERN_CRIT "BTRFS panic (device %s) in %s:%d: %pV (%s)\n",
290-
s_id, function, line, &vaf, errstr);
286+
panic(KERN_CRIT "BTRFS panic (device %s) in %s:%d: %pV (errno=%d %s)\n",
287+
s_id, function, line, &vaf, errno, errstr);
291288

292-
printk(KERN_CRIT "BTRFS panic (device %s) in %s:%d: %pV (%s)\n",
293-
s_id, function, line, &vaf, errstr);
289+
printk(KERN_CRIT "BTRFS panic (device %s) in %s:%d: %pV (errno=%d %s)\n",
290+
s_id, function, line, &vaf, errno, errstr);
294291
va_end(args);
295292
/* Caller calls BUG() */
296293
}

fs/btrfs/transaction.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
18081808
ret = btrfs_write_and_wait_transaction(trans, root);
18091809
if (ret) {
18101810
btrfs_error(root->fs_info, ret,
1811-
"Error while writing out transaction.");
1811+
"Error while writing out transaction");
18121812
mutex_unlock(&root->fs_info->tree_log_mutex);
18131813
goto cleanup_transaction;
18141814
}
@@ -1864,8 +1864,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
18641864
btrfs_qgroup_free(root, trans->qgroup_reserved);
18651865
trans->qgroup_reserved = 0;
18661866
}
1867-
btrfs_printk(root->fs_info, "Skipping commit of aborted transaction.\n");
1868-
// WARN_ON(1);
1867+
btrfs_printk(root->fs_info, "Skipping commit of aborted transaction\n");
18691868
if (current->journal_info == trans)
18701869
current->journal_info = NULL;
18711870
cleanup_transaction(trans, root, ret);

0 commit comments

Comments
 (0)