Skip to contentSkip to conversation

readdir cookies

DISCUSSION J. Bruce Fields 2 participants 7 messages Sep 17, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

How does the nfs client decide what directory cookies to return? (As the d_off field to readdir, for example).

I'd assumed it would return the server's cookie, but testing shows it returns a simple integer sequence.

--b.

#1 lore raw
Quoted 8 lines

-----Original Message-----
From: [email protected] [mailto:linux-nfs- [email protected]] On Behalf Of J. Bruce Fields
Sent: Monday, September 17, 2012 11:54 AM
To: Myklebust, Trond; Schumaker, Bryan
Cc: [email protected]
Subject: readdir cookies

Quoted 5 lines

How does the nfs client decide what directory cookies to return? (As the d_off field to readdir, for example).

I'd assumed it would return the server's cookie, but testing shows it returns a simple integer sequence.

We cache the cookies and use them to figure out where the readdir cursor is after a directory update, but we use positive integers for telldir()/seekdir(). The reason is that too many servers return cookies that use > 32 bits (NFSv2-incompatible) or are unsigned.

Cheers
Trond

#2 lore raw
Quoted 8 lines · Trond
Quoted 8 lines

-----Original Message-----
From: [email protected] [mailto:linux-nfs- [email protected]] On Behalf Of J. Bruce Fields
Sent: Monday, September 17, 2012 11:54 AM
To: Myklebust, Trond; Schumaker, Bryan
Cc: [email protected]
Subject: readdir cookies

Quoted 7 lines
Quoted 5 lines

How does the nfs client decide what directory cookies to return? (As the d_off field to readdir, for example).

I'd assumed it would return the server's cookie, but testing shows it returns a simple integer sequence.

We cache the cookies and use them to figure out where the readdir cursor is after a directory update, but we use positive integers for telldir()/seekdir(). The reason is that too many servers return cookies that use > 32 bits (NFSv2-incompatible) or are unsigned.

Ok--so the tradeoff is that telldir/seekdir cookies may not be good indefinitely?

--b.

#3 lore raw
Quoted 22 lines

-----Original Message-----
From: J. Bruce Fields [mailto:[email protected]]
Sent: Monday, September 17, 2012 12:51 PM
To: Myklebust, Trond
Cc: Schumaker, Bryan; [email protected]
Subject: Re: readdir cookies

Quoted 14 lines · Trond
Quoted 13 lines

-----Original Message-----
From: [email protected] [mailto:linux-nfs- [email protected]] On Behalf Of J. Bruce Fields
Sent: Monday, September 17, 2012 11:54 AM
To: Myklebust, Trond; Schumaker, Bryan
Cc: [email protected]
Subject: readdir cookies

How does the nfs client decide what directory cookies to return? (As the d_off field to readdir, for example).

I'd assumed it would return the server's cookie, but testing shows it returns a simple integer sequence.

Quoted 7 lines
Quoted 1 line

We cache the cookies and use them to figure out where the readdir cursor

is after a directory update, but we use positive integers for telldir()/seekdir(). The reason is that too many servers return cookies that use > 32 bits (NFSv2- incompatible) or are unsigned.

Ok--so the tradeoff is that telldir/seekdir cookies may not be good indefinitely?

Yes. Most apps don't care about telldir()/seekdir(), so it isn't really much of an issue. However, glibc has a bunch of assumptions about the 'd_offs' entries returned by getdents()/getdents64() and will do "sanity checks" on them that often end up failing when we just shove in the raw NFS cookies.

Cheers
Trond

#4 lore raw
Quoted 23 lines · Trond
Quoted 23 lines

-----Original Message-----
From: J. Bruce Fields [mailto:[email protected]]
Sent: Monday, September 17, 2012 12:51 PM
To: Myklebust, Trond
Cc: Schumaker, Bryan; [email protected]
Subject: Re: readdir cookies

Quoted 15 lines · Trond
Quoted 8 lines

-----Original Message-----
From: [email protected] [mailto:linux-nfs- [email protected]] On Behalf Of J. Bruce Fields
Sent: Monday, September 17, 2012 11:54 AM
To: Myklebust, Trond; Schumaker, Bryan
Cc: [email protected]
Subject: readdir cookies

Quoted 5 lines

How does the nfs client decide what directory cookies to return? (As the d_off field to readdir, for example).

I'd assumed it would return the server's cookie, but testing shows it returns a simple integer sequence.

We cache the cookies and use them to figure out where the readdir cursor

Quoted 8 lines
Quoted 6 lines

is after a directory update, but we use positive integers for telldir()/seekdir(). The reason is that too many servers return cookies that use > 32 bits (NFSv2- incompatible) or are unsigned.

Ok--so the tradeoff is that telldir/seekdir cookies may not be good indefinitely?

Yes. Most apps don't care about telldir()/seekdir(), so it isn't really much of an issue. However, glibc has a bunch of assumptions about the 'd_offs' entries returned by getdents()/getdents64() and will do "sanity checks" on them that often end up failing when we just shove in the raw NFS cookies.

OK, thanks. When did the client start doing that?

(And do you remember any details about the libc problems? ext4 is returning 64-bit cookies now in some cases, and we've seen a few problems elsewhere, but none with glibc.)

--b.

#5 lore raw
Quoted 41 lines

-----Original Message-----
From: J. Bruce Fields [mailto:[email protected]]
Sent: Monday, September 17, 2012 1:50 PM
To: Myklebust, Trond
Cc: Schumaker, Bryan; [email protected]
Subject: Re: readdir cookies

Quoted 19 lines · Trond
Quoted 19 lines

-----Original Message-----
From: J. Bruce Fields [mailto:[email protected]]
Sent: Monday, September 17, 2012 12:51 PM
To: Myklebust, Trond
Cc: Schumaker, Bryan; [email protected]
Subject: Re: readdir cookies

Quoted 11 lines · Trond
Quoted 11 lines

-----Original Message-----
From: [email protected] [mailto:linux-nfs- [email protected]] On Behalf Of J. Bruce Fields
Sent: Monday, September 17, 2012 11:54 AM
To: Myklebust, Trond; Schumaker, Bryan
Cc: [email protected]
Subject: readdir cookies

How does the nfs client decide what directory cookies to return? (As the d_off field to readdir, for example).

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

I'd assumed it would return the server's cookie, but testing shows it returns a simple integer sequence.

We cache the cookies and use them to figure out where the readdir cursor

is after a directory update, but we use positive integers for

telldir()/seekdir().

Quoted 7 lines
Quoted 6 lines

The reason is that too many servers return cookies that use > 32 bits (NFSv2-
incompatible) or are unsigned.

Ok--so the tradeoff is that telldir/seekdir cookies may not be good indefinitely?

Quoted 6 lines
Quoted 1 line

Yes. Most apps don't care about telldir()/seekdir(), so it isn't really much of

an issue. However, glibc has a bunch of assumptions about the 'd_offs' entries returned by getdents()/getdents64() and will do "sanity checks" on them that often end up failing when we just shove in the raw NFS cookies.

OK, thanks. When did the client start doing that?

Years ago. You want to look at commit 00a2642 (NFS: Hide NFS server-generated readdir cookies from userland) which dates back to Linux-2.6.13.

Quoted 3 lines

(And do you remember any details about the libc problems? ext4 is returning 64-bit cookies now in some cases, and we've seen a few problems elsewhere, but none with glibc.)

IIRC: At one point, in glibc-2(.1?), they started using getdents64() instead of getdents() in order to avoid the problem of mismatched 'struct dirent' sizes on 32-bit ix86 platforms. Whenever the getdents64() interface returned a 64-bit cookie (or a 32-bit negative cookie), glibc would generate an EOVERFLOW error.

Cheers
Trond

#6 lore raw
Quoted 48 lines · Trond
Quoted 41 lines

-----Original Message-----
From: J. Bruce Fields [mailto:[email protected]]
Sent: Monday, September 17, 2012 1:50 PM
To: Myklebust, Trond
Cc: Schumaker, Bryan; [email protected]
Subject: Re: readdir cookies

Quoted 19 lines · Trond
Quoted 19 lines

-----Original Message-----
From: J. Bruce Fields [mailto:[email protected]]
Sent: Monday, September 17, 2012 12:51 PM
To: Myklebust, Trond
Cc: Schumaker, Bryan; [email protected]
Subject: Re: readdir cookies

Quoted 11 lines · Trond
Quoted 11 lines

-----Original Message-----
From: [email protected] [mailto:linux-nfs- [email protected]] On Behalf Of J. Bruce Fields
Sent: Monday, September 17, 2012 11:54 AM
To: Myklebust, Trond; Schumaker, Bryan
Cc: [email protected]
Subject: readdir cookies

How does the nfs client decide what directory cookies to return? (As the d_off field to readdir, for example).

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

I'd assumed it would return the server's cookie, but testing shows it returns a simple integer sequence.

We cache the cookies and use them to figure out where the readdir cursor

is after a directory update, but we use positive integers for

telldir()/seekdir().

Quoted 7 lines
Quoted 6 lines

The reason is that too many servers return cookies that use > 32 bits (NFSv2-
incompatible) or are unsigned.

Ok--so the tradeoff is that telldir/seekdir cookies may not be good indefinitely?

Quoted 6 lines
Quoted 1 line

Yes. Most apps don't care about telldir()/seekdir(), so it isn't really much of

an issue. However, glibc has a bunch of assumptions about the 'd_offs' entries returned by getdents()/getdents64() and will do "sanity checks" on them that often end up failing when we just shove in the raw NFS cookies.

OK, thanks. When did the client start doing that?

Quoted 7 lines

Years ago. You want to look at commit 00a2642 (NFS: Hide NFS server-generated readdir cookies from userland) which dates back to Linux-2.6.13.

Quoted 3 lines

(And do you remember any details about the libc problems? ext4 is returning 64-bit cookies now in some cases, and we've seen a few problems elsewhere, but none with glibc.)

IIRC: At one point, in glibc-2(.1?), they started using getdents64() instead of getdents() in order to avoid the problem of mismatched 'struct dirent' sizes on 32-bit ix86 platforms. Whenever the getdents64() interface returned a 64-bit cookie (or a 32-bit negative cookie), glibc would generate an EOVERFLOW error.

Got it, thanks.

--b.