[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] [PATCH 10/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 in dquot.c renaming
it dquot_send_message and exporting it for use by filesystems
which do not use the dquot quota code.

Signed-off-by: Steven Whitehouse <swhiteho redhat com>
---
 fs/quota/dquot.c      |   45 ++++++++++++++++++++++++++++++---------------
 include/linux/quota.h |   11 +++++++++++
 2 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
index 38f7bd5..4ced204 100644
--- a/fs/quota/dquot.c
+++ b/fs/quota/dquot.c
@@ -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)
diff --git a/include/linux/quota.h b/include/linux/quota.h
index 78c4889..c2a13dc 100644
--- a/include/linux/quota.h
+++ b/include/linux/quota.h
@@ -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 */
-- 
1.6.2.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]