diff mbox

[ndctl,2/5] make interface to check device/nfit/dsm_mask flags

Message ID 20170831102503.DA33.E1E9C6FF@jp.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Gotou, Yasunori/五島 康文 Aug. 31, 2017, 1:25 a.m. UTC
To check what feature can be called via ND_CMD_CALL, ndctl need to read
device/nfit/dsm_mask. This patch make an interface to check it in libndctl.c


Signed-off-by: Yasunori Goto <y-goto@jp.fujitsu.com>

---
 ndctl/lib/libndctl.c   | 13 +++++++++++++
 ndctl/lib/libndctl.sym |  1 +
 ndctl/libndctl.h.in    |  1 +
 3 files changed, 15 insertions(+)

Comments

Dan Williams Aug. 31, 2017, 3:25 a.m. UTC | #1
On Wed, Aug 30, 2017 at 6:25 PM, Yasunori Goto <y-goto@jp.fujitsu.com> wrote:
>
> To check what feature can be called via ND_CMD_CALL, ndctl need to read
> device/nfit/dsm_mask. This patch make an interface to check it in libndctl.c
>
>
> Signed-off-by: Yasunori Goto <y-goto@jp.fujitsu.com>
>
> ---
>  ndctl/lib/libndctl.c   | 13 +++++++++++++
>  ndctl/lib/libndctl.sym |  1 +
>  ndctl/libndctl.h.in    |  1 +
>  3 files changed, 15 insertions(+)
>
> diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
> index c2e0efb..803056d 100644
> --- a/ndctl/lib/libndctl.c
> +++ b/ndctl/lib/libndctl.c
> @@ -102,6 +102,7 @@ struct ndctl_bus {
>         size_t buf_len;
>         char *wait_probe_path;
>         unsigned long dsm_mask;
> +       unsigned long passthru_dsm_mask;
>  };
>
>  /**
> @@ -846,6 +847,12 @@ static void *add_bus(void *parent, int id, const char *ctl_base)
>                 bus->revision = strtoul(buf, NULL, 0);
>         }
>
> +       sprintf(path, "%s/device/nfit/dsm_mask", ctl_base);
> +       if (sysfs_read_attr(ctx, path, buf) < 0)
> +               bus->passthru_dsm_mask = 0;
> +       else
> +               bus->passthru_dsm_mask = strtoul(buf, NULL, 16);

Let's keep the base 0 and 16 like the other calls to strtoul in this file.

> +
>         sprintf(path, "%s/device/provider", ctl_base);
>         if (sysfs_read_attr(ctx, path, buf) < 0)
>                 goto err_read;
> @@ -1101,6 +1108,12 @@ NDCTL_EXPORT int ndctl_bus_is_cmd_supported(struct ndctl_bus *bus,
>         return !!(bus->dsm_mask & (1ULL << cmd));
>  }
>
> +NDCTL_EXPORT int ndctl_bus_is_passthru_cmd_supported(struct ndctl_bus *bus,
> +               int cmd)

I realize that I said to call this "passthru" before, but thinking
about it further these commands are truly nfit specific. The command
numbers that ndctl_bus_is_cmd_supported() reports could theoretically
be emulated by the kernel for other bus types, but these are truly
nfit specific. For example, another bus type could theoretically reuse
the same command numbers for other operations and
ndctl_bus_is_passthru_cmd_supported() would not be able to tell the
difference.

Let's add a new source file called ndctl/lib/nfit.c for these nfit
specifc commands and add a:

    ndctl_bus_is_nfit_cmd_supported()

...that can operate on nfit command numbers directly. We can later
decide to wrap that in a generic front-end if some future nvdimm bus
arrives with similar functionality.
diff mbox

Patch

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index c2e0efb..803056d 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -102,6 +102,7 @@  struct ndctl_bus {
 	size_t buf_len;
 	char *wait_probe_path;
 	unsigned long dsm_mask;
+	unsigned long passthru_dsm_mask;
 };
 
 /**
@@ -846,6 +847,12 @@  static void *add_bus(void *parent, int id, const char *ctl_base)
 		bus->revision = strtoul(buf, NULL, 0);
 	}
 
+	sprintf(path, "%s/device/nfit/dsm_mask", ctl_base);
+	if (sysfs_read_attr(ctx, path, buf) < 0)
+		bus->passthru_dsm_mask = 0;
+	else
+		bus->passthru_dsm_mask = strtoul(buf, NULL, 16);
+
 	sprintf(path, "%s/device/provider", ctl_base);
 	if (sysfs_read_attr(ctx, path, buf) < 0)
 		goto err_read;
@@ -1101,6 +1108,12 @@  NDCTL_EXPORT int ndctl_bus_is_cmd_supported(struct ndctl_bus *bus,
 	return !!(bus->dsm_mask & (1ULL << cmd));
 }
 
+NDCTL_EXPORT int ndctl_bus_is_passthru_cmd_supported(struct ndctl_bus *bus,
+		int cmd)
+{
+	return !!(bus->passthru_dsm_mask & (1ULL << cmd));
+}
+
 NDCTL_EXPORT unsigned int ndctl_bus_get_revision(struct ndctl_bus *bus)
 {
 	return bus->revision;
diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym
index b8ac65f..48b0a2f 100644
--- a/ndctl/lib/libndctl.sym
+++ b/ndctl/lib/libndctl.sym
@@ -30,6 +30,7 @@  global:
 	ndctl_bus_get_by_provider;
 	ndctl_bus_get_cmd_name;
 	ndctl_bus_is_cmd_supported;
+	ndctl_bus_is_passthru_cmd_supported;
 	ndctl_bus_has_nfit;
 	ndctl_bus_get_revision;
 	ndctl_bus_get_id;
diff --git a/ndctl/libndctl.h.in b/ndctl/libndctl.h.in
index 855d883..49b73a4 100644
--- a/ndctl/libndctl.h.in
+++ b/ndctl/libndctl.h.in
@@ -109,6 +109,7 @@  struct ndctl_bus *ndctl_bus_get_by_provider(struct ndctl_ctx *ctx,
 		const char *provider);
 const char *ndctl_bus_get_cmd_name(struct ndctl_bus *bus, int cmd);
 int ndctl_bus_is_cmd_supported(struct ndctl_bus *bus, int cmd);
+int ndctl_bus_is_passthru_cmd_supported(struct ndctl_bus *bus, int cmd);
 unsigned int ndctl_bus_get_revision(struct ndctl_bus *bus);
 unsigned int ndctl_bus_get_id(struct ndctl_bus *bus);
 const char *ndctl_bus_get_provider(struct ndctl_bus *bus);