From: Jes Sorensen <jes@trained-monkey.org>
To: Oleksandr Shchirskyi <oleksandr.shchirskyi@intel.com>
Cc: linux-raid@vger.kernel.org
Subject: Re: [PATCH] imsm: nvme multipath support
Date: Mon, 8 Mar 2021 10:41:52 -0500 [thread overview]
Message-ID: <6230b3e8-5d8f-2cb2-1a84-edae0b350a6c@trained-monkey.org> (raw)
In-Reply-To: <20210115152824.51793-1-oleksandr.shchirskyi@intel.com>
On 1/15/21 10:28 AM, Oleksandr Shchirskyi wrote:
> From: Blazej Kucman <blazej.kucman@intel.com>
>
> Add support for nvme devices which are represented
> via nvme-subsystem.
> Print warning when multi-path disk is added to RAID
>
> Signed-off-by: Oleksandr Shchirskyi <oleksandr.shchirskyi@intel.com>
> Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
> ---
> platform-intel.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++-
> platform-intel.h | 2 ++
> super-intel.c | 38 ++++++++++++++--------
> 3 files changed, 108 insertions(+), 15 deletions(-)
Hi
A couple of nits on this one.
> diff --git a/platform-intel.c b/platform-intel.c
> index f1f6d4cd..2ee5a8da 100644
> --- a/platform-intel.c
> +++ b/platform-intel.c
> @@ -668,12 +668,71 @@ const struct imsm_orom *find_imsm_capability(struct sys_dev *hba)
> return NULL;
> }
>
> +/* Check whether the nvme device is represented by nvme subsytem,
> + * if yes virtual path should be changed to hardware device path,
> + * to allow IMSM capabilities detection.
> + * Returns:
> + * hardware path to device - if the device is represented via
> + * nvme virtual subsytem
> + * NULL - if the device is not represented via nvme virtual subsytem
> + */
> +char *get_nvme_multipath_dev_hw_path(const char *dev_path)
> +{
> + char buf[PATH_MAX];
> + DIR *dir;
> + struct dirent *ent;
> + char *nvme_subsystem_path = "/devices/virtual/nvme-subsystem";
> + char *ptr;
> + char *rp = NULL;
> +
> + if (!strstr(dev_path, nvme_subsystem_path))
> + return NULL;
> +
> + memcpy(buf, dev_path, sizeof(buf) - 1);
> + buf[PATH_MAX-1] = '\0';
You are indiscriminately copying PATH_MAX here, even if dev_path is only
a few characters long.
> + dir = opendir(buf);
> + if (!dir)
> + return NULL;
Second, the only thing you do with the copy is to pass it to opendir?
Why not just check the bounds and pass dev_path straight to opendir()?
> + for (ent = readdir(dir); ent; ent = readdir(dir)) {
> + if (!(strncmp(ent->d_name, "nvme", 4) == 0))
> + continue;
> +
> + // Needed is realpath to controller not to namespace.
Please use proper comments.
> + ptr = ent->d_name + 4;
> + if (!strstr(ptr, "n")) {
> + char buf1[PATH_MAX + NAME_MAX + 1];
That's a lot of stack usage in this function, why not just alloca() what
you need?
> +
> +/* Verify if multipath is supported by NVMe controller
> + * Returns:
> + * 0 - not supported
> + * 1 - supported
> + */
> +int is_multipath_nvme(int disk_fd)
> +{
> + char *ns_name;
> + char path_buf[PATH_MAX];
> + char ns_path[PATH_MAX];
> + char *nvme_subsystem_path = "/devices/virtual/nvme-subsystem";
> +
> + ns_name = fd2kname(disk_fd);
> + sprintf(path_buf, "/sys/block/%s", ns_name);
> + if (!realpath(path_buf, ns_path))
> + return 0;
> + if (!strstr(ns_path, nvme_subsystem_path))
> + return 0;
Given both path_buf and ns_path are throwaway buffers, why not just use
one and save the stack space?
Thanks,
Jes
prev parent reply other threads:[~2021-03-08 15:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-15 15:28 [PATCH] imsm: nvme multipath support Oleksandr Shchirskyi
2021-03-08 15:41 ` Jes Sorensen [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=6230b3e8-5d8f-2cb2-1a84-edae0b350a6c@trained-monkey.org \
--to=jes@trained-monkey.org \
--cc=linux-raid@vger.kernel.org \
--cc=oleksandr.shchirskyi@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).