From 024179d8eeab28c311bf40a9de14bf681e87af18 Mon Sep 17 00:00:00 2001 From: Nick Connolly Date: Tue, 17 Nov 2020 16:29:21 +0000 Subject: [PATCH] module: Use PRId64 for portability POSIX defines PRId64/PRIu64/PRIx64 for printing 64-bit values in a portable way. Replace a few references to %ld to remove the assumption about the size of a long. Similarly, use %z with size_t arguments. Where the value being printed is an unsigned 64-bit value, use PRIu64 instead of %ld. Signed-off-by: Nick Connolly Change-Id: I0ec4c0cb5e7a8f4b94a1ee6272c8df9ee7f06aa6 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5141 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Aleksey Marchuk Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- module/bdev/gpt/gpt.c | 2 +- module/bdev/malloc/bdev_malloc.c | 4 ++-- module/bdev/null/bdev_null.c | 4 ++-- module/bdev/nvme/bdev_nvme.c | 12 ++++++------ module/bdev/raid/bdev_raid.c | 2 +- module/bdev/raid/raid0.c | 5 +++-- module/bdev/zone_block/vbdev_zone_block.c | 14 ++++++++------ module/blobfs/bdev/blobfs_bdev_rpc.c | 2 +- 8 files changed, 24 insertions(+), 21 deletions(-) diff --git a/module/bdev/gpt/gpt.c b/module/bdev/gpt/gpt.c index 0944f0503..d206e6ffd 100644 --- a/module/bdev/gpt/gpt.c +++ b/module/bdev/gpt/gpt.c @@ -120,7 +120,7 @@ gpt_read_partitions(struct spdk_gpt *gpt) partition_entry_size = from_le32(&head->size_of_partition_entry); if (partition_entry_size != sizeof(struct spdk_gpt_partition_entry)) { - SPDK_ERRLOG("Partition_entry_size(%x) != expected(%lx)\n", + SPDK_ERRLOG("Partition_entry_size(%x) != expected(%zx)\n", partition_entry_size, sizeof(struct spdk_gpt_partition_entry)); return -1; } diff --git a/module/bdev/malloc/bdev_malloc.c b/module/bdev/malloc/bdev_malloc.c index 069c6f4a9..8baa4c3b4 100644 --- a/module/bdev/malloc/bdev_malloc.c +++ b/module/bdev/malloc/bdev_malloc.c @@ -149,7 +149,7 @@ bdev_malloc_readv(struct malloc_disk *mdisk, struct spdk_io_channel *ch, return; } - SPDK_DEBUGLOG(bdev_malloc, "read %lu bytes from offset %#lx\n", + SPDK_DEBUGLOG(bdev_malloc, "read %zu bytes from offset %#" PRIx64 "\n", len, offset); task->status = SPDK_BDEV_IO_STATUS_SUCCESS; @@ -183,7 +183,7 @@ bdev_malloc_writev(struct malloc_disk *mdisk, struct spdk_io_channel *ch, return; } - SPDK_DEBUGLOG(bdev_malloc, "wrote %lu bytes to offset %#lx\n", + SPDK_DEBUGLOG(bdev_malloc, "wrote %zu bytes to offset %#" PRIx64 "\n", len, offset); task->status = SPDK_BDEV_IO_STATUS_SUCCESS; diff --git a/module/bdev/null/bdev_null.c b/module/bdev/null/bdev_null.c index eabc7de20..0c4202e4f 100644 --- a/module/bdev/null/bdev_null.c +++ b/module/bdev/null/bdev_null.c @@ -146,7 +146,7 @@ bdev_null_submit_request(struct spdk_io_channel *_ch, struct spdk_bdev_io *bdev_ rc = spdk_dif_generate(bdev_io->u.bdev.iovs, bdev_io->u.bdev.iovcnt, bdev_io->u.bdev.num_blocks, &dif_ctx); if (0 != rc) { - SPDK_ERRLOG("IO DIF generation failed: lba %lu, num_block %lu\n", + SPDK_ERRLOG("IO DIF generation failed: lba %" PRIu64 ", num_block %" PRIu64 "\n", bdev_io->u.bdev.offset_blocks, bdev_io->u.bdev.num_blocks); spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED); @@ -160,7 +160,7 @@ bdev_null_submit_request(struct spdk_io_channel *_ch, struct spdk_bdev_io *bdev_ rc = spdk_dif_verify(bdev_io->u.bdev.iovs, bdev_io->u.bdev.iovcnt, bdev_io->u.bdev.num_blocks, &dif_ctx, &err_blk); if (0 != rc) { - SPDK_ERRLOG("IO DIF verification failed: lba %lu, num_blocks %lu, " + SPDK_ERRLOG("IO DIF verification failed: lba %" PRIu64 ", num_blocks %" PRIu64 ", " "err_type %u, expected %u, actual %u, err_offset %u\n", bdev_io->u.bdev.offset_blocks, bdev_io->u.bdev.num_blocks, diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index 13dd4658f..2bce7df43 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -1346,7 +1346,7 @@ nvme_ctrlr_populate_namespaces(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, num_sectors = spdk_nvme_ns_get_num_sectors(nvme_ns); bdev = TAILQ_FIRST(&ns->bdevs); if (bdev->disk.blockcnt != num_sectors) { - SPDK_NOTICELOG("NSID %u is resized: bdev name %s, old size %lu, new size %lu\n", + SPDK_NOTICELOG("NSID %u is resized: bdev name %s, old size %" PRIu64 ", new size %" PRIu64 "\n", nsid, bdev->disk.name, bdev->disk.blockcnt, @@ -2416,7 +2416,7 @@ bdev_nvme_no_pi_readv(struct nvme_bdev_ns *nvme_ns, struct nvme_io_channel *nvme { int rc; - SPDK_DEBUGLOG(bdev_nvme, "read %lu blocks with offset %#lx without PI check\n", + SPDK_DEBUGLOG(bdev_nvme, "read %" PRIu64 " blocks with offset %#" PRIx64 " without PI check\n", lba_count, lba); bio->iovs = iov; @@ -2442,7 +2442,7 @@ bdev_nvme_readv(struct nvme_bdev_ns *nvme_ns, struct nvme_io_channel *nvme_ch, { int rc; - SPDK_DEBUGLOG(bdev_nvme, "read %lu blocks with offset %#lx\n", + SPDK_DEBUGLOG(bdev_nvme, "read %" PRIu64 " blocks with offset %#" PRIx64 "\n", lba_count, lba); bio->iovs = iov; @@ -2477,7 +2477,7 @@ bdev_nvme_writev(struct nvme_bdev_ns *nvme_ns, struct nvme_io_channel *nvme_ch, { int rc; - SPDK_DEBUGLOG(bdev_nvme, "write %lu blocks with offset %#lx\n", + SPDK_DEBUGLOG(bdev_nvme, "write %" PRIu64 " blocks with offset %#" PRIx64 "\n", lba_count, lba); bio->iovs = iov; @@ -2512,7 +2512,7 @@ bdev_nvme_comparev(struct nvme_bdev_ns *nvme_ns, struct nvme_io_channel *nvme_ch { int rc; - SPDK_DEBUGLOG(bdev_nvme, "compare %lu blocks with offset %#lx\n", + SPDK_DEBUGLOG(bdev_nvme, "compare %" PRIu64 " blocks with offset %#" PRIx64 "\n", lba_count, lba); bio->iovs = iov; @@ -2540,7 +2540,7 @@ bdev_nvme_comparev_and_writev(struct nvme_bdev_ns *nvme_ns, struct nvme_io_chann struct spdk_bdev_io *bdev_io = spdk_bdev_io_from_ctx(bio); int rc; - SPDK_DEBUGLOG(bdev_nvme, "compare and write %lu blocks with offset %#lx\n", + SPDK_DEBUGLOG(bdev_nvme, "compare and write %" PRIu64 " blocks with offset %#" PRIx64 "\n", lba_count, lba); bio->iovs = cmp_iov; diff --git a/module/bdev/raid/bdev_raid.c b/module/bdev/raid/bdev_raid.c index b1b314852..aa667800d 100644 --- a/module/bdev/raid/bdev_raid.c +++ b/module/bdev/raid/bdev_raid.c @@ -1199,7 +1199,7 @@ raid_bdev_configure(struct raid_bdev *raid_bdev) } raid_bdev->state = RAID_BDEV_STATE_ONLINE; SPDK_DEBUGLOG(bdev_raid, "io device register %p\n", raid_bdev); - SPDK_DEBUGLOG(bdev_raid, "blockcnt %lu, blocklen %u\n", + SPDK_DEBUGLOG(bdev_raid, "blockcnt %" PRIu64 ", blocklen %u\n", raid_bdev_gen->blockcnt, raid_bdev_gen->blocklen); spdk_io_device_register(raid_bdev, raid_bdev_create_cb, raid_bdev_destroy_cb, sizeof(struct raid_bdev_io_channel), diff --git a/module/bdev/raid/raid0.c b/module/bdev/raid/raid0.c index 7d7ffca41..90b0761ba 100644 --- a/module/bdev/raid/raid0.c +++ b/module/bdev/raid/raid0.c @@ -244,7 +244,8 @@ _raid0_split_io_range(struct raid_bdev_io_range *io_range, uint8_t disk_idx, + end_offset_in_disk - start_offset_in_disk + 1; SPDK_DEBUGLOG(bdev_raid0, - "raid_bdev (strip_size 0x%lx) splits IO to base_bdev (%u) at (0x%lx, 0x%lx).\n", + "raid_bdev (strip_size 0x%" PRIx64 ") splits IO to base_bdev (%u) at (0x%" PRIx64 ", 0x%" PRIx64 + ").\n", io_range->strip_size, disk_idx, offset_in_disk, nblocks_in_disk); *_offset_in_disk = offset_in_disk; @@ -369,7 +370,7 @@ static int raid0_start(struct raid_bdev *raid_bdev) * of raid bdev is the number of base bdev times the minimum block count * of any base bdev. */ - SPDK_DEBUGLOG(bdev_raid0, "min blockcount %lu, numbasedev %u, strip size shift %u\n", + SPDK_DEBUGLOG(bdev_raid0, "min blockcount %" PRIu64 ", numbasedev %u, strip size shift %u\n", min_blockcnt, raid_bdev->num_base_bdevs, raid_bdev->strip_size_shift); raid_bdev->bdev.blockcnt = ((min_blockcnt >> raid_bdev->strip_size_shift) << raid_bdev->strip_size_shift) * raid_bdev->num_base_bdevs; diff --git a/module/bdev/zone_block/vbdev_zone_block.c b/module/bdev/zone_block/vbdev_zone_block.c index 2838f38ed..d6fd296d0 100644 --- a/module/bdev/zone_block/vbdev_zone_block.c +++ b/module/bdev/zone_block/vbdev_zone_block.c @@ -391,7 +391,7 @@ zone_block_write(struct bdev_zone_block *bdev_node, struct zone_block_io_channel zone = zone_block_get_zone_containing_lba(bdev_node, lba); } if (!zone) { - SPDK_ERRLOG("Trying to write to invalid zone (lba 0x%lx)\n", lba); + SPDK_ERRLOG("Trying to write to invalid zone (lba 0x%" PRIx64 ")\n", lba); return -EINVAL; } @@ -414,7 +414,8 @@ zone_block_write(struct bdev_zone_block *bdev_node, struct zone_block_io_channel lba = wp; } else { if (lba != wp) { - SPDK_ERRLOG("Trying to write to zone with invalid address (lba 0x%lx, wp 0x%lx)\n", lba, wp); + SPDK_ERRLOG("Trying to write to zone with invalid address (lba 0x%" PRIx64 ", wp 0x%" PRIx64 ")\n", + lba, wp); rc = -EINVAL; goto write_fail; } @@ -422,7 +423,8 @@ zone_block_write(struct bdev_zone_block *bdev_node, struct zone_block_io_channel num_blocks_left = zone->zone_info.zone_id + zone->zone_info.capacity - wp; if (len > num_blocks_left) { - SPDK_ERRLOG("Write exceeds zone capacity (lba 0x%" PRIu64 ", len 0x%lx, wp 0x%lx)\n", lba, len, wp); + SPDK_ERRLOG("Write exceeds zone capacity (lba 0x%" PRIx64 ", len 0x%" PRIx64 ", wp 0x%" PRIx64 + ")\n", lba, len, wp); rc = -EINVAL; goto write_fail; } @@ -478,12 +480,12 @@ zone_block_read(struct bdev_zone_block *bdev_node, struct zone_block_io_channel zone = zone_block_get_zone_containing_lba(bdev_node, lba); if (!zone) { - SPDK_ERRLOG("Trying to read from invalid zone (lba 0x%lx)\n", lba); + SPDK_ERRLOG("Trying to read from invalid zone (lba 0x%" PRIx64 ")\n", lba); return -EINVAL; } if ((lba + len) > (zone->zone_info.zone_id + zone->zone_info.capacity)) { - SPDK_ERRLOG("Read exceeds zone capacity (lba 0x%lx, len 0x%lx)\n", lba, len); + SPDK_ERRLOG("Read exceeds zone capacity (lba 0x%" PRIx64 ", len 0x%" PRIx64 ")\n", lba, len); return -EINVAL; } @@ -795,7 +797,7 @@ zone_block_register(const char *base_bdev_name) if (bdev_node->num_zones * name->zone_capacity != base_bdev->blockcnt) { SPDK_DEBUGLOG(vbdev_zone_block, - "Lost %lu blocks due to zone capacity and base bdev size misalignment\n", + "Lost %" PRIu64 " blocks due to zone capacity and base bdev size misalignment\n", base_bdev->blockcnt - bdev_node->num_zones * name->zone_capacity); } diff --git a/module/blobfs/bdev/blobfs_bdev_rpc.c b/module/blobfs/bdev/blobfs_bdev_rpc.c index d0f61e5a8..c51d9bd0c 100644 --- a/module/blobfs/bdev/blobfs_bdev_rpc.c +++ b/module/blobfs/bdev/blobfs_bdev_rpc.c @@ -193,7 +193,7 @@ rpc_decode_cluster_sz(const struct spdk_json_val *val, void *out) return -EINVAL; } - SPDK_DEBUGLOG(blobfs_bdev_rpc, "cluster_sz of blobfs: %ld\n", *cluster_sz); + SPDK_DEBUGLOG(blobfs_bdev_rpc, "cluster_sz of blobfs: %" PRId64 "\n", *cluster_sz); return 0; }