smb/client: fix incorrect nlink returned by fstat()
Subsystems (2)
ChenXiaoSong
reviewerPATCH 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
@@ -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
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 3Signed-off-by ChenXiaoSong <[email protected]>--- fs/smb/client/smb2pdu.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)fs/smb/client/smb2pdu.c +13
-10@@ -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
ChenXiaoSong
reviewerSMB2_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_infocall to open?
Signature · 3 lines
ChenXiaoSong <[email protected]> Chinese Homepage: https://chenxiaosong.com English Homepage: https://chenxiaosong.com/en
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_infocall to open?--
ChenXiaoSong <[email protected]>
Chinese Homepage: https://chenxiaosong.com
English Homepage: https://chenxiaosong.com/en
Signature · 3 lines
Thanks, Steve
ChenXiaoSong
reviewerQuoted 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
ChenXiaoSong
reviewerSashiko has a better idea:
https://sashiko.dev/#/patchset/20260629152659.703943-1-chenxiaosong%40chenxiaosong.com
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
Signature · 3 lines
ChenXiaoSong <[email protected]> Chinese Homepage: https://chenxiaosong.com English Homepage: https://chenxiaosong.com/en
ChenXiaoSong
reviewerCould 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_infocall to open?
Signature · 3 lines
ChenXiaoSong <[email protected]> Chinese Homepage: https://chenxiaosong.com English Homepage: https://chenxiaosong.com/en