Whamcloud - gitweb
LU-16120 build: Add support for kobj_type default_groups 65/48365/12
authorShaun Tancheff <shaun.tancheff@hpe.com>
Fri, 16 Dec 2022 09:41:54 +0000 (03:41 -0600)
committerOleg Drokin <green@whamcloud.com>
Tue, 3 Jan 2023 21:35:12 +0000 (21:35 +0000)
Linux commit v5.1-rc3-29-gaa30f47cf666
  kobject: Add support for default attribute groups to kobj_type

Linux commit v5.18-rc1-2-gcdb4f26a63c3
  kobject: kobj_type: remove default_attrs

Switch to using kobj_type default_groups when it is available.
Provide support for default_attrs for older kernels.

HPE-bug-id: LUS-11196
Signed-off-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Change-Id: I43b03c67c22307293a2abc444aa1a73889ca09ee
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/48365
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
22 files changed:
libcfs/autoconf/lustre-libcfs.m4
libcfs/include/libcfs/linux/linux-misc.h
lustre/include/obd_class.h
lustre/ldlm/ldlm_pool.c
lustre/ldlm/ldlm_resource.c
lustre/llite/lproc_llite.c
lustre/lmv/lproc_lmv.c
lustre/lod/lproc_lod.c
lustre/lov/lproc_lov.c
lustre/mdc/lproc_mdc.c
lustre/mdd/mdd_lproc.c
lustre/mdt/mdt_coordinator.c
lustre/mdt/mdt_lproc.c
lustre/mgc/lproc_mgc.c
lustre/mgs/lproc_mgs.c
lustre/obdclass/obd_config.c
lustre/ofd/lproc_ofd.c
lustre/osc/lproc_osc.c
lustre/osd-ldiskfs/osd_lproc.c
lustre/osd-zfs/osd_lproc.c
lustre/osp/lproc_osp.c
lustre/ptlrpc/lproc_ptlrpc.c

index 525de78..459ca0d 100644 (file)
@@ -1533,6 +1533,28 @@ EXTRA_KCFLAGS="$tmp_flags"
 ]) # LIBCFS_GET_REQUEST_KEY_AUTH
 
 #
+# LIBCFS_KOBJ_TYPE_DEFAULT_GROUPS
+#
+# Linux commit v5.1-rc3-29-gaa30f47cf666
+#    kobject: Add support for default attribute groups to kobj_type
+# Linux commit v5.18-rc1-2-gcdb4f26a63c3
+#    kobject: kobj_type: remove default_attrs
+#
+AC_DEFUN([LIBCFS_KOBJ_TYPE_DEFAULT_GROUPS],[
+LB_CHECK_COMPILE([does struct kobj_type have 'default_groups' member],
+kobj_type_default_groups, [
+               #include <linux/kobject.h>
+       ],[
+               struct kobj_type *kobj_type = NULL;
+               void *has = kobj_type->default_groups;
+               (void) has;
+       ],[
+               AC_DEFINE(HAVE_KOBJ_TYPE_DEFAULT_GROUPS, 1,
+                       [struct kobj_type has 'default_groups' member])
+       ])
+]) # LIBCFS_KOBJ_TYPE_DEFAULT_GROUPS
+
+#
 # LIBCFS_LOOKUP_USER_KEY
 #
 # kernel 5.3 commit 3cf5d076fb4d48979f382bc9452765bf8b79e740
@@ -2073,6 +2095,8 @@ LIBCFS_HAVE_IOV_ITER_TYPE
 LIBCFS_GENRADIX
 LIBCFS_MM_TOTALRAM_PAGES_FUNC
 LIBCFS_GET_REQUEST_KEY_AUTH
+# 5.2
+LIBCFS_KOBJ_TYPE_DEFAULT_GROUPS
 # 5.3
 LIBCFS_LOOKUP_USER_KEY
 LIBCFS_FORCE_SIG_WITH_TASK
index faec22b..5e21896 100644 (file)
@@ -166,4 +166,13 @@ static inline void *cfs_kallsyms_lookup_name(const char *name)
 }
 #endif
 
+#ifndef HAVE_KOBJ_TYPE_DEFAULT_GROUPS
+#define default_groups                 default_attrs
+#define KOBJ_ATTR_GROUPS(_name)                _name##_attrs
+#define KOBJ_ATTRIBUTE_GROUPS(_name)
+#else
+#define KOBJ_ATTR_GROUPS(_name)                _name##_groups
+#define KOBJ_ATTRIBUTE_GROUPS(_name)   ATTRIBUTE_GROUPS(_name)
+#endif
+
 #endif /* __LIBCFS_LINUX_MISC_H__ */
