linux-nvdimm.lists.01.org archive mirror
 help / color / mirror / Atom feed
From: Joao Martins <joao.m.martins@oracle.com>
To: linux-nvdimm@lists.01.org
Cc: Dan Williams <dan.j.williams@intel.com>,
	Vishal Verma <vishal.l.verma@intel.com>
Subject: [PATCH ndctl v1 1/8] daxctl: add daxctl_dev_{get,set}_align()
Date: Thu, 16 Jul 2020 19:47:00 +0100	[thread overview]
Message-ID: <20200716184707.23018-2-joao.m.martins@oracle.com> (raw)
In-Reply-To: <20200716184707.23018-1-joao.m.martins@oracle.com>

Add support for changing devices alignment.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
---
 daxctl/lib/libdaxctl-private.h |  1 +
 daxctl/lib/libdaxctl.c         | 34 ++++++++++++++++++++++++++++++++++
 daxctl/lib/libdaxctl.sym       |  2 ++
 daxctl/libdaxctl.h             |  2 ++
 4 files changed, 39 insertions(+)

diff --git a/daxctl/lib/libdaxctl-private.h b/daxctl/lib/libdaxctl-private.h
index 9f9c70d6024f..b307a8bc9438 100644
--- a/daxctl/lib/libdaxctl-private.h
+++ b/daxctl/lib/libdaxctl-private.h
@@ -99,6 +99,7 @@ struct daxctl_dev {
 	struct list_node list;
 	unsigned long long resource;
 	unsigned long long size;
+	unsigned long align;
 	struct kmod_module *module;
 	struct daxctl_region *region;
 	struct daxctl_memory *mem;
diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c
index 9b43b68facfe..c62e04bcdfd1 100644
--- a/daxctl/lib/libdaxctl.c
+++ b/daxctl/lib/libdaxctl.c
@@ -498,6 +498,11 @@ static void *add_dax_dev(void *parent, int id, const char *daxdev_base)
 		goto err_read;
 	dev->size = strtoull(buf, NULL, 0);
 
+	sprintf(path, "%s/align", daxdev_base);
+	if (sysfs_read_attr(ctx, path, buf) < 0)
+		goto err_read;
+	dev->align = strtoull(buf, NULL, 0);
+
 	dev->dev_path = strdup(daxdev_base);
 	if (!dev->dev_path)
 		goto err_read;
@@ -1086,6 +1091,35 @@ DAXCTL_EXPORT int daxctl_dev_set_size(struct daxctl_dev *dev, unsigned long long
 	return 0;
 }
 
+DAXCTL_EXPORT unsigned long daxctl_dev_get_align(struct daxctl_dev *dev)
+{
+	return dev->align;
+}
+
+DAXCTL_EXPORT int daxctl_dev_set_align(struct daxctl_dev *dev, unsigned long align)
+{
+	struct daxctl_ctx *ctx = daxctl_dev_get_ctx(dev);
+	char buf[SYSFS_ATTR_SIZE];
+	char *path = dev->dev_buf;
+	int len = dev->buf_len;
+
+	if (snprintf(path, len, "%s/align", dev->dev_path) >= len) {
+		err(ctx, "%s: buffer too small!\n",
+				daxctl_dev_get_devname(dev));
+		return -ENXIO;
+	}
+
+	sprintf(buf, "%#lx\n", align);
+	if (sysfs_write_attr(ctx, path, buf) < 0) {
+		err(ctx, "%s: failed to set align\n",
+				daxctl_dev_get_devname(dev));
+		return -ENXIO;
+	}
+
+	dev->align = align;
+	return 0;
+}
+
 DAXCTL_EXPORT int daxctl_dev_get_target_node(struct daxctl_dev *dev)
 {
 	return dev->target_node;
diff --git a/daxctl/lib/libdaxctl.sym b/daxctl/lib/libdaxctl.sym
index 33c926411037..c3d08179c9fd 100644
--- a/daxctl/lib/libdaxctl.sym
+++ b/daxctl/lib/libdaxctl.sym
@@ -81,4 +81,6 @@ global:
 	daxctl_dev_set_size;
 	daxctl_region_create_dev;
 	daxctl_region_destroy_dev;
+	daxctl_dev_get_align;
+	daxctl_dev_set_align;
 } LIBDAXCTL_7;
diff --git a/daxctl/libdaxctl.h b/daxctl/libdaxctl.h
index 2b14faad1895..b0bb5d78d357 100644
--- a/daxctl/libdaxctl.h
+++ b/daxctl/libdaxctl.h
@@ -71,6 +71,8 @@ int daxctl_dev_get_minor(struct daxctl_dev *dev);
 unsigned long long daxctl_dev_get_resource(struct daxctl_dev *dev);
 unsigned long long daxctl_dev_get_size(struct daxctl_dev *dev);
 int daxctl_dev_set_size(struct daxctl_dev *dev, unsigned long long size);
+unsigned long daxctl_dev_get_align(struct daxctl_dev *dev);
+int daxctl_dev_set_align(struct daxctl_dev *dev, unsigned long align);
 struct daxctl_ctx *daxctl_dev_get_ctx(struct daxctl_dev *dev);
 int daxctl_dev_is_enabled(struct daxctl_dev *dev);
 int daxctl_dev_disable(struct daxctl_dev *dev);
-- 
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

  reply	other threads:[~2020-07-16 18:47 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-16 18:46 [PATCH ndctl v1 0/8] daxctl: Add device align and range mapping allocation Joao Martins
2020-07-16 18:47 ` Joao Martins [this message]
2020-07-16 18:47 ` [PATCH ndctl v1 2/8] util/json: Print device align Joao Martins
2020-07-16 18:47 ` [PATCH ndctl v1 3/8] daxctl: add align support in reconfigure-device Joao Martins
2020-07-16 18:47 ` [PATCH ndctl v1 4/8] daxctl: add align support in create-device Joao Martins
2020-07-16 18:47 ` [PATCH ndctl v1 5/8] libdaxctl: add mapping iterator APIs Joao Martins
2020-07-16 18:47 ` [PATCH ndctl v1 6/8] daxctl: include mappings when listing Joao Martins
2020-07-16 18:47 ` [PATCH ndctl v1 7/8] libdaxctl: add daxctl_dev_set_mapping() Joao Martins
2020-07-16 18:47 ` [PATCH ndctl v1 8/8] daxctl: Allow restore devices from JSON metadata Joao Martins
2020-12-16 11:39 ` [PATCH ndctl v1 0/8] daxctl: Add device align and range mapping allocation Joao Martins
2020-12-16 18:42   ` Verma, Vishal L
2020-12-16 21:49     ` Joao Martins
2020-12-16 22:31       ` Dan Williams
2020-12-16 22:53         ` Joao Martins
2020-12-16 23:42           ` Dan Williams
2020-12-17 11:23             ` Joao Martins
2020-12-17 20:18               ` Verma, Vishal L
2020-12-16 19:13   ` Dan Williams
2020-12-16 21:35     ` Joao Martins

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=20200716184707.23018-2-joao.m.martins@oracle.com \
    --to=joao.m.martins@oracle.com \
    --cc=dan.j.williams@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).