Whamcloud - gitweb
LU-12275 sec: remove bio functions in fscrypt compat 23/50023/4
authorAndreas Dilger <adilger@whamcloud.com>
Thu, 16 Feb 2023 16:21:50 +0000 (09:21 -0700)
committerOleg Drokin <green@whamcloud.com>
Wed, 1 Mar 2023 06:18:03 +0000 (06:18 +0000)
Remove libcfs/llibcfs/crypto/bio.c since direct block device access
is not needed for client builds, and the use of stuct bio on the
client adds unnecessary complexity to portability.

Test-Parameters: trivial
Fixes: a813e8187 ("LU-12275 sec: add llcrypt as file encryption library")
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: I97642dfd85053b9ea4196374f2002ffb6a2540e5
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50023
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
contrib/scripts/crypto_patches/0006_bvec_iter_all.patch
libcfs/include/libcfs/crypto/llcrypt.h
libcfs/libcfs/Makefile.in
libcfs/libcfs/crypto/Makefile.am
libcfs/libcfs/crypto/bio.c [deleted file]

index a6968c2..fd8ebe1 100644 (file)
@@ -1,17 +1,54 @@
-Linux 5.1 (commit 6dc4f100c175dd0511ae8674786e7c9006cdfbfa) introduces
-bvec_iter_all.
-
---- a/libcfs/libcfs/crypto/bio.c
-+++ b/libcfs/libcfs/crypto/bio.c
-@@ -29,7 +29,11 @@
- static void __llcrypt_decrypt_bio(struct bio *bio, bool done)
+LU-12275 sec: disable bio functions on client
+    
+diff --git a/libcfs/include/libcfs/crypto/llcrypt.h b/libcfs/include/libcfs/crypto/llcrypt.h
+index b152915fb1..93e1766edc 100644
+--- a/libcfs/include/libcfs/crypto/llcrypt.h
++++ b/libcfs/include/libcfs/crypto/llcrypt.h
+@@ -267,12 +267,14 @@ static inline bool llcrypt_match_name(const struct llcrypt_name *fname,
+       return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len);
+ }
++#ifdef HAVE_SERVER_SUPPORT
+ /* bio.c */
+ extern void llcrypt_decrypt_bio(struct bio *);
+ extern void llcrypt_enqueue_decrypt_bio(struct llcrypt_ctx *ctx,
+                                       struct bio *bio);
+ extern int llcrypt_zeroout_range(const struct inode *, pgoff_t, sector_t,
+                                unsigned int);
++#endif
+ /* hooks.c */
+ extern int llcrypt_file_open(struct inode *inode, struct file *filp);
+@@ -525,6 +527,7 @@ static inline bool llcrypt_match_name(const struct llcrypt_name *fname,
+       return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len);
+ }
++#ifdef HAVE_SERVER_SUPPORT
+ /* bio.c */
+ static inline void llcrypt_decrypt_bio(struct bio *bio)
  {
-       struct bio_vec *bv;
-+#ifdef HAVE_BVEC_ITER_ALL
-       struct bvec_iter_all iter_all;
-+#else
-+      int iter_all;
+@@ -540,6 +543,7 @@ static inline int llcrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
+ {
+       return -EOPNOTSUPP;
+ }
 +#endif
  
-       bio_for_each_segment_all(bv, bio, iter_all) {
-               struct page *page = bv->bv_page;
+ /* hooks.c */
+diff --git a/libcfs/libcfs/crypto/bio.c b/libcfs/libcfs/crypto/bio.c
+index 78b56cbd36..02ecacff5e 100644
+--- a/libcfs/libcfs/crypto/bio.c
++++ b/libcfs/libcfs/crypto/bio.c
+@@ -24,6 +24,7 @@
+  * tags/v5.4
+  */
++#ifdef HAVE_SERVER_SUPPORT
+ #include <linux/pagemap.h>
+ #include <linux/module.h>
+ #include <linux/bio.h>
+@@ -126,3 +127,4 @@ errout:
+       return err;
+ }
+ EXPORT_SYMBOL(llcrypt_zeroout_range);
++#endif
index b152915..d05ff2a 100644 (file)
@@ -267,13 +267,6 @@ static inline bool llcrypt_match_name(const struct llcrypt_name *fname,
        return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len);
 }
 
-/* bio.c */
-extern void llcrypt_decrypt_bio(struct bio *);
-extern void llcrypt_enqueue_decrypt_bio(struct llcrypt_ctx *ctx,
-                                       struct bio *bio);
-extern int llcrypt_zeroout_range(const struct inode *, pgoff_t, sector_t,
-                                unsigned int);
-
 /* hooks.c */
 extern int llcrypt_file_open(struct inode *inode, struct file *filp);
 extern int __llcrypt_prepare_link(struct inode *inode, struct inode *dir,
@@ -525,22 +518,6 @@ static inline bool llcrypt_match_name(const struct llcrypt_name *fname,
        return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len);
 }
 
-/* bio.c */
-static inline void llcrypt_decrypt_bio(struct bio *bio)
-{
-}
-
-static inline void llcrypt_enqueue_decrypt_bio(struct llcrypt_ctx *ctx,
-                                              struct bio *bio)
-{
-}
-
-static inline int llcrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
-                                       sector_t pblk, unsigned int len)
-{
-       return -EOPNOTSUPP;
-}
-
 /* hooks.c */
 
 static inline int llcrypt_file_open(struct inode *inode, struct file *filp)
