fscrypt: add ->ci_inode to fscrypt_info
authorEric Biggers <ebiggers@google.com>
Mon, 5 Aug 2019 02:35:44 +0000 (19:35 -0700)
committerEric Biggers <ebiggers@google.com>
Tue, 13 Aug 2019 02:05:22 +0000 (19:05 -0700)
Add an inode back-pointer to 'struct fscrypt_info', such that
inode->i_crypt_info->ci_inode == inode.

This will be useful for:

1. Evicting the inodes when a fscrypt key is removed, since we'll track
   the inodes using a given key by linking their fscrypt_infos together,
   rather than the inodes directly.  This avoids bloating 'struct inode'
   with a new list_head.

2. Simplifying the per-file key setup, since the inode pointer won't
   have to be passed around everywhere just in case something goes wrong
   and it's needed for fscrypt_warn().

Reviewed-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Eric Biggers <ebiggers@google.com>
fs/crypto/fscrypt_private.h
fs/crypto/keyinfo.c

index fae411b2f78dcbe27b977aa29c8632a0d2c262fa..d345a7d28df8c2f40ec8d512d43c67648795d32e 100644 (file)
@@ -73,6 +73,9 @@ struct fscrypt_info {
         */
        struct fscrypt_mode *ci_mode;
 
+       /* Back-pointer to the inode */
+       struct inode *ci_inode;
+
        /*
         * If non-NULL, then this inode uses a master key directly rather than a
         * derived key, and ci_ctfm will equal ci_master_key->mk_ctfm.
index 22345ddede1199ffddaa461495af2558eeef1ed6..2d45a86f09db256bbba933531fa14adf771f1390 100644 (file)
@@ -556,6 +556,8 @@ int fscrypt_get_encryption_info(struct inode *inode)
        if (!crypt_info)
                return -ENOMEM;
 
+       crypt_info->ci_inode = inode;
+
        crypt_info->ci_flags = ctx.flags;
        crypt_info->ci_data_mode = ctx.contents_encryption_mode;
        crypt_info->ci_filename_mode = ctx.filenames_encryption_mode;