libnvdimm, namespace: refactor uuid_show() into a namespace_to_uuid() helper

The ability to translate a generic struct device pointer into a
namespace uuid is a useful utility as we go to unify the blk and pmem
label scanning paths.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
This commit is contained in:
Dan Williams 2016-09-21 18:16:21 -07:00
Родитель ae8219f186
Коммит f95b4bca9e
1 изменённых файлов: 12 добавлений и 7 удалений

Просмотреть файл

@ -1032,22 +1032,27 @@ static ssize_t size_show(struct device *dev,
} }
static DEVICE_ATTR(size, S_IRUGO, size_show, size_store); static DEVICE_ATTR(size, S_IRUGO, size_show, size_store);
static ssize_t uuid_show(struct device *dev, static u8 *namespace_to_uuid(struct device *dev)
struct device_attribute *attr, char *buf)
{ {
u8 *uuid;
if (is_namespace_pmem(dev)) { if (is_namespace_pmem(dev)) {
struct nd_namespace_pmem *nspm = to_nd_namespace_pmem(dev); struct nd_namespace_pmem *nspm = to_nd_namespace_pmem(dev);
uuid = nspm->uuid; return nspm->uuid;
} else if (is_namespace_blk(dev)) { } else if (is_namespace_blk(dev)) {
struct nd_namespace_blk *nsblk = to_nd_namespace_blk(dev); struct nd_namespace_blk *nsblk = to_nd_namespace_blk(dev);
uuid = nsblk->uuid; return nsblk->uuid;
} else } else
return -ENXIO; return ERR_PTR(-ENXIO);
}
static ssize_t uuid_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
u8 *uuid = namespace_to_uuid(dev);
if (IS_ERR(uuid))
return PTR_ERR(uuid);
if (uuid) if (uuid)
return sprintf(buf, "%pUb\n", uuid); return sprintf(buf, "%pUb\n", uuid);
return sprintf(buf, "\n"); return sprintf(buf, "\n");