@@ -1750,4 +1750,43 @@ extern u64 obd_heat_get(struct obd_heat_instance *instance,
unsigned int period_second);
extern void obd_heat_clear(struct obd_heat_instance *instance, int count);
+/* struct kobj_type */
+#define KOBJ_ATTR_GROUPS(_name) _name##_groups
+
+static inline
+struct attribute *_get_attr_matches(const struct kobj_type *typ,
+ const char *key, size_t keylen,
+ int (*is_match)(const char *, const char *,
+ size_t))
+{
+ int i;
+
+ for (i = 0; typ->default_groups[i]; i++) {
+ struct attribute **attrs;
+ int k;
+
+ attrs = (struct attribute **)typ->default_groups[i]->attrs;
+ for (k = 0; attrs[k]; k++) {
+ if (is_match(attrs[k]->name, key, keylen))
+ return (struct attribute *)attrs[k];
+ }
+ }
+
+ return NULL;
+}
+
+static inline
+int _attr_name_starts_with(const char *attr_name, const char *name, size_t len)
+{
+ return !strncmp(attr_name, name, len);
+}
+
+static inline
+struct attribute *get_attr_starts_with(const struct kobj_type *typ,
+ const char *name,
+ size_t len)
+{
+ return _get_attr_matches(typ, name, len, _attr_name_starts_with);
+}
+
#endif /* __LINUX_OBD_CLASS_H */
@@ -549,6 +549,8 @@ static struct attribute *ldlm_pl_attrs[] = {
NULL,
};
+ATTRIBUTE_GROUPS(ldlm_pl);
+
static void ldlm_pl_release(struct kobject *kobj)
{
struct ldlm_pool *pl = container_of(kobj, struct ldlm_pool,
@@ -557,7 +559,7 @@ static void ldlm_pl_release(struct kobject *kobj)
}
static struct kobj_type ldlm_pl_ktype = {
- .default_attrs = ldlm_pl_attrs,
+ .default_groups = KOBJ_ATTR_GROUPS(ldlm_pl),
.sysfs_ops = &lustre_sysfs_ops,
.release = ldlm_pl_release,
};
@@ -419,8 +419,10 @@ static void ldlm_ns_release(struct kobject *kobj)
complete(&ns->ns_kobj_unregister);
}
+ATTRIBUTE_GROUPS(ldlm_ns);
+
static struct kobj_type ldlm_ns_ktype = {
- .default_attrs = ldlm_ns_attrs,
+ .default_groups = KOBJ_ATTR_GROUPS(ldlm_ns),
.sysfs_ops = &lustre_sysfs_ops,
.release = ldlm_ns_release,
};
@@ -1759,6 +1759,8 @@ static struct attribute *llite_attrs[] = {
NULL,
};
+ATTRIBUTE_GROUPS(llite); /* creates llite_groups */
+
static void sbi_kobj_release(struct kobject *kobj)
{
struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info,
@@ -1767,7 +1769,7 @@ static void sbi_kobj_release(struct kobject *kobj)
}
static struct kobj_type sbi_ktype = {
- .default_attrs = llite_attrs,
+ .default_groups = KOBJ_ATTR_GROUPS(llite),
.sysfs_ops = &lustre_sysfs_ops,
.release = sbi_kobj_release,
};
@@ -290,11 +290,13 @@ static struct attribute *lmv_attrs[] = {
NULL,
};
+ATTRIBUTE_GROUPS(lmv); /* creates lmv_groups */
+
int lmv_tunables_init(struct obd_device *obd)
{
int rc;
- obd->obd_ktype.default_attrs = lmv_attrs;
+ obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(lmv);
rc = lprocfs_obd_setup(obd, true);
if (rc)
return rc;
@@ -277,12 +277,14 @@ static struct attribute *lov_attrs[] = {
NULL,
};
+ATTRIBUTE_GROUPS(lov); /* creates lov_groups */
+
int lov_tunables_init(struct obd_device *obd)
{
struct lov_obd *lov = &obd->u.lov;
int rc;
- obd->obd_ktype.default_attrs = lov_attrs;
+ obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(lov);
rc = lprocfs_obd_setup(obd, false);
if (rc)
return rc;
@@ -754,11 +754,13 @@ static struct attribute *mdc_attrs[] = {
NULL,
};
+ATTRIBUTE_GROUPS(mdc); /* creates mdc_groups */
+
int mdc_tunables_init(struct obd_device *obd)
{
int rc;
- obd->obd_ktype.default_attrs = mdc_attrs;
+ obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(mdc);
obd->obd_vars = lprocfs_mdc_obd_vars;
rc = lprocfs_obd_setup(obd, false);
@@ -1080,7 +1080,7 @@ ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
}
typ = get_ktype(kobj);
- if (!typ || !typ->default_attrs)
+ if (!typ || !typ->default_groups)
return -ENODEV;
print_lustre_cfg(lcfg);
@@ -1091,11 +1091,10 @@ ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
* or lctl conf_param lustre-OST0000.osc.max_dirty_mb=36
*/
for (i = 1; i < lcfg->lcfg_bufcount; i++) {
- struct attribute *attr;
+ struct attribute *attr = NULL;
size_t keylen;
char *value;
char *key;
- int j;
key = lustre_cfg_buf(lcfg, i);
/* Strip off prefix */
@@ -1116,15 +1115,7 @@ ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
keylen = value - key;
value++;
- attr = NULL;
- for (j = 0; typ->default_attrs[j]; j++) {
- if (!strncmp(typ->default_attrs[j]->name, key,
- keylen)) {
- attr = typ->default_attrs[j];
- break;
- }
- }
-
+ attr = get_attr_starts_with(typ, key, keylen);
if (!attr) {
char *envp[4], *param, *path;
@@ -872,12 +872,14 @@ static struct attribute *osc_attrs[] = {
NULL,
};
+ATTRIBUTE_GROUPS(osc); /* creates osc_groups */
+
int osc_tunables_init(struct obd_device *obd)
{
int rc;
obd->obd_vars = lprocfs_osc_obd_vars;
- obd->obd_ktype.default_attrs = osc_attrs;
+ obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(osc);
rc = lprocfs_obd_setup(obd, false);
if (rc)
return rc;
@@ -1125,6 +1125,8 @@ static struct attribute *ptlrpc_svc_attrs[] = {
NULL,
};
+ATTRIBUTE_GROUPS(ptlrpc_svc); /* creates ptlrpc_svc_groups */
+
static void ptlrpc_sysfs_svc_release(struct kobject *kobj)
{
struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
@@ -1134,7 +1136,7 @@ static void ptlrpc_sysfs_svc_release(struct kobject *kobj)
}
static struct kobj_type ptlrpc_svc_ktype = {
- .default_attrs = ptlrpc_svc_attrs,
+ .default_groups = KOBJ_ATTR_GROUPS(ptlrpc_svc),
.sysfs_ops = &lustre_sysfs_ops,
.release = ptlrpc_sysfs_svc_release,
};