From mboxrd@z Thu Jan 1 00:00:00 1970 From: Chris Mason Subject: Re: [PATCH 3/3] btrfs: extended inode refs Date: Thu, 10 May 2012 09:35:09 -0400 Message-ID: <20120510133509.GB11859@shiny> References: <1333656543-4843-1-git-send-email-mfasheh@suse.de> <1333656543-4843-4-git-send-email-mfasheh@suse.de> <4F871808.3050309@jan-o-sch.net> <20120508225739.GW17950@wotan.suse.de> <20120509170228.GA4025@shiny> <4FAB7B00.4090302@jan-o-sch.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Mark Fasheh , linux-btrfs@vger.kernel.org, Josef Bacik To: Jan Schmidt Return-path: In-Reply-To: <4FAB7B00.4090302@jan-o-sch.net> List-ID: On Thu, May 10, 2012 at 10:23:28AM +0200, Jan Schmidt wrote: > On Wed, May 09, 2012 at 19:02 (+0200), Chris Mason wrote: > >>>> + > >>>> + while (1) { > >>>> + ret = btrfs_find_one_extref(fs_root, inum, offset, path, &iref2, > >>>> + &offset); > >>>> + if (ret < 0) > >>>> + break; > >>>> + if (ret) { > >>>> + ret = found ? 0 : -ENOENT; > >>>> + break; > >>>> + } > >>>> + ++found; > >>>> + > >>>> + slot = path->slots[0]; > >>>> + eb = path->nodes[0]; > >>>> + /* make sure we can use eb after releasing the path */ > >>>> + atomic_inc(&eb->refs); > >>> > >>> You need a blocking read lock here, too. Grab it before releasing the path. > > > > If you're calling btrfs_search_slot, it will give you a blocking lock > > on the leaf. If you set path->leave_spinning before the call, you'll > > have a spinning lock on the leaf. > > > > If you unlock a block that you got from a path (like eb = > > path->nodes[0]), the path structure has a flag for each level that > > indicates if that block was locked or not. See btrfs_release_path(). > > So, don't fiddle the locks without fiddling the paths. > > > > You can switch from spinning to/from blocking without touching the path, it > > figures that out. > > Note that we're releasing the path shortly after. My suggestion was to > grab an *additional* read lock after atomic_inc(&eb->refs) (probably > better extent_buffer_get(eb)) and before btrfs_path_release(). > > An alternative would be to set path->locks[0] to NULL, which would > btrfs_release_path prevent from unlocking it, kidnapping its lock for > our purpose. But I much prefer the open coded solution. Thanks, I see now. -chris