dax: enable dax in the presence of known media errors (badblocks)
[deliverable/linux.git] / drivers / nvdimm / pmem.c
index 8e09c544d892eadfff181bc67c6f9f135adefcaa..c447579bd853cfccd55303fb3d623435b6d965ab 100644 (file)
@@ -103,6 +103,20 @@ static int pmem_do_bvec(struct pmem_device *pmem, struct page *page,
                        flush_dcache_page(page);
                }
        } else {
+               /*
+                * Note that we write the data both before and after
+                * clearing poison.  The write before clear poison
+                * handles situations where the latest written data is
+                * preserved and the clear poison operation simply marks
+                * the address range as valid without changing the data.
+                * In this case application software can assume that an
+                * interrupted write will either return the new good
+                * data or an error.
+                *
+                * However, if pmem_clear_poison() leaves the data in an
+                * indeterminate state we need to perform the write
+                * after clear poison.
+                */
                flush_dcache_page(page);
                memcpy_to_pmem(pmem_addr, mem + off, len);
                if (unlikely(bad_pmem)) {
@@ -168,14 +182,22 @@ static int pmem_rw_page(struct block_device *bdev, sector_t sector,
 }
 
 static long pmem_direct_access(struct block_device *bdev, sector_t sector,
-                     void __pmem **kaddr, pfn_t *pfn)
+                     void __pmem **kaddr, pfn_t *pfn, long size)
 {
        struct pmem_device *pmem = bdev->bd_disk->private_data;
        resource_size_t offset = sector * 512 + pmem->data_offset;
 
+       if (unlikely(is_bad_pmem(&pmem->bb, sector, size)))
+               return -EIO;
        *kaddr = pmem->virt_addr + offset;
        *pfn = phys_to_pfn_t(pmem->phys_addr + offset, pmem->pfn_flags);
 
+       /*
+        * If badblocks are present, limit known good range to the
+        * requested range.
+        */
+       if (unlikely(pmem->bb.count))
+               return size;
        return pmem->size - pmem->pfn_pad - offset;
 }
 
This page took 0.026508 seconds and 5 git commands to generate.