Staging: lustre: Convert macro class_export_rpc_inc into static inline function
PATCH 1/2 Staging: lustre: Convert macro class_export_rpc_inc into static inline function
Static inline function are generally preferred over macros because static inline functions have types and return values. But in order to change a macro into static inline function we have to check the calling sites of the macro and ensuring that the types of arguments in each case is same and also ensure that macro always returns same type.
This patch converts the macro class_export_rpc_inc into static inline function. To do so, we have used the following coccinelle script to ensure the above mentioned requirements for this change.
Since this macro does not return anything, so coccinelle script can be simplified to avoid return type checks.
@initialize:python@
@@
list = []
@rule1@
type T;
T e;
expression list[n] es;
@@class_export_rpc_inc(es,e,...);
@script:python rule2@
e << rule1.e;
T << rule1.T;
@@list.append(T)
@finalize:python@
@@
possible = True
for t in list:
if t != list[0]: possible = False
if possible:
print 'This patch is possible. Argument type:', list[0]
else:
print 'This patch is not possible'
--- drivers/staging/lustre/lustre/include/obd_class.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/include/obd_class.h +6 -6
@@ -222,12 +222,12 @@ extern void (*class_export_dump_hook)(struct obd_export *);#endif -#define class_export_rpc_inc (exp) \ -({ \ - atomic_inc(&(exp)->exp_rpc_count); \ - CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \ - (exp), atomic_read(&(exp)->exp_rpc_count)); \ -}) +static inline void class_export_rpc_inc (struct obd_export *exp) +{ +atomic_inc (&(exp)->exp_rpc_count); +CDEBUG (D_INFO ,"RPC GETting export %p : new rpc_count %d\n" , + (exp),atomic_read (&(exp)->exp_rpc_count)); +}#define class_export_rpc_dec (exp) \ ({ \
Signature · 1 line
1.9.1
PATCH 2/2 Staging: lustre: Convert macro class_export_rpc_dec into static inline function
Static inline function are generally preferred over macros because static inline functions have types and return values. But in order to change a macro into static inline function we have to check the calling sites of the macro and ensuring that the types of arguments in each case is same and also ensure that macro always returns same type.
This patch converts the macro class_export_rpc_dec into static inline function. To do so, we have used the following coccinelle script to ensure the above mentioned requirements for this change.
Since this macro does not return anything, so coccinelle script can be simplified to avoid return type checks.
@initialize:python@
@@
list = []
@rule1@
type T;
T e;
expression list[n] es;
@@class_export_rpc_dec(es,e,...);
@script:python rule2@
e << rule1.e;
T << rule1.T;
@@list.append(T)
@finalize:python@
@@
possible = True
for t in list:
if t != list[0]:
possible = False
if possible:
print 'This patch is possible. Argument type:', list[0]
else:
print 'This patch is not possible'
--- drivers/staging/lustre/lustre/include/obd_class.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/staging/lustre/lustre/include/obd_class.h +7 -7
@@ -229,13 +229,13 @@ static inline void class_export_rpc_inc(struct obd_export *exp) (exp), atomic_read(&(exp)->exp_rpc_count)); } -#define class_export_rpc_dec (exp) \ -({ \ - LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \ - atomic_dec(&(exp)->exp_rpc_count); \ - CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \ - (exp), atomic_read(&(exp)->exp_rpc_count)); \ -}) +static inline void class_export_rpc_dec (struct obd_export *exp) +{ +LASSERT_ATOMIC_POS (&exp->exp_rpc_count); +atomic_dec (&(exp)->exp_rpc_count); +CDEBUG (D_INFO ,"RPC PUTting export %p : new rpc_count %d\n" , + (exp),atomic_read (&(exp)->exp_rpc_count)); +}#define class_export_lock_get (exp, lock) \ ({ \
Signature · 1 line
1.9.1
Re: [Outreachy kernel] [PATCH 2/2] Staging: lustre: Convert macro class_export_rpc_dec into static inline function
Quoted 6 lines · Somya Anand
Static inline function are generally preferred over macros because static inline functions have types and return values. But in order to change a macro into static inline function we have to check the calling sites of the macro and ensuring that the types of arguments in each case is same and also ensure that macro always returns same type.
This is a nice effort to explain things, but I think that it is too much for a commit message. Just explain concisely what was done and why. Ie, you have changed the macro to a function, and you have checked that the type you have chosen for the parameter is compatible with the types of the arguments at all of the call sites. The kind of explanation you have here could be better for a cover letter.
julia
Quoted 76 lines
This patch converts the macro
class_export_rpc_decinto static inline function. To do so, we have used the following coccinelle script to ensure the above mentioned requirements for this change.Since this macro does not return anything, so coccinelle script can be simplified to avoid return type checks.
@initialize:python@
@@
list = []@rule1@
type T;
T e;
expression list[n] es;
@@class_export_rpc_dec(es,e,...);@script:python rule2@
e << rule1.e;
T << rule1.T;
@@list.append(T)@finalize:python@
@@
possible = True
for t in list:
if t != list[0]:
possible = Falseif possible:
print 'This patch is possible. Argument type:', list[0]
else:
print 'This patch is not possible'Signed-off-by Somya Anand <[email protected]>--- drivers/staging/lustre/lustre/include/obd_class.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)drivers/staging/lustre/lustre/include/obd_class.h +7
-8@@ -229,13 +229,13 @@ static inline void class_export_rpc_inc(struct obd_export *exp) (exp), atomic_read(&(exp)->exp_rpc_count)); } -#define class_export_rpc_dec (exp) \ -({ \ - LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \ - atomic_dec(&(exp)->exp_rpc_count); \ - CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \ - (exp), atomic_read(&(exp)->exp_rpc_count)); \ -}) +static inline void class_export_rpc_dec (struct obd_export *exp) +{ +LASSERT_ATOMIC_POS (&exp->exp_rpc_count); +atomic_dec (&(exp)->exp_rpc_count); +CDEBUG (D_INFO ,"RPC PUTting export %p : new rpc_count %d\n" , + (exp),atomic_read (&(exp)->exp_rpc_count)); +}#define class_export_lock_get (exp, lock) \ ({ \ --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/1426856679-1443-2-git-send-email-somyaanand214%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Re: [Outreachy kernel] [PATCH 2/2] Staging: lustre: Convert macro class_export_rpc_dec into static inline function
Quoted 9 lines · Julia Lawall
Quoted 6 lines · Somya Anand
Static inline function are generally preferred over macros because static inline functions have types and return values. But in order to change a macro into static inline function we have to check the calling sites of the macro and ensuring that the types of arguments in each case is same and also ensure that macro always returns same type.
Quoted 7 lines
This is a nice effort to explain things, but I think that it is too much for a commit message. Just explain concisely what was done and why. Ie, you have changed the macro to a function, and you have checked that the type you have chosen for the parameter is compatible with the types of the arguments at all of the call sites. The kind of explanation you have here could be better for a cover letter.
Thank you for pointing it out. I will do the necessary changes to make it concise and add further description in a cover letter.
Thanks
--
somya
Quoted 86 lines
julia
Quoted 36 lines
This patch converts the macro
class_export_rpc_decinto static inline function. To do so, we have used the following coccinelle script to ensure the above mentioned requirements for this change.Since this macro does not return anything, so coccinelle script can be simplified to avoid return type checks.
@initialize:python@
@@
list = []@rule1@
type T;
T e;
expression list[n] es;
@@class_export_rpc_dec(es,e,...);@script:python rule2@
e << rule1.e;
T << rule1.T;
@@list.append(T)@finalize:python@
@@
possible = True
for t in list:
if t != list[0]:
possible = Falseif possible:
print 'This patch is possible. Argument type:', list[0]
else:
print 'This patch is not possible'Review
Quoted 6 lines
Signed-off-by Somya Anand <[email protected]>--- drivers/staging/lustre/lustre/include/obd_class.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)(quoted diff) +0
-0
b/drivers/staging/lustre/lustre/include/obd_class.hdrivers/staging/lustre/lustre/include/obd_class.h static inline void class_export_rpc_inc(struct
Quoted 4 lines
index 9f528d4..3565660 100644
drivers/staging/lustre/lustre/include/obd_class.h +0
-0@@ -229,13 +229,13 @@ static inline void class_export_rpc_inc(struct
obd_export*exp)Quoted 23 lines
drivers/staging/lustre/lustre/include/obd_class.h +7
-8(exp), atomic_read(&(exp)->exp_rpc_count)); } -#define class_export_rpc_dec (exp) \ -({ \ - LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \ - atomic_dec(&(exp)->exp_rpc_count); \ - CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \ - (exp), atomic_read(&(exp)->exp_rpc_count)); \ -}) +static inline void class_export_rpc_dec (struct obd_export *exp) +{ +LASSERT_ATOMIC_POS (&exp->exp_rpc_count); +atomic_dec (&(exp)->exp_rpc_count); +CDEBUG (D_INFO ,"RPC PUTting export %p : new rpc_count %d\n" , + (exp),atomic_read (&(exp)->exp_rpc_count)); +}#define class_export_lock_get (exp, lock) \ ({ \ --1.9.1
Quoted 2 lines
--
You received this message because you are subscribed to the GoogleGroups "outreachy-kernel" group.
Quoted 1 line
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
Quoted 2 lines
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/1426856679-1443-2-git-send- email-somyaanand214%40gmail.com.
Quoted 2 lines
For more options, visit https://groups.google.com/d/optout.