Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4207325imm; Fri, 18 May 2018 00:52:12 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpWMk/wioGJSNYua7nyhXXvBhzBID6cmxh5tOWyg5DvJOaL25313wOnLt7IkeKBTlWKJon+ X-Received: by 2002:a65:4bca:: with SMTP id p10-v6mr2724681pgr.114.1526629931996; Fri, 18 May 2018 00:52:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526629931; cv=none; d=google.com; s=arc-20160816; b=bKNXw3vhHawN+eazI9ErzC3w759vt2xq2WiASVAx1XvWBdguqksJo1Emjn4tjSyGVV NKoWikpj5qIFaSgcFxKjvuSekvWTGsM/lv3oGBaocuNG7CXbxhk2e0iCCBuW0/FljkZ5 c0gx6QAuB1IR1L5O+EC21v+IbvwvKoqLVAAFdPKHtDSJCercblQ1jXRwVF15FlxaUGQ+ NR+LidL5f3V4y9o30Tyj8gspF1wH2kO/HfNX2oQUHNVZdszmbnPnQZVO2KOcW0o5sqBD Q+xUyg273mZ17gJCFiN159OcLQ60tnW6gCltAdtTmTcueJpmhfjq/07dwf0lIhjvaZTB wEkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=g8Qxxr973CKgRqCmKN26EopjZ8RkwC/Aw0jJ2VMnDXw=; b=O4FkP8ceR/bp32Dt3wekJTqTDE3VqwjV88eKnOTbfPL9rT//tJ0dRiBZmLE8nxqNZp 2dAar7WBmWTcpOKRo7AnCrC/BJCjwRo8edX8yeA6nqsm4KTFhWT8zO0DpRZAHXBVS5NY O2epna7DAbtmOF4sqlr+YkNP1pW3qEjEX7XtQO3Tfyd414NRHNaIAzzHPJW5P4RBeNtk qROPV2vSxx3YVnkhq9VKAe2XA//HLrwx2jJthdix8g9ygU/4pC5uFzlssu8JVNdDawUj 1HY/WWjtOjWZyicK1S0hHCg8/96lsGZmNGBaYCoCACNimcPq7AYG3FNTdtfVQGTkKXEH 498Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=T7PdF5FE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o6-v6si6573867pls.234.2018.05.18.00.51.57; Fri, 18 May 2018 00:52:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=T7PdF5FE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752466AbeERHuW (ORCPT + 99 others); Fri, 18 May 2018 03:50:22 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:44684 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752401AbeERHuS (ORCPT ); Fri, 18 May 2018 03:50:18 -0400 Received: by mail-qt0-f193.google.com with SMTP id d3-v6so9148334qtp.11; Fri, 18 May 2018 00:50:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=g8Qxxr973CKgRqCmKN26EopjZ8RkwC/Aw0jJ2VMnDXw=; b=T7PdF5FE+xh6YqBr3c5sAXF63c8EgGRq630PlWiO2BlXx0noiFb+oFzTuyRotUehiQ u4pf0UbjkRv8QhRkwvy62PubLt0ahbFekOfrgiC0Q6h/dlE5Bz926onf7sBYetCzVwRi DTu0zD5aJR7bxq+VPdS/CDDq+vGoqXyMBH+jVrFJNpHBWR6Sv5d8iOWQf1HzbqHZrfJZ 8JtBttrmMoDWLGOcHrGRj7EX0FUey2+SbnnWrZ0Y0Uu37Y0YeRIvR1hC9S0VVRCi4vke dDAs0hmrvSoQq3yptD6rWl7JcCEOC6GgtWkQsc6309RaFtbxp8wt2oMPZ18Ug3Uq8+XI lZjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=g8Qxxr973CKgRqCmKN26EopjZ8RkwC/Aw0jJ2VMnDXw=; b=hc1oCOIbQLZeVbEl04Yq42cIL4Jx621QDN7u6+vS8DT4Yj1nHh2iAYX/geKKHtI2y5 DF7fa6I8Gbap0/5w9sFzd7xqErm1VTQaoz7iOYPA4RstCh5ab+LdwK/t3WHoZzDcvgiS qfadSeVAVywwNBFvQB0rDzNJ/3zLeRy5UYGh/NKtEv8jLpyBmeJ7Vph867oMQXA3xaoL 7njrSy9wCGRw6rNW6mCCqHJFTQx0peBbCHBa5AmTUTdvIht2OtlQPY8j3zEjyV8i3M3m Gj2ttuL9Kh5VqmvlsErq7B8JASWtAwXMGDX4tg35X93k2r5WAOGE4WtlKgiPUTbiEe44 KeIw== X-Gm-Message-State: ALKqPweaMnkdjLxKCl5LCn3IpbrbRkQYCNhwRCYx0eGdcclt4tHIbf3z /9FNuXFbmAqXyJjN6gj12JsBzjCQag== X-Received: by 2002:ac8:22d4:: with SMTP id g20-v6mr8062591qta.159.1526629816682; Fri, 18 May 2018 00:50:16 -0700 (PDT) Received: from localhost.localdomain (c-71-234-172-214.hsd1.vt.comcast.net. [71.234.172.214]) by smtp.gmail.com with ESMTPSA id s64-v6sm5443004qkl.85.2018.05.18.00.50.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 May 2018 00:50:15 -0700 (PDT) From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Kent Overstreet , Andrew Morton , Dave Chinner , darrick.wong@oracle.com, tytso@mit.edu, linux-btrfs@vger.kernel.org, clm@fb.com, jbacik@fb.com, viro@zeniv.linux.org.uk, willy@infradead.org, peterz@infradead.org Subject: [PATCH 08/10] bcache: move closures to lib/ Date: Fri, 18 May 2018 03:49:13 -0400 Message-Id: <20180518074918.13816-16-kent.overstreet@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180518074918.13816-1-kent.overstreet@gmail.com> References: <20180518074918.13816-1-kent.overstreet@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Prep work for bcachefs - being a fork of bcache it also uses closures Signed-off-by: Kent Overstreet --- drivers/md/bcache/Kconfig | 10 +--------- drivers/md/bcache/Makefile | 6 +++--- drivers/md/bcache/bcache.h | 2 +- drivers/md/bcache/super.c | 1 - drivers/md/bcache/util.h | 3 +-- {drivers/md/bcache => include/linux}/closure.h | 17 ++++++++--------- lib/Kconfig | 3 +++ lib/Kconfig.debug | 9 +++++++++ lib/Makefile | 2 ++ {drivers/md/bcache => lib}/closure.c | 17 ++++++++--------- 10 files changed, 36 insertions(+), 34 deletions(-) rename {drivers/md/bcache => include/linux}/closure.h (97%) rename {drivers/md/bcache => lib}/closure.c (95%) diff --git a/drivers/md/bcache/Kconfig b/drivers/md/bcache/Kconfig index 4d200883c5..45f1094c08 100644 --- a/drivers/md/bcache/Kconfig +++ b/drivers/md/bcache/Kconfig @@ -1,6 +1,7 @@ config BCACHE tristate "Block device as cache" + select CLOSURES ---help--- Allows a block device to be used as cache for other devices; uses a btree for indexing and the layout is optimized for SSDs. @@ -15,12 +16,3 @@ config BCACHE_DEBUG Enables extra debugging tools, allows expensive runtime checks to be turned on. - -config BCACHE_CLOSURES_DEBUG - bool "Debug closures" - depends on BCACHE - select DEBUG_FS - ---help--- - Keeps all active closures in a linked list and provides a debugfs - interface to list them, which makes it possible to see asynchronous - operations that get stuck. diff --git a/drivers/md/bcache/Makefile b/drivers/md/bcache/Makefile index d26b351958..2b790fb813 100644 --- a/drivers/md/bcache/Makefile +++ b/drivers/md/bcache/Makefile @@ -2,8 +2,8 @@ obj-$(CONFIG_BCACHE) += bcache.o -bcache-y := alloc.o bset.o btree.o closure.o debug.o extents.o\ - io.o journal.o movinggc.o request.o stats.o super.o sysfs.o trace.o\ - util.o writeback.o +bcache-y := alloc.o bset.o btree.o debug.o extents.o io.o\ + journal.o movinggc.o request.o stats.o super.o sysfs.o trace.o util.o\ + writeback.o CFLAGS_request.o += -Iblock diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index 12e5197f18..d954dc44dd 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h @@ -180,6 +180,7 @@ #include #include +#include #include #include #include @@ -191,7 +192,6 @@ #include "bset.h" #include "util.h" -#include "closure.h" struct bucket { atomic_t pin; diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index f2273143b3..5f1ac8e0a3 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -2148,7 +2148,6 @@ static int __init bcache_init(void) mutex_init(&bch_register_lock); init_waitqueue_head(&unregister_wait); register_reboot_notifier(&reboot); - closure_debug_init(); bcache_major = register_blkdev(0, "bcache"); if (bcache_major < 0) { diff --git a/drivers/md/bcache/util.h b/drivers/md/bcache/util.h index a6763db7f0..a75523ed0d 100644 --- a/drivers/md/bcache/util.h +++ b/drivers/md/bcache/util.h @@ -4,6 +4,7 @@ #define _BCACHE_UTIL_H #include +#include #include #include #include @@ -12,8 +13,6 @@ #include #include -#include "closure.h" - #define PAGE_SECTORS (PAGE_SIZE / 512) struct closure; diff --git a/drivers/md/bcache/closure.h b/include/linux/closure.h similarity index 97% rename from drivers/md/bcache/closure.h rename to include/linux/closure.h index 2392a46bcd..1072bf2c13 100644 --- a/drivers/md/bcache/closure.h +++ b/include/linux/closure.h @@ -154,7 +154,7 @@ struct closure { atomic_t remaining; -#ifdef CONFIG_BCACHE_CLOSURES_DEBUG +#ifdef CONFIG_DEBUG_CLOSURES #define CLOSURE_MAGIC_DEAD 0xc054dead #define CLOSURE_MAGIC_ALIVE 0xc054a11e @@ -183,15 +183,13 @@ static inline void closure_sync(struct closure *cl) __closure_sync(cl); } -#ifdef CONFIG_BCACHE_CLOSURES_DEBUG +#ifdef CONFIG_DEBUG_CLOSURES -void closure_debug_init(void); void closure_debug_create(struct closure *cl); void closure_debug_destroy(struct closure *cl); #else -static inline void closure_debug_init(void) {} static inline void closure_debug_create(struct closure *cl) {} static inline void closure_debug_destroy(struct closure *cl) {} @@ -199,21 +197,21 @@ static inline void closure_debug_destroy(struct closure *cl) {} static inline void closure_set_ip(struct closure *cl) { -#ifdef CONFIG_BCACHE_CLOSURES_DEBUG +#ifdef CONFIG_DEBUG_CLOSURES cl->ip = _THIS_IP_; #endif } static inline void closure_set_ret_ip(struct closure *cl) { -#ifdef CONFIG_BCACHE_CLOSURES_DEBUG +#ifdef CONFIG_DEBUG_CLOSURES cl->ip = _RET_IP_; #endif } static inline void closure_set_waiting(struct closure *cl, unsigned long f) { -#ifdef CONFIG_BCACHE_CLOSURES_DEBUG +#ifdef CONFIG_DEBUG_CLOSURES cl->waiting_on = f; #endif } @@ -242,6 +240,7 @@ static inline void closure_queue(struct closure *cl) */ BUILD_BUG_ON(offsetof(struct closure, fn) != offsetof(struct work_struct, func)); + if (wq) { INIT_WORK(&cl->work, cl->work.func); queue_work(wq, &cl->work); @@ -254,7 +253,7 @@ static inline void closure_queue(struct closure *cl) */ static inline void closure_get(struct closure *cl) { -#ifdef CONFIG_BCACHE_CLOSURES_DEBUG +#ifdef CONFIG_DEBUG_CLOSURES BUG_ON((atomic_inc_return(&cl->remaining) & CLOSURE_REMAINING_MASK) <= 1); #else @@ -270,7 +269,7 @@ static inline void closure_get(struct closure *cl) */ static inline void closure_init(struct closure *cl, struct closure *parent) { - memset(cl, 0, sizeof(struct closure)); + cl->fn = NULL; cl->parent = parent; if (parent) closure_get(parent); diff --git a/lib/Kconfig b/lib/Kconfig index e960894993..eff939519e 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -393,6 +393,9 @@ config ASSOCIATIVE_ARRAY for more information. +config CLOSURES + bool + config HAS_IOMEM bool depends on !NO_IOMEM diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 64155e310a..427292a759 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1362,6 +1362,15 @@ config DEBUG_CREDENTIALS source "kernel/rcu/Kconfig.debug" +config DEBUG_CLOSURES + bool "Debug closures (bcache async widgits)" + depends on CLOSURES + select DEBUG_FS + ---help--- + Keeps all active closures in a linked list and provides a debugfs + interface to list them, which makes it possible to see asynchronous + operations that get stuck. + config DEBUG_WQ_FORCE_RR_CPU bool "Force round-robin CPU selection for unbound work items" depends on DEBUG_KERNEL diff --git a/lib/Makefile b/lib/Makefile index 5db5a7fb1e..66d2231d70 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -172,6 +172,8 @@ obj-$(CONFIG_ATOMIC64_SELFTEST) += atomic64_test.o obj-$(CONFIG_CPU_RMAP) += cpu_rmap.o +obj-$(CONFIG_CLOSURES) += closure.o + obj-$(CONFIG_CORDIC) += cordic.o obj-$(CONFIG_DQL) += dynamic_queue_limits.o diff --git a/drivers/md/bcache/closure.c b/lib/closure.c similarity index 95% rename from drivers/md/bcache/closure.c rename to lib/closure.c index 7f12920c14..025f8d8f48 100644 --- a/drivers/md/bcache/closure.c +++ b/lib/closure.c @@ -5,13 +5,12 @@ * Copyright 2012 Google, Inc. */ +#include #include -#include +#include #include #include -#include "closure.h" - static inline void closure_put_after_sub(struct closure *cl, int flags) { int r = flags & CLOSURE_REMAINING_MASK; @@ -126,7 +125,7 @@ void __sched __closure_sync(struct closure *cl) } EXPORT_SYMBOL(__closure_sync); -#ifdef CONFIG_BCACHE_CLOSURES_DEBUG +#ifdef CONFIG_DEBUG_CLOSURES static LIST_HEAD(closure_list); static DEFINE_SPINLOCK(closure_list_lock); @@ -162,6 +161,7 @@ static struct dentry *debug; static int debug_seq_show(struct seq_file *f, void *data) { struct closure *cl; + spin_lock_irq(&closure_list_lock); list_for_each_entry(cl, &closure_list, all) { @@ -180,7 +180,7 @@ static int debug_seq_show(struct seq_file *f, void *data) seq_printf(f, " W %pF\n", (void *) cl->waiting_on); - seq_printf(f, "\n"); + seq_puts(f, "\n"); } spin_unlock_irq(&closure_list_lock); @@ -199,12 +199,11 @@ static const struct file_operations debug_ops = { .release = single_release }; -void __init closure_debug_init(void) +static int __init closure_debug_init(void) { debug = debugfs_create_file("closures", 0400, NULL, NULL, &debug_ops); + return 0; } +late_initcall(closure_debug_init) #endif - -MODULE_AUTHOR("Kent Overstreet "); -MODULE_LICENSE("GPL"); -- 2.17.0