11 #include <linux/slab.h>
14 #include <linux/export.h>
43 static int emsgs_head_idx, emsgs_tail_idx;
46 static int nblocked_emsgs_readers;
47 static struct class *aoe_class;
64 interfaces(
const char __user *
str,
size_t size)
68 "aoe: could not set interface list: too many interfaces\n");
75 revalidate(
const char __user *str,
size_t size)
83 if (size >=
sizeof buf)
85 buf[
sizeof buf - 1] =
'\0';
89 n =
sscanf(buf,
"e%d.%d", &major, &minor);
91 pr_err(
"aoe: invalid device specification %s\n", buf);
102 spin_unlock_irqrestore(&d->
lock, flags);
113 __skb_queue_head_init(&
queue);
114 __skb_queue_tail(&
queue, skb);
131 em = emsgs + emsgs_tail_idx;
133 bail: spin_unlock_irqrestore(&emsgs_lock, flags);
151 spin_unlock_irqrestore(&emsgs_lock, flags);
153 if (nblocked_emsgs_readers)
158 aoechr_write(
struct file *filp,
const char __user *buf,
size_t cnt, loff_t *offp)
170 ret = interfaces(buf, cnt);
173 ret = revalidate(buf, cnt);
194 if (chardevs[i].minor == n) {
203 aoechr_rel(
struct inode *inode,
struct file *filp)
209 aoechr_read(
struct file *filp,
char __user *buf,
size_t cnt, loff_t *off)
224 em = emsgs + emsgs_head_idx;
228 spin_unlock_irqrestore(&emsgs_lock, flags);
231 nblocked_emsgs_readers++;
233 spin_unlock_irqrestore(&emsgs_lock, flags);
239 nblocked_emsgs_readers--;
242 spin_unlock_irqrestore(&emsgs_lock, flags);
247 spin_unlock_irqrestore(&emsgs_lock, flags);
258 spin_unlock_irqrestore(&emsgs_lock, flags);
262 return n == 0 ? len : -
EFAULT;
266 .write = aoechr_write,
269 .release = aoechr_rel,
284 n = register_chrdev(
AOE_MAJOR,
"aoechr", &aoe_fops);
289 init_completion(&emsgs_comp);
292 if (IS_ERR(aoe_class)) {
294 return PTR_ERR(aoe_class);
296 aoe_class->
devnode = aoe_devnode;