Ian Campbell
2011-Mar-24 14:10 UTC
[Xen-devel] [PATCH] libxl: drop domid field from libxl_device_*
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1300975785 0 # Node ID ca75b204dca4339dcdca4124bd010abe6604f616 # Parent fff89897e9c20b78cd73ce544c93bbc44b528f25 libxl: drop domid field from libxl_device_* All functions which add a device to a domain already take a domid argument and the callers typically write the same value to the structure right before making the call. Functions which delete a device typically do not but adding this field makes the interface more consistent anyway and all callers have the domid to hand. All functions which return a libxl device structure are given a domid as a paramter and the caller therefore already knows which domain it is dealing with. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r fff89897e9c2 -r ca75b204dca4 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Thu Mar 24 14:09:43 2011 +0000 +++ b/tools/libxl/libxl.c Thu Mar 24 14:09:45 2011 +0000 @@ -701,7 +701,6 @@ int libxl_event_get_disk_eject_info(libx disk->backend = LIBXL_DISK_BACKEND_UNKNOWN; } - disk->domid = domid; disk->pdev_path = strdup(""); disk->format = LIBXL_DISK_FORMAT_EMPTY; /* this value is returned to the user: do not free right away */ @@ -976,7 +975,7 @@ int libxl_device_disk_add(libxl_ctx *ctx device.backend_devid = devid; device.backend_domid = disk->backend_domid; device.devid = devid; - device.domid = disk->domid; + device.domid = domid; device.kind = DEVICE_VBD; switch (disk->backend) { @@ -1030,7 +1029,7 @@ int libxl_device_disk_add(libxl_ctx *ctx } flexarray_append(back, "frontend-id"); - flexarray_append(back, libxl__sprintf(&gc, "%d", disk->domid)); + flexarray_append(back, libxl__sprintf(&gc, "%d", domid)); flexarray_append(back, "online"); flexarray_append(back, "1"); flexarray_append(back, "removable"); @@ -1074,7 +1073,7 @@ out: return rc; } -int libxl_device_disk_del(libxl_ctx *ctx, +int libxl_device_disk_del(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, int wait) { libxl__gc gc = LIBXL_INIT_GC(ctx); @@ -1086,7 +1085,7 @@ int libxl_device_disk_del(libxl_ctx *ctx device.backend_devid = devid; device.backend_kind (disk->backend == LIBXL_DISK_BACKEND_PHY) ? DEVICE_VBD : DEVICE_TAP; - device.domid = disk->domid; + device.domid = domid; device.devid = devid; device.kind = DEVICE_VBD; rc = libxl__device_del(&gc, &device, wait); @@ -1186,7 +1185,6 @@ int libxl_device_nic_init(libxl_device_n memset(nic_info, ''\0'', sizeof(*nic_info)); nic_info->backend_domid = 0; - nic_info->domid = 0; nic_info->devid = devnum; nic_info->mtu = 1492; nic_info->model = strdup("rtl8139"); @@ -1243,11 +1241,11 @@ int libxl_device_nic_add(libxl_ctx *ctx, device.backend_domid = nic->backend_domid; device.backend_kind = DEVICE_VIF; device.devid = nic->devid; - device.domid = nic->domid; + device.domid = domid; device.kind = DEVICE_VIF; flexarray_append(back, "frontend-id"); - flexarray_append(back, libxl__sprintf(&gc, "%d", nic->domid)); + flexarray_append(back, libxl__sprintf(&gc, "%d", domid)); flexarray_append(back, "online"); flexarray_append(back, "1"); flexarray_append(back, "state"); @@ -1302,7 +1300,7 @@ out: return rc; } -int libxl_device_nic_del(libxl_ctx *ctx, +int libxl_device_nic_del(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic, int wait) { libxl__gc gc = LIBXL_INIT_GC(ctx); @@ -1313,7 +1311,7 @@ int libxl_device_nic_del(libxl_ctx *ctx, device.backend_domid = nic->backend_domid; device.backend_kind = DEVICE_VIF; device.devid = nic->devid; - device.domid = nic->domid; + device.domid = domid; device.kind = DEVICE_VIF; rc = libxl__device_del(&gc, &device, wait); @@ -1445,13 +1443,13 @@ int libxl_device_net2_add(libxl_ctx *ctx device.backend_domid = net2->backend_domid; device.backend_kind = DEVICE_VIF2; device.devid = net2->devid; - device.domid = net2->domid; + device.domid = domid; device.kind = DEVICE_VIF2; flexarray_append(back, "domain"); flexarray_append(back, dom); flexarray_append(back, "frontend-id"); - flexarray_append(back, libxl__sprintf(&gc, "%d", net2->domid)); + flexarray_append(back, libxl__sprintf(&gc, "%d", domid)); flexarray_append(back, "local-trusted"); flexarray_append(back, libxl__sprintf(&gc, "%d", net2->back_trusted)); @@ -1579,7 +1577,7 @@ err: return NULL; } -int libxl_device_net2_del(libxl_ctx *ctx, libxl_device_net2 *net2, int wait) +int libxl_device_net2_del(libxl_ctx *ctx, uint32_t domid, libxl_device_net2 *net2, int wait) { libxl__gc gc = LIBXL_INIT_GC(ctx); libxl__device device; @@ -1589,7 +1587,7 @@ int libxl_device_net2_del(libxl_ctx *ctx device.backend_domid = net2->backend_domid; device.backend_kind = DEVICE_VIF2; device.devid = net2->devid; - device.domid = net2->domid; + device.domid = domid; device.kind = DEVICE_VIF2; rc = libxl__device_del(&gc, &device, wait); @@ -1622,11 +1620,11 @@ int libxl_device_console_add(libxl_ctx * device.backend_domid = console->backend_domid; device.backend_kind = DEVICE_CONSOLE; device.devid = console->devid; - device.domid = console->domid; + device.domid = domid; device.kind = DEVICE_CONSOLE; flexarray_append(back, "frontend-id"); - flexarray_append(back, libxl__sprintf(&gc, "%d", console->domid)); + flexarray_append(back, libxl__sprintf(&gc, "%d", domid)); flexarray_append(back, "online"); flexarray_append(back, "1"); flexarray_append(back, "state"); @@ -1706,11 +1704,11 @@ int libxl_device_vkb_add(libxl_ctx *ctx, device.backend_domid = vkb->backend_domid; device.backend_kind = DEVICE_VKBD; device.devid = vkb->devid; - device.domid = vkb->domid; + device.domid = domid; device.kind = DEVICE_VKBD; flexarray_append(back, "frontend-id"); - flexarray_append(back, libxl__sprintf(&gc, "%d", vkb->domid)); + flexarray_append(back, libxl__sprintf(&gc, "%d", domid)); flexarray_append(back, "online"); flexarray_append(back, "1"); flexarray_append(back, "state"); @@ -1768,7 +1766,6 @@ static unsigned int libxl__append_disk_l pdisk_end = *disks + *ndisks; for (; pdisk < pdisk_end; pdisk++, dir++) { pdisk->backend_domid = 0; - pdisk->domid = domid; physpath_tmp = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(gc, "%s/%s/params", be_path, *dir), &len); if (physpath_tmp && strchr(physpath_tmp, '':'')) { pdisk->pdev_path = strdup(strchr(physpath_tmp, '':'') + 1); @@ -1866,15 +1863,12 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u ret = 0; - libxl_device_disk_del(ctx, disks + i, 1); + libxl_device_disk_del(ctx, domid, disks + i, 1); libxl_device_disk_add(ctx, domid, disk); stubdomid = libxl_get_stubdom_id(ctx, domid); if (stubdomid) { - disks[i].domid = stubdomid; - libxl_device_disk_del(ctx, disks + i, 1); - disk->domid = stubdomid; + libxl_device_disk_del(ctx, stubdomid, disks + i, 1); libxl_device_disk_add(ctx, stubdomid, disk); - disk->domid = domid; } out: for (i = 0; i < num; i++) @@ -1923,10 +1917,10 @@ int libxl_device_vfb_add(libxl_ctx *ctx, device.backend_domid = vfb->backend_domid; device.backend_kind = DEVICE_VFB; device.devid = vfb->devid; - device.domid = vfb->domid; + device.domid = domid; device.kind = DEVICE_VFB; - flexarray_append_pair(back, "frontend-id", libxl__sprintf(&gc, "%d", vfb->domid)); + flexarray_append_pair(back, "frontend-id", libxl__sprintf(&gc, "%d", domid)); flexarray_append_pair(back, "online", "1"); flexarray_append_pair(back, "state", libxl__sprintf(&gc, "%d", 1)); flexarray_append_pair(back, "domain", libxl__domid_to_name(&gc, domid)); diff -r fff89897e9c2 -r ca75b204dca4 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Thu Mar 24 14:09:43 2011 +0000 +++ b/tools/libxl/libxl.h Thu Mar 24 14:09:45 2011 +0000 @@ -360,7 +360,7 @@ libxl_vminfo * libxl_list_vm(libxl_ctx * libxl_vminfo * libxl_list_vm(libxl_ctx *ctx, int *nb_vm); int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk); -int libxl_device_disk_del(libxl_ctx *ctx, libxl_device_disk *disk, int wait); +int libxl_device_disk_del(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, int wait); libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *num); int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, libxl_diskinfo *diskinfo); @@ -374,7 +374,7 @@ int libxl_device_disk_local_detach(libxl int libxl_device_nic_init(libxl_device_nic *nic, int dev_num); int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic); -int libxl_device_nic_del(libxl_ctx *ctx, libxl_device_nic *nic, int wait); +int libxl_device_nic_del(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic, int wait); libxl_nicinfo *libxl_list_nics(libxl_ctx *ctx, uint32_t domid, unsigned int *nb); int libxl_device_console_add(libxl_ctx *ctx, uint32_t domid, libxl_device_console *console); @@ -482,7 +482,7 @@ int libxl_device_net2_add(libxl_ctx *ctx libxl_device_net2 *net2); libxl_net2info *libxl_device_net2_list(libxl_ctx *ctx, uint32_t domid, unsigned int *nb); -int libxl_device_net2_del(libxl_ctx *ctx, libxl_device_net2 *net2, +int libxl_device_net2_del(libxl_ctx *ctx, uint32_t domid, libxl_device_net2 *net2, int wait); int libxl_get_freecpus(libxl_ctx *ctx, libxl_cpumap *cpumap); diff -r fff89897e9c2 -r ca75b204dca4 tools/libxl/libxl.idl --- a/tools/libxl/libxl.idl Thu Mar 24 14:09:43 2011 +0000 +++ b/tools/libxl/libxl.idl Thu Mar 24 14:09:45 2011 +0000 @@ -228,7 +228,6 @@ Network is missing""") libxl_device_vfb = Struct("device_vfb", [ ("backend_domid", uint32), - ("domid", uint32), ("devid", integer), ("vnc", bool, False, "vnc enabled or disabled"), ("vnclisten", string, False, "address:port that should be listened on for the VNC server if vnc is set"), @@ -244,13 +243,11 @@ libxl_device_vfb = Struct("device_vfb", libxl_device_vkb = Struct("device_vkb", [ ("backend_domid", uint32), - ("domid", domid), ("devid", integer), ]) libxl_device_console = Struct("device_console", [ ("backend_domid", uint32), - ("domid", domid), ("devid", integer), ("consback", libxl_console_backend), ("build_state", Reference(libxl_domain_build_state), True), @@ -259,7 +256,6 @@ libxl_device_console = Struct("device_co libxl_device_disk = Struct("device_disk", [ ("backend_domid", uint32), - ("domid", domid), ("pdev_path", string), ("vdev", string), ("backend", libxl_disk_backend), @@ -271,7 +267,6 @@ libxl_device_disk = Struct("device_disk" libxl_device_nic = Struct("device_nic", [ ("backend_domid", uint32), - ("domid", domid), ("devid", integer), ("mtu", integer), ("model", string), @@ -288,7 +283,6 @@ libxl_device_net2 = Struct("device_net2" ("front_mac", libxl_mac), ("back_mac", libxl_mac), ("backend_domid", uint32), - ("domid", domid), ("trusted", BitField(uint32, 1)), ("back_trusted", BitField(uint32, 1)), ("filter_mac", BitField(uint32, 1)), diff -r fff89897e9c2 -r ca75b204dca4 tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Thu Mar 24 14:09:43 2011 +0000 +++ b/tools/libxl/libxl_create.c Thu Mar 24 14:09:45 2011 +0000 @@ -446,7 +446,6 @@ static int do_domain_create(libxl__gc *g } for (i = 0; i < d_config->num_disks; i++) { - d_config->disks[i].domid = domid; ret = libxl_device_disk_add(ctx, domid, &d_config->disks[i]); if (ret) { fprintf(stderr, "cannot add disk %d to domain: %d\n", i, ret); @@ -455,7 +454,6 @@ static int do_domain_create(libxl__gc *g } } for (i = 0; i < d_config->num_vifs; i++) { - d_config->vifs[i].domid = domid; ret = libxl_device_nic_add(ctx, domid, &d_config->vifs[i]); if (ret) { fprintf(stderr, "cannot add nic %d to domain: %d\n", i, ret); @@ -465,7 +463,6 @@ static int do_domain_create(libxl__gc *g } if (!d_config->c_info.hvm) { for (i = 0; i < d_config->num_vif2s; i++) { - d_config->vif2s[i].domid = domid; ret = libxl_device_net2_add(ctx, domid, &d_config->vif2s[i]); if (ret) { fprintf(stderr, "cannot add net2 %d to domain: %d\n", i, ret); @@ -480,7 +477,6 @@ static int do_domain_create(libxl__gc *g ret = init_console_info(&console, 0, &state); if ( ret ) goto error_out; - console.domid = domid; libxl_device_console_add(ctx, domid, &console); libxl_device_console_destroy(&console); @@ -499,16 +495,13 @@ static int do_domain_create(libxl__gc *g libxl_device_console console; for (i = 0; i < d_config->num_vfbs; i++) { - d_config->vfbs[i].domid = domid; libxl_device_vfb_add(ctx, domid, &d_config->vfbs[i]); - d_config->vkbs[i].domid = domid; libxl_device_vkb_add(ctx, domid, &d_config->vkbs[i]); } ret = init_console_info(&console, 0, &state); if ( ret ) goto error_out; - console.domid = domid; need_qemu = libxl__need_xenpv_qemu(gc, 1, &console, d_config->num_vfbs, d_config->vfbs, diff -r fff89897e9c2 -r ca75b204dca4 tools/libxl/libxl_dm.c --- a/tools/libxl/libxl_dm.c Thu Mar 24 14:09:43 2011 +0000 +++ b/tools/libxl/libxl_dm.c Thu Mar 24 14:09:45 2011 +0000 @@ -532,22 +532,18 @@ retry_transaction: goto retry_transaction; for (i = 0; i < num_disks; i++) { - disks[i].domid = domid; ret = libxl_device_disk_add(ctx, domid, &disks[i]); if (ret) goto out_free; } for (i = 0; i < num_vifs; i++) { - vifs[i].domid = domid; ret = libxl_device_nic_add(ctx, domid, &vifs[i]); if (ret) goto out_free; } - vfb->domid = domid; ret = libxl_device_vfb_add(ctx, domid, vfb); if (ret) goto out_free; - vkb->domid = domid; ret = libxl_device_vkb_add(ctx, domid, vkb); if (ret) goto out_free; @@ -564,7 +560,6 @@ retry_transaction: for (i = 0; i < num_console; i++) { console[i].devid = i; console[i].consback = LIBXL_CONSOLE_BACKEND_IOEMU; - console[i].domid = domid; /* STUBDOM_CONSOLE_LOGGING (console 0) is for minios logging * STUBDOM_CONSOLE_SAVE (console 1) is for writing the save file * STUBDOM_CONSOLE_RESTORE (console 2) is for reading the save file diff -r fff89897e9c2 -r ca75b204dca4 tools/libxl/libxl_utils.c --- a/tools/libxl/libxl_utils.c Thu Mar 24 14:09:43 2011 +0000 +++ b/tools/libxl/libxl_utils.c Thu Mar 24 14:09:45 2011 +0000 @@ -476,7 +476,6 @@ int libxl_mac_to_device_nic(libxl_ctx *c ; if ((b >= mac_n + 6) && (*a == *b)) { nic->backend_domid = nics[i].backend_id; - nic->domid = nics[i].frontend_id; nic->devid = nics[i].devid; memcpy(nic->mac, nics[i].mac, sizeof (nic->mac)); nic->script = strdup(nics[i].script); @@ -551,7 +550,6 @@ int libxl_devid_to_device_disk(libxl_ctx if (!val) goto out; disk->backend_domid = strtoul(val, NULL, 10); - disk->domid = domid; be_path = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/backend", diskpath)); disk->pdev_path = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/params", be_path)); val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/type", be_path)); @@ -606,7 +604,6 @@ int libxl_devid_to_device_net2(libxl_ctx val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/backend-id", net2path)); net2->backend_domid = strtoul(val, NULL, 10); - net2->domid = domid; val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/remote-trusted", be_path)); net2->trusted = strtoul(val, NULL, 10); val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/local-trusted", be_path)); diff -r fff89897e9c2 -r ca75b204dca4 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Thu Mar 24 14:09:43 2011 +0000 +++ b/tools/libxl/xl_cmdimpl.c Thu Mar 24 14:09:45 2011 +0000 @@ -379,7 +379,7 @@ static void printf_info(int domid, printf("\t(device\n"); printf("\t\t(tap\n"); printf("\t\t\t(backend_domid %d)\n", d_config->disks[i].backend_domid); - printf("\t\t\t(domid %d)\n", d_config->disks[i].domid); + printf("\t\t\t(domid %d)\n", domid); printf("\t\t\t(physpath %s)\n", d_config->disks[i].pdev_path); printf("\t\t\t(phystype %d)\n", d_config->disks[i].backend); printf("\t\t\t(virtpath %s)\n", d_config->disks[i].vdev); @@ -394,7 +394,7 @@ static void printf_info(int domid, printf("\t(device\n"); printf("\t\t(vif\n"); printf("\t\t\t(backend_domid %d)\n", d_config->vifs[i].backend_domid); - printf("\t\t\t(domid %d)\n", d_config->vifs[i].domid); + printf("\t\t\t(domid %d)\n", domid); printf("\t\t\t(devid %d)\n", d_config->vifs[i].devid); printf("\t\t\t(mtu %d)\n", d_config->vifs[i].mtu); printf("\t\t\t(model %s)\n", d_config->vifs[i].model); @@ -424,7 +424,7 @@ static void printf_info(int domid, printf("\t(device\n"); printf("\t\t(vfb\n"); printf("\t\t\t(backend_domid %d)\n", d_config->vfbs[i].backend_domid); - printf("\t\t\t(domid %d)\n", d_config->vfbs[i].domid); + printf("\t\t\t(domid %d)\n", domid); printf("\t\t\t(devid %d)\n", d_config->vfbs[i].devid); printf("\t\t\t(vnc %d)\n", d_config->vfbs[i].vnc); printf("\t\t\t(vnclisten %s)\n", d_config->vfbs[i].vnclisten); @@ -1885,7 +1885,6 @@ static void cd_insert(const char *dom, c return; } disk.backend_domid = 0; - disk.domid = domid; libxl_cdrom_insert(ctx, domid, &disk); free(buf); @@ -4300,7 +4299,6 @@ int main_networkattach(int argc, char ** return 1; } } - nic.domid = domid; if (libxl_device_nic_add(ctx, domid, &nic)) { fprintf(stderr, "libxl_device_nic_add failed.\n"); return 1; @@ -4395,7 +4393,7 @@ int main_networkdetach(int argc, char ** return 1; } } - if (libxl_device_nic_del(ctx, &nic, 1)) { + if (libxl_device_nic_del(ctx, domid, &nic, 1)) { fprintf(stderr, "libxl_device_nic_del failed.\n"); return 1; } @@ -4470,7 +4468,6 @@ int main_blockattach(int argc, char **ar return 1; } } - disk.domid = fe_domid; disk.backend_domid = be_domid; if (libxl_device_disk_add(ctx, fe_domid, &disk)) { @@ -4555,7 +4552,7 @@ int main_blockdetach(int argc, char **ar fprintf(stderr, "Error: Device %s not connected.\n", argv[optind+1]); return 1; } - if (libxl_device_disk_del(ctx, &disk, 1)) { + if (libxl_device_disk_del(ctx, domid, &disk, 1)) { fprintf(stderr, "libxl_device_disk_del failed.\n"); } return 0; @@ -4650,7 +4647,6 @@ int main_network2attach(int argc, char * return 1; } } - net2.domid = domid; net2.backend_domid = back_domid; if (libxl_device_net2_add(ctx, domid, &net2)) { fprintf(stderr, "libxl_device_net2_add failed.\n"); @@ -4731,7 +4727,7 @@ int main_network2detach(int argc, char * fprintf(stderr, "Error: Device %s not connected.\n", argv[optind+1]); return 1; } - if (libxl_device_net2_del(ctx, &net2, 1)) { + if (libxl_device_net2_del(ctx, domid, &net2, 1)) { fprintf(stderr, "libxl_device_net2_del failed.\n"); return 1; } diff -r fff89897e9c2 -r ca75b204dca4 tools/ocaml/libs/xl/xl_stubs.c --- a/tools/ocaml/libs/xl/xl_stubs.c Thu Mar 24 14:09:43 2011 +0000 +++ b/tools/ocaml/libs/xl/xl_stubs.c Thu Mar 24 14:09:45 2011 +0000 @@ -353,7 +353,6 @@ value stub_xl_disk_add(value info, value INIT_STRUCT(); device_disk_val(&gc, &c_info, info); - c_info.domid = Int_val(domid); INIT_CTX(); ret = libxl_device_disk_add(ctx, Int_val(domid), &c_info); @@ -371,10 +370,9 @@ value stub_xl_disk_remove(value info, va INIT_STRUCT(); device_disk_val(&gc, &c_info, info); - c_info.domid = Int_val(domid); INIT_CTX(); - ret = libxl_device_disk_del(ctx, &c_info, 0); + ret = libxl_device_disk_del(ctx, Int_val(domid), &c_info, 0); if (ret != 0) failwith_xl("disk_remove", &lg); FREE_CTX(); @@ -389,7 +387,6 @@ value stub_xl_nic_add(value info, value INIT_STRUCT(); device_nic_val(&gc, &c_info, info); - c_info.domid = Int_val(domid); INIT_CTX(); ret = libxl_device_nic_add(ctx, Int_val(domid), &c_info); @@ -407,10 +404,9 @@ value stub_xl_nic_remove(value info, val INIT_STRUCT(); device_nic_val(&gc, &c_info, info); - c_info.domid = Int_val(domid); INIT_CTX(); - ret = libxl_device_nic_del(ctx, &c_info, 0); + ret = libxl_device_nic_del(ctx, Int_val(domid), &c_info, 0); if (ret != 0) failwith_xl("nic_remove", &lg); FREE_CTX(); @@ -427,7 +423,6 @@ value stub_xl_console_add(value info, va device_console_val(&gc, &c_info, info); domain_build_state_val(&gc, &c_state, state); - c_info.domid = Int_val(domid); c_info.build_state = &c_state; INIT_CTX(); @@ -446,7 +441,6 @@ value stub_xl_vkb_add(value info, value INIT_STRUCT(); device_vkb_val(&gc, &c_info, info); - c_info.domid = Int_val(domid); INIT_CTX(); ret = libxl_device_vkb_add(ctx, Int_val(domid), &c_info); @@ -495,7 +489,6 @@ value stub_xl_vfb_add(value info, value INIT_STRUCT(); device_vfb_val(&gc, &c_info, info); - c_info.domid = Int_val(domid); INIT_CTX(); ret = libxl_device_vfb_add(ctx, Int_val(domid), &c_info); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Jackson
2011-Mar-31 18:06 UTC
Re: [Xen-devel] [PATCH] libxl: drop domid field from libxl_device_*
Ian Campbell writes ("[Xen-devel] [PATCH] libxl: drop domid field from libxl_device_*"):> libxl: drop domid field from libxl_device_*I''d love to apply this but it gets lots of rejects from my current tip (23116:7f894a4cf702). Also how backward-incompatible is it ? Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2011-Apr-01 10:29 UTC
Re: [Xen-devel] [PATCH] libxl: drop domid field from libxl_device_*
On Thu, 2011-03-31 at 19:06 +0100, Ian Jackson wrote:> Ian Campbell writes ("[Xen-devel] [PATCH] libxl: drop domid field from libxl_device_*"): > > libxl: drop domid field from libxl_device_* > > I''d love to apply this but it gets lots of rejects from my current tip > (23116:7f894a4cf702).I''ll repost once I''ve rebased.> Also how backward-incompatible is it ?It''s API incompatible I guess but somewhat easy to fix since you can just drop the initialiser in the caller since libxl always just overwrote it anyway, IOW by dropping the initialiser you become compatible with libxl both before and after this change. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2011-Apr-07 08:12 UTC
[Xen-devel] [PATCH] libxl: drop domid field from libxl_device_*
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1302161755 -3600 # Node ID 3a1f9a001a107cd210fbf1c81e70eacc7577f987 # Parent 9c05f7fa1edd8c013b5fb2666b2706eae0dc4341 libxl: drop domid field from libxl_device_* All functions which add a device to a domain already take a domid argument and the callers typically write the same value to the structure right before making the call. Functions which delete a device typically do not but adding this field makes the interface more consistent anyway and all callers have the domid to hand. All functions which return a libxl device structure are given a domid as a paramter and the caller therefore already knows which domain it is dealing with. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 9c05f7fa1edd -r 3a1f9a001a10 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Thu Apr 07 08:35:51 2011 +0100 +++ b/tools/libxl/libxl.c Thu Apr 07 08:35:55 2011 +0100 @@ -702,7 +702,6 @@ int libxl_event_get_disk_eject_info(libx disk->backend = DISK_BACKEND_UNKNOWN; } - disk->domid = domid; disk->pdev_path = strdup(""); disk->format = DISK_FORMAT_EMPTY; /* this value is returned to the user: do not free right away */ @@ -977,7 +976,7 @@ int libxl_device_disk_add(libxl_ctx *ctx device.backend_devid = devid; device.backend_domid = disk->backend_domid; device.devid = devid; - device.domid = disk->domid; + device.domid = domid; device.kind = DEVICE_VBD; switch (disk->backend) { @@ -1031,7 +1030,7 @@ int libxl_device_disk_add(libxl_ctx *ctx } flexarray_append(back, "frontend-id"); - flexarray_append(back, libxl__sprintf(&gc, "%d", disk->domid)); + flexarray_append(back, libxl__sprintf(&gc, "%d", domid)); flexarray_append(back, "online"); flexarray_append(back, "1"); flexarray_append(back, "removable"); @@ -1075,7 +1074,7 @@ out: return rc; } -int libxl_device_disk_del(libxl_ctx *ctx, +int libxl_device_disk_del(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, int wait) { libxl__gc gc = LIBXL_INIT_GC(ctx); @@ -1087,7 +1086,7 @@ int libxl_device_disk_del(libxl_ctx *ctx device.backend_devid = devid; device.backend_kind (disk->backend == DISK_BACKEND_PHY) ? DEVICE_VBD : DEVICE_TAP; - device.domid = disk->domid; + device.domid = domid; device.devid = devid; device.kind = DEVICE_VBD; rc = libxl__device_del(&gc, &device, wait); @@ -1187,7 +1186,6 @@ int libxl_device_nic_init(libxl_device_n memset(nic_info, ''\0'', sizeof(*nic_info)); nic_info->backend_domid = 0; - nic_info->domid = 0; nic_info->devid = devnum; nic_info->mtu = 1492; nic_info->model = strdup("rtl8139"); @@ -1244,11 +1242,11 @@ int libxl_device_nic_add(libxl_ctx *ctx, device.backend_domid = nic->backend_domid; device.backend_kind = DEVICE_VIF; device.devid = nic->devid; - device.domid = nic->domid; + device.domid = domid; device.kind = DEVICE_VIF; flexarray_append(back, "frontend-id"); - flexarray_append(back, libxl__sprintf(&gc, "%d", nic->domid)); + flexarray_append(back, libxl__sprintf(&gc, "%d", domid)); flexarray_append(back, "online"); flexarray_append(back, "1"); flexarray_append(back, "state"); @@ -1303,7 +1301,7 @@ out: return rc; } -int libxl_device_nic_del(libxl_ctx *ctx, +int libxl_device_nic_del(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic, int wait) { libxl__gc gc = LIBXL_INIT_GC(ctx); @@ -1314,7 +1312,7 @@ int libxl_device_nic_del(libxl_ctx *ctx, device.backend_domid = nic->backend_domid; device.backend_kind = DEVICE_VIF; device.devid = nic->devid; - device.domid = nic->domid; + device.domid = domid; device.kind = DEVICE_VIF; rc = libxl__device_del(&gc, &device, wait); @@ -1402,11 +1400,11 @@ int libxl_device_console_add(libxl_ctx * device.backend_domid = console->backend_domid; device.backend_kind = DEVICE_CONSOLE; device.devid = console->devid; - device.domid = console->domid; + device.domid = domid; device.kind = DEVICE_CONSOLE; flexarray_append(back, "frontend-id"); - flexarray_append(back, libxl__sprintf(&gc, "%d", console->domid)); + flexarray_append(back, libxl__sprintf(&gc, "%d", domid)); flexarray_append(back, "online"); flexarray_append(back, "1"); flexarray_append(back, "state"); @@ -1486,11 +1484,11 @@ int libxl_device_vkb_add(libxl_ctx *ctx, device.backend_domid = vkb->backend_domid; device.backend_kind = DEVICE_VKBD; device.devid = vkb->devid; - device.domid = vkb->domid; + device.domid = domid; device.kind = DEVICE_VKBD; flexarray_append(back, "frontend-id"); - flexarray_append(back, libxl__sprintf(&gc, "%d", vkb->domid)); + flexarray_append(back, libxl__sprintf(&gc, "%d", domid)); flexarray_append(back, "online"); flexarray_append(back, "1"); flexarray_append(back, "state"); @@ -1548,7 +1546,6 @@ static unsigned int libxl__append_disk_l pdisk_end = *disks + *ndisks; for (; pdisk < pdisk_end; pdisk++, dir++) { pdisk->backend_domid = 0; - pdisk->domid = domid; physpath_tmp = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(gc, "%s/%s/params", be_path, *dir), &len); if (physpath_tmp && strchr(physpath_tmp, '':'')) { pdisk->pdev_path = strdup(strchr(physpath_tmp, '':'') + 1); @@ -1647,15 +1644,12 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u ret = 0; - libxl_device_disk_del(ctx, disks + i, 1); + libxl_device_disk_del(ctx, domid, disks + i, 1); libxl_device_disk_add(ctx, domid, disk); stubdomid = libxl_get_stubdom_id(ctx, domid); if (stubdomid) { - disks[i].domid = stubdomid; - libxl_device_disk_del(ctx, disks + i, 1); - disk->domid = stubdomid; + libxl_device_disk_del(ctx, stubdomid, disks + i, 1); libxl_device_disk_add(ctx, stubdomid, disk); - disk->domid = domid; } out: for (i = 0; i < num; i++) @@ -1704,10 +1698,10 @@ int libxl_device_vfb_add(libxl_ctx *ctx, device.backend_domid = vfb->backend_domid; device.backend_kind = DEVICE_VFB; device.devid = vfb->devid; - device.domid = vfb->domid; + device.domid = domid; device.kind = DEVICE_VFB; - flexarray_append_pair(back, "frontend-id", libxl__sprintf(&gc, "%d", vfb->domid)); + flexarray_append_pair(back, "frontend-id", libxl__sprintf(&gc, "%d", domid)); flexarray_append_pair(back, "online", "1"); flexarray_append_pair(back, "state", libxl__sprintf(&gc, "%d", 1)); flexarray_append_pair(back, "domain", libxl__domid_to_name(&gc, domid)); diff -r 9c05f7fa1edd -r 3a1f9a001a10 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Thu Apr 07 08:35:51 2011 +0100 +++ b/tools/libxl/libxl.h Thu Apr 07 08:35:55 2011 +0100 @@ -412,7 +412,7 @@ libxl_cpupoolinfo * libxl_list_cpupool(l libxl_vminfo * libxl_list_vm(libxl_ctx *ctx, int *nb_vm); int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk); -int libxl_device_disk_del(libxl_ctx *ctx, libxl_device_disk *disk, int wait); +int libxl_device_disk_del(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, int wait); libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *num); int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, libxl_diskinfo *diskinfo); @@ -426,7 +426,7 @@ int libxl_device_disk_local_detach(libxl int libxl_device_nic_init(libxl_device_nic *nic, int dev_num); int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic); -int libxl_device_nic_del(libxl_ctx *ctx, libxl_device_nic *nic, int wait); +int libxl_device_nic_del(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic, int wait); libxl_nicinfo *libxl_list_nics(libxl_ctx *ctx, uint32_t domid, unsigned int *nb); int libxl_device_console_add(libxl_ctx *ctx, uint32_t domid, libxl_device_console *console); diff -r 9c05f7fa1edd -r 3a1f9a001a10 tools/libxl/libxl.idl --- a/tools/libxl/libxl.idl Thu Apr 07 08:35:51 2011 +0100 +++ b/tools/libxl/libxl.idl Thu Apr 07 08:35:55 2011 +0100 @@ -173,7 +173,6 @@ Network is missing""") libxl_device_vfb = Struct("device_vfb", [ ("backend_domid", uint32), - ("domid", uint32), ("devid", integer), ("vnc", bool, False, "vnc enabled or disabled"), ("vnclisten", string, False, "address:port that should be listened on for the VNC server if vnc is set"), @@ -189,13 +188,11 @@ libxl_device_vfb = Struct("device_vfb", libxl_device_vkb = Struct("device_vkb", [ ("backend_domid", uint32), - ("domid", domid), ("devid", integer), ]) libxl_device_console = Struct("device_console", [ ("backend_domid", uint32), - ("domid", domid), ("devid", integer), ("consback", libxl_console_consback), ("build_state", Reference(libxl_domain_build_state), True), @@ -204,7 +201,6 @@ libxl_device_console = Struct("device_co libxl_device_disk = Struct("device_disk", [ ("backend_domid", uint32), - ("domid", domid), ("pdev_path", string), ("vdev", string), ("backend", libxl_disk_backend), @@ -216,7 +212,6 @@ libxl_device_disk = Struct("device_disk" libxl_device_nic = Struct("device_nic", [ ("backend_domid", uint32), - ("domid", domid), ("devid", integer), ("mtu", integer), ("model", string), diff -r 9c05f7fa1edd -r 3a1f9a001a10 tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Thu Apr 07 08:35:51 2011 +0100 +++ b/tools/libxl/libxl_create.c Thu Apr 07 08:35:55 2011 +0100 @@ -443,7 +443,6 @@ static int do_domain_create(libxl__gc *g } for (i = 0; i < d_config->num_disks; i++) { - d_config->disks[i].domid = domid; ret = libxl_device_disk_add(ctx, domid, &d_config->disks[i]); if (ret) { fprintf(stderr, "cannot add disk %d to domain: %d\n", i, ret); @@ -452,7 +451,6 @@ static int do_domain_create(libxl__gc *g } } for (i = 0; i < d_config->num_vifs; i++) { - d_config->vifs[i].domid = domid; ret = libxl_device_nic_add(ctx, domid, &d_config->vifs[i]); if (ret) { fprintf(stderr, "cannot add nic %d to domain: %d\n", i, ret); @@ -466,7 +464,6 @@ static int do_domain_create(libxl__gc *g ret = init_console_info(&console, 0, &state); if ( ret ) goto error_out; - console.domid = domid; libxl_device_console_add(ctx, domid, &console); libxl_device_console_destroy(&console); @@ -485,16 +482,13 @@ static int do_domain_create(libxl__gc *g libxl_device_console console; for (i = 0; i < d_config->num_vfbs; i++) { - d_config->vfbs[i].domid = domid; libxl_device_vfb_add(ctx, domid, &d_config->vfbs[i]); - d_config->vkbs[i].domid = domid; libxl_device_vkb_add(ctx, domid, &d_config->vkbs[i]); } ret = init_console_info(&console, 0, &state); if ( ret ) goto error_out; - console.domid = domid; need_qemu = libxl__need_xenpv_qemu(gc, 1, &console, d_config->num_vfbs, d_config->vfbs, diff -r 9c05f7fa1edd -r 3a1f9a001a10 tools/libxl/libxl_dm.c --- a/tools/libxl/libxl_dm.c Thu Apr 07 08:35:51 2011 +0100 +++ b/tools/libxl/libxl_dm.c Thu Apr 07 08:35:55 2011 +0100 @@ -580,22 +580,18 @@ retry_transaction: goto retry_transaction; for (i = 0; i < num_disks; i++) { - disks[i].domid = domid; ret = libxl_device_disk_add(ctx, domid, &disks[i]); if (ret) goto out_free; } for (i = 0; i < num_vifs; i++) { - vifs[i].domid = domid; ret = libxl_device_nic_add(ctx, domid, &vifs[i]); if (ret) goto out_free; } - vfb->domid = domid; ret = libxl_device_vfb_add(ctx, domid, vfb); if (ret) goto out_free; - vkb->domid = domid; ret = libxl_device_vkb_add(ctx, domid, vkb); if (ret) goto out_free; @@ -612,7 +608,6 @@ retry_transaction: for (i = 0; i < num_console; i++) { console[i].devid = i; console[i].consback = LIBXL_CONSBACK_IOEMU; - console[i].domid = domid; /* STUBDOM_CONSOLE_LOGGING (console 0) is for minios logging * STUBDOM_CONSOLE_SAVE (console 1) is for writing the save file * STUBDOM_CONSOLE_RESTORE (console 2) is for reading the save file diff -r 9c05f7fa1edd -r 3a1f9a001a10 tools/libxl/libxl_utils.c --- a/tools/libxl/libxl_utils.c Thu Apr 07 08:35:51 2011 +0100 +++ b/tools/libxl/libxl_utils.c Thu Apr 07 08:35:55 2011 +0100 @@ -476,7 +476,6 @@ int libxl_mac_to_device_nic(libxl_ctx *c ; if ((b >= mac_n + 6) && (*a == *b)) { nic->backend_domid = nics[i].backend_id; - nic->domid = nics[i].frontend_id; nic->devid = nics[i].devid; memcpy(nic->mac, nics[i].mac, sizeof (nic->mac)); nic->script = strdup(nics[i].script); @@ -551,7 +550,6 @@ int libxl_devid_to_device_disk(libxl_ctx if (!val) goto out; disk->backend_domid = strtoul(val, NULL, 10); - disk->domid = domid; be_path = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/backend", diskpath)); disk->pdev_path = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/params", be_path)); val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/type", be_path)); diff -r 9c05f7fa1edd -r 3a1f9a001a10 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Thu Apr 07 08:35:51 2011 +0100 +++ b/tools/libxl/xl_cmdimpl.c Thu Apr 07 08:35:55 2011 +0100 @@ -381,7 +381,7 @@ static void printf_info(int domid, printf("\t(device\n"); printf("\t\t(tap\n"); printf("\t\t\t(backend_domid %d)\n", d_config->disks[i].backend_domid); - printf("\t\t\t(domid %d)\n", d_config->disks[i].domid); + printf("\t\t\t(domid %d)\n", domid); printf("\t\t\t(physpath %s)\n", d_config->disks[i].pdev_path); printf("\t\t\t(phystype %d)\n", d_config->disks[i].backend); printf("\t\t\t(virtpath %s)\n", d_config->disks[i].vdev); @@ -396,7 +396,7 @@ static void printf_info(int domid, printf("\t(device\n"); printf("\t\t(vif\n"); printf("\t\t\t(backend_domid %d)\n", d_config->vifs[i].backend_domid); - printf("\t\t\t(domid %d)\n", d_config->vifs[i].domid); + printf("\t\t\t(domid %d)\n", domid); printf("\t\t\t(devid %d)\n", d_config->vifs[i].devid); printf("\t\t\t(mtu %d)\n", d_config->vifs[i].mtu); printf("\t\t\t(model %s)\n", d_config->vifs[i].model); @@ -426,7 +426,7 @@ static void printf_info(int domid, printf("\t(device\n"); printf("\t\t(vfb\n"); printf("\t\t\t(backend_domid %d)\n", d_config->vfbs[i].backend_domid); - printf("\t\t\t(domid %d)\n", d_config->vfbs[i].domid); + printf("\t\t\t(domid %d)\n", domid); printf("\t\t\t(devid %d)\n", d_config->vfbs[i].devid); printf("\t\t\t(vnc %d)\n", d_config->vfbs[i].vnc); printf("\t\t\t(vnclisten %s)\n", d_config->vfbs[i].vnclisten); @@ -1844,7 +1844,6 @@ static void cd_insert(const char *dom, c return; } disk.backend_domid = 0; - disk.domid = domid; libxl_cdrom_insert(ctx, domid, &disk); free(buf); @@ -4263,7 +4262,6 @@ int main_networkattach(int argc, char ** return 1; } } - nic.domid = domid; if (libxl_device_nic_add(ctx, domid, &nic)) { fprintf(stderr, "libxl_device_nic_add failed.\n"); return 1; @@ -4358,7 +4356,7 @@ int main_networkdetach(int argc, char ** return 1; } } - if (libxl_device_nic_del(ctx, &nic, 1)) { + if (libxl_device_nic_del(ctx, domid, &nic, 1)) { fprintf(stderr, "libxl_device_nic_del failed.\n"); return 1; } @@ -4433,7 +4431,6 @@ int main_blockattach(int argc, char **ar return 1; } } - disk.domid = fe_domid; disk.backend_domid = be_domid; if (libxl_device_disk_add(ctx, fe_domid, &disk)) { @@ -4518,7 +4515,7 @@ int main_blockdetach(int argc, char **ar fprintf(stderr, "Error: Device %s not connected.\n", argv[optind+1]); return 1; } - if (libxl_device_disk_del(ctx, &disk, 1)) { + if (libxl_device_disk_del(ctx, domid, &disk, 1)) { fprintf(stderr, "libxl_device_disk_del failed.\n"); } return 0; diff -r 9c05f7fa1edd -r 3a1f9a001a10 tools/ocaml/libs/xl/xl_stubs.c --- a/tools/ocaml/libs/xl/xl_stubs.c Thu Apr 07 08:35:51 2011 +0100 +++ b/tools/ocaml/libs/xl/xl_stubs.c Thu Apr 07 08:35:55 2011 +0100 @@ -376,7 +376,6 @@ value stub_xl_disk_add(value info, value INIT_STRUCT(); device_disk_val(&gc, &c_info, info); - c_info.domid = Int_val(domid); INIT_CTX(); ret = libxl_device_disk_add(ctx, Int_val(domid), &c_info); @@ -394,10 +393,9 @@ value stub_xl_disk_remove(value info, va INIT_STRUCT(); device_disk_val(&gc, &c_info, info); - c_info.domid = Int_val(domid); INIT_CTX(); - ret = libxl_device_disk_del(ctx, &c_info, 0); + ret = libxl_device_disk_del(ctx, Int_val(domid), &c_info, 0); if (ret != 0) failwith_xl("disk_remove", &lg); FREE_CTX(); @@ -412,7 +410,6 @@ value stub_xl_nic_add(value info, value INIT_STRUCT(); device_nic_val(&gc, &c_info, info); - c_info.domid = Int_val(domid); INIT_CTX(); ret = libxl_device_nic_add(ctx, Int_val(domid), &c_info); @@ -430,10 +427,9 @@ value stub_xl_nic_remove(value info, val INIT_STRUCT(); device_nic_val(&gc, &c_info, info); - c_info.domid = Int_val(domid); INIT_CTX(); - ret = libxl_device_nic_del(ctx, &c_info, 0); + ret = libxl_device_nic_del(ctx, Int_val(domid), &c_info, 0); if (ret != 0) failwith_xl("nic_remove", &lg); FREE_CTX(); @@ -450,7 +446,6 @@ value stub_xl_console_add(value info, va device_console_val(&gc, &c_info, info); domain_build_state_val(&gc, &c_state, state); - c_info.domid = Int_val(domid); c_info.build_state = &c_state; INIT_CTX(); @@ -469,7 +464,6 @@ value stub_xl_vkb_add(value info, value INIT_STRUCT(); device_vkb_val(&gc, &c_info, info); - c_info.domid = Int_val(domid); INIT_CTX(); ret = libxl_device_vkb_add(ctx, Int_val(domid), &c_info); @@ -518,7 +512,6 @@ value stub_xl_vfb_add(value info, value INIT_STRUCT(); device_vfb_val(&gc, &c_info, info); - c_info.domid = Int_val(domid); INIT_CTX(); ret = libxl_device_vfb_add(ctx, Int_val(domid), &c_info); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Jackson
2011-Apr-08 15:36 UTC
Re: [Xen-devel] [PATCH] libxl: drop domid field from libxl_device_*
Ian Campbell writes ("[Xen-devel] [PATCH] libxl: drop domid field from libxl_device_*"):> libxl: drop domid field from libxl_device_*Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com> _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel