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