index b94628e..ae6b8c9 100644 (file)
@@ -8,7 +8,7 @@ libcfs-linux-objs += glob.o
 libcfs-linux-objs += xarray.o
 
 libcfs-crypto-objs := crypto.o fname.o hkdf.o hooks.o keyring.o
-libcfs-crypto-objs += keysetup.o keysetup_v1.o policy.o bio.o
+libcfs-crypto-objs += keysetup.o keysetup_v1.o policy.o
 
 default: all
 
index 2eaeb83..45b0829 100644 (file)
@@ -1,4 +1,4 @@
 if LLCRYPT
 EXTRA_DIST = crypto.c fname.c hkdf.c hooks.c keyring.c \
-       keysetup.c keysetup_v1.c policy.c bio.c llcrypt_private.h
+       keysetup.c keysetup_v1.c policy.c llcrypt_private.h
 endif
diff --git a/libcfs/libcfs/crypto/bio.c b/libcfs/libcfs/crypto/bio.c
deleted file mode 100644 (file)
index 78b56cb..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * This contains encryption functions for per-file encryption.
- *
- * Copyright (C) 2015, Google, Inc.
- * Copyright (C) 2015, Motorola Mobility
- *
- * Written by Michael Halcrow, 2014.
- *
- * Filename encryption additions
- *     Uday Savagaonkar, 2014
- * Encryption policy handling additions
- *     Ildar Muslukhov, 2014
- * Add llcrypt_pullback_bio_page()
- *     Jaegeuk Kim, 2015.
- *
- * This has not yet undergone a rigorous security audit.
- *
- * The usage of AES-XTS should conform to recommendations in NIST
- * Special Publication 800-38E and IEEE P1619/D16.
- */
-/*
- * Linux commit 219d54332a09
- * tags/v5.4
- */
-
-#include <linux/pagemap.h>
-#include <linux/module.h>
-#include <linux/bio.h>
-#include <linux/namei.h>
-#include <lustre_compat.h>
-#include "llcrypt_private.h"
-
-static void __llcrypt_decrypt_bio(struct bio *bio, bool done)
-{
-       struct bio_vec *bv;
-#ifdef HAVE_BVEC_ITER_ALL
-       struct bvec_iter_all iter_all;
-#else
-       int iter_all;
-#endif
-
-       bio_for_each_segment_all(bv, bio, iter_all) {
-               struct page *page = bv->bv_page;
-               int ret = llcrypt_decrypt_pagecache_blocks(page, bv->bv_len,
-                                                          bv->bv_offset);
-               if (ret)
-                       SetPageError(page);
-               else if (done)
-                       SetPageUptodate(page);
-               if (done)
-                       unlock_page(page);
-       }
-}
-
-void llcrypt_decrypt_bio(struct bio *bio)
-{
-       __llcrypt_decrypt_bio(bio, false);
-}
-EXPORT_SYMBOL(llcrypt_decrypt_bio);
-
-static void completion_pages(struct work_struct *work)
-{
-       struct llcrypt_ctx *ctx = container_of(work, struct llcrypt_ctx, work);
-       struct bio *bio = ctx->bio;
-
-       __llcrypt_decrypt_bio(bio, true);
-       llcrypt_release_ctx(ctx);
-       bio_put(bio);
-}
-
-void llcrypt_enqueue_decrypt_bio(struct llcrypt_ctx *ctx, struct bio *bio)
-{
-       INIT_WORK(&ctx->work, completion_pages);
-       ctx->bio = bio;
-       llcrypt_enqueue_decrypt_work(&ctx->work);
-}
-EXPORT_SYMBOL(llcrypt_enqueue_decrypt_bio);
-
-int llcrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
-                               sector_t pblk, unsigned int len)
-{
-       const unsigned int blockbits = inode->i_blkbits;
-       const unsigned int blocksize = 1 << blockbits;
-       struct page *ciphertext_page;
-       struct bio *bio;
-       int ret, err = 0;
-
-       ciphertext_page = llcrypt_alloc_bounce_page(GFP_NOWAIT);
-       if (!ciphertext_page)
-               return -ENOMEM;
-
-       while (len--) {
-               err = llcrypt_crypt_block(inode, FS_ENCRYPT, lblk,
-                                         ZERO_PAGE(0), ciphertext_page,
-                                         blocksize, 0, GFP_NOFS);
-               if (err)
-                       goto errout;
-
-               bio = cfs_bio_alloc(inode->i_sb->s_bdev, 1, REQ_OP_WRITE,
-                                   GFP_NOWAIT);
-               if (!bio) {
-                       err = -ENOMEM;
-                       goto errout;
-               }
-               bio->bi_iter.bi_sector = pblk << (blockbits - 9);
-               ret = bio_add_page(bio, ciphertext_page, blocksize, 0);
-               if (WARN_ON(ret != blocksize)) {
-                       /* should never happen! */
-                       bio_put(bio);
-                       err = -EIO;
-                       goto errout;
-               }
-               err = submit_bio_wait(bio);
-               if (err == 0 && bio->bi_status)
-                       err = -EIO;
-               bio_put(bio);
-               if (err)
-                       goto errout;
-               lblk++;
-               pblk++;
-       }
-       err = 0;
-errout:
-       llcrypt_free_bounce_page(ciphertext_page);
-       return err;
-}
-EXPORT_SYMBOL(llcrypt_zeroout_range);