0001
0002 #include <linux/cred.h>
0003 #include <linux/init.h>
0004 #include <linux/kernel.h>
0005 #include <linux/quotaops.h>
0006 #include <linux/sched.h>
0007 #include <linux/slab.h>
0008 #include <net/netlink.h>
0009 #include <net/genetlink.h>
0010
0011 static const struct genl_multicast_group quota_mcgrps[] = {
0012 { .name = "events", },
0013 };
0014
0015
0016 static struct genl_family quota_genl_family __ro_after_init = {
0017 .module = THIS_MODULE,
0018 .hdrsize = 0,
0019 .name = "VFS_DQUOT",
0020 .version = 1,
0021 .maxattr = QUOTA_NL_A_MAX,
0022 .mcgrps = quota_mcgrps,
0023 .n_mcgrps = ARRAY_SIZE(quota_mcgrps),
0024 };
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 void quota_send_warning(struct kqid qid, dev_t dev,
0038 const char warntype)
0039 {
0040 static atomic_t seq;
0041 struct sk_buff *skb;
0042 void *msg_head;
0043 int ret;
0044 int msg_size = 4 * nla_total_size(sizeof(u32)) +
0045 2 * nla_total_size_64bit(sizeof(u64));
0046
0047
0048
0049
0050 skb = genlmsg_new(msg_size, GFP_NOFS);
0051 if (!skb) {
0052 printk(KERN_ERR
0053 "VFS: Not enough memory to send quota warning.\n");
0054 return;
0055 }
0056 msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
0057 "a_genl_family, 0, QUOTA_NL_C_WARNING);
0058 if (!msg_head) {
0059 printk(KERN_ERR
0060 "VFS: Cannot store netlink header in quota warning.\n");
0061 goto err_out;
0062 }
0063 ret = nla_put_u32(skb, QUOTA_NL_A_QTYPE, qid.type);
0064 if (ret)
0065 goto attr_err_out;
0066 ret = nla_put_u64_64bit(skb, QUOTA_NL_A_EXCESS_ID,
0067 from_kqid_munged(&init_user_ns, qid),
0068 QUOTA_NL_A_PAD);
0069 if (ret)
0070 goto attr_err_out;
0071 ret = nla_put_u32(skb, QUOTA_NL_A_WARNING, warntype);
0072 if (ret)
0073 goto attr_err_out;
0074 ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MAJOR, MAJOR(dev));
0075 if (ret)
0076 goto attr_err_out;
0077 ret = nla_put_u32(skb, QUOTA_NL_A_DEV_MINOR, MINOR(dev));
0078 if (ret)
0079 goto attr_err_out;
0080 ret = nla_put_u64_64bit(skb, QUOTA_NL_A_CAUSED_ID,
0081 from_kuid_munged(&init_user_ns, current_uid()),
0082 QUOTA_NL_A_PAD);
0083 if (ret)
0084 goto attr_err_out;
0085 genlmsg_end(skb, msg_head);
0086
0087 genlmsg_multicast("a_genl_family, skb, 0, 0, GFP_NOFS);
0088 return;
0089 attr_err_out:
0090 printk(KERN_ERR "VFS: Not enough space to compose quota message!\n");
0091 err_out:
0092 kfree_skb(skb);
0093 }
0094 EXPORT_SYMBOL(quota_send_warning);
0095
0096 static int __init quota_init(void)
0097 {
0098 if (genl_register_family("a_genl_family) != 0)
0099 printk(KERN_ERR
0100 "VFS: Failed to create quota netlink interface.\n");
0101 return 0;
0102 };
0103 fs_initcall(quota_init);