linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* odd sysfs find behavior, was: Re: [PATCH v6 00/10] Implement NVMe Namespace Descriptor Identification
       [not found]           ` <CA+55aFxJ0bpRFsnZFe6sh2i4jxNdYmDi_6RZx2CQQdmQ_HU3wQ@mail.gmail.com>
@ 2017-06-17 12:08             ` Christoph Hellwig
  2017-06-18  1:12               ` Greg Kroah-Hartman
  0 siblings, 1 reply; 10+ messages in thread
From: Christoph Hellwig @ 2017-06-17 12:08 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Tejun Heo, Greg Kroah-Hartman, linux-fsdevel

On Fri, Jun 16, 2017 at 10:28:28PM +0900, Linus Torvalds wrote:
> Hmm. The *traditional* reason for this particular 'find' oddity is
> that find has an optimization which will look at the nlink count of a
> directory to decide how many subdirectories it can have.

It looks like sysfs maintains i_nlink properly as far as I can tell.
But I noticed another things that's even more weird:

root@testvm:~/nvmetcli# find /sys -name uuid
root@testvm:~/nvmetcli# find /sys -name uuid
/sys/devices/virtual/nvme-fabrics/ctl/nvme2/nvme2n1/uuid

so just repeating the find a second time makes it work!  Looks like
there is some sort of lazy population scheme in sysfs..

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: odd sysfs find behavior, was: Re: [PATCH v6 00/10] Implement NVMe Namespace Descriptor Identification
  2017-06-17 12:08             ` odd sysfs find behavior, was: Re: [PATCH v6 00/10] Implement NVMe Namespace Descriptor Identification Christoph Hellwig
@ 2017-06-18  1:12               ` Greg Kroah-Hartman
  2017-06-18  7:32                 ` Christoph Hellwig
  0 siblings, 1 reply; 10+ messages in thread
From: Greg Kroah-Hartman @ 2017-06-18  1:12 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Linus Torvalds, Tejun Heo, linux-fsdevel

On Sat, Jun 17, 2017 at 02:08:14PM +0200, Christoph Hellwig wrote:
> On Fri, Jun 16, 2017 at 10:28:28PM +0900, Linus Torvalds wrote:
> > Hmm. The *traditional* reason for this particular 'find' oddity is
> > that find has an optimization which will look at the nlink count of a
> > directory to decide how many subdirectories it can have.
> 
> It looks like sysfs maintains i_nlink properly as far as I can tell.
> But I noticed another things that's even more weird:
> 
> root@testvm:~/nvmetcli# find /sys -name uuid
> root@testvm:~/nvmetcli# find /sys -name uuid
> /sys/devices/virtual/nvme-fabrics/ctl/nvme2/nvme2n1/uuid
> 
> so just repeating the find a second time makes it work!  Looks like
> there is some sort of lazy population scheme in sysfs..

There is a lazy population scheme in sysfs, but that means that things
are only populated in memory when we actually look for them, not the
second time around only :)

I just tried this on my laptop which does have a nvme block device in
it, and it worked just fine both times.

As Linus said, a strace would be great.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: odd sysfs find behavior, was: Re: [PATCH v6 00/10] Implement NVMe Namespace Descriptor Identification
  2017-06-18  1:12               ` Greg Kroah-Hartman
@ 2017-06-18  7:32                 ` Christoph Hellwig
       [not found]                   ` <20170618073305.GB25797@lst.de>
  0 siblings, 1 reply; 10+ messages in thread
From: Christoph Hellwig @ 2017-06-18  7:32 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Christoph Hellwig, Linus Torvalds, Tejun Heo, linux-fsdevel

On Sun, Jun 18, 2017 at 09:12:50AM +0800, Greg Kroah-Hartman wrote:
> > 
> > root@testvm:~/nvmetcli# find /sys -name uuid
> > root@testvm:~/nvmetcli# find /sys -name uuid
> > /sys/devices/virtual/nvme-fabrics/ctl/nvme2/nvme2n1/uuid
> > 
> > so just repeating the find a second time makes it work!  Looks like
> > there is some sort of lazy population scheme in sysfs..
> 
> There is a lazy population scheme in sysfs, but that means that things
> are only populated in memory when we actually look for them, not the
> second time around only :)
> 
> I just tried this on my laptop which does have a nvme block device in
> it, and it worked just fine both times.

Note that the search is for an attribute in the sysfs dir, but trying
to search for the device it doesn't make any difference.

> As Linus said, a strace would be great.

Both straces attached (gzipped due to size).  Note that this on a system
with four NVMe devices, two of which are nvme-loop devices that have the
uuid attribute.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: odd sysfs find behavior, was: Re: [PATCH v6 00/10] Implement NVMe Namespace Descriptor Identification
       [not found]                   ` <20170618073305.GB25797@lst.de>
