Ksmbd (Samba3/4 alternative, ex cifsd/smbd) package support thread

Unfortunately I get an error recompiling.

Applying /home/debian/openwrt-ipq-mx4300/target/linux/qualcommax/patches-6.6/0981-2-ksmbd_vfs_fix.patch using plaintext: 
patching file fs/smb/server/vfs.c
Hunk #1 FAILED at 1264.
Hunk #2 FAILED at 1271.
2 out of 2 hunks FAILED -- saving rejects to file fs/smb/server/vfs.c.rej
Patch failed!  Please fix /home/debian/openwrt-ipq-mx4300/target/linux/qualcommax/patches-6.6/0981-2-ksmbd_vfs_fix.patch!
make[4]: *** [Makefile:33: /home/debian/openwrt-ipq-mx4300/build_dir/target-aarch64_cortex-a53_musl/linux-qualcommax_ipq807x/linux-6.6.69/.prepared_a7c9d1dc872ea0659a991d7680753d4f] Error 1
make[4]: Leaving directory '/home/debian/openwrt-ipq-mx4300/target/linux/qualcommax'
make[3]: *** [Makefile:12: compile] Error 2
make[3]: Leaving directory '/home/debian/openwrt-ipq-mx4300/target/linux'
time: target/linux/compile#10.10#37.21#67.22
    ERROR: target/linux failed to build.
make[2]: *** [target/Makefile:32: target/linux/compile] Error 1
make[2]: Leaving directory '/home/debian/openwrt-ipq-mx4300'
make[1]: *** [target/Makefile:25: /home/debian/openwrt-ipq-mx4300/staging_dir/target-aarch64_cortex-a53_musl/stamp/.target_compile] Error 2
make[1]: Leaving directory '/home/debian/openwrt-ipq-mx4300'
make: *** [/home/debian/openwrt-ipq-mx4300/include/toplevel.mk:233: world] Error 2

Maybe it needs a patch refresh for OpenWrt.
This is the code in original vfs.c

line 1257 err = vfs_path_lookup(share_conf->vfs_path.dentry,
					      share_conf->vfs_path.mnt,
					      filepath,
					      flags,
					      path);
			if (err)
				goto out2;
			else if (is_last)
				goto out1;
			path_put(parent_path);
			*parent_path = *path;

			next[0] = '/';
			remain_len -= filename_len + 1;
line 1271		}

If you want I can try to do it...

Yes, please!
Thank you!
Obviously I don't get it how to adjust the patch. I'll have to familiarize myself with this.

You can use that patch and compile... or compile from my source.

Select branch ksmbd-fix-a

3 Likes

@linkinjeon and @pesa1234
Just compiled and tested the patch and I'm glad to inform you that the issue is resolved. Although I didn't have enough time to test it more extensively. Qbittorrent now can create/remove directories on NAS without any issue.
Tested with f2fs, exfat and ntfs file systems on two routers.

1 Like

ok. Thanks

@linkinjeon Just to know, this patch will be applyed soon on mainline or do you think we need to make a pull request on openwrt source?

Thanks a lot

1 Like

@linkinjeon I don't know if it is important or not but I saw some errors in log but otherwise ksmbd works.

[ 2107.321547] ksmbd: kill command received
[ 2107.324791] ksmbd: PDU length(16496) exceeded maximum allowed pdu size(16384) on connection(2)
[ 2107.324929] ksmbd: Unable to close RPC pipe 0
[ 2107.333174] ksmbd: Unable to close RPC pipe 1

@linkinjeon Are you going to fix this upstream or @pesa1234 should make a PR with your patch.

@sppmaster this patch was merged into linux-6.13-rc7. and it is released. And then this patch is propagated to the 6.6 stable kernel. It will be applied to 6.6.71 kernel, which will take about a week.

3 Likes

@sppmaster Linux 6.6.72 kernel released. Please use this version.

2 Likes

Thanks, just compiled with 6.6.73 and it's OK.

Had a single ksmbd crash in 24.10.0-rc6 while streaming a movie across my network to kodi on tv. Service restarted and it was fine after but never had this happen before so maybe an anamoly or will resolve in a later kernel update:

Sat Jan 25 11:04:51 2025 daemon.notice ksmbd: Stopping Ksmbd userspace service.
Sat Jan 25 11:04:51 2025 daemon.err rmmod: unloading the module failed
Sat Jan 25 11:04:51 2025 daemon.info ksmbd: triggering kill_server
Sat Jan 25 11:04:51 2025 kern.info kernel: [138295.232829] ksmbd: kill command received
Sat Jan 25 11:04:53 2025 daemon.notice ksmbd: Starting Ksmbd userspace service.

Check Kodi network buffers and set them accordingly considering your TV (TV Box) RAM.
I use a buffer size big enough to allow at least 30 seconds playback if the network connection is interrupted for some reason.

1 Like

Hi,
Can we tune something for low power routers to match Samba4 in performance?
I'm using Xiaomi mir3g v1 (OpenWrt 24.10.0) with usb disk,
Ubuntu 24.10 and Windows 11 as clients

Samba4: ~28/24MB/s R/W
Samba4: ~37/24MB/s R/W (ENABLE_EXTRA_TUNING and DISABLE_ASYNC_IO are enabled)
Ksmdb: ~27/24MB/s R/W

Are there options to tune for Ksmdb, as it done for Samba4 ?

1 Like

Hi, thanks for sharing,
Unfortunately there is no match for

socket options = SO_KEEPALIVE
max xmit = 131072
min receivefile size = 131072
fake oplocks = Yes
use sendfile = Yes

aio read size = 0
aio write size = 0

upd:
actually those made difference for Samba4:

aio read size = 0
aio write size = 0
use sendfile = yes

It took me an embarrassingly long time to find this command when migrating from samba4 to ksmbd to maintain my username/password configuration.

1 Like

I don't know why it is the case. I've added that info a while ago to the ksmbd wiki exactly for that reason.

To access a shared storage over the LAN using a username and password you have to use ksmbd.adduser from SSH. A /etc/ksmbd/ksmbdpwd.db file is created.

root@OpenWrt:~# ksmbd.adduser --help
Usage: ksmbd.adduser [-v] [-P PWDDB] [-c CONF] [-a | -u | -d] [-p PWD] USER

If neither `-a', `-u', nor `-d' is given, either add or update USER.
USER must be UTF-8 and [1, 48) bytes.
USER cannot contain colon (`:').

  -a, --add             add USER to user database
  -u, --update          update USER in user database
  -d, --delete          delete USER from user database
  -p, --password=PWD    use PWD as user password instead of prompting;
                        PWD must be UTF-8 and [0, 129) bytes
  -P, --pwddb=PWDDB     use PWDDB as user database instead of
                        `/etc/ksmbd/ksmbdpwd.db'
  -C, --config=CONF     use CONF as configuration file instead of
                        `/etc/ksmbd/ksmbd.conf'
  -v, --verbose         be verbose
  -V, --version         output version information and exit
  -h, --help            display this help and exit

See ksmbd.adduser(8) for more details.

Then you still need to make the appropriate changes to the ksmbd settings - allowed users.
Luci example.

or /etc/config/ksmbd

config globals
	option workgroup 'WORKGROUP'
	option description 'Ksmbd on OpenWrt'

config share
	option name 'router-USB1'
	option path '/mnt/sda1'
	option read_only 'no'
	option guest_ok 'no'
	option create_mask '0666'
	option dir_mask '0777'
	option users 'user1'

I've added some more info and example settings to the wiki.