super.c (754451342fc5954061ede74b0a8485ec4a4c6eaa) super.c (0f0709e6bfc3ce4e8e1c0e8573490c45f76cfeee)
1/*
2 * bcache setup/teardown code, and some metadata io - read a superblock and
3 * figure out what to do with it.
4 *
5 * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com>
6 * Copyright 2012 Google, Inc.
7 */
8

--- 640 unchanged lines hidden (view full) ---

649 struct bcache_device *d = b->private_data;
650 closure_put(&d->cl);
651}
652
653static int ioctl_dev(struct block_device *b, fmode_t mode,
654 unsigned int cmd, unsigned long arg)
655{
656 struct bcache_device *d = b->bd_disk->private_data;
1/*
2 * bcache setup/teardown code, and some metadata io - read a superblock and
3 * figure out what to do with it.
4 *
5 * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com>
6 * Copyright 2012 Google, Inc.
7 */
8

--- 640 unchanged lines hidden (view full) ---

649 struct bcache_device *d = b->private_data;
650 closure_put(&d->cl);
651}
652
653static int ioctl_dev(struct block_device *b, fmode_t mode,
654 unsigned int cmd, unsigned long arg)
655{
656 struct bcache_device *d = b->bd_disk->private_data;
657 struct cached_dev *dc = container_of(d, struct cached_dev, disk);
658
659 if (dc->io_disable)
660 return -EIO;
661
657 return d->ioctl(d, mode, cmd, arg);
658}
659
660static const struct block_device_operations bcache_ops = {
661 .open = open_dev,
662 .release = release_dev,
663 .ioctl = ioctl_dev,
664 .owner = THIS_MODULE,

--- 194 unchanged lines hidden (view full) ---

859 struct cached_dev *dc;
860
861 list_for_each_entry(dc, &c->cached_devs, list)
862 sectors += bdev_sectors(dc->bdev);
863
864 c->cached_dev_sectors = sectors;
865}
866
662 return d->ioctl(d, mode, cmd, arg);
663}
664
665static const struct block_device_operations bcache_ops = {
666 .open = open_dev,
667 .release = release_dev,
668 .ioctl = ioctl_dev,
669 .owner = THIS_MODULE,

--- 194 unchanged lines hidden (view full) ---

864 struct cached_dev *dc;
865
866 list_for_each_entry(dc, &c->cached_devs, list)
867 sectors += bdev_sectors(dc->bdev);
868
869 c->cached_dev_sectors = sectors;
870}
871
872#define BACKING_DEV_OFFLINE_TIMEOUT 5
873static int cached_dev_status_update(void *arg)
874{
875 struct cached_dev *dc = arg;
876 struct request_queue *q;
877
878 /*
879 * If this delayed worker is stopping outside, directly quit here.
880 * dc->io_disable might be set via sysfs interface, so check it
881 * here too.
882 */
883 while (!kthread_should_stop() && !dc->io_disable) {
884 q = bdev_get_queue(dc->bdev);
885 if (blk_queue_dying(q))
886 dc->offline_seconds++;
887 else
888 dc->offline_seconds = 0;
889
890 if (dc->offline_seconds >= BACKING_DEV_OFFLINE_TIMEOUT) {
891 pr_err("%s: device offline for %d seconds",
892 dc->backing_dev_name,
893 BACKING_DEV_OFFLINE_TIMEOUT);
894 pr_err("%s: disable I/O request due to backing "
895 "device offline", dc->disk.name);
896 dc->io_disable = true;
897 /* let others know earlier that io_disable is true */
898 smp_mb();
899 bcache_device_stop(&dc->disk);
900 break;
901 }
902 schedule_timeout_interruptible(HZ);
903 }
904
905 wait_for_kthread_stop();
906 return 0;
907}
908
909
867void bch_cached_dev_run(struct cached_dev *dc)
868{
869 struct bcache_device *d = &dc->disk;
870 char buf[SB_LABEL_SIZE + 1];
871 char *env[] = {
872 "DRIVER=bcache",
873 kasprintf(GFP_KERNEL, "CACHED_UUID=%pU", dc->sb.uuid),
874 NULL,

--- 26 unchanged lines hidden (view full) ---

901 * only class / kset properties are persistent */
902 kobject_uevent_env(&disk_to_dev(d->disk)->kobj, KOBJ_CHANGE, env);
903 kfree(env[1]);
904 kfree(env[2]);
905
906 if (sysfs_create_link(&d->kobj, &disk_to_dev(d->disk)->kobj, "dev") ||
907 sysfs_create_link(&disk_to_dev(d->disk)->kobj, &d->kobj, "bcache"))
908 pr_debug("error creating sysfs link");
910void bch_cached_dev_run(struct cached_dev *dc)
911{
912 struct bcache_device *d = &dc->disk;
913 char buf[SB_LABEL_SIZE + 1];
914 char *env[] = {
915 "DRIVER=bcache",
916 kasprintf(GFP_KERNEL, "CACHED_UUID=%pU", dc->sb.uuid),
917 NULL,

--- 26 unchanged lines hidden (view full) ---

944 * only class / kset properties are persistent */
945 kobject_uevent_env(&disk_to_dev(d->disk)->kobj, KOBJ_CHANGE, env);
946 kfree(env[1]);
947 kfree(env[2]);
948
949 if (sysfs_create_link(&d->kobj, &disk_to_dev(d->disk)->kobj, "dev") ||
950 sysfs_create_link(&disk_to_dev(d->disk)->kobj, &d->kobj, "bcache"))
951 pr_debug("error creating sysfs link");
952
953 dc->status_update_thread = kthread_run(cached_dev_status_update,
954 dc, "bcache_status_update");
955 if (IS_ERR(dc->status_update_thread)) {
956 pr_warn("failed to create bcache_status_update kthread, "
957 "continue to run without monitoring backing "
958 "device status");
959 }
909}
910
911/*
912 * If BCACHE_DEV_RATE_DW_RUNNING is set, it means routine of the delayed
913 * work dc->writeback_rate_update is running. Wait until the routine
914 * quits (BCACHE_DEV_RATE_DW_RUNNING is clear), then continue to
915 * cancel it. If BCACHE_DEV_RATE_DW_RUNNING is not clear after time_out
916 * seconds, give up waiting here and continue to cancel it too.

--- 217 unchanged lines hidden (view full) ---

1134
1135 if (test_and_clear_bit(BCACHE_DEV_WB_RUNNING, &dc->disk.flags))
1136 cancel_writeback_rate_update_dwork(dc);
1137
1138 if (!IS_ERR_OR_NULL(dc->writeback_thread))
1139 kthread_stop(dc->writeback_thread);
1140 if (dc->writeback_write_wq)
1141 destroy_workqueue(dc->writeback_write_wq);
960}
961
962/*
963 * If BCACHE_DEV_RATE_DW_RUNNING is set, it means routine of the delayed
964 * work dc->writeback_rate_update is running. Wait until the routine
965 * quits (BCACHE_DEV_RATE_DW_RUNNING is clear), then continue to
966 * cancel it. If BCACHE_DEV_RATE_DW_RUNNING is not clear after time_out
967 * seconds, give up waiting here and continue to cancel it too.

--- 217 unchanged lines hidden (view full) ---

1185
1186 if (test_and_clear_bit(BCACHE_DEV_WB_RUNNING, &dc->disk.flags))
1187 cancel_writeback_rate_update_dwork(dc);
1188
1189 if (!IS_ERR_OR_NULL(dc->writeback_thread))
1190 kthread_stop(dc->writeback_thread);
1191 if (dc->writeback_write_wq)
1192 destroy_workqueue(dc->writeback_write_wq);
1193 if (!IS_ERR_OR_NULL(dc->status_update_thread))
1194 kthread_stop(dc->status_update_thread);
1142
1143 if (atomic_read(&dc->running))
1144 bd_unlink_disk_holder(dc->bdev, dc->disk.disk);
1145 bcache_device_free(&dc->disk);
1146 list_del(&dc->list);
1147
1148 mutex_unlock(&bch_register_lock);
1149

--- 1166 unchanged lines hidden ---
1195
1196 if (atomic_read(&dc->running))
1197 bd_unlink_disk_holder(dc->bdev, dc->disk.disk);
1198 bcache_device_free(&dc->disk);
1199 list_del(&dc->list);
1200
1201 mutex_unlock(&bch_register_lock);
1202

--- 1166 unchanged lines hidden ---