mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
libnvdimm: Move attribute groups to device type
Statically initialize the attribute groups for each libnvdimm device_type. This is a preparation step for removing unnecessary exports of attributes that can be included in the device_type by default. Also take the opportunity to mark 'struct device_type' instances const. Cc: Ira Weiny <ira.weiny@intel.com> Cc: Vishal Verma <vishal.l.verma@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> Link: https://lore.kernel.org/r/157309900111.1582359.2445687530383470348.stgit@dwillia2-desk3.amr.corp.intel.com
This commit is contained in:
@@ -25,17 +25,6 @@ static void nd_btt_release(struct device *dev)
|
|||||||
kfree(nd_btt);
|
kfree(nd_btt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct device_type nd_btt_device_type = {
|
|
||||||
.name = "nd_btt",
|
|
||||||
.release = nd_btt_release,
|
|
||||||
};
|
|
||||||
|
|
||||||
bool is_nd_btt(struct device *dev)
|
|
||||||
{
|
|
||||||
return dev->type == &nd_btt_device_type;
|
|
||||||
}
|
|
||||||
EXPORT_SYMBOL(is_nd_btt);
|
|
||||||
|
|
||||||
struct nd_btt *to_nd_btt(struct device *dev)
|
struct nd_btt *to_nd_btt(struct device *dev)
|
||||||
{
|
{
|
||||||
struct nd_btt *nd_btt = container_of(dev, struct nd_btt, dev);
|
struct nd_btt *nd_btt = container_of(dev, struct nd_btt, dev);
|
||||||
@@ -178,6 +167,18 @@ static const struct attribute_group *nd_btt_attribute_groups[] = {
|
|||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const struct device_type nd_btt_device_type = {
|
||||||
|
.name = "nd_btt",
|
||||||
|
.release = nd_btt_release,
|
||||||
|
.groups = nd_btt_attribute_groups,
|
||||||
|
};
|
||||||
|
|
||||||
|
bool is_nd_btt(struct device *dev)
|
||||||
|
{
|
||||||
|
return dev->type == &nd_btt_device_type;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(is_nd_btt);
|
||||||
|
|
||||||
static struct device *__nd_btt_create(struct nd_region *nd_region,
|
static struct device *__nd_btt_create(struct nd_region *nd_region,
|
||||||
unsigned long lbasize, u8 *uuid,
|
unsigned long lbasize, u8 *uuid,
|
||||||
struct nd_namespace_common *ndns)
|
struct nd_namespace_common *ndns)
|
||||||
@@ -204,7 +205,6 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
|
|||||||
dev_set_name(dev, "btt%d.%d", nd_region->id, nd_btt->id);
|
dev_set_name(dev, "btt%d.%d", nd_region->id, nd_btt->id);
|
||||||
dev->parent = &nd_region->dev;
|
dev->parent = &nd_region->dev;
|
||||||
dev->type = &nd_btt_device_type;
|
dev->type = &nd_btt_device_type;
|
||||||
dev->groups = nd_btt_attribute_groups;
|
|
||||||
device_initialize(&nd_btt->dev);
|
device_initialize(&nd_btt->dev);
|
||||||
if (ndns && !__nd_attach_ndns(&nd_btt->dev, ndns, &nd_btt->ndns)) {
|
if (ndns && !__nd_attach_ndns(&nd_btt->dev, ndns, &nd_btt->ndns)) {
|
||||||
dev_dbg(&ndns->dev, "failed, already claimed by %s\n",
|
dev_dbg(&ndns->dev, "failed, already claimed by %s\n",
|
||||||
|
@@ -23,17 +23,6 @@ static void nd_dax_release(struct device *dev)
|
|||||||
kfree(nd_dax);
|
kfree(nd_dax);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct device_type nd_dax_device_type = {
|
|
||||||
.name = "nd_dax",
|
|
||||||
.release = nd_dax_release,
|
|
||||||
};
|
|
||||||
|
|
||||||
bool is_nd_dax(struct device *dev)
|
|
||||||
{
|
|
||||||
return dev ? dev->type == &nd_dax_device_type : false;
|
|
||||||
}
|
|
||||||
EXPORT_SYMBOL(is_nd_dax);
|
|
||||||
|
|
||||||
struct nd_dax *to_nd_dax(struct device *dev)
|
struct nd_dax *to_nd_dax(struct device *dev)
|
||||||
{
|
{
|
||||||
struct nd_dax *nd_dax = container_of(dev, struct nd_dax, nd_pfn.dev);
|
struct nd_dax *nd_dax = container_of(dev, struct nd_dax, nd_pfn.dev);
|
||||||
@@ -43,13 +32,18 @@ struct nd_dax *to_nd_dax(struct device *dev)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL(to_nd_dax);
|
EXPORT_SYMBOL(to_nd_dax);
|
||||||
|
|
||||||
static const struct attribute_group *nd_dax_attribute_groups[] = {
|
static const struct device_type nd_dax_device_type = {
|
||||||
&nd_pfn_attribute_group,
|
.name = "nd_dax",
|
||||||
&nd_device_attribute_group,
|
.release = nd_dax_release,
|
||||||
&nd_numa_attribute_group,
|
.groups = nd_pfn_attribute_groups,
|
||||||
NULL,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool is_nd_dax(struct device *dev)
|
||||||
|
{
|
||||||
|
return dev ? dev->type == &nd_dax_device_type : false;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(is_nd_dax);
|
||||||
|
|
||||||
static struct nd_dax *nd_dax_alloc(struct nd_region *nd_region)
|
static struct nd_dax *nd_dax_alloc(struct nd_region *nd_region)
|
||||||
{
|
{
|
||||||
struct nd_pfn *nd_pfn;
|
struct nd_pfn *nd_pfn;
|
||||||
@@ -69,7 +63,6 @@ static struct nd_dax *nd_dax_alloc(struct nd_region *nd_region)
|
|||||||
|
|
||||||
dev = &nd_pfn->dev;
|
dev = &nd_pfn->dev;
|
||||||
dev_set_name(dev, "dax%d.%d", nd_region->id, nd_pfn->id);
|
dev_set_name(dev, "dax%d.%d", nd_region->id, nd_pfn->id);
|
||||||
dev->groups = nd_dax_attribute_groups;
|
|
||||||
dev->type = &nd_dax_device_type;
|
dev->type = &nd_dax_device_type;
|
||||||
dev->parent = &nd_region->dev;
|
dev->parent = &nd_region->dev;
|
||||||
|
|
||||||
|
@@ -44,35 +44,9 @@ static void namespace_blk_release(struct device *dev)
|
|||||||
kfree(nsblk);
|
kfree(nsblk);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct device_type namespace_io_device_type = {
|
static bool is_namespace_pmem(const struct device *dev);
|
||||||
.name = "nd_namespace_io",
|
static bool is_namespace_blk(const struct device *dev);
|
||||||
.release = namespace_io_release,
|
static bool is_namespace_io(const struct device *dev);
|
||||||
};
|
|
||||||
|
|
||||||
static const struct device_type namespace_pmem_device_type = {
|
|
||||||
.name = "nd_namespace_pmem",
|
|
||||||
.release = namespace_pmem_release,
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct device_type namespace_blk_device_type = {
|
|
||||||
.name = "nd_namespace_blk",
|
|
||||||
.release = namespace_blk_release,
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool is_namespace_pmem(const struct device *dev)
|
|
||||||
{
|
|
||||||
return dev ? dev->type == &namespace_pmem_device_type : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool is_namespace_blk(const struct device *dev)
|
|
||||||
{
|
|
||||||
return dev ? dev->type == &namespace_blk_device_type : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool is_namespace_io(const struct device *dev)
|
|
||||||
{
|
|
||||||
return dev ? dev->type == &namespace_io_device_type : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int is_uuid_busy(struct device *dev, void *data)
|
static int is_uuid_busy(struct device *dev, void *data)
|
||||||
{
|
{
|
||||||
@@ -1680,6 +1654,39 @@ static const struct attribute_group *nd_namespace_attribute_groups[] = {
|
|||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const struct device_type namespace_io_device_type = {
|
||||||
|
.name = "nd_namespace_io",
|
||||||
|
.release = namespace_io_release,
|
||||||
|
.groups = nd_namespace_attribute_groups,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct device_type namespace_pmem_device_type = {
|
||||||
|
.name = "nd_namespace_pmem",
|
||||||
|
.release = namespace_pmem_release,
|
||||||
|
.groups = nd_namespace_attribute_groups,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct device_type namespace_blk_device_type = {
|
||||||
|
.name = "nd_namespace_blk",
|
||||||
|
.release = namespace_blk_release,
|
||||||
|
.groups = nd_namespace_attribute_groups,
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool is_namespace_pmem(const struct device *dev)
|
||||||
|
{
|
||||||
|
return dev ? dev->type == &namespace_pmem_device_type : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool is_namespace_blk(const struct device *dev)
|
||||||
|
{
|
||||||
|
return dev ? dev->type == &namespace_blk_device_type : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool is_namespace_io(const struct device *dev)
|
||||||
|
{
|
||||||
|
return dev ? dev->type == &namespace_io_device_type : false;
|
||||||
|
}
|
||||||
|
|
||||||
struct nd_namespace_common *nvdimm_namespace_common_probe(struct device *dev)
|
struct nd_namespace_common *nvdimm_namespace_common_probe(struct device *dev)
|
||||||
{
|
{
|
||||||
struct nd_btt *nd_btt = is_nd_btt(dev) ? to_nd_btt(dev) : NULL;
|
struct nd_btt *nd_btt = is_nd_btt(dev) ? to_nd_btt(dev) : NULL;
|
||||||
@@ -2095,7 +2102,6 @@ static struct device *nd_namespace_blk_create(struct nd_region *nd_region)
|
|||||||
}
|
}
|
||||||
dev_set_name(dev, "namespace%d.%d", nd_region->id, nsblk->id);
|
dev_set_name(dev, "namespace%d.%d", nd_region->id, nsblk->id);
|
||||||
dev->parent = &nd_region->dev;
|
dev->parent = &nd_region->dev;
|
||||||
dev->groups = nd_namespace_attribute_groups;
|
|
||||||
|
|
||||||
return &nsblk->common.dev;
|
return &nsblk->common.dev;
|
||||||
}
|
}
|
||||||
@@ -2126,7 +2132,6 @@ static struct device *nd_namespace_pmem_create(struct nd_region *nd_region)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
dev_set_name(dev, "namespace%d.%d", nd_region->id, nspm->id);
|
dev_set_name(dev, "namespace%d.%d", nd_region->id, nspm->id);
|
||||||
dev->groups = nd_namespace_attribute_groups;
|
|
||||||
nd_namespace_pmem_set_resource(nd_region, nspm, 0);
|
nd_namespace_pmem_set_resource(nd_region, nspm, 0);
|
||||||
|
|
||||||
return dev;
|
return dev;
|
||||||
@@ -2625,7 +2630,6 @@ int nd_region_register_namespaces(struct nd_region *nd_region, int *err)
|
|||||||
if (id < 0)
|
if (id < 0)
|
||||||
break;
|
break;
|
||||||
dev_set_name(dev, "namespace%d.%d", nd_region->id, id);
|
dev_set_name(dev, "namespace%d.%d", nd_region->id, id);
|
||||||
dev->groups = nd_namespace_attribute_groups;
|
|
||||||
nd_device_register(dev);
|
nd_device_register(dev);
|
||||||
}
|
}
|
||||||
if (i)
|
if (i)
|
||||||
|
@@ -302,7 +302,7 @@ struct device *nd_pfn_create(struct nd_region *nd_region);
|
|||||||
struct device *nd_pfn_devinit(struct nd_pfn *nd_pfn,
|
struct device *nd_pfn_devinit(struct nd_pfn *nd_pfn,
|
||||||
struct nd_namespace_common *ndns);
|
struct nd_namespace_common *ndns);
|
||||||
int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig);
|
int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig);
|
||||||
extern struct attribute_group nd_pfn_attribute_group;
|
extern const struct attribute_group *nd_pfn_attribute_groups[];
|
||||||
#else
|
#else
|
||||||
static inline int nd_pfn_probe(struct device *dev,
|
static inline int nd_pfn_probe(struct device *dev,
|
||||||
struct nd_namespace_common *ndns)
|
struct nd_namespace_common *ndns)
|
||||||
|
@@ -26,17 +26,6 @@ static void nd_pfn_release(struct device *dev)
|
|||||||
kfree(nd_pfn);
|
kfree(nd_pfn);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct device_type nd_pfn_device_type = {
|
|
||||||
.name = "nd_pfn",
|
|
||||||
.release = nd_pfn_release,
|
|
||||||
};
|
|
||||||
|
|
||||||
bool is_nd_pfn(struct device *dev)
|
|
||||||
{
|
|
||||||
return dev ? dev->type == &nd_pfn_device_type : false;
|
|
||||||
}
|
|
||||||
EXPORT_SYMBOL(is_nd_pfn);
|
|
||||||
|
|
||||||
struct nd_pfn *to_nd_pfn(struct device *dev)
|
struct nd_pfn *to_nd_pfn(struct device *dev)
|
||||||
{
|
{
|
||||||
struct nd_pfn *nd_pfn = container_of(dev, struct nd_pfn, dev);
|
struct nd_pfn *nd_pfn = container_of(dev, struct nd_pfn, dev);
|
||||||
@@ -287,18 +276,30 @@ static umode_t pfn_visible(struct kobject *kobj, struct attribute *a, int n)
|
|||||||
return a->mode;
|
return a->mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct attribute_group nd_pfn_attribute_group = {
|
static struct attribute_group nd_pfn_attribute_group = {
|
||||||
.attrs = nd_pfn_attributes,
|
.attrs = nd_pfn_attributes,
|
||||||
.is_visible = pfn_visible,
|
.is_visible = pfn_visible,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct attribute_group *nd_pfn_attribute_groups[] = {
|
const struct attribute_group *nd_pfn_attribute_groups[] = {
|
||||||
&nd_pfn_attribute_group,
|
&nd_pfn_attribute_group,
|
||||||
&nd_device_attribute_group,
|
&nd_device_attribute_group,
|
||||||
&nd_numa_attribute_group,
|
&nd_numa_attribute_group,
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const struct device_type nd_pfn_device_type = {
|
||||||
|
.name = "nd_pfn",
|
||||||
|
.release = nd_pfn_release,
|
||||||
|
.groups = nd_pfn_attribute_groups,
|
||||||
|
};
|
||||||
|
|
||||||
|
bool is_nd_pfn(struct device *dev)
|
||||||
|
{
|
||||||
|
return dev ? dev->type == &nd_pfn_device_type : false;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(is_nd_pfn);
|
||||||
|
|
||||||
struct device *nd_pfn_devinit(struct nd_pfn *nd_pfn,
|
struct device *nd_pfn_devinit(struct nd_pfn *nd_pfn,
|
||||||
struct nd_namespace_common *ndns)
|
struct nd_namespace_common *ndns)
|
||||||
{
|
{
|
||||||
@@ -337,7 +338,6 @@ static struct nd_pfn *nd_pfn_alloc(struct nd_region *nd_region)
|
|||||||
|
|
||||||
dev = &nd_pfn->dev;
|
dev = &nd_pfn->dev;
|
||||||
dev_set_name(dev, "pfn%d.%d", nd_region->id, nd_pfn->id);
|
dev_set_name(dev, "pfn%d.%d", nd_region->id, nd_pfn->id);
|
||||||
dev->groups = nd_pfn_attribute_groups;
|
|
||||||
dev->type = &nd_pfn_device_type;
|
dev->type = &nd_pfn_device_type;
|
||||||
dev->parent = &nd_region->dev;
|
dev->parent = &nd_region->dev;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user