1 #include <linux/cred.h>
2 #include <linux/init.h>
3 #include <linux/kernel.h>
4 #include <linux/quotaops.h>
5 #include <linux/sched.h>
6 #include <linux/slab.h>
7 #include <net/netlink.h>
8 #include <net/genetlink.h>
10 static const struct genl_multicast_group quota_mcgrps
[] = {
11 { .name
= "events", },
14 /* Netlink family structure for quota */
15 static struct genl_family quota_genl_family __ro_after_init
= {
16 .module
= THIS_MODULE
,
20 .maxattr
= QUOTA_NL_A_MAX
,
21 .mcgrps
= quota_mcgrps
,
22 .n_mcgrps
= ARRAY_SIZE(quota_mcgrps
),
26 * quota_send_warning - Send warning to userspace about exceeded quota
27 * @qid: The kernel internal quota identifier.
28 * @dev: The device on which the fs is mounted (sb->s_dev)
29 * @warntype: The type of the warning: QUOTA_NL_...
31 * This can be used by filesystems (including those which don't use
32 * dquot) to send a message to userspace relating to quota limits.
36 void quota_send_warning(struct kqid qid
, dev_t dev
,
43 int msg_size
= 4 * nla_total_size(sizeof(u32
)) +
44 2 * nla_total_size_64bit(sizeof(u64
));
46 /* We have to allocate using GFP_NOFS as we are called from a
47 * filesystem performing write and thus further recursion into
48 * the fs to free some data could cause deadlocks. */
49 skb
= genlmsg_new(msg_size
, GFP_NOFS
);
52 "VFS: Not enough memory to send quota warning.\n");
55 msg_head
= genlmsg_put(skb
, 0, atomic_add_return(1, &seq
),
56 "a_genl_family
, 0, QUOTA_NL_C_WARNING
);
59 "VFS: Cannot store netlink header in quota warning.\n");
62 ret
= nla_put_u32(skb
, QUOTA_NL_A_QTYPE
, qid
.type
);
65 ret
= nla_put_u64_64bit(skb
, QUOTA_NL_A_EXCESS_ID
,
66 from_kqid_munged(&init_user_ns
, qid
),
70 ret
= nla_put_u32(skb
, QUOTA_NL_A_WARNING
, warntype
);
73 ret
= nla_put_u32(skb
, QUOTA_NL_A_DEV_MAJOR
, MAJOR(dev
));
76 ret
= nla_put_u32(skb
, QUOTA_NL_A_DEV_MINOR
, MINOR(dev
));
79 ret
= nla_put_u64_64bit(skb
, QUOTA_NL_A_CAUSED_ID
,
80 from_kuid_munged(&init_user_ns
, current_uid()),
84 genlmsg_end(skb
, msg_head
);
86 genlmsg_multicast("a_genl_family
, skb
, 0, 0, GFP_NOFS
);
89 printk(KERN_ERR
"VFS: Not enough space to compose quota message!\n");
93 EXPORT_SYMBOL(quota_send_warning
);
95 static int __init
quota_init(void)
97 if (genl_register_family("a_genl_family
) != 0)
99 "VFS: Failed to create quota netlink interface.\n");
102 fs_initcall(quota_init
);