From 2421e998491decb1ab3e25f298ee6291575fad36 Mon Sep 17 00:00:00 2001 From: Swapnil Ingle Date: Fri, 7 May 2021 06:35:15 -0400 Subject: [PATCH] scsi: Cache physical block size locally Addressing review comment from 6cebe9d0. Minor optimisation to cache result of spdk_u32log2() into local variable instead of calling it multiple times. Signed-off-by: Swapnil Ingle Change-Id: I2fd6afd1e3ee461662de3f9d278958664224e106 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7806 Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto Reviewed-by: sunshihao Tested-by: SPDK CI Jenkins Community-CI: Broadcom CI --- lib/scsi/scsi_bdev.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/scsi/scsi_bdev.c b/lib/scsi/scsi_bdev.c index e135296e0..fe6b1d204 100644 --- a/lib/scsi/scsi_bdev.c +++ b/lib/scsi/scsi_bdev.c @@ -1614,15 +1614,16 @@ bdev_scsi_process_block(struct spdk_scsi_task *task) switch (cdb[1] & 0x1f) { /* SERVICE ACTION */ case SPDK_SBC_SAI_READ_CAPACITY_16: { uint8_t buffer[32] = {0}; - uint32_t lbppb; + uint32_t lbppb, lbppbe; to_be64(&buffer[0], spdk_bdev_get_num_blocks(bdev) - 1); to_be32(&buffer[8], spdk_bdev_get_data_block_size(bdev)); lbppb = spdk_bdev_get_physical_block_size(bdev) / spdk_bdev_get_data_block_size(bdev); - if (spdk_u32log2(lbppb) > 0xf) { - SPDK_ERRLOG("lbppbe(0x%x) > 0xf\n", spdk_u32log2(lbppb)); + lbppbe = spdk_u32log2(lbppb); + if (lbppbe > 0xf) { + SPDK_ERRLOG("lbppbe(0x%x) > 0xf\n", lbppbe); } else { - buffer[13] = spdk_u32log2(lbppb); + buffer[13] = lbppbe; } /* * Set the TPE bit to 1 to indicate thin provisioning.