From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH RFC 2/3] btrfs: Update per-profile available space when device size/used space get updated
Date: Wed, 25 Dec 2019 21:39:37 +0800 [thread overview]
Message-ID: <20191225133938.115733-3-wqu@suse.com> (raw)
In-Reply-To: <20191225133938.115733-1-wqu@suse.com>
There are 4 locations where device size or used space get updated:
- Chunk allocation
- Chunk removal
- Device grow
- Device shrink
Now also update per-profile available space at those timings.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/volumes.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 8d4be1d48f2f..92d45a406d98 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2799,6 +2799,7 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
struct btrfs_super_block *super_copy = fs_info->super_copy;
u64 old_total;
u64 diff;
+ int ret;
if (!test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state))
return -EACCES;
@@ -2827,6 +2828,11 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
&trans->transaction->dev_update_list);
mutex_unlock(&fs_info->chunk_mutex);
+ mutex_lock(&fs_info->fs_devices->device_list_mutex);
+ ret = calc_per_profile_avail(fs_info);
+ mutex_unlock(&fs_info->fs_devices->device_list_mutex);
+ if (ret < 0)
+ return ret;
return btrfs_update_device(trans, device);
}
@@ -3005,7 +3011,12 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset)
goto out;
}
}
+ ret = calc_per_profile_avail(fs_info);
mutex_unlock(&fs_devices->device_list_mutex);
+ if (ret < 0) {
+ btrfs_abort_transaction(trans, ret);
+ goto out;
+ }
ret = btrfs_free_chunk(trans, chunk_offset);
if (ret) {
@@ -4821,6 +4832,10 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
device->fs_devices->total_rw_bytes += diff;
atomic64_add(diff, &fs_info->free_chunk_space);
mutex_unlock(&fs_info->chunk_mutex);
+ } else {
+ mutex_lock(&fs_info->fs_devices->device_list_mutex);
+ ret = calc_per_profile_avail(fs_info);
+ mutex_unlock(&fs_info->fs_devices->device_list_mutex);
}
return ret;
}
--
2.24.1
next prev parent reply other threads:[~2019-12-25 13:40 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-25 13:39 [PATCH RFC 0/3] Introduce per-profile available space array to avoid over-confident can_overcommit() Qu Wenruo
2019-12-25 13:39 ` [PATCH RFC 1/3] btrfs: Introduce per-profile available space facility Qu Wenruo
2019-12-30 16:14 ` Josef Bacik
2019-12-25 13:39 ` Qu Wenruo [this message]
2019-12-30 16:17 ` [PATCH RFC 2/3] btrfs: Update per-profile available space when device size/used space get updated Josef Bacik
2019-12-31 0:25 ` Qu Wenruo
2019-12-25 13:39 ` [PATCH RFC 3/3] btrfs: space-info: Use per-profile available space in can_overcommit() Qu Wenruo
2019-12-30 16:17 ` Josef Bacik
2019-12-27 18:32 ` [PATCH RFC 0/3] Introduce per-profile available space array to avoid over-confident can_overcommit() Josef Bacik
2019-12-28 1:09 ` Qu Wenruo
2019-12-30 14:29 ` Josef Bacik
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=20191225133938.115733-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;
as well as URLs for NNTP newsgroup(s).