All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Simmons <jsimmons@infradead.org>
To: lustre-devel@lists.lustre.org
Subject: [lustre-devel] [PATCH 11/38] lustre: llite: create ll_stats_pid_write()
Date: Thu, 16 Aug 2018 23:10:14 -0400	[thread overview]
Message-ID: <1534475441-15543-12-git-send-email-jsimmons@infradead.org> (raw)
In-Reply-To: <1534475441-15543-1-git-send-email-jsimmons@infradead.org>

From: Steve Guminski <stephenx.guminski@intel.com>

Several repeated code blocks are consolidated into a new function,
ll_stats_pid_write(), to reduce duplication.

Signed-off-by: Steve Guminski <stephenx.guminski@intel.com>
WC-bug-id: https://jira.whamcloud.com/browse/LU-8767
Reviewed-on: https://review.whamcloud.com/23942
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
---
 drivers/staging/lustre/lustre/llite/lproc_llite.c | 90 +++++++++++------------
 1 file changed, 41 insertions(+), 49 deletions(-)

diff --git a/drivers/staging/lustre/lustre/llite/lproc_llite.c b/drivers/staging/lustre/lustre/llite/lproc_llite.c
index 0dc4d00..f57ad15 100644
--- a/drivers/staging/lustre/lustre/llite/lproc_llite.c
+++ b/drivers/staging/lustre/lustre/llite/lproc_llite.c
@@ -95,6 +95,41 @@ void llite_tunables_unregister(void)
 static const struct file_operations ll_rw_extents_stats_pp_fops;
 static const struct file_operations ll_rw_offset_stats_fops;
 
