"Fossies" - the Fresh Open Source Software Archive

Member "aoe-aoe6-86/linux/drivers/block/aoe/aoemain.c" (4 Jul 2015, 2826 Bytes) of archive /linux/misc/aoe-aoe6-86.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code 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  */
   21 MODULE_VERSION(VERSION);
   22 
   23 /* modinfo sometimes works, but this will be in sysfs */
   24 static char version[] = VERSION;
   25 module_param_string(version, version, sizeof version, 0400);
   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
   46 discover_timer(ulong vp)
   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 {
   85     discover_timer(TKILL);
   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);
  123     discover_timer(TINIT);
  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 
  140 module_init(aoe_init);
  141 module_exit(aoe_exit);
  142