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 <net/netlink.h>
9 #include <net/genetlink.h>
11 /* Netlink family structure for quota */
12 static struct genl_family quota_genl_family
= {
13 .id
= GENL_ID_GENERATE
,
17 .maxattr
= QUOTA_NL_A_MAX
,
21 * quota_send_warning - Send warning to userspace about exceeded quota
22 * @type: The quota type: USRQQUOTA, GRPQUOTA,...
23 * @id: The user or group id of the quota that was exceeded
24 * @dev: The device on which the fs is mounted (sb->s_dev)
25 * @warntype: The type of the warning: QUOTA_NL_...
27 * This can be used by filesystems (including those which don't use
28 * dquot) to send a message to userspace relating to quota limits.
32 void quota_send_warning(short type
, unsigned int id
, dev_t dev
,
39 int msg_size
= 4 * nla_total_size(sizeof(u32
)) +
40 2 * nla_total_size(sizeof(u64
));
42 /* We have to allocate using GFP_NOFS as we are called from a
43 * filesystem performing write and thus further recursion into
44 * the fs to free some data could cause deadlocks. */
45 skb
= genlmsg_new(msg_size
, GFP_NOFS
);
48 "VFS: Not enough memory to send quota warning.\n");
51 msg_head
= genlmsg_put(skb
, 0, atomic_add_return(1, &seq
),
52 "a_genl_family
, 0, QUOTA_NL_C_WARNING
);
55 "VFS: Cannot store netlink header in quota warning.\n");
58 ret
= nla_put_u32(skb
, QUOTA_NL_A_QTYPE
, type
);
61 ret
= nla_put_u64(skb
, QUOTA_NL_A_EXCESS_ID
, id
);
64 ret
= nla_put_u32(skb
, QUOTA_NL_A_WARNING
, warntype
);
67 ret
= nla_put_u32(skb
, QUOTA_NL_A_DEV_MAJOR
, MAJOR(dev
));
70 ret
= nla_put_u32(skb
, QUOTA_NL_A_DEV_MINOR
, MINOR(dev
));
73 ret
= nla_put_u64(skb
, QUOTA_NL_A_CAUSED_ID
, current_uid());
76 genlmsg_end(skb
, msg_head
);
78 genlmsg_multicast(skb
, 0, quota_genl_family
.id
, GFP_NOFS
);
81 printk(KERN_ERR
"VFS: Not enough space to compose quota message!\n");
85 EXPORT_SYMBOL(quota_send_warning
);
87 static int __init
quota_init(void)
89 if (genl_register_family("a_genl_family
) != 0)
91 "VFS: Failed to create quota netlink interface.\n");
95 module_init(quota_init
);