+/**
+ * ll_stats_pid_write() - Determine if stats collection should be enabled
+ * @buf: Buffer containing the data written
+ * @len: Number of bytes in the buffer
+ *
+ * Several proc files begin collecting stats when a value is written, and stop
+ * collecting when either '0' or 'disable' is written. This function checks the
+ * written value to see if collection should be enabled or disabled.
+ *
+ * Return: If '0' or 'disable' is provided, 0 is returned. If the text
+ * equivalent of a number is written, that number is returned. Otherwise,
+ * 1 is returned. Non-zero return values indicate collection should be enabled.
+ */
+static s64 ll_stats_pid_write(const char __user *buf, size_t len)
+{
+	unsigned long long value = 1;
+	char kernbuf[16];
+	int rc;
+
+	rc = kstrtoull_from_user(buf, len, 0, &value);
+	if (rc < 0 && len < sizeof(kernbuf)) {
+		if (copy_from_user(kernbuf, buf, len))
+			return -EFAULT;
+		kernbuf[len] = 0;
+
+		if (kernbuf[len - 1] == '\n')
+			kernbuf[len - 1] = 0;
+
+		if (strncasecmp(kernbuf, "disable", 7) == 0)
+			value = 0;
+	}
+
+	return value;
+}
+
 static ssize_t blocksize_show(struct kobject *kobj, struct attribute *attr,
 			      char *buf)
 {
@@ -1425,26 +1460,12 @@ static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
 	struct ll_sb_info *sbi = seq->private;
 	struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
 	int i;
-	int value = 1, rc = 0;
+	s64 value;
 
 	if (len == 0)
 		return -EINVAL;
 
-	rc = lprocfs_write_helper(buf, len, &value);
-	if (rc < 0 && len < 16) {
-		char kernbuf[16];
-
-		if (copy_from_user(kernbuf, buf, len))
-			return -EFAULT;
-		kernbuf[len] = 0;
-
-		if (kernbuf[len - 1] == '\n')
-			kernbuf[len - 1] = 0;
-
-		if (strcmp(kernbuf, "disabled") == 0 ||
-		    strcmp(kernbuf, "Disabled") == 0)
-			value = 0;
-	}
+	value = ll_stats_pid_write(buf, len);
 
 	if (value == 0)
 		sbi->ll_rw_stats_on = 0;
@@ -1498,26 +1519,12 @@ static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
 	struct ll_sb_info *sbi = seq->private;
 	struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
 	int i;
-	int value = 1, rc = 0;
+	s64 value;
 
 	if (len == 0)
 		return -EINVAL;
 
-	rc = lprocfs_write_helper(buf, len, &value);
-	if (rc < 0 && len < 16) {
-		char kernbuf[16];
-
-		if (copy_from_user(kernbuf, buf, len))
-			return -EFAULT;
-		kernbuf[len] = 0;
-
-		if (kernbuf[len - 1] == '\n')
-			kernbuf[len - 1] = 0;
-
-		if (strcmp(kernbuf, "disabled") == 0 ||
-		    strcmp(kernbuf, "Disabled") == 0)
-			value = 0;
-	}
+	value = ll_stats_pid_write(buf, len);
 
 	if (value == 0)
 		sbi->ll_rw_stats_on = 0;
@@ -1702,27 +1709,12 @@ static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
 	struct ll_sb_info *sbi = seq->private;
 	struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
 	struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
-	int value = 1, rc = 0;
+	s64 value;
 
 	if (len == 0)
 		return -EINVAL;
 
-	rc = lprocfs_write_helper(buf, len, &value);
-
-	if (rc < 0 && len < 16) {
-		char kernbuf[16];
-
-		if (copy_from_user(kernbuf, buf, len))
-			return -EFAULT;
-		kernbuf[len] = 0;
-
-		if (kernbuf[len - 1] == '\n')
-			kernbuf[len - 1] = 0;
-
-		if (strcmp(kernbuf, "disabled") == 0 ||
-		    strcmp(kernbuf, "Disabled") == 0)
-			value = 0;
-	}
+	value = ll_stats_pid_write(buf, len);
 
 	if (value == 0)
 		sbi->ll_rw_stats_on = 0;
-- 
1.8.3.1

  parent reply	other threads:[~2018-08-17  3:10 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-17  3:10 [lustre-devel] [PATCH 00/38] lustre: fixes for sysfs handling James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 01/38] lustre: llite: rename ldebugfs_[un]register_mountpoint James Simmons
2018-08-17  4:24   ` NeilBrown
2018-08-17 22:03     ` James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 02/38] lustre: llite: change ll_statfs_internal to use struct ll_sb_info James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 03/38] lustre: llite: move llite_root and llite_kset to lproc_llite.c James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 04/38] lustre: llite: remove ll_sb James Simmons
2018-08-17  4:27   ` NeilBrown
2018-08-18  0:35     ` James Simmons
2018-08-18  5:12       ` Andreas Dilger
2018-08-17  3:10 ` [lustre-devel] [PATCH 05/38] lustre: llite: change top kobject for llite into a kset James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 06/38] lustre: llite: rename llite_sb_release James Simmons
2018-08-17  5:56   ` NeilBrown
2018-08-17  3:10 ` [lustre-devel] [PATCH 07/38] lustre: llite: register mountpoint before process llog James Simmons
2018-08-17  6:21   ` NeilBrown
2018-08-17  3:10 ` [lustre-devel] [PATCH 08/38] lustre: llite: move lmd_profile handling James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 09/38] lustre: llite: add proper error handling for ll_debugfs_register_super() James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 10/38] lustre: llite: use C99 for struct lprocfs_llite_obd_vars James Simmons
2018-08-17  3:10 ` James Simmons [this message]
2018-08-17  3:10 ` [lustre-devel] [PATCH 12/38] lustre: llite: improve sysfs file text in lproc_llite.c James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 13/38] lustre: llite: don't handle success case for blocksize sysfs code James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 14/38] lustre: llite: don't handle success case for kbyte* " James Simmons
2018-08-17  6:32   ` NeilBrown
2018-08-17  3:10 ` [lustre-devel] [PATCH 15/38] lustre: llite: don't handle success case for file* " James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 16/38] lustre: llite: user kstrtobool for some sysfs handling James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 17/38] lustre: llite: add newline to llite.*.offset_stats James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 18/38] lustre: obd: embedded struct lprocfs_vars in obd device James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 19/38] lustre: obdclass: swap obd device attrs and default_attrs James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 20/38] lustre: obdclass: embedded attributes in struct obd_device James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 21/38] lustre: obdclass: add light weight obd_def_uuid_attrs James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 22/38] lustre: obd: migrate to ksets James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 23/38] lustre: obd: create class_setup_tunables() function James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 24/38] lustre: obd: create conn_uuid sysfs file James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 25/38] lustre: obd: enhance print_lustre_cfg() James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 26/38] lustre: obd: merge both top lustre sysfs attributes James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 27/38] lustre: obd: resolve config log sysfs issues James Simmons
2018-08-17  6:52   ` NeilBrown
2018-08-17  3:10 ` [lustre-devel] [PATCH 28/38] lustre: obd: move ioctl handling to class_obd.c James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 29/38] lustre: llite: replace ll_process_config with class_modify_config James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 30/38] lustre: mgc: update sysfs handling James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 31/38] lustre: osc: fixup kstrto* for " James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 32/38] lustre: osc: restore cl_loi_list_lock James Simmons
2018-08-17  7:30   ` NeilBrown
2018-08-18  0:59     ` James Simmons
2018-08-18  5:08       ` Andreas Dilger
2018-08-18  5:10         ` Andreas Dilger
2018-08-17  3:10 ` [lustre-devel] [PATCH 33/38] lustre: osc: make unstable_stats a debugfs file James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 34/38] lustre: osc: enhance end to end bulk cksum error report James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 35/38] lustre: osc: update sysfs handling James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 36/38] lustre: lmv: " James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 37/38] lustre: lov: " James Simmons
2018-08-17  3:10 ` [lustre-devel] [PATCH 38/38] lustre: mdc: " James Simmons
2018-08-20  4:28 ` [lustre-devel] [PATCH 00/38] lustre: fixes for " NeilBrown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1534475441-15543-12-git-send-email-jsimmons@infradead.org \
    --to=jsimmons@infradead.org \
    --cc=lustre-devel@lists.lustre.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.