Message ID | fd590fbbc2f1abaeca1fd368d26c4e90c3a89d69.1641233076.git.alison.schofield@intel.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Add partitioning support for CXL memdevs | expand |
On Mon, Jan 03, 2022 at 12:16:18PM -0800, Schofield, Alison wrote: > From: Alison Schofield <alison.schofield@intel.com> > "User will need a command line option for setting partition info. Add 'set-partition-info' to the cxl command line tool." > The command 'cxl set-partition-info' operates on a CXL memdev, > or a set of memdevs, allowing the user to change the partition > layout of the device. ^^^^^^ device(s). > > Synopsis: > Usage: cxl set-partition-info <mem0> [<mem1>..<memN>] [<options>] > > -v, --verbose turn on debug > -s, --volatile_size <n> > next volatile partition size in bytes > > The MAN page explains how to find partitioning capabilities and > restrictions. > > Signed-off-by: Alison Schofield <alison.schofield@intel.com> > --- > Documentation/cxl/cxl-set-partition-info.txt | 27 ++++++ > Documentation/cxl/partition-description.txt | 15 ++++ > Documentation/cxl/partition-options.txt | 19 +++++ > Documentation/cxl/Makefile.am | 3 +- > cxl/builtin.h | 1 + > cxl/cxl.c | 1 + > cxl/memdev.c | 89 ++++++++++++++++++++ > 7 files changed, 154 insertions(+), 1 deletion(-) > create mode 100644 Documentation/cxl/cxl-set-partition-info.txt > create mode 100644 Documentation/cxl/partition-description.txt > create mode 100644 Documentation/cxl/partition-options.txt > > diff --git a/Documentation/cxl/cxl-set-partition-info.txt b/Documentation/cxl/cxl-set-partition-info.txt > new file mode 100644 > index 0000000..32418b6 > --- /dev/null > +++ b/Documentation/cxl/cxl-set-partition-info.txt > @@ -0,0 +1,27 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +cxl-set-partition-info(1) > +========================= > + > +NAME > +---- > +cxl-set-partition-info - set the partitioning between volatile and persistent capacity on a CXL memdev > + > +SYNOPSIS > +-------- > +[verse] > +'cxl set-partition-info <mem> [ [<mem1>..<memN>] [<options>]' > + > +include::partition-description.txt[] > +Partition the device on the next device reset using the volatile capacity > +requested. Using this command to change the size of the persistent capacity > +shall result in the loss of stored data. > + > +OPTIONS > +------- > +include::partition-options.txt[] > + > +SEE ALSO > +-------- > +linkcxl:cxl-list[1], Did I miss the update to the cxl-list command documentation? > +CXL-2.0 8.2.9.5.2 > diff --git a/Documentation/cxl/partition-description.txt b/Documentation/cxl/partition-description.txt > new file mode 100644 > index 0000000..b3efac8 > --- /dev/null > +++ b/Documentation/cxl/partition-description.txt > @@ -0,0 +1,15 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +DESCRIPTION > +----------- > +Partition the device into volatile and persistent capacity. The change > +in partitioning will become the “next” configuration, to become active > +on the next device reset. > + > +Use "cxl list -m <memdev> -P" to examine the partition capacities > +supported on a device. Paritionable capacity must exist on the > +device. A partition_alignment of zero means no partitionable > +capacity is available. > + > +Using this command to change the size of the persistent capacity shall > +result in the loss of data stored. > diff --git a/Documentation/cxl/partition-options.txt b/Documentation/cxl/partition-options.txt > new file mode 100644 > index 0000000..84e49c9 > --- /dev/null > +++ b/Documentation/cxl/partition-options.txt > @@ -0,0 +1,19 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +<memory device(s)>:: > +include::memdev-option.txt[] > + > +-s:: > +--size=:: > + Size in bytes of the volatile partition requested. > + > + Size must align to the devices partition_alignment. > + Use 'cxl list -m <memdev> -P' to find partition_alignment. > + > + Size must be less than or equal to the devices partitionable bytes. > + (total_capacity - volatile_only_capacity - persistent_only_capacity) > + Use 'cxl list -m <memdev> -P' to find *_capacity values. > + > +-v:: > + Turn on verbose debug messages in the library (if libcxl was built with > + logging and debug enabled). > diff --git a/Documentation/cxl/Makefile.am b/Documentation/cxl/Makefile.am > index efabaa3..c5faf04 100644 > --- a/Documentation/cxl/Makefile.am > +++ b/Documentation/cxl/Makefile.am > @@ -22,7 +22,8 @@ man1_MANS = \ > cxl-list.1 \ > cxl-read-labels.1 \ > cxl-write-labels.1 \ > - cxl-zero-labels.1 > + cxl-zero-labels.1 \ > + cxl-set-partition-info.1 > > EXTRA_DIST = $(man1_MANS) > > diff --git a/cxl/builtin.h b/cxl/builtin.h > index 78eca6e..7f11f28 100644 > --- a/cxl/builtin.h > +++ b/cxl/builtin.h > @@ -10,4 +10,5 @@ int cmd_read_labels(int argc, const char **argv, struct cxl_ctx *ctx); > int cmd_zero_labels(int argc, const char **argv, struct cxl_ctx *ctx); > int cmd_init_labels(int argc, const char **argv, struct cxl_ctx *ctx); > int cmd_check_labels(int argc, const char **argv, struct cxl_ctx *ctx); > +int cmd_set_partition_info(int argc, const char **argv, struct cxl_ctx *ctx); > #endif /* _CXL_BUILTIN_H_ */ > diff --git a/cxl/cxl.c b/cxl/cxl.c > index 4b1661d..3153cf0 100644 > --- a/cxl/cxl.c > +++ b/cxl/cxl.c > @@ -64,6 +64,7 @@ static struct cmd_struct commands[] = { > { "zero-labels", .c_fn = cmd_zero_labels }, > { "read-labels", .c_fn = cmd_read_labels }, > { "write-labels", .c_fn = cmd_write_labels }, > + { "set-partition-info", .c_fn = cmd_set_partition_info }, > }; > > int main(int argc, const char **argv) > diff --git a/cxl/memdev.c b/cxl/memdev.c > index 5ee38e5..fa63317 100644 > --- a/cxl/memdev.c > +++ b/cxl/memdev.c > @@ -6,6 +6,7 @@ > #include <unistd.h> > #include <limits.h> > #include <util/log.h> > +#include <util/size.h> > #include <util/filter.h> > #include <cxl/libcxl.h> > #include <util/parse-options.h> > @@ -23,6 +24,7 @@ static struct parameters { > unsigned len; > unsigned offset; > bool verbose; > + unsigned long long volatile_size; > } param; > > #define fail(fmt, ...) \ > @@ -47,6 +49,10 @@ OPT_UINTEGER('s', "size", ¶m.len, "number of label bytes to operate"), \ > OPT_UINTEGER('O', "offset", ¶m.offset, \ > "offset into the label area to start operation") > > +#define SET_PARTITION_OPTIONS() \ > +OPT_U64('s', "volatile_size", ¶m.volatile_size, \ > + "next volatile partition size in bytes") > + > static const struct option read_options[] = { > BASE_OPTIONS(), > LABEL_OPTIONS(), > @@ -67,6 +73,12 @@ static const struct option zero_options[] = { > OPT_END(), > }; > > +static const struct option set_partition_options[] = { > + BASE_OPTIONS(), > + SET_PARTITION_OPTIONS(), > + OPT_END(), > +}; > + > static int action_zero(struct cxl_memdev *memdev, struct action_context *actx) > { > size_t size; > @@ -174,6 +186,73 @@ out: > return rc; > } > > +static int validate_partition(struct cxl_memdev *memdev, > + unsigned long long volatile_request) > +{ > + unsigned long long total_cap, volatile_only, persistent_only; > + unsigned long long partitionable_bytes, partition_align_bytes; > + const char *devname = cxl_memdev_get_devname(memdev); > + struct cxl_cmd *cmd; > + int rc; > + > + cmd = cxl_cmd_new_identify(memdev); > + if (!cmd) > + return -ENXIO; > + rc = cxl_cmd_submit(cmd); > + if (rc < 0) > + goto err; > + rc = cxl_cmd_get_mbox_status(cmd); > + if (rc != 0) > + goto err; > + > + partition_align_bytes = cxl_cmd_identify_get_partition_align(cmd); > + if (partition_align_bytes == 0) { > + fprintf(stderr, "%s: no partitionable capacity\n", devname); > + rc = -EINVAL; > + goto err; > + } > + > + total_cap = cxl_cmd_identify_get_total_capacity(cmd); > + volatile_only = cxl_cmd_identify_get_volatile_only_capacity(cmd); > + persistent_only = cxl_cmd_identify_get_persistent_only_capacity(cmd); > + > + partitionable_bytes = total_cap - volatile_only - persistent_only; > + > + if (volatile_request > partitionable_bytes) { > + fprintf(stderr, "%s: volatile size %lld exceeds partitionable capacity %lld\n", > + devname, volatile_request, partitionable_bytes); > + rc = -EINVAL; > + goto err; > + } > + if (!IS_ALIGNED(volatile_request, partition_align_bytes)) { > + fprintf(stderr, "%s: volatile size %lld is not partition aligned %lld\n", > + devname, volatile_request, partition_align_bytes); > + rc = -EINVAL; > + } > +err: > + cxl_cmd_unref(cmd); > + return rc; > +} > + > +static int action_set_partition(struct cxl_memdev *memdev, > + struct action_context *actx) > +{ > + const char *devname = cxl_memdev_get_devname(memdev); > + unsigned long long volatile_request; > + int rc; > + > + volatile_request = param.volatile_size; > + > + rc = validate_partition(memdev, volatile_request); > + if (rc) > + return rc; > + > + rc = cxl_memdev_set_partition_info(memdev, volatile_request, 0); CXL_CMD_SET_PARTITION_INFO_NO_FLAG? Ira > + if (rc) > + fprintf(stderr, "%s error: %s\n", devname, strerror(-rc)); > + return rc; > +} > + > static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx, > int (*action)(struct cxl_memdev *memdev, struct action_context *actx), > const struct option *options, const char *usage) > @@ -322,3 +401,13 @@ int cmd_zero_labels(int argc, const char **argv, struct cxl_ctx *ctx) > count > 1 ? "s" : ""); > return count >= 0 ? 0 : EXIT_FAILURE; > } > + > +int cmd_set_partition_info(int argc, const char **argv, struct cxl_ctx *ctx) > +{ > + int count = memdev_action(argc, argv, ctx, action_set_partition, > + set_partition_options, > + "cxl set-partition-info <mem0> [<mem1>..<memN>] [<options>]"); > + fprintf(stderr, "set_partition %d mem%s\n", count >= 0 ? count : 0, > + count > 1 ? "s" : ""); > + return count >= 0 ? 0 : EXIT_FAILURE; > +} > -- > 2.31.1 >
On Mon, Jan 3, 2022 at 12:11 PM <alison.schofield@intel.com> wrote: > > From: Alison Schofield <alison.schofield@intel.com> > > The command 'cxl set-partition-info' operates on a CXL memdev, > or a set of memdevs, allowing the user to change the partition > layout of the device. > > Synopsis: > Usage: cxl set-partition-info <mem0> [<mem1>..<memN>] [<options>] > > -v, --verbose turn on debug > -s, --volatile_size <n> > next volatile partition size in bytes > > The MAN page explains how to find partitioning capabilities and > restrictions. > > Signed-off-by: Alison Schofield <alison.schofield@intel.com> [..] > diff --git a/cxl/memdev.c b/cxl/memdev.c > index 5ee38e5..fa63317 100644 > --- a/cxl/memdev.c > +++ b/cxl/memdev.c > @@ -6,6 +6,7 @@ > #include <unistd.h> > #include <limits.h> > #include <util/log.h> > +#include <util/size.h> > #include <util/filter.h> > #include <cxl/libcxl.h> > #include <util/parse-options.h> > @@ -23,6 +24,7 @@ static struct parameters { > unsigned len; > unsigned offset; > bool verbose; > + unsigned long long volatile_size; This should be a string. See parse_size64() that handles suffixes like K,M,G,T, so you can do things like "cxl set-partition -s 256M" and behave like the other "--size" options in ndctl.
On Mon, Jan 3, 2022 at 12:11 PM <alison.schofield@intel.com> wrote: > > From: Alison Schofield <alison.schofield@intel.com> > > The command 'cxl set-partition-info' operates on a CXL memdev, > or a set of memdevs, allowing the user to change the partition > layout of the device. > > Synopsis: > Usage: cxl set-partition-info <mem0> [<mem1>..<memN>] [<options>] > > -v, --verbose turn on debug > -s, --volatile_size <n> > next volatile partition size in bytes > > The MAN page explains how to find partitioning capabilities and > restrictions. > > Signed-off-by: Alison Schofield <alison.schofield@intel.com> > --- > Documentation/cxl/cxl-set-partition-info.txt | 27 ++++++ > Documentation/cxl/partition-description.txt | 15 ++++ > Documentation/cxl/partition-options.txt | 19 +++++ > Documentation/cxl/Makefile.am | 3 +- > cxl/builtin.h | 1 + > cxl/cxl.c | 1 + > cxl/memdev.c | 89 ++++++++++++++++++++ > 7 files changed, 154 insertions(+), 1 deletion(-) > create mode 100644 Documentation/cxl/cxl-set-partition-info.txt > create mode 100644 Documentation/cxl/partition-description.txt > create mode 100644 Documentation/cxl/partition-options.txt > > diff --git a/Documentation/cxl/cxl-set-partition-info.txt b/Documentation/cxl/cxl-set-partition-info.txt > new file mode 100644 > index 0000000..32418b6 > --- /dev/null > +++ b/Documentation/cxl/cxl-set-partition-info.txt > @@ -0,0 +1,27 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +cxl-set-partition-info(1) > +========================= > + > +NAME > +---- > +cxl-set-partition-info - set the partitioning between volatile and persistent capacity on a CXL memdev > + > +SYNOPSIS > +-------- > +[verse] > +'cxl set-partition-info <mem> [ [<mem1>..<memN>] [<options>]' > + > +include::partition-description.txt[] > +Partition the device on the next device reset using the volatile capacity > +requested. Using this command to change the size of the persistent capacity > +shall result in the loss of stored data. > + > +OPTIONS > +------- > +include::partition-options.txt[] > + > +SEE ALSO > +-------- > +linkcxl:cxl-list[1], > +CXL-2.0 8.2.9.5.2 > diff --git a/Documentation/cxl/partition-description.txt b/Documentation/cxl/partition-description.txt > new file mode 100644 > index 0000000..b3efac8 > --- /dev/null > +++ b/Documentation/cxl/partition-description.txt > @@ -0,0 +1,15 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +DESCRIPTION > +----------- > +Partition the device into volatile and persistent capacity. The change > +in partitioning will become the “next” configuration, to become active > +on the next device reset. > + > +Use "cxl list -m <memdev> -P" to examine the partition capacities > +supported on a device. Paritionable capacity must exist on the > +device. A partition_alignment of zero means no partitionable > +capacity is available. > + > +Using this command to change the size of the persistent capacity shall > +result in the loss of data stored. > diff --git a/Documentation/cxl/partition-options.txt b/Documentation/cxl/partition-options.txt > new file mode 100644 > index 0000000..84e49c9 > --- /dev/null > +++ b/Documentation/cxl/partition-options.txt > @@ -0,0 +1,19 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +<memory device(s)>:: > +include::memdev-option.txt[] > + > +-s:: > +--size=:: > + Size in bytes of the volatile partition requested. > + > + Size must align to the devices partition_alignment. > + Use 'cxl list -m <memdev> -P' to find partition_alignment. > + > + Size must be less than or equal to the devices partitionable bytes. > + (total_capacity - volatile_only_capacity - persistent_only_capacity) > + Use 'cxl list -m <memdev> -P' to find *_capacity values. > + > +-v:: > + Turn on verbose debug messages in the library (if libcxl was built with > + logging and debug enabled). > diff --git a/Documentation/cxl/Makefile.am b/Documentation/cxl/Makefile.am > index efabaa3..c5faf04 100644 > --- a/Documentation/cxl/Makefile.am > +++ b/Documentation/cxl/Makefile.am > @@ -22,7 +22,8 @@ man1_MANS = \ > cxl-list.1 \ > cxl-read-labels.1 \ > cxl-write-labels.1 \ > - cxl-zero-labels.1 > + cxl-zero-labels.1 \ > + cxl-set-partition-info.1 > > EXTRA_DIST = $(man1_MANS) > > diff --git a/cxl/builtin.h b/cxl/builtin.h > index 78eca6e..7f11f28 100644 > --- a/cxl/builtin.h > +++ b/cxl/builtin.h > @@ -10,4 +10,5 @@ int cmd_read_labels(int argc, const char **argv, struct cxl_ctx *ctx); > int cmd_zero_labels(int argc, const char **argv, struct cxl_ctx *ctx); > int cmd_init_labels(int argc, const char **argv, struct cxl_ctx *ctx); > int cmd_check_labels(int argc, const char **argv, struct cxl_ctx *ctx); > +int cmd_set_partition_info(int argc, const char **argv, struct cxl_ctx *ctx); > #endif /* _CXL_BUILTIN_H_ */ > diff --git a/cxl/cxl.c b/cxl/cxl.c > index 4b1661d..3153cf0 100644 > --- a/cxl/cxl.c > +++ b/cxl/cxl.c > @@ -64,6 +64,7 @@ static struct cmd_struct commands[] = { > { "zero-labels", .c_fn = cmd_zero_labels }, > { "read-labels", .c_fn = cmd_read_labels }, > { "write-labels", .c_fn = cmd_write_labels }, > + { "set-partition-info", .c_fn = cmd_set_partition_info }, > }; > > int main(int argc, const char **argv) > diff --git a/cxl/memdev.c b/cxl/memdev.c > index 5ee38e5..fa63317 100644 > --- a/cxl/memdev.c > +++ b/cxl/memdev.c > @@ -6,6 +6,7 @@ > #include <unistd.h> > #include <limits.h> > #include <util/log.h> > +#include <util/size.h> > #include <util/filter.h> > #include <cxl/libcxl.h> > #include <util/parse-options.h> > @@ -23,6 +24,7 @@ static struct parameters { > unsigned len; > unsigned offset; > bool verbose; > + unsigned long long volatile_size; > } param; > > #define fail(fmt, ...) \ > @@ -47,6 +49,10 @@ OPT_UINTEGER('s', "size", ¶m.len, "number of label bytes to operate"), \ > OPT_UINTEGER('O', "offset", ¶m.offset, \ > "offset into the label area to start operation") > > +#define SET_PARTITION_OPTIONS() \ > +OPT_U64('s', "volatile_size", ¶m.volatile_size, \ > + "next volatile partition size in bytes") > + > static const struct option read_options[] = { > BASE_OPTIONS(), > LABEL_OPTIONS(), > @@ -67,6 +73,12 @@ static const struct option zero_options[] = { > OPT_END(), > }; > > +static const struct option set_partition_options[] = { > + BASE_OPTIONS(), > + SET_PARTITION_OPTIONS(), > + OPT_END(), > +}; > + > static int action_zero(struct cxl_memdev *memdev, struct action_context *actx) > { > size_t size; > @@ -174,6 +186,73 @@ out: > return rc; > } > > +static int validate_partition(struct cxl_memdev *memdev, > + unsigned long long volatile_request) > +{ > + unsigned long long total_cap, volatile_only, persistent_only; > + unsigned long long partitionable_bytes, partition_align_bytes; > + const char *devname = cxl_memdev_get_devname(memdev); > + struct cxl_cmd *cmd; > + int rc; > + > + cmd = cxl_cmd_new_identify(memdev); > + if (!cmd) > + return -ENXIO; > + rc = cxl_cmd_submit(cmd); > + if (rc < 0) > + goto err; > + rc = cxl_cmd_get_mbox_status(cmd); > + if (rc != 0) > + goto err; > + > + partition_align_bytes = cxl_cmd_identify_get_partition_align(cmd); > + if (partition_align_bytes == 0) { > + fprintf(stderr, "%s: no partitionable capacity\n", devname); > + rc = -EINVAL; > + goto err; > + } > + > + total_cap = cxl_cmd_identify_get_total_capacity(cmd); > + volatile_only = cxl_cmd_identify_get_volatile_only_capacity(cmd); > + persistent_only = cxl_cmd_identify_get_persistent_only_capacity(cmd); > + > + partitionable_bytes = total_cap - volatile_only - persistent_only; > + > + if (volatile_request > partitionable_bytes) { > + fprintf(stderr, "%s: volatile size %lld exceeds partitionable capacity %lld\n", > + devname, volatile_request, partitionable_bytes); > + rc = -EINVAL; > + goto err; > + } > + if (!IS_ALIGNED(volatile_request, partition_align_bytes)) { > + fprintf(stderr, "%s: volatile size %lld is not partition aligned %lld\n", > + devname, volatile_request, partition_align_bytes); > + rc = -EINVAL; > + } > +err: > + cxl_cmd_unref(cmd); > + return rc; > +} > + > +static int action_set_partition(struct cxl_memdev *memdev, > + struct action_context *actx) > +{ > + const char *devname = cxl_memdev_get_devname(memdev); > + unsigned long long volatile_request; > + int rc; > + > + volatile_request = param.volatile_size; > + > + rc = validate_partition(memdev, volatile_request); > + if (rc) > + return rc; > + > + rc = cxl_memdev_set_partition_info(memdev, volatile_request, 0); > + if (rc) > + fprintf(stderr, "%s error: %s\n", devname, strerror(-rc)); > + return rc; One of the conventions from ndctl is that any command that modifies an object should also emit the updated state of that object in JSON. For example, "ndctl reconfigure-namespace" arranges for: unsigned long flags = UTIL_JSON_DAX | UTIL_JSON_DAX_DEVS; struct json_object *jndns; if (isatty(1)) flags |= UTIL_JSON_HUMAN; jndns = util_namespace_to_json(ndns, flags); if (jndns) printf("%s\n", json_object_to_json_string_ext(jndns, JSON_C_TO_STRING_PRETTY)); ...to dump the updated state of the namespace, so a similar util_memdev_to_json() seems appropriate here. However, perhaps that can come later. I have work-in-progress patches to move the core of cxl/list.c to a cxl_filter_walk() helper that would allow you to just call that to dump a listing for all the memdevs that were passed on the command line.
On Thu, Jan 06, 2022 at 02:19:08PM -0800, Dan Williams wrote: > On Mon, Jan 3, 2022 at 12:11 PM <alison.schofield@intel.com> wrote: > > snip > > One of the conventions from ndctl is that any command that modifies an > object should also emit the updated state of that object in JSON. For > example, "ndctl reconfigure-namespace" arranges for: > > unsigned long flags = UTIL_JSON_DAX | UTIL_JSON_DAX_DEVS; > struct json_object *jndns; > > if (isatty(1)) > flags |= UTIL_JSON_HUMAN; > jndns = util_namespace_to_json(ndns, flags); > if (jndns) > printf("%s\n", json_object_to_json_string_ext(jndns, > JSON_C_TO_STRING_PRETTY)); > > ...to dump the updated state of the namespace, so a similar > util_memdev_to_json() seems appropriate here. However, perhaps that > can come later. I have work-in-progress patches to move the core of > cxl/list.c to a cxl_filter_walk() helper that would allow you to just > call that to dump a listing for all the memdevs that were passed on > the command line. Will add. Thanks!
On Thu, Jan 06, 2022 at 01:35:03PM -0800, Dan Williams wrote: > On Mon, Jan 3, 2022 at 12:11 PM <alison.schofield@intel.com> wrote: > > > > unsigned offset; > > bool verbose; > > + unsigned long long volatile_size; > > This should be a string. > > See parse_size64() that handles suffixes like K,M,G,T, so you can do > things like "cxl set-partition -s 256M" and behave like the other > "--size" options in ndctl. Got it. Thanks! This will fix a couple of pesky UI things I was worried about.
On Thu, Jan 06, 2022 at 01:05:26PM -0800, Ira Weiny wrote: > On Mon, Jan 03, 2022 at 12:16:18PM -0800, Schofield, Alison wrote: > > From: Alison Schofield <alison.schofield@intel.com> > > > > "User will need a command line option for setting partition info. Add > 'set-partition-info' to the cxl command line tool." > > > The command 'cxl set-partition-info' operates on a CXL memdev, > > or a set of memdevs, allowing the user to change the partition > > layout of the device. > ^^^^^^ > device(s). > Got it. Thanks! > > snip > > Did I miss the update to the cxl-list command documentation? You must've blinked ;) See Patch 4 - cxl: add memdev partition information to cxl-list > snip > > > + > > + rc = cxl_memdev_set_partition_info(memdev, volatile_request, 0); > > CXL_CMD_SET_PARTITION_INFO_NO_FLAG? Yeah...I couldn't get to that at the last minute. Will figure that out and use it here. Thanks! > > Ira
On Fri, Jan 07, 2022 at 02:45:15PM -0800, Alison Schofield wrote: > On Thu, Jan 06, 2022 at 02:19:08PM -0800, Dan Williams wrote: > > On Mon, Jan 3, 2022 at 12:11 PM <alison.schofield@intel.com> wrote: > > > > > snip > > > > > One of the conventions from ndctl is that any command that modifies an > > object should also emit the updated state of that object in JSON. For > > example, "ndctl reconfigure-namespace" arranges for: > > > > unsigned long flags = UTIL_JSON_DAX | UTIL_JSON_DAX_DEVS; > > struct json_object *jndns; > > > > if (isatty(1)) > > flags |= UTIL_JSON_HUMAN; > > jndns = util_namespace_to_json(ndns, flags); > > if (jndns) > > printf("%s\n", json_object_to_json_string_ext(jndns, > > JSON_C_TO_STRING_PRETTY)); > > > > ...to dump the updated state of the namespace, so a similar > > util_memdev_to_json() seems appropriate here. However, perhaps that > > can come later. I have work-in-progress patches to move the core of > > cxl/list.c to a cxl_filter_walk() helper that would allow you to just > > call that to dump a listing for all the memdevs that were passed on > > the command line. > > Will add. Thanks! Oops...should've said - 'Will wait for helper.'
diff --git a/Documentation/cxl/cxl-set-partition-info.txt b/Documentation/cxl/cxl-set-partition-info.txt new file mode 100644 index 0000000..32418b6 --- /dev/null +++ b/Documentation/cxl/cxl-set-partition-info.txt @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0 + +cxl-set-partition-info(1) +========================= + +NAME +---- +cxl-set-partition-info - set the partitioning between volatile and persistent capacity on a CXL memdev + +SYNOPSIS +-------- +[verse] +'cxl set-partition-info <mem> [ [<mem1>..<memN>] [<options>]' + +include::partition-description.txt[] +Partition the device on the next device reset using the volatile capacity +requested. Using this command to change the size of the persistent capacity +shall result in the loss of stored data. + +OPTIONS +------- +include::partition-options.txt[] + +SEE ALSO +-------- +linkcxl:cxl-list[1], +CXL-2.0 8.2.9.5.2 diff --git a/Documentation/cxl/partition-description.txt b/Documentation/cxl/partition-description.txt new file mode 100644 index 0000000..b3efac8 --- /dev/null +++ b/Documentation/cxl/partition-description.txt @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 + +DESCRIPTION +----------- +Partition the device into volatile and persistent capacity. The change +in partitioning will become the “next” configuration, to become active +on the next device reset. + +Use "cxl list -m <memdev> -P" to examine the partition capacities +supported on a device. Paritionable capacity must exist on the +device. A partition_alignment of zero means no partitionable +capacity is available. + +Using this command to change the size of the persistent capacity shall +result in the loss of data stored. diff --git a/Documentation/cxl/partition-options.txt b/Documentation/cxl/partition-options.txt new file mode 100644 index 0000000..84e49c9 --- /dev/null +++ b/Documentation/cxl/partition-options.txt @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 + +<memory device(s)>:: +include::memdev-option.txt[] + +-s:: +--size=:: + Size in bytes of the volatile partition requested. + + Size must align to the devices partition_alignment. + Use 'cxl list -m <memdev> -P' to find partition_alignment. + + Size must be less than or equal to the devices partitionable bytes. + (total_capacity - volatile_only_capacity - persistent_only_capacity) + Use 'cxl list -m <memdev> -P' to find *_capacity values. + +-v:: + Turn on verbose debug messages in the library (if libcxl was built with + logging and debug enabled). diff --git a/Documentation/cxl/Makefile.am b/Documentation/cxl/Makefile.am index efabaa3..c5faf04 100644 --- a/Documentation/cxl/Makefile.am +++ b/Documentation/cxl/Makefile.am @@ -22,7 +22,8 @@ man1_MANS = \ cxl-list.1 \ cxl-read-labels.1 \ cxl-write-labels.1 \ - cxl-zero-labels.1 + cxl-zero-labels.1 \ + cxl-set-partition-info.1 EXTRA_DIST = $(man1_MANS) diff --git a/cxl/builtin.h b/cxl/builtin.h index 78eca6e..7f11f28 100644 --- a/cxl/builtin.h +++ b/cxl/builtin.h @@ -10,4 +10,5 @@ int cmd_read_labels(int argc, const char **argv, struct cxl_ctx *ctx); int cmd_zero_labels(int argc, const char **argv, struct cxl_ctx *ctx); int cmd_init_labels(int argc, const char **argv, struct cxl_ctx *ctx); int cmd_check_labels(int argc, const char **argv, struct cxl_ctx *ctx); +int cmd_set_partition_info(int argc, const char **argv, struct cxl_ctx *ctx); #endif /* _CXL_BUILTIN_H_ */ diff --git a/cxl/cxl.c b/cxl/cxl.c index 4b1661d..3153cf0 100644 --- a/cxl/cxl.c +++ b/cxl/cxl.c @@ -64,6 +64,7 @@ static struct cmd_struct commands[] = { { "zero-labels", .c_fn = cmd_zero_labels }, { "read-labels", .c_fn = cmd_read_labels }, { "write-labels", .c_fn = cmd_write_labels }, + { "set-partition-info", .c_fn = cmd_set_partition_info }, }; int main(int argc, const char **argv) diff --git a/cxl/memdev.c b/cxl/memdev.c index 5ee38e5..fa63317 100644 --- a/cxl/memdev.c +++ b/cxl/memdev.c @@ -6,6 +6,7 @@ #include <unistd.h> #include <limits.h> #include <util/log.h> +#include <util/size.h> #include <util/filter.h> #include <cxl/libcxl.h> #include <util/parse-options.h> @@ -23,6 +24,7 @@ static struct parameters { unsigned len; unsigned offset; bool verbose; + unsigned long long volatile_size; } param; #define fail(fmt, ...) \ @@ -47,6 +49,10 @@ OPT_UINTEGER('s', "size", ¶m.len, "number of label bytes to operate"), \ OPT_UINTEGER('O', "offset", ¶m.offset, \ "offset into the label area to start operation") +#define SET_PARTITION_OPTIONS() \ +OPT_U64('s', "volatile_size", ¶m.volatile_size, \ + "next volatile partition size in bytes") + static const struct option read_options[] = { BASE_OPTIONS(), LABEL_OPTIONS(), @@ -67,6 +73,12 @@ static const struct option zero_options[] = { OPT_END(), }; +static const struct option set_partition_options[] = { + BASE_OPTIONS(), + SET_PARTITION_OPTIONS(), + OPT_END(), +}; + static int action_zero(struct cxl_memdev *memdev, struct action_context *actx) { size_t size; @@ -174,6 +186,73 @@ out: return rc; } +static int validate_partition(struct cxl_memdev *memdev, + unsigned long long volatile_request) +{ + unsigned long long total_cap, volatile_only, persistent_only; + unsigned long long partitionable_bytes, partition_align_bytes; + const char *devname = cxl_memdev_get_devname(memdev); + struct cxl_cmd *cmd; + int rc; + + cmd = cxl_cmd_new_identify(memdev); + if (!cmd) + return -ENXIO; + rc = cxl_cmd_submit(cmd); + if (rc < 0) + goto err; + rc = cxl_cmd_get_mbox_status(cmd); + if (rc != 0) + goto err; + + partition_align_bytes = cxl_cmd_identify_get_partition_align(cmd); + if (partition_align_bytes == 0) { + fprintf(stderr, "%s: no partitionable capacity\n", devname); + rc = -EINVAL; + goto err; + } + + total_cap = cxl_cmd_identify_get_total_capacity(cmd); + volatile_only = cxl_cmd_identify_get_volatile_only_capacity(cmd); + persistent_only = cxl_cmd_identify_get_persistent_only_capacity(cmd); + + partitionable_bytes = total_cap - volatile_only - persistent_only; + + if (volatile_request > partitionable_bytes) { + fprintf(stderr, "%s: volatile size %lld exceeds partitionable capacity %lld\n", + devname, volatile_request, partitionable_bytes); + rc = -EINVAL; + goto err; + } + if (!IS_ALIGNED(volatile_request, partition_align_bytes)) { + fprintf(stderr, "%s: volatile size %lld is not partition aligned %lld\n", + devname, volatile_request, partition_align_bytes); + rc = -EINVAL; + } +err: + cxl_cmd_unref(cmd); + return rc; +} + +static int action_set_partition(struct cxl_memdev *memdev, + struct action_context *actx) +{ + const char *devname = cxl_memdev_get_devname(memdev); + unsigned long long volatile_request; + int rc; + + volatile_request = param.volatile_size; + + rc = validate_partition(memdev, volatile_request); + if (rc) + return rc; + + rc = cxl_memdev_set_partition_info(memdev, volatile_request, 0); + if (rc) + fprintf(stderr, "%s error: %s\n", devname, strerror(-rc)); + return rc; +} + static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx, int (*action)(struct cxl_memdev *memdev, struct action_context *actx), const struct option *options, const char *usage) @@ -322,3 +401,13 @@ int cmd_zero_labels(int argc, const char **argv, struct cxl_ctx *ctx) count > 1 ? "s" : ""); return count >= 0 ? 0 : EXIT_FAILURE; } + +int cmd_set_partition_info(int argc, const char **argv, struct cxl_ctx *ctx) +{ + int count = memdev_action(argc, argv, ctx, action_set_partition, + set_partition_options, + "cxl set-partition-info <mem0> [<mem1>..<memN>] [<options>]"); + fprintf(stderr, "set_partition %d mem%s\n", count >= 0 ? count : 0, + count > 1 ? "s" : ""); + return count >= 0 ? 0 : EXIT_FAILURE; +}