• Boris Burkov's avatar
    btrfs: keep sb cache_generation consistent with space_cache · 94846229
    Boris Burkov authored
    When mounting, btrfs uses the cache_generation in the super block to
    determine if space cache v1 is in use. However, by mounting with
    nospace_cache or space_cache=v2, it is possible to disable space cache
    v1, which does not result in un-setting cache_generation back to 0.
    
    In order to base some logic, like mount option printing in /proc/mounts,
    on the current state of the space cache rather than just the values of
    the mount option, keep the value of cache_generation consistent with the
    status of space cache v1.
    
    We ensure that cache_generation > 0 iff the file system is using
    space_cache v1. This requires committing a transaction on any mount
    which changes whether we are using v1. (v1->nospace_cache, v1->v2,
    nospace_cache->v1, v2->v1).
    
    Since the mechanism for writing out the cache generation is transaction
    commit, but we want some finer grained control over when we un-set it,
    we can't just rely on the SPACE_CACHE mount option, and introduce an
    fs_info flag that mount can use when it wants to unset the generation.
    Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
    Signed-off-by: default avatarBoris Burkov <boris@bur.io>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    94846229
transaction.c 69.3 KB