Whamcloud - gitweb
Branch HEAD
authorbobijam <bobijam>
Wed, 10 Sep 2008 02:43:33 +0000 (02:43 +0000)
committerbobijam <bobijam>
Wed, 10 Sep 2008 02:43:33 +0000 (02:43 +0000)
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
lustre/include/lprocfs_status.h
lustre/mdc/lproc_mdc.c
lustre/mgc/lproc_mgc.c
lustre/obdclass/lprocfs_status.c
lustre/osc/lproc_osc.c

index 499c535..f9ebc36 100644 (file)
@@ -12,6 +12,12 @@ tbd  Sun Microsystems, Inc.
        * RHEL 4 and RHEL 5/SLES 10 clients behaves differently on 'cd' to a
         removed cwd "./" (refer to Bugzilla 14399).
 
        * RHEL 4 and RHEL 5/SLES 10 clients behaves differently on 'cd' to a
         removed cwd "./" (refer to Bugzilla 14399).
 
+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
 Severity   : major
 Bugzilla   : 16561
 Description: Hitting mdc_commit_close() ASSERTION
index 319d799..c3e69c7 100644 (file)
@@ -64,6 +64,10 @@ struct lprocfs_vars {
         cfs_write_proc_t *write_fptr;
         void *data;
         struct file_operations *fops;
         cfs_write_proc_t *write_fptr;
         void *data;
         struct file_operations *fops;
+        /**
+         * /proc file mode.
+         */
+        mode_t proc_mode;
 };
 
 struct lprocfs_static_vars {
 };
 
 struct lprocfs_static_vars {
index 470996a..81f8af2 100644 (file)
@@ -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 },
 }
 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 },
         { "connect_flags",   lprocfs_rd_connect_flags, 0, 0 },
         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
index a817264..c679668 100644 (file)
@@ -44,7 +44,7 @@
 
 static struct lprocfs_vars lprocfs_mgc_obd_vars[] = {
         { "uuid",            lprocfs_rd_uuid,          0, 0 },
 
 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 },
         { "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 },
index 7841007..cef248d 100644 (file)
@@ -117,7 +117,7 @@ int lprocfs_add_simple(struct proc_dir_entry *root, char *name,
 {
         struct proc_dir_entry *proc;
         mode_t mode = 0;
 {
         struct proc_dir_entry *proc;
         mode_t mode = 0;
-        
+
         if (root == NULL || name == NULL)
                 return -EINVAL;
         if (read_proc)
         if (root == NULL || name == NULL)
                 return -EINVAL;
         if (read_proc)
@@ -167,7 +167,7 @@ static ssize_t lprocfs_fops_read(struct file *f, char __user *buf,
         LPROCFS_ENTRY();
         OBD_FAIL_TIMEOUT(OBD_FAIL_LPROC_REMOVE, 10);
         if (!dp->deleted && dp->read_proc)
         LPROCFS_ENTRY();
         OBD_FAIL_TIMEOUT(OBD_FAIL_LPROC_REMOVE, 10);
         if (!dp->deleted && dp->read_proc)
-                rc = dp->read_proc(page, &start, *ppos, CFS_PAGE_SIZE, 
+                rc = dp->read_proc(page, &start, *ppos, CFS_PAGE_SIZE,
                         &eof, dp->data);
         LPROCFS_EXIT();
         if (rc <= 0)
                         &eof, dp->data);
         LPROCFS_EXIT();
         if (rc <= 0)
@@ -247,6 +247,17 @@ struct file_operations lprocfs_evict_client_fops = {
 };
 EXPORT_SYMBOL(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)
 {
 int lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
                      void *data)
 {
@@ -286,10 +297,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;
                                             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);
                         }
                 }
                                 proc = create_proc_entry(cur, mode, cur_root);
                         }
                 }
@@ -343,7 +358,7 @@ void lprocfs_remove(struct proc_dir_entry **rooth)
                          "0x%p  %s/%s len %d\n", rm_entry, temp->name,
                          rm_entry->name, (int)strlen(rm_entry->name));
 
                          "0x%p  %s/%s len %d\n", rm_entry, temp->name,
                          rm_entry->name, (int)strlen(rm_entry->name));
 
