# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1318941402 -3600
# Node ID 11ae241660f62c85dba0d6f7d8f85197f748e47a
# Parent 7357a4c2c0113afb971a074f4b21b5c67eb5140b
libxl: convert NIC handling to device API
Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Acked-by: Ian Jackson <ian.jackson.citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
---
diff -r 7357a4c2c011 -r 11ae241660f6 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Tue Oct 18 13:36:42 2011 +0100
+++ b/tools/libxl/libxl.c Tue Oct 18 13:36:42 2011 +0100
@@ -1187,32 +1187,46 @@
}
/******************************************************************************/
-int libxl_device_nic_init(libxl_device_nic *nic_info, int devnum)
+int libxl_device_nic_init(libxl_ctx *ctx, libxl_device_nic *nic)
{
const uint8_t *r;
libxl_uuid uuid;
libxl_uuid_generate(&uuid);
r = libxl_uuid_bytearray(&uuid);
- memset(nic_info, '\0', sizeof(*nic_info));
-
- nic_info->backend_domid = 0;
- nic_info->devid = devnum;
- nic_info->mtu = 1492;
- nic_info->model = strdup("rtl8139");
- nic_info->mac[0] = 0x00;
- nic_info->mac[1] = 0x16;
- nic_info->mac[2] = 0x3e;
- nic_info->mac[3] = r[0] & 0x7f;
- nic_info->mac[4] = r[1];
- nic_info->mac[5] = r[2];
- nic_info->ifname = NULL;
- nic_info->bridge = strdup("xenbr0");
- nic_info->ip = NULL;
- if ( asprintf(&nic_info->script, "%s/vif-bridge",
+ memset(nic, '\0', sizeof(*nic));
+
+ nic->backend_domid = 0;
+ nic->devid = -1;
+ nic->mtu = 1492;
+ nic->model = strdup("rtl8139");
+ nic->mac[0] = 0x00;
+ nic->mac[1] = 0x16;
+ nic->mac[2] = 0x3e;
+ nic->mac[3] = r[0] & 0x7f;
+ nic->mac[4] = r[1];
+ nic->mac[5] = r[2];
+ nic->ifname = NULL;
+ nic->bridge = strdup("xenbr0");
+ nic->ip = NULL;
+ if ( asprintf(&nic->script, "%s/vif-bridge",
libxl_xen_script_dir_path()) < 0 )
return ERROR_FAIL;
- nic_info->nictype = LIBXL_NIC_TYPE_IOEMU;
+ nic->nictype = LIBXL_NIC_TYPE_IOEMU;
+ return 0;
+}
+
+static int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,
+ libxl_device_nic *nic,
+ libxl__device *device)
+{
+ device->backend_devid = nic->devid;
+ device->backend_domid = nic->backend_domid;
+ device->backend_kind = LIBXL__DEVICE_KIND_VIF;
+ device->devid = nic->devid;
+ device->domid = domid;
+ device->kind = LIBXL__DEVICE_KIND_VIF;
+
return 0;
}
@@ -1249,12 +1263,8 @@
}
}
- device.backend_devid = nic->devid;
- device.backend_domid = nic->backend_domid;
- device.backend_kind = LIBXL__DEVICE_KIND_VIF;
- device.devid = nic->devid;
- device.domid = domid;
- device.kind = LIBXL__DEVICE_KIND_VIF;
+ rc = libxl__device_from_nic(&gc, domid, nic, &device);
+ if ( rc != 0 ) goto out_free;
flexarray_append(back, "frontend-id");
flexarray_append(back, libxl__sprintf(&gc, "%d", domid));
@@ -1305,29 +1315,37 @@
return rc;
}
-int libxl_device_nic_del(libxl_ctx *ctx, uint32_t domid,
- libxl_device_nic *nic, int wait)
+int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid,
+ libxl_device_nic *nic)
{
libxl__gc gc = LIBXL_INIT_GC(ctx);
libxl__device device;
int rc;
- device.backend_devid = nic->devid;
- device.backend_domid = nic->backend_domid;
- device.backend_kind = LIBXL__DEVICE_KIND_VIF;
- device.devid = nic->devid;
- device.domid = domid;
- device.kind = LIBXL__DEVICE_KIND_VIF;
-
- if (wait)
- rc = libxl__device_remove(&gc, &device, wait);
- else
- rc = libxl__device_destroy(&gc, &device);
-
+ rc = libxl__device_from_nic(&gc, domid, nic, &device);
+ if (rc != 0) goto out;
+
+ rc = libxl__device_remove(&gc, &device, 1);
+out:
libxl__free_all(&gc);
return rc;
}
+int libxl_device_nic_destroy(libxl_ctx *ctx, uint32_t domid,
+ libxl_device_nic *nic)
+{
+ libxl__gc gc = LIBXL_INIT_GC(ctx);
+ libxl__device device;
+ int rc;
+
+ rc = libxl__device_from_nic(&gc, domid, nic, &device);
+ if (rc != 0) goto out;
+
+ rc = libxl__device_destroy(&gc, &device);
+out:
+ libxl__free_all(&gc);
+ return rc;
+}
static void libxl__device_nic_from_xs_be(libxl__gc *gc,
const char *be_path,
libxl_device_nic *nic)
diff -r 7357a4c2c011 -r 11ae241660f6 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h Tue Oct 18 13:36:42 2011 +0100
+++ b/tools/libxl/libxl.h Tue Oct 18 13:36:42 2011 +0100
@@ -463,9 +463,12 @@
char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk);
int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk);
-int libxl_device_nic_init(libxl_device_nic *nic, int dev_num);
+/* Network Interfaces */
+int libxl_device_nic_init(libxl_ctx *ctx, libxl_device_nic *nic);
int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic
*nic);
-int libxl_device_nic_del(libxl_ctx *ctx, uint32_t domid, libxl_device_nic
*nic, int wait);
+int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_nic
*nic);
+int libxl_device_nic_destroy(libxl_ctx *ctx, uint32_t domid, libxl_device_nic
*nic);
+
libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx, uint32_t domid, int
*num);
int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid,
libxl_device_nic *nic, libxl_nicinfo *nicinfo);
diff -r 7357a4c2c011 -r 11ae241660f6 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Tue Oct 18 13:36:42 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c Tue Oct 18 13:36:42 2011 +0100
@@ -762,7 +762,8 @@
d_config->vifs = (libxl_device_nic *) realloc(d_config->vifs,
sizeof (libxl_device_nic) * (d_config->num_vifs+1));
nic = d_config->vifs + d_config->num_vifs;
- CHK_ERRNO( libxl_device_nic_init(nic, d_config->num_vifs) );
+ CHK_ERRNO( libxl_device_nic_init(ctx, nic) );
+ nic->devid = d_config->num_vifs;
if (default_vifscript) {
free(nic->script);
@@ -3972,7 +3973,7 @@
fprintf(stderr, "%s is an invalid domain identifier\n", argv[optind]);
return 1;
}
- libxl_device_nic_init(&nic, -1);
+ libxl_device_nic_init(ctx, &nic);
for (argv += optind+1, argc -= optind+1; argc > 0; ++argv, --argc) {
if (MATCH_OPTION("type", *argv, oparg)) {
if (!strcmp("vif", oparg)) {
@@ -4089,7 +4090,7 @@
return 1;
}
}
- if (libxl_device_nic_del(ctx, domid, &nic, 1)) {
+ if (libxl_device_nic_remove(ctx, domid, &nic)) {
fprintf(stderr, "libxl_device_nic_del failed.\n");
return 1;
}
diff -r 7357a4c2c011 -r 11ae241660f6 tools/ocaml/libs/xl/genwrap.py
--- a/tools/ocaml/libs/xl/genwrap.py Tue Oct 18 13:36:42 2011 +0100
+++ b/tools/ocaml/libs/xl/genwrap.py Tue Oct 18 13:36:42 2011 +0100
@@ -33,9 +33,7 @@
"device_console": [ ("add", ["t", "domid", "unit"]),
],
"device_disk": DEVICE_FUNCTIONS,
- "device_nic": [ ("add", ["t", "domid", "unit"]),
- ("del", ["t", "domid", "unit"]),
- ],
+ "device_nic": DEVICE_FUNCTIONS,
"device_pci": [ ("add", ["t", "domid", "unit"]),
("remove", ["t", "domid", "unit"]),
("shutdown", ["domid", "unit"]),
diff -r 7357a4c2c011 -r 11ae241660f6 tools/ocaml/libs/xl/xenlight_stubs.c
--- a/tools/ocaml/libs/xl/xenlight_stubs.c Tue Oct 18 13:36:42 2011 +0100
+++ b/tools/ocaml/libs/xl/xenlight_stubs.c Tue Oct 18 13:36:42 2011 +0100
@@ -281,7 +281,7 @@
device_nic_val(&gc, &lg, &c_info, info);
INIT_CTX();
- ret = libxl_device_nic_del(ctx, Int_val(domid), &c_info, 0);
+ ret = libxl_device_nic_remove(ctx, Int_val(domid), &c_info);
if (ret != 0)
failwith_xl("nic_del", &lg);
FREE_CTX();
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|