From db6a38f59903d285fdb35eff5bab2527e6cd8e94 Mon Sep 17 00:00:00 2001
From: bobijam <bobijam>
Date: Wed, 10 Sep 2008 02:59:34 +0000
Subject: [PATCH] Branch b1_8_gate b=16643 o=Herb Wartens (hwartens@llnl.gov)
 i=adilger i=johann

Description: Generic /proc file permissions
Details    : Set /Proc file permissions in a more generic way to enable non-
             root users operate on some /proc files.
---
 lustre/ChangeLog                 |  6 ++++++
 lustre/include/lprocfs_status.h  |  4 ++++
 lustre/mdc/lproc_mdc.c           |  2 +-
 lustre/mgc/lproc_mgc.c           |  2 +-
 lustre/obdclass/lprocfs_status.c | 23 +++++++++++++++++++----
 lustre/osc/lproc_osc.c           | 14 +++++++-------
 6 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/lustre/ChangeLog b/lustre/ChangeLog
index 9a8cd577a7..7604ca16b7 100644
--- a/lustre/ChangeLog
+++ b/lustre/ChangeLog
@@ -38,6 +38,12 @@ tbd Sun Microsystems, Inc.
 	* Output of lfs quota has been made less detailed by default,
 	  old (verbose) output can be obtained by using -v option.
 
+Severity   : enhancement
+Bugzilla   : 16643
+Description: Generic /proc file permissions
+Details    : Set /Proc file permissions in a more generic way to enable non-
+             root users operate on some /proc files.
+
 Severity   : major
 Bugzilla   : 16561
 Description: Hitting mdc_commit_close() ASSERTION
diff --git a/lustre/include/lprocfs_status.h b/lustre/include/lprocfs_status.h
index 34038724e1..34d9106630 100644
--- a/lustre/include/lprocfs_status.h
+++ b/lustre/include/lprocfs_status.h
@@ -64,6 +64,10 @@ struct lprocfs_vars {
         cfs_write_proc_t *write_fptr;
         void *data;
         struct file_operations *fops;
+        /**
+         * /proc file mode.
+         */
+        mode_t proc_mode;
 };
 
 struct lprocfs_static_vars {
diff --git a/lustre/mdc/lproc_mdc.c b/lustre/mdc/lproc_mdc.c
index 470996a256..81f8af2bee 100644
--- a/lustre/mdc/lproc_mdc.c
+++ b/lustre/mdc/lproc_mdc.c
@@ -77,7 +77,7 @@ static int mdc_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
 }
 static struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
         { "uuid",            lprocfs_rd_uuid,        0, 0 },
-        { "ping",            0, lprocfs_wr_ping,        0 },
+        { "ping",            0, lprocfs_wr_ping,     0, 0, 0222 },
         { "connect_flags",   lprocfs_rd_connect_flags, 0, 0 },
         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
