From: Mr NeilBrown Date: Sun, 24 Nov 2019 23:00:50 +0000 (+1100) Subject: LU-12678 lnet: make "struct lnet_lnd" always "const". X-Git-Tag: 2.13.52~87 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=4f526f5c20073d7025154d97885ec2fdfe832e1c LU-12678 lnet: make "struct lnet_lnd" always "const". Every place where "struct lnet_lnd" appears, "const" is added in front. Now all those structs can be in read-only memory which is generally more secure. Linux-commit 07499855083e ("lnet: make "struct lnet_lnd" always "const".") Test-Parameters: trivial Signed-off-by: Mr NeilBrown Change-Id: I54a73d5b12de8c6b9a98182577c3c30d05c00222 Reviewed-on: https://review.whamcloud.com/36832 Reviewed-by: Serguei Smirnov Reviewed-by: Chris Horn Reviewed-by: Amir Shehata Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- diff --git a/lnet/include/lnet/lib-lnet.h b/lnet/include/lnet/lib-lnet.h index 413813a..75387fb 100644 --- a/lnet/include/lnet/lib-lnet.h +++ b/lnet/include/lnet/lib-lnet.h @@ -544,7 +544,7 @@ lnet_net2rnethash(__u32 net) ((1U << the_lnet.ln_remote_nets_hbits) - 1)]; } -extern struct lnet_lnd the_lolnd; +extern const struct lnet_lnd the_lolnd; extern int avoid_asym_router_failure; extern unsigned int lnet_nid_cpt_hash(lnet_nid_t nid, unsigned int number); @@ -832,8 +832,8 @@ struct page *lnet_kvaddr_to_page(unsigned long vaddr); int lnet_cpt_of_md(struct lnet_libmd *md, unsigned int offset); unsigned int lnet_get_lnd_timeout(void); -void lnet_register_lnd(struct lnet_lnd *lnd); -void lnet_unregister_lnd(struct lnet_lnd *lnd); +void lnet_register_lnd(const struct lnet_lnd *lnd); +void lnet_unregister_lnd(const struct lnet_lnd *lnd); int lnet_connect(struct socket **sockp, lnet_nid_t peer_nid, __u32 local_ip, __u32 peer_ip, int peer_port, struct net *ns); diff --git a/lnet/include/lnet/lib-types.h b/lnet/include/lnet/lib-types.h index 703251e..c5d6b2b 100644 --- a/lnet/include/lnet/lib-types.h +++ b/lnet/include/lnet/lib-types.h @@ -399,7 +399,7 @@ struct lnet_net { bool net_tunables_set; /* procedural interface */ - struct lnet_lnd *net_lnd; + const struct lnet_lnd *net_lnd; /* list of NIs on this net */ struct list_head net_ni_list; @@ -1110,7 +1110,7 @@ struct lnet { /* uniquely identifies this ni in this epoch */ __u64 ln_interface_cookie; /* registered LNDs */ - struct lnet_lnd *ln_lnds[NUM_LNDS]; + const struct lnet_lnd *ln_lnds[NUM_LNDS]; /* test protocol compatibility flags */ int ln_testprotocompat; diff --git a/lnet/klnds/gnilnd/gnilnd.c b/lnet/klnds/gnilnd/gnilnd.c index 90ee025..a197c99 100644 --- a/lnet/klnds/gnilnd/gnilnd.c +++ b/lnet/klnds/gnilnd/gnilnd.c @@ -25,7 +25,7 @@ #include "gnilnd.h" /* Primary entry points from LNET. There are no guarantees against reentrance. */ -struct lnet_lnd the_kgnilnd = { +const struct lnet_lnd the_kgnilnd = { .lnd_type = GNILND, .lnd_startup = kgnilnd_startup, .lnd_shutdown = kgnilnd_shutdown, diff --git a/lnet/klnds/o2iblnd/o2iblnd.c b/lnet/klnds/o2iblnd/o2iblnd.c index 3437f30..f2966d7 100644 --- a/lnet/klnds/o2iblnd/o2iblnd.c +++ b/lnet/klnds/o2iblnd/o2iblnd.c @@ -39,7 +39,7 @@ #include "o2iblnd.h" -static struct lnet_lnd the_o2iblnd; +static const struct lnet_lnd the_o2iblnd; struct kib_data kiblnd_data; @@ -3354,7 +3354,7 @@ failed: return -ENETDOWN; } -static struct lnet_lnd the_o2iblnd = { +static const struct lnet_lnd the_o2iblnd = { .lnd_type = O2IBLND, .lnd_startup = kiblnd_startup, .lnd_shutdown = kiblnd_shutdown, diff --git a/lnet/klnds/socklnd/socklnd.c b/lnet/klnds/socklnd/socklnd.c index 2393e018..a9907c5 100644 --- a/lnet/klnds/socklnd/socklnd.c +++ b/lnet/klnds/socklnd/socklnd.c @@ -40,7 +40,7 @@ #include "socklnd.h" #include -static struct lnet_lnd the_ksocklnd; +static const struct lnet_lnd the_ksocklnd; struct ksock_nal_data ksocknal_data; static struct ksock_interface * @@ -2797,7 +2797,7 @@ static void __exit ksocklnd_exit(void) lnet_unregister_lnd(&the_ksocklnd); } -static struct lnet_lnd the_ksocklnd = { +static const struct lnet_lnd the_ksocklnd = { .lnd_type = SOCKLND, .lnd_startup = ksocknal_startup, .lnd_shutdown = ksocknal_shutdown, diff --git a/lnet/lnet/api-ni.c b/lnet/lnet/api-ni.c index d298f46..2ccbecc 100644 --- a/lnet/lnet/api-ni.c +++ b/lnet/lnet/api-ni.c @@ -800,9 +800,9 @@ static void lnet_assert_wire_constants(void) BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_ni) != 0); } -static struct lnet_lnd *lnet_find_lnd_by_type(__u32 type) +static const struct lnet_lnd *lnet_find_lnd_by_type(__u32 type) { - struct lnet_lnd *lnd; + const struct lnet_lnd *lnd; /* holding lnd mutex */ if (type >= NUM_LNDS) @@ -821,7 +821,7 @@ lnet_get_lnd_timeout(void) EXPORT_SYMBOL(lnet_get_lnd_timeout); void -lnet_register_lnd(struct lnet_lnd *lnd) +lnet_register_lnd(const struct lnet_lnd *lnd) { mutex_lock(&the_lnet.ln_lnd_mutex); @@ -837,7 +837,7 @@ lnet_register_lnd(struct lnet_lnd *lnd) EXPORT_SYMBOL(lnet_register_lnd); void -lnet_unregister_lnd(struct lnet_lnd *lnd) +lnet_unregister_lnd(const struct lnet_lnd *lnd) { mutex_lock(&the_lnet.ln_lnd_mutex); @@ -2274,7 +2274,7 @@ lnet_startup_lndnet(struct lnet_net *net, struct lnet_lnd_tunables *tun) int rc; int ni_count = 0; __u32 lnd_type; - struct lnet_lnd *lnd; + const struct lnet_lnd *lnd; int peer_timeout = net->net_tunables.lct_peer_timeout; int maxtxcredits = diff --git a/lnet/lnet/lo.c b/lnet/lnet/lo.c index 4f0ec8b..6b881fc 100644 --- a/lnet/lnet/lo.c +++ b/lnet/lnet/lo.c @@ -103,7 +103,7 @@ lolnd_startup(struct lnet_ni *ni) return (0); } -struct lnet_lnd the_lolnd = { +const struct lnet_lnd the_lolnd = { .lnd_type = LOLND, .lnd_startup = lolnd_startup, .lnd_shutdown = lolnd_shutdown,