[PATCH v3 17/68] fscache: Implement simple cookie state machine

David Howells dhowells at redhat.com
Fri Dec 17 11:45:26 PST 2021


Jeff Layton <jlayton at kernel.org> wrote:

> > +	case FSCACHE_COOKIE_STATE_RELINQUISHING:
> > +	case FSCACHE_COOKIE_STATE_WITHDRAWING:
> > +		if (cookie->cache_priv) {
> > +			spin_unlock(&cookie->lock);
> > +			cookie->volume->cache->ops->withdraw_cookie(cookie);
> > +			spin_lock(&cookie->lock);
> > +		}
> > +
> > +		switch (state) {
> > +		case FSCACHE_COOKIE_STATE_RELINQUISHING:
> > +			fscache_see_cookie(cookie, fscache_cookie_see_relinquish);
> > +			fscache_unhash_cookie(cookie);
> > +			__fscache_set_cookie_state(cookie,
> > +						   FSCACHE_COOKIE_STATE_DROPPED);
> > +			wake = true;
> > +			goto out;
> > +		case FSCACHE_COOKIE_STATE_WITHDRAWING:
> > +			fscache_see_cookie(cookie, fscache_cookie_see_withdraw);
> > +			break;
> > +		default:
> > +			BUG();
> > +		}
> > +
> 
> Ugh, the nested switch here is a bit hard to follow. It makes it seem
> like the state could change due to the withdraw_cookie and you're
> checking it again, but it doesn't do that.
> 
> This would be clearer if you just duplicated the withdraw_cookie stanza
> for both states and moved the stuff below here to a helper or to a new
> goto block.

There are actually three states, but one's added in a later patch.  It
probably does make sense to split the RELINQ state from the other two.

David




More information about the linux-afs mailing list