Commit b8c99a3a authored by Nick Connolly's avatar Nick Connolly Committed by Tomasz Zawadzki
Browse files

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

Explicitly test for not __linux__ where that is the intent, rather
than testing for __FreeBSD__.

Cast pointer to uintptr_t before aligning it, rather than using
a specific integer size which may not be large enough to store a
pointer.

Signed-off-by: default avatarNick Connolly <nick.connolly@mayadata.io>
Change-Id: Icfe219e1bbb2d06b3ef05710fac5b7091d340251
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5142


Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent bb19c18f
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -181,7 +181,7 @@ bs_allocate_cluster(struct spdk_blob *blob, uint32_t cluster_num,
		}
	}

	SPDK_DEBUGLOG(blob, "Claiming cluster %lu for blob %lu\n", *cluster, blob->id);
	SPDK_DEBUGLOG(blob, "Claiming cluster %" PRIu64 " for blob %" PRIu64 "\n", *cluster, blob->id);

	if (update_map) {
		blob_insert_cluster(blob, cluster_num, *cluster);
@@ -782,7 +782,7 @@ blob_parse(const struct spdk_blob_md_page *pages, uint32_t page_count,
	 * happen for example if a bogus blobid is passed in through open.
	 */
	if (blob->id != pages[0].id) {
		SPDK_ERRLOG("Blobid (%lu) doesn't match what's in metadata (%lu)\n",
		SPDK_ERRLOG("Blobid (%" PRIu64 ") doesn't match what's in metadata (%" PRIu64 ")\n",
			    blob->id, pages[0].id);
		return -ENOENT;
	}
@@ -1422,7 +1422,7 @@ blob_load_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserrno)
	}

	if (bserrno) {
		SPDK_ERRLOG("Metadata page %d read failed for blobid %lu: %d\n",
		SPDK_ERRLOG("Metadata page %d read failed for blobid %" PRIu64 ": %d\n",
			    current_page, blob->id, bserrno);
		blob_load_final(ctx, bserrno);
		return;
@@ -1431,7 +1431,7 @@ blob_load_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserrno)
	page = &ctx->pages[ctx->num_pages - 1];
	crc = blob_md_page_calc_crc(page);
	if (crc != page->crc) {
		SPDK_ERRLOG("Metadata page %d crc mismatch for blobid %lu\n",
		SPDK_ERRLOG("Metadata page %d crc mismatch for blobid %" PRIu64 "\n",
			    current_page, blob->id);
		blob_load_final(ctx, -EINVAL);
		return;
@@ -2048,7 +2048,7 @@ blob_persist_generate_new_md(struct spdk_blob_persist_ctx *ctx)
		ctx->pages[i - 1].crc = blob_md_page_calc_crc(&ctx->pages[i - 1]);
		blob->active.pages[i] = page_num;
		bs_claim_md_page(bs, page_num);
		SPDK_DEBUGLOG(blob, "Claiming page %u for blob %lu\n", page_num, blob->id);
		SPDK_DEBUGLOG(blob, "Claiming page %u for blob %" PRIu64 "\n", page_num, blob->id);
		page_num++;
	}
	ctx->pages[i - 1].crc = blob_md_page_calc_crc(&ctx->pages[i - 1]);
@@ -4222,7 +4222,7 @@ bs_load_super_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserrno)
	}

	if (ctx->super->size > ctx->bs->dev->blockcnt * ctx->bs->dev->blocklen) {
		SPDK_NOTICELOG("Size mismatch, dev size: %lu, blobstore size: %lu\n",
		SPDK_NOTICELOG("Size mismatch, dev size: %" PRIu64 ", blobstore size: %" PRIu64 "\n",
			       ctx->bs->dev->blockcnt * ctx->bs->dev->blocklen, ctx->super->size);
		bs_load_ctx_fail(ctx, -EILSEQ);
		return;
@@ -5256,7 +5256,7 @@ bs_create_blob(struct spdk_blob_store *bs,

	id = bs_page_to_blobid(page_idx);

	SPDK_DEBUGLOG(blob, "Creating blob with id %lu at page %u\n", id, page_idx);
	SPDK_DEBUGLOG(blob, "Creating blob with id %" PRIu64 " at page %u\n", id, page_idx);

	blob = blob_alloc(bs, id);
	if (!blob) {
@@ -5673,7 +5673,7 @@ bs_snapshot_origblob_open_cpl(void *cb_arg, struct spdk_blob *_blob, int bserrno
	ctx->original.blob = _blob;

	if (_blob->data_ro || _blob->md_ro) {
		SPDK_DEBUGLOG(blob, "Cannot create snapshot from read only blob with id %lu\n",
		SPDK_DEBUGLOG(blob, "Cannot create snapshot from read only blob with id %" PRIu64 "\n",
			      _blob->id);
		ctx->bserrno = -EINVAL;
		spdk_blob_close(_blob, bs_clone_snapshot_cleanup_finish, ctx);
@@ -6104,7 +6104,7 @@ spdk_blob_resize(struct spdk_blob *blob, uint64_t sz, spdk_blob_op_complete cb_f

	blob_verify_md_op(blob);

	SPDK_DEBUGLOG(blob, "Resizing blob %lu to %lu clusters\n", blob->id, sz);
	SPDK_DEBUGLOG(blob, "Resizing blob %" PRIu64 " to %" PRIu64 " clusters\n", blob->id, sz);

	if (blob->md_ro) {
		cb_fn(cb_arg, -EPERM);
@@ -6631,7 +6631,7 @@ spdk_bs_delete_blob(struct spdk_blob_store *bs, spdk_blob_id blobid,
	struct spdk_bs_cpl	cpl;
	spdk_bs_sequence_t	*seq;

	SPDK_DEBUGLOG(blob, "Deleting blob %lu\n", blobid);
	SPDK_DEBUGLOG(blob, "Deleting blob %" PRIu64 "\n", blobid);

	assert(spdk_get_thread() == bs->md_thread);

@@ -6695,7 +6695,7 @@ bs_open_blob(struct spdk_blob_store *bs,
	spdk_bs_sequence_t		*seq;
	uint32_t			page_num;

	SPDK_DEBUGLOG(blob, "Opening blob %lu\n", blobid);
	SPDK_DEBUGLOG(blob, "Opening blob %" PRIu64 "\n", blobid);
	assert(spdk_get_thread() == bs->md_thread);

	page_num = bs_blobid_to_page(blobid);
@@ -6805,7 +6805,7 @@ spdk_blob_sync_md(struct spdk_blob *blob, spdk_blob_op_complete cb_fn, void *cb_
{
	blob_verify_md_op(blob);

	SPDK_DEBUGLOG(blob, "Syncing blob %lu\n", blob->id);
	SPDK_DEBUGLOG(blob, "Syncing blob %" PRIu64 "\n", blob->id);

	if (blob->md_ro) {
		assert(blob->state == SPDK_BLOB_STATE_CLEAN);
@@ -6994,7 +6994,7 @@ void spdk_blob_close(struct spdk_blob *blob, spdk_blob_op_complete cb_fn, void *

	blob_verify_md_op(blob);

	SPDK_DEBUGLOG(blob, "Closing blob %lu\n", blob->id);
	SPDK_DEBUGLOG(blob, "Closing blob %" PRIu64 "\n", blob->id);

	if (blob->open_ref == 0) {
		cb_fn(cb_arg, -EBADF);
@@ -7173,7 +7173,7 @@ blob_set_xattr(struct spdk_blob *blob, const char *name, const void *value,

	desc_size = sizeof(struct spdk_blob_md_descriptor_xattr) + strlen(name) + value_len;
	if (desc_size > SPDK_BS_MAX_DESC_SIZE) {
		SPDK_DEBUGLOG(blob, "Xattr '%s' of size %ld does not fix into single page %ld\n", name,
		SPDK_DEBUGLOG(blob, "Xattr '%s' of size %zu does not fix into single page %zu\n", name,
			      desc_size, SPDK_BS_MAX_DESC_SIZE);
		return -ENOMEM;
	}
+1 −1
Original line number Diff line number Diff line
@@ -438,7 +438,7 @@ spdk_ring_dequeue(struct spdk_ring *ring, void **objs, size_t count)
void
spdk_env_dpdk_dump_mem_stats(FILE *file)
{
	fprintf(file, "DPDK memory size %lu\n", rte_eal_get_physmem_size());
	fprintf(file, "DPDK memory size %" PRIu64 "\n", rte_eal_get_physmem_size());
	fprintf(file, "DPDK memory layout\n");
	rte_dump_physmem_layout(file);
	fprintf(file, "DPDK memzones.\n");
+3 −3
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@
#include "spdk/env_dpdk.h"
#include "spdk/log.h"

#ifdef __FreeBSD__
#ifndef __linux__
#define VFIO_ENABLED 0
#else
#include <linux/version.h>
@@ -605,13 +605,13 @@ spdk_mem_map_set_translation(struct spdk_mem_map *map, uint64_t vaddr, uint64_t
	struct map_2mb *map_2mb;

	if ((uintptr_t)vaddr & ~MASK_256TB) {
		DEBUG_PRINT("invalid usermode virtual address %lu\n", vaddr);
		DEBUG_PRINT("invalid usermode virtual address %" PRIu64 "\n", vaddr);
		return -EINVAL;
	}

	/* For now, only 2 MB-aligned registrations are supported */
	if (((uintptr_t)vaddr & MASK_2MB) || (size & MASK_2MB)) {
		DEBUG_PRINT("invalid %s parameters, vaddr=%lu len=%ju\n",
		DEBUG_PRINT("invalid %s parameters, vaddr=%" PRIu64 " len=%" PRIu64 "\n",
			    __func__, vaddr, size);
		return -EINVAL;
	}
+1 −1
Original line number Diff line number Diff line
@@ -1299,7 +1299,7 @@ iscsi_conn_handle_nop(struct spdk_iscsi_conn *conn)
	if (conn->nop_outstanding) {
		if ((tsc - conn->last_nopin) > conn->timeout) {
			SPDK_ERRLOG("Timed out waiting for NOP-Out response from initiator\n");
			SPDK_ERRLOG("  tsc=0x%lx, last_nopin=0x%lx\n", tsc, conn->last_nopin);
			SPDK_ERRLOG("  tsc=0x%" PRIx64 ", last_nopin=0x%" PRIx64 "\n", tsc, conn->last_nopin);
			SPDK_ERRLOG("  initiator=%s, target=%s\n", conn->initiator_name,
				    conn->target_short_name);
			conn->state = ISCSI_CONN_STATE_EXITING;
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ mobj_ctor(struct spdk_mempool *mp, __attribute__((unused)) void *arg,

	m->mp = mp;
	m->buf = (uint8_t *)m + sizeof(struct spdk_mobj);
	m->buf = (void *)((unsigned long)((uint8_t *)m->buf + ISCSI_DATA_BUFFER_ALIGNMENT) &
	m->buf = (void *)((uintptr_t)((uint8_t *)m->buf + ISCSI_DATA_BUFFER_ALIGNMENT) &
			  ~ISCSI_DATA_BUFFER_MASK);
}

Loading