Skip to content

Commit 040fd04

Browse files
Yair Elharrarkeithbusch
authored andcommitted
nvme: change format default namespace id
Reject format to char device without an explicit namespace argument unless FNA requires format to all namespaces. Signed-off-by: Yair Elharrar <[email protected]> [formatting, changelog] Signed-off-by: Keith Busch <[email protected]>
1 parent 9bab71e commit 040fd04

4 files changed

Lines changed: 52 additions & 23 deletions

File tree

Documentation/nvme-format.1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'\" t
22
.\" Title: nvme-format
3-
.\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4-
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5-
.\" Date: 05/16/2019
3+
.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
4+
.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
5+
.\" Date: 07/28/2019
66
.\" Manual: NVMe Manual
77
.\" Source: NVMe
88
.\" Language: English
99
.\"
10-
.TH "NVME\-FORMAT" "1" "05/16/2019" "NVMe" "NVMe Manual"
10+
.TH "NVME\-FORMAT" "1" "07/28/2019" "NVMe" "NVMe Manual"
1111
.\" -----------------------------------------------------------------
1212
.\" * Define some portability stuff
1313
.\" -----------------------------------------------------------------
@@ -46,7 +46,7 @@ nvme-format \- Format an NVMe device
4646
.sp
4747
For the NVMe device given, send an nvme Format Namespace admin command and provides the results\&.
4848
.sp
49-
The <device> parameter is mandatory and may be either the NVMe character device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1)\&. If the character device is given, the namespace identifier will default to 0xffffffff to send the format to all namespace, but can be overridden to any namespace with the \fInamespace\-id\fR option\&. If the block device is given, the namespace identifier will default to the namespace id of the block device given, but can be overridden with the same option\&.
49+
The <device> parameter is mandatory and may be either the NVMe character device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1)\&. If the character device is given, and the controller does not support formatting of particular namespaces (ID_CTRL\&.FNA bit 0 enabled), then all namespaces will be formatted\&. If FNA is disabled, then the namespace identifier must be specified with the \fInamespace\-id\fR option; specify a value of 0xffffffff to send the format to all namespaces\&. If the block device is given, the namespace identifier will default to the namespace ID of the block device given, but can be overridden with the same option\&.
5050
.sp
5151
Note, the numeric suffix on the character device, for example the \fI0\fR in /dev/nvme0, does NOT indicate this device handle is the parent controller of any namespaces with the same suffix\&. The namespace handle\(cqs numeral may be coming from the subsystem identifier, which is independent of the controller\(cqs identifier\&. Do not assume any particular device relationship based on their names\&. If you do, you may irrevocably erase data on an unintended device\&.
5252
.sp
@@ -55,7 +55,7 @@ On success, the program will automatically issue BLKRRPART ioctl to force rescan
5555
.PP
5656
\-n <nsid>, \-\-namespace\-id=<nsid>
5757
.RS 4
58-
Send the format command for the specified nsid\&. This can be used to override the default value for either character device (0xffffffff) or the block device (result from NVME_IOCTL_ID)\&.
58+
Send the format command for the specified nsid\&. This can be used to override the default value for either character device (unspecified) or the block device (result from NVME_IOCTL_ID)\&.
5959
.RE
6060
.PP
6161
\-l <lbaf>, \-\-lbaf=<lbaf>

Documentation/nvme-format.html

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
12
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
23
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
34
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
45
<head>
56
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
6-
<meta name="generator" content="AsciiDoc 8.6.8" />
7+
<meta name="generator" content="AsciiDoc 8.6.10" />
78
<title>nvme-format(1)</title>
89
<style type="text/css">
910
/* Shared CSS for AsciiDoc xhtml11 and html5 backends */
@@ -94,7 +95,9 @@
9495
padding: 0;
9596
margin: 0;
9697
}
97-
98+
pre {
99+
white-space: pre-wrap;
100+
}
98101

99102
#author {
100103
color: #527bbd;
@@ -223,7 +226,7 @@
223226
}
224227

225228
div.imageblock div.content { padding-left: 0; }
226-
span.image img { border-style: none; }
229+
span.image img { border-style: none; vertical-align: text-bottom; }
227230
a.image:visited { color: white; }
228231

