From fbd3431424a5a7c3b2a36968df4e4a0cb9ff384c Mon Sep 17 00:00:00 2001 From: Sandeep Dhavale Date: Mon, 11 Nov 2024 15:53:58 -0800 Subject: [PATCH] libublksrv: fix eventfd write so we always write 8-bytes eventfd expects 8-bytes unsigned integer (uint64_t) for read/writes. Instead of using native data types which can have different sizes on 32-bit platforms, use uint64_t to make this explicit throughout. Signed-off-by: Sandeep Dhavale --- lib/ublksrv.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/ublksrv.c b/lib/ublksrv.c index 2b2adc65..cb65401b 100644 --- a/lib/ublksrv.c +++ b/lib/ublksrv.c @@ -238,7 +238,7 @@ int ublksrv_queue_handled_event(const struct ublksrv_queue *tq) struct _ublksrv_queue *q = tq_to_local(tq); if (q->efd >= 0) { - unsigned long long data; + uint64_t data; const int cnt = sizeof(uint64_t); /* read has to be done, otherwise poll event won't be stopped */ @@ -267,7 +267,7 @@ int ublksrv_queue_send_event(const struct ublksrv_queue *tq) struct _ublksrv_queue *q = tq_to_local(tq); if (q->efd >= 0) { - unsigned long long data = 1; + uint64_t data = 1; const int cnt = sizeof(uint64_t); if (write(q->efd, &data, cnt) != cnt) { @@ -412,13 +412,13 @@ static void ublksrv_set_sched_affinity(struct _ublksrv_dev *dev, static void ublksrv_kill_eventfd(struct _ublksrv_queue *q) { if ((q->state & UBLKSRV_QUEUE_STOPPING) && q->efd >= 0) { - unsigned long long data = 1; + uint64_t data = 1; int ret; - ret = write(q->efd, &data, 8); - if (ret != 8) - ublk_err("%s:%d write fail %d/%d\n", - __func__, __LINE__, ret, 8); + ret = write(q->efd, &data, sizeof(uint64_t)); + if (ret != sizeof(uint64_t)) + ublk_err("%s:%d write fail %d/%zu\n", + __func__, __LINE__, ret, sizeof(uint64_t)); } } @@ -899,13 +899,13 @@ static void ublksrv_submit_aio_batch(struct _ublksrv_queue *q) for (i = 0; i < q->nr_ctxs; i++) { struct ublksrv_aio_ctx *ctx = q->ctxs[i]; - unsigned long data = 1; + uint64_t data = 1; int ret; - ret = write(ctx->efd, &data, 8); - if (ret != 8) - ublk_err("%s:%d write fail %d/%d\n", - __func__, __LINE__, ret, 8); + ret = write(ctx->efd, &data, sizeof(uint64_t)); + if (ret != sizeof(uint64_t)) + ublk_err("%s:%d write fail ctx[%d]: %d/%zu\n", + __func__, __LINE__, i, ret, sizeof(uint64_t)); } }