Skip to content

Commit

Permalink
nvmet: Fix controller serial number inconsistency
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Sagi Grimberg committed Aug 4, 2016
1 parent 40e64e0 commit 28b8911
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
6 changes: 1 addition & 5 deletions drivers/nvme/target/admin-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/random.h>
#include <generated/utsrelease.h>
#include "nvmet.h"

Expand Down Expand Up @@ -83,7 +82,6 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
{
struct nvmet_ctrl *ctrl = req->sq->ctrl;
struct nvme_id_ctrl *id;
u64 serial;
u16 status = 0;

id = kzalloc(sizeof(*id), GFP_KERNEL);
Expand All @@ -96,10 +94,8 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
id->vid = 0;
id->ssvid = 0;

/* generate a random serial number as our controllers are ephemeral: */
get_random_bytes(&serial, sizeof(serial));
memset(id->sn, ' ', sizeof(id->sn));
snprintf(id->sn, sizeof(id->sn), "%llx", serial);
snprintf(id->sn, sizeof(id->sn), "%llx", ctrl->serial);

memset(id->mn, ' ', sizeof(id->mn));
strncpy((char *)id->mn, "Linux", sizeof(id->mn));
Expand Down
4 changes: 4 additions & 0 deletions drivers/nvme/target/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/random.h>
#include "nvmet.h"

static struct nvmet_fabrics_ops *nvmet_transports[NVMF_TRTYPE_MAX];
Expand Down Expand Up @@ -728,6 +729,9 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,
memcpy(ctrl->subsysnqn, subsysnqn, NVMF_NQN_SIZE);
memcpy(ctrl->hostnqn, hostnqn, NVMF_NQN_SIZE);

/* generate a random serial number as our controllers are ephemeral: */
get_random_bytes(&ctrl->serial, sizeof(ctrl->serial));

kref_init(&ctrl->ref);
ctrl->subsys = subsys;

Expand Down
1 change: 1 addition & 0 deletions drivers/nvme/target/nvmet.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ struct nvmet_ctrl {

struct mutex lock;
u64 cap;
u64 serial;
u32 cc;
u32 csts;

Expand Down

0 comments on commit 28b8911

Please sign in to comment.