when virtual machine is destroyed. Signed-off-by: Quan Xu <quan...@intel.com> --- tools/libxl/libxl_device.c | 61 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-)
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index b1a71fe..668bf71 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -660,10 +660,11 @@ void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs) { STATE_AO_GC(drs->ao); uint32_t domid = drs->domid; - char *path; - unsigned int num_kinds, num_dev_xsentries; - char **kinds = NULL, **devs = NULL; - int i, j, rc = 0; + char *path, *dom_name, *name; + unsigned int num_kinds, num_fkinds, num_dev_xsentries, num_dev; + char **kinds = NULL, **fkinds = NULL, **devs = NULL, **sdevs = NULL, + **be_doms = NULL; + int i, j, k, rc = 0; libxl__device *dev; libxl__multidev *multidev = &drs->multidev; libxl__ao_device *aodev; @@ -731,6 +732,58 @@ void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs) libxl__device_destroy(gc, dev); } + /* + * Frontend device, such as vTPM, is under: + * /local/domain/0/frontend/{type}/{backend_dom_id}/{dev} + */ + path = GCSPRINTF("/local/domain/%d/frontend", 0); + fkinds = libxl__xs_directory(gc, XBT_NULL, path, &num_fkinds); + if (!fkinds) { + if (errno != ENOENT) { + LOGE(ERROR, "unable to get xenstore device listing %s", path); + goto out; + } + num_fkinds = 0; + } + + name = libxl_domid_to_name(CTX, domid); + + /* /local/domain/0/frontend/{type} */ + for (i = 0; i < num_fkinds; i++) { + if (libxl__device_kind_from_string(fkinds[i], &kind)) + continue; + + path = GCSPRINTF("/local/domain/0/frontend/%s", fkinds[i]); + be_doms = libxl__xs_directory(gc, XBT_NULL, path, &num_dev_xsentries); + if (!be_doms) + continue; + + /* /local/domain/0/frontend/{type}/{backend_dom_id} */ + for (j = 0; j < num_dev_xsentries; j++) { + path = GCSPRINTF("/local/domain/0/frontend/%s/%d", + fkinds[i], atoi(be_doms[j])); + sdevs = libxl__xs_directory(gc, XBT_NULL, path, &num_dev); + + /* /local/domain/0/frontend/{type}/{backend_dom_id}/{dev} */ + for (k = 0; k < num_dev; k++) { + path = GCSPRINTF("/local/domain/0/frontend/%s/%d/%d/domain", + fkinds[i], atoi(be_doms[j]), atoi(sdevs[k])); + dom_name = libxl__xs_read(gc, XBT_NULL, path); + if (strcmp(name, dom_name)) { + continue; + } + + path = GCSPRINTF("/local/domain/0/frontend/%s/%d/%d/backend", + fkinds[i], atoi(be_doms[j]), atoi(sdevs[k])); + path = libxl__xs_read(gc, XBT_NULL, path); + GCNEW(dev); + if (path && strcmp(path, "") && + libxl__parse_backend_path(gc, path, dev) == 0) + libxl__device_destroy(gc, dev); + } + } + } + out: libxl__multidev_prepared(egc, multidev, rc); } -- 1.8.3.2 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel