fs/smb/server/connection.c
Source file repositories/reference/linux-study-clean/fs/smb/server/connection.c
File Facts
- System
- Linux kernel
- Corpus path
fs/smb/server/connection.c- Extension
.c- Size
- 16974 bytes
- Lines
- 692
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mutex.hlinux/freezer.hlinux/module.hserver.hsmb_common.hmgmt/ksmbd_ida.hconnection.hcompress.htransport_tcp.htransport_rdma.hmisc.h
Detected Declarations
function proc_show_clientsfunction create_proc_clientsfunction delete_proc_clientsfunction create_proc_clientsfunction delete_proc_clientsfunction ksmbd_conn_wq_initfunction ksmbd_conn_wq_destroyfunction __ksmbd_conn_release_workfunction ksmbd_server_initfunction ksmbd_conn_freefunction ksmbd_conn_allocfunction ksmbd_conn_lookup_dialectfunction ksmbd_conn_enqueue_requestfunction ksmbd_conn_try_dequeue_requestfunction ksmbd_conn_lockfunction ksmbd_conn_unlockfunction ksmbd_all_conn_set_statusfunction ksmbd_conn_wait_idlefunction ksmbd_conn_wait_idle_sess_idfunction ksmbd_conn_writefunction ksmbd_conn_rdma_readfunction ksmbd_conn_rdma_writefunction ksmbd_conn_alivefunction time_afterfunction ksmbd_conn_handler_loopfunction ksmbd_conn_init_server_callbacksfunction ksmbd_conn_r_count_incfunction ksmbd_conn_r_count_decfunction ksmbd_conn_transport_initfunction stop_sessionsfunction ksmbd_conn_transport_destroy
Annotated Snippet
static int create_proc_clients(void) { return 0; }
static void delete_proc_clients(void) {}
#endif
static struct workqueue_struct *ksmbd_conn_wq;
int ksmbd_conn_wq_init(void)
{
ksmbd_conn_wq = alloc_workqueue("ksmbd-conn-release",
WQ_UNBOUND | WQ_MEM_RECLAIM, 0);
if (!ksmbd_conn_wq)
return -ENOMEM;
return 0;
}
void ksmbd_conn_wq_destroy(void)
{
if (ksmbd_conn_wq) {
destroy_workqueue(ksmbd_conn_wq);
ksmbd_conn_wq = NULL;
}
}
/*
* __ksmbd_conn_release_work() - perform the final, once-per-struct cleanup
* of a ksmbd_conn whose refcount has just dropped to zero.
*
* This is the common release path used by ksmbd_conn_put() for the embedded
* state that outlives the connection thread: async_ida and the attached
* transport (which owns the socket and iov for TCP). Called from a workqueue
* so that sleep-allowed teardown (sock_release -> tcp_close ->
* lock_sock_nested) never runs from an RCU softirq callback (free_opinfo_rcu)
* or any other non-sleeping putter context.
*/
static void __ksmbd_conn_release_work(struct work_struct *work)
{
struct ksmbd_conn *conn =
container_of(work, struct ksmbd_conn, release_work);
ida_destroy(&conn->async_ida);
conn->transport->ops->free_transport(conn->transport);
kfree(conn);
}
/**
* ksmbd_conn_get() - take a reference on @conn and return it.
*
* @conn: connection instance to get a reference to
*
* Returns @conn unchanged so callers can write
* "fp->conn = ksmbd_conn_get(work->conn);" in one expression. Returns NULL
* if @conn is NULL.
*/
struct ksmbd_conn *ksmbd_conn_get(struct ksmbd_conn *conn)
{
if (!conn)
return NULL;
atomic_inc(&conn->refcnt);
return conn;
}
/**
* ksmbd_conn_put() - drop a reference and, if it was the last, queue the
* release onto ksmbd_conn_wq so it runs from process context.
*
* @conn: connection instance to put a reference to
*
* Callable from any context including RCU softirq callbacks and non-sleeping
* locks; the actual release is deferred to the workqueue. ksmbd_conn_wq is
* created in ksmbd_server_init() before any conn can be allocated and is
* destroyed in ksmbd_server_exit() after rcu_barrier(), so it is always
* non-NULL while a conn reference is held.
*/
void ksmbd_conn_put(struct ksmbd_conn *conn)
{
if (!conn)
return;
if (atomic_dec_and_test(&conn->refcnt))
queue_work(ksmbd_conn_wq, &conn->release_work);
}
/**
* ksmbd_conn_free() - free resources of the connection instance
*
* @conn: connection instance to be cleaned up
*
* During the thread termination, the corresponding conn instance
* resources(sock/memory) are released and finally the conn object is freed.
Annotation
- Immediate include surface: `linux/mutex.h`, `linux/freezer.h`, `linux/module.h`, `server.h`, `smb_common.h`, `mgmt/ksmbd_ida.h`, `connection.h`, `compress.h`.
- Detected declarations: `function proc_show_clients`, `function create_proc_clients`, `function delete_proc_clients`, `function create_proc_clients`, `function delete_proc_clients`, `function ksmbd_conn_wq_init`, `function ksmbd_conn_wq_destroy`, `function __ksmbd_conn_release_work`, `function ksmbd_server_init`, `function ksmbd_conn_free`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.