Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vdev: log failed requests in vhost_handle_msg, log features in vhost_get_features, vhost_set_features #13

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion vdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,9 @@ static int vhost_get_features(struct vhd_vdev *vdev, const void *payload,
vdev->supported_features = g_default_features |
vdev->type->get_features(vdev);

VHD_OBJ_INFO(vdev, "GET_FEATURES: reply with supported_features 0x%" PRIx64,
vdev->supported_features);

return vhost_reply_u64(vdev, vdev->supported_features);
}

Expand Down Expand Up @@ -791,6 +794,8 @@ static int vhost_set_features(struct vhd_vdev *vdev, const void *payload,
uint64_t supported_features = vdev->supported_features;
uint64_t changed_features;

VHD_OBJ_INFO(vdev, "SET_FEATURES: features 0x%" PRIx64, *features);

if (num_fds || size < sizeof(*features)) {
VHD_OBJ_ERROR(vdev, "malformed message size=%zu #fds=%zu", size,
num_fds);
Expand Down Expand Up @@ -1750,17 +1755,46 @@ static int (*vhost_msg_handlers[])(struct vhd_vdev *vdev,
[VHOST_USER_SET_VRING_ENABLE] = vhost_vring_enable,
};

static inline void log_vhost_request_failed(struct vhd_vdev *vdev, uint32_t req,
const void *payload, size_t size,
int ret)
{
#define CHARS_PER_BYTE 3 // hex number + space
#define MAX_BYTES_TO_DUMP 100
char payload_hex[CHARS_PER_BYTE * MAX_BYTES_TO_DUMP + 1];
size_t payload_bytes_to_dump;

payload_bytes_to_dump = MIN(MAX_BYTES_TO_DUMP, size);

for (size_t i = 0; i < payload_bytes_to_dump; ++i) {
sprintf(payload_hex + CHARS_PER_BYTE * i, "%02X ", ((char*)payload)[i]);
}
payload_hex[CHARS_PER_BYTE * payload_bytes_to_dump] = '\0';
#undef MAX_BYTES_TO_DUMP
#undef CHARS_PER_BYTE

VHD_OBJ_ERROR(vdev, "%s (%u) request failed: %s, request payload (%zu bytes): %s",
vhost_req_name(req), req, strerror(-ret), size, payload_hex);
}

static int vhost_handle_msg(struct vhd_vdev *vdev, uint32_t req,
const void *payload, size_t size,
const int *fds, size_t num_fds)
{
int ret;

if (req >= sizeof(vhost_msg_handlers) / sizeof(vhost_msg_handlers[0]) ||
!vhost_msg_handlers[req]) {
VHD_OBJ_WARN(vdev, "%s (%u) not supported", vhost_req_name(req), req);
return -ENOTSUP;
}

return vhost_msg_handlers[req](vdev, payload, size, fds, num_fds);
ret = vhost_msg_handlers[req](vdev, payload, size, fds, num_fds);
if (ret < 0) {
log_vhost_request_failed(vdev, req, payload, size, ret);
}

return ret;
}

struct vdev_work {
Expand Down