ksmbd: make ksmbd thread names distinct by client IP
Subsystems (2)
Namjae Jeon
maintainerPATCH 1/3 ksmbd: make ksmbd thread names distinct by client IP
This patch makes ksmbd thread names distinct by client IP address.
100943 ? S 0:00 [ksmbd:::ffff:10.177.110.57]
or
101752 ? S 0:00 [ksmbd:10.177.110.57]
--- fs/smb/server/transport_tcp.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-)
fs/smb/server/transport_tcp.c +8 -24
@@ -177,17 +177,6 @@ static struct kvec *get_conn_iovec(struct tcp_transport *t, unsigned int nr_segsreturn new_iov; } -static unsigned short ksmbd_tcp_get_port (const struct sockaddr *sa) -{ -switch (sa->sa_family) { -case AF_INET : -return ntohs (((struct sockaddr_in *)sa)->sin_port); -case AF_INET6 : -return ntohs (((struct sockaddr_in6 *)sa)->sin6_port); - } -return 0 ; -} -/** * ksmbd_tcp_new_connection() - create a new tcp session on mount * @client_sk: socket associated with new connection
@@ -199,7 +188,6 @@ static unsigned short ksmbd_tcp_get_port(const struct sockaddr *sa)*/ static int ksmbd_tcp_new_connection (struct socket *client_sk) { -struct sockaddr *csin;int rc =0 ;struct tcp_transport *t;struct task_struct *handler;
@@ -210,17 +198,14 @@ static int ksmbd_tcp_new_connection(struct socket *client_sk)return -ENOMEM ; } - csin =KSMBD_TCP_PEER_SOCKADDR (KSMBD_TRANS (t)->conn); -if (kernel_getpeername (client_sk, csin) <0 ) { -pr_err ("client ip resolution failed\n" ); - rc = -EINVAL ; - goto out_error; - } - - handler =kthread_run (ksmbd_conn_handler_loop, -KSMBD_TRANS (t)->conn, -"ksmbd:%u" , -ksmbd_tcp_get_port (csin)); +if (client_sk->sk->sk_family ==AF_INET6 ) + handler =kthread_run (ksmbd_conn_handler_loop, +KSMBD_TRANS (t)->conn,"ksmbd:%pI6c" , + &KSMBD_TRANS (t)->conn->inet6_addr); +else + handler =kthread_run (ksmbd_conn_handler_loop, +KSMBD_TRANS (t)->conn,"ksmbd:%pI4" , + &KSMBD_TRANS (t)->conn->inet_addr);if (IS_ERR (handler)) {pr_err ("cannot start conn thread\n" ); rc =PTR_ERR (handler);
@@ -228,7 +213,6 @@ static int ksmbd_tcp_new_connection(struct socket *client_sk) }return rc; -out_error:free_transport (t);return rc; }
Signature · 1 line
2.25.1
Namjae Jeon
maintainerPATCH 2/3 ksmbd: use sock_create_kern interface to create kernel socket
we should use sock_create_kern() if the socket resides in kernel space.
--- fs/smb/server/transport_tcp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/smb/server/transport_tcp.c +4 -3
@@ -469,12 +469,13 @@ static int create_socket(struct interface *iface)struct socket *ksmbd_socket;bool ipv4 = false; - ret =sock_create (PF_INET6 ,SOCK_STREAM ,IPPROTO_TCP , &ksmbd_socket); + ret =sock_create_kern (current->nsproxy->net_ns,PF_INET6 ,SOCK_STREAM , +IPPROTO_TCP , &ksmbd_socket);if (ret) {if (ret != -EAFNOSUPPORT )pr_err ("Can't create socket for ipv6, fallback to ipv4: %d\n" , ret); - ret =sock_create (PF_INET ,SOCK_STREAM ,IPPROTO_TCP , - &ksmbd_socket); + ret =sock_create_kern (current->nsproxy->net_ns,PF_INET , +SOCK_STREAM ,IPPROTO_TCP , &ksmbd_socket);if (ret) {pr_err ("Can't create socket for ipv4: %d\n" , ret); goto out_clear;
Signature · 1 line
2.25.1
Namjae Jeon
maintainerPATCH 3/3 ksmbd: copy overlapped range within the same file
In reply to Namjae Jeoncifs.ko request to copy overlapped range within the same file. ksmbd is using vfs_copy_file_range for this, vfs_copy_file_range() does not allow overlapped copying within the same file.
This patch use do_splice_direct() if offset and length are overlapped.
--- fs/smb/server/vfs.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
fs/smb/server/vfs.c +14 -2
@@ -20,6 +20,7 @@#include <linux/sched/xacct.h> #include <linux/crc32c.h> #include <linux/namei.h> +#include <linux/splice.h> #include "glob.h" #include "oplock.h"
@@ -1830,8 +1831,19 @@ int ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work,if (src_off + len > src_file_size)return -E2BIG ; - ret =vfs_copy_file_range (src_fp->filp, src_off, - dst_fp->filp, dst_off, len,0 ); +/* +* vfs_copy_file_range does not allow overlapped copying +* within the same file. +*/ +if (file_inode (src_fp->filp) ==file_inode (dst_fp->filp) && + dst_off + len > src_off && + dst_off < src_off + len) + ret =do_splice_direct (src_fp->filp, &src_off, + dst_fp->filp, &dst_off, +min_t (size_t, len,MAX_RW_COUNT ),0 ); +else + ret =vfs_copy_file_range (src_fp->filp, src_off, + dst_fp->filp, dst_off, len,0 );if (ret == -EOPNOTSUPP || ret == -EXDEV ) ret = vfs_copy_file_range(src_fp->filp, src_off, dst_fp->filp, dst_off, len,
Signature · 1 line
2.25.1
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Namjae,
kernel test robot noticed the following build errors:
[auto build test ERROR on brauner-vfs/vfs.all]
[also build test ERROR on linus/master v6.17-rc7 next-20250925] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Namjae-Jeon/ksmbd-use-sock_create_kern-interface-to-create-kernel-socket/20250925-202722 base: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all patch link: https://lore.kernel.org/r/20250925122118.11082-1-linkinjeon%40kernel.org patch subject: [PATCH 1/3] ksmbd: make ksmbd thread names distinct by client IP config: sh-randconfig-001-20250926 (https://download.01.org/0day-ci/archive/20250926/[email protected]/config) compiler: sh4-linux-gcc (GCC) 12.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250926/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from include/linux/psi_types.h:5,
from include/linux/cgroup-defs.h:23,
from include/linux/cgroup.h:29,
from include/net/netprio_cgroup.h:11,
from include/linux/netdevice.h:42,
from include/net/sock.h:46,
from fs/smb/server/connection.h:11,
from fs/smb/server/transport_tcp.c:12:
fs/smb/server/transport_tcp.c: In function 'ksmbd_tcp_new_connection':
>> fs/smb/server/transport_tcp.c:197:56: error: 'struct ksmbd_conn' has no member named 'inet6_addr'; did you mean 'inet_addr'?
197 | &KSMBD_TRANS(t)->conn->inet6_addr);
| ^~~~~~~~~~ include/linux/kthread.h:28:73: note: in definition of macro 'kthread_create'
28 | kthread_create_on_node(threadfn, data, NUMA_NO_NODE, namefmt, ##arg)
| ^~~
fs/smb/server/transport_tcp.c:195:27: note: in expansion of macro 'kthread_run'
195 | handler = kthread_run(ksmbd_conn_handler_loop,
| ^~~~~~~~~~~
vim +197 fs/smb/server/transport_tcp.c
172
173 /**
174 * ksmbd_tcp_new_connection() - create a new tcp session on mount
175 * @client_sk: socket associated with new connection
176 *
177 * whenever a new connection is requested, create a conn thread
178 * (session thread) to handle new incoming smb requests from the connection
179 *
180 * Return: 0 on success, otherwise error
181 */
182 static int ksmbd_tcp_new_connection(struct socket *client_sk)
183 {
184 int rc = 0;
185 struct tcp_transport *t;
186 struct task_struct *handler;
187
188 t = alloc_transport(client_sk);
189 if (!t) {
190 sock_release(client_sk);
191 return -ENOMEM;
192 }
193
194 if (client_sk->sk->sk_family == AF_INET6)
195 handler = kthread_run(ksmbd_conn_handler_loop,
196 KSMBD_TRANS(t)->conn, "ksmbd:%pI6c",
> 197 &KSMBD_TRANS(t)->conn->inet6_addr);
198 else
199 handler = kthread_run(ksmbd_conn_handler_loop,
200 KSMBD_TRANS(t)->conn, "ksmbd:%pI4",
201 &KSMBD_TRANS(t)->conn->inet_addr);
202 if (IS_ERR(handler)) {
203 pr_err("cannot start conn thread\n");
204 rc = PTR_ERR(handler);
205 free_transport(t);
206 }
207 return rc;
208
209 free_transport(t);
210 return rc;
211 }
212
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki