Whamcloud - gitweb
LU-8066 obdclass: don't copy ops structures in to new type. 87/35687/8
authorNeilBrown <neilb@suse.com>
Fri, 11 Oct 2019 01:26:06 +0000 (21:26 -0400)
committerOleg Drokin <green@whamcloud.com>
Fri, 20 Dec 2019 03:26:18 +0000 (03:26 +0000)
The obd_ops and md_ops structures passed to class_register_type() are
read-only, and have a lifetime that is exceeds the lifetime of the
obd_type - they are static in a module which unregisters the type before
being unloaded.

So there is no need to copy the ops, just store a pointer.

Also mark all the structures as read-only to confirm they don't get
written. This is best-practice for structures of function pointers.

Linux-commit: 2233f57f1b95b9a85a3129ddcc2860ddbc4c2a94

Signed-off-by: NeilBrown <neilb@suse.com>
Change-Id: Id0be1477925e0c878e3edb6a9d892f3c89a8b19b
Reviewed-on: https://review.whamcloud.com/35687
Reviewed-by: Neil Brown <neilb@suse.de>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Yang Sheng <ys@whamcloud.com>
Reviewed-by: Shaun Tancheff <stancheff@cray.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
27 files changed:
lustre/include/lustre_dlm.h
lustre/include/obd.h
lustre/include/obd_class.h
lustre/lmv/lmv_obd.c
lustre/lod/lod_dev.c
lustre/lov/lov_obd.c
lustre/mdc/mdc_request.c
lustre/mdd/mdd_device.c
lustre/mdt/mdt_handler.c
lustre/mdt/mdt_mds.c
lustre/mgc/mgc_request.c
lustre/mgs/mgs_handler.c
lustre/obdclass/genops.c
lustre/obdclass/llog_test.c
lustre/obdecho/echo.c
lustre/obdecho/echo_client.c
lustre/obdecho/echo_internal.h
lustre/ofd/ofd_internal.h
lustre/ofd/ofd_obd.c
lustre/osc/osc_request.c
lustre/osd-ldiskfs/osd_handler.c
lustre/osd-zfs/osd_handler.c
lustre/osp/lwp_dev.c
lustre/osp/osp_dev.c
lustre/osp/osp_internal.h
lustre/ost/ost_handler.c
lustre/quota/qmt_dev.c

