• Neil Brown's avatar
    sunrpc/cache: make cache flushing more reliable. · 77862036
    Neil Brown authored
    The caches used to store sunrpc authentication information can be
    flushed by writing a timestamp to a file in /proc.
    
    This timestamp has a one-second resolution and any entry in cache that
    was last_refreshed *before* that time is treated as expired.
    
    This is problematic as it is not possible to reliably flush the cache
    without interrupting NFS service.
    If the current time is written to the "flush" file, any entry that was
    added since the current second started will still be treated as valid.
    If one second beyond than the current time is written to the file
    then no entries can be valid until the second ticks over.  This will
    mean that no NFS request will be handled for up to 1 second.
    
    To resolve this issue we make two changes:
    
    1/ treat an entry as expired if the timestamp when it was last_refreshed
      is before *or the same as* the expiry time.  This means that current
      code which writes out the current time will now flush the cache
      reliably.
    
    2/ when a new entry in added to the cache -  set the last_refresh timestamp
      to 1 second *beyond* the current flush time, when that not in the
      past.
      This ensures that newly added entries will always be valid.
    
    Now that we have a very reliable way to flush the cache, and also
    since we are using "since-boot" timestamps which are monotonic,
    change cache_purge() to set the smallest future flush_time which
    will work, and leave it there: don't revert to '1'.
    
    Also disable the setting of the 'flush_time' far into the future.
    That has never been useful and is now awkward as it would cause
    last_refresh times to be strange.
    Finally: if a request is made to set the 'flush_time' to the current
    second, assume the intent is to flush the cache and advance it, if
    necessary, to 1 second beyond the current 'flush_time' so that all
    active entries will be deemed to be expired.
    
    As part of this we need to add a 'cache_detail' arg to cache_init()
    and cache_fresh_locked() so they can find the current ->flush_time.
    Signed-off-by: default avatarNeilBrown <neilb@suse.com>
    Reported-by: default avatarOlaf Kirch <okir@suse.com>
    Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
    77862036
cache.c 44.3 KB