diff options
author | Sagi Grimberg <sagi@grimberg.me> | 2016-08-04 04:18:49 -0400 |
---|---|---|
committer | Sagi Grimberg <sagi@grimberg.me> | 2016-08-04 10:45:10 -0400 |
commit | 28b89118539da03f4b188763e1b2fd1aec0f580a (patch) | |
tree | 2c004bc3fe811df5a1abf39771c82c9ef518c18c | |
parent | 40e64e07213201710a51e270595d6e6c028f9502 (diff) |
nvmet: Fix controller serial number inconsistency
The host is allowed to issue identify as many times
as it wants, we need to stay consistent when reporting
the serial number for a given controller.
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Christoph Hellwig <hch@lst.de>
-rw-r--r-- | drivers/nvme/target/admin-cmd.c | 6 | ||||
-rw-r--r-- | drivers/nvme/target/core.c | 4 | ||||
-rw-r--r-- | drivers/nvme/target/nvmet.h | 1 |
3 files changed, 6 insertions, 5 deletions
diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c index 2fac17a5ad53..47c564b5a289 100644 --- a/drivers/nvme/target/admin-cmd.c +++ b/drivers/nvme/target/admin-cmd.c | |||
@@ -13,7 +13,6 @@ | |||
13 | */ | 13 | */ |
14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/random.h> | ||
17 | #include <generated/utsrelease.h> | 16 | #include <generated/utsrelease.h> |
18 | #include "nvmet.h" | 17 | #include "nvmet.h" |
19 | 18 | ||
@@ -83,7 +82,6 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req) | |||
83 | { | 82 | { |
84 | struct nvmet_ctrl *ctrl = req->sq->ctrl; | 83 | struct nvmet_ctrl *ctrl = req->sq->ctrl; |
85 | struct nvme_id_ctrl *id; | 84 | struct nvme_id_ctrl *id; |
86 | u64 serial; | ||
87 | u16 status = 0; | 85 | u16 status = 0; |
88 | 86 | ||
89 | id = kzalloc(sizeof(*id), GFP_KERNEL); | 87 | id = kzalloc(sizeof(*id), GFP_KERNEL); |
@@ -96,10 +94,8 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req) | |||
96 | id->vid = 0; | 94 | id->vid = 0; |
97 | id->ssvid = 0; | 95 | id->ssvid = 0; |
98 | 96 | ||
99 | /* generate a random serial number as our controllers are ephemeral: */ | ||
100 | get_random_bytes(&serial, sizeof(serial)); | ||
101 | memset(id->sn, ' ', sizeof(id->sn)); | 97 | memset(id->sn, ' ', sizeof(id->sn)); |
102 | snprintf(id->sn, sizeof(id->sn), "%llx", serial); | 98 | snprintf(id->sn, sizeof(id->sn), "%llx", ctrl->serial); |
103 | 99 | ||
104 | memset(id->mn, ' ', sizeof(id->mn)); | 100 | memset(id->mn, ' ', sizeof(id->mn)); |
105 | strncpy((char *)id->mn, "Linux", sizeof(id->mn)); | 101 | strncpy((char *)id->mn, "Linux", sizeof(id->mn)); |
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index 8a891ca53367..6559d5afa7bf 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c | |||
@@ -13,6 +13,7 @@ | |||
13 | */ | 13 | */ |
14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/random.h> | ||
16 | #include "nvmet.h" | 17 | #include "nvmet.h" |
17 | 18 | ||
18 | static struct nvmet_fabrics_ops *nvmet_transports[NVMF_TRTYPE_MAX]; | 19 | static struct nvmet_fabrics_ops *nvmet_transports[NVMF_TRTYPE_MAX]; |
@@ -728,6 +729,9 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn, | |||
728 | memcpy(ctrl->subsysnqn, subsysnqn, NVMF_NQN_SIZE); | 729 | memcpy(ctrl->subsysnqn, subsysnqn, NVMF_NQN_SIZE); |
729 | memcpy(ctrl->hostnqn, hostnqn, NVMF_NQN_SIZE); | 730 | memcpy(ctrl->hostnqn, hostnqn, NVMF_NQN_SIZE); |
730 | 731 | ||
732 | /* generate a random serial number as our controllers are ephemeral: */ | ||
733 | get_random_bytes(&ctrl->serial, sizeof(ctrl->serial)); | ||
734 | |||
731 | kref_init(&ctrl->ref); | 735 | kref_init(&ctrl->ref); |
732 | ctrl->subsys = subsys; | 736 | ctrl->subsys = subsys; |
733 | 737 | ||
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 57dd6d834c28..76b6eedccaf9 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h | |||
@@ -113,6 +113,7 @@ struct nvmet_ctrl { | |||
113 | 113 | ||
114 | struct mutex lock; | 114 | struct mutex lock; |
115 | u64 cap; | 115 | u64 cap; |
116 | u64 serial; | ||
116 | u32 cc; | 117 | u32 cc; |
117 | u32 csts; | 118 | u32 csts; |
118 | 119 | ||