• Eric Biggers's avatar
    fs/inode.c: make inode_init_always() initialize i_ino to 0 · edbb35cc
    Eric Biggers authored
    Currently inode_init_always() doesn't initialize i_ino to 0.  This is
    unexpected because unlike the other inode fields that aren't initialized
    by inode_init_always(), i_ino isn't guaranteed to end up back at its
    initial value after the inode is freed.  Only one filesystem (XFS)
    actually sets set i_ino back to 0 when freeing its inodes.
    
    So, callers of new_inode() see some random previous i_ino.  Normally
    that's fine, since normally i_ino isn't accessed before being set.
    There can be edge cases where that isn't necessarily true, though.
    
    The one I've run into is that on ext4, when creating an encrypted file,
    the new file's encryption key has to be set up prior to the jbd2
    transaction, and thus prior to i_ino being set.  If something goes
    wrong, fs/crypto/ may log warning or error messages, which normally
    include i_ino.  So it needs to know whether it is valid to include i_ino
    yet or not.  Also, on some files i_ino needs to be hashed for use in the
    crypto, so fs/crypto/ needs to know whether that can be done yet or not.
    
    There are ways this could be worked around, either in fs/crypto/ or in
    fs/ext4/.  But, it seems there's no reason not to just fix
    inode_init_always() to do the expected thing and initialize i_ino to 0.
    
    So, do that, and also remove the initialization in jfs_fill_super() that
    becomes redundant.
    Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
    Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
    edbb35cc
super.c 23.6 KB