linux/fs/smb/server/stats.h
Bahubali B Gumaji b38f99c121 ksmbd: add procfs interface for runtime monitoring and statistics
This patch introduces a /proc filesystem interface to ksmbd, providing
visibility into the internal state of the SMB server. This allows
administrators and developers to monitor active connections, user
sessions, and opened files in real-time without relying on external
tools or heavy debugging.

Key changes include:
 - Connection Monitoring (/proc/fs/ksmbd/clients): Displays a list of
   active network connections, including client IP addresses, SMB dialects,
   credits, and last active timestamps.

 - Session Management (/proc/fs/ksmbd/sessions/): Adds a global sessions
   file to list all authenticated users and their session IDs.

 - Creates individual session entries (e.g., /proc/fs/ksmbd/sessions/<id>)
   detailing capabilities (DFS, Multi-channel, etc.), signing/encryption
   algorithms, and connected tree shares.

 - File Tracking (/proc/fs/ksmbd/files): Shows all currently opened files
   across the server, including tree IDs, process IDs (PID), access modes
   (daccess/saccess), and oplock/lease states.

 - Statistics & Counters: Implements internal counters for global server
   metrics, such as the number of tree connections, total sessions, and
   processed read/write bytes.

Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Bahubali B Gumaji <bahubali.bg@samsung.com>
Signed-off-by: Sang-Soo Lee  <constant.lee@samsung.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
2026-02-08 20:25:16 -06:00

73 lines
1.8 KiB
C

/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2025, LG Electronics.
* Author(s): Hyunchul Lee <hyc.lee@gmail.com>
* Copyright (C) 2025, Samsung Electronics.
* Author(s): Vedansh Bhardwaj <v.bhardwaj@samsung.com>
*/
#ifndef __KSMBD_STATS_H__
#define __KSMBD_STATS_H__
#define KSMBD_COUNTER_MAX_REQS 19
enum {
KSMBD_COUNTER_SESSIONS = 0,
KSMBD_COUNTER_TREE_CONNS,
KSMBD_COUNTER_REQUESTS,
KSMBD_COUNTER_READ_BYTES,
KSMBD_COUNTER_WRITE_BYTES,
KSMBD_COUNTER_FIRST_REQ,
KSMBD_COUNTER_LAST_REQ = KSMBD_COUNTER_FIRST_REQ +
KSMBD_COUNTER_MAX_REQS - 1,
KSMBD_COUNTER_MAX,
};
#ifdef CONFIG_PROC_FS
extern struct ksmbd_counters ksmbd_counters;
struct ksmbd_counters {
struct percpu_counter counters[KSMBD_COUNTER_MAX];
};
static inline void ksmbd_counter_inc(int type)
{
percpu_counter_inc(&ksmbd_counters.counters[type]);
}
static inline void ksmbd_counter_dec(int type)
{
percpu_counter_dec(&ksmbd_counters.counters[type]);
}
static inline void ksmbd_counter_add(int type, s64 value)
{
percpu_counter_add(&ksmbd_counters.counters[type], value);
}
static inline void ksmbd_counter_sub(int type, s64 value)
{
percpu_counter_sub(&ksmbd_counters.counters[type], value);
}
static inline void ksmbd_counter_inc_reqs(unsigned int cmd)
{
if (cmd < KSMBD_COUNTER_MAX_REQS)
percpu_counter_inc(&ksmbd_counters.counters[KSMBD_COUNTER_FIRST_REQ + cmd]);
}
static inline s64 ksmbd_counter_sum(int type)
{
return percpu_counter_sum_positive(&ksmbd_counters.counters[type]);
}
#else
static inline void ksmbd_counter_inc(int type) {}
static inline void ksmbd_counter_dec(int type) {}
static inline void ksmbd_counter_add(int type, s64 value) {}
static inline void ksmbd_counter_sub(int type, s64 value) {}
static inline void ksmbd_counter_inc_reqs(unsigned int cmd) {}
static inline s64 ksmbd_counter_sum(int type) { return 0; }
#endif
#endif