GFS2: Fix up some sparse warnings
PATCH 1/1 GFS2: Fix up some sparse warnings
In reply to a message not in the archiveHi,
This patch cleans up various pieces of GFS2 to avoid sparse errors. This doesn't fix them all, but it fixes several. The first error, in function glock_hash_walk was a genuine bug where the rhashtable could be started and not stopped.
---
fs/gfs2/glock.c +9 -8
@@ -1550,14 +1550,13 @@ static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)do { gl =ERR_PTR (rhashtable_walk_start (&iter)); -if (gl) -continue ; - -while ((gl =rhashtable_walk_next (&iter)) && !IS_ERR (gl)) -if ((gl->gl_name.ln_sbd == sdp) && -lockref_get_not_dead (&gl->gl_lockref)) -examiner (gl); - +if (!gl) { +while ((gl =rhashtable_walk_next (&iter)) && + !IS_ERR (gl)) +if ((gl->gl_name.ln_sbd == sdp) && +lockref_get_not_dead (&gl->gl_lockref)) +examiner (gl); + }rhashtable_walk_stop (&iter); }while (cond_resched (), gl ==ERR_PTR (-EAGAIN ));
@@ -1940,6 +1939,7 @@ static void gfs2_glock_iter_next(struct gfs2_glock_iter *gi) }static void *gfs2_glock_seq_start (struct seq_file *seq,loff_t *pos) +__acquires (RCU ) {struct gfs2_glock_iter *gi = seq->private;loff_t n = *pos;
@@ -1972,6 +1972,7 @@ static void *gfs2_glock_seq_next(struct seq_file *seq, void *iter_ptr, }static void gfs2_glock_seq_stop (struct seq_file *seq,void *iter_ptr) +__releases (RCU ) {struct gfs2_glock_iter *gi = seq->private;
fs/gfs2/lock_dlm.c +1 -3
@@ -23,8 +23,6 @@#include "sys.h" #include "trace_gfs2.h" -extern struct workqueue_struct *gfs2_control_wq; -/** * gfs2_update_stats - Update time based stats * @mv: Pointer to mean/variance structure to update
@@ -1176,7 +1174,7 @@ static void gdlm_recovery_result(struct gfs2_sbd *sdp, unsigned int jid,spin_unlock (&ls->ls_recover_spin); } -const struct dlm_lockspace_ops gdlm_lockspace_ops = { +static const struct dlm_lockspace_ops gdlm_lockspace_ops = { .recover_prep = gdlm_recover_prep, .recover_slot = gdlm_recover_slot, .recover_done = gdlm_recover_done,
fs/gfs2/main.c +0 -2
@@ -32,8 +32,6 @@#include "dir.h" #include "glops.h" -struct workqueue_struct *gfs2_control_wq; -static void gfs2_init_inode_once (void *foo) {struct gfs2_inode *ip = foo;
fs/gfs2/util.h +1 -0
@@ -151,6 +151,7 @@ extern struct kmem_cache *gfs2_rgrpd_cachep;extern struct kmem_cache *gfs2_quotad_cachep;extern struct kmem_cache *gfs2_qadata_cachep;extern mempool_t *gfs2_page_pool; +extern struct workqueue_struct *gfs2_control_wq;static inline unsigned int gfs2_tune_get_i (struct gfs2_tune *gt,unsigned int *p)
fs/gfs2/xattr.c +1 -0
@@ -25,6 +25,7 @@#include "meta_io.h" #include "quota.h" #include "rgrp.h" +#include "super.h" #include "trans.h" #include "util.h"
PATCH 1/1 GFS2: Fix up some sparse warnings
Quoted 14 lines · Bob Peterson
Hi,
This patch cleans up various pieces of GFS2 to avoid sparse errors. This doesn't fix them all, but it fixes several. The first error, in function
glock_hash_walkwas a genuine bug where the rhashtable could be started and not stopped.Signed-off-by Bob Peterson <[email protected]>---
fs/gfs2/glock.c +0
-0
fs/gfs2/glock.c static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp) · line 1552
Quoted 3 lines
fs/gfs2/glock.c +0
-0@@ -1550,14 +1550,13 @@ static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp) do { gl = ERR_PTR(rhashtable_walk_start(&iter));
Couldn't the rhashtable_walk_start() call be moved before the outer loop?
"* Returns -EAGAIN if resize event occured. Note that the iterator
* will rewind back to the beginning and you may use it immediately
* by calling rhashtable_walk_next."
so it looks like -EAGAIN doesn't require a stop and restart of the walk.
fs/gfs2/glock.c static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp) · line 1553
Quoted 9 lines
fs/gfs2/glock.c +1
-8-if (gl) -continue ; - -while ((gl =rhashtable_walk_next (&iter)) && !IS_ERR (gl)) -if ((gl->gl_name.ln_sbd == sdp) && -lockref_get_not_dead (&gl->gl_lockref)) -examiner (gl); - +if (!gl) {
This looks like it should be if (!IS_ERR(gl)) { ...
fs/gfs2/glock.c static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp) · line 1560
Quoted 7 lines
fs/gfs2/glock.c +6
-0+while ((gl =rhashtable_walk_next (&iter)) && + !IS_ERR (gl)) +if ((gl->gl_name.ln_sbd == sdp) && +lockref_get_not_dead (&gl->gl_lockref)) +examiner (gl); + }rhashtable_walk_stop (&iter);
See above.
Cheers,
Andy
Quoted 78 lines
fs/gfs2/glock.c +2
-0}while (cond_resched (), gl ==ERR_PTR (-EAGAIN ));@@ -1940,6 +1939,7 @@ static void gfs2_glock_iter_next(struct gfs2_glock_iter *gi) }static void *gfs2_glock_seq_start (struct seq_file *seq,loff_t *pos) +__acquires (RCU ) {struct gfs2_glock_iter *gi = seq->private;loff_t n = *pos;@@ -1972,6 +1972,7 @@ static void *gfs2_glock_seq_next(struct seq_file *seq, void *iter_ptr, }static void gfs2_glock_seq_stop (struct seq_file *seq,void *iter_ptr) +__releases (RCU ) {struct gfs2_glock_iter *gi = seq->private;fs/gfs2/lock_dlm.c +1
-3@@ -23,8 +23,6 @@#include "sys.h" #include "trace_gfs2.h" -extern struct workqueue_struct *gfs2_control_wq; -/** * gfs2_update_stats - Update time based stats * @mv: Pointer to mean/variance structure to update @@ -1176,7 +1174,7 @@ static void gdlm_recovery_result(struct gfs2_sbd *sdp, unsigned int jid,spin_unlock (&ls->ls_recover_spin); } -const struct dlm_lockspace_ops gdlm_lockspace_ops = { +static const struct dlm_lockspace_ops gdlm_lockspace_ops = { .recover_prep = gdlm_recover_prep, .recover_slot = gdlm_recover_slot, .recover_done = gdlm_recover_done,fs/gfs2/main.c +0
-2@@ -32,8 +32,6 @@#include "dir.h" #include "glops.h" -struct workqueue_struct *gfs2_control_wq; -static void gfs2_init_inode_once (void *foo) {struct gfs2_inode *ip = foo;fs/gfs2/util.h +1
-0@@ -151,6 +151,7 @@ extern struct kmem_cache *gfs2_rgrpd_cachep;extern struct kmem_cache *gfs2_quotad_cachep;extern struct kmem_cache *gfs2_qadata_cachep;extern mempool_t *gfs2_page_pool; +extern struct workqueue_struct *gfs2_control_wq;static inline unsigned int gfs2_tune_get_i (struct gfs2_tune *gt,unsigned int *p)fs/gfs2/xattr.c +1
-0@@ -25,6 +25,7 @@#include "meta_io.h" #include "quota.h" #include "rgrp.h" +#include "super.h" #include "trans.h" #include "util.h"
PATCH 1/1 GFS2: Fix up some sparse warnings
Hi Andy,
Comments inline.
----- Original Message -----
| On Fri, Aug 18, 2017 at 10:20:56AM -0400, Bob Peterson wrote: | > Hi, | > | > This patch cleans up various pieces of GFS2 to avoid sparse errors. | > This doesn't fix them all, but it fixes several. The first error, | > in function glock_hash_walk was a genuine bug where the rhashtable | > could be started and not stopped. | > | > Signed-off-by: Bob Peterson <[email protected]> | > --- | > diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c | > index ffca19598525..db78720f3c89 100644 | > --- a/fs/gfs2/glock.c | > +++ b/fs/gfs2/glock.c | > @@ -1550,14 +1550,13 @@ static void glock_hash_walk(glock_examiner | > examiner, const struct gfs2_sbd *sdp) | > | > do { | > gl = ERR_PTR(rhashtable_walk_start(&iter)); | | Couldn't the rhashtable_walk_start() call be moved before the outer loop? | | "* Returns -EAGAIN if resize event occured. Note that the iterator | * will rewind back to the beginning and you may use it immediately | * by calling rhashtable_walk_next." | | so it looks like -EAGAIN doesn't require a stop and restart of the walk.
Yes, I'm pretty sure you're right. I could (and should) re-factor this and straighten it out. However, my goal with this set of patches was to not change the logic at all, and in today's code, it's inside the loop.
| > - if (gl)
| > - continue;
| > -
| > - while ((gl = rhashtable_walk_next(&iter)) && !IS_ERR(gl))
| > - if ((gl->gl_name.ln_sbd == sdp) &&
| > - lockref_get_not_dead(&gl->gl_lockref))
| > - examiner(gl);
| > -
| > + if (!gl) {
|
| This looks like it should be if (!IS_ERR(gl)) { ...Here again, the original was "if (gl)" and I didn't want to change it, so it becomes "if (gl) {". Again, I think I need to change it, but perhaps in another patch that targets this function, especially since it can't return anything other than 0 or -EAGAIN.
| > + while ((gl = rhashtable_walk_next(&iter)) && | > + !IS_ERR(gl)) | > + if ((gl->gl_name.ln_sbd == sdp) && | > + lockref_get_not_dead(&gl->gl_lockref)) | > + examiner(gl); | > + } | > rhashtable_walk_stop(&iter);
So I propose I push this patch "as is" and write another patch to re-work function glock_hash_walk so it cleans up the issues you pointed out and makes more logical sense.
Regards,
Bob Peterson
Red Hat File Systems
PATCH v2 1/1 GFS2: Fix up some sparse warnings
In reply to Bob PetersonHi,
I've been doing some investigation with regard to Andy Price's questions about the glock / rhashtable portion of this patch.
It turns out that the rhashtable code in function glock_hash_walk was patterned after the code in function tipc_sk_reinit() in net/tips/socket.c. The loop in Andy's question was added recently by Herbert Xu in commit 40f9f439706073b4b0a654b3b99e18296b7990b3 and comments in that patch explain why the loop was added. This differs, however, from net/netlink/diag.c which does not have the loop.
As far as I can tell, the difference between having and not having the loop comes down to what happens when an rhashtable resize event occurs: Would you rather have it (a) process some unpredictable number of glocks twice, or (b) skip some altogether?
Since the callers of function glock_hash_walk are gfs2_glock_thaw and gfs2_gl_hash_clear, it makes more sense to me to process them twice than not at all.
In doing this investigation, I found a bug in the original tipc code, and submitted a patch for it this morning. That bug was one I has proposed fixing with version 1 of this patch.
I've therefore revised this patch to (a) use IS_ERR(gl) rather than just (gl) as Andy suggested. (b) Added a goto instead of using braces, so that it more closely matches the patched tipc code, and (c) got rid of some parenthesis to appease Andreas.
Bob Peterson
Patch description:
------------------
This patch cleans up various pieces of GFS2 to avoid sparse errors. This doesn't fix them all, but it fixes several. The first error, in function glock_hash_walk was a genuine bug where the rhashtable could be started and not stopped.
---
fs/gfs2/glock.c +6 -3
@@ -1550,14 +1550,15 @@ static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)do { gl =ERR_PTR (rhashtable_walk_start (&iter)); -if (gl) -continue ; +if (IS_ERR (gl)) + goto walk_stop;while ((gl =rhashtable_walk_next (&iter)) && !IS_ERR (gl)) -if ((gl->gl_name.ln_sbd == sdp) && +if (gl->gl_name.ln_sbd == sdp &&lockref_get_not_dead (&gl->gl_lockref))examiner (gl); +walk_stop:rhashtable_walk_stop (&iter); }while (cond_resched (), gl ==ERR_PTR (-EAGAIN ));
@@ -1940,6 +1941,7 @@ static void gfs2_glock_iter_next(struct gfs2_glock_iter *gi) }static void *gfs2_glock_seq_start (struct seq_file *seq,loff_t *pos) +__acquires (RCU ) {struct gfs2_glock_iter *gi = seq->private;loff_t n = *pos;
@@ -1972,6 +1974,7 @@ static void *gfs2_glock_seq_next(struct seq_file *seq, void *iter_ptr, }static void gfs2_glock_seq_stop (struct seq_file *seq,void *iter_ptr) +__releases (RCU ) {struct gfs2_glock_iter *gi = seq->private;
fs/gfs2/lock_dlm.c +1 -3
@@ -23,8 +23,6 @@#include "sys.h" #include "trace_gfs2.h" -extern struct workqueue_struct *gfs2_control_wq; -/** * gfs2_update_stats - Update time based stats * @mv: Pointer to mean/variance structure to update
@@ -1176,7 +1174,7 @@ static void gdlm_recovery_result(struct gfs2_sbd *sdp, unsigned int jid,spin_unlock (&ls->ls_recover_spin); } -const struct dlm_lockspace_ops gdlm_lockspace_ops = { +static const struct dlm_lockspace_ops gdlm_lockspace_ops = { .recover_prep = gdlm_recover_prep, .recover_slot = gdlm_recover_slot, .recover_done = gdlm_recover_done,
fs/gfs2/main.c +0 -2
@@ -32,8 +32,6 @@#include "dir.h" #include "glops.h" -struct workqueue_struct *gfs2_control_wq; -static void gfs2_init_inode_once (void *foo) {struct gfs2_inode *ip = foo;
fs/gfs2/util.h +1 -0
@@ -151,6 +151,7 @@ extern struct kmem_cache *gfs2_rgrpd_cachep;extern struct kmem_cache *gfs2_quotad_cachep;extern struct kmem_cache *gfs2_qadata_cachep;extern mempool_t *gfs2_page_pool; +extern struct workqueue_struct *gfs2_control_wq;static inline unsigned int gfs2_tune_get_i (struct gfs2_tune *gt,unsigned int *p)
fs/gfs2/xattr.c +1 -0
@@ -25,6 +25,7 @@#include "meta_io.h" #include "quota.h" #include "rgrp.h" +#include "super.h" #include "trans.h" #include "util.h"
PATCH v2 1/1 GFS2: Fix up some sparse warnings
Quoted 18 lines · Bob Peterson
Hi,
I've been doing some investigation with regard to Andy Price's questions about the glock / rhashtable portion of this patch.
It turns out that the rhashtable code in function
glock_hash_walkwas patterned after the code in functiontipc_sk_reinit()innet/tips/socket.c. The loop in Andy's question was added recently by Herbert Xu in commit40f9f439706073b4b0a654b3b99e18296b7990b3and comments in that patch explain why the loop was added. This differs, however, fromnet/netlink/diag.cwhich does not have the loop.As far as I can tell, the difference between having and not having the loop comes down to what happens when an rhashtable resize event occurs: Would you rather have it (a) process some unpredictable number of glocks twice, or (b) skip some altogether?
Quoted 6 lines
Since the callers of function
glock_hash_walkaregfs2_glock_thawandgfs2_gl_hash_clear, it makes more sense to me to process them twice than not at all.In doing this investigation, I found a bug in the original tipc code, and submitted a patch for it this morning.
Nice!
Quoted 7 lines
That bug was
one I has proposed fixing with version 1 of this patch.I've therefore revised this patch to (a) use
IS_ERR(gl)rather than just (gl) as Andy suggested. (b) Added a goto instead of using braces, so that it more closely matches the patched tipc code, and (c) got rid of some parenthesis to appease Andreas.
Looks good to me.
Cheers,
Andy
Quoted 109 lines
Bob Peterson
Patch description:
------------------
This patch cleans up various pieces of GFS2 to avoid sparse errors. This doesn't fix them all, but it fixes several. The first error, in functionglock_hash_walkwas a genuine bug where the rhashtable could be started and not stopped.Signed-off-by Bob Peterson <[email protected]>---
fs/gfs2/glock.c +6
-3@@ -1550,14 +1550,15 @@ static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)do { gl =ERR_PTR (rhashtable_walk_start (&iter)); -if (gl) -continue ; +if (IS_ERR (gl)) + goto walk_stop;while ((gl =rhashtable_walk_next (&iter)) && !IS_ERR (gl)) -if ((gl->gl_name.ln_sbd == sdp) && +if (gl->gl_name.ln_sbd == sdp &&lockref_get_not_dead (&gl->gl_lockref))examiner (gl); +walk_stop:rhashtable_walk_stop (&iter); }while (cond_resched (), gl ==ERR_PTR (-EAGAIN ));@@ -1940,6 +1941,7 @@ static void gfs2_glock_iter_next(struct gfs2_glock_iter *gi) }static void *gfs2_glock_seq_start (struct seq_file *seq,loff_t *pos) +__acquires (RCU ) {struct gfs2_glock_iter *gi = seq->private;loff_t n = *pos;@@ -1972,6 +1974,7 @@ static void *gfs2_glock_seq_next(struct seq_file *seq, void *iter_ptr, }static void gfs2_glock_seq_stop (struct seq_file *seq,void *iter_ptr) +__releases (RCU ) {struct gfs2_glock_iter *gi = seq->private;fs/gfs2/lock_dlm.c +1
-3@@ -23,8 +23,6 @@#include "sys.h" #include "trace_gfs2.h" -extern struct workqueue_struct *gfs2_control_wq; -/** * gfs2_update_stats - Update time based stats * @mv: Pointer to mean/variance structure to update @@ -1176,7 +1174,7 @@ static void gdlm_recovery_result(struct gfs2_sbd *sdp, unsigned int jid,spin_unlock (&ls->ls_recover_spin); } -const struct dlm_lockspace_ops gdlm_lockspace_ops = { +static const struct dlm_lockspace_ops gdlm_lockspace_ops = { .recover_prep = gdlm_recover_prep, .recover_slot = gdlm_recover_slot, .recover_done = gdlm_recover_done,fs/gfs2/main.c +0
-2@@ -32,8 +32,6 @@#include "dir.h" #include "glops.h" -struct workqueue_struct *gfs2_control_wq; -static void gfs2_init_inode_once (void *foo) {struct gfs2_inode *ip = foo;fs/gfs2/util.h +1
-0@@ -151,6 +151,7 @@ extern struct kmem_cache *gfs2_rgrpd_cachep;extern struct kmem_cache *gfs2_quotad_cachep;extern struct kmem_cache *gfs2_qadata_cachep;extern mempool_t *gfs2_page_pool; +extern struct workqueue_struct *gfs2_control_wq;static inline unsigned int gfs2_tune_get_i (struct gfs2_tune *gt,unsigned int *p)fs/gfs2/xattr.c +1
-0@@ -25,6 +25,7 @@#include "meta_io.h" #include "quota.h" #include "rgrp.h" +#include "super.h" #include "trans.h" #include "util.h"