libnvdimm: register nvdimm_bus devices with an nd_bus driver
authorDan Williams <dan.j.williams@intel.com>
Sat, 23 Jul 2016 06:46:08 +0000 (23:46 -0700)
committerDan Williams <dan.j.williams@intel.com>
Sat, 23 Jul 2016 18:06:33 +0000 (11:06 -0700)
commit18515942d61bdfd4b31ea13f9fbb9c18650c6818
tree6ae9bcd75578fbe43d3c07df9408acf2c78e16a8
parent5bf0b6e1af98a012e8871a89c2082353c3f70fee
libnvdimm: register nvdimm_bus devices with an nd_bus driver

A recent effort to add a new nvdimm bus provider attribute highlighted a
race between interrogating nvdimm_bus->nd_desc and nvdimm_bus tear down.
The typical way to handle these races is to take the device_lock() in
the attribute method and validate that the device is still active.  In
order for a device to be 'active' it needs to be associated with a
driver.  So, we create the small boilerplate for a driver and register
nvdimm_bus devices on the 'nvdimm_bus_type' bus.

A result of this change is that ndbusX devices now appear under
/sys/bus/nd/devices.  In fact this makes /sys/class/nd somewhat
redundant, but removing that will need to take a long deprecation period
given its use by ndctl binaries in the field.

This change naturally pulls code from drivers/nvdimm/core.c to
drivers/nvdimm/bus.c, so it is a nice code organization clean-up as
well.

Cc: Vishal Verma <vishal.l.verma@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/nvdimm/bus.c
drivers/nvdimm/core.c