-                /* Now, the rm_entry->deleted flags is protected 
+                /* Now, the rm_entry->deleted flags is protected
                  * by _lprocfs_lock. */
                 rm_entry->data = NULL;
                 remove_proc_entry(rm_entry->name, temp);
                  * by _lprocfs_lock. */
                 rm_entry->data = NULL;
                 remove_proc_entry(rm_entry->name, temp);
@@ -433,14 +448,14 @@ int lprocfs_wr_atomic(struct file *file, const char *buffer,
         atomic_t *atm = data;
         int val = 0;
         int rc;
         atomic_t *atm = data;
         int val = 0;
         int rc;
-        
+
         rc = lprocfs_write_helper(buffer, count, &val);
         if (rc < 0)
                 return rc;
 
         if (val <= 0)
                 return -ERANGE;
         rc = lprocfs_write_helper(buffer, count, &val);
         if (rc < 0)
                 return rc;
 
         if (val <= 0)
                 return -ERANGE;
-                
+
         atomic_set(atm, val);
         return count;
 }
         atomic_set(atm, val);
         return count;
 }
@@ -783,7 +798,7 @@ int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list)
 
 int lprocfs_obd_cleanup(struct obd_device *obd)
 {
 
 int lprocfs_obd_cleanup(struct obd_device *obd)
 {
-        if (!obd) 
+        if (!obd)
                 return -EINVAL;
         if (obd->obd_proc_exports_entry) {
                 /* Should be no exports left */
                 return -EINVAL;
         if (obd->obd_proc_exports_entry) {
                 /* Should be no exports left */
@@ -1234,7 +1249,7 @@ int lprocfs_alloc_obd_stats(struct obd_device *obd, unsigned num_private_stats)
 
 void lprocfs_free_obd_stats(struct obd_device *obd)
 {
 
 void lprocfs_free_obd_stats(struct obd_device *obd)
 {
-        if (obd->obd_stats) 
+        if (obd->obd_stats)
                 lprocfs_free_stats(&obd->obd_stats);
 }
 
                 lprocfs_free_stats(&obd->obd_stats);
 }
 
@@ -1592,7 +1607,7 @@ int lprocfs_read_frac_helper(char *buffer, unsigned long count, long val, int mu
                         2. #echo x.0x > /proc/xxx       output result : x.0x
                         3. #echo x.x0 > /proc/xxx       output result : x.x
                         4. #echo x.xx > /proc/xxx       output result : x.xx
                         2. #echo x.0x > /proc/xxx       output result : x.0x
                         3. #echo x.x0 > /proc/xxx       output result : x.x
                         4. #echo x.xx > /proc/xxx       output result : x.xx
-                        Only reserved 2bits fraction.       
+                        Only reserved 2bits fraction.
                  */
                 for (i = 0; i < (5 - prtn); i++)
                         temp_mult *= 10;
                  */
                 for (i = 0; i < (5 - prtn); i++)
                         temp_mult *= 10;
@@ -1671,7 +1686,7 @@ int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
                 units <<= 10;
         }
         /* Specified units override the multiplier */
                 units <<= 10;
         }
         /* Specified units override the multiplier */
-        if (units) 
+        if (units)
                 mult = mult < 0 ? -units : units;
 
         frac *= mult;
                 mult = mult < 0 ? -units : units;
 
         frac *= mult;
@@ -1680,7 +1695,7 @@ int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
         return 0;
 }
 
         return 0;
 }
 
-int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, 
+int lprocfs_seq_create(cfs_proc_dir_entry_t *parent,
                        char *name, mode_t mode,
                        struct file_operations *seq_fops, void *data)
 {
                        char *name, mode_t mode,
                        struct file_operations *seq_fops, void *data)
 {
@@ -1702,7 +1717,7 @@ __inline__ int lprocfs_obd_seq_create(struct obd_device *dev, char *name,
                                       struct file_operations *seq_fops,
                                       void *data)
 {
                                       struct file_operations *seq_fops,
                                       void *data)
 {
-        return (lprocfs_seq_create(dev->obd_proc_entry, name, 
+        return (lprocfs_seq_create(dev->obd_proc_entry, name,
                                    mode, seq_fops, data));
 }
 EXPORT_SYMBOL(lprocfs_obd_seq_create);
                                    mode, seq_fops, data));
 }
 EXPORT_SYMBOL(lprocfs_obd_seq_create);
@@ -1856,7 +1871,7 @@ int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
                                  obd->obd_requests_queued_for_recovery) <= 0)
                 goto out;
 
                                  obd->obd_requests_queued_for_recovery) <= 0)
                 goto out;
 
