Skip to content

Commit

Permalink
xen-shell-cmd: Allow config selection for domain creation
Browse files Browse the repository at this point in the history
Add linker script to collect all domain configs in one place.
Add macro DECL_CONFIG to mark domain config structures.
Specific config can be selected for domain creation by name via the
shell command line parameter.

Signed-off-by: Mykyta Poturai <[email protected]>
  • Loading branch information
Deedone committed Apr 1, 2024
1 parent f93f5d6 commit ce00583
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
2 changes: 2 additions & 0 deletions xen-dom-mgmt/include/xen_dom_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ int domain_pause(uint32_t domid);
int domain_unpause(uint32_t domid);
int domain_post_create(const struct xen_domain_cfg *domcfg, uint32_t domid);

#define DECL_CONFIG static __attribute__((__section__(".domain_configs"))) __used

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions xen-shell-cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ add_library(XEN_SHELL INTERFACE)

zephyr_library()
zephyr_library_sources(src/xen_cmds.c)
zephyr_linker_sources(DATA_SECTIONS linker.ld)
zephyr_library_sources_ifdef(CONFIG_XRUN_SHELL_CMDS src/xrun_cmds.c)
zephyr_library_sources_ifdef(CONFIG_XSTAT_SHELL_CMDS src/xstat_cmds.c)
zephyr_library_link_libraries(XEN_SHELL)
6 changes: 6 additions & 0 deletions xen-shell-cmd/linker.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.domain_configs :
{
_domain_configs_start = .;
KEEP(*(.domain_configs))
_domain_configs_end = .;
} > RAM
57 changes: 47 additions & 10 deletions xen-shell-cmd/src/xen_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <zephyr/shell/shell.h>
#include <zephyr/logging/log.h>
#include <stdlib.h>
#include <string.h>

#include <xen_dom_mgmt.h>
#ifdef CONFIG_XEN_CONSOLE_SRV
Expand All @@ -15,7 +16,8 @@

LOG_MODULE_REGISTER(xen_shell);

extern struct xen_domain_cfg domd_cfg;
extern struct xen_domain_cfg _domain_configs_start[];
extern struct xen_domain_cfg _domain_configs_end[];

uint32_t parse_domid(size_t argc, char **argv)
{
Expand All @@ -32,23 +34,58 @@ uint32_t parse_domid(size_t argc, char **argv)
return 0;
}

char *parse_name(size_t argc, char **argv)
{
/* first would be the cmd name, start from second */
int pos = 3;

if (argv[pos][0] == '-' && argv[pos][1] == 'c') {
/* Take next value after "-c" option */
pos++;
return argv[pos];
}

/* Use zero as invalid value */
return NULL;
}

static int domu_create(const struct shell *shell, int argc, char **argv)
{
uint32_t domid;
char *name;
struct xen_domain_cfg *cfg;

if (argc != 3)
if (argc != 5)
return -EINVAL;

domid = parse_domid(argc, argv);
if (!domid) {
LOG_ERR("Invalid domid passed to create cmd");
shell_error(shell, "Invalid domid passed to create cmd");
return -EINVAL;
}
/*
* TODO: this should be changed in app code.
* Not all domains using domd config
*/
return domain_create(&domd_cfg, domid);

name = parse_name(argc, argv);
if (!name) {
shell_error(shell, "Invalid config passed to create cmd");
return -EINVAL;
}

for (cfg = _domain_configs_start; cfg < _domain_configs_end; cfg++) {
if (strncmp(cfg->name, name, CONTAINER_NAME_SIZE) == 0) {
break;
}
}

if (cfg == _domain_configs_end) {
shell_error(shell, "Config with name %s not found", name);
shell_error(shell, "Available configs are:");
for (cfg = _domain_configs_start; cfg < _domain_configs_end; cfg++) {
shell_error(shell, "%s", cfg->name);
}
return -EINVAL;
}

return domain_create(cfg, domid);
}

int domu_destroy(const struct shell *shell, size_t argc, char **argv)
Expand Down Expand Up @@ -131,8 +168,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
subcmd_xu,
SHELL_CMD_ARG(create, NULL,
" Create Xen domain\n"
" Usage: create -d <domid>\n",
domu_create, 3, 0),
" Usage: create -d <domid> -c <config_name>\n",
domu_create, 5, 0),
SHELL_CMD_ARG(destroy, NULL,
" Destroy Xen domain\n"
" Usage: destroy -d <domid>\n",
Expand Down

0 comments on commit ce00583

Please sign in to comment.