[Devel] [PATCH VZ9 2/7] drivers/vhost/blk: better log errors in vhost-blk

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Mon Jun 15 13:45:31 MSK 2026


pr_debug() is too specific. Let's use pr_warn_ratelimited() so we
get better exposure

https://virtuozzo.atlassian.net/browse/VSTOR-134034
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 drivers/vhost/blk.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
index e4236df2f2161..7e33a4f30165d 100644
--- a/drivers/vhost/blk.c
+++ b/drivers/vhost/blk.c
@@ -51,6 +51,14 @@ enum {
 
 #define NR_INLINE 16
 
+#define vhostblk_vq_err(blk, vq, fmt, ...) do {				\
+		pr_warn_ratelimited(KBUILD_MODNAME "(%d) : " fmt,	\
+				    blk->owner_pid, ##__VA_ARGS__);	\
+		if ((vq)->error_ctx)					\
+			eventfd_signal((vq)->error_ctx);		\
+	} while (0)
+
+
 struct vhost_blk_req {
 	struct bio *inline_bio[NR_INLINE];
 	int req_bin;
@@ -94,6 +102,7 @@ struct vhost_blk {
 	int new_req_bin;
 	struct file *backend;
 	char serial[VIRTIO_BLK_ID_BYTES];
+	pid_t owner_pid;
 };
 
 static int gen;
@@ -133,7 +142,7 @@ static inline int vhost_blk_set_status(struct vhost_blk_req *req, u8 status)
 	iov_iter_init(&iter, ITER_DEST, req->status, ARRAY_SIZE(req->status), sizeof(status));
 	ret = copy_to_iter(&status, sizeof(status), &iter);
 	if (ret != sizeof(status)) {
-		vq_err(&req->blk_vq->vq, "Failed to write status\n");
+		vhostblk_vq_err(req->blk, &req->blk_vq->vq, "Failed to write status\n");
 		return -EFAULT;
 	}
 
@@ -481,7 +490,7 @@ static int vhost_blk_req_handle(struct vhost_virtqueue *vq,
 		vhost_add_used_and_signal(&blk->dev, vq, head, len);
 		break;
 	default:
-		vq_err(vq, "Unsupported request type %d\n", hdr->type);
+		vhostblk_vq_err(blk, vq, "Unsupported request type %d\n", hdr->type);
 		status = VIRTIO_BLK_S_UNSUPP;
 		ret = vhost_blk_set_status(req, status);
 		if (ret)
@@ -530,7 +539,7 @@ static void vhost_blk_handle_guest_kick(struct vhost_work *work)
 
 		ret = move_iovec(vq->iov, hdr_iovec, sizeof(hdr), in + out, ARRAY_SIZE(hdr_iovec));
 		if (ret < 0) {
-			vq_err(vq, "virtio_blk_hdr is too split!");
+			vhostblk_vq_err(blk, vq, "virtio_blk_hdr (head %d) is too split!", head);
 			vhost_discard_vq_desc(vq, 1);
 			break;
 		}
@@ -538,8 +547,8 @@ static void vhost_blk_handle_guest_kick(struct vhost_work *work)
 		iov_iter_init(&iter, ITER_SOURCE, hdr_iovec, ARRAY_SIZE(hdr_iovec), sizeof(hdr));
 		ret = copy_from_iter(&hdr, sizeof(hdr), &iter);
 		if (ret != sizeof(hdr)) {
-			vq_err(vq, "Failed to get block header: read %d bytes instead of %ld!\n",
-			       ret, sizeof(hdr));
+			vhostblk_vq_err(blk, vq, "Failed to get read header (head %d): got %d, expected %ld!\n",
+					head, ret, sizeof(hdr));
 			vhost_discard_vq_desc(vq, 1);
 			break;
 		}
@@ -671,6 +680,7 @@ static int vhost_blk_open(struct inode *inode, struct file *file)
 	blk->new_req_bin = 0;
 	spin_lock_init(&blk->flush_lock);
 	init_waitqueue_head(&blk->flush_wait);
+	blk->owner_pid = current->pid;
 
 	vhost_dev_init(&blk->dev, vqs, VHOST_BLK_VQ_MAX, UIO_MAXIOV,
 		       VHOST_DEV_WEIGHT, VHOST_DEV_PKT_WEIGHT, true, NULL);
-- 
2.43.5



More information about the Devel mailing list