@ 2017-06-18 10:20                     ` Tejun Heo
  2017-06-18 10:32                       ` Tejun Heo
  2017-06-18 13:43                       ` Christoph Hellwig
  0 siblings, 2 replies; 10+ messages in thread
From: Tejun Heo @ 2017-06-18 10:20 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Greg Kroah-Hartman, Linus Torvalds, linux-fsdevel

Hello, Christoph.

On Sun, Jun 18, 2017 at 09:33:05AM +0200, Christoph Hellwig wrote:
> > Both straces attached (gzipped due to size).  Note that this on a system
> > with four NVMe devices, two of which are nvme-loop devices that have the
> > uuid attribute.
> 
> And now really attached..

If you "cd /sys/kernel/debug/tracing; cd -" before doing the find,
does it succeed the first time?  It could be that the on-demand
mounting of tracefs is giving incoherent results across the mounting
and confusing find.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: odd sysfs find behavior, was: Re: [PATCH v6 00/10] Implement NVMe Namespace Descriptor Identification
  2017-06-18 10:20                     ` Tejun Heo
@ 2017-06-18 10:32                       ` Tejun Heo
  2017-06-18 13:43                       ` Christoph Hellwig
  1 sibling, 0 replies; 10+ messages in thread
From: Tejun Heo @ 2017-06-18 10:32 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Greg Kroah-Hartman, Linus Torvalds, linux-fsdevel

On Sun, Jun 18, 2017 at 06:20:20AM -0400, Tejun Heo wrote:
> Hello, Christoph.
> 
> On Sun, Jun 18, 2017 at 09:33:05AM +0200, Christoph Hellwig wrote:
> > > Both straces attached (gzipped due to size).  Note that this on a system
> > > with four NVMe devices, two of which are nvme-loop devices that have the
> > > uuid attribute.
> > 
> > And now really attached..
> 
> If you "cd /sys/kernel/debug/tracing; cd -" before doing the find,
> does it succeed the first time?  It could be that the on-demand
> mounting of tracefs is giving incoherent results across the mounting
> and confusing find.

