From 406cd8a74d84c9e28b042792d4b2766f744fc36a Mon Sep 17 00:00:00 2001 From: James Simmons Date: Thu, 14 Jun 2018 12:53:29 -0400 Subject: [PATCH] LU-8066 osc: fix idle_timeout handling The patch that landed for LU-7236 introduced new sysfs entries which were done wrong. 1) For idle_timeout it returns -ERANGE for any value passed in expect setting idle_timeout to zero. This does not match what the commit message said for LU-7236. So I changed lprocfs_str_with_units_to_s64() into kstrtouint() since a signed 64 bit timeout is not needed. Using kstrtouint() ensures that negative values are not possible and also cap the value to CONNECTION_SWITCH_MAX since the max of 4 billion seconds is over kill. 2) For the next procfs idle_connect it is really a write only file but it was treated as both read and write. There is no need for the osc_idle_connect_seq_show() function. 3) Lastly no more stuffing new entries into proc or debugfs. For this patch convert these new proc entries to sysfs. It seems to be a common occurrence so add LPROC_SEQ_* to spelling.txt so checkpatch will complain about using LPROC_SEQ_* which will go away. Change-Id: I1c992b2db47aade6a887919824d869e8d5354c71 Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/32719 Reviewed-by: Alex Zhuravlev Reviewed-by: John L. Hammond Reviewed-by: Andreas Dilger Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- contrib/scripts/spelling.txt | 5 +++++ lustre/osc/lproc_osc.c | 49 ++++++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/contrib/scripts/spelling.txt b/contrib/scripts/spelling.txt index 9061f01..4dfc385 100644 --- a/contrib/scripts/spelling.txt +++ b/contrib/scripts/spelling.txt @@ -128,6 +128,11 @@ LPLD||%ld LPLX||%#lx LPPID||%d LPROCFS||CONFIG_PROC_FS +LPROC_SEQ_FOPS_WR_ONLY||LUSTRE_WO_ATTR +LPROC_SEQ_FOPS_RO_TYPE||LUSTRE_RO_ATTR +LPROC_SEQ_FOPS_RO||LUSTRE_RO_ATTR +LPROC_SEQ_FOPS_RW_TYPE||LUSTRE_RW_ATTR +LPROC_SEQ_FOPS||LUSTRE_RW_ATTR lprocfs_str_to_s64||kstrtoxxx_from_user mktemp||mkstemp sprintf||snprintf diff --git a/lustre/osc/lproc_osc.c b/lustre/osc/lproc_osc.c index 3c0e138..5c012e4 100644 --- a/lustre/osc/lproc_osc.c +++ b/lustre/osc/lproc_osc.c @@ -608,29 +608,31 @@ static int osc_unstable_stats_seq_show(struct seq_file *m, void *v) } LPROC_SEQ_FOPS_RO(osc_unstable_stats); -static int osc_idle_timeout_seq_show(struct seq_file *m, void *v) +static ssize_t idle_timeout_show(struct kobject *kobj, struct attribute *attr, + char *buf) { - struct obd_device *obd = m->private; + struct obd_device *obd = container_of(kobj, struct obd_device, + obd_kset.kobj); struct client_obd *cli = &obd->u.cli; - seq_printf(m, "%u\n", cli->cl_import->imp_idle_timeout); - return 0; + return sprintf(buf, "%u\n", cli->cl_import->imp_idle_timeout); } -static ssize_t osc_idle_timeout_seq_write(struct file *f, - const char __user *buffer, - size_t count, loff_t *off) +static ssize_t idle_timeout_store(struct kobject *kobj, struct attribute *attr, + const char *buffer, size_t count) { - struct obd_device *dev = ((struct seq_file *)f->private_data)->private; + struct obd_device *dev = container_of(kobj, struct obd_device, + obd_kset.kobj); struct client_obd *cli = &dev->u.cli; struct ptlrpc_request *req; - __s64 val; + unsigned int val; int rc; - rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1'); + rc = kstrtouint(buffer, 10, &val); if (rc) return rc; - if (val < 0 || val > 1) + + if (val > CONNECTION_SWITCH_MAX) return -ERANGE; cli->cl_import->imp_idle_timeout = val; @@ -644,30 +646,25 @@ static ssize_t osc_idle_timeout_seq_write(struct file *f, return count; } -LPROC_SEQ_FOPS(osc_idle_timeout); - -static int osc_idle_connect_seq_show(struct seq_file *m, void *v) -{ - return 0; -} +LUSTRE_RW_ATTR(idle_timeout); -static ssize_t osc_idle_connect_seq_write(struct file *f, - const char __user *buffer, - size_t count, loff_t *off) +static ssize_t idle_connect_store(struct kobject *kobj, struct attribute *attr, + const char *buffer, size_t count) { - struct obd_device *dev = ((struct seq_file *)f->private_data)->private; + struct obd_device *dev = container_of(kobj, struct obd_device, + obd_kset.kobj); struct client_obd *cli = &dev->u.cli; struct ptlrpc_request *req; /* to initiate the connection if it's in IDLE state */ req = ptlrpc_request_alloc(cli->cl_import, &RQF_OST_STATFS); - if (req != NULL) + if (req) ptlrpc_req_finished(req); ptlrpc_pinger_force(cli->cl_import); return count; } -LPROC_SEQ_FOPS(osc_idle_connect); +LUSTRE_WO_ATTR(idle_connect); LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags); LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid); @@ -700,10 +697,6 @@ struct lprocfs_vars lprocfs_osc_obd_vars[] = { .fops = &osc_pinger_recov_fops }, { .name = "unstable_stats", .fops = &osc_unstable_stats_fops }, - { .name = "idle_timeout", - .fops = &osc_idle_timeout_fops }, - { .name = "idle_connect", - .fops = &osc_idle_connect_fops }, { NULL } }; @@ -889,6 +882,8 @@ static struct attribute *osc_attrs[] = { &lustre_attr_resend_count.attr, &lustre_attr_conn_uuid.attr, &lustre_attr_ping.attr, + &lustre_attr_idle_timeout.attr, + &lustre_attr_idle_connect.attr, NULL, }; -- 1.8.3.1