[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC XEN PATCH v4 18/41] tools/xl: add xl command 'pmem-setup'
The new xl command 'pmem-setup' with '-m' option is used to setup the specified PMEM region for the management usage. Signed-off-by: Haozhong Zhang <haozhong.zhang@xxxxxxxxx> --- Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Cc: Wei Liu <wei.liu2@xxxxxxxxxx> --- tools/libxl/libxl.h | 13 ++++++++++++ tools/libxl/libxl_nvdimm.c | 11 ++++++++++ tools/xl/xl.h | 1 + tools/xl/xl_cmdtable.c | 6 ++++++ tools/xl/xl_nvdimm.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 9ce487e79f..e13a911cb4 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -2324,6 +2324,19 @@ int libxl_nvdimm_pmem_get_regions(libxl_ctx *ctx, libxl_nvdimm_pmem_region **regions_r, unsigned int *nr_r); +/* + * Setup the specified PMEM region for management usage. + * + * Parameters: + * ctx: libxl context + * smfn, emfn: start and end MFN's of the PMEM region + * + * Return: + * 0 on success; otherwise, ERROR_*, and leave errno valid. + */ +int libxl_nvdimm_pmem_setup_mgmt(libxl_ctx *ctx, + unsigned long smfn, unsigned long emfn); + /* misc */ /* Each of these sets or clears the flag according to whether the diff --git a/tools/libxl/libxl_nvdimm.c b/tools/libxl/libxl_nvdimm.c index 70da18f11f..c0024298ec 100644 --- a/tools/libxl/libxl_nvdimm.c +++ b/tools/libxl/libxl_nvdimm.c @@ -136,3 +136,14 @@ int libxl_nvdimm_pmem_get_regions(libxl_ctx *ctx, return rc; } + +int libxl_nvdimm_pmem_setup_mgmt(libxl_ctx *ctx, + unsigned long smfn, unsigned long emfn) +{ + int rc = xc_nvdimm_pmem_setup_mgmt(ctx->xch, smfn, emfn); + + if (rc) + errno = -rc; + + return errno ? ERROR_FAIL : 0; +} diff --git a/tools/xl/xl.h b/tools/xl/xl.h index 9359a3d9c7..8995f64a6f 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -211,6 +211,7 @@ int main_psr_cat_show(int argc, char **argv); #endif int main_qemu_monitor_command(int argc, char **argv); int main_pmem_list(int argc, char **argv); +int main_pmem_setup(int argc, char **argv); void help(const char *command); diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index f525cafcdf..12a2c2d601 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -622,6 +622,12 @@ struct cmd_spec cmd_table[] = { "[options]", "-r, --raw List PMEM regions detected by Xen hypervisor\n" }, + { "pmem-setup", + &main_pmem_setup, 0, 1, + "Setup a PMEM region for specified usage purpose", + "[options]", + "-m, --mgmt <smfn> <emfn> Set PMEM pages smfn - emfn for management usage\n" + }, }; int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec); diff --git a/tools/xl/xl_nvdimm.c b/tools/xl/xl_nvdimm.c index 799c76e4c2..25dc6350da 100644 --- a/tools/xl/xl_nvdimm.c +++ b/tools/xl/xl_nvdimm.c @@ -24,8 +24,10 @@ #include <string.h> #include <libxl.h> +#include <libxlutil.h> #include "xl.h" +#include "xl_parse.h" #include "xl_utils.h" typedef void (*show_region_fn_t)(libxl_nvdimm_pmem_region *region, @@ -90,3 +92,52 @@ int main_pmem_list(int argc, char **argv) return ret; } + +int main_pmem_setup(int argc, char **argv) +{ + static struct option opts[] = { + { "mgmt", 1, 0, 'm' }, + COMMON_LONG_OPTS + }; + + bool mgmt = false; + unsigned long mgmt_smfn, mgmt_emfn; + int opt, rc = 0; + +#define CHECK_NR_ARGS(expected, option) \ + do { \ + if (argc + 1 != optind + (expected)) { \ + fprintf(stderr, \ + "Error: 'xl pmem-setup %s' requires %u arguments\n\n", \ + (option), (expected)); \ + help("pmem-setup"); \ + \ + rc = ERROR_INVAL; \ + errno = EINVAL; \ + \ + goto out; \ + } \ + } while (0) + + SWITCH_FOREACH_OPT(opt, "m:", opts, "pmem-setup", 0) { + case 'm': + CHECK_NR_ARGS(2, "-m"); + + mgmt = true; + mgmt_smfn = parse_ulong(optarg); + mgmt_emfn = parse_ulong(argv[optind]); + + break; + } + +#undef CHECK_NR_ARGS + + if (mgmt) + rc = libxl_nvdimm_pmem_setup_mgmt(ctx, mgmt_smfn, mgmt_emfn); + + out: + if (rc) + fprintf(stderr, "Error: pmem-setup failed, %s\n", strerror(errno)); + + return rc; +} -- 2.15.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |