Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bcache: move closures to lib/

Prep work for bcachefs - being a fork of bcache it also uses closures

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Acked-by: Coly Li <colyli@suse.de>
Reviewed-by: Randy Dunlap <rdunlap@infradead.org>

authored by

Kent Overstreet and committed by
Kent Overstreet
8c8d2d96 957e4808

+43 -43
+1 -9
drivers/md/bcache/Kconfig
··· 4 4 tristate "Block device as cache" 5 5 select BLOCK_HOLDER_DEPRECATED if SYSFS 6 6 select CRC64 7 + select CLOSURES 7 8 help 8 9 Allows a block device to be used as cache for other devices; uses 9 10 a btree for indexing and the layout is optimized for SSDs. ··· 19 18 20 19 Enables extra debugging tools, allows expensive runtime checks to be 21 20 turned on. 22 - 23 - config BCACHE_CLOSURES_DEBUG 24 - bool "Debug closures" 25 - depends on BCACHE 26 - select DEBUG_FS 27 - help 28 - Keeps all active closures in a linked list and provides a debugfs 29 - interface to list them, which makes it possible to see asynchronous 30 - operations that get stuck. 31 21 32 22 config BCACHE_ASYNC_REGISTRATION 33 23 bool "Asynchronous device registration"
+2 -2
drivers/md/bcache/Makefile
··· 2 2 3 3 obj-$(CONFIG_BCACHE) += bcache.o 4 4 5 - bcache-y := alloc.o bset.o btree.o closure.o debug.o extents.o\ 6 - io.o journal.o movinggc.o request.o stats.o super.o sysfs.o trace.o\ 5 + bcache-y := alloc.o bset.o btree.o debug.o extents.o io.o\ 6 + journal.o movinggc.o request.o stats.o super.o sysfs.o trace.o\ 7 7 util.o writeback.o features.o
+1 -1
drivers/md/bcache/bcache.h
··· 179 179 #define pr_fmt(fmt) "bcache: %s() " fmt, __func__ 180 180 181 181 #include <linux/bio.h> 182 + #include <linux/closure.h> 182 183 #include <linux/kobject.h> 183 184 #include <linux/list.h> 184 185 #include <linux/mutex.h> ··· 193 192 #include "bcache_ondisk.h" 194 193 #include "bset.h" 195 194 #include "util.h" 196 - #include "closure.h" 197 195 198 196 struct bucket { 199 197 atomic_t pin;
+16 -19
drivers/md/bcache/closure.c lib/closure.c
··· 6 6 * Copyright 2012 Google, Inc. 7 7 */ 8 8 9 + #include <linux/closure.h> 9 10 #include <linux/debugfs.h> 10 - #include <linux/module.h> 11 + #include <linux/export.h> 11 12 #include <linux/seq_file.h> 12 13 #include <linux/sched/debug.h> 13 - 14 - #include "closure.h" 15 14 16 15 static inline void closure_put_after_sub(struct closure *cl, int flags) 17 16 { ··· 44 45 { 45 46 closure_put_after_sub(cl, atomic_sub_return(v, &cl->remaining)); 46 47 } 48 + EXPORT_SYMBOL(closure_sub); 47 49 48 50 /* 49 51 * closure_put - decrement a closure's refcount ··· 53 53 { 54 54 closure_put_after_sub(cl, atomic_dec_return(&cl->remaining)); 55 55 } 56 + EXPORT_SYMBOL(closure_put); 56 57 57 58 /* 58 59 * closure_wake_up - wake up all closures on a wait list, without memory barrier ··· 75 74 closure_sub(cl, CLOSURE_WAITING + 1); 76 75 } 77 76 } 77 + EXPORT_SYMBOL(__closure_wake_up); 78 78 79 79 /** 80 80 * closure_wait - add a closure to a waitlist ··· 95 93 96 94 return true; 97 95 } 96 + EXPORT_SYMBOL(closure_wait); 98 97 99 98 struct closure_syncer { 100 99 struct task_struct *task; ··· 130 127 131 128 __set_current_state(TASK_RUNNING); 132 129 } 130 + EXPORT_SYMBOL(__closure_sync); 133 131 134 - #ifdef CONFIG_BCACHE_CLOSURES_DEBUG 132 + #ifdef CONFIG_DEBUG_CLOSURES 135 133 136 134 static LIST_HEAD(closure_list); 137 135 static DEFINE_SPINLOCK(closure_list_lock); ··· 148 144 list_add(&cl->all, &closure_list); 149 145 spin_unlock_irqrestore(&closure_list_lock, flags); 150 146 } 147 + EXPORT_SYMBOL(closure_debug_create); 151 148 152 149 void closure_debug_destroy(struct closure *cl) 153 150 { ··· 161 156 list_del(&cl->all); 162 157 spin_unlock_irqrestore(&closure_list_lock, flags); 163 158 } 164 - 165 - static struct dentry *closure_debug; 159 + EXPORT_SYMBOL(closure_debug_destroy); 166 160 167 161 static int debug_show(struct seq_file *f, void *data) 168 162 { ··· 185 181 seq_printf(f, " W %pS\n", 186 182 (void *) cl->waiting_on); 187 183 188 - seq_printf(f, "\n"); 184 + seq_puts(f, "\n"); 189 185 } 190 186 191 187 spin_unlock_irq(&closure_list_lock); ··· 194 190 195 191 DEFINE_SHOW_ATTRIBUTE(debug); 196 192 197 - void __init closure_debug_init(void) 193 + static int __init closure_debug_init(void) 198 194 { 199 - if (!IS_ERR_OR_NULL(bcache_debug)) 200 - /* 201 - * it is unnecessary to check return value of 202 - * debugfs_create_file(), we should not care 203 - * about this. 204 - */ 205 - closure_debug = debugfs_create_file( 206 - "closures", 0400, bcache_debug, NULL, &debug_fops); 195 + debugfs_create_file("closures", 0400, NULL, NULL, &debug_fops); 196 + return 0; 207 197 } 208 - #endif 198 + late_initcall(closure_debug_init) 209 199 210 - MODULE_AUTHOR("Kent Overstreet <koverstreet@google.com>"); 211 - MODULE_LICENSE("GPL"); 200 + #endif
+8 -9
drivers/md/bcache/closure.h include/linux/closure.h
··· 155 155 156 156 atomic_t remaining; 157 157 158 - #ifdef CONFIG_BCACHE_CLOSURES_DEBUG 158 + #ifdef CONFIG_DEBUG_CLOSURES 159 159 #define CLOSURE_MAGIC_DEAD 0xc054dead 160 160 #define CLOSURE_MAGIC_ALIVE 0xc054a11e 161 161 ··· 184 184 __closure_sync(cl); 185 185 } 186 186 187 - #ifdef CONFIG_BCACHE_CLOSURES_DEBUG 187 + #ifdef CONFIG_DEBUG_CLOSURES 188 188 189 - void closure_debug_init(void); 190 189 void closure_debug_create(struct closure *cl); 191 190 void closure_debug_destroy(struct closure *cl); 192 191 193 192 #else 194 193 195 - static inline void closure_debug_init(void) {} 196 194 static inline void closure_debug_create(struct closure *cl) {} 197 195 static inline void closure_debug_destroy(struct closure *cl) {} 198 196 ··· 198 200 199 201 static inline void closure_set_ip(struct closure *cl) 200 202 { 201 - #ifdef CONFIG_BCACHE_CLOSURES_DEBUG 203 + #ifdef CONFIG_DEBUG_CLOSURES 202 204 cl->ip = _THIS_IP_; 203 205 #endif 204 206 } 205 207 206 208 static inline void closure_set_ret_ip(struct closure *cl) 207 209 { 208 - #ifdef CONFIG_BCACHE_CLOSURES_DEBUG 210 + #ifdef CONFIG_DEBUG_CLOSURES 209 211 cl->ip = _RET_IP_; 210 212 #endif 211 213 } 212 214 213 215 static inline void closure_set_waiting(struct closure *cl, unsigned long f) 214 216 { 215 - #ifdef CONFIG_BCACHE_CLOSURES_DEBUG 217 + #ifdef CONFIG_DEBUG_CLOSURES 216 218 cl->waiting_on = f; 217 219 #endif 218 220 } ··· 241 243 */ 242 244 BUILD_BUG_ON(offsetof(struct closure, fn) 243 245 != offsetof(struct work_struct, func)); 246 + 244 247 if (wq) { 245 248 INIT_WORK(&cl->work, cl->work.func); 246 249 BUG_ON(!queue_work(wq, &cl->work)); ··· 254 255 */ 255 256 static inline void closure_get(struct closure *cl) 256 257 { 257 - #ifdef CONFIG_BCACHE_CLOSURES_DEBUG 258 + #ifdef CONFIG_DEBUG_CLOSURES 258 259 BUG_ON((atomic_inc_return(&cl->remaining) & 259 260 CLOSURE_REMAINING_MASK) <= 1); 260 261 #else ··· 270 271 */ 271 272 static inline void closure_init(struct closure *cl, struct closure *parent) 272 273 { 273 - memset(cl, 0, sizeof(struct closure)); 274 + cl->fn = NULL; 274 275 cl->parent = parent; 275 276 if (parent) 276 277 closure_get(parent);
-1
drivers/md/bcache/super.c
··· 2905 2905 goto err; 2906 2906 2907 2907 bch_debug_init(); 2908 - closure_debug_init(); 2909 2908 2910 2909 bcache_is_reboot = false; 2911 2910
+1 -2
drivers/md/bcache/util.h
··· 4 4 #define _BCACHE_UTIL_H 5 5 6 6 #include <linux/blkdev.h> 7 + #include <linux/closure.h> 7 8 #include <linux/errno.h> 8 9 #include <linux/kernel.h> 9 10 #include <linux/sched/clock.h> ··· 13 12 #include <linux/vmalloc.h> 14 13 #include <linux/workqueue.h> 15 14 #include <linux/crc64.h> 16 - 17 - #include "closure.h" 18 15 19 16 struct closure; 20 17
+3
lib/Kconfig
··· 506 506 507 507 for more information. 508 508 509 + config CLOSURES 510 + bool 511 + 509 512 config HAS_IOMEM 510 513 bool 511 514 depends on !NO_IOMEM
+9
lib/Kconfig.debug
··· 1720 1720 This is a relatively cheap check but if you care about maximum 1721 1721 performance, say N. 1722 1722 1723 + config DEBUG_CLOSURES 1724 + bool "Debug closures (bcache async widgits)" 1725 + depends on CLOSURES 1726 + select DEBUG_FS 1727 + help 1728 + Keeps all active closures in a linked list and provides a debugfs 1729 + interface to list them, which makes it possible to see asynchronous 1730 + operations that get stuck. 1731 + 1723 1732 config DEBUG_MAPLE_TREE 1724 1733 bool "Debug maple trees" 1725 1734 depends on DEBUG_KERNEL
+2
lib/Makefile
··· 255 255 256 256 obj-$(CONFIG_CPU_RMAP) += cpu_rmap.o 257 257 258 + obj-$(CONFIG_CLOSURES) += closure.o 259 + 258 260 obj-$(CONFIG_DQL) += dynamic_queue_limits.o 259 261 260 262 obj-$(CONFIG_GLOB) += glob.o