]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/error.c
Rename from bcache-tools to bcachefs-tools
[bcachefs-tools-debian] / libbcachefs / error.c
1 #include "bcachefs.h"
2 #include "error.h"
3 #include "io.h"
4 #include "super.h"
5
6 void bch2_inconsistent_error(struct bch_fs *c)
7 {
8         set_bit(BCH_FS_ERROR, &c->flags);
9
10         switch (c->opts.errors) {
11         case BCH_ON_ERROR_CONTINUE:
12                 break;
13         case BCH_ON_ERROR_RO:
14                 if (bch2_fs_emergency_read_only(c))
15                         bch_err(c, "emergency read only");
16                 break;
17         case BCH_ON_ERROR_PANIC:
18                 panic(bch2_fmt(c, "panic after error"));
19                 break;
20         }
21 }
22
23 void bch2_fatal_error(struct bch_fs *c)
24 {
25         if (bch2_fs_emergency_read_only(c))
26                 bch_err(c, "emergency read only");
27 }
28
29 void bch2_nonfatal_io_error_work(struct work_struct *work)
30 {
31         struct bch_dev *ca = container_of(work, struct bch_dev, io_error_work);
32         struct bch_fs *c = ca->fs;
33         bool dev;
34
35         mutex_lock(&c->state_lock);
36         dev = bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_RO,
37                                     BCH_FORCE_IF_DEGRADED);
38         if (dev
39             ? __bch2_dev_set_state(c, ca, BCH_MEMBER_STATE_RO,
40                                   BCH_FORCE_IF_DEGRADED)
41             : bch2_fs_emergency_read_only(c))
42                 bch_err(ca,
43                         "too many IO errors, setting %s RO",
44                         dev ? "device" : "filesystem");
45         mutex_unlock(&c->state_lock);
46 }
47
48 void bch2_nonfatal_io_error(struct bch_dev *ca)
49 {
50         queue_work(system_long_wq, &ca->io_error_work);
51 }