Skip to content

Commit 3ffa9d6

Browse files
Jakob-Koschelidryomov
authored andcommitted
ceph: replace usage of found with dedicated list iterator variable
To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body. To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable instead of a found boolean. This removes the need to use a found variable and simply checking if the variable was set, can determine if the break/goto was hit. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ Signed-off-by: Jakob Koschel <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 57a5df0 commit 3ffa9d6

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

fs/ceph/caps.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,10 +3183,9 @@ void ceph_put_wrbuffer_cap_refs(struct ceph_inode_info *ci, int nr,
31833183
struct ceph_snap_context *snapc)
31843184
{
31853185
struct inode *inode = &ci->vfs_inode;
3186-
struct ceph_cap_snap *capsnap = NULL;
3186+
struct ceph_cap_snap *capsnap = NULL, *iter;
31873187
int put = 0;
31883188
bool last = false;
3189-
bool found = false;
31903189
bool flush_snaps = false;
31913190
bool complete_capsnap = false;
31923191

@@ -3213,14 +3212,14 @@ void ceph_put_wrbuffer_cap_refs(struct ceph_inode_info *ci, int nr,
32133212
ci->i_wrbuffer_ref, ci->i_wrbuffer_ref_head,
32143213
last ? " LAST" : "");
32153214
} else {
3216-
list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) {
3217-
if (capsnap->context == snapc) {
3218-
found = true;
3215+
list_for_each_entry(iter, &ci->i_cap_snaps, ci_item) {
3216+
if (iter->context == snapc) {
3217+
capsnap = iter;
32193218
break;
32203219
}
32213220
}
32223221

3223-
if (!found) {
3222+
if (!capsnap) {
32243223
/*
32253224
* The capsnap should already be removed when removing
32263225
* auth cap in the case of a forced unmount.
@@ -3770,35 +3769,34 @@ static void handle_cap_flushsnap_ack(struct inode *inode, u64 flush_tid,
37703769
struct ceph_inode_info *ci = ceph_inode(inode);
37713770
struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc;
37723771
u64 follows = le64_to_cpu(m->snap_follows);
3773-
struct ceph_cap_snap *capsnap;
3774-
bool flushed = false;
3772+
struct ceph_cap_snap *capsnap = NULL, *iter;
37753773
bool wake_ci = false;
37763774
bool wake_mdsc = false;
37773775

37783776
dout("handle_cap_flushsnap_ack inode %p ci %p mds%d follows %lld\n",
37793777
inode, ci, session->s_mds, follows);
37803778

37813779
spin_lock(&ci->i_ceph_lock);
3782-
list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) {
3783-
if (capsnap->follows == follows) {
3784-
if (capsnap->cap_flush.tid != flush_tid) {
3780+
list_for_each_entry(iter, &ci->i_cap_snaps, ci_item) {
3781+
if (iter->follows == follows) {
3782+
if (iter->cap_flush.tid != flush_tid) {
37853783
dout(" cap_snap %p follows %lld tid %lld !="
3786-
" %lld\n", capsnap, follows,
3787-
flush_tid, capsnap->cap_flush.tid);
3784+
" %lld\n", iter, follows,
3785+
flush_tid, iter->cap_flush.tid);
37883786
break;
37893787
}
3790-
flushed = true;
3788+
capsnap = iter;
37913789
break;
37923790
} else {
37933791
dout(" skipping cap_snap %p follows %lld\n",
3794-
capsnap, capsnap->follows);
3792+
iter, iter->follows);
37953793
}
37963794
}
3797-
if (flushed)
3795+
if (capsnap)
37983796
ceph_remove_capsnap(inode, capsnap, &wake_ci, &wake_mdsc);
37993797
spin_unlock(&ci->i_ceph_lock);
38003798

3801-
if (flushed) {
3799+
if (capsnap) {
38023800
ceph_put_snap_context(capsnap->context);
38033801
ceph_put_cap_snap(capsnap);
38043802
if (wake_ci)

0 commit comments

Comments
 (0)