Skip to content

Commit

Permalink
Add PCI query port control operation
Browse files Browse the repository at this point in the history
It is useful for upper layer plugging infrastructure to be able to
query the PCI address given the vhost-user socket path of a specific
relay. This commit implements this query operation via the port control
script and the newly added generic response string in the
PortControlResponse message.

Signed-off-by: Heinrich Kuhn <[email protected]>
Signed-off-by: Simon Horman <[email protected]>
  • Loading branch information
Heinrich Kuhn committed Nov 26, 2021
1 parent f014e68 commit 70fc9fc
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 2 deletions.
3 changes: 2 additions & 1 deletion scripts/python2/virtioforwarder_port_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ def _syntax():
parser = argparse.ArgumentParser()
parser.add_argument(
'op', metavar='OP',
choices=('add', 'remove', 'add_sock', 'remove_sock'),
choices=('add', 'remove', 'add_sock', 'remove_sock', 'query_pci'),
help='port control operation',
)
parser.add_argument(
'--vhost-path', type=str,
help='Path to vhostuser socket.'
' Use this option with the add/remove-sock operations'
' or when querying the associated PCI device'
)
parser.add_argument(
'--virtio-id', metavar='virtio-id', type=int,
Expand Down
3 changes: 2 additions & 1 deletion scripts/python3/virtioforwarder_port_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ def _syntax():
parser = argparse.ArgumentParser()
parser.add_argument(
'op', metavar='OP',
choices=('add', 'remove', 'add_sock', 'remove_sock'),
choices=('add', 'remove', 'add_sock', 'remove_sock', 'query_pci'),
help='port control operation',
)
parser.add_argument(
'--vhost-path', type=str,
help='Path to vhostuser socket.'
' Use this option with the add/remove-sock operations'
' or when querying the associated PCI device'
)
parser.add_argument(
'--virtio-id', metavar='virtio-id', type=int,
Expand Down
41 changes: 41 additions & 0 deletions virtio_vhostuser.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <stdbool.h>
#include <bsd/string.h>
#include "virtio_vhostuser.h"
#include "virtioforwarder.pb-c.h"
#define __MODULE__ "virtio_vhostuser"
#include "log.h"
#include "virtio_worker.h"
Expand Down Expand Up @@ -801,6 +802,46 @@ int virtio_add_sock_dev_pair(const char *vhost_path,
return 5;
}

int virtio_query_pci(Virtioforwarder__PortControlResponse *response,
const char *vhost_path)
{
int relay_id = -1;
vio_vf_relay_t *relay;

if (!vhost_path) {
// This should never happen because the zmq logic checks for
// this case too
log_error("vhost path not passed to virtio_query_pci");
return EINVAL;
}

relay_id = get_relay_for_sock(vhost_path);

if (relay_id < 0) {
log_error("Could not find relay associated with %s",
vhost_path);
return ENOENT;
}

log_debug("query PCI for relay number: %d", relay_id);

relay = get_relay_from_id(relay_id);
if (relay == NULL) {
// This shouldn't happen but gaurd against it here anyway
log_error("Could not find relay instance with ID: %d",
relay_id);
return ENOENT;
}

log_debug("Got virtio_query_pci(*response, %s)", vhost_path);

// Just set the query_string pointer to the pci_dbdf pointer in the
// relay struct
response->query_string = relay->dpdk.pci_dbdf;

return 0;
}

int virtio_remove_sock_dev_pair(const char *vhost_path, char *dev,
bool conditional)
{
Expand Down
4 changes: 4 additions & 0 deletions virtio_vhostuser.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include <rte_eal.h>
#include <rte_ethdev.h>

#include "virtioforwarder.pb-c.h"

#define MAX_RELAYS RTE_MAX_ETHPORTS
#define MAX_NUM_BOND_SLAVES 8

Expand Down Expand Up @@ -82,5 +84,7 @@ int virtio_add_sock_dev_pair(const char *vhost_path,
bool conditional);
int virtio_remove_sock_dev_pair(const char *vhost_path, char *dev,
bool conditional);
int virtio_query_pci(Virtioforwarder__PortControlResponse *response,
const char *vhost_path);

#endif // _VIRTIO_VHOSTUSER_THREAD
1 change: 1 addition & 0 deletions virtioforwarder.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ message PortControlRequest {
REMOVE = 1;
ADD_SOCK = 2;
REMOVE_SOCK = 3;
QUERY_PCI = 4;
}

required Op op = 1;
Expand Down
23 changes: 23 additions & 0 deletions zmq_port_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ validate_PortControlRequest(Virtioforwarder__PortControlRequest const *pc)
log_warning("The virtio id will be ignored for socket pair operations.");
}

if (pc->op == VIRTIOFORWARDER__PORT_CONTROL_REQUEST__OP__QUERY_PCI &&
pc->vhost_path == NULL) {
log_error("PCI query requires a vhost-user socket path");
return false;
}

return true;
}

Expand Down Expand Up @@ -204,6 +210,19 @@ port_control_handle_remove_socket(Virtioforwarder__PortControlResponse *response
);
}

static void
port_control_handle_query_pci(Virtioforwarder__PortControlResponse *response,
struct port_control_req_buffer *cfg)
{
printf("In handle_query_pci");
handle_PortControlRequest_set_error_code(
response, "virtio_query_pci()",
virtio_query_pci(
response, cfg->vhost_path
)
);
}

static void
port_control_handle_add(Virtioforwarder__PortControlResponse *response,
struct port_control_req_buffer *cfg,
Expand Down Expand Up @@ -335,6 +354,10 @@ handle_PortControlRequest(
pc->name, conditional);
break;

case VIRTIOFORWARDER__PORT_CONTROL_REQUEST__OP__QUERY_PCI:
port_control_handle_query_pci(&response, &b);
break;

default:
log_critical("unhandled PortControlRequest.Op %i", pc->op);
break;
Expand Down

0 comments on commit 70fc9fc

Please sign in to comment.