Commit 4cbd23e2 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

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: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: Ide87eb44c1d6d524234820dc07c78ba5b8bcd3ad
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13958


Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarTom Nabarro <tom.nabarro@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 052ea0ba
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -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.
+8 −0
Original line number Diff line number Diff line
@@ -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
+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
	spdk_vmd_get_led_state;
	spdk_vmd_hotplug_monitor;
	spdk_vmd_remove_device;
	spdk_vmd_rescan;

	local: *;
};
+16 −0
Original line number Diff line number Diff line
@@ -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)
{
+25 −0
Original line number Diff line number Diff line
@@ -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)
Loading