X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fptlrpc%2Fsec_bulk.c;h=e6c1df12cb89f5235c06395f3c1ee0f592b7ac24;hp=f8d3222c4826037deb2976b21d48718352f670d2;hb=917655fc2938b90a9c246dd2d58408c42aa1658d;hpb=9b7ca14430edf84f8c031b1489b3c0d2fb617535 diff --git a/lustre/ptlrpc/sec_bulk.c b/lustre/ptlrpc/sec_bulk.c index f8d3222..e6c1df1 100644 --- a/lustre/ptlrpc/sec_bulk.c +++ b/lustre/ptlrpc/sec_bulk.c @@ -55,10 +55,9 @@ module_param(enc_pool_max_memory_mb, int, 0644); MODULE_PARM_DESC(enc_pool_max_memory_mb, "Encoding pool max memory (MB), 1/8 of total physical memory by default"); -/**************************************** - * bulk encryption page pools * - ****************************************/ - +/* + * bulk encryption page pools + */ #define PTRS_PER_PAGE (PAGE_SIZE / sizeof(void *)) #define PAGES_PER_POOL (PTRS_PER_PAGE) @@ -69,57 +68,50 @@ MODULE_PARM_DESC(enc_pool_max_memory_mb, #define CACHE_QUIESCENT_PERIOD (20) static struct ptlrpc_enc_page_pool { - /* - * constants - */ - unsigned long epp_max_pages; /* maximum pages can hold, const */ - unsigned int epp_max_pools; /* number of pools, const */ + unsigned long epp_max_pages; /* maximum pages can hold, const */ + unsigned int epp_max_pools; /* number of pools, const */ /* * wait queue in case of not enough free pages. */ - wait_queue_head_t epp_waitq; /* waiting threads */ - unsigned int epp_waitqlen; /* wait queue length */ - unsigned long epp_pages_short; /* # of pages wanted of in-q users */ - unsigned int epp_growing:1; /* during adding pages */ - - /* - * indicating how idle the pools are, from 0 to MAX_IDLE_IDX - * this is counted based on each time when getting pages from - * the pools, not based on time. which means in case that system - * is idled for a while but the idle_idx might still be low if no - * activities happened in the pools. - */ - unsigned long epp_idle_idx; - - /* last shrink time due to mem tight */ - time64_t epp_last_shrink; - time64_t epp_last_access; - - /* - * in-pool pages bookkeeping - */ - spinlock_t epp_lock; /* protect following fields */ - unsigned long epp_total_pages; /* total pages in pools */ - unsigned long epp_free_pages; /* current pages available */ - - /* - * statistics - */ - unsigned long epp_st_max_pages; /* # of pages ever reached */ - unsigned int epp_st_grows; /* # of grows */ - unsigned int epp_st_grow_fails; /* # of add pages failures */ - unsigned int epp_st_shrinks; /* # of shrinks */ - unsigned long epp_st_access; /* # of access */ - unsigned long epp_st_missings; /* # of cache missing */ - unsigned long epp_st_lowfree; /* lowest free pages reached */ - unsigned int epp_st_max_wqlen; /* highest waitqueue length */ - ktime_t epp_st_max_wait; /* in nanoseconds */ - unsigned long epp_st_outofmem; /* # of out of mem requests */ + wait_queue_head_t epp_waitq; /* waiting threads */ + unsigned int epp_waitqlen; /* wait queue length */ + unsigned long epp_pages_short; /* # of pages wanted of in-q users */ + unsigned int epp_growing:1; /* during adding pages */ + + /* + * indicating how idle the pools are, from 0 to MAX_IDLE_IDX + * this is counted based on each time when getting pages from + * the pools, not based on time. which means in case that system + * is idled for a while but the idle_idx might still be low if no + * activities happened in the pools. + */ + unsigned long epp_idle_idx; + + /* last shrink time due to mem tight */ + time64_t epp_last_shrink; + time64_t epp_last_access; + + /* in-pool pages bookkeeping */ + spinlock_t epp_lock; /* protect following fields */ + unsigned long epp_total_pages; /* total pages in pools */ + unsigned long epp_free_pages; /* current pages available */ + + /* statistics */ + unsigned long epp_st_max_pages; /* # of pages ever reached */ + unsigned int epp_st_grows; /* # of grows */ + unsigned int epp_st_grow_fails; /* # of add pages failures */ + unsigned int epp_st_shrinks; /* # of shrinks */ + unsigned long epp_st_access; /* # of access */ + unsigned long epp_st_missings; /* # of cache missing */ + unsigned long epp_st_lowfree; /* lowest free pages reached */ + unsigned int epp_st_max_wqlen; /* highest waitqueue length */ + ktime_t epp_st_max_wait; /* in nanoseconds */ + unsigned long epp_st_outofmem; /* # of out of mem requests */ /* * pointers to pools, may be vmalloc'd */ - struct page ***epp_pools; + struct page ***epp_pools; } page_pools; /* @@ -155,7 +147,7 @@ int sptlrpc_proc_enc_pool_seq_show(struct seq_file *m, void *v) "max waitqueue depth: %u\n" "max wait time ms: %lld\n" "out of mem: %lu\n", - totalram_pages, PAGES_PER_POOL, + cfs_totalram_pages(), PAGES_PER_POOL, page_pools.epp_max_pages, page_pools.epp_max_pools, page_pools.epp_total_pages, @@ -180,47 +172,47 @@ int sptlrpc_proc_enc_pool_seq_show(struct seq_file *m, void *v) static void enc_pools_release_free_pages(long npages) { - int p_idx, g_idx; - int p_idx_max1, p_idx_max2; + int p_idx, g_idx; + int p_idx_max1, p_idx_max2; - LASSERT(npages > 0); - LASSERT(npages <= page_pools.epp_free_pages); - LASSERT(page_pools.epp_free_pages <= page_pools.epp_total_pages); + LASSERT(npages > 0); + LASSERT(npages <= page_pools.epp_free_pages); + LASSERT(page_pools.epp_free_pages <= page_pools.epp_total_pages); - /* max pool index before the release */ - p_idx_max2 = (page_pools.epp_total_pages - 1) / PAGES_PER_POOL; + /* max pool index before the release */ + p_idx_max2 = (page_pools.epp_total_pages - 1) / PAGES_PER_POOL; - page_pools.epp_free_pages -= npages; - page_pools.epp_total_pages -= npages; + page_pools.epp_free_pages -= npages; + page_pools.epp_total_pages -= npages; - /* max pool index after the release */ - p_idx_max1 = page_pools.epp_total_pages == 0 ? -1 : - ((page_pools.epp_total_pages - 1) / PAGES_PER_POOL); + /* max pool index after the release */ + p_idx_max1 = page_pools.epp_total_pages == 0 ? -1 : + ((page_pools.epp_total_pages - 1) / PAGES_PER_POOL); - p_idx = page_pools.epp_free_pages / PAGES_PER_POOL; - g_idx = page_pools.epp_free_pages % PAGES_PER_POOL; - LASSERT(page_pools.epp_pools[p_idx]); + p_idx = page_pools.epp_free_pages / PAGES_PER_POOL; + g_idx = page_pools.epp_free_pages % PAGES_PER_POOL; + LASSERT(page_pools.epp_pools[p_idx]); - while (npages--) { - LASSERT(page_pools.epp_pools[p_idx]); - LASSERT(page_pools.epp_pools[p_idx][g_idx] != NULL); + while (npages--) { + LASSERT(page_pools.epp_pools[p_idx]); + LASSERT(page_pools.epp_pools[p_idx][g_idx] != NULL); __free_page(page_pools.epp_pools[p_idx][g_idx]); - page_pools.epp_pools[p_idx][g_idx] = NULL; + page_pools.epp_pools[p_idx][g_idx] = NULL; - if (++g_idx == PAGES_PER_POOL) { - p_idx++; - g_idx = 0; - } + if (++g_idx == PAGES_PER_POOL) { + p_idx++; + g_idx = 0; + } } - /* free unused pools */ - while (p_idx_max1 < p_idx_max2) { - LASSERT(page_pools.epp_pools[p_idx_max2]); + /* free unused pools */ + while (p_idx_max1 < p_idx_max2) { + LASSERT(page_pools.epp_pools[p_idx_max2]); OBD_FREE(page_pools.epp_pools[p_idx_max2], PAGE_SIZE); - page_pools.epp_pools[p_idx_max2] = NULL; - p_idx_max2--; - } + page_pools.epp_pools[p_idx_max2] = NULL; + p_idx_max2--; + } } /* @@ -294,10 +286,6 @@ static int enc_pools_shrink(SHRINKER_ARGS(sc, nr_to_scan, gfp_mask)) .nr_to_scan = shrink_param(sc, nr_to_scan), .gfp_mask = shrink_param(sc, gfp_mask) }; -#if !defined(HAVE_SHRINKER_WANT_SHRINK_PTR) && !defined(HAVE_SHRINK_CONTROL) - struct shrinker* shrinker = NULL; -#endif - enc_pools_shrink_scan(shrinker, &scv); return enc_pools_shrink_count(shrinker, &scv); @@ -308,7 +296,7 @@ static int enc_pools_shrink(SHRINKER_ARGS(sc, nr_to_scan, gfp_mask)) static inline int npages_to_npools(unsigned long npages) { - return (int) ((npages + PAGES_PER_POOL - 1) / PAGES_PER_POOL); + return (int) ((npages + PAGES_PER_POOL - 1) / PAGES_PER_POOL); } /* @@ -317,7 +305,7 @@ int npages_to_npools(unsigned long npages) static unsigned long enc_pools_cleanup(struct page ***pools, int npools) { unsigned long cleaned = 0; - int i, j; + int i, j; for (i = 0; i < npools; i++) { if (pools[i]) { @@ -344,81 +332,83 @@ static unsigned long enc_pools_cleanup(struct page ***pools, int npools) */ static void enc_pools_insert(struct page ***pools, int npools, int npages) { - int freeslot; - int op_idx, np_idx, og_idx, ng_idx; - int cur_npools, end_npools; + int freeslot; + int op_idx, np_idx, og_idx, ng_idx; + int cur_npools, end_npools; - LASSERT(npages > 0); - LASSERT(page_pools.epp_total_pages+npages <= page_pools.epp_max_pages); - LASSERT(npages_to_npools(npages) == npools); - LASSERT(page_pools.epp_growing); + LASSERT(npages > 0); + LASSERT(page_pools.epp_total_pages+npages <= page_pools.epp_max_pages); + LASSERT(npages_to_npools(npages) == npools); + LASSERT(page_pools.epp_growing); spin_lock(&page_pools.epp_lock); - /* - * (1) fill all the free slots of current pools. - */ - /* free slots are those left by rent pages, and the extra ones with - * index >= total_pages, locate at the tail of last pool. */ - freeslot = page_pools.epp_total_pages % PAGES_PER_POOL; - if (freeslot != 0) - freeslot = PAGES_PER_POOL - freeslot; - freeslot += page_pools.epp_total_pages - page_pools.epp_free_pages; - - op_idx = page_pools.epp_free_pages / PAGES_PER_POOL; - og_idx = page_pools.epp_free_pages % PAGES_PER_POOL; - np_idx = npools - 1; - ng_idx = (npages - 1) % PAGES_PER_POOL; - - while (freeslot) { - LASSERT(page_pools.epp_pools[op_idx][og_idx] == NULL); - LASSERT(pools[np_idx][ng_idx] != NULL); - - page_pools.epp_pools[op_idx][og_idx] = pools[np_idx][ng_idx]; - pools[np_idx][ng_idx] = NULL; - - freeslot--; - - if (++og_idx == PAGES_PER_POOL) { - op_idx++; - og_idx = 0; - } - if (--ng_idx < 0) { - if (np_idx == 0) - break; - np_idx--; - ng_idx = PAGES_PER_POOL - 1; - } - } - - /* - * (2) add pools if needed. - */ - cur_npools = (page_pools.epp_total_pages + PAGES_PER_POOL - 1) / - PAGES_PER_POOL; - end_npools = (page_pools.epp_total_pages + npages + PAGES_PER_POOL -1) / - PAGES_PER_POOL; - LASSERT(end_npools <= page_pools.epp_max_pools); - - np_idx = 0; - while (cur_npools < end_npools) { - LASSERT(page_pools.epp_pools[cur_npools] == NULL); - LASSERT(np_idx < npools); - LASSERT(pools[np_idx] != NULL); - - page_pools.epp_pools[cur_npools++] = pools[np_idx]; - pools[np_idx++] = NULL; - } - - page_pools.epp_total_pages += npages; - page_pools.epp_free_pages += npages; - page_pools.epp_st_lowfree = page_pools.epp_free_pages; - - if (page_pools.epp_total_pages > page_pools.epp_st_max_pages) - page_pools.epp_st_max_pages = page_pools.epp_total_pages; - - CDEBUG(D_SEC, "add %d pages to total %lu\n", npages, - page_pools.epp_total_pages); + /* + * (1) fill all the free slots of current pools. + */ + /* + * free slots are those left by rent pages, and the extra ones with + * index >= total_pages, locate at the tail of last pool. + */ + freeslot = page_pools.epp_total_pages % PAGES_PER_POOL; + if (freeslot != 0) + freeslot = PAGES_PER_POOL - freeslot; + freeslot += page_pools.epp_total_pages - page_pools.epp_free_pages; + + op_idx = page_pools.epp_free_pages / PAGES_PER_POOL; + og_idx = page_pools.epp_free_pages % PAGES_PER_POOL; + np_idx = npools - 1; + ng_idx = (npages - 1) % PAGES_PER_POOL; + + while (freeslot) { + LASSERT(page_pools.epp_pools[op_idx][og_idx] == NULL); + LASSERT(pools[np_idx][ng_idx] != NULL); + + page_pools.epp_pools[op_idx][og_idx] = pools[np_idx][ng_idx]; + pools[np_idx][ng_idx] = NULL; + + freeslot--; + + if (++og_idx == PAGES_PER_POOL) { + op_idx++; + og_idx = 0; + } + if (--ng_idx < 0) { + if (np_idx == 0) + break; + np_idx--; + ng_idx = PAGES_PER_POOL - 1; + } + } + + /* + * (2) add pools if needed. + */ + cur_npools = (page_pools.epp_total_pages + PAGES_PER_POOL - 1) / + PAGES_PER_POOL; + end_npools = (page_pools.epp_total_pages + npages + + PAGES_PER_POOL - 1) / PAGES_PER_POOL; + LASSERT(end_npools <= page_pools.epp_max_pools); + + np_idx = 0; + while (cur_npools < end_npools) { + LASSERT(page_pools.epp_pools[cur_npools] == NULL); + LASSERT(np_idx < npools); + LASSERT(pools[np_idx] != NULL); + + page_pools.epp_pools[cur_npools++] = pools[np_idx]; + pools[np_idx++] = NULL; + } + + page_pools.epp_total_pages += npages; + page_pools.epp_free_pages += npages; + page_pools.epp_st_lowfree = page_pools.epp_free_pages; + + if (page_pools.epp_total_pages > page_pools.epp_st_max_pages) + page_pools.epp_st_max_pages = page_pools.epp_total_pages; + + CDEBUG(D_SEC, "add %d pages to total %lu\n", npages, + page_pools.epp_total_pages); spin_unlock(&page_pools.epp_lock); } @@ -426,25 +416,25 @@ static void enc_pools_insert(struct page ***pools, int npools, int npages) static int enc_pools_add_pages(int npages) { static DEFINE_MUTEX(add_pages_mutex); - struct page ***pools; - int npools, alloced = 0; - int i, j, rc = -ENOMEM; + struct page ***pools; + int npools, alloced = 0; + int i, j, rc = -ENOMEM; if (npages < PTLRPC_MAX_BRW_PAGES) npages = PTLRPC_MAX_BRW_PAGES; mutex_lock(&add_pages_mutex); - if (npages + page_pools.epp_total_pages > page_pools.epp_max_pages) - npages = page_pools.epp_max_pages - page_pools.epp_total_pages; - LASSERT(npages > 0); + if (npages + page_pools.epp_total_pages > page_pools.epp_max_pages) + npages = page_pools.epp_max_pages - page_pools.epp_total_pages; + LASSERT(npages > 0); - page_pools.epp_st_grows++; + page_pools.epp_st_grows++; - npools = npages_to_npools(npages); - OBD_ALLOC(pools, npools * sizeof(*pools)); - if (pools == NULL) - goto out; + npools = npages_to_npools(npages); + OBD_ALLOC(pools, npools * sizeof(*pools)); + if (pools == NULL) + goto out; for (i = 0; i < npools; i++) { OBD_ALLOC(pools[i], PAGE_SIZE); @@ -462,21 +452,21 @@ static int enc_pools_add_pages(int npages) } LASSERT(alloced == npages); - enc_pools_insert(pools, npools, npages); - CDEBUG(D_SEC, "added %d pages into pools\n", npages); - rc = 0; + enc_pools_insert(pools, npools, npages); + CDEBUG(D_SEC, "added %d pages into pools\n", npages); + rc = 0; out_pools: - enc_pools_cleanup(pools, npools); - OBD_FREE(pools, npools * sizeof(*pools)); + enc_pools_cleanup(pools, npools); + OBD_FREE(pools, npools * sizeof(*pools)); out: - if (rc) { - page_pools.epp_st_grow_fails++; - CERROR("Failed to allocate %d enc pages\n", npages); - } + if (rc) { + page_pools.epp_st_grow_fails++; + CERROR("Failed to allocate %d enc pages\n", npages); + } mutex_unlock(&add_pages_mutex); - return rc; + return rc; } static inline void enc_pools_wakeup(void) @@ -491,7 +481,8 @@ static inline void enc_pools_wakeup(void) static int enc_pools_should_grow(int page_needed, time64_t now) { - /* don't grow if someone else is growing the pools right now, + /* + * don't grow if someone else is growing the pools right now, * or the pools has reached its full capacity */ if (page_pools.epp_growing || @@ -603,10 +594,12 @@ again: spin_lock(&page_pools.epp_lock); page_pools.epp_waitqlen--; } else { - /* ptlrpcd thread should not sleep in that case, + /* + * ptlrpcd thread should not sleep in that case, * or deadlock may occur! * Instead, return -ENOMEM so that upper layers - * will put request back in queue. */ + * will put request back in queue. + */ page_pools.epp_st_outofmem++; spin_unlock(&page_pools.epp_lock); OBD_FREE_LARGE(GET_ENC_KIOV(desc), @@ -632,11 +625,11 @@ again: page_pools.epp_st_max_wait = tick; } - /* proceed with rest of allocation */ - page_pools.epp_free_pages -= desc->bd_iov_count; + /* proceed with rest of allocation */ + page_pools.epp_free_pages -= desc->bd_iov_count; - p_idx = page_pools.epp_free_pages / PAGES_PER_POOL; - g_idx = page_pools.epp_free_pages % PAGES_PER_POOL; + p_idx = page_pools.epp_free_pages / PAGES_PER_POOL; + g_idx = page_pools.epp_free_pages % PAGES_PER_POOL; for (i = 0; i < desc->bd_iov_count; i++) { LASSERT(page_pools.epp_pools[p_idx][g_idx] != NULL); @@ -650,19 +643,19 @@ again: } } - if (page_pools.epp_free_pages < page_pools.epp_st_lowfree) - page_pools.epp_st_lowfree = page_pools.epp_free_pages; + if (page_pools.epp_free_pages < page_pools.epp_st_lowfree) + page_pools.epp_st_lowfree = page_pools.epp_free_pages; - /* - * new idle index = (old * weight + new) / (weight + 1) - */ - if (this_idle == -1) { - this_idle = page_pools.epp_free_pages * IDLE_IDX_MAX / - page_pools.epp_total_pages; - } - page_pools.epp_idle_idx = (page_pools.epp_idle_idx * IDLE_IDX_WEIGHT + - this_idle) / - (IDLE_IDX_WEIGHT + 1); + /* + * new idle index = (old * weight + new) / (weight + 1) + */ + if (this_idle == -1) { + this_idle = page_pools.epp_free_pages * IDLE_IDX_MAX / + page_pools.epp_total_pages; + } + page_pools.epp_idle_idx = (page_pools.epp_idle_idx * IDLE_IDX_WEIGHT + + this_idle) / + (IDLE_IDX_WEIGHT + 1); page_pools.epp_last_access = ktime_get_seconds(); @@ -673,8 +666,8 @@ EXPORT_SYMBOL(sptlrpc_enc_pool_get_pages); void sptlrpc_enc_pool_put_pages(struct ptlrpc_bulk_desc *desc) { - int p_idx, g_idx; - int i; + int p_idx, g_idx; + int i; LASSERT(ptlrpc_is_bulk_desc_kiov(desc->bd_type)); @@ -724,7 +717,7 @@ void sptlrpc_enc_pool_put_pages(struct ptlrpc_bulk_desc *desc) */ int sptlrpc_enc_pool_add_user(void) { - int need_grow = 0; + int need_grow = 0; spin_lock(&page_pools.epp_lock); if (page_pools.epp_growing == 0 && page_pools.epp_total_pages == 0) { @@ -748,7 +741,7 @@ EXPORT_SYMBOL(sptlrpc_enc_pool_add_user); int sptlrpc_enc_pool_del_user(void) { - return 0; + return 0; } EXPORT_SYMBOL(sptlrpc_enc_pool_del_user); @@ -775,9 +768,9 @@ int sptlrpc_enc_pool_init(void) DEF_SHRINKER_VAR(shvar, enc_pools_shrink, enc_pools_shrink_count, enc_pools_shrink_scan); - page_pools.epp_max_pages = totalram_pages / 8; + page_pools.epp_max_pages = cfs_totalram_pages() / 8; if (enc_pool_max_memory_mb > 0 && - enc_pool_max_memory_mb <= (totalram_pages >> mult)) + enc_pool_max_memory_mb <= (cfs_totalram_pages() >> mult)) page_pools.epp_max_pages = enc_pool_max_memory_mb << mult; page_pools.epp_max_pools = npages_to_npools(page_pools.epp_max_pages); @@ -786,55 +779,55 @@ int sptlrpc_enc_pool_init(void) page_pools.epp_waitqlen = 0; page_pools.epp_pages_short = 0; - page_pools.epp_growing = 0; + page_pools.epp_growing = 0; - page_pools.epp_idle_idx = 0; + page_pools.epp_idle_idx = 0; page_pools.epp_last_shrink = ktime_get_seconds(); page_pools.epp_last_access = ktime_get_seconds(); spin_lock_init(&page_pools.epp_lock); - page_pools.epp_total_pages = 0; - page_pools.epp_free_pages = 0; - - page_pools.epp_st_max_pages = 0; - page_pools.epp_st_grows = 0; - page_pools.epp_st_grow_fails = 0; - page_pools.epp_st_shrinks = 0; - page_pools.epp_st_access = 0; - page_pools.epp_st_missings = 0; - page_pools.epp_st_lowfree = 0; - page_pools.epp_st_max_wqlen = 0; + page_pools.epp_total_pages = 0; + page_pools.epp_free_pages = 0; + + page_pools.epp_st_max_pages = 0; + page_pools.epp_st_grows = 0; + page_pools.epp_st_grow_fails = 0; + page_pools.epp_st_shrinks = 0; + page_pools.epp_st_access = 0; + page_pools.epp_st_missings = 0; + page_pools.epp_st_lowfree = 0; + page_pools.epp_st_max_wqlen = 0; page_pools.epp_st_max_wait = ktime_set(0, 0); page_pools.epp_st_outofmem = 0; - enc_pools_alloc(); - if (page_pools.epp_pools == NULL) - return -ENOMEM; + enc_pools_alloc(); + if (page_pools.epp_pools == NULL) + return -ENOMEM; pools_shrinker = set_shrinker(pools_shrinker_seeks, &shvar); - if (pools_shrinker == NULL) { - enc_pools_free(); - return -ENOMEM; - } + if (pools_shrinker == NULL) { + enc_pools_free(); + return -ENOMEM; + } - return 0; + return 0; } void sptlrpc_enc_pool_fini(void) { - unsigned long cleaned, npools; + unsigned long cleaned, npools; - LASSERT(pools_shrinker); - LASSERT(page_pools.epp_pools); - LASSERT(page_pools.epp_total_pages == page_pools.epp_free_pages); + LASSERT(pools_shrinker); + LASSERT(page_pools.epp_pools); + LASSERT(page_pools.epp_total_pages == page_pools.epp_free_pages); remove_shrinker(pools_shrinker); - npools = npages_to_npools(page_pools.epp_total_pages); - cleaned = enc_pools_cleanup(page_pools.epp_pools, npools); - LASSERT(cleaned == page_pools.epp_total_pages); + npools = npages_to_npools(page_pools.epp_total_pages); + cleaned = enc_pools_cleanup(page_pools.epp_pools, npools); + LASSERT(cleaned == page_pools.epp_total_pages); - enc_pools_free(); + enc_pools_free(); if (page_pools.epp_st_access > 0) { CDEBUG(D_SEC, @@ -859,7 +852,7 @@ static int cfs_hash_alg_id[] = { [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) +const char *sptlrpc_get_hash_name(__u8 hash_alg) { return cfs_crypto_hash_name(cfs_hash_alg_id[hash_alg]); } @@ -871,39 +864,38 @@ __u8 sptlrpc_get_hash_alg(const char *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; + 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); @@ -916,26 +908,26 @@ EXPORT_SYMBOL(bulk_sec_desc_unpack); int sptlrpc_get_bulk_checksum(struct ptlrpc_bulk_desc *desc, __u8 alg, void *buf, int buflen) { - struct cfs_crypto_hash_desc *hdesc; - int hashsize; - unsigned int bufsize; - int i, err; + struct ahash_request *req; + int hashsize; + unsigned int bufsize; + int i, err; LASSERT(ptlrpc_is_bulk_desc_kiov(desc->bd_type)); LASSERT(alg > BULK_HASH_ALG_NULL && alg < BULK_HASH_ALG_MAX); LASSERT(buflen >= 4); - hdesc = cfs_crypto_hash_init(cfs_hash_alg_id[alg], NULL, 0); - if (IS_ERR(hdesc)) { + 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(hdesc); + 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(hdesc, + cfs_crypto_hash_update_page(req, BD_GET_KIOV(desc, i).kiov_page, BD_GET_KIOV(desc, i).kiov_offset & ~PAGE_MASK, @@ -948,11 +940,11 @@ int sptlrpc_get_bulk_checksum(struct ptlrpc_bulk_desc *desc, __u8 alg, bufsize = sizeof(hashbuf); LASSERTF(bufsize >= hashsize, "bufsize = %u < hashsize %u\n", bufsize, hashsize); - err = cfs_crypto_hash_final(hdesc, hashbuf, &bufsize); + err = cfs_crypto_hash_final(req, hashbuf, &bufsize); memcpy(buf, hashbuf, buflen); } else { bufsize = buflen; - err = cfs_crypto_hash_final(hdesc, buf, &bufsize); + err = cfs_crypto_hash_final(req, buf, &bufsize); } return err;