On Mon, Mar 25, 2019 at 02:31:23PM +0200, Nikolay Borisov wrote: > During device shrink pinned/pending chunks (i.e those which have been > deleted/created respectively, in the current transaction and haven't > touched disk) need to be accounted when doing device shrink. Presently > this happens after the main relocation loop in btrfs_shrink_device, > which could lead to making another go in the body of the function. > > Since there is no hard requirement to perform pinned/pending chunks > handling after the relocation loop, move the code before it. This leads > to simplifying the code flow around - i.e no need to use 'goto again'. > > Signed-off-by: Nikolay Borisov <nborisov@xxxxxxxx> > --- > fs/btrfs/volumes.c | 54 ++++++++++++++++++---------------------------- > 1 file changed, 21 insertions(+), 33 deletions(-) > > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c > index 3f81380265e5..b49cc5ad758e 100644 > --- a/fs/btrfs/volumes.c > +++ b/fs/btrfs/volumes.c > @@ -4722,15 +4722,15 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) > int slot; > int failed = 0; > bool retried = false; > - bool checked_pending_chunks = false; > struct extent_buffer *l; > struct btrfs_key key; > struct btrfs_super_block *super_copy = fs_info->super_copy; > u64 old_total = btrfs_super_total_bytes(super_copy); > u64 old_size = btrfs_device_get_total_bytes(device); > u64 diff; > + u64 start; > > - new_size = round_down(new_size, fs_info->sectorsize); > + start = new_size = round_down(new_size, fs_info->sectorsize); > diff = round_down(old_size - new_size, fs_info->sectorsize); > > if (test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) > @@ -4742,6 +4742,10 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) > > path->reada = READA_BACK; > > + trans = btrfs_start_transaction(root, 0); > + if (IS_ERR(trans)) path is leaked here > + return PTR_ERR(trans); > + > mutex_lock(&fs_info->chunk_mutex); > > btrfs_device_set_total_bytes(device, new_size);
