libnvdimm, pmem: flush posted-write queues on shutdown
authorDan Williams <dan.j.williams@intel.com>
Sat, 9 Jul 2016 07:12:52 +0000 (00:12 -0700)
committerDan Williams <dan.j.williams@intel.com>
Tue, 12 Jul 2016 22:13:48 +0000 (15:13 -0700)
Commit writes to media on system shutdown or pmem driver unload.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/nvdimm/bus.c
drivers/nvdimm/pmem.c
include/linux/nd.h

index e4882e63beceebfecdaea53938dfa8029db5222a..1cc7880320fe68a8bfb7e326070c09e997e3c2ab 100644 (file)
@@ -136,6 +136,21 @@ static int nvdimm_bus_remove(struct device *dev)
        return rc;
 }
 
+static void nvdimm_bus_shutdown(struct device *dev)
+{
+       struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev);
+       struct nd_device_driver *nd_drv = NULL;
+
+       if (dev->driver)
+               nd_drv = to_nd_device_driver(dev->driver);
+
+       if (nd_drv && nd_drv->shutdown) {
+               nd_drv->shutdown(dev);
+               dev_dbg(&nvdimm_bus->dev, "%s.shutdown(%s)\n",
+                               dev->driver->name, dev_name(dev));
+       }
+}
+
 void nd_device_notify(struct device *dev, enum nvdimm_event event)
 {
        device_lock(dev);
@@ -214,6 +229,7 @@ static struct bus_type nvdimm_bus_type = {
        .match = nvdimm_bus_match,
        .probe = nvdimm_bus_probe,
        .remove = nvdimm_bus_remove,
+       .shutdown = nvdimm_bus_shutdown,
 };
 
 static ASYNC_DOMAIN_EXCLUSIVE(nd_async_domain);
index 9d9c1beef0205f84949872f881791b0dfefb407c..8bfc6acc2e43f49996a0edbc3dd714b760781310 100644 (file)
@@ -349,9 +349,16 @@ static int nd_pmem_remove(struct device *dev)
 {
        if (is_nd_btt(dev))
                nvdimm_namespace_detach_btt(to_nd_btt(dev));
+       nvdimm_flush(to_nd_region(dev->parent));
+
        return 0;
 }
 
+static void nd_pmem_shutdown(struct device *dev)
+{
+       nvdimm_flush(to_nd_region(dev->parent));
+}
+
 static void nd_pmem_notify(struct device *dev, enum nvdimm_event event)
 {
        struct pmem_device *pmem = dev_get_drvdata(dev);
@@ -391,6 +398,7 @@ static struct nd_device_driver nd_pmem_driver = {
        .probe = nd_pmem_probe,
        .remove = nd_pmem_remove,
        .notify = nd_pmem_notify,
+       .shutdown = nd_pmem_shutdown,
        .drv = {
                .name = "nd_pmem",
        },
index aee2761d294cbc6a06ae32de2c66dd4533cade3d..1ecd64643512215a233c79c8bc384e66e079dbbc 100644 (file)
@@ -26,6 +26,7 @@ struct nd_device_driver {
        unsigned long type;
        int (*probe)(struct device *dev);
        int (*remove)(struct device *dev);
+       void (*shutdown)(struct device *dev);
        void (*notify)(struct device *dev, enum nvdimm_event event);
 };