All of lore.kernel.org
 help / color / mirror / Atom feed
* nvme cli format question
@ 2019-04-03 23:03 Heitke, Kenneth
  2019-04-04 15:45 ` Keith Busch
  0 siblings, 1 reply; 2+ messages in thread
From: Heitke, Kenneth @ 2019-04-03 23:03 UTC (permalink / 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;
                         }
         }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* nvme cli format question
  2019-04-03 23:03 nvme cli format question Heitke, Kenneth
@ 2019-04-04 15:45 ` Keith Busch
  0 siblings, 0 replies; 2+ messages in thread
From: Keith Busch @ 2019-04-04 15:45 UTC (permalink / raw)


On Wed, Apr 03, 2019@04:03:25PM -0700, Heitke, Kenneth wrote:
> 
> 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).

Right, not needed. Code yanked.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-04-04 15:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-03 23:03 nvme cli format question Heitke, Kenneth
2019-04-04 15:45 ` Keith Busch

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.