Whamcloud - gitweb
LU-15855 enc: enc-unaware clients get ENOKEY if file not found
[fs/lustre-release.git] / lustre / llite / crypto.c
index 18698d6..acd7f16 100644 (file)
@@ -251,21 +251,26 @@ int ll_setup_filename(struct inode *dir, const struct qstr *iname,
                fid->f_ver = 0;
        }
        rc = llcrypt_setup_filename(dir, &dname, lookup, fname);
-       if (rc == -ENOENT && lookup &&
-           ((is_root_inode(dir) && iname->len == strlen(dot_fscrypt_name) &&
-             strncmp(iname->name, dot_fscrypt_name, iname->len) == 0) ||
-            (!llcrypt_has_encryption_key(dir) &&
-             unlikely(filename_is_volatile(iname->name, iname->len, NULL))))) {
-               /* In case of subdir mount of an encrypted directory, we allow
-                * lookup of /.fscrypt directory.
-                */
-               /* For purpose of migration or mirroring without enc key, we
-                * allow lookup of volatile file without enc context.
-                */
-               memset(fname, 0, sizeof(struct llcrypt_name));
-               fname->disk_name.name = (unsigned char *)iname->name;
-               fname->disk_name.len = iname->len;
-               rc = 0;
+       if (rc == -ENOENT && lookup) {
+               if (((is_root_inode(dir) &&
+                    iname->len == strlen(dot_fscrypt_name) &&
+                    strncmp(iname->name, dot_fscrypt_name, iname->len) == 0) ||
+                    (!llcrypt_has_encryption_key(dir) &&
+                     unlikely(filename_is_volatile(iname->name,
+                                                   iname->len, NULL))))) {
+                       /* In case of subdir mount of an encrypted directory,
+                        * we allow lookup of /.fscrypt directory.
+                        */
+                       /* For purpose of migration or mirroring without enc key
+                        * we allow lookup of volatile file without enc context.
+                        */
+                       memset(fname, 0, sizeof(struct llcrypt_name));
+                       fname->disk_name.name = (unsigned char *)iname->name;
+                       fname->disk_name.len = iname->len;
+                       rc = 0;
+               } else if (!llcrypt_has_encryption_key(dir)) {
+                       rc = -ENOKEY;
+               }
        }
        if (rc)
                return rc;