• Coly Li's avatar
    bcache: stop bcache device when backing device is offline · 0f0709e6
    Coly Li authored
    Currently bcache does not handle backing device failure, if backing
    device is offline and disconnected from system, its bcache device can still
    be accessible. If the bcache device is in writeback mode, I/O requests even
    can success if the requests hit on cache device. That is to say, when and
    how bcache handles offline backing device is undefined.
    
    This patch tries to handle backing device offline in a rather simple way,
    - Add cached_dev->status_update_thread kernel thread to update backing
      device status in every 1 second.
    - Add cached_dev->offline_seconds to record how many seconds the backing
      device is observed to be offline. If the backing device is offline for
      BACKING_DEV_OFFLINE_TIMEOUT (30) seconds, set dc->io_disable to 1 and
      call bcache_device_stop() to stop the bache device which linked to the
      offline backing device.
    
    Now if a backing device is offline for BACKING_DEV_OFFLINE_TIMEOUT seconds,
    its bcache device will be removed, then user space application writing on
    it will get error immediately, and handler the device failure in time.
    
    This patch is quite simple, does not handle more complicated situations.
    Once the bcache device is stopped, users need to recovery the backing
    device, register and attach it manually.
    
    Changelog:
    v3: call wait_for_kthread_stop() before exits kernel thread.
    v2: remove "bcache: " prefix when calling pr_warn().
    v1: initial version.
    Signed-off-by: default avatarColy Li <colyli@suse.de>
    Reviewed-by: default avatarHannes Reinecke <hare@suse.com>
    Cc: Michael Lyle <mlyle@lyle.org>
    Cc: Junhui Tang <tang.junhui@zte.com.cn>
    Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
    0f0709e6
super.c 58.3 KB