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
= {
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.
22 .id
= GENL_ID_VFS_DQUOT
,
26 .maxattr
= QUOTA_NL_A_MAX
,
27 .mcgrps
= quota_mcgrps
,
28 .n_mcgrps
= ARRAY_SIZE(quota_mcgrps
),
32 * quota_send_warning - Send warning to userspace about exceeded quota
33 * @qid: The kernel internal quota identifier.
34 * @dev: The device on which the fs is mounted (sb->s_dev)
35 * @warntype: The type of the warning: QUOTA_NL_...
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.
42 void quota_send_warning(struct kqid qid
, dev_t dev
,
49 int msg_size
= 4 * nla_total_size(sizeof(u32
)) +
50 2 * nla_total_size_64bit(sizeof(u64
));
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
);
58 "VFS: Not enough memory to send quota warning.\n");
61 msg_head
= genlmsg_put(skb
, 0, atomic_add_return(1, &seq
),
62 "a_genl_family
, 0, QUOTA_NL_C_WARNING
);
65 "VFS: Cannot store netlink header in quota warning.\n");
68 ret
= nla_put_u32(skb
, QUOTA_NL_A_QTYPE
, qid
.type
);
71 ret
= nla_put_u64_64bit(skb
, QUOTA_NL_A_EXCESS_ID
,
72 from_kqid_munged(&init_user_ns
, qid
),
76 ret
= nla_put_u32(skb
, QUOTA_NL_A_WARNING
, warntype
);
79 ret
= nla_put_u32(skb
, QUOTA_NL_A_DEV_MAJOR
, MAJOR(dev
));
82 ret
= nla_put_u32(skb
, QUOTA_NL_A_DEV_MINOR
, MINOR(dev
));
85 ret
= nla_put_u64_64bit(skb
, QUOTA_NL_A_CAUSED_ID
,
86 from_kuid_munged(&init_user_ns
, current_uid()),
90 genlmsg_end(skb
, msg_head
);
92 genlmsg_multicast("a_genl_family
, skb
, 0, 0, GFP_NOFS
);
95 printk(KERN_ERR
"VFS: Not enough space to compose quota message!\n");
99 EXPORT_SYMBOL(quota_send_warning
);
101 static int __init
quota_init(void)
103 if (genl_register_family("a_genl_family
) != 0)
105 "VFS: Failed to create quota netlink interface.\n");
108 fs_initcall(quota_init
);