examples: 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.

Where the value being printed is an unsigned 64-bit value, use PRIu64
instead of %ld.

Signed-off-by: Nick Connolly <nick.connolly@mayadata.io>
Change-Id: Ifa558522437f4922b922abf17712173cb5ca1184
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5134
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
Nick Connolly 2020-11-17 14:40:28 +00:00 committed by Tomasz Zawadzki
parent 4c890c3160
commit bb19c18f6a
4 changed files with 23 additions and 22 deletions

View File

@ -428,7 +428,8 @@ dump_result(struct thread_entry *threads, uint32_t num_threads)
total_failed += t->xfer_failed;
total_failed += t->fill_failed;
if (total_completed || total_failed)
printf("lcore = %d, copy success = %ld, copy failed = %ld, fill success = %ld, fill failed = %ld\n",
printf("lcore = %d, copy success = %" PRIu64 ", copy failed = %" PRIu64 ", fill success = %" PRIu64
", fill failed = %" PRIu64 "\n",
t->lcore_id, t->xfer_completed, t->xfer_failed, t->fill_completed, t->fill_failed);
}
return total_failed ? 1 : 0;

View File

@ -822,17 +822,17 @@ unregister_workers(void)
TAILQ_FOREACH_SAFE(ns_ctx, &worker->ns_ctx, link, tmp_ns_ctx) {
TAILQ_REMOVE(&worker->ns_ctx, ns_ctx, link);
printf("NS: %s I/O completed: %lu, failed: %lu\n",
printf("NS: %s I/O completed: %" PRIu64 ", failed: %" PRIu64 "\n",
ns_ctx->entry->name, ns_ctx->io_completed, ns_ctx->io_failed);
free(ns_ctx);
}
TAILQ_FOREACH_SAFE(ctrlr_ctx, &worker->ctrlr_ctx, link, tmp_ctrlr_ctx) {
TAILQ_REMOVE(&worker->ctrlr_ctx, ctrlr_ctx, link);
printf("CTRLR: %s abort submitted %lu, failed to submit %lu\n",
printf("CTRLR: %s abort submitted %" PRIu64 ", failed to submit %" PRIu64 "\n",
ctrlr_ctx->entry->name, ctrlr_ctx->abort_submitted,
ctrlr_ctx->abort_submit_failed);
printf("\t success %lu, unsuccess %lu, failed %lu\n",
printf("\t success %" PRIu64 ", unsuccess %" PRIu64 ", failed %" PRIu64 "\n",
ctrlr_ctx->successful_abort, ctrlr_ctx->unsuccessful_abort,
ctrlr_ctx->abort_failed);
free(ctrlr_ctx);

View File

@ -667,7 +667,7 @@ print_uint_var_dec(uint8_t *array, unsigned int len)
result += (uint64_t)array[i - 1] << (8 * (i - 1));
i--;
}
printf("%lu", result);
printf("%" PRIu64, result);
}
/* Print ASCII string as defined by the NVMe spec */
@ -714,9 +714,9 @@ print_ocssd_chunk_info(struct spdk_ocssd_chunk_information_entry *chk_info, int
printf("Chunk type (write mode): %s\n", ct_str);
printf("Chunk type (size_deviate): %s\n", chk_info[i].ct.size_deviate ? "Yes" : "No");
printf("Wear-level Index: %d\n", chk_info[i].wli);
printf("Starting LBA: %ld\n", chk_info[i].slba);
printf("Number of blocks in chunk: %ld\n", chk_info[i].cnlb);
printf("Write Pointer: %ld\n", chk_info[i].wp);
printf("Starting LBA: %" PRIu64 "\n", chk_info[i].slba);
printf("Number of blocks in chunk: %" PRIu64 "\n", chk_info[i].cnlb);
printf("Write Pointer: %" PRIu64 "\n", chk_info[i].wp);
}
}
@ -1207,7 +1207,7 @@ print_controller(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_transport
size *= (0x1000 << (cmbsz.bits.szu * 4));
printf("Supported: Yes\n");
printf("Total Size: %lu bytes\n", size);
printf("Total Size: %" PRIu64 " bytes\n", size);
printf("Submission Queues in CMB: %s\n",
cmbsz.bits.sqs ? "Supported" : "Not Supported");
printf("Completion Queues in CMB: %s\n",
@ -1775,18 +1775,18 @@ print_controller(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_transport
if (spdk_nvme_ctrlr_is_log_page_supported(ctrlr, SPDK_NVME_INTEL_LOG_TEMPERATURE)) {
printf("Intel Temperature Information\n");
printf("==================\n");
printf("Current Temperature: %lu\n", intel_temperature_page.current_temperature);
printf("Overtemp shutdown Flag for last critical component temperature: %lu\n",
printf("Current Temperature: %" PRIu64 "\n", intel_temperature_page.current_temperature);
printf("Overtemp shutdown Flag for last critical component temperature: %" PRIu64 "\n",
intel_temperature_page.shutdown_flag_last);
printf("Overtemp shutdown Flag for life critical component temperature: %lu\n",
printf("Overtemp shutdown Flag for life critical component temperature: %" PRIu64 "\n",
intel_temperature_page.shutdown_flag_life);
printf("Highest temperature: %lu\n", intel_temperature_page.highest_temperature);
printf("Lowest temperature: %lu\n", intel_temperature_page.lowest_temperature);
printf("Specified Maximum Operating Temperature: %lu\n",
printf("Highest temperature: %" PRIu64 "\n", intel_temperature_page.highest_temperature);
printf("Lowest temperature: %" PRIu64 "\n", intel_temperature_page.lowest_temperature);
printf("Specified Maximum Operating Temperature: %" PRIu64 "\n",
intel_temperature_page.specified_max_op_temperature);
printf("Specified Minimum Operating Temperature: %lu\n",
printf("Specified Minimum Operating Temperature: %" PRIu64 "\n",
intel_temperature_page.specified_min_op_temperature);
printf("Estimated offset: %ld\n", intel_temperature_page.estimated_offset);
printf("Estimated offset: %" PRId64 "\n", (int64_t)intel_temperature_page.estimated_offset);
printf("\n");
printf("\n");

View File

@ -909,7 +909,7 @@ opal_dump_info(struct spdk_opal_d0_features_info *feat)
printf("Opal Geometry feature:\n");
printf("Align = %s", (feat->geo.alignment_granularity ? "Y, " : "N, "));
printf("Logical block size = %d, ", from_be32(&feat->geo.logical_block_size));
printf("Lowest aligned LBA = %ld\n", from_be64(&feat->geo.lowest_aligned_lba));
printf("Lowest aligned LBA = %" PRIu64 "\n", from_be64(&feat->geo.lowest_aligned_lba));
printf("\n");
}
@ -1104,8 +1104,8 @@ opal_setup_lockingrange(struct dev *iter)
info = spdk_opal_get_locking_range_info(iter->opal_dev, locking_range_id);
printf("\nlocking range ID: %d\n", info->locking_range_id);
printf("range start: %ld\n", info->range_start);
printf("range length: %ld\n", info->range_length);
printf("range start: %" PRIu64 "\n", info->range_start);
printf("range length: %" PRIu64 "\n", info->range_length);
printf("read lock enabled: %d\n", info->read_lock_enabled);
printf("write lock enabled: %d\n", info->write_lock_enabled);
printf("read locked: %d\n", info->read_locked);
@ -1168,8 +1168,8 @@ opal_list_locking_ranges(struct dev *iter)
printf("locking range ID: %d\t", info->locking_range_id);
if (i == 0) { printf("(Global Range)"); }
printf("\n===============================================\n");
printf("range start: %ld\t", info->range_start);
printf("range length: %ld\n", info->range_length);
printf("range start: %" PRIu64 "\t", info->range_start);
printf("range length: %" PRIu64 "\n", info->range_length);
printf("read lock enabled: %d\t", info->read_lock_enabled);
printf("write lock enabled: %d\t", info->write_lock_enabled);
printf("read locked: %d\t", info->read_locked);