netatalk  4.4.0dev
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
lantest_io_monitor.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025, Andy Lemin (andylemin)
3 * Credits; Based on work by Netatalk contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#ifndef LANTEST_IO_MONITOR_H
17#define LANTEST_IO_MONITOR_H
18
19#include <stdbool.h>
20#include <stdint.h>
21#include <sys/types.h>
22
23/* Define PID_MAX if not available from system headers */
24#ifndef PID_MAX
25/* Conservative default maximum PID value */
26#define PID_MAX 99999
27#endif
28
29/* Global Debug flag - controlled by -b option in lantest.c */
30extern bool Debug;
31
32#ifdef __linux__
33
34/* Process filtering configuration for finding Netatalk daemons.
35 * Supports two modes: filter by process UID ownership (for afpd which drops privileges)
36 * or filter by cmdline -u argument (for cnid_dbd which runs as root). */
37typedef struct {
38 const char *process_name;
39 const char *username;
40 int32_t filter_by_cmdline; /* 0 = filter by UID ownership, 1 = filter by cmdline -u arg */
41 uid_t target_uid; /* For ownership filtering */
42} ProcessFilter;
43
44/* Container for discovered process IDs during /proc_io scanning.
45 * Stores up to 10 matching PIDs to detect multiple instances.
46 * count=0 means no match, count=1 is ideal, count>1 indicates duplicates. */
47typedef struct {
48 pid_t pids[10];
49 int32_t count;
50} ProcessList;
51
52/* External variables for IO monitoring */
53extern bool io_monitoring_enabled;
54extern pid_t afpd_pid;
55extern pid_t cnid_dbd_pid;
56extern uint64_t afpd_start_reads, afpd_start_writes;
57extern uint64_t cnid_start_reads, cnid_start_writes;
58extern uint64_t afpd_end_reads, afpd_end_writes;
59extern uint64_t cnid_end_reads, cnid_end_writes;
60
61/* Constants for capture_io_values() */
62#define TEST_START 1
63#define TEST_STOP 0
64
65/* Function declarations */
66int32_t check_proc_io_availability(void);
67pid_t find_process_pid(const char *process_name, const char *username,
68 int32_t filter_by_cmdline);
69void capture_io_values(int32_t is_start);
70uint64_t iodiff_io(pid_t pid, int32_t is_write);
71
72/* Initialization function */
73void init_io_monitoring(const char *username);
74
75#endif /* __linux__ */
76
77#endif /* LANTEST_IO_MONITOR_H */
bool Debug
Definition lantest.c:94
uint64_t iodiff_io(pid_t pid, int32_t is_write)
Definition lantest_io_monitor.c:723
uint64_t afpd_end_reads
Definition lantest_io_monitor.c:699
void capture_io_values(int32_t is_start)
Definition lantest_io_monitor.c:717
pid_t cnid_dbd_pid
Definition lantest_io_monitor.c:696
uint64_t cnid_end_reads
Definition lantest_io_monitor.c:700
void init_io_monitoring(const char *username)
Definition lantest_io_monitor.c:730
bool io_monitoring_enabled
Definition lantest_io_monitor.c:694
int32_t check_proc_io_availability(void)
Definition lantest_io_monitor.c:703
pid_t find_process_pid(const char *process_name, const char *username, int32_t filter_by_cmdline)
Definition lantest_io_monitor.c:708
uint64_t cnid_start_reads
Definition lantest_io_monitor.c:698
uint64_t afpd_end_writes
Definition lantest_io_monitor.c:699
uint64_t afpd_start_writes
Definition lantest_io_monitor.c:697
uint64_t cnid_start_writes
Definition lantest_io_monitor.c:698
uint64_t afpd_start_reads
Definition lantest_io_monitor.c:697
uint64_t cnid_end_writes
Definition lantest_io_monitor.c:700
static pid_t afpd_pid
Definition netatalk.c:63