vmd: method for forcing a rescan

Added a new RPC, vmd_rescan, that forces the VMD driver to do a rescan
of all devices behind the VMD.  A device that was previously removed via
spdk_vmd_remove_device() will be found again during vmd_rescan.

Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com>
Change-Id: Ide87eb44c1d6d524234820dc07c78ba5b8bcd3ad
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13958
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Tom Nabarro <tom.nabarro@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Konrad Sztyber 2022-07-05 15:33:35 +02:00 committed by Tomasz Zawadzki
parent 052ea0baac
commit 4cbd23e28b
7 changed files with 95 additions and 0 deletions

View File

@ -10030,6 +10030,40 @@ Example response:
}
~~~
### vmd_rescan {#rpc_vmd_rescan}
Force a rescan of the devices behind VMD.
### Parameters
This method has no parameters.
#### Response
The response is the number of new devices found.
### Example
~~~json
{
"jsonrpc": "2.0",
"method": "vmd_rescan",
"id": 1
}
~~~
Example response:
~~~json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"count": 1
}
}
~~~
### spdk_get_version {#rpc_spdk_get_version}
Get the version info of the running SPDK application.

View File

@ -90,6 +90,14 @@ int spdk_vmd_hotplug_monitor(void);
*/
int spdk_vmd_remove_device(const struct spdk_pci_addr *addr);
/**
* Forces a rescan of the devices behind the VMD. If a device was previously removed through
* spdk_vmd_remove_device() this will cause it to be reattached.
*
* \return number of new devices found during scanning or negative errno on failure.
*/
int spdk_vmd_rescan(void);
#ifdef __cplusplus
}
#endif

View File

@ -9,6 +9,7 @@
spdk_vmd_get_led_state;
spdk_vmd_hotplug_monitor;
spdk_vmd_remove_device;
spdk_vmd_rescan;
local: *;
};

View File

@ -1435,6 +1435,22 @@ spdk_vmd_remove_device(const struct spdk_pci_addr *addr)
return 0;
}
int
spdk_vmd_rescan(void)
{
struct vmd_pci_bus *bus;
uint32_t i;
int rc = 0;
for (i = 0; i < g_vmd_container.count; ++i) {
TAILQ_FOREACH(bus, &g_vmd_container.vmd[i].bus_list, tailq) {
rc += vmd_scan_single_bus(bus, bus->self, true);
}
}
return rc;
}
static int
vmd_attach_device(const struct spdk_pci_addr *addr)
{

View File

@ -69,3 +69,28 @@ out:
free(req.addr);
}
SPDK_RPC_REGISTER("vmd_remove_device", rpc_vmd_remove_device, SPDK_RPC_RUNTIME)
static void
rpc_vmd_rescan(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
{
struct spdk_json_write_ctx *w;
int rc;
if (!vmd_subsystem_is_enabled()) {
spdk_jsonrpc_send_error_response(request, -EPERM, "VMD subsystem is disabled");
return;
}
rc = spdk_vmd_rescan();
if (rc < 0) {
spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
return;
}
w = spdk_jsonrpc_begin_result(request);
spdk_json_write_object_begin(w);
spdk_json_write_named_uint32(w, "count", (uint32_t)rc);
spdk_json_write_object_end(w);
spdk_jsonrpc_end_result(request, w);
}
SPDK_RPC_REGISTER("vmd_rescan", rpc_vmd_rescan, SPDK_RPC_RUNTIME)

View File

@ -10,3 +10,8 @@ def vmd_enable(client):
def vmd_remove_device(client, addr):
"""Remove a device behind VMD"""
return client.call('vmd_remove_device', {'addr': addr})
def vmd_rescan(client):
"""Force a rescan of the devices behind VMD"""
return client.call('vmd_rescan')

View File

@ -2080,6 +2080,12 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
p.add_argument('addr', help='Address of the device to remove', type=str)
p.set_defaults(func=vmd_remove_device)
def vmd_rescan(args):
print_dict(rpc.vmd.vmd_rescan(args.client))
p = subparsers.add_parser('vmd_rescan', help='Force a rescan of the devices behind VMD')
p.set_defaults(func=vmd_rescan)
# nbd
def nbd_start_disk(args):
print(rpc.nbd.nbd_start_disk(args.client,