opt
/
kaspersky
/
kav4fs
/
src
/
kernel
/
module.linux
➕ New
📤 Upload
✎ Editing:
watchdog.c
← Back
#include "watchdog.h" #include "module.h" #include "queue.h" #include <oas/small/protocol.h> #include <linux/kthread.h> #include <linux/delay.h> #include <linux/sched.h> #include <linux/fs.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> static bool Monitor_watchdog_timeout_expired(void); static int Monitor_watchdog_thread(void*); enum WatchdogState { WATCHDOG_STOPPED = 0, WATCHDOG_STARTED = 1, }; static atomic_t watchdog_state = ATOMIC_INIT(WATCHDOG_STOPPED); struct monitor_watchdog_ops watchdog_ops; struct task_struct* watchdog = NULL; // static struct proc_dir_entry* watchdog_file; static int watchdog_proc_print(struct seq_file* m, void* v) { long hitratio; seq_printf(m, "Processed requests: %ld\n", atomic_long_read(&queue_stats.requests)); seq_printf(m, "Detected objected: %ld\n", atomic_long_read(&queue_stats.detects)); hitratio = 10000 * atomic_long_read(&queue_stats.requests) / atomic_long_read(&queue_stats.allocs); seq_printf(m, "Cache hit ratio: %ld.%2ld\n", hitratio / 100, hitratio % 100); return 0; } static int watchdog_open(struct inode* inode, struct file* file) { return single_open(file, watchdog_proc_print, NULL); } static const struct file_operations watchdog_fops = { .owner = THIS_MODULE, .open = watchdog_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, }; int Monitor_watchdog_init(struct monitor_watchdog_ops* ops) { int rv; if (WATCHDOG_STARTED == atomic_read(&watchdog_state)) { printk(KERN_ERR "klflt: watchdog already running\n"); return 1; } watchdog_ops.invoke = ops->invoke; watchdog = kthread_run(Monitor_watchdog_thread, NULL, "kav_watchdog"); if (IS_ERR(watchdog)) { rv = PTR_ERR(watchdog); printk(KERN_ERR "klflt: init watchdog thread failed, err=%d\n", rv); return 1; } return 0; } int Monitor_watchdog_cleanup(void) { if (WATCHDOG_STOPPED != atomic_read(&watchdog_state)) { kthread_stop(watchdog); } return 1; } int Monitor_watchdog_stop(void) { return Monitor_watchdog_cleanup(); } static bool Monitor_watchdog_timeout_expired(void) { check_req_data_t* reqd; bool result = false; u_short queue_id = Monitor_queue_get_id(); enum FileAccessType answer = FILE_ACCESS_ACCEPT; if (!atomic_read(&monitor_started)) return false; reqd = (check_req_data_t*)MEM_ALLOC(sizeof(*reqd)); if (!reqd) return -ENOMEM; fill_check_req_common_fields(reqd, CHECK_FILE, 0, 0, NULL, NULL, MONITOR_WATCHDOG_FILENAME); reqd->file_op_type = FILE_OPEN_OPER; result = (Monitor_timedqueue_add(queue_id, 0, reqd, &answer, MONITOR_WATCHDOG_PERIOD) == 1); check_req_queue_put(reqd); return result; } static int Monitor_watchdog_thread(void* unused) { int proc_created = 1; atomic_xchg(&watchdog_state, WATCHDOG_STARTED); if (!proc_create(MONITOR_WATCHDOG_NAME, 0, NULL, &watchdog_fops)) { printk(KERN_INFO "klflt: Warning! Failed to create %s\n", MONITOR_WATCHDOG_NAME); proc_created = 0; } while (!kthread_should_stop()) { if (Monitor_watchdog_timeout_expired()) { watchdog_ops.invoke(); break; } msleep(MONITOR_WATCHDOG_PERIOD); } if (proc_created) remove_proc_entry(MONITOR_WATCHDOG_NAME, NULL); atomic_xchg(&watchdog_state, WATCHDOG_STOPPED); return 0; }
💾 Save Changes
Cancel
📤 Upload File
×
Select File
Upload
Cancel
➕ Create New
×
Type
📄 File
📁 Folder
Name
Create
Cancel
✎ Rename Item
×
Current Name
New Name
Rename
Cancel
🔐 Change Permissions
×
Target File
Permission (e.g., 0755, 0644)
0755
0644
0777
Apply
Cancel