From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 5/6] btrfs: Make free_objectid hold the next available objectid in the root
Date: Mon, 7 Dec 2020 17:32:36 +0200 [thread overview]
Message-ID: <20201207153237.1073887-6-nborisov@suse.com> (raw)
In-Reply-To: <20201207153237.1073887-1-nborisov@suse.com>
Adjust the way free_objectid is being initialized, it now stores
BTRFS_FIRST_FREE_OBJECTID rather than the, somewhat arbitrary,
BTRFS_FIRST_FREE_OBJECTID - 1. This change also has the added benefit
that now it becomes unnecessary to explicitly initialize free_objectid
for a newly create fs root.
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
fs/btrfs/disk-io.c | 8 ++++----
fs/btrfs/inode.c | 8 ++++++--
fs/btrfs/ioctl.c | 4 ----
3 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index e96103b1c5db..6a4d7ea61903 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -4762,10 +4762,10 @@ int btrfs_init_root_free_objectid(struct btrfs_root *root)
slot = path->slots[0] - 1;
l = path->nodes[0];
btrfs_item_key_to_cpu(l, &found_key, slot);
- root->free_objectid = max_t(u64, found_key.objectid,
- BTRFS_FIRST_FREE_OBJECTID - 1);
+ root->free_objectid = max_t(u64, found_key.objectid + 1,
+ BTRFS_FIRST_FREE_OBJECTID);
} else {
- root->free_objectid = BTRFS_FIRST_FREE_OBJECTID - 1;
+ root->free_objectid = BTRFS_FIRST_FREE_OBJECTID;
}
ret = 0;
error:
@@ -4786,7 +4786,7 @@ int btrfs_get_free_objectid(struct btrfs_root *root, u64 *objectid)
goto out;
}
- *objectid = ++root->free_objectid;
+ *objectid = root->free_objectid++;
ret = 0;
out:
mutex_unlock(&root->objectid_mutex);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 0dee1fa29207..aea76abd83ba 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -8583,9 +8583,13 @@ int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
struct inode *inode;
int err;
u64 index = 0;
+ u64 ino;
+
+ err = btrfs_get_free_objectid(new_root, &ino);
+ if (err < 0)
+ return err;
- inode = btrfs_new_inode(trans, new_root, NULL, "..", 2,
- new_dirid, new_dirid,
+ inode = btrfs_new_inode(trans, new_root, NULL, "..", 2, ino, ino,
S_IFDIR | (~current_umask() & S_IRWXUGO),
&index);
if (IS_ERR(inode))
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 21c0215a0fd0..58b9a27559c0 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -724,10 +724,6 @@ static noinline int create_subvol(struct inode *dir,
goto fail;
}
- mutex_lock(&new_root->objectid_mutex);
- new_root->free_objectid = new_dirid;
- mutex_unlock(&new_root->objectid_mutex);
-
/*
* insert the directory item
*/
--
2.25.1
next prev parent reply other threads:[~2020-12-07 15:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-07 15:32 [PATCH 0/6] Overhaul free objectid code Nikolay Borisov
2020-12-07 15:32 ` [PATCH 1/6] btrfs: Rename btrfs_find_highest_objectid to btrfs_init_root_free_objectid Nikolay Borisov
2020-12-07 15:32 ` [PATCH 2/6] btrfs: Rename btrfs_find_free_objectid to btrfs_get_free_objectid Nikolay Borisov
2020-12-07 15:32 ` [PATCH 3/6] btrfs: Remove useless ASSERTS Nikolay Borisov
2020-12-15 16:58 ` David Sterba
2020-12-15 17:48 ` Nikolay Borisov
2020-12-18 15:03 ` David Sterba
2020-12-07 15:32 ` [PATCH 4/6] btrfs: Rename highest_objectid to free_objectid Nikolay Borisov
2020-12-07 15:32 ` Nikolay Borisov [this message]
2020-12-07 15:32 ` [PATCH 6/6] btrfs: Remove new_dirid argument from btrfs_create_subvol_root Nikolay Borisov
2020-12-07 16:19 ` [RESEND PATCH] btrfs: Add test 154 Nikolay Borisov
2020-12-20 14:32 ` Eryu Guan
2020-12-07 16:27 ` [PATCH 0/6] Overhaul free objectid code Josef Bacik
2020-12-15 17:08 ` 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=20201207153237.1073887-6-nborisov@suse.com \
--to=nborisov@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