Whamcloud - gitweb
LU-8066 sysfs: make ping sysfs file read and writable 76/33776/5
authorJames Simmons <uja.ornl@yahoo.com>
Wed, 12 Dec 2018 16:19:45 +0000 (11:19 -0500)
committerOleg Drokin <green@whamcloud.com>
Fri, 4 Jan 2019 04:48:54 +0000 (04:48 +0000)
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 <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/33776
Tested-by: Jenkins
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Bobi Jam <bobijam@hotmail.com>
lustre/include/lprocfs_status.h
lustre/mdc/lproc_mdc.c
lustre/mgc/lproc_mgc.c
lustre/osc/lproc_osc.c
lustre/ptlrpc/lproc_ptlrpc.c
lustre/tests/sanity.sh
lustre/utils/liblustreapi.c

index 865553d..acf1bc0 100644 (file)
@@ -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);
 #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);
 extern ssize_t
 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
                         size_t count, loff_t *off);
index fd5dcf0..c912232 100644 (file)
@@ -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_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)
 {
 
 static int mdc_cached_mb_seq_show(struct seq_file *m, void *v)
 {
index b712008..ec4ba5e 100644 (file)
@@ -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_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,
 
 static struct attribute *mgc_attrs[] = {
        &lustre_attr_mgs_conn_uuid.attr,
index 4289266..727e930 100644 (file)
@@ -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_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)
 {
 
 static int osc_cached_mb_seq_show(struct seq_file *m, void *v)
 {
index 301088f..4e009e0 100644 (file)
@@ -1309,8 +1309,8 @@ void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd)
 }
 EXPORT_SYMBOL(ptlrpc_lprocfs_unregister_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);
 {
        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);
 
        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,
 
 /* 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,
index e5a1ca0..f785522 100755 (executable)
@@ -8630,7 +8630,6 @@ test_104b() {
        [ $RUNAS_ID -eq $UID ] &&
                skip_env "RUNAS_ID = UID = $UID -- skipping"
 
        [ $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
        denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
                        grep "Permission denied" | wc -l)))
        if [ $denied_cnt -ne 0 ]; then
index ea286c3..8f69ac6 100644 (file)
@@ -4821,26 +4821,32 @@ int llapi_obd_statfs(char *path, __u32 type, __u32 index,
 
 int llapi_ping(char *obd_type, char *obd_name)
 {
 
 int llapi_ping(char *obd_type, char *obd_name)
 {
+       int flags = O_RDONLY;
+       char buf[1] = { 0 };
        glob_t path;
        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;
        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 (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;
        }
 
                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);
        if (rc < 0)
                rc = -errno;
        close(fd);