index 769a902..26b043e 100644 (file)
@@ -1912,4 +1912,61 @@ extern __u64 obd_heat_get(struct obd_heat_instance *instance,
                          unsigned int time_second, unsigned int weight,
                          unsigned int period_second);
 extern void obd_heat_clear(struct obd_heat_instance *instance, int count);
+
+/* struct kobj_type */
+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;
+
+#ifdef HAVE_KOBJ_TYPE_DEFAULT_GROUPS
+       for (i = 0; typ->default_groups[i]; i++) {
+               int k;
+               struct attribute **attrs;
+
+               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];
+               }
+       }
+#else
+       for (i = 0; typ->default_attrs[i]; i++) {
+               if (is_match(typ->default_attrs[i]->name, key, keylen))
+                       return typ->default_attrs[i];
+       }
+#endif
+       return NULL;
+}
+
+static inline
+int _attr_name_exact(const char *attr_name, const char *key, size_t len)
+{
+       return !strcmp(attr_name, key);
+}
+
+static inline
+struct attribute *get_attr_by_name(const struct kobj_type *typ,
+                                  const char *name)
+{
+       return _get_attr_matches(typ, name, 0, _attr_name_exact);
+}
+
+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 */
index 197e3da..83ca764 100644 (file)
@@ -792,6 +792,8 @@ static struct attribute *ldlm_pl_attrs[] = {
        NULL,
 };
 
+KOBJ_ATTRIBUTE_GROUPS(ldlm_pl);
+
 static void ldlm_pl_release(struct kobject *kobj)
 {
        struct ldlm_pool *pl = container_of(kobj, struct ldlm_pool,
@@ -800,7 +802,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,
 };
index cf17024..1616cb2 100644 (file)
@@ -702,8 +702,10 @@ static void ldlm_ns_release(struct kobject *kobj)
        complete(&ns->ns_kobj_unregister);
 }
 
+KOBJ_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,
 };
index 4ac6033..7776381 100644 (file)
@@ -1799,6 +1799,8 @@ static struct attribute *llite_attrs[] = {
        NULL,
 };
 
+KOBJ_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,
@@ -1807,7 +1809,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,
 };
index 1f118f1..3dee359 100644 (file)
@@ -290,11 +290,13 @@ static struct attribute *lmv_attrs[] = {
        NULL,
 };
 
+KOBJ_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)
                goto out_failed;
index 3130a72..2a164d8 100644 (file)
@@ -1354,6 +1354,8 @@ static struct attribute *lod_attrs[] = {
        NULL,
 };
 
