diff options
author | Robert Elliott <elliott@hpe.com> | 2018-05-31 19:36:36 -0400 |
---|---|---|
committer | Dan Williams <dan.j.williams@intel.com> | 2018-06-01 00:07:33 -0400 |
commit | 254a4cd50b9fe2291a12b8902e08e56dcc4e9b10 (patch) | |
tree | ddca38d2bb5c822e2c17aa2cd69fff983b5f2b74 | |
parent | b04e217704b7f879c6b91222b066983a44a7a09f (diff) |
linvdimm, pmem: Preserve read-only setting for pmem devices
The pmem driver does not honor a forced read-only setting for very long:
$ blockdev --setro /dev/pmem0
$ blockdev --getro /dev/pmem0
1
followed by various commands like these:
$ blockdev --rereadpt /dev/pmem0
or
$ mkfs.ext4 /dev/pmem0
results in this in the kernel serial log:
nd_pmem namespace0.0: region0 read-write, marking pmem0 read-write
with the read-only setting lost:
$ blockdev --getro /dev/pmem0
0
That's from bus.c nvdimm_revalidate_disk(), which always applies the
setting from nd_region (which is initially based on the ACPI NFIT
NVDIMM state flags not_armed bit).
In contrast, commit 20bd1d026aac ("scsi: sd: Keep disk read-only when
re-reading partition") fixed this issue for SCSI devices to preserve
the previous setting if it was set to read-only.
This patch modifies bus.c to preserve any previous read-only setting.
It also eliminates the kernel serial log print except for cases where
read-write is changed to read-only, so it doesn't print read-only to
read-only non-changes.
Cc: <stable@vger.kernel.org>
Fixes: 581388209405 ("libnvdimm, nfit: handle unarmed dimms, mark namespaces read-only")
Signed-off-by: Robert Elliott <elliott@hpe.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
-rw-r--r-- | drivers/nvdimm/bus.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c index a64023690cad..b9e0d30e317a 100644 --- a/drivers/nvdimm/bus.c +++ b/drivers/nvdimm/bus.c | |||
@@ -566,14 +566,18 @@ int nvdimm_revalidate_disk(struct gendisk *disk) | |||
566 | { | 566 | { |
567 | struct device *dev = disk_to_dev(disk)->parent; | 567 | struct device *dev = disk_to_dev(disk)->parent; |
568 | struct nd_region *nd_region = to_nd_region(dev->parent); | 568 | struct nd_region *nd_region = to_nd_region(dev->parent); |
569 | const char *pol = nd_region->ro ? "only" : "write"; | 569 | int disk_ro = get_disk_ro(disk); |
570 | 570 | ||
571 | if (nd_region->ro == get_disk_ro(disk)) | 571 | /* |
572 | * Upgrade to read-only if the region is read-only preserve as | ||
573 | * read-only if the disk is already read-only. | ||
574 | */ | ||
575 | if (disk_ro || nd_region->ro == disk_ro) | ||
572 | return 0; | 576 | return 0; |
573 | 577 | ||
574 | dev_info(dev, "%s read-%s, marking %s read-%s\n", | 578 | dev_info(dev, "%s read-only, marking %s read-only\n", |
575 | dev_name(&nd_region->dev), pol, disk->disk_name, pol); | 579 | dev_name(&nd_region->dev), disk->disk_name); |
576 | set_disk_ro(disk, nd_region->ro); | 580 | set_disk_ro(disk, 1); |
577 | 581 | ||
578 | return 0; | 582 | return 0; |
579 | 583 | ||