Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libnvdimm: Export nvdimm shutdown helper, nvdimm_delete()

CXL is a hotplug bus and arranges for nvdimm devices to be dynamically
discovered and removed. The libnvdimm core manages shutdown of nvdimm
security operations when the device is unregistered. That functionality
is moved to nvdimm_delete() and invoked by the CXL-to-nvdimm glue code.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/162379910271.2993820.2955889139842401250.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>

+23 -15
+4 -15
drivers/nvdimm/bus.c
··· 396 396 if (dev->class) 397 397 return 0; 398 398 399 - if (is_nvdimm(dev)) { 400 - struct nvdimm *nvdimm = to_nvdimm(dev); 401 - bool dev_put = false; 402 - 403 - /* We are shutting down. Make state frozen artificially. */ 404 - nvdimm_bus_lock(dev); 405 - set_bit(NVDIMM_SECURITY_FROZEN, &nvdimm->sec.flags); 406 - if (test_and_clear_bit(NDD_WORK_PENDING, &nvdimm->flags)) 407 - dev_put = true; 408 - nvdimm_bus_unlock(dev); 409 - cancel_delayed_work_sync(&nvdimm->dwork); 410 - if (dev_put) 411 - put_device(dev); 412 - } 413 - nd_device_unregister(dev, ND_SYNC); 399 + if (is_nvdimm(dev)) 400 + nvdimm_delete(to_nvdimm(dev)); 401 + else 402 + nd_device_unregister(dev, ND_SYNC); 414 403 415 404 return 0; 416 405 }
+18
drivers/nvdimm/dimm_devs.c
··· 642 642 } 643 643 EXPORT_SYMBOL_GPL(__nvdimm_create); 644 644 645 + void nvdimm_delete(struct nvdimm *nvdimm) 646 + { 647 + struct device *dev = &nvdimm->dev; 648 + bool dev_put = false; 649 + 650 + /* We are shutting down. Make state frozen artificially. */ 651 + nvdimm_bus_lock(dev); 652 + set_bit(NVDIMM_SECURITY_FROZEN, &nvdimm->sec.flags); 653 + if (test_and_clear_bit(NDD_WORK_PENDING, &nvdimm->flags)) 654 + dev_put = true; 655 + nvdimm_bus_unlock(dev); 656 + cancel_delayed_work_sync(&nvdimm->dwork); 657 + if (dev_put) 658 + put_device(dev); 659 + nd_device_unregister(dev, ND_SYNC); 660 + } 661 + EXPORT_SYMBOL_GPL(nvdimm_delete); 662 + 645 663 static void shutdown_security_notify(void *data) 646 664 { 647 665 struct nvdimm *nvdimm = data;
+1
include/linux/libnvdimm.h
··· 278 278 return __nvdimm_create(nvdimm_bus, provider_data, groups, flags, 279 279 cmd_mask, num_flush, flush_wpq, NULL, NULL, NULL); 280 280 } 281 + void nvdimm_delete(struct nvdimm *nvdimm); 281 282 282 283 const struct nd_cmd_desc *nd_cmd_dimm_desc(int cmd); 283 284 const struct nd_cmd_desc *nd_cmd_bus_desc(int cmd);