aoe  87
About: AoE (ATA over Ethernet) Protocol Driver (Linux kernel 4.8.x and greater are not supported).
  Fossies Dox: aoe-87.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

aoemain.c
Go to the documentation of this file.
1 /* Copyright (c) 2012 Coraid, Inc. See COPYING for GPL terms. */
2 /*
3  * aoemain.c
4  * Module initialization routines, discover timer
5  */
6 
7 #include <linux/hdreg.h>
8 #include <linux/blkdev.h>
9 #include <linux/module.h>
10 #include <linux/moduleparam.h>
11 #include <linux/init.h>
12 #include <linux/slab.h>
13 #include "aoe.h"
14 
15 MODULE_LICENSE("GPL");
16 MODULE_AUTHOR("Sam Hopkins <sah@coraid.com>");
17 MODULE_DESCRIPTION("AoE block/char driver for 2.6.2 and newer 2.6 kernels");
18 /* The line below, needed by DKMS, sometimes results in the warning:
19  * "Warning: could not find versions for .tmp_versions/aoe.mod"
20  */
22 
23 /* modinfo sometimes works, but this will be in sysfs */
24 static char version[] = VERSION;
26 MODULE_PARM_DESC(version, "aoe module version " VERSION "\n");
27 
28 enum { TINIT, TRUN, TKILL };
29 
30 /* copied from mm/slab.c for backwards compatibility */
31 void *
32 aoe_kcalloc(size_t n, size_t size, int flags)
33 {
34  void *ret = NULL;
35 
36  if (n != 0 && size > INT_MAX / n)
37  return ret;
38 
39  ret = kmalloc(n * size, flags);
40  if (ret)
41  memset(ret, 0, n * size);
42  return ret;
43 }
44 
45 static void
47 {
48  static struct timer_list t;
49  static volatile ulong die;
50  static spinlock_t lock;
51  ulong flags;
52  enum { DTIMERTICK = HZ * 60 }; /* one minute */
53 
54  switch (vp) {
55  case TINIT:
56  init_timer(&t);
57  spin_lock_init(&lock);
58  t.data = TRUN;
59  t.function = discover_timer;
60  die = 0;
61  case TRUN:
62  spin_lock_irqsave(&lock, flags);
63  if (!die) {
64  t.expires = jiffies + DTIMERTICK;
65  add_timer(&t);
66  }
67  spin_unlock_irqrestore(&lock, flags);
68 
69  aoecmd_cfg(0xffff, 0xff);
70  return;
71  case TKILL:
72  spin_lock_irqsave(&lock, flags);
73  die = 1;
74  spin_unlock_irqrestore(&lock, flags);
75 
76  del_timer_sync(&t);
77  default:
78  return;
79  }
80 }
81 
82 static void
83 aoe_exit(void)
84 {
86 
87  aoenet_exit();
88  unregister_blkdev(AOE_MAJOR, DEVICE_NAME);
89  aoecmd_exit();
90  aoechr_exit();
91  aoedev_exit();
92  aoeblk_exit(); /* free cache after de-allocating bufs */
93  aoedbg_exit();
94 }
95 
96 static int __init
97 aoe_init(void)
98 {
99  int ret;
100 
101  aoedbg_init();
102  ret = aoedev_init();
103  if (ret)
104  return ret;
105  ret = aoechr_init();
106  if (ret)
107  goto chr_fail;
108  ret = aoeblk_init();
109  if (ret)
110  goto blk_fail;
111  ret = aoenet_init();
112  if (ret)
113  goto net_fail;
114  ret = aoecmd_init();
115  if (ret)
116  goto cmd_fail;
117  ret = register_blkdev(AOE_MAJOR, DEVICE_NAME);
118  if (ret < 0) {
119  printk(KERN_ERR "aoe: can't register major\n");
120  goto blkreg_fail;
121  }
122  printk(KERN_INFO "aoe: AoE v%s initialised.\n", VERSION);
124  return 0;
125  blkreg_fail:
126  aoecmd_exit();
127  cmd_fail:
128  aoenet_exit();
129  net_fail:
130  aoeblk_exit();
131  blk_fail:
132  aoechr_exit();
133  chr_fail:
134  aoedev_exit();
135 
136  printk(KERN_INFO "aoe: initialisation failure.\n");
137  return ret;
138 }
139 
142 
aoedbg_exit
void aoedbg_exit(void)
Definition: aoedbg.c:268
TINIT
Definition: aoemain.c:28
VERSION
#define VERSION
Definition: aoe.h:2
aoechr_exit
void aoechr_exit(void)
Definition: aoechr.c:297
aoenet_init
int aoenet_init(void)
Definition: aoenet.c:244
module_exit
module_exit(aoe_exit)
MODULE_LICENSE
MODULE_LICENSE("GPL")
aoedbg_init
void __init aoedbg_init(void)
Definition: aoedbg.c:80
aoe.h
MODULE_VERSION
MODULE_VERSION("87")
aoe_exit
static void aoe_exit(void)
Definition: aoemain.c:83
aoe_kcalloc
void * aoe_kcalloc(size_t n, size_t size, int flags)
Definition: aoemain.c:32
TRUN
Definition: aoemain.c:28
aoecmd_cfg
void aoecmd_cfg(ushort aoemajor, unsigned char aoeminor)
Definition: aoecmd.c:1454
AOE_MAJOR
#define AOE_MAJOR
Definition: aoe.h:3
MODULE_AUTHOR
MODULE_AUTHOR("Sam Hopkins <sah@coraid.com>")
aoeblk_init
int aoeblk_init(void)
Definition: aoeblk.c:452
aoenet_exit
void aoenet_exit(void)
Definition: aoenet.c:261
ulong
unsigned long ulong
Definition: aoe-sancheck.c:30
aoedev_init
int aoedev_init(void)
Definition: aoedev.c:531
DEVICE_NAME
#define DEVICE_NAME
Definition: aoe.h:4
aoecmd_exit
void aoecmd_exit(void)
Definition: aoecmd.c:1837
MODULE_DESCRIPTION
MODULE_DESCRIPTION("AoE block/char driver for 2.6.2 and newer 2.6 kernels")
module_init
module_init(aoe_init)
aoecmd_init
int aoecmd_init(void)
Definition: aoecmd.c:1772
module_param_string
module_param_string(version, version, sizeof version, 0400)
MODULE_PARM_DESC
MODULE_PARM_DESC(version, "aoe module version " "87" "\n")
aoechr_init
int aoechr_init(void)
Definition: 24-cdc4.c:14
aoeblk_exit
void aoeblk_exit(void)
Definition: aoeblk.c:444
aoe_init
static int __init aoe_init(void)
Definition: aoemain.c:97
aoedev_exit
void aoedev_exit(void)
Definition: aoedev.c:524
discover_timer
static void discover_timer(ulong vp)
Definition: aoemain.c:46
TKILL
Definition: aoemain.c:28
version
static char version[]
Definition: aoemain.c:24