2 * Copyright 2012 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following
13 * disclaimer in the documentation and/or other materials
14 * provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
29 * The views and conclusions contained in the software and
30 * documentation are those of the authors and should not be
31 * interpreted as representing official policies, either expressed
32 * or implied, of GRNET S.A.
35 #include <linux/kernel.h>
36 #include <linux/types.h>
37 #include <linux/slab.h>
38 #include <linux/module.h>
39 #include <linux/time.h>
41 #include <sys/domain.h>
43 #include <xtypes/domain.h>
44 #include <xseg/domain.h>
46 int (*xseg_snprintf)(char *str, size_t size, const char *format, ...) = snprintf;
48 char __xseg_errbuf[4096];
50 static spinlock_t __lock;
52 void __lock_domain(void)
54 spin_lock_irq(&__lock);
57 void __unlock_domain(void)
59 spin_unlock_irq(&__lock);
62 void __load_plugin(const char *name)
67 uint64_t __get_id(void)
72 int __xseg_preinit(void)
77 void __xseg_log(const char *msg)
79 (void)printk(KERN_INFO "%s\n", msg);
82 void *xtypes_malloc(unsigned long size)
84 return kmalloc(size, GFP_KERNEL);
87 void xtypes_free(void *ptr)
92 void __get_current_time(struct timeval *tv)
97 static int __init xsegmod_init(void)
99 printk(KERN_INFO "xseg loaded");
103 static void __exit xsegmod_exit(void)
105 printk(KERN_INFO "xseg unloaded");
110 int __renew_logctx(struct log_ctx *lc, char *peer_name,
111 enum log_level log_level, char *logfile, uint32_t flags)
116 int (*renew_logctx)(struct log_ctx *lc, char *peer_name,
117 enum log_level log_level, char *logfile, uint32_t flags) = __renew_logctx;
119 int __init_logctx(struct log_ctx *lc, char *peer_name,
120 enum log_level log_level, char *logfile, uint32_t flags)
123 strncpy(lc->peer_name, peer_name, MAX_PEER_NAME);
124 lc->peer_name[MAX_PEER_NAME -1] = 0;
130 lc->log_level = log_level;
134 int (*init_logctx)(struct log_ctx *lc, char *peer_name,
135 enum log_level log_level, char *logfile, uint32_t flags) = __init_logctx;
137 void __xseg_log2(struct log_ctx *lc, unsigned int level, char *fmt, ...)
144 char *type = NULL, *pn = NULL;
148 case E: type = "XSEG[EE]"; break;
149 case W: type = "XSEG[WW]"; break;
150 case I: type = "XSEG[II]"; break;
151 case D: type = "XSEG[DD]"; break;
152 default: type = "XSEG[UNKNONW]"; break;
156 pn = "Invalid peer name";
159 time_to_tm(t.tv_sec, 0, &broken);
161 buf += sprintf(buf, "%s: %s: ", type, lc->peer_name);
162 buf += sprintf(buf, "%d:%d:%d:%ld\n\t", broken.tm_hour, broken.tm_min,
163 broken.tm_sec, t.tv_usec);
164 buf += vsprintf(buf, fmt, ap);
165 buf += sprintf(buf, "\n");
167 (void)printk(KERN_INFO "%s\n", buffer);
173 void xseg_printtrace(void)
178 module_init(xsegmod_init);
179 module_exit(xsegmod_exit);
181 MODULE_DESCRIPTION("xseg");
182 MODULE_AUTHOR("XSEG");
183 MODULE_LICENSE("BSD");