7 void bch_inconsistent_error(struct cache_set *c)
9 set_bit(CACHE_SET_ERROR, &c->flags);
11 switch (c->opts.errors) {
12 case BCH_ON_ERROR_CONTINUE:
15 if (!test_bit(CACHE_SET_INITIAL_GC_DONE, &c->flags)) {
16 /* XXX do something better here? */
17 bch_cache_set_stop(c);
21 if (bch_cache_set_emergency_read_only(c))
22 bch_err(c, "emergency read only");
24 case BCH_ON_ERROR_PANIC:
25 panic(bch_fmt(c, "panic after error"));
30 void bch_fatal_error(struct cache_set *c)
32 if (bch_cache_set_emergency_read_only(c))
33 bch_err(c, "emergency read only");
36 /* Nonfatal IO errors, IO error/latency accounting: */
38 /* Just does IO error accounting: */
39 void bch_account_io_completion(struct cache *ca)
42 * The halflife of an error is:
43 * log2(1/2)/log2(127/128) * refresh ~= 88 * refresh
46 if (ca->set->error_decay) {
47 unsigned count = atomic_inc_return(&ca->io_count);
49 while (count > ca->set->error_decay) {
52 unsigned new = count - ca->set->error_decay;
55 * First we subtract refresh from count; each time we
56 * succesfully do so, we rescale the errors once:
59 count = atomic_cmpxchg(&ca->io_count, old, new);
64 errors = atomic_read(&ca->io_errors);
67 new = ((uint64_t) errors * 127) / 128;
68 errors = atomic_cmpxchg(&ca->io_errors,
70 } while (old != errors);
76 /* IO error accounting and latency accounting: */
77 void bch_account_io_completion_time(struct cache *ca,
78 unsigned submit_time_us, int op)
87 threshold = op_is_write(op)
88 ? c->congested_write_threshold_us
89 : c->congested_read_threshold_us;
91 if (threshold && submit_time_us) {
92 unsigned t = local_clock_us();
94 int us = t - submit_time_us;
95 int congested = atomic_read(&c->congested);
97 if (us > (int) threshold) {
99 c->congested_last_us = t;
101 ms = min(ms, CONGESTED_MAX + congested);
102 atomic_sub(ms, &c->congested);
103 } else if (congested < 0)
104 atomic_inc(&c->congested);
107 bch_account_io_completion(ca);
110 void bch_nonfatal_io_error_work(struct work_struct *work)
112 struct cache *ca = container_of(work, struct cache, io_error_work);
113 struct cache_set *c = ca->set;
114 unsigned errors = atomic_read(&ca->io_errors);
115 char buf[BDEVNAME_SIZE];
118 if (errors < c->error_limit) {
119 bch_notify_cache_error(ca, false);
121 bch_notify_cache_error(ca, true);
123 mutex_lock(&bch_register_lock);
124 dev = bch_cache_may_remove(ca);
126 ? bch_cache_read_only(ca)
127 : bch_cache_set_emergency_read_only(c))
129 "too many IO errors on %s, setting %s RO",
130 bdevname(ca->disk_sb.bdev, buf),
131 dev ? "device" : "filesystem");
132 mutex_unlock(&bch_register_lock);
136 void bch_nonfatal_io_error(struct cache *ca)
138 atomic_add(1 << IO_ERROR_SHIFT, &ca->io_errors);
139 queue_work(system_long_wq, &ca->io_error_work);