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>
8 #include <linux/slab.h>
9 #include <net/netlink.h>
10 #include <net/genetlink.h>
12 /* Netlink family structure for quota */
13 static struct genl_family quota_genl_family
= {
14 .id
= GENL_ID_GENERATE
,
18 .maxattr
= QUOTA_NL_A_MAX
,
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_...
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.
33 void quota_send_warning(short type
, unsigned int id
, dev_t dev
,
40 int msg_size
= 4 * nla_total_size(sizeof(u32
)) +
41 2 * nla_total_size(sizeof(u64
));
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
);
49 "VFS: Not enough memory to send quota warning.\n");
52 msg_head
= genlmsg_put(skb
, 0, atomic_add_return(1, &seq
),
53 "a_genl_family
, 0, QUOTA_NL_C_WARNING
);
56 "VFS: Cannot store netlink header in quota warning.\n");
59 ret
= nla_put_u32(skb
, QUOTA_NL_A_QTYPE
, type
);
62 ret
= nla_put_u64(skb
, QUOTA_NL_A_EXCESS_ID
, id
);
65 ret
= nla_put_u32(skb
, QUOTA_NL_A_WARNING
, warntype
);
68 ret
= nla_put_u32(skb
, QUOTA_NL_A_DEV_MAJOR
, MAJOR(dev
));
71 ret
= nla_put_u32(skb
, QUOTA_NL_A_DEV_MINOR
, MINOR(dev
));
74 ret
= nla_put_u64(skb
, QUOTA_NL_A_CAUSED_ID
, current_uid());
77 genlmsg_end(skb
, msg_head
);
79 genlmsg_multicast(skb
, 0, quota_genl_family
.id
, GFP_NOFS
);
82 printk(KERN_ERR
"VFS: Not enough space to compose quota message!\n");
86 EXPORT_SYMBOL(quota_send_warning
);
88 static int __init
quota_init(void)
90 if (genl_register_family("a_genl_family
) != 0)
92 "VFS: Failed to create quota netlink interface.\n");
96 module_init(quota_init
);