From: NeilBrown Date: Fri, 11 Oct 2019 01:26:06 +0000 (-0400) Subject: LU-8066 obdclass: don't copy ops structures in to new type. X-Git-Tag: 2.13.51~56 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=acd639bf0de0c39419dff94fd6d338283a1ddb24 LU-8066 obdclass: don't copy ops structures in to new type. 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 Change-Id: Id0be1477925e0c878e3edb6a9d892f3c89a8b19b Reviewed-on: https://review.whamcloud.com/35687 Reviewed-by: Neil Brown Tested-by: jenkins Tested-by: Maloo Reviewed-by: Yang Sheng Reviewed-by: Shaun Tancheff Reviewed-by: Oleg Drokin --- diff --git a/lustre/include/lustre_dlm.h b/lustre/include/lustre_dlm.h index 7534486..c3a7928 100644 --- a/lustre/include/lustre_dlm.h +++ b/lustre/include/lustre_dlm.h @@ -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); diff --git a/lustre/include/obd.h b/lustre/include/obd.h index 4b73b4f..4bb7f24 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -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 diff --git a/lustre/include/obd_class.h b/lustre/include/obd_class.h index 964baf1..9cc8a4c 100644 --- a/lustre/include/obd_class.h +++ b/lustre/include/obd_class.h @@ -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); diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index a7f9cb6..465c3bc 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -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, diff --git a/lustre/lod/lod_dev.c b/lustre/lod/lod_dev.c index 5b2b38f..63f6ce7 100644 --- a/lustre/lod/lod_dev.c +++ b/lustre/lod/lod_dev.c @@ -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, diff --git a/lustre/lov/lov_obd.c b/lustre/lov/lov_obd.c index 841c3ca..2bf865f 100644 --- a/lustre/lov/lov_obd.c +++ b/lustre/lov/lov_obd.c @@ -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, diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c index a46b44b..102e24f 100644 --- a/lustre/mdc/mdc_request.c +++ b/lustre/mdc/mdc_request.c @@ -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, diff --git a/lustre/mdd/mdd_device.c b/lustre/mdd/mdd_device.c index fef3dc1..3590ed9 100644 --- a/lustre/mdd/mdd_device.c +++ b/lustre/mdd/mdd_device.c @@ -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, diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 9213c45..a2ffa2c 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -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, diff --git a/lustre/mdt/mdt_mds.c b/lustre/mdt/mdt_mds.c index d7408b1..5699c40 100644 --- a/lustre/mdt/mdt_mds.c +++ b/lustre/mdt/mdt_mds.c @@ -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, }; diff --git a/lustre/mgc/mgc_request.c b/lustre/mgc/mgc_request.c index c30de4a..08f1c8c 100644 --- a/lustre/mgc/mgc_request.c +++ b/lustre/mgc/mgc_request.c @@ -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, diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index c262706..a670b07 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -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, diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index 1e02f89..1a635f3 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -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); } diff --git a/lustre/obdclass/llog_test.c b/lustre/obdclass/llog_test.c index 7724903..77c65af 100644 --- a/lustre/obdclass/llog_test.c +++ b/lustre/obdclass/llog_test.c @@ -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, diff --git a/lustre/obdecho/echo.c b/lustre/obdecho/echo.c index e6f7a53..4f069b9 100644 --- a/lustre/obdecho/echo.c +++ b/lustre/obdecho/echo.c @@ -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, diff --git a/lustre/obdecho/echo_client.c b/lustre/obdecho/echo_client.c index 790e2fb..36a2fb0 100644 --- a/lustre/obdecho/echo_client.c +++ b/lustre/obdecho/echo_client.c @@ -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, diff --git a/lustre/obdecho/echo_internal.h b/lustre/obdecho/echo_internal.h index 469d68e..4462422 100644 --- a/lustre/obdecho/echo_internal.h +++ b/lustre/obdecho/echo_internal.h @@ -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); diff --git a/lustre/ofd/ofd_internal.h b/lustre/ofd/ofd_internal.h index 779aea5..8f6a70e 100644 --- a/lustre/ofd/ofd_internal.h +++ b/lustre/ofd/ofd_internal.h @@ -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, diff --git a/lustre/ofd/ofd_obd.c b/lustre/ofd/ofd_obd.c index 2e74bc4..7240b8f 100644 --- a/lustre/ofd/ofd_obd.c +++ b/lustre/ofd/ofd_obd.c @@ -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, diff --git a/lustre/osc/osc_request.c b/lustre/osc/osc_request.c index 7a0a550..10fcc44 100644 --- a/lustre/osc/osc_request.c +++ b/lustre/osc/osc_request.c @@ -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, diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index 5710374..4f726fd 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -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, diff --git a/lustre/osd-zfs/osd_handler.c b/lustre/osd-zfs/osd_handler.c index 4e23ba1..c4bfd4f 100644 --- a/lustre/osd-zfs/osd_handler.c +++ b/lustre/osd-zfs/osd_handler.c @@ -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, diff --git a/lustre/osp/lwp_dev.c b/lustre/osp/lwp_dev.c index b94ec53..4c5828e 100644 --- a/lustre/osp/lwp_dev.c +++ b/lustre/osp/lwp_dev.c @@ -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, diff --git a/lustre/osp/osp_dev.c b/lustre/osp/osp_dev.c index ba348ef..94ce956 100644 --- a/lustre/osp/osp_dev.c +++ b/lustre/osp/osp_dev.c @@ -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, diff --git a/lustre/osp/osp_internal.h b/lustre/osp/osp_internal.h index e65284c..93c4e61 100644 --- a/lustre/osp/osp_internal.h +++ b/lustre/osp/osp_internal.h @@ -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) diff --git a/lustre/ost/ost_handler.c b/lustre/ost/ost_handler.c index ab72698..831f44d 100644 --- a/lustre/ost/ost_handler.c +++ b/lustre/ost/ost_handler.c @@ -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, diff --git a/lustre/quota/qmt_dev.c b/lustre/quota/qmt_dev.c index 19605fa..d876cd3 100644 --- a/lustre/quota/qmt_dev.c +++ b/lustre/quota/qmt_dev.c @@ -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,