diff options
Diffstat (limited to 'fs/quota/netlink.c')
-rw-r--r-- | fs/quota/netlink.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c new file mode 100644 index 000000000000..2663ed90fb03 --- /dev/null +++ b/fs/quota/netlink.c | |||
@@ -0,0 +1,95 @@ | |||
1 | |||
2 | #include <linux/cred.h> | ||
3 | #include <linux/init.h> | ||
4 | #include <linux/module.h> | ||
5 | #include <linux/kernel.h> | ||
6 | #include <linux/quotaops.h> | ||
7 | #include <linux/sched.h> | ||
8 | #include <net/netlink.h> | ||
9 | #include <net/genetlink.h> | ||
10 | |||
11 | /* Netlink family structure for quota */ | ||
12 | static struct genl_family quota_genl_family = { | ||
13 | .id = GENL_ID_GENERATE, | ||
14 | .hdrsize = 0, | ||
15 | .name = "VFS_DQUOT", | ||
16 | .version = 1, | ||
17 | .maxattr = QUOTA_NL_A_MAX, | ||
18 | }; | ||
19 | |||
20 | /** | ||
21 | * quota_send_warning - Send warning to userspace about exceeded quota | ||
22 | * @type: The quota type: USRQQUOTA, GRPQUOTA,... | ||
23 | * @id: The user or group id of the quota that was exceeded | ||
24 | * @dev: The device on which the fs is mounted (sb->s_dev) | ||
25 | * @warntype: The type of the warning: QUOTA_NL_... | ||
26 | * | ||
27 | * This can be used by filesystems (including those which don't use | ||
28 | * dquot) to send a message to userspace relating to quota limits. | ||
29 | * | ||
30 | */ | ||
31 | |||
32 | void quota_send_warning(short type, unsigned int id, dev_t dev, | ||
33 | const char warntype) | ||
34 | { | ||
35 | static atomic_t seq; | ||
36 | struct sk_buff *skb; | ||
37 | void *msg_head; | ||
38 | int ret; | ||
39 | int msg_size = 4 * nla_total_size(sizeof(u32)) + | ||
40 | 2 * nla_total_size(sizeof(u64)); | ||
41 | |||
42 | /* We have to allocate using GFP_NOFS as we are called from a | ||
43 | * filesystem performing write and thus further recursion into | ||
44 | * the fs to free some data could cause deadlocks. */ | ||
45 | skb = genlmsg_new(msg_size, GFP_NOFS); | ||
46 | if (!skb) { | ||
47 | printk(KERN_ERR | ||
48 | "VFS: Not enough memory to send quota warning.\n"); | ||
49 | return; | ||
50 | } | ||
51 | msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq), | ||
52 | "a_genl_family, 0, QUOTA_NL_C_WARNING); | ||
53 | if (!msg_head) { | ||
54 | printk(KERN_ERR | ||
55 | "VFS: Cannot store netlink header in quota warning.\n"); | ||
56 | goto err_out; | ||
57 | } | ||
58 | ret = nla_put_u32(skb, QUOTA_NL_A_QTYPE, type); | ||
59 | if (ret) | ||
60 | goto attr_err_out; | ||
61 | ret = nla_put_u64(skb, QUOTA_NL_A_EXCESS_ID, id); | ||
62 | if (ret) | ||
63 | goto attr_err_out; | ||
64 | ret = nla_put_u32(skb, QUOTA_NL_A_WARNING, warntype); | ||
65 | if (ret) | ||
66 | goto attr_err_out; | ||
67 | ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MAJOR, MAJOR(dev)); | ||
68 | if (ret) | ||
69 | goto attr_err_out; | ||
70 | ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MINOR, MINOR(dev)); | ||
71 | if (ret) | ||
72 | goto attr_err_out; | ||
73 | ret = nla_put_u64(skb, QUOTA_NL_A_CAUSED_ID, current_uid()); | ||
74 | if (ret) | ||
75 | goto attr_err_out; | ||
76 | genlmsg_end(skb, msg_head); | ||
77 | |||
78 | genlmsg_multicast(skb, 0, quota_genl_family.id, GFP_NOFS); | ||
79 | return; | ||
80 | attr_err_out: | ||
81 | printk(KERN_ERR "VFS: Not enough space to compose quota message!\n"); | ||
82 | err_out: | ||
83 | kfree_skb(skb); | ||
84 | } | ||
85 | EXPORT_SYMBOL(quota_send_warning); | ||
86 | |||
87 | static int __init quota_init(void) | ||
88 | { | ||
89 | if (genl_register_family("a_genl_family) != 0) | ||
90 | printk(KERN_ERR | ||
91 | "VFS: Failed to create quota netlink interface.\n"); | ||
92 | return 0; | ||
93 | }; | ||
94 | |||
95 | module_init(quota_init); | ||