btrfs: return void in functions without error conditions
[firefly-linux-kernel-4.4.55.git] / fs / btrfs / super.c
index 3ce97b217cbeae21ef23e57fe2a605ed11572af1..ae7963b2d5277c0a9e2eba1c7e4e12edf772572c 100644 (file)
@@ -76,6 +76,9 @@ static const char *btrfs_decode_error(struct btrfs_fs_info *fs_info, int errno,
        case -EROFS:
                errstr = "Readonly filesystem";
                break;
+       case -EEXIST:
+               errstr = "Object already exists";
+               break;
        default:
                if (nbuf) {
                        if (snprintf(nbuf, 16, "error %d", -errno) >= 0)
@@ -145,6 +148,36 @@ void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
        btrfs_handle_error(fs_info);
 }
 
+/*
+ * __btrfs_panic decodes unexpected, fatal errors from the caller,
+ * issues an alert, and either panics or BUGs, depending on mount options.
+ */
+void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
+                  unsigned int line, int errno, const char *fmt, ...)
+{
+       char nbuf[16];
+       char *s_id = "<unknown>";
+       const char *errstr;
+       struct va_format vaf = { .fmt = fmt };
+       va_list args;
+
+       if (fs_info)
+               s_id = fs_info->sb->s_id;
+
+       va_start(args, fmt);
+       vaf.va = &args;
+
+       errstr = btrfs_decode_error(fs_info, errno, nbuf);
+       if (fs_info->mount_opt & BTRFS_MOUNT_PANIC_ON_FATAL_ERROR)
+               panic(KERN_CRIT "BTRFS panic (device %s) in %s:%d: %pV (%s)\n",
+                       s_id, function, line, &vaf, errstr);
+
+       printk(KERN_CRIT "BTRFS panic (device %s) in %s:%d: %pV (%s)\n",
+              s_id, function, line, &vaf, errstr);
+       va_end(args);
+       /* Caller calls BUG() */
+}
+
 static void btrfs_put_super(struct super_block *sb)
 {
        (void)close_ctree(btrfs_sb(sb)->tree_root);
@@ -166,7 +199,7 @@ enum {
        Opt_enospc_debug, Opt_subvolrootid, Opt_defrag, Opt_inode_cache,
        Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
        Opt_check_integrity, Opt_check_integrity_including_extent_data,
-       Opt_check_integrity_print_mask,
+       Opt_check_integrity_print_mask, Opt_fatal_errors,
        Opt_err,
 };
 
@@ -206,6 +239,7 @@ static match_table_t tokens = {
        {Opt_check_integrity, "check_int"},
        {Opt_check_integrity_including_extent_data, "check_int_data"},
        {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
+       {Opt_fatal_errors, "fatal_errors=%s"},
        {Opt_err, NULL},
 };
 
@@ -438,6 +472,18 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
                        ret = -EINVAL;
                        goto out;
 #endif
+               case Opt_fatal_errors:
+                       if (strcmp(args[0].from, "panic") == 0)
+                               btrfs_set_opt(info->mount_opt,
+                                             PANIC_ON_FATAL_ERROR);
+                       else if (strcmp(args[0].from, "bug") == 0)
+                               btrfs_clear_opt(info->mount_opt,
+                                             PANIC_ON_FATAL_ERROR);
+                       else {
+                               ret = -EINVAL;
+                               goto out;
+                       }
+                       break;
                case Opt_err:
                        printk(KERN_INFO "btrfs: unrecognized mount option "
                               "'%s'\n", p);
@@ -766,6 +812,8 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
                seq_puts(seq, ",inode_cache");
        if (btrfs_test_opt(root, SKIP_BALANCE))
                seq_puts(seq, ",skip_balance");
+       if (btrfs_test_opt(root, PANIC_ON_FATAL_ERROR))
+               seq_puts(seq, ",fatal_errors=panic");
        return 0;
 }
 
@@ -1360,9 +1408,7 @@ static int __init init_btrfs_fs(void)
        if (err)
                return err;
 
-       err = btrfs_init_compress();
-       if (err)
-               goto free_sysfs;
+       btrfs_init_compress();
 
        err = btrfs_init_cachep();
        if (err)
@@ -1403,7 +1449,6 @@ free_cachep:
        btrfs_destroy_cachep();
 free_compress:
        btrfs_exit_compress();
-free_sysfs:
        btrfs_exit_sysfs();
        return err;
 }