Staging: lustre: Replace macros with static inline functions
v2 cover Staging: lustre: Replace macros with static inline functions
Convert macros LPROCFS_CLIMP_CHECK and LPROCFS_CLIMP_EXIT into static inline functions
Ksenija Stanojevic (2):
Staging: lustre: Replace LPROCFS_CLIMP_CHECK with lprocfs_climp_check
Staging: lustre: Replace LPROCFS_CLIMP_EXIT with up_read
.../staging/lustre/lustre/include/lprocfs_status.h | 13 ------ drivers/staging/lustre/lustre/include/obd_class.h | 10 +++++ drivers/staging/lustre/lustre/mgc/mgc_request.c | 8 +++- .../lustre/lustre/obdclass/lprocfs_status.c | 50 ++++++++++++++++------ .../staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c | 22 +++++++--- 5 files changed, 68 insertions(+), 35 deletions(-)
Signature · 1 line
1.9.1
PATCH v2 1/2 Staging: lustre: Replace LPROCFS_CLIMP_CHECK with lprocfs_climp_check
Static inline functions are preferred over macros. The function is placed in obd_class.h instead lprocfs_status.h because obd_class.h includes header obd.h which contains definition of struct obd_device and in that way avoids build error: Dereferencing pointer to incomplete type. Also remove macro LPROCFS_CLIMP_CHECK since it's no longer used.
---
Changes in v2:
- remove macro in this patch and not in separate one
.../staging/lustre/lustre/include/lprocfs_status.h | 10 ------ drivers/staging/lustre/lustre/include/obd_class.h | 10 ++++++ drivers/staging/lustre/lustre/mgc/mgc_request.c | 6 +++- .../lustre/lustre/obdclass/lprocfs_status.c | 38 +++++++++++++++++----- .../staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c | 16 +++++++-- 5 files changed, 58 insertions(+), 22 deletions(-)
drivers/staging/lustre/lustre/include/lprocfs_status.h +0 -10
@@ -626,16 +626,6 @@ void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,int lprocfs_single_release (struct inode *,struct file *);int lprocfs_seq_release (struct inode *,struct file *); -/* You must use these macros when you want to refer to -* the import in a client obd_device for a lprocfs entry */ -#define LPROCFS_CLIMP_CHECK (obd) do { \ - typecheck(struct obd_device *, obd); \ - down_read(&(obd)->u.cli.cl_sem); \ - if ((obd)->u.cli.cl_import == NULL) { \ - up_read(&(obd)->u.cli.cl_sem); \ - return -ENODEV; \ - } \ -} while (0)#define LPROCFS_CLIMP_EXIT (obd) \ up_read(&(obd)->u.cli.cl_sem)
drivers/staging/lustre/lustre/include/obd_class.h +10 -0
@@ -251,6 +251,16 @@ static inline enum obd_option exp_flags_from_obd(struct obd_device *obd) 0); } +static inline int lprocfs_climp_check (struct obd_device *obd) +{ +down_read (&(obd)->u.cli.cl_sem); +if (!(obd)->u.cli.cl_import) { +up_read (&(obd)->u.cli.cl_sem); +return -ENODEV ; + } +return 0 ; +} +struct inode ;struct lu_attr ;struct obdo ;
drivers/staging/lustre/lustre/mgc/mgc_request.c +5 -1
@@ -440,8 +440,12 @@ int lprocfs_mgc_rd_ir_state(struct seq_file *m, void *data)struct obd_import *imp;struct obd_connect_data *ocd;struct config_llog_data *cld; +int rc; + + rc =lprocfs_climp_check (obd); +if (rc) +return rc; -LPROCFS_CLIMP_CHECK (obd); imp = obd->u.cli.cl_import; ocd = &imp->imp_connect_data;
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +30 -8
@@ -489,9 +489,13 @@ int lprocfs_rd_server_uuid(struct seq_file *m, void *data)struct obd_device *obd = data;struct obd_import *imp;char *imp_state_name =NULL ; +int rc;LASSERT (obd !=NULL ); -LPROCFS_CLIMP_CHECK (obd); + rc =lprocfs_climp_check (obd); +if (rc) +return rc; + imp = obd->u.cli.cl_import; imp_state_name =ptlrpc_import_state_name (imp->imp_state); seq_printf(m, "%s\t%s%s\n",
@@ -508,10 +512,14 @@ int lprocfs_rd_conn_uuid(struct seq_file *m, void *data) {struct obd_device *obd = data;struct ptlrpc_connection *conn; +int rc;LASSERT (obd !=NULL ); -LPROCFS_CLIMP_CHECK (obd); + rc =lprocfs_climp_check (obd); +if (rc) +return rc; + conn = obd->u.cli.cl_import->imp_connection;if (conn && obd->u.cli.cl_import)seq_printf (m,"%s\n" , conn->c_remote_uuid.uuid);
@@ -618,9 +626,13 @@ int lprocfs_rd_import(struct seq_file *m, void *data)int j;int k;int rw =0 ; +int rc;LASSERT (obd !=NULL ); -LPROCFS_CLIMP_CHECK (obd); + rc =lprocfs_climp_check (obd); +if (rc) +return rc; + imp = obd->u.cli.cl_import; seq_printf(m,
@@ -759,10 +771,13 @@ int lprocfs_rd_state(struct seq_file *m, void *data) {struct obd_device *obd = data;struct obd_import *imp; -int j, k; +int j, k, rc;LASSERT (obd !=NULL ); -LPROCFS_CLIMP_CHECK (obd); + rc =lprocfs_climp_check (obd); +if (rc) +return rc; + imp = obd->u.cli.cl_import; seq_printf(m, "current_state: %s\n",
@@ -802,10 +817,13 @@ int lprocfs_rd_timeouts(struct seq_file *m, void *data)unsigned int cur, worst;time64_t now, worstt;struct dhms ts; -int i; +int i, rc;LASSERT (obd !=NULL ); -LPROCFS_CLIMP_CHECK (obd); + rc =lprocfs_climp_check (obd); +if (rc) +return rc; + imp = obd->u.cli.cl_import; now =ktime_get_real_seconds ();
@@ -845,8 +863,12 @@ int lprocfs_rd_connect_flags(struct seq_file *m, void *data) {struct obd_device *obd = data;__u64 flags; +int rc; + + rc =lprocfs_climp_check (obd); +if (rc) +return rc; -LPROCFS_CLIMP_CHECK (obd); flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;seq_printf (m,"flags=%#llx\n" , flags);obd_connect_seq_flags2str (m, flags,"\n" );
drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c +13 -3
@@ -1189,7 +1189,10 @@ int lprocfs_wr_ping(struct file *file, const char __user *buffer,struct ptlrpc_request *req;int rc; -LPROCFS_CLIMP_CHECK (obd); + rc =lprocfs_climp_check (obd); +if (rc) +return rc; + req =ptlrpc_prep_ping (obd->u.cli.cl_import);LPROCFS_CLIMP_EXIT (obd);if (req ==NULL )
@@ -1278,8 +1281,12 @@ int lprocfs_rd_pinger_recov(struct seq_file *m, void *n) {struct obd_device *obd = m->private;struct obd_import *imp = obd->u.cli.cl_import; +int rc; + + rc =lprocfs_climp_check (obd); +if (rc) +return rc; -LPROCFS_CLIMP_CHECK (obd);seq_printf (m,"%d\n" , !imp->imp_no_pinger_recover);LPROCFS_CLIMP_EXIT (obd);
@@ -1302,7 +1309,10 @@ int lprocfs_wr_pinger_recov(struct file *file, const char __user *buffer,if (val !=0 && val !=1 )return -ERANGE ; -LPROCFS_CLIMP_CHECK (obd); + rc =lprocfs_climp_check (obd); +if (rc) +return rc; +spin_lock (&imp->imp_lock); imp->imp_no_pinger_recover = !val;spin_unlock (&imp->imp_lock);
Signature · 1 line
1.9.1
PATCH v2 2/2 Staging: lustre: Replace LPROCFS_CLIMP_EXIT with up_read
In reply to Ksenija StanojevicIn all call sites type of argument that macro LPROCFS_CLIMP_EXIT use is the same, so replace it with up_read function. Also remove the macro since it's no longer used.
---
Changes in v2:
- remove macro in this patch and not in separate one.
- use up_read and not a static inline wrapper function
drivers/staging/lustre/lustre/include/lprocfs_status.h | 3 --- drivers/staging/lustre/lustre/mgc/mgc_request.c | 2 +- drivers/staging/lustre/lustre/obdclass/lprocfs_status.c | 12 ++++++------ drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c | 6 +++--- 4 files changed, 10 insertions(+), 13 deletions(-)
drivers/staging/lustre/lustre/include/lprocfs_status.h +0 -3
@@ -626,9 +626,6 @@ void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,int lprocfs_single_release (struct inode *,struct file *);int lprocfs_seq_release (struct inode *,struct file *); -#define LPROCFS_CLIMP_EXIT (obd) \ - up_read(&(obd)->u.cli.cl_sem) -/* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only proc entries; otherwise, you will define name##_seq_write function also for a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
drivers/staging/lustre/lustre/mgc/mgc_request.c +1 -1
@@ -463,7 +463,7 @@ int lprocfs_mgc_rd_ir_state(struct seq_file *m, void *data) }spin_unlock (&config_list_lock); -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);return 0 ; }
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +6 -6
@@ -502,7 +502,7 @@ int lprocfs_rd_server_uuid(struct seq_file *m, void *data)obd2cli_tgt (obd), imp_state_name, imp->imp_deactive ? "\tDEACTIVATED" : ""); -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);return 0 ; }
@@ -526,7 +526,7 @@ int lprocfs_rd_conn_uuid(struct seq_file *m, void *data)else seq_puts (m,"<none>\n" ); -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);return 0 ; }
@@ -762,7 +762,7 @@ int lprocfs_rd_import(struct seq_file *m, void *data) } out_climp: -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);return 0 ; }EXPORT_SYMBOL (lprocfs_rd_import);
@@ -793,7 +793,7 @@ int lprocfs_rd_state(struct seq_file *m, void *data) ptlrpc_import_state_name(ish->ish_state)); } -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);return 0 ; }EXPORT_SYMBOL (lprocfs_rd_state);
@@ -854,7 +854,7 @@ int lprocfs_rd_timeouts(struct seq_file *m, void *data)lprocfs_at_hist_helper (m, &imp->imp_at.iat_service_estimate[i]); } -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);return 0 ; }EXPORT_SYMBOL (lprocfs_rd_timeouts);
@@ -873,7 +873,7 @@ int lprocfs_rd_connect_flags(struct seq_file *m, void *data)seq_printf (m,"flags=%#llx\n" , flags);obd_connect_seq_flags2str (m, flags,"\n" );seq_printf (m,"\n" ); -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);return 0 ; }EXPORT_SYMBOL (lprocfs_rd_connect_flags);
drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c +3 -3
@@ -1194,7 +1194,7 @@ int lprocfs_wr_ping(struct file *file, const char __user *buffer,return rc; req =ptlrpc_prep_ping (obd->u.cli.cl_import); -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);if (req ==NULL )return -ENOMEM ;
@@ -1288,7 +1288,7 @@ int lprocfs_rd_pinger_recov(struct seq_file *m, void *n)return rc;seq_printf (m,"%d\n" , !imp->imp_no_pinger_recover); -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);return 0 ; }
@@ -1316,7 +1316,7 @@ int lprocfs_wr_pinger_recov(struct file *file, const char __user *buffer,spin_lock (&imp->imp_lock); imp->imp_no_pinger_recover = !val;spin_unlock (&imp->imp_lock); -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);return count;
Signature · 1 line
1.9.1
Re: [Outreachy kernel] [PATCH v2 2/2] Staging: lustre: Replace LPROCFS_CLIMP_EXIT with up_read
Quoted 35 lines · Ksenija Stanojevic
In all call sites type of argument that macro
LPROCFS_CLIMP_EXITuse is the same, so replace it withup_readfunction. Also remove the macro since it's no longer used.Signed-off-by Ksenija Stanojevic <[email protected]>---
Changes in v2:
- remove macro in this patch and not in separate one.
- useup_readand not a static inline wrapper functiondrivers/staging/lustre/lustre/include/lprocfs_status.h | 3 --- drivers/staging/lustre/lustre/mgc/mgc_request.c | 2 +- drivers/staging/lustre/lustre/obdclass/lprocfs_status.c | 12 ++++++------ drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c | 6 +++--- 4 files changed, 10 insertions(+), 13 deletions(-)drivers/staging/lustre/lustre/include/lprocfs_status.h +0
-3@@ -626,9 +626,6 @@ void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,int lprocfs_single_release (struct inode *,struct file *);int lprocfs_seq_release (struct inode *,struct file *); -#define LPROCFS_CLIMP_EXIT (obd) \ - up_read(&(obd)->u.cli.cl_sem) -/* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only proc entries; otherwise, you will define name##_seq_write function also for a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally, drivers/staging/lustre/lustre/mgc/mgc_request.c +0
-0
drivers/staging/lustre/lustre/mgc/mgc_request.c int lprocfs_mgc_rd_ir_state(struct seq_file *m, void *data) · line 466
Quoted 5 lines
drivers/staging/lustre/lustre/mgc/mgc_request.c +1
-1@@ -463,7 +463,7 @@ int lprocfs_mgc_rd_ir_state(struct seq_file *m, void *data) }spin_unlock (&config_list_lock); -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);
I don't think you need the parentheses.
julia
Quoted 102 lines
drivers/staging/lustre/lustre/mgc/mgc_request.c +0
-0return 0 ; }drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +6
-6@@ -502,7 +502,7 @@ int lprocfs_rd_server_uuid(struct seq_file *m, void *data)obd2cli_tgt (obd), imp_state_name, imp->imp_deactive ? "\tDEACTIVATED" : ""); -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);return 0 ; }@@ -526,7 +526,7 @@ int lprocfs_rd_conn_uuid(struct seq_file *m, void *data)else seq_puts (m,"<none>\n" ); -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);return 0 ; }@@ -762,7 +762,7 @@ int lprocfs_rd_import(struct seq_file *m, void *data) } out_climp: -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);return 0 ; }EXPORT_SYMBOL (lprocfs_rd_import);@@ -793,7 +793,7 @@ int lprocfs_rd_state(struct seq_file *m, void *data) ptlrpc_import_state_name(ish->ish_state)); } -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);return 0 ; }EXPORT_SYMBOL (lprocfs_rd_state);@@ -854,7 +854,7 @@ int lprocfs_rd_timeouts(struct seq_file *m, void *data)lprocfs_at_hist_helper (m, &imp->imp_at.iat_service_estimate[i]); } -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);return 0 ; }EXPORT_SYMBOL (lprocfs_rd_timeouts);@@ -873,7 +873,7 @@ int lprocfs_rd_connect_flags(struct seq_file *m, void *data)seq_printf (m,"flags=%#llx\n" , flags);obd_connect_seq_flags2str (m, flags,"\n" );seq_printf (m,"\n" ); -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);return 0 ; }EXPORT_SYMBOL (lprocfs_rd_connect_flags);drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c +3
-4@@ -1194,7 +1194,7 @@ int lprocfs_wr_ping(struct file *file, const char __user *buffer,return rc; req =ptlrpc_prep_ping (obd->u.cli.cl_import); -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);if (req ==NULL )return -ENOMEM ;@@ -1288,7 +1288,7 @@ int lprocfs_rd_pinger_recov(struct seq_file *m, void *n)return rc;seq_printf (m,"%d\n" , !imp->imp_no_pinger_recover); -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);return 0 ; }@@ -1316,7 +1316,7 @@ int lprocfs_wr_pinger_recov(struct file *file, const char __user *buffer,spin_lock (&imp->imp_lock); imp->imp_no_pinger_recover = !val;spin_unlock (&imp->imp_lock); -LPROCFS_CLIMP_EXIT (obd); +up_read (&(obd)->u.cli.cl_sem);return count; --1.9.1
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/0e2d7570c644c1de4d1cf681e6f13de3e0fb1ff7.1445871650.git.ksenija.stanojevic%40gmail.com.
For more options, visit https://groups.google.com/d/optout.