From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 2/4] btrfs: detect uninitialized btrfs_root::anon_dev for user visible subvolumes
Date: Tue, 16 Jun 2020 10:17:35 +0800 [thread overview]
Message-ID: <20200616021737.44617-3-wqu@suse.com> (raw)
In-Reply-To: <20200616021737.44617-1-wqu@suse.com>
btrfs_root::anon_dev is an indicator for different subvolume namespaces.
Thus it should always be initialized to an anonymous block device.
Add a safe net to catch such uninitialized values.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/inode.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 00647e8cf2df..195aac71fe32 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -8697,6 +8697,7 @@ static int btrfs_getattr(const struct path *path, struct kstat *stat,
{
u64 delalloc_bytes;
struct inode *inode = d_inode(path->dentry);
+ struct btrfs_root *root = BTRFS_I(inode)->root;
u32 blocksize = inode->i_sb->s_blocksize;
u32 bi_flags = BTRFS_I(inode)->flags;
@@ -8718,7 +8719,13 @@ static int btrfs_getattr(const struct path *path, struct kstat *stat,
STATX_ATTR_NODUMP);
generic_fillattr(inode, stat);
- stat->dev = BTRFS_I(inode)->root->anon_dev;
+ if (unlikely(!root->anon_dev)) {
+ WARN_ON(IS_ENABLED(CONFIG_BTRFS_DEBUG));
+ btrfs_warn(root->fs_info,
+ "uninitialized btrfs_root::anon_dev detected, root=%llu",
+ root->root_key.objectid);
+ }
+ stat->dev = root->anon_dev;
spin_lock(&BTRFS_I(inode)->lock);
delalloc_bytes = BTRFS_I(inode)->new_delalloc_bytes;
--
2.27.0
next prev parent reply other threads:[~2020-06-16 2:17 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-16 2:17 [PATCH 0/4] btrfs: workaround exhausted anonymous block device pool Qu Wenruo
2020-06-16 2:17 ` [PATCH 1/4] btrfs: disk-io: don't allocate anonymous block device for user invisible roots Qu Wenruo
2020-06-16 19:21 ` Josef Bacik
2020-06-16 2:17 ` Qu Wenruo [this message]
2020-06-16 19:25 ` [PATCH 2/4] btrfs: detect uninitialized btrfs_root::anon_dev for user visible subvolumes Josef Bacik
2020-06-16 22:49 ` Qu Wenruo
2020-06-16 23:32 ` Josef Bacik
2020-06-16 23:49 ` Qu Wenruo
2020-06-17 11:31 ` David Sterba
2020-06-17 13:37 ` Josef Bacik
2020-06-17 23:39 ` Qu Wenruo
2020-06-16 2:17 ` [PATCH 3/4] btrfs: preallocate anon_dev for subvolume and snapshot creation Qu Wenruo
2020-06-16 15:10 ` David Sterba
2020-06-16 22:54 ` Qu Wenruo
2020-07-01 3:25 ` Qu Wenruo
2020-07-01 17:39 ` David Sterba
2020-07-01 23:56 ` Qu Wenruo
2020-07-02 16:08 ` David Sterba
2020-07-02 23:46 ` David Sterba
2020-07-03 5:19 ` Qu Wenruo
2020-07-03 12:29 ` David Sterba
2020-07-03 12:39 ` Qu Wenruo
2020-06-16 2:17 ` [PATCH 4/4] btrfs: free anon_dev earlier to prevent exhausting anonymous block device pool Qu Wenruo
2020-06-16 19:23 ` Josef Bacik
2020-06-16 22:48 ` David Sterba
2020-06-16 23:31 ` Josef Bacik
2020-06-30 14:14 ` [PATCH 0/4] btrfs: workaround exhausted " David Sterba
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=20200616021737.44617-3-wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/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