namjaejeon / ksmbd

ksmbd kernel server(SMB/CIFS server)
https://github.com/cifsd-team/ksmbd
282 stars 64 forks source link

ksmbd-server: Shared files/directories are not visible in root folder of the share #469

Closed sppmasterspp closed 10 months ago

sppmasterspp commented 10 months ago

Ksmbd-server Version 3.4.8-1

ubus call system board
{
        "kernel": "6.1.71",
        "hostname": "QNAP",
        "system": "ARMv8 Processor rev 4",
        "model": "QNAP 301w",
        "board_name": "qnap,301w",
        "rootfs_type": "squashfs",
        "release": {
                "distribution": "OpenWrt",
                "version": "SNAPSHOT",
                "revision": "r24887+2-c43e96d28f",
                "target": "qualcommax/ipq807x",
                "description": "OpenWrt SNAPSHOT r24887+2-c43e96d28f"
        }
}

Description: I saw there were a lot of ksmbd changes (commits) in kernel 6.1.71. Having compiled a new build with 6.1.71 I cannot access the root directory of shared disk. Actually it opens but is shown as empty on all devices. 981f66beb39846b25ae20ff56cb1f3593ff2c532

The files are still there 420b7c0b6ee21f0938f6cf1988fb0a6c3646068f_2_689x408

but not visible in file explorers on different devices. Writing to the root shared folder is not possible either. I can write to the down directories if I access them directly via address bar. It worked normally with kernel 6.1.69. I can view and access the mounted device directories with cd and ls commands via router SSH console and I can open some shared directories down the root directory from Windows File Explorer typing the address in the address bar.

The discussion on OpenWrt forum.

namjaejeon commented 10 months ago

Please use the higher version ksmbd-tools than 3.4.8.

namjaejeon commented 10 months ago

@neheb openWRT should upgrade ksmbd-tools in openWRT with the latest version. Can you request it ?

neheb commented 10 months ago

https://github.com/openwrt/packages/pull/23095

namjaejeon commented 10 months ago

@sppmasterspp ksmbd-tools-3.5.1 seems to be merged into openWRT. Can you check if your problem is fixed ?

sppmasterspp commented 10 months ago

@sppmasterspp ksmbd-tools-3.5.1 seems to be merged into openWRT. Can you check if your problem is fixed ?

Yes, recompiled this morning with latest changes and all is OK. The issue is fixed. Thanks a lot guys.

namjaejeon commented 10 months ago

@neheb Thanks for your help!

namjaejeon commented 10 months ago

@ptpt52 I can not attach the patch in github. Can you temporarily apply the following patch to openWRT's 5.15 and 6.1 kernel ? I need the time to apply this patch to mainline and stable kernels.(may take about 2 weeks)

From a65ef261519e1dc3ff7f1ae3c740487ab2e961e8 Mon Sep 17 00:00:00 2001
From: Namjae Jeon <linkinjeon@kernel.org>
Date: Mon, 15 Jan 2024 10:24:54 +0900
Subject: [PATCH] ksmbd: only v2 leases handle the directory

When smb2 leases is disable, ksmbd can send oplock break notification
and cause wait oplock break ack timeout. It may appear like hang when
accessing a directory. This patch make only v2 leases handle the
directory.

Cc: stable@vger.kernel.org
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
---
 fs/smb/server/oplock.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/smb/server/oplock.c b/fs/smb/server/oplock.c
index 001926d3b348..53dfaac425c6 100644
--- a/fs/smb/server/oplock.c
+++ b/fs/smb/server/oplock.c
@@ -1197,6 +1197,12 @@ int smb_grant_oplock(struct ksmbd_work *work, int req_op_level, u64 pid,
    bool prev_op_has_lease;
    __le32 prev_op_state = 0;

+   /* Only v2 leases handle the directory */
+   if (S_ISDIR(file_inode(fp->filp)->i_mode)) {
+       if (!lctx || lctx->version != 2)
+           return 0;
+   }
+
    opinfo = alloc_opinfo(work, pid, tid);
    if (!opinfo)
        return -ENOMEM;
-- 
2.34.1
ptpt52 commented 10 months ago

looks into the code in kernel 5.15 It looks like that it is now not support directory lease? @namjaejeon

int smb_grant_oplock(struct ksmbd_work *work, int req_op_level, u64 pid, 
                     struct ksmbd_file *fp, __u16 tid, 
                     struct lease_ctx_info *lctx, int share_ret)
{
        struct ksmbd_session *sess = work->sess;
        int err = 0; 
        struct oplock_info *opinfo = NULL, *prev_opinfo = NULL;
        struct ksmbd_inode *ci = fp->f_ci;
        bool prev_op_has_lease;
        __le32 prev_op_state = 0; 

        /* not support directory lease */
        if (S_ISDIR(file_inode(fp->filp)->i_mode))
                return 0;

        opinfo = alloc_opinfo(work, pid, tid);
        if (!opinfo)
                return -ENOMEM;

        if (lctx) {
                err = alloc_lease(opinfo, lctx);
                if (err)
                        goto err_out;
                opinfo->is_lease = 1; 
        }    

        /* ci does not have any oplock */
        if (!opinfo_count(fp))
                goto set_lev;

        /* grant none-oplock if second open is trunc */
        if (fp->attrib_only && fp->cdoption != FILE_OVERWRITE_IF_LE &&
            fp->cdoption != FILE_OVERWRITE_LE &&
            fp->cdoption != FILE_SUPERSEDE_LE) {
                req_op_level = SMB2_OPLOCK_LEVEL_NONE;
                goto set_lev;
        }    
...
ptpt52 commented 10 months ago

PR: https://github.com/openwrt/openwrt/pull/14409

namjaejeon commented 10 months ago

@ptpt52 Oh, Thanks for your work!

namjaejeon commented 10 months ago

@sppmasterspp If your issues are fixed, Please close this.

sppmasterspp commented 10 months ago

I closed this. Everithing is OK - compiled with above @ptpt52 PR. Thank You!