* [PATCH V2] nvme-cli/list: fix when nvme device can not be open
@ 2017-08-02 7:51 Guan Junxiong
2017-08-02 8:02 ` Keith Busch
0 siblings, 1 reply; 2+ messages in thread
From: Guan Junxiong @ 2017-08-02 7:51 UTC (permalink / raw)
This patch checks the validity of fd returned by open operation on
the nvme divices. For example, when a user who doesn't have the
permission to open the device trys to use nvme list command to list
nvme devices, the fd is returned as -1 and errno indicates permission
denied.
In addition,this patch closes the current open device before
processing the next device.
Signed-off-by: Guan Junxiong <guanjunxiong at huawei.com>
Reviewed-by: Christoph Hellwig <hch at lst.de>
---
The V1 version was _applied_ in the mail list , but isn't applied into
nvme-cli mainstream. Here comes the new version:
change since V1:
* rebase latest master branch and fix conflicts
* add reviewed-by tag of Christoph
nvme.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/nvme.c b/nvme.c
index 235a1bb..b4a039a 100644
--- a/nvme.c
+++ b/nvme.c
@@ -911,7 +911,13 @@ static int list(int argc, char **argv, struct command *cmd, struct plugin *plugi
for (i = 0; i < n; i++) {
snprintf(path, sizeof(path), "%s%s", dev, devices[i]->d_name);
fd = open(path, O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "can not open %s: %s\n", path,
+ strerror(errno));
+ return errno;
+ }
ret = get_nvme_info(fd, &list_items[i], path);
+ close(fd);
if (ret)
return ret;
}
--
2.11.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH V2] nvme-cli/list: fix when nvme device can not be open
2017-08-02 7:51 [PATCH V2] nvme-cli/list: fix when nvme device can not be open Guan Junxiong
@ 2017-08-02 8:02 ` Keith Busch
0 siblings, 0 replies; 2+ messages in thread
From: Keith Busch @ 2017-08-02 8:02 UTC (permalink / raw)
On Wed, Aug 02, 2017@03:51:09PM +0800, Guan Junxiong wrote:
> This patch checks the validity of fd returned by open operation on
> the nvme divices. For example, when a user who doesn't have the
> permission to open the device trys to use nvme list command to list
> nvme devices, the fd is returned as -1 and errno indicates permission
> denied.
> In addition,this patch closes the current open device before
> processing the next device.
>
> Signed-off-by: Guan Junxiong <guanjunxiong at huawei.com>
> Reviewed-by: Christoph Hellwig <hch at lst.de>
Applied to the repo, thanks for the resend.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-08-02 8:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-02 7:51 [PATCH V2] nvme-cli/list: fix when nvme device can not be open Guan Junxiong
2017-08-02 8:02 ` Keith Busch
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).