debuggers.hg

changeset 22866:310cc33bfc81

xl: avoid creating domains with duplicate names

Do not create the domain if another domain with the same name is already
running.

This is another error-checking function at rather too high a level:
this should be moved into libxl_domain_rename in 4.2.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Ian Jackson <ian.jackson@eu.citrix.com>
date Wed Jan 26 16:05:09 2011 +0000 (2011-01-26)
parents 67d5b8004947
children 5ce41defa1fa
files tools/libxl/xl_cmdimpl.c
line diff
     1.1 --- a/tools/libxl/xl_cmdimpl.c	Wed Jan 26 11:58:45 2011 +0000
     1.2 +++ b/tools/libxl/xl_cmdimpl.c	Wed Jan 26 16:05:09 2011 +0000
     1.3 @@ -583,6 +583,7 @@ static void parse_config_data(const char
     1.4      XLU_ConfigList *vbds, *nics, *pcis, *cvfbs, *net2s, *cpuids;
     1.5      int pci_power_mgmt = 0;
     1.6      int pci_msitranslate = 1;
     1.7 +    uint32_t domid_e;
     1.8      int e;
     1.9  
    1.10      libxl_domain_create_info *c_info = &d_config->c_info;
    1.11 @@ -612,6 +613,15 @@ static void parse_config_data(const char
    1.12  
    1.13      if (xlu_cfg_replace_string (config, "name", &c_info->name))
    1.14          c_info->name = strdup("test");
    1.15 +    e = libxl_name_to_domid(&ctx, c_info->name, &domid_e);
    1.16 +    if (!e) {
    1.17 +        fprintf(stderr, "A domain with name \"%s\" already exists.\n", c_info->name);
    1.18 +        exit(1);
    1.19 +    }
    1.20 +    if (e != ERROR_INVAL) {
    1.21 +        fprintf(stderr, "Unexpected error checking for existing domain"
    1.22 +                " (error=%d)", e);
    1.23 +    }
    1.24  
    1.25      if (!xlu_cfg_get_string (config, "uuid", &buf) ) {
    1.26          if ( libxl_uuid_from_string(&c_info->uuid, buf) ) {