Return-Path: Received: from mx2.suse.de ([195.135.220.15]:59805 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751937AbdLETIQ (ORCPT ); Tue, 5 Dec 2017 14:08:16 -0500 Date: Tue, 5 Dec 2017 20:06:16 +0100 From: David Sterba To: Anand Jain Cc: linux-btrfs@vger.kernel.org Subject: Re: [PATCH v4 1/2] btrfs: add function to device list delete Message-ID: <20171205190616.GU3553@twin.jikos.cz> Reply-To: dsterba@suse.cz References: <20171205085258.4038-1-anand.jain@oracle.com> <20171205085258.4038-2-anand.jain@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii In-Reply-To: <20171205085258.4038-2-anand.jain@oracle.com> Sender: linux-btrfs-owner@vger.kernel.org List-ID: On Tue, Dec 05, 2017 at 04:52:56PM +0800, Anand Jain wrote: > We need device delete from the dev_list so create a new function. > New instead of refactor of btrfs_free_stale_device() because, > btrfs_free_stale_device() doesn't hold device_list_mutex which > is actually needed here. > > Signed-off-by: Anand Jain > --- > v1: title of this patch > btrfs: refactor btrfs_free_stale_device() to get device list delete > v2: > delete_device_from_list() is not pealed from btrfs_free_stale_device() > as this needs device_list_mutex. And its static now. > v3: Send to correct ML > v4: no change > > fs/btrfs/volumes.c | 22 ++++++++++++++++++++++ > 1 file changed, 22 insertions(+) > > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c > index 04164337ac69..5deda80316f0 100644 > --- a/fs/btrfs/volumes.c > +++ b/fs/btrfs/volumes.c > @@ -531,6 +531,28 @@ static void pending_bios_fn(struct btrfs_work *work) > run_scheduled_bios(device); > } > > +static void delete_device_from_list(struct btrfs_device *device) > +{ > + struct btrfs_fs_devices *fs_devices; > + > + fs_devices = device->fs_devices; > + > + lockdep_assert_held(&uuid_mutex); > + > + mutex_lock(&fs_devices->device_list_mutex); > + fs_devices->num_devices--; > + list_del(&device->dev_list); > + mutex_unlock(&fs_devices->device_list_mutex); > + > + rcu_string_free(device->name); > + kfree(device); Please use the new helper introduced in patch "btrfs: introduce free_device helper" (currently in misc-next), you'd leak the flush bio here. > + > + if (fs_devices->num_devices == 0) { > + btrfs_sysfs_remove_fsid(fs_devices); > + list_del(&fs_devices->list); > + free_fs_devices(fs_devices); > + } > +}