forked from vtl/ethblk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
111 lines (93 loc) · 2.36 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2019 Vitaly Mayatskikh <[email protected]>
*
* This work is licensed under the terms of the GNU GPL, version 2.
*
*/
#include <linux/init.h>
#include <linux/kobject.h>
#include <linux/module.h>
#include <linux/printk.h>
#include "ethblk.h"
#include "initiator.h"
#include "target.h"
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Vitaly Mayatskikh <[email protected]>");
MODULE_DESCRIPTION("High performance block-over-ethernet target and initiator");
MODULE_VERSION(VERSION);
int net_stat = 1;
module_param(net_stat, int, 0644);
MODULE_PARM_DESC(net_stat, "Enable network counters");
char *log_buf;
bool target_mode = false;
bool initiator_mode = false;
static struct kobject ethblk_sysfs_root_kobj;
static void ethblk_sysfs_root_release(struct kobject *kobj)
{
}
static struct kobj_type ethblk_sysfs_root_ktype = {
.sysfs_ops = &kobj_sysfs_ops,
.release = ethblk_sysfs_root_release,
};
static void ethblk_exit(void)
{
int ret;
ethblk_net_exit();
if (target_mode)
ret = ethblk_target_stop();
if (initiator_mode)
ret = ethblk_initiator_stop();
kobject_put(ðblk_sysfs_root_kobj);
dprintk(info, "unloaded\n");
if (log_buf)
vfree(log_buf);
}
static int __init ethblk_init(void)
{
int ret = 0;
log_buf = vmalloc(LOG_ENTRY_SIZE * NR_CPUS);
if (!log_buf) {
printk(KERN_ERR "ethblk: can't allocate log buffer\n");
goto out;
}
ret = kobject_init_and_add(ðblk_sysfs_root_kobj,
ðblk_sysfs_root_ktype, kernel_kobj, "%s",
"ethblk");
if (ret) {
dprintk(err, "can't init root sysfs object: %d\n", ret);
goto out;
}
if (target_mode) {
ret = ethblk_target_start(ðblk_sysfs_root_kobj);
if (ret) {
dprintk(err, "Target failed to start: %d\n", ret);
goto out;
}
}
if (initiator_mode) {
ret = ethblk_initiator_start(ðblk_sysfs_root_kobj);
if (ret) {
dprintk(err, "Initiator failed to start: %d\n", ret);
if (target_mode)
ethblk_target_stop();
goto out;
}
}
ethblk_net_init();
if (ret == 0)
dprintk(info, "loaded\n");
return ret;
out:
if (log_buf) {
vfree(log_buf);
log_buf = NULL;
}
return ret;
}
module_init(ethblk_init);
module_exit(ethblk_exit);
module_param_named(target, target_mode, bool, 0);
MODULE_PARM_DESC(target, "Enable target mode");
module_param_named(initiator, initiator_mode, bool, 0);
MODULE_PARM_DESC(initiator, "Enable initiator mode");