+KOBJ_ATTRIBUTE_GROUPS(lod); /* creates lod_groups from lod_attrs */
+
 /**
  * Initialize procfs entries for LOD.
  *
@@ -1369,7 +1371,7 @@ int lod_procfs_init(struct lod_device *lod)
        struct kobject *lov;
        int rc;
 
-       lod->lod_dt_dev.dd_ktype.default_attrs = lod_attrs;
+       lod->lod_dt_dev.dd_ktype.default_groups = KOBJ_ATTR_GROUPS(lod);
        rc = dt_tunables_init(&lod->lod_dt_dev, obd->obd_type, obd->obd_name,
                              NULL);
        if (rc) {
index 442a491..3898868 100644 (file)
@@ -276,12 +276,14 @@ static struct attribute *lov_attrs[] = {
        NULL,
 };
 
+KOBJ_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)
                GOTO(out, rc);
index 26e86a8..f932dfc 100644 (file)
@@ -761,11 +761,13 @@ static struct attribute *mdc_attrs[] = {
        NULL,
 };
 
+KOBJ_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);
index 81fd96d..49216ec 100644 (file)
@@ -771,6 +771,8 @@ static struct attribute *mdd_attrs[] = {
        NULL,
 };
 
+KOBJ_ATTRIBUTE_GROUPS(mdd); /* creates mdd_groups */
+
 static void mdd_sysfs_release(struct kobject *kobj)
 {
        struct mdd_device *mdd = container_of(kobj, struct mdd_device,
@@ -802,7 +804,7 @@ int mdd_procfs_init(struct mdd_device *mdd, const char *name)
        /* put reference taken by class_search_type */
        kobject_put(&type->typ_kobj);
 
-       mdd->mdd_ktype.default_attrs = mdd_attrs;
+       mdd->mdd_ktype.default_groups = KOBJ_ATTR_GROUPS(mdd);
        mdd->mdd_ktype.release = mdd_sysfs_release;
        mdd->mdd_ktype.sysfs_ops = &lustre_sysfs_ops;
 
index 239629a..d64a22e 100644 (file)
@@ -2614,6 +2614,8 @@ static struct attribute *hsm_attrs[] = {
        NULL,
 };
 
+KOBJ_ATTRIBUTE_GROUPS(hsm); /* creates hsm_groups from hsm_attrs */
+
 static void hsm_kobj_release(struct kobject *kobj)
 {
        struct coordinator *cdt = container_of(kobj, struct coordinator,
@@ -2626,7 +2628,7 @@ static void hsm_kobj_release(struct kobject *kobj)
 }
 
 static struct kobj_type hsm_ktype = {
-       .default_attrs  = hsm_attrs,
+       .default_groups = KOBJ_ATTR_GROUPS(hsm),
        .sysfs_ops      = &lustre_sysfs_ops,
        .release        = hsm_kobj_release,
 };
index 39f8264..8ca3a52 100644 (file)
@@ -1545,6 +1545,8 @@ static struct attribute *mdt_attrs[] = {
        NULL,
 };
 
+KOBJ_ATTRIBUTE_GROUPS(mdt); /* creates mdt_groups from mdt_attrs */
+
 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
        { .name =       "recovery_status",
          .fops =       &mdt_recovery_status_fops               },
@@ -1688,7 +1690,7 @@ int mdt_tunables_init(struct mdt_device *mdt, const char *name)
        ENTRY;
        LASSERT(name != NULL);
 
-       obd->obd_ktype.default_attrs = mdt_attrs;
+       obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(mdt);
        obd->obd_vars = lprocfs_mdt_obd_vars;
        rc = lprocfs_obd_setup(obd, true);
        if (rc) {
index 84cd38b..051e315 100644 (file)
@@ -116,11 +116,13 @@ static struct attribute *mgc_attrs[] = {
        NULL,
 };
 
+KOBJ_ATTRIBUTE_GROUPS(mgc);
+
 int mgc_tunables_init(struct obd_device *obd)
 {
        int rc;
 
-       obd->obd_ktype.default_attrs = mgc_attrs;
+       obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(mgc);
        obd->obd_debugfs_vars = ldebugfs_mgc_obd_vars;
        rc = lprocfs_obd_setup(obd, true);
        if (rc)
index c0b0fa6..41cf93d 100644 (file)
@@ -256,17 +256,19 @@ static struct attribute *mgs_attrs[] = {
        NULL,
 };
 
+KOBJ_ATTRIBUTE_GROUPS(mgs); /* creates mgs_groups from mgs_attrs */
+
 int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name)
 {
        int osd_len = strlen(osd_name) - strlen("-osd");
        struct obd_device *obd = mgs->mgs_obd;
        const struct kobj_type *bottom_type;
+       struct attribute *attr;
        struct obd_device *osd_obd;
        int rc;
-       int i;
 
        obd->obd_vars = lprocfs_mgs_obd_vars;
-       obd->obd_ktype.default_attrs = mgs_attrs;
+       obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(mgs);
        rc = lprocfs_obd_setup(obd, true);
        if (rc != 0)
                GOTO(out, rc);
@@ -304,21 +306,12 @@ int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name)
        }
 
        bottom_type = get_ktype(&mgs->mgs_bottom->dd_kobj);
-
-       for (i = 0; bottom_type->default_attrs[i]; i++) {
-               if (strcmp(bottom_type->default_attrs[i]->name, "fstype") == 0) {
-                       mgs->mgs_fstype = bottom_type->default_attrs[i];
-                       break;
-               }
-       }
-
-       for (i = 0; bottom_type->default_attrs[i]; i++) {
-               if (strcmp(bottom_type->default_attrs[i]->name, "mntdev") == 0) {
-                       mgs->mgs_mntdev = bottom_type->default_attrs[i];
-                       break;
-               }
-       }
-
+       attr = get_attr_by_name(bottom_type, "fstype");
+       if (attr)
+               mgs->mgs_fstype = attr;
+       attr = get_attr_by_name(bottom_type, "mntdev");
+       if (attr)
+               mgs->mgs_fstype = mgs->mgs_mntdev;
        osd_obd = mgs->mgs_bottom->dd_lu_dev.ld_obd;
        mgs->mgs_proc_osd = lprocfs_add_symlink("osd",
                                                obd->obd_proc_entry,
index b8610e3..9845a8f 100644 (file)
@@ -1637,7 +1637,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);
@@ -1648,11 +1648,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 */
@@ -1674,15 +1673,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;
 
index 32ff9d3..f24bb16 100644 (file)
@@ -1129,6 +1129,8 @@ static struct attribute *ofd_attrs[] = {
        NULL,
 };
 
+KOBJ_ATTRIBUTE_GROUPS(ofd); /* creates ofd_groups from ofd_attrs */
+
 /**
  * Initialize all needed procfs entries for OFD device.
  *
@@ -1147,7 +1149,7 @@ int ofd_tunables_init(struct ofd_device *ofd)
        /* lprocfs must be setup before the ofd so state can be safely added
         * to /proc incrementally as the ofd is setup
         */
-       obd->obd_ktype.default_attrs = ofd_attrs;
+       obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(ofd);
        obd->obd_vars = lprocfs_ofd_obd_vars;
        rc = lprocfs_obd_setup(obd, false);
        if (rc) {
index 58d95f3..78a8c14 100644 (file)
@@ -884,12 +884,14 @@ static struct attribute *osc_attrs[] = {
        NULL,
 };
 
+KOBJ_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;
index 1984700..13ba77d 100644 (file)
@@ -815,6 +815,8 @@ static struct attribute *ldiskfs_attrs[] = {
        NULL,
 };
 
+KOBJ_ATTRIBUTE_GROUPS(ldiskfs); /* creates ldiskfs_groups from ldiskfs_attrs */
+
 int osd_procfs_init(struct osd_device *osd, const char *name)
 {
        struct obd_type *type;
@@ -835,7 +837,7 @@ int osd_procfs_init(struct osd_device *osd, const char *name)
        /* put reference taken by class_search_type */
        kobject_put(&type->typ_kobj);
 
-       osd->od_dt_dev.dd_ktype.default_attrs = ldiskfs_attrs;
+       osd->od_dt_dev.dd_ktype.default_groups = KOBJ_ATTR_GROUPS(ldiskfs);
        rc = dt_tunables_init(&osd->od_dt_dev, type, name,
                              ldebugfs_osd_obd_vars);
        if (rc) {
index 317101f..44bc966 100644 (file)
@@ -355,6 +355,8 @@ struct ldebugfs_vars ldebugfs_osd_obd_vars[] = {
        { 0 }
 };
 
+KOBJ_ATTRIBUTE_GROUPS(zfs); /* creates zfs_groups from zfs_attrs */
+
 int osd_procfs_init(struct osd_device *osd, const char *name)
 {
        struct obd_type *type;
@@ -373,7 +375,7 @@ int osd_procfs_init(struct osd_device *osd, const char *name)
        /* put reference taken by class_search_type */
        kobject_put(&type->typ_kobj);
 
-       osd->od_dt_dev.dd_ktype.default_attrs = zfs_attrs;
+       osd->od_dt_dev.dd_ktype.default_groups = KOBJ_ATTR_GROUPS(zfs);
        rc = dt_tunables_init(&osd->od_dt_dev, type, name,
                              ldebugfs_osd_obd_vars);
        if (rc) {
index a93cfbd..f4b0e8a 100644 (file)
@@ -1155,6 +1155,8 @@ static struct attribute *osp_obd_attrs[] = {
        NULL,
 };
 
+KOBJ_ATTRIBUTE_GROUPS(osp_obd); /* creates osp_obd_groups from osp_obd_attrs */
+
 static struct attribute *osp_md_attrs[] = {
        /* First two for compatiability reasons */
        &lustre_attr_lfsck_max_rpcs_in_flight.attr,
@@ -1174,6 +1176,8 @@ static struct attribute *osp_md_attrs[] = {
        NULL,
 };
 
+KOBJ_ATTRIBUTE_GROUPS(osp_md); /* creates osp_md_groups from osp_md_attrs */
+
 void osp_tunables_fini(struct osp_device *osp)
 {
        struct obd_device *obd = osp->opd_obd;
@@ -1208,10 +1212,12 @@ void osp_tunables_init(struct osp_device *osp)
        int rc;
 
        if (osp->opd_connect_mdt) {
-               osp->opd_dt_dev.dd_ktype.default_attrs = osp_md_attrs;
+               osp->opd_dt_dev.dd_ktype.default_groups =
+                       KOBJ_ATTR_GROUPS(osp_md);
                obd->obd_debugfs_vars = ldebugfs_osp_md_vars;
        } else {
-               osp->opd_dt_dev.dd_ktype.default_attrs = osp_obd_attrs;
+               osp->opd_dt_dev.dd_ktype.default_groups =
+                       KOBJ_ATTR_GROUPS(osp_obd);
                obd->obd_debugfs_vars = ldebugfs_osp_obd_vars;
        }
 
index adcda47..2474c80 100644 (file)
@@ -1179,6 +1179,8 @@ static struct attribute *ptlrpc_svc_attrs[] = {
        NULL,
 };
 
+KOBJ_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,
@@ -1188,7 +1190,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,
 };