From 6bbae72c6900dbd2b853d716bc4d456dc7fd586e Mon Sep 17 00:00:00 2001 From: James Simmons Date: Wed, 12 Dec 2018 11:19:45 -0500 Subject: [PATCH] LU-8066 sysfs: make ping sysfs file read and writable Starting with 4.15 kernels any sysfs read only is limited to root access only. To retain the ability for non root users to detect if a remote server is alive using the 'ping' sysfs file we need to change it to writable. Retain the read ability so older tools will work. Change-Id: I6560c119328d723a20a2b32e1fa8c68dce5d407a Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/33776 Tested-by: Jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Bobi Jam --- lustre/include/lprocfs_status.h | 6 +++--- lustre/mdc/lproc_mdc.c | 2 +- lustre/mgc/lproc_mgc.c | 2 +- lustre/osc/lproc_osc.c | 2 +- lustre/ptlrpc/lproc_ptlrpc.c | 37 +++++++++---------------------------- lustre/tests/sanity.sh | 1 - lustre/utils/liblustreapi.c | 18 ++++++++++++------ 7 files changed, 27 insertions(+), 41 deletions(-) diff --git a/lustre/include/lprocfs_status.h b/lustre/include/lprocfs_status.h index 865553d..acf1bc0 100644 --- a/lustre/include/lprocfs_status.h +++ b/lustre/include/lprocfs_status.h @@ -598,9 +598,9 @@ lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer, #endif ssize_t ping_store(struct kobject *kobj, struct attribute *attr, const char *buffer, size_t count); -extern ssize_t -lprocfs_ping_seq_write(struct file *file, const char __user *buffer, - size_t count, loff_t *off); +ssize_t ping_show(struct kobject *kobj, struct attribute *attr, + char *buffer); + extern ssize_t lprocfs_import_seq_write(struct file *file, const char __user *buffer, size_t count, loff_t *off); diff --git a/lustre/mdc/lproc_mdc.c b/lustre/mdc/lproc_mdc.c index fd5dcf0..c912232 100644 --- a/lustre/mdc/lproc_mdc.c +++ b/lustre/mdc/lproc_mdc.c @@ -225,7 +225,7 @@ LUSTRE_RW_ATTR(contention_seconds); LUSTRE_ATTR(mds_conn_uuid, 0444, conn_uuid_show, NULL); LUSTRE_RO_ATTR(conn_uuid); -LUSTRE_WO_ATTR(ping); +LUSTRE_RW_ATTR(ping); static int mdc_cached_mb_seq_show(struct seq_file *m, void *v) { diff --git a/lustre/mgc/lproc_mgc.c b/lustre/mgc/lproc_mgc.c index b712008..ec4ba5e 100644 --- a/lustre/mgc/lproc_mgc.c +++ b/lustre/mgc/lproc_mgc.c @@ -72,7 +72,7 @@ struct lprocfs_vars lprocfs_mgc_obd_vars[] = { LUSTRE_ATTR(mgs_conn_uuid, 0444, conn_uuid_show, NULL); LUSTRE_RO_ATTR(conn_uuid); -LUSTRE_WO_ATTR(ping); +LUSTRE_RW_ATTR(ping); static struct attribute *mgc_attrs[] = { &lustre_attr_mgs_conn_uuid.attr, diff --git a/lustre/osc/lproc_osc.c b/lustre/osc/lproc_osc.c index 4289266..727e930 100644 --- a/lustre/osc/lproc_osc.c +++ b/lustre/osc/lproc_osc.c @@ -189,7 +189,7 @@ LUSTRE_RW_ATTR(max_dirty_mb); LUSTRE_ATTR(ost_conn_uuid, 0444, conn_uuid_show, NULL); LUSTRE_RO_ATTR(conn_uuid); -LUSTRE_WO_ATTR(ping); +LUSTRE_RW_ATTR(ping); static int osc_cached_mb_seq_show(struct seq_file *m, void *v) { diff --git a/lustre/ptlrpc/lproc_ptlrpc.c b/lustre/ptlrpc/lproc_ptlrpc.c index 301088f..4e009e0 100644 --- a/lustre/ptlrpc/lproc_ptlrpc.c +++ b/lustre/ptlrpc/lproc_ptlrpc.c @@ -1309,8 +1309,8 @@ void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd) } EXPORT_SYMBOL(ptlrpc_lprocfs_unregister_obd); -ssize_t ping_store(struct kobject *kobj, struct attribute *attr, - const char *buffer, size_t count) +ssize_t ping_show(struct kobject *kobj, struct attribute *attr, + char *buffer) { struct obd_device *obd = container_of(kobj, struct obd_device, obd_kset.kobj); @@ -1329,36 +1329,17 @@ ssize_t ping_store(struct kobject *kobj, struct attribute *attr, rc = ptlrpc_queue_wait(req); ptlrpc_req_finished(req); - RETURN(rc >= 0 ? count : rc); + RETURN(rc); } -EXPORT_SYMBOL(ping_store); +EXPORT_SYMBOL(ping_show); -ssize_t -lprocfs_ping_seq_write(struct file *file, const char __user *buffer, - size_t count, loff_t *off) +/* kept for older verison of tools. */ +ssize_t ping_store(struct kobject *kobj, struct attribute *attr, + const char *buffer, size_t count) { - struct seq_file *m = file->private_data; - struct obd_device *obd = m->private; - struct ptlrpc_request *req; - int rc; - ENTRY; - - LPROCFS_CLIMP_CHECK(obd); - req = ptlrpc_prep_ping(obd->u.cli.cl_import); - LPROCFS_CLIMP_EXIT(obd); - if (req == NULL) - RETURN(-ENOMEM); - - req->rq_send_state = LUSTRE_IMP_FULL; - - rc = ptlrpc_queue_wait(req); - - ptlrpc_req_finished(req); - if (rc >= 0) - RETURN(count); - RETURN(rc); + return ping_show(kobj, attr, (char *)buffer); } -EXPORT_SYMBOL(lprocfs_ping_seq_write); +EXPORT_SYMBOL(ping_store); /* Write the connection UUID to this file to attempt to connect to that node. * The connection UUID is a node's primary NID. For example, diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index e5a1ca0..f785522 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -8630,7 +8630,6 @@ test_104b() { [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" - chmod 666 /dev/obd denied_cnt=$(($($RUNAS $LFS check servers 2>&1 | grep "Permission denied" | wc -l))) if [ $denied_cnt -ne 0 ]; then diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index ea286c3..8f69ac6 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -4821,26 +4821,32 @@ int llapi_obd_statfs(char *path, __u32 type, __u32 index, int llapi_ping(char *obd_type, char *obd_name) { + int flags = O_RDONLY; + char buf[1] = { 0 }; glob_t path; - char buf[1]; int rc, fd; rc = cfs_get_param_paths(&path, "%s/%s/ping", obd_type, obd_name); if (rc != 0) return -errno; - - fd = open(path.gl_pathv[0], O_WRONLY); +retry_open: + fd = open(path.gl_pathv[0], flags); if (fd < 0) { + if (errno == EACCES && flags == O_RDONLY) { + flags = O_WRONLY; + goto retry_open; + } rc = -errno; llapi_error(LLAPI_MSG_ERROR, rc, "error opening %s", path.gl_pathv[0]); goto failed; } - /* The purpose is to send a byte as a ping, whatever this byte is. */ - /* coverity[uninit_use_in_call] */ - rc = write(fd, buf, 1); + if (flags == O_RDONLY) + rc = read(fd, buf, sizeof(buf)); + else + rc = write(fd, buf, sizeof(buf)); if (rc < 0) rc = -errno; close(fd); -- 1.8.3.1