staging: lustre: include: replace macros by functions
v3 cover staging: lustre: include: replace macros by functions
Replace two macros with static inline functions that return values. Inline functions are preferred because compilers are aware of them and can optimize the calls. In addition, if macros are treated like functions they can introduce bugs into the code.
Some minor fixes were done in patches 1 and 2 of the series. That is why the patchset is resent.
Aya Mahfouz (3):
staging: lustre: include: replace OBD_CHECK_DEV by obd_check_dev
staging: lustre: include: replace OBD_CHECK_DEV_ACTIVE by
obd_check_dev_active
staging: lustre: include: remove unused macros
drivers/staging/lustre/lustre/include/obd_class.h | 76 +++++++++++++++-------- 1 file changed, 50 insertions(+), 26 deletions(-)
Signature · 6 lines
2.1.0 -- Kind Regards, Aya Saif El-yazal Mahfouz
PATCH v3 1/3 staging: lustre: include: replace OBD_CHECK_DEV by obd_check_dev
Static inline functions are preferred over macros. Hence, the function obd_check_dev was introduced. obd_check_dev replaces the macro OBD_CHECK_DEV. All functions that call obd_check_dev store the return values and return them if they represent an error code.
Some of the changes were carried out manually and others were done using coccinelle.
---
v2: removed unneeded parenthesis around the variable obd.
v3: v2 was sent as v1. Fixed that mistake.
drivers/staging/lustre/lustre/include/obd_class.h | 33 ++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/include/obd_class.h +27 -6
@@ -341,6 +341,15 @@ do { \ } \ }while (0 ) +static inline int obd_check_dev(struct obd_device *obd) +{ +if (!obd) { +CERROR ("NULL device\n" ); +return -ENODEV ; + } +return 0 ; +} +/* ensure obd_setup and !obd_stopping */ #define OBD_CHECK_DEV_ACTIVE (obd) \ do { \
@@ -594,7 +603,9 @@ static inline int obd_precleanup(struct obd_device *obd,int rc;DECLARE_LU_VARS (ldt, d); -OBD_CHECK_DEV (obd); + rc =obd_check_dev (obd); +if (rc) +return rc; ldt = obd->obd_type->typ_lu; d = obd->obd_lu_dev;if (ldt !=NULL && d !=NULL ) {
@@ -620,7 +631,9 @@ static inline int obd_cleanup(struct obd_device *obd)int rc;DECLARE_LU_VARS (ldt, d); -OBD_CHECK_DEV (obd); + rc =obd_check_dev (obd); +if (rc) +return rc; ldt = obd->obd_type->typ_lu; d = obd->obd_lu_dev;
@@ -668,7 +681,9 @@ obd_process_config(struct obd_device *obd, int datalen, void *data)int rc;DECLARE_LU_VARS (ldt, d); -OBD_CHECK_DEV (obd); + rc =obd_check_dev (obd); +if (rc) +return rc; obd->obd_process_conf =1 ; ldt = obd->obd_type->typ_lu;
@@ -1280,7 +1295,9 @@ static inline int obd_notify(struct obd_device *obd, {int rc; -OBD_CHECK_DEV (obd); + rc =obd_check_dev (obd); +if (rc) +return rc;/* the check for async_recov is a complete hack - I'm hereby overloading the meaning to also mean "this was called from
@@ -1381,7 +1398,11 @@ static inline int obd_health_check(const struct lu_env *env,static inline int obd_register_observer (struct obd_device *obd,struct obd_device *observer) { -OBD_CHECK_DEV (obd); +int rc; + + rc =obd_check_dev (obd); +if (rc) +return rc;down_write (&obd->obd_observer_link_sem);if (obd->obd_observer && observer) {up_write (&obd->obd_observer_link_sem);
@@ -1389,7 +1410,7 @@ static inline int obd_register_observer(struct obd_device *obd, } obd->obd_observer = observer;up_write (&obd->obd_observer_link_sem); -return 0 ; +return rc; }#if 0
Signature · 6 lines
2.1.0 -- Kind Regards, Aya Saif El-yazal Mahfouz
PATCH v3 2/3 staging: lustre: include: replace OBD_CHECK_DEV_ACTIVE by obd_check_dev_active
In reply to Aya MahfouzStatic inline functions are preferred over macros. The inline function obd_check_dev_active is introduced to replace OBD_CHECK_DEV_ACTIVE. All functions that call obd_check_dev_active store the return values and return them if they represent an error code.
Some of the changes were carried out manually while others were done using coccinelle.
---
v2: removed unneeded parenthesis around the variable obd.
v3: v2 was sent as v1. Fixed that mistake.
drivers/staging/lustre/lustre/include/obd_class.h | 29 +++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-)
drivers/staging/lustre/lustre/include/obd_class.h +25 -4
@@ -361,6 +361,19 @@ do { \ } \ }while (0 ) +static inline int obd_check_dev_active(struct obd_device *obd) +{ +int rc; + + rc =obd_check_dev (obd); +if (rc) +return rc; +if (!obd->obd_set_up || obd->obd_stopping) { +CERROR ("Device %d not setup\n" , obd->obd_minor); +return -ENODEV ; + } +return rc; +}#if defined (CONFIG_PROC_FS )#define OBD_COUNTER_OFFSET (op) \
@@ -901,7 +914,9 @@ static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,struct obd_device *obd = imp->imp_obd;int rc; -OBD_CHECK_DEV_ACTIVE (obd); + rc =obd_check_dev_active (obd); +if (rc) +return rc;OBD_CHECK_DT_OP (obd, add_conn, -EOPNOTSUPP );OBD_COUNTER_INCREMENT (obd, add_conn);
@@ -914,7 +929,9 @@ static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)struct obd_device *obd = imp->imp_obd;int rc; -OBD_CHECK_DEV_ACTIVE (obd); + rc =obd_check_dev_active (obd); +if (rc) +return rc;OBD_CHECK_DT_OP (obd, del_conn, -EOPNOTSUPP );OBD_COUNTER_INCREMENT (obd, del_conn);
@@ -948,7 +965,9 @@ static inline int obd_connect(const struct lu_env *env,__u64 ocf = data ? data->ocd_connect_flags :0 ;/* for post-condition * check */ -OBD_CHECK_DEV_ACTIVE (obd); + rc =obd_check_dev_active (obd); +if (rc) +return rc;OBD_CHECK_DT_OP (obd, connect, -EOPNOTSUPP );OBD_COUNTER_INCREMENT (obd, connect);
@@ -970,7 +989,9 @@ static inline int obd_reconnect(const struct lu_env *env,__u64 ocf = d ? d->ocd_connect_flags :0 ;/* for post-condition * check */ -OBD_CHECK_DEV_ACTIVE (obd); + rc =obd_check_dev_active (obd); +if (rc) +return rc;OBD_CHECK_DT_OP (obd, reconnect,0 );OBD_COUNTER_INCREMENT (obd, reconnect);
Signature · 6 lines
2.1.0 -- Kind Regards, Aya Saif El-yazal Mahfouz
PATCH v3 3/3 staging: lustre: include: remove unused macros
In reply to Aya MahfouzOBD_CHECK_DEV and OBD_CHECK_DEV_ACTIVE have been replaced by static inline functions. They are removed since they are not used anymore.
---
v2: No changes. The patch is part of a patchset, so it was resent with them.
v3: same as v2.
drivers/staging/lustre/lustre/include/obd_class.h | 18 ------------------ 1 file changed, 18 deletions(-)
drivers/staging/lustre/lustre/include/obd_class.h +0 -18
@@ -333,14 +333,6 @@ void obdo_le_to_cpu(struct obdo *dobdo, struct obdo *sobdo);/* Ensure obd_setup: used for cleanup which must be called while obd is stopping */ -#define OBD_CHECK_DEV (obd) \ -do { \ - if (!(obd)) { \ - CERROR("NULL device\n"); \ - return -ENODEV; \ - } \ -} while (0) -static inline int obd_check_dev (struct obd_device *obd) {if (!obd) {
@@ -351,16 +343,6 @@ static inline int obd_check_dev(struct obd_device *obd) }/* ensure obd_setup and !obd_stopping */ -#define OBD_CHECK_DEV_ACTIVE (obd) \ -do { \ - OBD_CHECK_DEV(obd); \ - if (!(obd)->obd_set_up || (obd)->obd_stopping) { \ - CERROR("Device %d not setup\n", \ - (obd)->obd_minor); \ - return -ENODEV; \ - } \ -} while (0) -static inline int obd_check_dev_active (struct obd_device *obd) {int rc;
Signature · 6 lines
2.1.0 -- Kind Regards, Aya Saif El-yazal Mahfouz
Greg KH
maintainerRe: [Outreachy kernel] [PATCH v3 1/3] staging: lustre: include: replace OBD_CHECK_DEV by obd_check_dev
In reply to Aya MahfouzQuoted 94 lines · Aya Mahfouz
Static inline functions are preferred over macros. Hence, the function
obd_check_devwas introduced.obd_check_devreplaces the macroOBD_CHECK_DEV. All functions that callobd_check_devstore the return values and return them if they represent an error code.Some of the changes were carried out manually and others were done using coccinelle.
Signed-off-by Aya Mahfouz <[email protected]>---
v2: removed unneeded parenthesis around the variable obd.
v3: v2 was sent as v1. Fixed that mistake.drivers/staging/lustre/lustre/include/obd_class.h | 33 ++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-)drivers/staging/lustre/lustre/include/obd_class.h +26
-5@@ -341,6 +341,15 @@ do { \ } \ }while (0 ) +static inline int obd_check_dev(struct obd_device *obd) +{ +if (!obd) { +CERROR ("NULL device\n" ); +return -ENODEV ; + } +return 0 ; +} +/* ensure obd_setup and !obd_stopping */ #define OBD_CHECK_DEV_ACTIVE (obd) \ do { \@@ -594,7 +603,9 @@ static inline int obd_precleanup(struct obd_device *obd,int rc;DECLARE_LU_VARS (ldt, d); -OBD_CHECK_DEV (obd); + rc =obd_check_dev (obd); +if (rc) +return rc; ldt = obd->obd_type->typ_lu; d = obd->obd_lu_dev;if (ldt !=NULL && d !=NULL ) {@@ -620,7 +631,9 @@ static inline int obd_cleanup(struct obd_device *obd)int rc;DECLARE_LU_VARS (ldt, d); -OBD_CHECK_DEV (obd); + rc =obd_check_dev (obd); +if (rc) +return rc; ldt = obd->obd_type->typ_lu; d = obd->obd_lu_dev;@@ -668,7 +681,9 @@ obd_process_config(struct obd_device *obd, int datalen, void *data)int rc;DECLARE_LU_VARS (ldt, d); -OBD_CHECK_DEV (obd); + rc =obd_check_dev (obd); +if (rc) +return rc; obd->obd_process_conf =1 ; ldt = obd->obd_type->typ_lu;@@ -1280,7 +1295,9 @@ static inline int obd_notify(struct obd_device *obd, {int rc; -OBD_CHECK_DEV (obd); + rc =obd_check_dev (obd); +if (rc) +return rc;/* the check for async_recov is a complete hack - I'm hereby overloading the meaning to also mean "this was called from @@ -1381,7 +1398,11 @@ static inline int obd_health_check(const struct lu_env *env,static inline int obd_register_observer (struct obd_device *obd,struct obd_device *observer) { -OBD_CHECK_DEV (obd); +int rc; + + rc =obd_check_dev (obd); +if (rc) +return rc;down_write (&obd->obd_observer_link_sem);if (obd->obd_observer && observer) {up_write (&obd->obd_observer_link_sem);
drivers/staging/lustre/lustre/include/obd_class.h static inline int obd_register_observer(struct obd_device *obd, · line 1413
Quoted 5 lines
drivers/staging/lustre/lustre/include/obd_class.h +1
-1@@ -1389,7 +1410,7 @@ static inline int obd_register_observer(struct obd_device *obd, } obd->obd_observer = observer;up_write (&obd->obd_observer_link_sem); -return 0 ; +return rc;
Again, as I stated before, this change is not needed.
sorry,
greg k-h
Re: [Outreachy kernel] [PATCH v3 1/3] staging: lustre: include: replace OBD_CHECK_DEV by obd_check_dev
Quoted 103 lines · Greg KH
Quoted 94 lines · Aya Mahfouz
Static inline functions are preferred over macros. Hence, the function
obd_check_devwas introduced.obd_check_devreplaces the macroOBD_CHECK_DEV. All functions that callobd_check_devstore the return values and return them if they represent an error code.Some of the changes were carried out manually and others were done using coccinelle.
Signed-off-by Aya Mahfouz <[email protected]>---
v2: removed unneeded parenthesis around the variable obd.
v3: v2 was sent as v1. Fixed that mistake.drivers/staging/lustre/lustre/include/obd_class.h | 33 ++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-)drivers/staging/lustre/lustre/include/obd_class.h +26
-5@@ -341,6 +341,15 @@ do { \ } \ }while (0 ) +static inline int obd_check_dev(struct obd_device *obd) +{ +if (!obd) { +CERROR ("NULL device\n" ); +return -ENODEV ; + } +return 0 ; +} +/* ensure obd_setup and !obd_stopping */ #define OBD_CHECK_DEV_ACTIVE (obd) \ do { \@@ -594,7 +603,9 @@ static inline int obd_precleanup(struct obd_device *obd,int rc;DECLARE_LU_VARS (ldt, d); -OBD_CHECK_DEV (obd); + rc =obd_check_dev (obd); +if (rc) +return rc; ldt = obd->obd_type->typ_lu; d = obd->obd_lu_dev;if (ldt !=NULL && d !=NULL ) {@@ -620,7 +631,9 @@ static inline int obd_cleanup(struct obd_device *obd)int rc;DECLARE_LU_VARS (ldt, d); -OBD_CHECK_DEV (obd); + rc =obd_check_dev (obd); +if (rc) +return rc; ldt = obd->obd_type->typ_lu; d = obd->obd_lu_dev;@@ -668,7 +681,9 @@ obd_process_config(struct obd_device *obd, int datalen, void *data)int rc;DECLARE_LU_VARS (ldt, d); -OBD_CHECK_DEV (obd); + rc =obd_check_dev (obd); +if (rc) +return rc; obd->obd_process_conf =1 ; ldt = obd->obd_type->typ_lu;@@ -1280,7 +1295,9 @@ static inline int obd_notify(struct obd_device *obd, {int rc; -OBD_CHECK_DEV (obd); + rc =obd_check_dev (obd); +if (rc) +return rc;/* the check for async_recov is a complete hack - I'm hereby overloading the meaning to also mean "this was called from @@ -1381,7 +1398,11 @@ static inline int obd_health_check(const struct lu_env *env,static inline int obd_register_observer (struct obd_device *obd,struct obd_device *observer) { -OBD_CHECK_DEV (obd); +int rc; + + rc =obd_check_dev (obd); +if (rc) +return rc;down_write (&obd->obd_observer_link_sem);if (obd->obd_observer && observer) {up_write (&obd->obd_observer_link_sem);drivers/staging/lustre/lustre/include/obd_class.h static inline int obd_register_observer(struct obd_device *obd, · line 1413
Quoted 5 lines
drivers/staging/lustre/lustre/include/obd_class.h +1
-1@@ -1389,7 +1410,7 @@ static inline int obd_register_observer(struct obd_device *obd, } obd->obd_observer = observer;up_write (&obd->obd_observer_link_sem); -return 0 ; +return rc;Again, as I stated before, this change is not needed.
Quoted 2 lines
sorry,
No, problem. Done in the fourth version.
Quoted 1 line
greg k-h
Signature · 2 lines
Kind Regards, Aya Saif El-yazal Mahfouz