All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linda Knippers <linda.knippers@hpe.com>
To: Vishal Verma <vishal.l.verma@intel.com>, linux-nvdimm@lists.01.org
Subject: Re: [ndctl PATCH v2] ndctl: print 'size' when creating/listing BTT namespaces
Date: Thu, 28 Jul 2016 16:48:31 -0400	[thread overview]
Message-ID: <579A6F9F.3060009@hpe.com> (raw)
In-Reply-To: <1469659164-26216-1-git-send-email-vishal.l.verma@intel.com>

On 07/27/2016 06:39 PM, Vishal Verma wrote:
> Print the usable size of a BTT namespace after removing driver overhead
> in the json for listing/creating a BTT namespace. This makes it
> consistent with other flavors of namespaces (dax, pfn).

Thanks, this works for me.  I also tried it on a kernel without the btt
patch that exposes the size to confirm that it does no harm with older kernels.

-- ljk
> 
> Cc: Dan Williams <dan.j.williams@intel.com>
> Reported-by: Linda Knippers <linda.knippers@hpe.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
> ---
> 
> v2:
> - For a create-namespace command, size was not shown as expected, and as
>   it did for 'ndctl list'. This was because after creating the namespace,
>   the 'size' field in the existing list of BTTs in libndctl needed to be
>   updated with the new value found in sysfs. Add this missing update.
> 
>  ndctl/lib/libndctl.c   | 14 ++++++++++++++
>  ndctl/lib/libndctl.sym |  1 +
>  ndctl/libndctl.h.in    |  1 +
>  ndctl/util/json.c      |  1 +
>  4 files changed, 17 insertions(+)
> 
> diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
> index 0722f79..8ad62c6 100644
> --- a/ndctl/lib/libndctl.c
> +++ b/ndctl/lib/libndctl.c
> @@ -271,6 +271,7 @@ struct ndctl_namespace {
>   * struct ndctl_btt - stacked block device provided sector atomicity
>   * @module: kernel module (nd_btt)
>   * @lbasize: sector size info
> + * @size: usable size of the btt after removing metadata etc
>   * @ndns: host namespace for the btt instance
>   * @region: parent region
>   * @btt_path: btt devpath
> @@ -284,6 +285,7 @@ struct ndctl_btt {
>  	struct ndctl_namespace *ndns;
>  	struct list_node list;
>  	struct ndctl_lbasize lbasize;
> +	unsigned long long size;
>  	char *btt_path;
>  	char *btt_buf;
>  	char *bdev;
> @@ -3614,9 +3616,16 @@ static int add_btt(void *parent, int id, const char *btt_base)
>  	if (parse_lbasize_supported(ctx, devname, buf, &btt->lbasize) < 0)
>  		goto err_read;
>  
> +	sprintf(path, "%s/size", btt_base);
> +	if (sysfs_read_attr(ctx, path, buf) < 0)
> +		btt->size = ULLONG_MAX;
> +	else
> +		btt->size = strtoull(buf, NULL, 0);
> +
>  	free(path);
>  	ndctl_btt_foreach(region, btt_dup)
>  		if (btt->id == btt_dup->id) {
> +			btt_dup->size = btt->size;
>  			free_btt(btt, NULL);
>  			return 1;
>  		}
> @@ -3705,6 +3714,11 @@ NDCTL_EXPORT void ndctl_btt_get_uuid(struct ndctl_btt *btt, uuid_t uu)
>  	memcpy(uu, btt->uuid, sizeof(uuid_t));
>  }
>  
> +NDCTL_EXPORT unsigned long long ndctl_btt_get_size(struct ndctl_btt *btt)
> +{
> +	return btt->size;
> +}
> +
>  NDCTL_EXPORT int ndctl_btt_set_uuid(struct ndctl_btt *btt, uuid_t uu)
>  {
>  	struct ndctl_ctx *ctx = ndctl_btt_get_ctx(btt);
> diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym
> index 6af267a..b5d2866 100644
> --- a/ndctl/lib/libndctl.sym
> +++ b/ndctl/lib/libndctl.sym
> @@ -196,6 +196,7 @@ global:
>  	ndctl_btt_get_num_sector_sizes;
>  	ndctl_btt_get_namespace;
>  	ndctl_btt_get_uuid;
> +	ndctl_btt_get_size;
>  	ndctl_btt_is_enabled;
>  	ndctl_btt_is_valid;
>  	ndctl_btt_get_devname;
> diff --git a/ndctl/libndctl.h.in b/ndctl/libndctl.h.in
> index 9e0e82a..451466a 100644
> --- a/ndctl/libndctl.h.in
> +++ b/ndctl/libndctl.h.in
> @@ -521,6 +521,7 @@ unsigned int ndctl_btt_get_sector_size(struct ndctl_btt *btt);
>  int ndctl_btt_get_num_sector_sizes(struct ndctl_btt *btt);
>  struct ndctl_namespace *ndctl_btt_get_namespace(struct ndctl_btt *btt);
>  void ndctl_btt_get_uuid(struct ndctl_btt *btt, uuid_t uu);
> +unsigned long long ndctl_btt_get_size(struct ndctl_btt *btt);
>  int ndctl_btt_is_enabled(struct ndctl_btt *btt);
>  int ndctl_btt_is_valid(struct ndctl_btt *btt);
>  const char *ndctl_btt_get_devname(struct ndctl_btt *btt);
> diff --git a/ndctl/util/json.c b/ndctl/util/json.c
> index a9c096c..c727bc2 100644
> --- a/ndctl/util/json.c
> +++ b/ndctl/util/json.c
> @@ -174,6 +174,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns)
>  		break;
>  	case NDCTL_NS_MODE_SAFE:
>  		jobj = json_object_new_string("sector");
> +		size = ndctl_btt_get_size(btt);
>  		break;
>  	case NDCTL_NS_MODE_RAW:
>  		size = ndctl_namespace_get_size(ndns);
> 

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

      reply	other threads:[~2016-07-28 20:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-27 22:39 [ndctl PATCH v2] ndctl: print 'size' when creating/listing BTT namespaces Vishal Verma
2016-07-28 20:48 ` Linda Knippers [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=579A6F9F.3060009@hpe.com \
    --to=linda.knippers@hpe.com \
    --cc=linux-nvdimm@lists.01.org \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.