From patchwork Fri Aug 17 03:10:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Simmons X-Patchwork-Id: 10568399 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B737A13B6 for ; Fri, 17 Aug 2018 03:12:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4CB62B176 for ; Fri, 17 Aug 2018 03:12:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98EAA2B1A7; Fri, 17 Aug 2018 03:12:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3079E2B176 for ; Fri, 17 Aug 2018 03:12:33 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id B20324E246E; Thu, 16 Aug 2018 20:11:36 -0700 (PDT) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from smtp4.ccs.ornl.gov (smtp4.ccs.ornl.gov [160.91.203.40]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id A90974E1E32 for ; Thu, 16 Aug 2018 20:10:57 -0700 (PDT) Received: from star.ccs.ornl.gov (star.ccs.ornl.gov [160.91.202.134]) by smtp4.ccs.ornl.gov (Postfix) with ESMTP id 488001005391; Thu, 16 Aug 2018 23:10:46 -0400 (EDT) Received: by star.ccs.ornl.gov (Postfix, from userid 2004) id 448D6463; Thu, 16 Aug 2018 23:10:46 -0400 (EDT) From: James Simmons To: Andreas Dilger , Oleg Drokin , NeilBrown Date: Thu, 16 Aug 2018 23:10:34 -0400 Message-Id: <1534475441-15543-32-git-send-email-jsimmons@infradead.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1534475441-15543-1-git-send-email-jsimmons@infradead.org> References: <1534475441-15543-1-git-send-email-jsimmons@infradead.org> Subject: [lustre-devel] [PATCH 31/38] lustre: osc: fixup kstrto* for sysfs handling X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: James Simmons , Lustre Development List MIME-Version: 1.0 Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" X-Virus-Scanned: ClamAV using ClamSMTP Some of the osc sysfs files only allow 1 or 0 which was retrieved with kstrtoul(). A much better fit would be to use kstrtobool(). This adds 'Y' or 'N' as valid options as well. Instead of using kstrtoull() for everything with additional range checking we can change to a different kstrtoxxx() so the range checking can be removed. Signed-off-by: James Simmons WC-bug-id: https://jira.whamcloud.com/browse/LU-9325 Reviewed-on: https://review.whamcloud.com/30539 Reviewed-by: Dmitry Eremin Reviewed-by: Andreas Dilger Reviewed-by: Ben Evans Reviewed-by: Oleg Drokin Signed-off-by: James Simmons --- drivers/staging/lustre/lustre/osc/lproc_osc.c | 43 ++++++++++++--------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/drivers/staging/lustre/lustre/osc/lproc_osc.c b/drivers/staging/lustre/lustre/osc/lproc_osc.c index 4ed289b..3c31e98 100644 --- a/drivers/staging/lustre/lustre/osc/lproc_osc.c +++ b/drivers/staging/lustre/lustre/osc/lproc_osc.c @@ -55,20 +55,18 @@ static ssize_t active_store(struct kobject *kobj, struct attribute *attr, { struct obd_device *dev = container_of(kobj, struct obd_device, obd_kset.kobj); + bool val; int rc; - unsigned long val; - rc = kstrtoul(buffer, 10, &val); + rc = kstrtobool(buffer, &val); if (rc) return rc; - if (val > 1) - return -ERANGE; /* opposite senses */ if (dev->u.cli.cl_import->imp_deactive == val) rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val); else - CDEBUG(D_CONFIG, "activate %ld: ignoring repeat request\n", + CDEBUG(D_CONFIG, "activate %u: ignoring repeat request\n", val); return count; @@ -94,15 +92,15 @@ static ssize_t max_rpcs_in_flight_store(struct kobject *kobj, struct obd_device *dev = container_of(kobj, struct obd_device, obd_kset.kobj); struct client_obd *cli = &dev->u.cli; - int rc; - unsigned long val; int adding, added, req_count; + unsigned int val; + int rc; - rc = kstrtoul(buffer, 10, &val); + rc = kstrtouint(buffer, 10, &val); if (rc) return rc; - if (val < 1 || val > OSC_MAX_RIF_MAX) + if (val == 0 || val > OSC_MAX_RIF_MAX) return -ERANGE; adding = val - cli->cl_max_rpcs_in_flight; @@ -334,14 +332,14 @@ static ssize_t grant_shrink_interval_store(struct kobject *kobj, { struct obd_device *obd = container_of(kobj, struct obd_device, obd_kset.kobj); + unsigned int val; int rc; - unsigned long val; - rc = kstrtoul(buffer, 10, &val); + rc = kstrtouint(buffer, 10, &val); if (rc) return rc; - if (val <= 0) + if (val == 0) return -ERANGE; obd->u.cli.cl_grant_shrink_interval = val; @@ -367,14 +365,14 @@ static ssize_t checksums_store(struct kobject *kobj, { struct obd_device *obd = container_of(kobj, struct obd_device, obd_kset.kobj); + bool val; int rc; - unsigned long val; - rc = kstrtoul(buffer, 10, &val); + rc = kstrtobool(buffer, &val); if (rc) return rc; - obd->u.cli.cl_checksum = (val ? 1 : 0); + obd->u.cli.cl_checksum = val; return count; } @@ -454,10 +452,10 @@ static ssize_t resend_count_store(struct kobject *kobj, { struct obd_device *obd = container_of(kobj, struct obd_device, obd_kset.kobj); + unsigned int val; int rc; - unsigned long val; - rc = kstrtoul(buffer, 10, &val); + rc = kstrtouint(buffer, 10, &val); if (rc) return rc; @@ -486,16 +484,13 @@ static ssize_t contention_seconds_store(struct kobject *kobj, struct obd_device *obd = container_of(kobj, struct obd_device, obd_kset.kobj); struct osc_device *od = obd2osc_dev(obd); + unsigned int val; int rc; - int val; - rc = kstrtoint(buffer, 10, &val); + rc = kstrtouint(buffer, 10, &val); if (rc) return rc; - if (val < 0) - return -EINVAL; - od->od_contention_time = val; return count; @@ -521,10 +516,10 @@ static ssize_t lockless_truncate_store(struct kobject *kobj, struct obd_device *obd = container_of(kobj, struct obd_device, obd_kset.kobj); struct osc_device *od = obd2osc_dev(obd); + bool val; int rc; - unsigned int val; - rc = kstrtouint(buffer, 10, &val); + rc = kstrtobool(buffer, &val); if (rc) return rc;