Merge branch 'core-lib-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[deliverable/linux.git] / fs / quota / netlink.c
CommitLineData
799a9d44
CH
1#include <linux/cred.h>
2#include <linux/init.h>
799a9d44
CH
3#include <linux/kernel.h>
4#include <linux/quotaops.h>
5#include <linux/sched.h>
5a0e3ad6 6#include <linux/slab.h>
799a9d44
CH
7#include <net/netlink.h>
8#include <net/genetlink.h>
9
2a94fe48
JB
10static const struct genl_multicast_group quota_mcgrps[] = {
11 { .name = "events", },
12};
13
799a9d44
CH
14/* Netlink family structure for quota */
15static struct genl_family quota_genl_family = {
2ecf7536
JB
16 /*
17 * Needed due to multicast group ID abuse - old code assumed
18 * the family ID was also a valid multicast group ID (which
19 * isn't true) and userspace might thus rely on it. Assign a
20 * static ID for this group to make dealing with that easier.
21 */
22 .id = GENL_ID_VFS_DQUOT,
799a9d44
CH
23 .hdrsize = 0,
24 .name = "VFS_DQUOT",
25 .version = 1,
26 .maxattr = QUOTA_NL_A_MAX,
2a94fe48
JB
27 .mcgrps = quota_mcgrps,
28 .n_mcgrps = ARRAY_SIZE(quota_mcgrps),
2ecf7536
JB
29};
30
799a9d44
CH
31/**
32 * quota_send_warning - Send warning to userspace about exceeded quota
2c15ac5b 33 * @qid: The kernel internal quota identifier.
799a9d44
CH
34 * @dev: The device on which the fs is mounted (sb->s_dev)
35 * @warntype: The type of the warning: QUOTA_NL_...
36 *
37 * This can be used by filesystems (including those which don't use
38 * dquot) to send a message to userspace relating to quota limits.
39 *
40 */
41
431f1974 42void quota_send_warning(struct kqid qid, dev_t dev,
799a9d44
CH
43 const char warntype)
44{
45 static atomic_t seq;
46 struct sk_buff *skb;
47 void *msg_head;
48 int ret;
49 int msg_size = 4 * nla_total_size(sizeof(u32)) +
50 2 * nla_total_size(sizeof(u64));
51
52 /* We have to allocate using GFP_NOFS as we are called from a
53 * filesystem performing write and thus further recursion into
54 * the fs to free some data could cause deadlocks. */
55 skb = genlmsg_new(msg_size, GFP_NOFS);
56 if (!skb) {
57 printk(KERN_ERR
58 "VFS: Not enough memory to send quota warning.\n");
59 return;
60 }
61 msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
62 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
63 if (!msg_head) {
64 printk(KERN_ERR
65 "VFS: Cannot store netlink header in quota warning.\n");
66 goto err_out;
67 }
431f1974 68 ret = nla_put_u32(skb, QUOTA_NL_A_QTYPE, qid.type);
799a9d44
CH
69 if (ret)
70 goto attr_err_out;
431f1974
EB
71 ret = nla_put_u64(skb, QUOTA_NL_A_EXCESS_ID,
72 from_kqid_munged(&init_user_ns, qid));
799a9d44
CH
73 if (ret)
74 goto attr_err_out;
75 ret = nla_put_u32(skb, QUOTA_NL_A_WARNING, warntype);
76 if (ret)
77 goto attr_err_out;
78 ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MAJOR, MAJOR(dev));
79 if (ret)
80 goto attr_err_out;
81 ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MINOR, MINOR(dev));
82 if (ret)
83 goto attr_err_out;
431f1974
EB
84 ret = nla_put_u64(skb, QUOTA_NL_A_CAUSED_ID,
85 from_kuid_munged(&init_user_ns, current_uid()));
799a9d44
CH
86 if (ret)
87 goto attr_err_out;
88 genlmsg_end(skb, msg_head);
89
2a94fe48 90 genlmsg_multicast(&quota_genl_family, skb, 0, 0, GFP_NOFS);
799a9d44
CH
91 return;
92attr_err_out:
93 printk(KERN_ERR "VFS: Not enough space to compose quota message!\n");
94err_out:
95 kfree_skb(skb);
96}
97EXPORT_SYMBOL(quota_send_warning);
98
99static int __init quota_init(void)
100{
101 if (genl_register_family(&quota_genl_family) != 0)
102 printk(KERN_ERR
103 "VFS: Failed to create quota netlink interface.\n");
104 return 0;
105};
7da54463 106fs_initcall(quota_init);
This page took 0.387562 seconds and 5 git commands to generate.