linux-next.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Rothwell <sfr@canb.auug.org.au>
To: David Sterba <dsterba@suse.cz>
Cc: Linux Next Mailing List <linux-next@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Filipe Manana <fdmanana@suse.com>, Qu Wenruo <wqu@suse.com>,
	Josef Bacik <josef@toxicpanda.com>
Subject: linux-next: manual merge of the btrfs-kdave tree with the btrfs-fixes tree
Date: Thu, 8 Aug 2019 10:54:54 +1000	[thread overview]
Message-ID: <20190808105454.7b09b26b@canb.auug.org.au> (raw)

[-- Attachment #1: Type: text/plain, Size: 5991 bytes --]

Hi all,

Today's linux-next merge of the btrfs-kdave tree got conflicts in:

  fs/btrfs/ctree.h
  fs/btrfs/extent-tree.c

between commits:

  d7cd4dd907c1 ("Btrfs: fix sysfs warning and missing raid sysfs directories")
  07301df7d2fc ("btrfs: trim: Check the range passed into to prevent overflow")

from the btrfs-fixes tree and commit:

  4dfbf33fbfb6 ("btrfs: migrate the block group lookup code")
  f35f767acec1 ("btrfs: move sysfs declarations out of ctree.h")
  76c49f86437b ("btrfs: factor sysfs code out of link_block_group")

from the btrfs-kdave tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

I also added this patch:

From: Stephen Rothwell <sfr@canb.auug.org.au>
Date: Thu, 8 Aug 2019 10:14:25 +1000
Subject: [PATCH] btrfs: merge fix up for "Btrfs: fix sysfs warning and missing
 raid sysfs directories"

Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
---
 fs/btrfs/sysfs.c | 52 +++++++++++++++++++-----------------------------
 1 file changed, 21 insertions(+), 31 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 600db4be740d..ee6f70e8f258 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -4,6 +4,7 @@
  */
 
 #include <linux/sched.h>
+#include <linux/sched/mm.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/completion.h>
@@ -27,7 +28,6 @@ struct btrfs_feature_attr {
 struct raid_kobject {
 	u64 flags;
 	struct kobject kobj;
-	struct list_head list;
 };
 
 #define __INIT_KOBJ_ATTR(_name, _mode, _show, _store)			\
@@ -819,33 +819,6 @@ static void init_feature_attrs(void)
 	}
 }
 
