diff --git a/scripts/python2/virtioforwarder_port_control.py b/scripts/python2/virtioforwarder_port_control.py index 635a485..c45ad27 100755 --- a/scripts/python2/virtioforwarder_port_control.py +++ b/scripts/python2/virtioforwarder_port_control.py @@ -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, diff --git a/scripts/python3/virtioforwarder_port_control.py b/scripts/python3/virtioforwarder_port_control.py index e938055..d950341 100755 --- a/scripts/python3/virtioforwarder_port_control.py +++ b/scripts/python3/virtioforwarder_port_control.py @@ -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, diff --git a/virtio_vhostuser.c b/virtio_vhostuser.c index 50affff..75a926d 100644 --- a/virtio_vhostuser.c +++ b/virtio_vhostuser.c @@ -39,6 +39,7 @@ #include #include #include "virtio_vhostuser.h" +#include "virtioforwarder.pb-c.h" #define __MODULE__ "virtio_vhostuser" #include "log.h" #include "virtio_worker.h" @@ -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) { diff --git a/virtio_vhostuser.h b/virtio_vhostuser.h index 56960e7..4fd7668 100644 --- a/virtio_vhostuser.h +++ b/virtio_vhostuser.h @@ -39,6 +39,8 @@ #include #include +#include "virtioforwarder.pb-c.h" + #define MAX_RELAYS RTE_MAX_ETHPORTS #define MAX_NUM_BOND_SLAVES 8 @@ -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 diff --git a/virtioforwarder.proto b/virtioforwarder.proto index 01e5698..be66396 100644 --- a/virtioforwarder.proto +++ b/virtioforwarder.proto @@ -41,6 +41,7 @@ message PortControlRequest { REMOVE = 1; ADD_SOCK = 2; REMOVE_SOCK = 3; + QUERY_PCI = 4; } required Op op = 1; diff --git a/zmq_port_control.c b/zmq_port_control.c index 393ae8e..b36c6bf 100644 --- a/zmq_port_control.c +++ b/zmq_port_control.c @@ -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; } @@ -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, @@ -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;