From f61a8c9f5fa4cebc40981fd1fb0fb9fd23e586ac Mon Sep 17 00:00:00 2001 From: Patrick Farrell Date: Wed, 27 Mar 2024 17:34:09 -0400 Subject: [PATCH] LU-17422 obdclass: move page pools to obdclass This patch starts the process of moving page pools to obdclass by moving the file and making the changes necessary to compile and run Lustre with the file moved. This does not rename anything in the file yet, that will be done in subsequent patches. Signed-off-by: Patrick Farrell Change-Id: Iff39dd9ddfb105773f8eafa4754d32189067189b Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53667 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Sebastien Buisson Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/include/obd_class.h | 6 ++ lustre/obdclass/Makefile.in | 1 + .../{ptlrpc/sec_bulk.c => obdclass/page_pools.c} | 117 ++------------------- lustre/ptlrpc/Makefile.in | 2 +- lustre/ptlrpc/ptlrpc_internal.h | 6 -- lustre/ptlrpc/sec.c | 109 +++++++++++++++++++ 6 files changed, 123 insertions(+), 118 deletions(-) rename lustre/{ptlrpc/sec_bulk.c => obdclass/page_pools.c} (91%) diff --git a/lustre/include/obd_class.h b/lustre/include/obd_class.h index f2f74be..d488e6d 100644 --- a/lustre/include/obd_class.h +++ b/lustre/include/obd_class.h @@ -146,6 +146,12 @@ __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli); int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max); int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq); +/* page_pools.c */ +int sptlrpc_pool_init(void); +void sptlrpc_pool_fini(void); +int encrypt_page_pools_seq_show(struct seq_file *m, void *v); +int page_pools_seq_show(struct seq_file *m, void *v); + __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc); void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc, __u16 tag); diff --git a/lustre/obdclass/Makefile.in b/lustre/obdclass/Makefile.in index ba1ef4c..7bf2edf 100644 --- a/lustre/obdclass/Makefile.in +++ b/lustre/obdclass/Makefile.in @@ -24,6 +24,7 @@ obdclass-all-objs += kernelcomm.o jobid.o obdclass-all-objs += integrity.o obd_cksum.o obdclass-all-objs += lu_tgt_descs.o lu_tgt_pool.o obdclass-all-objs += range_lock.o interval_tree.o +obdclass-all-objs += page_pools.o @SERVER_TRUE@obdclass-all-objs += idmap.o @SERVER_TRUE@obdclass-all-objs += lprocfs_jobstats.o diff --git a/lustre/ptlrpc/sec_bulk.c b/lustre/obdclass/page_pools.c similarity index 91% rename from lustre/ptlrpc/sec_bulk.c rename to lustre/obdclass/page_pools.c index a005c2b..c420f30 100644 --- a/lustre/ptlrpc/sec_bulk.c +++ b/lustre/obdclass/page_pools.c @@ -28,7 +28,7 @@ /* * This file is part of Lustre, http://www.lustre.org/ * - * lustre/ptlrpc/sec_bulk.c + * lustre/obdclass/page_pools.c * * Author: Eric Mei */ @@ -38,7 +38,6 @@ #include #include -#include #include #include #include @@ -46,8 +45,6 @@ #include #include -#include "ptlrpc_internal.h" - /* we have a pool for every power of 2 number of pages <= MAX_BRW_BITS. * most pools will be unused, but that's OK - unused pools are very cheap */ @@ -189,6 +186,7 @@ int encrypt_page_pools_seq_show(struct seq_file *m, void *v) return 0; } +EXPORT_SYMBOL(encrypt_page_pools_seq_show); /* * /sys/kernel/debug/lustre/sptlrpc/page_pools @@ -249,6 +247,7 @@ int page_pools_seq_show(struct seq_file *m, void *v) } return 0; } +EXPORT_SYMBOL(page_pools_seq_show); static void pool_release_free_pages(long npages, struct ptlrpc_page_pool *pool) { @@ -896,6 +895,7 @@ void sptlrpc_pool_put_desc_pages(struct ptlrpc_bulk_desc *desc) desc->bd_iov_count * sizeof(*desc->bd_enc_vec)); desc->bd_enc_vec = NULL; } +EXPORT_SYMBOL(sptlrpc_pool_put_desc_pages); void sptlrpc_pool_put_pages_array(struct page **pa, unsigned int count) { @@ -1076,6 +1076,7 @@ fail: RETURN(rc); } +EXPORT_SYMBOL(sptlrpc_pool_init); void sptlrpc_pool_fini(void) { @@ -1114,110 +1115,4 @@ void sptlrpc_pool_fini(void) OBD_FREE(page_pools, POOLS_COUNT * sizeof(*page_pools)); } - -static int cfs_hash_alg_id[] = { - [BULK_HASH_ALG_NULL] = CFS_HASH_ALG_NULL, - [BULK_HASH_ALG_ADLER32] = CFS_HASH_ALG_ADLER32, - [BULK_HASH_ALG_CRC32] = CFS_HASH_ALG_CRC32, - [BULK_HASH_ALG_MD5] = CFS_HASH_ALG_MD5, - [BULK_HASH_ALG_SHA1] = CFS_HASH_ALG_SHA1, - [BULK_HASH_ALG_SHA256] = CFS_HASH_ALG_SHA256, - [BULK_HASH_ALG_SHA384] = CFS_HASH_ALG_SHA384, - [BULK_HASH_ALG_SHA512] = CFS_HASH_ALG_SHA512, -}; -const char *sptlrpc_get_hash_name(__u8 hash_alg) -{ - return cfs_crypto_hash_name(cfs_hash_alg_id[hash_alg]); -} - -__u8 sptlrpc_get_hash_alg(const char *algname) -{ - return cfs_crypto_hash_alg(algname); -} - -int bulk_sec_desc_unpack(struct lustre_msg *msg, int offset, int swabbed) -{ - struct ptlrpc_bulk_sec_desc *bsd; - int size = msg->lm_buflens[offset]; - - bsd = lustre_msg_buf(msg, offset, sizeof(*bsd)); - if (bsd == NULL) { - CERROR("Invalid bulk sec desc: size %d\n", size); - return -EINVAL; - } - - if (swabbed) - __swab32s(&bsd->bsd_nob); - - if (unlikely(bsd->bsd_version != 0)) { - CERROR("Unexpected version %u\n", bsd->bsd_version); - return -EPROTO; - } - - if (unlikely(bsd->bsd_type >= SPTLRPC_BULK_MAX)) { - CERROR("Invalid type %u\n", bsd->bsd_type); - return -EPROTO; - } - - /* FIXME more sanity check here */ - - if (unlikely(bsd->bsd_svc != SPTLRPC_BULK_SVC_NULL && - bsd->bsd_svc != SPTLRPC_BULK_SVC_INTG && - bsd->bsd_svc != SPTLRPC_BULK_SVC_PRIV)) { - CERROR("Invalid svc %u\n", bsd->bsd_svc); - return -EPROTO; - } - - return 0; -} -EXPORT_SYMBOL(bulk_sec_desc_unpack); - -/* - * Compute the checksum of an RPC buffer payload. If the return \a buflen - * is not large enough, truncate the result to fit so that it is possible - * to use a hash function with a large hash space, but only use a part of - * the resulting hash. - */ -int sptlrpc_get_bulk_checksum(struct ptlrpc_bulk_desc *desc, __u8 alg, - void *buf, int buflen) -{ - struct ahash_request *req; - int hashsize; - unsigned int bufsize; - int i, err; - - LASSERT(alg > BULK_HASH_ALG_NULL && alg < BULK_HASH_ALG_MAX); - LASSERT(buflen >= 4); - - req = cfs_crypto_hash_init(cfs_hash_alg_id[alg], NULL, 0); - if (IS_ERR(req)) { - CERROR("Unable to initialize checksum hash %s\n", - cfs_crypto_hash_name(cfs_hash_alg_id[alg])); - return PTR_ERR(req); - } - - hashsize = cfs_crypto_hash_digestsize(cfs_hash_alg_id[alg]); - - for (i = 0; i < desc->bd_iov_count; i++) { - cfs_crypto_hash_update_page(req, - desc->bd_vec[i].bv_page, - desc->bd_vec[i].bv_offset & - ~PAGE_MASK, - desc->bd_vec[i].bv_len); - } - - if (hashsize > buflen) { - unsigned char hashbuf[CFS_CRYPTO_HASH_DIGESTSIZE_MAX]; - - bufsize = sizeof(hashbuf); - LASSERTF(bufsize >= hashsize, "bufsize = %u < hashsize %u\n", - bufsize, hashsize); - err = cfs_crypto_hash_final(req, hashbuf, &bufsize); - memcpy(buf, hashbuf, buflen); - } else { - bufsize = buflen; - err = cfs_crypto_hash_final(req, buf, &bufsize); - } - - return err; -} +EXPORT_SYMBOL(sptlrpc_pool_fini); diff --git a/lustre/ptlrpc/Makefile.in b/lustre/ptlrpc/Makefile.in index 5471a34..d2e9c37 100644 --- a/lustre/ptlrpc/Makefile.in +++ b/lustre/ptlrpc/Makefile.in @@ -7,7 +7,7 @@ ptlrpc_objs := client.o recover.o connection.o niobuf.o pack_generic.o ptlrpc_objs += events.o ptlrpc_module.o service.o pinger.o ptlrpc_objs += llog_net.o llog_client.o import.o ptlrpcd.o ptlrpc_objs += pers.o lproc_ptlrpc.o wiretest.o layout.o -ptlrpc_objs += sec.o sec_ctx.o sec_bulk.o sec_gc.o sec_config.o sec_lproc.o +ptlrpc_objs += sec.o sec_ctx.o sec_gc.o sec_config.o sec_lproc.o ptlrpc_objs += sec_null.o sec_plain.o nrs.o nrs_fifo.o nrs_delay.o heap.o ptlrpc_objs += errno.o batch.o diff --git a/lustre/ptlrpc/ptlrpc_internal.h b/lustre/ptlrpc/ptlrpc_internal.h index 820906f..95f5955 100644 --- a/lustre/ptlrpc/ptlrpc_internal.h +++ b/lustre/ptlrpc/ptlrpc_internal.h @@ -290,12 +290,6 @@ void sptlrpc_null_fini(void); int sptlrpc_plain_init(void); void sptlrpc_plain_fini(void); -/* sec_bulk.c */ -int sptlrpc_pool_init(void); -void sptlrpc_pool_fini(void); -int encrypt_page_pools_seq_show(struct seq_file *m, void *v); -int page_pools_seq_show(struct seq_file *m, void *v); - /* sec_lproc.c */ int sptlrpc_lproc_init(void); void sptlrpc_lproc_fini(void); diff --git a/lustre/ptlrpc/sec.c b/lustre/ptlrpc/sec.c index 682426a..f725ab6 100644 --- a/lustre/ptlrpc/sec.c +++ b/lustre/ptlrpc/sec.c @@ -48,6 +48,7 @@ #include #include #include +#include #include "ptlrpc_internal.h" @@ -2788,6 +2789,114 @@ int sptlrpc_flavor_has_bulk(struct sptlrpc_flavor *flvr) } EXPORT_SYMBOL(sptlrpc_flavor_has_bulk); + +static int cfs_hash_alg_id[] = { + [BULK_HASH_ALG_NULL] = CFS_HASH_ALG_NULL, + [BULK_HASH_ALG_ADLER32] = CFS_HASH_ALG_ADLER32, + [BULK_HASH_ALG_CRC32] = CFS_HASH_ALG_CRC32, + [BULK_HASH_ALG_MD5] = CFS_HASH_ALG_MD5, + [BULK_HASH_ALG_SHA1] = CFS_HASH_ALG_SHA1, + [BULK_HASH_ALG_SHA256] = CFS_HASH_ALG_SHA256, + [BULK_HASH_ALG_SHA384] = CFS_HASH_ALG_SHA384, + [BULK_HASH_ALG_SHA512] = CFS_HASH_ALG_SHA512, +}; +const char *sptlrpc_get_hash_name(__u8 hash_alg) +{ + return cfs_crypto_hash_name(cfs_hash_alg_id[hash_alg]); +} + +__u8 sptlrpc_get_hash_alg(const char *algname) +{ + return cfs_crypto_hash_alg(algname); +} + +int bulk_sec_desc_unpack(struct lustre_msg *msg, int offset, int swabbed) +{ + struct ptlrpc_bulk_sec_desc *bsd; + int size = msg->lm_buflens[offset]; + + bsd = lustre_msg_buf(msg, offset, sizeof(*bsd)); + if (bsd == NULL) { + CERROR("Invalid bulk sec desc: size %d\n", size); + return -EINVAL; + } + + if (swabbed) + __swab32s(&bsd->bsd_nob); + + if (unlikely(bsd->bsd_version != 0)) { + CERROR("Unexpected version %u\n", bsd->bsd_version); + return -EPROTO; + } + + if (unlikely(bsd->bsd_type >= SPTLRPC_BULK_MAX)) { + CERROR("Invalid type %u\n", bsd->bsd_type); + return -EPROTO; + } + + /* FIXME more sanity check here */ + + if (unlikely(bsd->bsd_svc != SPTLRPC_BULK_SVC_NULL && + bsd->bsd_svc != SPTLRPC_BULK_SVC_INTG && + bsd->bsd_svc != SPTLRPC_BULK_SVC_PRIV)) { + CERROR("Invalid svc %u\n", bsd->bsd_svc); + return -EPROTO; + } + + return 0; +} +EXPORT_SYMBOL(bulk_sec_desc_unpack); + +/* + * Compute the checksum of an RPC buffer payload. If the return \a buflen + * is not large enough, truncate the result to fit so that it is possible + * to use a hash function with a large hash space, but only use a part of + * the resulting hash. + */ +int sptlrpc_get_bulk_checksum(struct ptlrpc_bulk_desc *desc, __u8 alg, + void *buf, int buflen) +{ + struct ahash_request *req; + int hashsize; + unsigned int bufsize; + int i, err; + + LASSERT(alg > BULK_HASH_ALG_NULL && alg < BULK_HASH_ALG_MAX); + LASSERT(buflen >= 4); + + req = cfs_crypto_hash_init(cfs_hash_alg_id[alg], NULL, 0); + if (IS_ERR(req)) { + CERROR("Unable to initialize checksum hash %s\n", + cfs_crypto_hash_name(cfs_hash_alg_id[alg])); + return PTR_ERR(req); + } + + hashsize = cfs_crypto_hash_digestsize(cfs_hash_alg_id[alg]); + + for (i = 0; i < desc->bd_iov_count; i++) { + cfs_crypto_hash_update_page(req, + desc->bd_vec[i].bv_page, + desc->bd_vec[i].bv_offset & + ~PAGE_MASK, + desc->bd_vec[i].bv_len); + } + + if (hashsize > buflen) { + unsigned char hashbuf[CFS_CRYPTO_HASH_DIGESTSIZE_MAX]; + + bufsize = sizeof(hashbuf); + LASSERTF(bufsize >= hashsize, "bufsize = %u < hashsize %u\n", + bufsize, hashsize); + err = cfs_crypto_hash_final(req, hashbuf, &bufsize); + memcpy(buf, hashbuf, buflen); + } else { + bufsize = buflen; + err = cfs_crypto_hash_final(req, buf, &bufsize); + } + + return err; +} + /* * crypto API helper/alloc blkciper */ -- 1.8.3.1