Ian Campbell
2011-Dec-13 17:09 UTC
[PATCH] libxl: remove stubdom device model save file when destroying stubdom
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1323795995 0 # Node ID 738c34b1b0450724c4b91b739d1e9cae09f26035 # Parent 47606788dec2f110aecf5b356b250d65343070ac libxl: remove stubdom device model save file when destroying stubdom /var/lib/xen/qemu-save.<domid> is created when the stub domain is started (connected to a stubdom console) and is used to save the device model state on suspend/migrate but never cleaned up. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 47606788dec2 -r 738c34b1b045 tools/libxl/libxl_dm.c --- a/tools/libxl/libxl_dm.c Tue Dec 13 16:24:17 2011 +0000 +++ b/tools/libxl/libxl_dm.c Tue Dec 13 17:06:35 2011 +0000 @@ -36,6 +36,11 @@ static const char *libxl_tapif_script(li #endif } +const char *libxl__device_model_savefile(libxl__gc *gc, uint32_t domid) +{ + return libxl__sprintf(gc, "/var/lib/xen/qemu-save.%d", domid); +} + const char *libxl__domain_device_model(libxl__gc *gc, libxl_device_model_info *info) { @@ -721,7 +726,8 @@ retry_transaction: free(filename); break; case STUBDOM_CONSOLE_SAVE: - console[i].output = libxl__sprintf(gc, "file:"SAVEFILE".%d", info->domid); + console[i].output = libxl__sprintf(gc, "file:%s", + libxl__device_model_savefile(gc, info->domid)); break; case STUBDOM_CONSOLE_RESTORE: if (info->saved_state) @@ -924,6 +930,8 @@ int libxl__destroy_device_model(libxl__g pid = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "/local/domain/%d/image/device-model-pid", domid)); if (!pid) { int stubdomid = libxl_get_stubdom_id(ctx, domid); + const char *savefile; + if (!stubdomid) { LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn''t find device model''s pid"); ret = ERROR_INVAL; @@ -933,6 +941,20 @@ int libxl__destroy_device_model(libxl__g ret = libxl_domain_destroy(ctx, stubdomid, 0); if (ret) goto out; + + savefile = libxl__device_model_savefile(gc, domid); + ret = unlink(savefile); + /* + * On suspend libxl__domain_save_device_model will have already + * unlinked the save file. + */ + if (ret && errno == ENOENT) ret = 0; + if (ret) { + LIBXL__LOG_ERRNO(ctx, XTL_ERROR, + "failed to remove device-model savefile %s\n", + savefile); + goto out; + } } else { ret = kill(atoi(pid), SIGHUP); if (ret < 0 && errno == ESRCH) { diff -r 47606788dec2 -r 738c34b1b045 tools/libxl/libxl_dom.c --- a/tools/libxl/libxl_dom.c Tue Dec 13 16:24:17 2011 +0000 +++ b/tools/libxl/libxl_dom.c Tue Dec 13 17:06:35 2011 +0000 @@ -607,7 +607,7 @@ int libxl__domain_save_device_model(libx libxl_ctx *ctx = libxl__gc_owner(gc); int fd2, c; char buf[1024]; - char *filename = libxl__sprintf(gc, "/var/lib/xen/qemu-save.%d", domid); + const char *filename = libxl__device_model_savefile(gc, domid); struct stat st; uint32_t qemu_state_len; diff -r 47606788dec2 -r 738c34b1b045 tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Tue Dec 13 16:24:17 2011 +0000 +++ b/tools/libxl/libxl_internal.h Tue Dec 13 17:06:35 2011 +0000 @@ -59,7 +59,6 @@ #define STUBDOM_CONSOLE_RESTORE 2 #define STUBDOM_CONSOLE_SERIAL 3 #define STUBDOM_SPECIAL_CONSOLES 3 -#define SAVEFILE "/var/lib/xen/qemu-save" #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) @@ -244,6 +243,7 @@ _hidden int libxl__domain_restore_common _hidden int libxl__domain_suspend_common(libxl__gc *gc, uint32_t domid, int fd, libxl_domain_type type, int live, int debug); +_hidden const char *libxl__device_model_savefile(libxl__gc *gc, uint32_t domid); _hidden int libxl__domain_save_device_model(libxl__gc *gc, uint32_t domid, int fd); _hidden void libxl__userdata_destroyall(libxl__gc *gc, uint32_t domid);
Ian Jackson
2011-Dec-15 16:56 UTC
Re: [PATCH] libxl: remove stubdom device model save file when destroying stubdom
Ian Campbell writes ("[Xen-devel] [PATCH] libxl: remove stubdom device model save file when destroying stubdom"):> libxl: remove stubdom device model save file when destroying stubdomAcked-by: Ian Jackson <ian.jackson@eu.citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>