Skip to contentSkip to conversation

smb/client: fix incorrect nlink returned by fstat()

PATCH Superseded ChenXiaoSong 2 participants 7 messages Jun 29 – Jul 1

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

ChenXiaoSong

author reviewer
#0 lore raw

PATCH 1/1 smb/client: fix incorrect nlink returned by fstat()

From: ChenXiaoSong <[email protected]>

Reproducer:

1. mount -t cifs //${server_ip}/export /mnt
2. touch /mnt/file1; ln /mnt/file1 /mnt/file2; ln /mnt/file1 /mnt/file3
3. C program: int fd = open("/mnt/file1", O_RDONLY);
4. C program: struct stat stbuf; fstat(fd, &stbuf); stbuf.st_nlink is always 1, should be 3

---
 fs/smb/client/smb2pdu.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
fs/smb/client/smb2pdu.c +13 -9
index d058584b8f05..70b3beb96aff 100644
@@ -3371,15 +3371,19 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
 #endif /* CIFS_DEBUG2 */
 
 	if (buf) {
-		buf->CreationTime = rsp->CreationTime;
-		buf->LastAccessTime = rsp->LastAccessTime;
-		buf->LastWriteTime = rsp->LastWriteTime;
-		buf->ChangeTime = rsp->ChangeTime;
-		buf->AllocationSize = rsp->AllocationSize;
-		buf->EndOfFile = rsp->EndofFile;
-		buf->Attributes = rsp->FileAttributes;
-		buf->NumberOfLinks = cpu_to_le32(1);
-		buf->DeletePending = 0; /* successful open = not delete pending */
+		int qrc = SMB2_query_info(xid, tcon, oparms->fid->persistent_fid,
+					  oparms->fid->volatile_fid, buf);
+		if (qrc) {
+			buf->CreationTime = rsp->CreationTime;
+			buf->LastAccessTime = rsp->LastAccessTime;
+			buf->LastWriteTime = rsp->LastWriteTime;
+			buf->ChangeTime = rsp->ChangeTime;
+			buf->AllocationSize = rsp->AllocationSize;
+			buf->EndOfFile = rsp->EndofFile;
+			buf->Attributes = rsp->FileAttributes;
+			buf->NumberOfLinks = cpu_to_le32(1);
+			buf->DeletePending = 0; /* successful open = not delete pending */
+		}
 	}
 
 
Signature · 1 line
2.54.0
#1 lore raw

wouldn't this be a big performance penalty, adding an extra roundtrip, adding query_info call to open?

Quoted 52 lines · ChenXiaoSong

From: ChenXiaoSong <[email protected]>

Reproducer:

1. mount -t cifs //${server_ip}/export /mnt
2. touch /mnt/file1; ln /mnt/file1 /mnt/file2; ln /mnt/file1 /mnt/file3
3. C program: int fd = open("/mnt/file1", O_RDONLY);
4. C program: struct stat stbuf; fstat(fd, &stbuf); stbuf.st_nlink is always 1, should be 3

---
 fs/smb/client/smb2pdu.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
fs/smb/client/smb2pdu.c +13 -10
index d058584b8f05..70b3beb96aff 100644
@@ -3371,15 +3371,19 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
 #endif /* CIFS_DEBUG2 */
 
        if (buf) {
-               buf->CreationTime = rsp->CreationTime;
-               buf->LastAccessTime = rsp->LastAccessTime;
-               buf->LastWriteTime = rsp->LastWriteTime;
-               buf->ChangeTime = rsp->ChangeTime;
-               buf->AllocationSize = rsp->AllocationSize;
-               buf->EndOfFile = rsp->EndofFile;
-               buf->Attributes = rsp->FileAttributes;
-               buf->NumberOfLinks = cpu_to_le32(1);
-               buf->DeletePending = 0; /* successful open = not delete pending */
+               int qrc = SMB2_query_info(xid, tcon, oparms->fid->persistent_fid,
+                                         oparms->fid->volatile_fid, buf);
+               if (qrc) {
+                       buf->CreationTime = rsp->CreationTime;
+                       buf->LastAccessTime = rsp->LastAccessTime;
+                       buf->LastWriteTime = rsp->LastWriteTime;
+                       buf->ChangeTime = rsp->ChangeTime;
+                       buf->AllocationSize = rsp->AllocationSize;
+                       buf->EndOfFile = rsp->EndofFile;
+                       buf->Attributes = rsp->FileAttributes;
+                       buf->NumberOfLinks = cpu_to_le32(1);
+                       buf->DeletePending = 0; /* successful open = not delete pending */
+               }
        }
 
 
--

2.54.0

Signature · 3 lines
Thanks,

Steve
author reviewer
#2 lore raw

SMB2_open() should not be called that frequently. Steve, do you have any better ideas?

Quoted 2 lines · Steve French

wouldn't this be a big performance penalty, adding an extra roundtrip, adding query_info call to open?

Signature · 3 lines
ChenXiaoSong <[email protected]>
Chinese Homepage: https://chenxiaosong.com
English Homepage: https://chenxiaosong.com/en
#3 lore raw
Quoted 1 line

do you have any better ideas?

Not really, was hoping that there was a way to cache the link count locally as additional hardlinks are done

Does this fix any xfstests?

Quoted 13 lines · ChenXiaoSong

SMB2_open() should not be called that frequently. Steve, do you have any better ideas?

Quoted 2 lines · Steve French

wouldn't this be a big performance penalty, adding an extra roundtrip, adding query_info call to open?

--
ChenXiaoSong <[email protected]>
Chinese Homepage: https://chenxiaosong.com
English Homepage: https://chenxiaosong.com/en

Signature · 3 lines
Thanks,

Steve
author reviewer
#4 lore raw
Quoted 2 lines · Steve French

Not really, was hoping that there was a way to cache the link count locally as additional hardlinks are done

That would not work for hardlinks that were created before mounting, fstat() will not be able to return the correct nlink.

Quoted 2 lines

Does this fix any xfstests?

I found this issue while testing the modified xfstests generic/035.

Signature · 3 lines
ChenXiaoSong <[email protected]>
Chinese Homepage: https://chenxiaosong.com
English Homepage: https://chenxiaosong.com/en
author reviewer
#6 lore raw
In reply to Steve French

Could we query FileStandardInformation instead of FileAllInformation just to get nlink?

Quoted 2 lines · Steve French

wouldn't this be a big performance penalty, adding an extra roundtrip, adding query_info call to open?

Signature · 3 lines
ChenXiaoSong <[email protected]>
Chinese Homepage: https://chenxiaosong.com
English Homepage: https://chenxiaosong.com/en