VFS: Export dquot_send_warning
Subsystems (2)
RFC 1/1 VFS: Export dquot_send_warning
Hi,
It would be useful to have a generic method of sending quota messages to userspace. The dquot code has such a method, but it can only currently be used by that code, so I'm wondering whether there would be any objections to exporting it so that other (non-dquot) filesystems could use it?
My proposed (first draft) patch is below,
Steve.
------------------------------------------------------------------------
Quoted 1 line
From
77e4ac5ef6311073e59e6abb34e0ff53df684bd2Mon Sep 17 00:00:00 2001
From: Steven Whitehouse <[email protected]>
Date: Wed, 16 Sep 2009 18:16:11 +0100
Subject: VFS: Export dquot_send_warning
Sending a message to userspace in a generic format to warn of events (e.g. quota exceeded) in the quota subsystem is a generically useful feature. This patch makes some minor changes to the send_message function in dquot.c renaming it dquot_send_message and exporting it for use by filesystems which do not use the dquot quota code.
--- fs/quota/dquot.c | 45 ++++++++++++++++++++++++++++++--------------- include/linux/quota.h | 11 +++++++++++ 2 files changed, 41 insertions(+), 15 deletions(-)
fs/quota/dquot.c +30 -15
@@ -1082,8 +1082,21 @@ static struct genl_family quota_genl_family = { .maxattr = QUOTA_NL_A_MAX, }; -/* Send warning to userspace about user which exceeded quota */ -static void send_warning (const struct dquot *dquot,const char warntype) +/** +* dquot_send_warning - Send warning to userspace about exceeded quota +* @type: The quota type: USRQQUOTA, GRPQUOTA,... +* @id: The user or group id of the quota that was exceeded +* @dev: The device on which the fs is mounted (sb->s_dev) +* @warntype: The type of the warning: QUOTA_NL_... +* +* This can be used by filesystems (including those which don't use +* other parts of dquot) to send a message to userspace relating to +* quota limits. +* +*/ + +void dquot_send_warning (short type,unsigned int id,dev_t dev, +const char warntype) {static atomic_t seq;struct sk_buff *skb;
@@ -1108,21 +1121,19 @@ static void send_warning(const struct dquot *dquot, const char warntype) "VFS: Cannot store netlink header in quota warning.\n"); goto err_out; } - ret =nla_put_u32 (skb,QUOTA_NL_A_QTYPE , dquot->dq_type); + ret =nla_put_u32 (skb,QUOTA_NL_A_QTYPE , type);if (ret) goto attr_err_out; - ret =nla_put_u64 (skb,QUOTA_NL_A_EXCESS_ID , dquot->dq_id); + ret =nla_put_u64 (skb,QUOTA_NL_A_EXCESS_ID , id);if (ret) goto attr_err_out; ret =nla_put_u32 (skb,QUOTA_NL_A_WARNING , warntype);if (ret) goto attr_err_out; - ret =nla_put_u32 (skb,QUOTA_NL_A_DEV_MAJOR , -MAJOR (dquot->dq_sb->s_dev)); + ret =nla_put_u32 (skb,QUOTA_NL_A_DEV_MAJOR ,MAJOR (dev));if (ret) goto attr_err_out; - ret =nla_put_u32 (skb,QUOTA_NL_A_DEV_MINOR , -MINOR (dquot->dq_sb->s_dev)); + ret =nla_put_u32 (skb,QUOTA_NL_A_DEV_MINOR ,MINOR (dev));if (ret) goto attr_err_out; ret =nla_put_u64 (skb,QUOTA_NL_A_CAUSED_ID ,current_uid ());
@@ -1137,6 +1148,8 @@ attr_err_out: err_out: kfree_skb(skb); } +EXPORT_SYMBOL (dquot_send_warning); +#endif /* * Write warnings to the console and send warning messages over netlink.
@@ -1145,18 +1158,20 @@ err_out:*/ static void flush_warnings (struct dquot *const *dquots,char *warntype) { +struct dquot *dq;int i; -for (i =0 ; i <MAXQUOTAS ; i++) -if (dquots[i] && warntype[i] !=QUOTA_NL_NOWARN && - !warning_issued (dquots[i], warntype[i])) { +for (i =0 ; i <MAXQUOTAS ; i++) { + dq = dquots[i]; +if (dq && warntype[i] !=QUOTA_NL_NOWARN && + !warning_issued (dq, warntype[i])) {#ifdef CONFIG_PRINT_QUOTA_WARNING -print_warning (dquots[i], warntype[i]); -#endif -#ifdef CONFIG_QUOTA_NETLINK_INTERFACE -send_warning (dquots[i], warntype[i]); +print_warning (dq, warntype[i]);#endif +dquot_send_warning (dq->dq_type, dq->dq_id, + dq->dq_sb->s_dev, warntype[i]); } + } }static int ignore_hardlimit (struct dquot *dquot)
include/linux/quota.h +11 -0
@@ -376,6 +376,17 @@ static inline unsigned int dquot_generic_flag(unsigned int flags, int type)return flags >> _DQUOT_STATE_FLAGS; } +#ifdef CONFIG_QUOTA_NETLINK_INTERFACE +extern void dquot_send_warning (short type,unsigned int id,dev_t dev, +const char warntype); +#else +static inline void dquot_send_warning (short type,unsigned int id,dev_t dev, +const char warntype) +{ +return ; +} +#endif /* CONFIG_QUOTA_NETLINK_INTERFACE */ +struct quota_info {unsigned int flags;/* Flags for diskquotas on this device */ struct mutex dqio_mutex;/* lock device while I/O in progress */
Signature · 1 line
1.6.2.5
Quoted 8 lines · Steven Whitehouse
Hi,
It would be useful to have a generic method of sending quota messages to userspace. The dquot code has such a method, but it can only currently be used by that code, so I'm wondering whether there would be any objections to exporting it so that other (non-dquot) filesystems could use it?
My proposed (first draft) patch is below,
If you want to use it without the "generic" quotas it needs to move from dquota.c to quota.c. And of course a user in the patch series makes the likelyhood of getting this included muc higher :)
Hi,
Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · Steven Whitehouse
Hi,
It would be useful to have a generic method of sending quota messages to userspace. The dquot code has such a method, but it can only currently be used by that code, so I'm wondering whether there would be any objections to exporting it so that other (non-dquot) filesystems could use it?
Quoted 6 lines
Quoted 1 line
My proposed (first draft) patch is below,
If you want to use it without the "generic" quotas it needs to move from
dquota.ctoquota.c. And of course a user in the patch series makes the likelyhood of getting this included muc higher :)
Yes, I have a patch to make use of this from GFS2 though I didn't sent it in the first instance as its trivial and I was more worried about the generic idea being acceptable. Anyway, I'll send an updated patch, including moving/renaming where required, shortly,
Steve.
Quoted 9 lines · Steven Whitehouse
Quoted 4 lines
If you want to use it without the "generic" quotas it needs to move from
dquota.ctoquota.c. And of course a user in the patch series makes the likelyhood of getting this included muc higher :)Yes, I have a patch to make use of this from GFS2 though I didn't sent it in the first instance as its trivial and I was more worried about the generic idea being acceptable. Anyway, I'll send an updated patch, including moving/renaming where required, shortly,
Ok, if you want to be nice send a patch for XFS, too. Any I really want to exercise this functionality in XFSQA as it feels a bit fragile to me. Does anyone know about an example userspace client for the notifications?
Hi,
Quoted 11 lines · Christoph Hellwig
Quoted 9 lines · Steven Whitehouse
Quoted 4 lines
If you want to use it without the "generic" quotas it needs to move from
dquota.ctoquota.c. And of course a user in the patch series makes the likelyhood of getting this included muc higher :)Yes, I have a patch to make use of this from GFS2 though I didn't sent it in the first instance as its trivial and I was more worried about the generic idea being acceptable. Anyway, I'll send an updated patch, including moving/renaming where required, shortly,
Quoted 5 lines
Ok, if you want to be nice send a patch for XFS, too. Any I really want to exercise this functionality in XFSQA as it feels a bit fragile to me. Does anyone know about an example userspace client for the notifications?
Yes, I'll look at the other filesystems too, but I wanted to be reasonably sure that it would be ok first. I've got an updated patch which I'll send shortly.
There is a userspace client in the quota tools called quota_nld but at the moment its refusing to build for me... looks like some version issue wrt to the netlink library that its using. Otherwise I'll write my own :-)
Steve.
Hi,
Here is an updated version (moves the function to quota.c). This has had some testing with a few different kernel configs and also I've got the userland quota_nld (in the quota tools) daemon working with it,
Steve.
-----------------------------------------------------------------------
Quoted 1 line
From
42a7f843a445c369c189a8929f80692e341f1bceMon Sep 17 00:00:00 2001
From: Steven Whitehouse <[email protected]>
Date: Mon, 28 Sep 2009 12:35:17 +0100
Subject: [PATCH 11/12] VFS: Export dquot_send_warning
Sending a message to userspace in a generic format to warn of events (e.g. quota exceeded) in the quota subsystem is a generically useful feature. This patch makes some minor changes to the send_message function from dquot.c renaming it quota_send_message, moving it to quota.c and exporting it for use by filesystems which do not use the dquot code.
--- fs/quota/Kconfig | 2 +- fs/quota/dquot.c | 93 +++++-------------------------------------------- fs/quota/quota.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/quota.h | 11 ++++++ 4 files changed, 114 insertions(+), 85 deletions(-)
fs/quota/Kconfig +1 -1
@@ -17,7 +17,7 @@ config QUOTA config QUOTA_NETLINK_INTERFACE bool "Report quota messages through netlink interface" - depends on QUOTA && NET + depends on QUOTACTL && NET help If you say Y here, quota warnings (about exceeding softlimit, reaching hardlimit, etc.) will be reported through netlink interface. If unsure,
fs/quota/dquot.c +9 -84
122 lines not on this page · raw message
fs/quota/quota.c +93 -0
102 lines not on this page · raw message
include/linux/quota.h +11 -0
@@ -376,6 +376,17 @@ static inline unsigned int dquot_generic_flag(unsigned int flags, int type)return flags >> _DQUOT_STATE_FLAGS; } +#ifdef CONFIG_QUOTA_NETLINK_INTERFACE +extern void quota_send_warning (short type,unsigned int id,dev_t dev, +const char warntype); +#else +static inline void quota_send_warning (short type,unsigned int id,dev_t dev, +const char warntype) +{ +return ; +} +#endif /* CONFIG_QUOTA_NETLINK_INTERFACE */ +struct quota_info {unsigned int flags;/* Flags for diskquotas on this device */ struct mutex dqio_mutex;/* lock device while I/O in progress */
Signature · 1 line
1.6.2.5
Hi,
Here is the patch to make it work with GFS2,
Steve.
------------------------------------------------------------------------------
Quoted 1 line
From
2d098b275c0ef952e3a3a328bae1beac7d9b9017Mon Sep 17 00:00:00 2001
From: Steven Whitehouse <[email protected]>
Date: Mon, 28 Sep 2009 12:49:15 +0100
Subject: [PATCH 12/12] GFS2: Use dquot_send_warning()
This adds support to GFS2 to send quota warnings via netlink. Also it removes a stray \r which was left over from when the code used to print warnings on the console.
--- fs/gfs2/quota.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
fs/gfs2/quota.c +9 -1
@@ -47,6 +47,7 @@#include <linux/gfs2_ondisk.h> #include <linux/kthread.h> #include <linux/freezer.h> +#include <linux/quota.h> #include <linux/dqblk_xfs.h> #include "gfs2.h"
@@ -1001,7 +1002,7 @@ static int print_message(struct gfs2_quota_data *qd, char *type) {struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; -printk (KERN_INFO "GFS2: fsid=%s: quota %s for %s %u\r\n" , +printk (KERN_INFO "GFS2: fsid=%s: quota %s for %s %u\n" , sdp->sd_fsname, type, (test_bit (QDF_USER , &qd->qd_flags)) ?"user" :"group" , qd->qd_id);
@@ -1038,6 +1039,10 @@ int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid)if (be64_to_cpu (qd->qd_qb.qb_limit) && (s64 )be64_to_cpu (qd->qd_qb.qb_limit) < value) {print_message (qd,"exceeded" ); +quota_send_warning (test_bit (QDF_USER , &qd->qd_flags) ? +USRQUOTA :GRPQUOTA , qd->qd_id, + sdp->sd_vfs->s_dev,QUOTA_NL_BHARDWARN ); + error = -EDQUOT ;break ; } else if (be64_to_cpu(qd->qd_qb.qb_warn) &&
@@ -1045,6 +1050,9 @@ int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid) time_after_eq(jiffies, qd->qd_last_warn + gfs2_tune_get(sdp, gt_quota_warn_period) * HZ)) { +quota_send_warning (test_bit (QDF_USER , &qd->qd_flags) ? +USRQUOTA :GRPQUOTA , qd->qd_id, + sdp->sd_vfs->s_dev,QUOTA_NL_BSOFTWARN ); error =print_message (qd,"warning" ); qd->qd_last_warn = jiffies; }
Signature · 1 line
1.6.2.5