-        if (lprocfs_obd_snprintf(&page, size, &len, "next_transno: "LPD64"\n", 
+        if (lprocfs_obd_snprintf(&page, size, &len, "next_transno: "LPD64"\n",
                                  obd->obd_next_recovery_transno) <= 0)
                 goto out;
 
                                  obd->obd_next_recovery_transno) <= 0)
                 goto out;
 
@@ -1873,7 +1888,7 @@ int lprocfs_obd_rd_recovery_maxtime(char *page, char **start, off_t off,
         struct obd_device *obd = (struct obd_device *)data;
         LASSERT(obd != NULL);
 
         struct obd_device *obd = (struct obd_device *)data;
         LASSERT(obd != NULL);
 
-        return snprintf(page, count, "%lu\n", 
+        return snprintf(page, count, "%lu\n",
                         obd->obd_recovery_max_time);
 }
 EXPORT_SYMBOL(lprocfs_obd_rd_recovery_maxtime);
                         obd->obd_recovery_max_time);
 }
 EXPORT_SYMBOL(lprocfs_obd_rd_recovery_maxtime);
index 2ae9521..7aa7b2c 100644 (file)
@@ -61,7 +61,7 @@ static int osc_wr_active(struct file *file, const char *buffer,
 {
         struct obd_device *dev = data;
         int val, rc;
 {
         struct obd_device *dev = data;
         int val, rc;
-        
+
         rc = lprocfs_write_helper(buffer, count, &val);
         if (rc)
                 return rc;
         rc = lprocfs_write_helper(buffer, count, &val);
         if (rc)
                 return rc;
@@ -70,11 +70,11 @@ static int osc_wr_active(struct file *file, const char *buffer,
 
         LPROCFS_CLIMP_CHECK(dev);
         /* opposite senses */
 
         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);
                 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;
 }
         LPROCFS_CLIMP_EXIT(dev);
         return count;
 }
@@ -112,7 +112,7 @@ static int osc_wr_max_pages_per_rpc(struct file *file, const char *buffer,
         client_obd_list_lock(&cli->cl_loi_list_lock);
         cli->cl_max_pages_per_rpc = val;
         client_obd_list_unlock(&cli->cl_loi_list_lock);
         client_obd_list_lock(&cli->cl_loi_list_lock);
         cli->cl_max_pages_per_rpc = val;
         client_obd_list_unlock(&cli->cl_loi_list_lock);
-        
+
         LPROCFS_CLIMP_EXIT(dev);
         return count;
 }
         LPROCFS_CLIMP_EXIT(dev);
         return count;
 }
@@ -152,7 +152,7 @@ static int osc_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
         client_obd_list_lock(&cli->cl_loi_list_lock);
         cli->cl_max_rpcs_in_flight = val;
         client_obd_list_unlock(&cli->cl_loi_list_lock);
         client_obd_list_lock(&cli->cl_loi_list_lock);
         cli->cl_max_rpcs_in_flight = val;
         client_obd_list_unlock(&cli->cl_loi_list_lock);
-        
+
         LPROCFS_CLIMP_EXIT(dev);
         return count;
 }
         LPROCFS_CLIMP_EXIT(dev);
         return count;
 }
@@ -458,7 +458,7 @@ static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
 {
         struct obd_device *obd = data;
 
 {
         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,
 }
 
 static int osc_wr_resend_count(struct file *file, const char *buffer,
@@ -481,7 +481,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 },
 
 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 },
         { "connect_flags",   lprocfs_rd_connect_flags, 0, 0 },
         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
@@ -492,7 +492,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 },
         //{ "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 },
                              osc_wr_active, 0 },
         { "max_pages_per_rpc", osc_rd_max_pages_per_rpc,
                                osc_wr_max_pages_per_rpc, 0 },
@@ -605,7 +605,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),
                 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;
                            w, pct(w, write_tot), pct(write_cum, write_tot));
                 if (read_cum == read_tot && write_cum == write_tot)
                         break;