-/* link_block_group will queue up kobjects to add when we're reclaim-safe */
-void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info)
-{
-	struct btrfs_space_info *space_info;
-	struct raid_kobject *rkobj;
-	LIST_HEAD(list);
-	int ret = 0;
-
-	spin_lock(&fs_info->pending_raid_kobjs_lock);
-	list_splice_init(&fs_info->pending_raid_kobjs, &list);
-	spin_unlock(&fs_info->pending_raid_kobjs_lock);
-
-	list_for_each_entry(rkobj, &list, list) {
-		space_info = btrfs_find_space_info(fs_info, rkobj->flags);
-
-		ret = kobject_add(&rkobj->kobj, &space_info->kobj,
-				"%s", btrfs_bg_type_to_raid_name(rkobj->flags));
-		if (ret) {
-			kobject_put(&rkobj->kobj);
-			break;
-		}
-	}
-	if (ret)
-		btrfs_warn(fs_info,
-			   "failed to add kobject for block cache, ignoring");
-}
-
 /*
  * Create a sysfs entry for a given block group type at path
  * /sys/fs/btrfs/UUID/allocation/data/TYPE
@@ -855,10 +828,21 @@ void btrfs_sysfs_add_block_group_type(struct btrfs_block_group_cache *cache)
 	struct btrfs_fs_info *fs_info = cache->fs_info;
 	struct btrfs_space_info *space_info = cache->space_info;
 	struct raid_kobject *rkobj;
+	unsigned int nofs_flag;
+	int ret;
 	const int index = btrfs_bg_flags_to_raid_index(cache->flags);
 
+	/*
+	 * Setup a NOFS context because kobject_add(), deep in its call
+	 * chain, does GFP_KERNEL allocations, and we are often called
+	 * in a context where if reclaim is triggered we can deadlock
+	 * (we are either holding a transaction handle or some lock
+	 * required for a transaction commit).
+	 */
+	nofs_flag = memalloc_nofs_save();
 	rkobj = kzalloc(sizeof(*rkobj), GFP_NOFS);
 	if (!rkobj) {
+		memalloc_nofs_restore(nofs_flag);
 		btrfs_warn(cache->fs_info,
 				"couldn't alloc memory for raid level kobject");
 		return;
@@ -867,9 +851,15 @@ void btrfs_sysfs_add_block_group_type(struct btrfs_block_group_cache *cache)
 	rkobj->flags = cache->flags;
 	kobject_init(&rkobj->kobj, &btrfs_raid_ktype);
 
-	spin_lock(&fs_info->pending_raid_kobjs_lock);
-	list_add_tail(&rkobj->list, &fs_info->pending_raid_kobjs);
-	spin_unlock(&fs_info->pending_raid_kobjs_lock);
+	ret = kobject_add(&rkobj->kobj, &space_info->kobj, "%s",
+			  btrfs_bg_type_to_raid_name(rkobj->flags));
+	memalloc_nofs_restore(nofs_flag);
+	if (ret) {
+		kobject_put(&rkobj->kobj);
+		btrfs_warn(fs_info,
+		   "failed to add kobject for block cache, ignoring");
+		return;
+	}
 	space_info->block_group_kobjs[index] = &rkobj->kobj;
 }
 
-- 
2.20.1


-- 
Cheers,
Stephen Rothwell

diff --cc fs/btrfs/ctree.h
index 94660063a162,357316173d84..000000000000
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
diff --cc fs/btrfs/extent-tree.c
index 8b7eb22d508a,ad15d05e256b..000000000000
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@@ -8976,27 -8751,20 +8752,27 @@@ int btrfs_trim_fs(struct btrfs_fs_info 
  	int dev_ret = 0;
  	int ret = 0;
  
 +	/*
 +	 * Check range overflow if range->len is set.
 +	 * The default range->len is U64_MAX.
 +	 */
 +	if (range->len != U64_MAX &&
 +	    check_add_overflow(range->start, range->len, &range_end))
 +		return -EINVAL;
 +
  	cache = btrfs_lookup_first_block_group(fs_info, range->start);
- 	for (; cache; cache = next_block_group(cache)) {
+ 	for (; cache; cache = btrfs_next_block_group(cache)) {
 -		if (cache->key.objectid >= (range->start + range->len)) {
 +		if (cache->key.objectid >= range_end) {
  			btrfs_put_block_group(cache);
  			break;
  		}
  
  		start = max(range->start, cache->key.objectid);
 -		end = min(range->start + range->len,
 -				cache->key.objectid + cache->key.offset);
 +		end = min(range_end, cache->key.objectid + cache->key.offset);
  
  		if (end - start >= range->minlen) {
- 			if (!block_group_cache_done(cache)) {
- 				ret = cache_block_group(cache, 0);
+ 			if (!btrfs_block_group_cache_done(cache)) {
+ 				ret = btrfs_cache_block_group(cache, 0);
  				if (ret) {
  					bg_failed++;
  					bg_ret = ret;

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

             reply	other threads:[~2019-08-08  0:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-08  0:54 Stephen Rothwell [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-04-04 23:03 linux-next: manual merge of the btrfs-kdave tree with the btrfs-fixes tree Stephen Rothwell
2018-05-15 23:47 Stephen Rothwell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190808105454.7b09b26b@canb.auug.org.au \
    --to=sfr@canb.auug.org.au \
    --cc=dsterba@suse.cz \
    --cc=fdmanana@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=wqu@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).