Skip to content

Commit

Permalink
libxl: introduce LIBXL_DOMAIN_TYPE_INVALID
Browse files Browse the repository at this point in the history
To avoid recent gcc complaining about:
libxl.c: In function 'libxl_primary_console_exec':
libxl.c:1233:9: error: case value '4294967295' not in enumerated type 'libxl_domain_type' [-Werror=switch]

Also:
 - have all the call sites of libxl__domain_type() return with error in
   case the function returns LIBXL_DOMAIN_TYPE_INVALID;
 - adjust all other code segments where -Wswitch makes would claim that
   LIBXL_DOMAIN_TYPE_INVALID is not handled by adding a "default: abort();"
   clause.

Signed-off-by: Dario Faggioli <[email protected]>
Signed-off-by: Christoph Egger <[email protected]>
Acked-by: Ian Campbell <[email protected]>
[ ijc -- use LIBXL_DOMAIN_TYPE_INVALID instead of -1 for
         libxl_domain_build_info.type's keyvar_init_val.
      -- what used to be libxl_primary_console_exec is now in
         libxl__primary_console_find so resolve the rejected hunk
         accordingly ]
Committed-by: Ian Campbell <[email protected]>
  • Loading branch information
dfaggioli committed Jun 6, 2012
1 parent afdeff6 commit 4c0b682
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
9 changes: 6 additions & 3 deletions tools/libxl/libxl.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,11 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
libxl_domain_type type = libxl__domain_type(gc, domid);
int rc = 0;

if (type == LIBXL_DOMAIN_TYPE_INVALID) {
rc = ERROR_FAIL;
goto remus_fail;
}

if (info == NULL) {
LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
"No remus_info structure supplied for domain %d", domid);
Expand Down Expand Up @@ -1313,11 +1318,9 @@ static int libxl__primary_console_find(libxl_ctx *ctx, uint32_t domid_vm,
*cons_num = 0;
*type = LIBXL_CONSOLE_TYPE_PV;
break;
case -1:
LOG(ERROR,"unable to get domain type for domid=%"PRIu32, domid_vm);
case LIBXL_DOMAIN_TYPE_INVALID:
rc = ERROR_INVAL;
goto out;
break;
default:
abort();
}
Expand Down
4 changes: 4 additions & 0 deletions tools/libxl/libxl_dm.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ static char ** libxl__build_device_model_args_old(libxl__gc *gc,
for (i = 0; b_info->extra_hvm && b_info->extra_hvm[i] != NULL; i++)
flexarray_append(dm_args, b_info->extra_hvm[i]);
break;
default:
abort();
}
flexarray_append(dm_args, NULL);
return (char **) flexarray_contents(dm_args);
Expand Down Expand Up @@ -505,6 +507,8 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc,
for (i = 0; b_info->extra_hvm && b_info->extra_hvm[i] != NULL; i++)
flexarray_append(dm_args, b_info->extra_hvm[i]);
break;
default:
abort();
}

ram_size = libxl__sizekb_to_mb(b_info->max_memkb - b_info->video_memkb);
Expand Down
9 changes: 5 additions & 4 deletions tools/libxl/libxl_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ libxl_domain_type libxl__domain_type(libxl__gc *gc, uint32_t domid)
int ret;

ret = xc_domain_getinfolist(ctx->xch, domid, 1, &info);
if (ret != 1)
return -1;
if (info.domain != domid)
return -1;
if (ret != 1 || info.domain != domid) {
LIBXL__LOG(CTX, LIBXL__LOG_ERROR,
"unable to get domain type for domid=%"PRIu32, domid);
return LIBXL_DOMAIN_TYPE_INVALID;
}
if (info.flags & XEN_DOMINF_hvm_guest)
return LIBXL_DOMAIN_TYPE_HVM;
else
Expand Down
4 changes: 3 additions & 1 deletion tools/libxl/libxl_types.idl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT")
#

libxl_domain_type = Enumeration("domain_type", [
(-1, "INVALID"),
(1, "HVM"),
(2, "PV"),
])
Expand Down Expand Up @@ -310,7 +311,8 @@ libxl_domain_build_info = Struct("domain_build_info",[
# Use host's E820 for PCI passthrough.
("e820_host", libxl_defbool),
])),
], keyvar_init_val = "-1")),
("invalid", Struct(None, [])),
], keyvar_init_val = "LIBXL_DOMAIN_TYPE_INVALID")),
], dir=DIR_IN
)

Expand Down

0 comments on commit 4c0b682

Please sign in to comment.