Skip to content

Commit

Permalink
vhost-user: add VHOST_USER_GET_QUEUE_NUM message
Browse files Browse the repository at this point in the history
This is for querying how many queues the backend supports if it has mq
support(when VHOST_USER_PROTOCOL_F_MQ flag is set from the quried
protocol features).

vhost_net_get_max_queues() is the interface to export that value, and
to tell if the backend supports # of queues user requested, which is
done in the following patch.

Signed-off-by: Yuanhan Liu <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Yuanhan Liu <[email protected]>
Tested-by: Marcel Apfelbaum <[email protected]>
  • Loading branch information
Yuanhan Liu authored and mstsirkin committed Sep 24, 2015
1 parent d1f8b30 commit e2051e9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docs/specs/vhost-user.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,14 @@ Message types
Bits (0-7) of the payload contain the vring index. Bit 8 is the
invalid FD flag. This flag is set when there is no file descriptor
in the ancillary data.

* VHOST_USER_GET_QUEUE_NUM

Id: 17
Equivalent ioctl: N/A
Master payload: N/A
Slave payload: u64

Query how many queues the backend supports. This request should be
sent only when VHOST_USER_PROTOCOL_F_MQ is set in quried protocol
features by VHOST_USER_GET_PROTOCOL_FEATURES.
12 changes: 12 additions & 0 deletions hw/net/vhost_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ void vhost_net_ack_features(struct vhost_net *net, uint64_t features)
vhost_ack_features(&net->dev, vhost_net_get_feature_bits(net), features);
}

uint64_t vhost_net_get_max_queues(VHostNetState *net)
{
return net->dev.max_queues;
}

static int vhost_net_get_fd(NetClientState *backend)
{
switch (backend->info->type) {
Expand All @@ -144,6 +149,8 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
goto fail;
}

net->dev.max_queues = 1;

if (backend_kernel) {
r = vhost_net_get_fd(options->net_backend);
if (r < 0) {
Expand Down Expand Up @@ -414,6 +421,11 @@ VHostNetState *get_vhost_net(NetClientState *nc)
return vhost_net;
}
#else
uint64_t vhost_net_get_max_queues(VHostNetState *net)
{
return 1;
}

struct vhost_net *vhost_net_init(VhostNetOptions *options)
{
error_report("vhost-net support is not compiled in");
Expand Down
15 changes: 14 additions & 1 deletion hw/virtio/vhost-user.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

#define VHOST_MEMORY_MAX_NREGIONS 8
#define VHOST_USER_F_PROTOCOL_FEATURES 30
#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x0ULL
#define VHOST_USER_PROTOCOL_FEATURE_MASK 0x1ULL

#define VHOST_USER_PROTOCOL_F_MQ 0

typedef enum VhostUserRequest {
VHOST_USER_NONE = 0,
Expand All @@ -45,6 +47,7 @@ typedef enum VhostUserRequest {
VHOST_USER_SET_VRING_ERR = 14,
VHOST_USER_GET_PROTOCOL_FEATURES = 15,
VHOST_USER_SET_PROTOCOL_FEATURES = 16,
VHOST_USER_GET_QUEUE_NUM = 17,
VHOST_USER_MAX
} VhostUserRequest;

Expand Down Expand Up @@ -211,6 +214,7 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,
switch (msg_request) {
case VHOST_USER_GET_FEATURES:
case VHOST_USER_GET_PROTOCOL_FEATURES:
case VHOST_USER_GET_QUEUE_NUM:
need_reply = 1;
break;

Expand Down Expand Up @@ -315,6 +319,7 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,
switch (msg_request) {
case VHOST_USER_GET_FEATURES:
case VHOST_USER_GET_PROTOCOL_FEATURES:
case VHOST_USER_GET_QUEUE_NUM:
if (msg.size != sizeof(m.u64)) {
error_report("Received bad msg size.");
return -1;
Expand Down Expand Up @@ -366,6 +371,14 @@ static int vhost_user_init(struct vhost_dev *dev, void *opaque)
if (err < 0) {
return err;
}

/* query the max queues we support if backend supports Multiple Queue */
if (dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_MQ)) {
err = vhost_user_call(dev, VHOST_USER_GET_QUEUE_NUM, &dev->max_queues);
if (err < 0) {
return err;
}
}
}

return 0;
Expand Down
1 change: 1 addition & 0 deletions include/hw/virtio/vhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct vhost_dev {
unsigned long long acked_features;
unsigned long long backend_features;
unsigned long long protocol_features;
unsigned long long max_queues;
bool started;
bool log_enabled;
unsigned long long log_size;
Expand Down
1 change: 1 addition & 0 deletions include/net/vhost_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ typedef struct VhostNetOptions {
void *opaque;
} VhostNetOptions;

uint64_t vhost_net_get_max_queues(VHostNetState *net);
struct vhost_net *vhost_net_init(VhostNetOptions *options);

int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, int total_queues);
Expand Down

0 comments on commit e2051e9

Please sign in to comment.