index 7534486..c3a7928 100644 (file)
@@ -1207,8 +1207,6 @@ struct ldlm_enqueue_info {
 
 #define ei_res_id      ei_cb_gl
 
-extern struct obd_ops ldlm_obd_ops;
-
 extern char *ldlm_lockname[];
 extern char *ldlm_typename[];
 extern const char *ldlm_it2str(enum ldlm_intent_flags it);
index 4b73b4f..4bb7f24 100644 (file)
@@ -99,8 +99,8 @@ struct obd_info {
 };
 
 struct obd_type {
-       struct obd_ops          *typ_dt_ops;
-       struct md_ops           *typ_md_ops;
+       const struct obd_ops    *typ_dt_ops;
+       const struct md_ops     *typ_md_ops;
        struct proc_dir_entry   *typ_procroot;
        struct dentry           *typ_debugfs_entry;
 #ifdef HAVE_SERVER_SUPPORT
index 964baf1..9cc8a4c 100644 (file)
@@ -68,7 +68,8 @@ struct obd_export *class_conn2export(struct lustre_handle *);
 #ifdef HAVE_SERVER_SUPPORT
 struct obd_type *class_add_symlinks(const char *name, bool enable_proc);
 #endif
-int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
+int class_register_type(const struct obd_ops *dt_ops,
+                       const struct md_ops *md_ops, bool enable_proc,
                        struct lprocfs_vars *module_vars,
                        const char *nm, struct lu_device_type *ldt);
 int class_unregister_type(const char *nm);
index a7f9cb6..465c3bc 100644 (file)
@@ -3588,7 +3588,7 @@ static int lmv_merge_attr(struct obd_export *exp,
        return 0;
 }
 
-struct obd_ops lmv_obd_ops = {
+static const struct obd_ops lmv_obd_ops = {
         .o_owner                = THIS_MODULE,
         .o_setup                = lmv_setup,
         .o_cleanup              = lmv_cleanup,
@@ -3606,7 +3606,7 @@ struct obd_ops lmv_obd_ops = {
         .o_quotactl             = lmv_quotactl
 };
 
-struct md_ops lmv_md_ops = {
+static const struct md_ops lmv_md_ops = {
        .m_get_root             = lmv_get_root,
         .m_null_inode          = lmv_null_inode,
         .m_close                = lmv_close,
index 5b2b38f..63f6ce7 100644 (file)
@@ -2132,7 +2132,7 @@ static int lod_obd_set_info_async(const struct lu_env *env,
        RETURN(rc);
 }
 
-static struct obd_ops lod_obd_device_ops = {
+static const struct obd_ops lod_obd_device_ops = {
        .o_owner        = THIS_MODULE,
        .o_connect      = lod_obd_connect,
        .o_disconnect   = lod_obd_disconnect,
index 841c3ca..2bf865f 100644 (file)
@@ -1324,7 +1324,7 @@ static int lov_quotactl(struct obd_device *obd, struct obd_export *exp,
         RETURN(rc);
 }
 
-static struct obd_ops lov_obd_ops = {
+static const struct obd_ops lov_obd_ops = {
        .o_owner                = THIS_MODULE,
        .o_setup                = lov_setup,
        .o_cleanup              = lov_cleanup,
index a46b44b..102e24f 100644 (file)
@@ -2896,7 +2896,7 @@ static int mdc_cleanup(struct obd_device *obd)
        return osc_cleanup_common(obd);
 }
 
-static struct obd_ops mdc_obd_ops = {
+static const struct obd_ops mdc_obd_ops = {
        .o_owner            = THIS_MODULE,
        .o_setup            = mdc_setup,
        .o_precleanup       = mdc_precleanup,
@@ -2919,7 +2919,7 @@ static struct obd_ops mdc_obd_ops = {
        .o_quotactl         = mdc_quotactl,
 };
 
-static struct md_ops mdc_md_ops = {
+static const struct md_ops mdc_md_ops = {
        .m_get_root         = mdc_get_root,
        .m_null_inode       = mdc_null_inode,
        .m_close            = mdc_close,
index fef3dc1..3590ed9 100644 (file)
@@ -1497,7 +1497,7 @@ static int mdd_obd_set_info_async(const struct lu_env *env,
        RETURN(rc);
 }
 
-static struct obd_ops mdd_obd_device_ops = {
+static const struct obd_ops mdd_obd_device_ops = {
        .o_owner        = THIS_MODULE,
        .o_connect      = mdd_obd_connect,
        .o_disconnect   = mdd_obd_disconnect,
index 9213c45..a2ffa2c 100644 (file)
@@ -6938,7 +6938,7 @@ static int mdt_obd_postrecov(struct obd_device *obd)
         return rc;
 }
 
-static struct obd_ops mdt_obd_device_ops = {
+static const struct obd_ops mdt_obd_device_ops = {
         .o_owner          = THIS_MODULE,
         .o_set_info_async = mdt_obd_set_info_async,
         .o_connect        = mdt_obd_connect,
index d7408b1..5699c40 100644 (file)
@@ -677,7 +677,7 @@ static int mds_health_check(const struct lu_env *env, struct obd_device *obd)
        return rc != 0 ? 1 : 0;
 }
 
-static struct obd_ops mds_obd_device_ops = {
+static const struct obd_ops mds_obd_device_ops = {
        .o_owner           = THIS_MODULE,
        .o_health_check    = mds_health_check,
 };
index c30de4a..08f1c8c 100644 (file)
@@ -2267,7 +2267,7 @@ out:
         RETURN(rc);
 }
 
-static struct obd_ops mgc_obd_ops = {
+static const struct obd_ops mgc_obd_ops = {
         .o_owner        = THIS_MODULE,
         .o_setup        = mgc_setup,
         .o_precleanup   = mgc_precleanup,
index c262706..a670b07 100644 (file)
@@ -1734,7 +1734,7 @@ static int mgs_health_check(const struct lu_env *env, struct obd_device *obd)
 }
 
 /* use obd ops to offer management infrastructure */
-static struct obd_ops mgs_obd_device_ops = {
+static const struct obd_ops mgs_obd_device_ops = {
        .o_owner                = THIS_MODULE,
        .o_connect              = mgs_obd_connect,
        .o_reconnect            = mgs_obd_reconnect,
index 1e02f89..1a635f3 100644 (file)
@@ -172,11 +172,6 @@ static void class_sysfs_release(struct kobject *kobj)
        if (type->typ_name && type->typ_procroot)
                remove_proc_subtree(type->typ_name, proc_lustre_root);
 #endif
-       if (type->typ_md_ops)
-               OBD_FREE_PTR(type->typ_md_ops);
-       if (type->typ_dt_ops)
-               OBD_FREE_PTR(type->typ_dt_ops);
-
        OBD_FREE(type, sizeof(*type));
 }
 
@@ -234,7 +229,8 @@ EXPORT_SYMBOL(class_add_symlinks);
 
 #define CLASS_MAX_NAME 1024
 
-int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,
+int class_register_type(const struct obd_ops *dt_ops,
+                       const struct md_ops *md_ops,
                        bool enable_proc, struct lprocfs_vars *vars,
                        const char *name, struct lu_device_type *ldt)
 {
@@ -265,17 +261,9 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,
 #ifdef HAVE_SERVER_SUPPORT
 dir_exist:
 #endif /* HAVE_SERVER_SUPPORT */
-        OBD_ALLOC_PTR(type->typ_dt_ops);
-        OBD_ALLOC_PTR(type->typ_md_ops);
-
-        if (type->typ_dt_ops == NULL ||
-           type->typ_md_ops == NULL)
-               GOTO (failed, rc = -ENOMEM);
 
-        *(type->typ_dt_ops) = *dt_ops;
-        /* md_ops is optional */
-        if (md_ops)
-                *(type->typ_md_ops) = *md_ops;
+       type->typ_dt_ops = dt_ops;
+       type->typ_md_ops = md_ops;
 
 #ifdef HAVE_SERVER_SUPPORT
        if (type->typ_sym_filter) {
@@ -343,8 +331,8 @@ int class_unregister_type(const char *name)
                       atomic_read(&type->typ_refcnt));
                 /* This is a bad situation, let's make the best of it */
                 /* Remove ops, but leave the name for debugging */
-                OBD_FREE_PTR(type->typ_dt_ops);
-                OBD_FREE_PTR(type->typ_md_ops);
+               type->typ_dt_ops = NULL;
+               type->typ_md_ops = NULL;
                GOTO(out_put, rc = -EBUSY);
         }
 
index 7724903..77c65af 100644 (file)
@@ -2263,7 +2263,7 @@ cleanup_env:
        RETURN(rc);
 }
 
-static struct obd_ops llog_obd_ops = {
+static const struct obd_ops llog_obd_ops = {
        .o_owner       = THIS_MODULE,
        .o_setup       = llog_test_setup,
        .o_cleanup     = llog_test_cleanup,
index e6f7a53..4f069b9 100644 (file)
@@ -465,7 +465,7 @@ static struct lprocfs_vars lprocfs_echo_obd_vars[] = {
        { NULL }
 };
 
-struct obd_ops echo_obd_ops = {
+const struct obd_ops echo_obd_ops = {
        .o_owner           = THIS_MODULE,
        .o_connect         = echo_connect,
        .o_disconnect      = echo_disconnect,
index 790e2fb..36a2fb0 100644 (file)
@@ -3091,7 +3091,7 @@ out:
        return rc;
 }
 
-static struct obd_ops echo_client_obd_ops = {
+static const struct obd_ops echo_client_obd_ops = {
        .o_owner       = THIS_MODULE,
        .o_iocontrol   = echo_client_iocontrol,
        .o_connect     = echo_client_connect,
index 469d68e..4462422 100644 (file)
@@ -44,7 +44,7 @@
 #define OBD_ECHO_BLOCK_SIZE    (4<<10)
 
 #ifdef HAVE_SERVER_SUPPORT
-extern struct obd_ops echo_obd_ops;
+extern const struct obd_ops echo_obd_ops;
 extern struct lu_device_type echo_srv_type;
 int echo_persistent_pages_init(void);
 void echo_persistent_pages_fini(void);
index 779aea5..8f6a70e 100644 (file)
@@ -288,7 +288,7 @@ int ofd_fiemap_get(const struct lu_env *env, struct ofd_device *ofd,
                   struct lu_fid *fid, struct fiemap *fiemap);
 
 /* ofd_obd.c */
-extern struct obd_ops ofd_obd_ops;
+extern const struct obd_ops ofd_obd_ops;
 int ofd_destroy_by_fid(const struct lu_env *env, struct ofd_device *ofd,
                       const struct lu_fid *fid, int orphan);
 int ofd_statfs(const struct lu_env *env,  struct obd_export *exp,
index 2e74bc4..7240b8f 100644 (file)
@@ -1478,7 +1478,7 @@ out:
        return !!rc;
 }
 
-struct obd_ops ofd_obd_ops = {
+const struct obd_ops ofd_obd_ops = {
        .o_owner                = THIS_MODULE,
        .o_connect              = ofd_obd_connect,
        .o_reconnect            = ofd_obd_reconnect,
index 7a0a550..10fcc44 100644 (file)
@@ -3344,7 +3344,7 @@ int osc_cleanup_common(struct obd_device *obd)
 }
 EXPORT_SYMBOL(osc_cleanup_common);
 
-static struct obd_ops osc_obd_ops = {
+static const struct obd_ops osc_obd_ops = {
         .o_owner                = THIS_MODULE,
         .o_setup                = osc_setup,
         .o_precleanup           = osc_precleanup,
index 5710374..4f726fd 100644 (file)
@@ -8146,7 +8146,7 @@ static int osd_health_check(const struct lu_env *env, struct obd_device *obd)
 /*
  * lprocfs legacy support.
  */
-static struct obd_ops osd_obd_device_ops = {
+static const struct obd_ops osd_obd_device_ops = {
        .o_owner = THIS_MODULE,
        .o_connect      = osd_obd_connect,
        .o_disconnect   = osd_obd_disconnect,
index 4e23ba1..c4bfd4f 100644 (file)
@@ -1614,7 +1614,7 @@ static struct lu_device_type osd_device_type = {
 };
 
 
-static struct obd_ops osd_obd_device_ops = {
+static const struct obd_ops osd_obd_device_ops = {
        .o_owner       = THIS_MODULE,
        .o_connect      = osd_obd_connect,
        .o_disconnect   = osd_obd_disconnect,
index b94ec53..4c5828e 100644 (file)
@@ -622,7 +622,7 @@ static int lwp_set_info_async(const struct lu_env *env,
        RETURN(-EINVAL);
 }
 
-struct obd_ops lwp_obd_device_ops = {
+const struct obd_ops lwp_obd_device_ops = {
        .o_owner        = THIS_MODULE,
        .o_add_conn     = client_import_add_conn,
        .o_del_conn     = client_import_del_conn,
index ba348ef..94ce956 100644 (file)
@@ -1870,7 +1870,7 @@ static struct lu_device_type osp_device_type = {
        .ldt_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD,
 };
 
-static struct obd_ops osp_obd_device_ops = {
+static const struct obd_ops osp_obd_device_ops = {
        .o_owner        = THIS_MODULE,
        .o_add_conn     = client_import_add_conn,
        .o_del_conn     = client_import_del_conn,
index e65284c..93c4e61 100644 (file)
@@ -891,7 +891,7 @@ int osp_sync_add_commit_cb_1s(const struct lu_env *env, struct osp_device *d,
                              struct thandle *th);
 
 /* lwp_dev.c */
-extern struct obd_ops lwp_obd_device_ops;
+extern const struct obd_ops lwp_obd_device_ops;
 extern struct lu_device_type lwp_device_type;
 
 static inline struct lu_device *osp2top(const struct osp_device *osp)
index ab72698..831f44d 100644 (file)
@@ -407,7 +407,7 @@ static int ost_health_check(const struct lu_env *env, struct obd_device *obd)
 }
 
 /* use obd ops to offer management infrastructure */
-static struct obd_ops ost_obd_ops = {
+static const struct obd_ops ost_obd_ops = {
         .o_owner        = THIS_MODULE,
         .o_setup        = ost_setup,
         .o_cleanup      = ost_cleanup,
index 19605fa..d876cd3 100644 (file)
@@ -419,7 +419,7 @@ static int qmt_device_obd_disconnect(struct obd_export *exp)
 /*
  * obd device operations associated with the master target.
  */
-struct obd_ops qmt_obd_ops = {
+static const struct obd_ops qmt_obd_ops = {
        .o_owner        = THIS_MODULE,
        .o_connect      = qmt_device_obd_connect,
        .o_disconnect   = qmt_device_obd_disconnect,