From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0959BC43381 for ; Mon, 25 Mar 2019 15:14:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D70AE20879 for ; Mon, 25 Mar 2019 15:14:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729036AbfCYPO4 (ORCPT ); Mon, 25 Mar 2019 11:14:56 -0400 Received: from mx2.suse.de ([195.135.220.15]:58546 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726010AbfCYPO4 (ORCPT ); Mon, 25 Mar 2019 11:14:56 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 57CBFABA1 for ; Mon, 25 Mar 2019 15:14:55 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 7667BDA825; Mon, 25 Mar 2019 16:16:08 +0100 (CET) Date: Mon, 25 Mar 2019 16:16:07 +0100 From: David Sterba To: Nikolay Borisov Cc: linux-btrfs@vger.kernel.org Subject: Re: [PATCH v3 03/12] btrfs: Handle pending/pinned chunks before blockgroup relocation during device shrink Message-ID: <20190325151607.GG10640@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Nikolay Borisov , linux-btrfs@vger.kernel.org References: <20190325123132.27835-1-nborisov@suse.com> <20190325123132.27835-4-nborisov@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190325123132.27835-4-nborisov@suse.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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 > --- > 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);