Before tracefs is automounted

    File: '/sys/kernel/debug/tracing'
    Size: 0               Blocks: 0          IO Block: 4096   directory
  Device: 8h/8d   Inode: 2054        Links: 3
  Access: (0555/dr-xr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
  Access: 2017-06-18 03:21:26.241000000 -0700
  Modify: 2017-06-18 03:21:26.241000000 -0700
  Change: 2017-06-18 03:21:26.241000000 -0700
   Birth: -

and after

    File: '/sys/kernel/debug/tracing/'
    Size: 0               Blocks: 0          IO Block: 4096   directory
  Device: 9h/9d   Inode: 1           Links: 6
  Access: (0700/drwx------)  Uid: (    0/    root)   Gid: (    0/    root)
  Access: 2017-06-18 03:21:26.241000000 -0700
  Modify: 2017-06-18 03:21:26.241000000 -0700
  Change: 2017-06-18 03:21:26.241000000 -0700
   Birth: -

and it gets mounted while the first find is iterating through it.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: odd sysfs find behavior, was: Re: [PATCH v6 00/10] Implement NVMe Namespace Descriptor Identification
  2017-06-18 10:20                     ` Tejun Heo
  2017-06-18 10:32                       ` Tejun Heo
@ 2017-06-18 13:43                       ` Christoph Hellwig
  2017-06-19 17:59                         ` Tejun Heo
  1 sibling, 1 reply; 10+ messages in thread
From: Christoph Hellwig @ 2017-06-18 13:43 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Christoph Hellwig, Greg Kroah-Hartman, Linus Torvalds,
	linux-fsdevel

On Sun, Jun 18, 2017 at 06:20:20AM -0400, Tejun Heo wrote:
> If you "cd /sys/kernel/debug/tracing; cd -" before doing the find,
> does it succeed the first time?  It could be that the on-demand
> mounting of tracefs is giving incoherent results across the mounting
> and confusing find.

Yes, that works fine:

root@testvm:~# cd /sys/kernel/debug/tracing; cd -
/root
root@testvm:~# find /sys -name uuid
/sys/devices/virtual/nvme-fabrics/ctl/nvme3/nvme3n1/uuid
/sys/devices/virtual/nvme-fabrics/ctl/nvme2/nvme2n1/uuid

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: odd sysfs find behavior, was: Re: [PATCH v6 00/10] Implement NVMe Namespace Descriptor Identification
  2017-06-18 13:43                       ` Christoph Hellwig
@ 2017-06-19 17:59                         ` Tejun Heo
  2017-06-21 14:48                           ` Greg Kroah-Hartman
  2017-06-22  0:21                           ` Linus Torvalds
  0 siblings, 2 replies; 10+ messages in thread
From: Tejun Heo @ 2017-06-19 17:59 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Greg Kroah-Hartman, Linus Torvalds, linux-fsdevel

Hello,

On Sun, Jun 18, 2017 at 03:43:36PM +0200, Christoph Hellwig wrote:
> On Sun, Jun 18, 2017 at 06:20:20AM -0400, Tejun Heo wrote:
> > If you "cd /sys/kernel/debug/tracing; cd -" before doing the find,
> > does it succeed the first time?  It could be that the on-demand
> > mounting of tracefs is giving incoherent results across the mounting
> > and confusing find.
> 
> Yes, that works fine:
> 
> root@testvm:~# cd /sys/kernel/debug/tracing; cd -
> /root
> root@testvm:~# find /sys -name uuid
> /sys/devices/virtual/nvme-fabrics/ctl/nvme3/nvme3n1/uuid
> /sys/devices/virtual/nvme-fabrics/ctl/nvme2/nvme2n1/uuid

So, looks like this is the debugfs automount mechanism changing nlinks
across automounts and confusing find in the process.  Greg?

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: odd sysfs find behavior, was: Re: [PATCH v6 00/10] Implement NVMe Namespace Descriptor Identification
  2017-06-19 17:59                         ` Tejun Heo
@ 2017-06-21 14:48                           ` Greg Kroah-Hartman
  2017-06-21 15:36                             ` Tejun Heo
  2017-06-22  0:21                           ` Linus Torvalds
  1 sibling, 1 reply; 10+ messages in thread
From: Greg Kroah-Hartman @ 2017-06-21 14:48 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Christoph Hellwig, Linus Torvalds, linux-fsdevel

On Mon, Jun 19, 2017 at 01:59:34PM -0400, Tejun Heo wrote:
> Hello,
> 
> On Sun, Jun 18, 2017 at 03:43:36PM +0200, Christoph Hellwig wrote:
> > On Sun, Jun 18, 2017 at 06:20:20AM -0400, Tejun Heo wrote:
> > > If you "cd /sys/kernel/debug/tracing; cd -" before doing the find,
> > > does it succeed the first time?  It could be that the on-demand
> > > mounting of tracefs is giving incoherent results across the mounting
> > > and confusing find.
> > 
> > Yes, that works fine:
> > 
> > root@testvm:~# cd /sys/kernel/debug/tracing; cd -
> > /root
> > root@testvm:~# find /sys -name uuid
> > /sys/devices/virtual/nvme-fabrics/ctl/nvme3/nvme3n1/uuid
> > /sys/devices/virtual/nvme-fabrics/ctl/nvme2/nvme2n1/uuid
> 
> So, looks like this is the debugfs automount mechanism changing nlinks
> across automounts and confusing find in the process.  Greg?

That's odd, is find racing with itself here?  I don't really know how to
do anything about this in sysfs, as this should happen for any other
filesystem, right?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: odd sysfs find behavior, was: Re: [PATCH v6 00/10] Implement NVMe Namespace Descriptor Identification
  2017-06-21 14:48                           ` Greg Kroah-Hartman
@ 2017-06-21 15:36                             ` Tejun Heo
  0 siblings, 0 replies; 10+ messages in thread
From: Tejun Heo @ 2017-06-21 15:36 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Christoph Hellwig, Linus Torvalds, linux-fsdevel

Hello,

On Wed, Jun 21, 2017 at 10:48:26PM +0800, Greg Kroah-Hartman wrote:
> On Mon, Jun 19, 2017 at 01:59:34PM -0400, Tejun Heo wrote:
> > So, looks like this is the debugfs automount mechanism changing nlinks
> > across automounts and confusing find in the process.  Greg?
> 
> That's odd, is find racing with itself here?  I don't really know how to
> do anything about this in sysfs, as this should happen for any other
> filesystem, right?

I don't actually know why find gets confused over nlinks changing
underneath it.  Can't we also automount on the first stat(2) call?

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: odd sysfs find behavior, was: Re: [PATCH v6 00/10] Implement NVMe Namespace Descriptor Identification
  2017-06-19 17:59                         ` Tejun Heo
  2017-06-21 14:48                           ` Greg Kroah-Hartman
@ 2017-06-22  0:21                           ` Linus Torvalds
  1 sibling, 0 replies; 10+ messages in thread
From: Linus Torvalds @ 2017-06-22  0:21 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Christoph Hellwig, Greg Kroah-Hartman, linux-fsdevel

On Mon, Jun 19, 2017 at 10:59 AM, Tejun Heo <tj@kernel.org> wrote:
>
> So, looks like this is the debugfs automount mechanism changing nlinks
> across automounts and confusing find in the process.  Greg?

Btw, you should be able to use the "-noleaf" option to find to disable
the whole "count nlink of directories" logic.

So does

    find /sys -noleaf -name uuid

work reliably whether that automount thing has triggered or not?

That said, I don't understand why the automount of debugfs should
matter. It's not even under the same hierarchy as any of the uuid
files, unless I'm confused. So the nlink on *those* directories
shouldn't even matter. Very odd.

                   Linus

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-06-22  0:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20170607094536.32419-1-jthumshirn@suse.de>
     [not found] ` <20170615163141.GA27307@lst.de>
     [not found]   ` <bab953e9-7026-5833-9f65-1ef8b90433d7@suse.de>
     [not found]     ` <20170616094056.GA12465@lst.de>
     [not found]       ` <905ed2e6-1c1c-f3a3-5391-66e42fb61861@suse.de>
     [not found]         ` <20170616095837.GA14217@lst.de>
     [not found]           ` <CA+55aFxJ0bpRFsnZFe6sh2i4jxNdYmDi_6RZx2CQQdmQ_HU3wQ@mail.gmail.com>
2017-06-17 12:08             ` odd sysfs find behavior, was: Re: [PATCH v6 00/10] Implement NVMe Namespace Descriptor Identification Christoph Hellwig
2017-06-18  1:12               ` Greg Kroah-Hartman
2017-06-18  7:32                 ` Christoph Hellwig
     [not found]                   ` <20170618073305.GB25797@lst.de>
2017-06-18 10:20                     ` Tejun Heo
2017-06-18 10:32                       ` Tejun Heo
2017-06-18 13:43                       ` Christoph Hellwig
2017-06-19 17:59                         ` Tejun Heo
2017-06-21 14:48                           ` Greg Kroah-Hartman
2017-06-21 15:36                             ` Tejun Heo
2017-06-22  0:21                           ` Linus Torvalds

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).