Re: [PATCH] smb/client: fix incorrect nlink returned by fstat()

Steve French <[email protected]>
Newsgroups org.kernel.vger.linux-cifs
Message-ID <CAH2r5mt2Jonpx-YZ9ea0icKtGTCHFcEF77F0nJdFXRn97eUC=w@mail.gmail.com>
wouldn't this be a big performance penalty, adding an extra roundtrip,
adding query_info call to open?

On Mon, Jun 29, 2026 at 10:27 AM ChenXiaoSong
<[email protected]> wrote:
>
> 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
>
> Signed-off-by: ChenXiaoSong <[email protected]>
> ---
>  fs/smb/client/smb2pdu.c | 22 +++++++++++++---------
>  1 file changed, 13 insertions(+), 9 deletions(-)
>
> diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
> index d058584b8f05..70b3beb96aff 100644
> --- a/fs/smb/client/smb2pdu.c
> +++ b/fs/smb/client/smb2pdu.c
> @@ -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
>


-- 
Thanks,

Steve
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.