This patch adds netowkr2-detach command to xl.
Usage: xl network2-detach <Domain> <DevId>
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -1748,6 +1748,20 @@ libxl_net2info *libxl_device_net2_list(s
return res;
}
+int libxl_device_net2_del(struct libxl_ctx *ctx, libxl_device_net2 *net2, int
wait)
+{
+ libxl_device device;
+
+ device.backend_devid = net2->devid;
+ device.backend_domid = net2->backend_domid;
+ device.backend_kind = DEVICE_VIF2;
+ device.devid = net2->devid;
+ device.domid = net2->domid;
+ device.kind = DEVICE_VIF2;
+
+ return libxl_device_del(ctx, &device, wait);
+}
+
/******************************************************************************/
int libxl_device_console_add(struct libxl_ctx *ctx, uint32_t domid,
libxl_device_console *console)
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -567,6 +567,7 @@ typedef struct {
int libxl_device_net2_add(struct libxl_ctx *ctx, uint32_t domid,
libxl_device_net2 *net2);
libxl_net2info *libxl_device_net2_list(struct libxl_ctx *ctx, uint32_t domid,
unsigned int *nb);
+int libxl_device_net2_del(struct libxl_ctx *ctx, libxl_device_net2 *net2, int
wait);
#endif /* LIBXL_H */
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -468,6 +468,54 @@ int libxl_devid_to_device_disk(struct li
return 0;
}
+int libxl_devid_to_device_net2(struct libxl_ctx *ctx, uint32_t domid,
+ const char *devid, libxl_device_net2 *net2)
+{
+ char *tok, *endptr, *val;
+ char *dompath, *net2path, *be_path;
+ unsigned int devid_n, i;
+
+ devid_n = strtoul(devid, &endptr, 10);
+ if (devid == endptr) {
+ return ERROR_INVAL;
+ }
+ dompath = libxl_xs_get_dompath(ctx, domid);
+ net2path = libxl_sprintf(ctx, "%s/device/vif2/%s", dompath, devid);
+ if (!net2path) {
+ return ERROR_FAIL;
+ }
+ memset(net2, 0, sizeof (libxl_device_net2));
+ be_path = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/backend",
net2path));
+
+ net2->devid = devid_n;
+ val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/mac", net2path));
+ for (i = 0, tok = strtok(val, ":"); tok && (i < 6);
+ ++i, tok = strtok(NULL, ":")) {
+ net2->front_mac[i] = strtoul(tok, NULL, 16);
+ }
+ val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/remote-mac",
net2path));
+ for (i = 0, tok = strtok(val, ":"); tok && (i < 6);
+ ++i, tok = strtok(NULL, ":")) {
+ net2->back_mac[i] = strtoul(tok, NULL, 16);
+ }
+ val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/backend-id",
net2path));
+ net2->backend_domid = strtoul(val, NULL, 10);
+
+ net2->domid = domid;
+ val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/remote-trusted",
be_path));
+ net2->trusted = strtoul(val, NULL, 10);
+ val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/local-trusted",
be_path));
+ net2->back_trusted = strtoul(val, NULL, 10);
+ val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/filter-mac",
be_path));
+ net2->filter_mac = strtoul(val, NULL, 10);
+ val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/filter-mac",
net2path));
+ net2->front_filter_mac = strtoul(val, NULL, 10);
+ val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/max-bypasses",
be_path));
+ net2->max_bypasses = strtoul(val, NULL, 10);
+
+ return 0;
+}
+
int libxl_strtomac(const char *mac_s, uint8_t *mac)
{
const char *end = mac_s + 17;
diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h
+++ b/tools/libxl/libxl_utils.h
@@ -65,5 +65,8 @@ int libxl_devid_to_device_disk(struct li
int libxl_strtomac(const char *mac_s, uint8_t *mac);
+int libxl_devid_to_device_net2(struct libxl_ctx *ctx, uint32_t domid,
+ const char *devid, libxl_device_net2 *net2);
+
#endif
diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h
--- a/tools/libxl/xl.h
+++ b/tools/libxl/xl.h
@@ -74,6 +74,7 @@ int main_tmem_set(int argc, char **argv)
int main_tmem_shared_auth(int argc, char **argv);
int main_network2attach(int argc, char **argv);
int main_network2list(int argc, char **argv);
+int main_network2detach(int argc, char **argv);
void help(char *command);
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -3914,6 +3914,41 @@ int main_network2list(int argc, char **a
exit(0);
}
+int main_network2detach(int argc, char **argv)
+{
+ int opt;
+ libxl_device_net2 net2;
+
+ if (argc != 4) {
+ help("network2-detach");
+ exit(0);
+ }
+ while ((opt = getopt(argc, argv, "h")) != -1) {
+ switch (opt) {
+ case 'h':
+ help("network2-detach");
+ exit(0);
+ default:
+ fprintf(stderr, "option `%c' not supported.\n", opt);
+ break;
+ }
+ }
+
+ if (domain_qualifier_to_domid(argv[2], &domid, 0) < 0) {
+ fprintf(stderr, "%s is an invalid domain identifier\n", argv[2]);
+ exit(1);
+ }
+ if (libxl_devid_to_device_net2(&ctx, domid, argv[3], &net2)) {
+ fprintf(stderr, "Error: Device %s not connected.\n", argv[3]);
+ exit(1);
+ }
+ if (libxl_device_net2_del(&ctx, &net2, 1)) {
+ fprintf(stderr, "libxl_device_net2_del failed.\n");
+ exit(1);
+ }
+ exit(0);
+}
+
static char *uptime_to_string(unsigned long time, int short_mode)
{
int sec, min, hour, day;
diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c
+++ b/tools/libxl/xl_cmdtable.c
@@ -300,6 +300,11 @@ struct cmd_spec cmd_table[] = {
"list version 2 virtual network interfaces for a domain",
"<Domain(s)>",
},
+ { "network2-detach",
+ &main_network2detach,
+ "destroy a domain's version 2 virtual network device",
+ "<Domain> <DevId>",
+ },
};
int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|