• David Howells's avatar
    afs: Fix validation/callback interaction · ae3b7361
    David Howells authored
    When afs_validate() is called to validate a vnode (inode), there are two
    unhandled cases in the fastpath at the top of the function:
    
     (1) If the vnode is promised (AFS_VNODE_CB_PROMISED is set), the break
         counters match and the data has expired, then there's an implicit case
         in which the vnode needs revalidating.
    
         This has no consequences since the default "valid = false" set at the
         top of the function happens to do the right thing.
    
     (2) If the vnode is not promised and it hasn't been deleted
         (AFS_VNODE_DELETED is not set) then there's a default case we're not
         handling in which the vnode is invalid.  If the vnode is invalid, we
         need to bring cb_s_break and cb_v_break up to date before we refetch
         the status.
    
         As a consequence, once the server loses track of the client
         (ie. sufficient time has passed since we last sent it an operation),
         it will send us a CB.InitCallBackState* operation when we next try to
         talk to it.  This calls afs_init_callback_state() which increments
         afs_server::cb_s_break, but this then doesn't propagate to the
         afs_vnode record.
    
         The result being that every afs_validate() call thereafter sends a
         status fetch operation to the server.
    
    Clarify and fix this by:
    
     (A) Setting valid in all the branches rather than initialising it at the
         top so that the compiler catches where we've missed.
    
     (B) Restructuring the logic in the 'promised' branch so that we set valid
         to false if the callback is due to expire (or has expired) and so that
         the final case is that the vnode is still valid.
    
     (C) Adding an else-statement that ups cb_s_break and cb_v_break if the
         promised and deleted cases don't match.
    
    Fixes: c435ee34 ("afs: Overhaul the callback handling")
    Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
    Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
    ae3b7361
inode.c 14.9 KB