229232
dl {
@@ -766,11 +769,13 @@ <h2 id="_description">DESCRIPTION</h2>
766769
and provides the results.</p></div>
767770
<div class="paragraph"><p>The &lt;device&gt; parameter is mandatory and may be either the NVMe character
768771
device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1).
769-
If the character device is given, the namespace identifier will default
770-
to 0xffffffff to send the format to all namespace, but can be overridden
771-
to any namespace with the <em>namespace-id</em> option. If the block device
772-
is given, the namespace identifier will default to the namespace id of
773-
the block device given, but can be overridden with the same option.</p></div>
772+
If the character device is given, and the controller does not support
773+
formatting of particular namespaces (ID_CTRL.FNA bit 0 enabled), then all
774+
namespaces will be formatted. If FNA is disabled, then the namespace
775+
identifier must be specified with the <em>namespace-id</em> option; specify a
776+
value of 0xffffffff to send the format to all namespaces. If the block
777+
device is given, the namespace identifier will default to the namespace
778+
ID of the block device given, but can be overridden with the same option.</p></div>
774779
<div class="paragraph"><p>Note, the numeric suffix on the character device, for example the <em>0</em> in
775780
/dev/nvme0, does NOT indicate this device handle is the parent controller
776781
of any namespaces with the same suffix. The namespace handle&#8217;s numeral
@@ -799,7 +804,7 @@ <h2 id="_options">OPTIONS</h2>
799804
<p>
800805
Send the format command for the specified nsid. This can be
801806
used to override the default value for either character device
802-
(0xffffffff) or the block device (result from NVME_IOCTL_ID).
807+
(unspecified) or the block device (result from NVME_IOCTL_ID).
803808
</p>
804809
</dd>
805810
<dt class="hdlist1">
@@ -1020,7 +1025,8 @@ <h2 id="_nvme">NVME</h2>
10201025
<div id="footnotes"><hr /></div>
10211026
<div id="footer">
10221027
<div id="footer-text">
1023-
Last updated 2019-05-16 09:47:03 MDT
1028+
Last updated
1029+
2019-07-28 09:33:55 IDT
10241030
</div>
10251031
</div>
10261032
</body>

Documentation/nvme-format.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ and provides the results.
2525

2626
The <device> parameter is mandatory and may be either the NVMe character
2727
device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1).
28-
If the character device is given, the namespace identifier will default
29-
to 0xffffffff to send the format to all namespace, but can be overridden
30-
to any namespace with the 'namespace-id' option. If the block device
31-
is given, the namespace identifier will default to the namespace id of
32-
the block device given, but can be overridden with the same option.
28+
If the character device is given, and the controller does not support
29+
formatting of particular namespaces (ID_CTRL.FNA bit 0 enabled), then all
30+
namespaces will be formatted. If FNA is disabled, then the namespace
31+
identifier must be specified with the 'namespace-id' option; specify a
32+
value of 0xffffffff to send the format to all namespaces. If the block
33+
device is given, the namespace identifier will default to the namespace
34+
ID of the block device given, but can be overridden with the same option.
3335

3436
Note, the numeric suffix on the character device, for example the '0' in
3537
/dev/nvme0, does NOT indicate this device handle is the parent controller
@@ -51,7 +53,7 @@ OPTIONS
5153
--namespace-id=<nsid>::
5254
Send the format command for the specified nsid. This can be
5355
used to override the default value for either character device
54-
(0xffffffff) or the block device (result from NVME_IOCTL_ID).
56+
(unspecified) or the block device (result from NVME_IOCTL_ID).
5557

5658
-l <lbaf>::
5759
--lbaf=<lbaf>::

nvme.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3241,7 +3241,7 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu
32413241
};
32423242

32433243
struct config cfg = {
3244-
.namespace_id = NVME_NSID_ALL,
3244+
.namespace_id = 0,
32453245
.timeout = 600000,
32463246
.lbaf = 0xff,
32473247
.ses = 0,
@@ -3290,6 +3290,27 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu
32903290
err = -EINVAL;
32913291
goto close_fd;
32923292
}
3293+
} else if (cfg.namespace_id == 0) {
3294+
struct nvme_id_ctrl ctrl;
3295+
3296+
memset(&ctrl, 0, sizeof (struct nvme_id_ctrl));
3297+
err = nvme_identify_ctrl(fd, &ctrl);
3298+
if (err) {
3299+
perror("identify-ctrl");
3300+
goto close_fd;
3301+
}
3302+
if ((ctrl.fna & 1) == 1) {
3303+
/*
3304+
* FNA bit 0 set to 1: all namespaces ... shall be configured with the same
3305+
* attributes and a format (excluding secure erase) of any namespace results in a
3306+
* format of all namespaces.
3307+
*/
3308+
cfg.namespace_id = NVME_NSID_ALL;
3309+
} else {
3310+
fprintf(stderr, "Invalid namespace ID, specify a namespace to format or use '-n 0xffffffff' to format all namespaces on this controller.\n");
3311+
err = -EINVAL;
3312+
goto close_fd;
3313+
}
32933314
}
32943315
if (cfg.namespace_id != NVME_NSID_ALL) {
32953316
err = nvme_identify_ns(fd, cfg.namespace_id, 0, &ns);

0 commit comments

Comments
 (0)