diff --git a/lustre/mgc/lproc_mgc.c b/lustre/mgc/lproc_mgc.c
index a8172649a7..c679668a6c 100644
--- a/lustre/mgc/lproc_mgc.c
+++ b/lustre/mgc/lproc_mgc.c
@@ -44,7 +44,7 @@
 
 static struct lprocfs_vars lprocfs_mgc_obd_vars[] = {
         { "uuid",            lprocfs_rd_uuid,          0, 0 },
-        { "ping",            0, lprocfs_wr_ping,          0 },
+        { "ping",            0, lprocfs_wr_ping,       0, 0, 0222 },
         { "connect_flags",   lprocfs_rd_connect_flags, 0, 0 },
         { "mgs_server_uuid", lprocfs_rd_server_uuid,   0, 0 },
         { "mgs_conn_uuid",   lprocfs_rd_conn_uuid,     0, 0 },
diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c
index 9d2fdd3bff..70bb76c63a 100644
--- a/lustre/obdclass/lprocfs_status.c
+++ b/lustre/obdclass/lprocfs_status.c
@@ -232,6 +232,17 @@ struct file_operations lprocfs_evict_client_fops = {
 };
 EXPORT_SYMBOL(lprocfs_evict_client_fops);
 
+/**
+ * Add /proc entrys.
+ *
+ * \param root [in]  The parent proc entry on which new entry will be added.
+ * \param list [in]  Array of proc entries to be added.
+ * \param data [in]  The argument to be passed when entries read/write routines
+ *                   are called through /proc file.
+ *
+ * \retval 0   on success
+ *         < 0 on error
+ */
 int lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
                      void *data)
 {
@@ -271,10 +282,14 @@ int lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
                                             proc_mkdir(cur, cur_root));
                         } else if (proc == NULL) {
                                 mode_t mode = 0;
-                                if (list->read_fptr)
-                                        mode = 0444;
-                                if (list->write_fptr)
-                                        mode |= 0200;
+                                if (list->proc_mode != 0000) {
+                                        mode = list->proc_mode;
+                                } else {
+                                        if (list->read_fptr)
+                                                mode = 0444;
+                                        if (list->write_fptr)
+                                                mode |= 0200;
+                                }
                                 proc = create_proc_entry(cur, mode, cur_root);
                         }
                 }
diff --git a/lustre/osc/lproc_osc.c b/lustre/osc/lproc_osc.c
index f6f72958d9..508bae52e6 100644
--- a/lustre/osc/lproc_osc.c
+++ b/lustre/osc/lproc_osc.c
@@ -62,7 +62,7 @@ static int osc_wr_active(struct file *file, const char *buffer,
 {
         struct obd_device *dev = data;
         int val, rc;
-        
+
         rc = lprocfs_write_helper(buffer, count, &val);
         if (rc)
                 return rc;
@@ -71,11 +71,11 @@ static int osc_wr_active(struct file *file, const char *buffer,
 
         LPROCFS_CLIMP_CHECK(dev);
         /* opposite senses */
-        if (dev->u.cli.cl_import->imp_deactive == val) 
+        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 %d: ignoring repeat request\n", val);
-        
+
         LPROCFS_CLIMP_EXIT(dev);
         return count;
 }
@@ -425,7 +425,7 @@ static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
 {
         struct obd_device *obd = data;
 
-        return snprintf(page, count, "%u\n", atomic_read(&obd->u.cli.cl_resends)); 
+        return snprintf(page, count, "%u\n", atomic_read(&obd->u.cli.cl_resends));
 }
 
 static int osc_wr_resend_count(struct file *file, const char *buffer,
@@ -448,7 +448,7 @@ static int osc_wr_resend_count(struct file *file, const char *buffer,
 
 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
         { "uuid",            lprocfs_rd_uuid,        0, 0 },
-        { "ping",            0, lprocfs_wr_ping,        0 },
+        { "ping",            0, lprocfs_wr_ping,     0, 0, 0222 },
         { "connect_flags",   lprocfs_rd_connect_flags, 0, 0 },
         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
@@ -459,7 +459,7 @@ static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
         //{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },
         { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
         { "ost_conn_uuid",   lprocfs_rd_conn_uuid, 0, 0 },
-        { "active",          osc_rd_active, 
+        { "active",          osc_rd_active,
                              osc_wr_active, 0 },
         { "max_pages_per_rpc", osc_rd_max_pages_per_rpc,
                                osc_wr_max_pages_per_rpc, 0 },
@@ -572,7 +572,7 @@ static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
                 write_cum += w;
                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
                            (i == 0) ? 0 : 1 << (i - 1),
-                           r, pct(r, read_tot), pct(read_cum, read_tot), 
+                           r, pct(r, read_tot), pct(read_cum, read_tot),
                            w, pct(w, write_tot), pct(write_cum, write_tot));
                 if (read_cum == read_tot && write_cum == write_tot)
                         break;
-- 
GitLab