Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: kenneth.heitke@intel.com (Heitke, Kenneth)
Subject: nvme cli format question
Date: Wed, 3 Apr 2019 17:03:25 -0600	[thread overview]
Message-ID: <754e9409-0255-220f-c4c2-18fe55dd4df3@intel.com> (raw)


What is the expected behavior when calling 'format' on a NVMe character
device? I see two problems with the code below.

1) If no namespace Id is specified and the device is not a block device,
then nvme_identify_ns() is never called and the 'ns' variable used in
the 'if (cfg.bs)' case is  uninitialized.

2) If the namespace_id is specified or determined from the block device,
then the 'cfg.bs' check is redundant (and done twice).

         if (cfg.namespace_id != NVME_NSID_ALL) {
                 err = nvme_identify_ns(fd, cfg.namespace_id, 0, &ns);
                 if (err) {
                         if (err < 0)
                                 perror("identify-namespace");
                         else
                                 fprintf(stderr,
                                         "NVME Admin command 
error:%s(%x)\n",
                                         nvme_status_to_string(err), err);
                         return err;
                 }
                 prev_lbaf = ns.flbas & 0xf;

                 if (cfg.bs) {
                         for (i = 0; i < 16; ++i) {
                                 if ((1ULL << ns.lbaf[i].ds) == cfg.bs &&
                                     ns.lbaf[i].ms == 0) {
                                         cfg.lbaf = i;
                                         break;
                                 }
                         }
                         if (cfg.lbaf == 0xff) {
                                 fprintf(stderr,
                                         "LBAF corresponding to block 
size %"PRIu64"(LBAF %u) not found\n",
                                         (uint64_t)cfg.bs, lbads);
                                 fprintf(stderr,
                                         "Please correct block size, or 
specify LBAF directly\n");
                                 return EINVAL;
                         }
                 }
         }
         if (cfg.bs) {
                 __u64 bs = cfg.bs;
                 bs = bs >> 1;
                 while (bs) {
                         ++lbads;
                         bs = bs >> 1;
                 }
                 for (i=0; i<16; ++i) {
                         if (ns.lbaf[i].ds == lbads && ns.lbaf[i].ms == 0) {
                                 cfg.lbaf = i;
                                 break;
                         }
                 }
                         if (cfg.lbaf == 0xff) {
                                 fprintf(stderr,
                                         "LBAF corresponding to block 
size %"PRIu64" (LBAF %u) not found\n",
                                         (uint64_t)cfg.bs, lbads);
                                 fprintf(stderr,
                                         "Please correct block size, or 
specify LBAF directly\n");
                                 return EINVAL;
                         }
         }

             reply	other threads:[~2019-04-03 23:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-03 23:03 Heitke, Kenneth [this message]
2019-04-04 15:45 ` nvme cli format question Keith Busch

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=754e9409-0255-220f-c4c2-18fe55dd4df3@intel.com \
    --to=kenneth.heitke@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