~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to ubuntu/iscsitarget/event.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Event notification code.
3
 
 * (C) 2005 FUJITA Tomonori <tomof@acm.org>
4
 
 * This code is licenced under the GPL.
5
 
 *
6
 
 * Some functions are based on audit code.
7
 
 */
8
 
 
9
 
#include <net/tcp.h>
10
 
#include "iet_u.h"
11
 
#include "iscsi_dbg.h"
12
 
 
13
 
static struct sock *nl;
14
 
static u32 ietd_pid;
15
 
 
16
 
static int event_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
17
 
{
18
 
        u32 uid, pid, seq;
19
 
        char *data;
20
 
 
21
 
        pid  = NETLINK_CREDS(skb)->pid;
22
 
        uid  = NETLINK_CREDS(skb)->uid;
23
 
        seq  = nlh->nlmsg_seq;
24
 
        data = NLMSG_DATA(nlh);
25
 
 
26
 
        ietd_pid = pid;
27
 
 
28
 
        return 0;
29
 
}
30
 
 
31
 
static void event_recv_skb(struct sk_buff *skb)
32
 
{
33
 
        int err;
34
 
        struct nlmsghdr *nlh;
35
 
        u32 rlen;
36
 
 
37
 
        while (skb->len >= NLMSG_SPACE(0)) {
38
 
                nlh = (struct nlmsghdr *)skb->data;
39
 
                if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len)
40
 
                        break;
41
 
                rlen = NLMSG_ALIGN(nlh->nlmsg_len);
42
 
                if (rlen > skb->len)
43
 
                        rlen = skb->len;
44
 
                if ((err = event_recv_msg(skb, nlh))) {
45
 
                        netlink_ack(skb, nlh, -err);
46
 
                } else if (nlh->nlmsg_flags & NLM_F_ACK)
47
 
                        netlink_ack(skb, nlh, 0);
48
 
                skb_pull(skb, rlen);
49
 
        }
50
 
}
51
 
 
52
 
static int notify(void *data, int len, int gfp_mask)
53
 
{
54
 
        struct sk_buff *skb;
55
 
        struct nlmsghdr *nlh;
56
 
        static u32 seq = 0;
57
 
 
58
 
        if (!(skb = alloc_skb(NLMSG_SPACE(len), gfp_mask)))
59
 
                return -ENOMEM;
60
 
 
61
 
        nlh = __nlmsg_put(skb, ietd_pid, seq++, NLMSG_DONE, len - sizeof(*nlh), 0);
62
 
 
63
 
        memcpy(NLMSG_DATA(nlh), data, len);
64
 
 
65
 
        return netlink_unicast(nl, skb, ietd_pid, 0);
66
 
}
67
 
 
68
 
int event_send(u32 tid, u64 sid, u32 cid, u32 state, int atomic)
69
 
{
70
 
        int err;
71
 
        struct iet_event event;
72
 
 
73
 
        event.tid = tid;
74
 
        event.sid = sid;
75
 
        event.cid = cid;
76
 
        event.state = state;
77
 
 
78
 
        err = notify(&event, NLMSG_SPACE(sizeof(struct iet_event)), 0);
79
 
 
80
 
        return err;
81
 
}
82
 
 
83
 
int event_init(void)
84
 
{
85
 
        nl = netlink_kernel_create(&init_net, NETLINK_IET, 1, event_recv_skb,
86
 
                                   NULL, THIS_MODULE);
87
 
        if (!nl)
88
 
                return -ENOMEM;
89
 
        else
90
 
                return 0;
91
 
}
92
 
 
93
 
void event_exit(void)
94
 
{
95
 
        netlink_kernel_release(nl);
96
 
}