4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
32 #define DEBUG_SUBSYSTEM S_SEC
34 #include <libcfs/libcfs.h>
35 #include <linux/crypto.h>
36 #include <linux/key.h>
39 #include <obd_class.h>
40 #include <obd_support.h>
41 #include <lustre_net.h>
42 #include <lustre_import.h>
43 #include <lustre_log.h>
44 #include <lustre_disk.h>
45 #include <lustre_dlm.h>
46 #include <uapi/linux/lustre/lustre_param.h>
47 #include <lustre_sec.h>
49 #include "ptlrpc_internal.h"
51 const char *sptlrpc_part2name(enum lustre_sec_part part)
70 EXPORT_SYMBOL(sptlrpc_part2name);
72 enum lustre_sec_part sptlrpc_target_sec_part(struct obd_device *obd)
74 const char *type = obd->obd_type->typ_name;
76 if (!strcmp(type, LUSTRE_MDT_NAME))
78 if (!strcmp(type, LUSTRE_OST_NAME))
80 if (!strcmp(type, LUSTRE_MGS_NAME))
83 CERROR("unknown target %p(%s)\n", obd, type);
87 /****************************************
88 * user supplied flavor string parsing *
89 ****************************************/
92 * format: <base_flavor>[-<bulk_type:alg_spec>]
94 int sptlrpc_parse_flavor(const char *str, struct sptlrpc_flavor *flvr)
99 memset(flvr, 0, sizeof(*flvr));
101 if (str == NULL || str[0] == '\0') {
102 flvr->sf_rpc = SPTLRPC_FLVR_INVALID;
106 strlcpy(buf, str, sizeof(buf));
108 bulk = strchr(buf, '-');
112 flvr->sf_rpc = sptlrpc_name2flavor_base(buf);
113 if (flvr->sf_rpc == SPTLRPC_FLVR_INVALID)
117 * currently only base flavor "plain" can have bulk specification.
119 if (flvr->sf_rpc == SPTLRPC_FLVR_PLAIN) {
120 flvr->u_bulk.hash.hash_alg = BULK_HASH_ALG_ADLER32;
123 * format: plain-hash:<hash_alg>
125 alg = strchr(bulk, ':');
130 if (strcmp(bulk, "hash"))
133 flvr->u_bulk.hash.hash_alg = sptlrpc_get_hash_alg(alg);
134 if (flvr->u_bulk.hash.hash_alg >= BULK_HASH_ALG_MAX)
138 if (flvr->u_bulk.hash.hash_alg == BULK_HASH_ALG_NULL)
139 flvr_set_bulk_svc(&flvr->sf_rpc, SPTLRPC_BULK_SVC_NULL);
141 flvr_set_bulk_svc(&flvr->sf_rpc, SPTLRPC_BULK_SVC_INTG);
151 CERROR("invalid flavor string: %s\n", str);
154 EXPORT_SYMBOL(sptlrpc_parse_flavor);
156 /****************************************
158 ****************************************/
160 static void get_default_flavor(struct sptlrpc_flavor *sf)
162 memset(sf, 0, sizeof(*sf));
164 sf->sf_rpc = SPTLRPC_FLVR_NULL;
168 static void sptlrpc_rule_init(struct sptlrpc_rule *rule)
170 rule->sr_netid = LNET_NET_ANY;
171 rule->sr_from = LUSTRE_SP_ANY;
172 rule->sr_to = LUSTRE_SP_ANY;
173 rule->sr_padding = 0;
175 get_default_flavor(&rule->sr_flvr);
179 * format: network[.direction]=flavor
181 int sptlrpc_parse_rule(char *param, struct sptlrpc_rule *rule)
186 sptlrpc_rule_init(rule);
188 flavor = strchr(param, '=');
189 if (flavor == NULL) {
190 CERROR("invalid param, no '='\n");
195 dir = strchr(param, '.');
200 if (strcmp(param, "default")) {
201 rule->sr_netid = libcfs_str2net(param);
202 if (rule->sr_netid == LNET_NET_ANY) {
203 CERROR("invalid network name: %s\n", param);
210 if (!strcmp(dir, "mdt2ost")) {
211 rule->sr_from = LUSTRE_SP_MDT;
212 rule->sr_to = LUSTRE_SP_OST;
213 } else if (!strcmp(dir, "mdt2mdt")) {
214 rule->sr_from = LUSTRE_SP_MDT;
215 rule->sr_to = LUSTRE_SP_MDT;
216 } else if (!strcmp(dir, "cli2ost")) {
217 rule->sr_from = LUSTRE_SP_CLI;
218 rule->sr_to = LUSTRE_SP_OST;
219 } else if (!strcmp(dir, "cli2mdt")) {
220 rule->sr_from = LUSTRE_SP_CLI;
221 rule->sr_to = LUSTRE_SP_MDT;
223 CERROR("invalid rule dir segment: %s\n", dir);
229 rc = sptlrpc_parse_flavor(flavor, &rule->sr_flvr);
235 EXPORT_SYMBOL(sptlrpc_parse_rule);
237 void sptlrpc_rule_set_free(struct sptlrpc_rule_set *rset)
239 LASSERT(rset->srs_nslot ||
240 (rset->srs_nrule == 0 && rset->srs_rules == NULL));
242 if (rset->srs_nslot) {
243 OBD_FREE_PTR_ARRAY(rset->srs_rules, rset->srs_nslot);
244 sptlrpc_rule_set_init(rset);
247 EXPORT_SYMBOL(sptlrpc_rule_set_free);
250 * return 0 if the rule set could accomodate one more rule.
252 int sptlrpc_rule_set_expand(struct sptlrpc_rule_set *rset)
254 struct sptlrpc_rule *rules;
259 if (rset->srs_nrule < rset->srs_nslot)
262 nslot = rset->srs_nslot + 8;
264 /* better use realloc() if available */
265 OBD_ALLOC_PTR_ARRAY(rules, nslot);
269 if (rset->srs_nrule) {
270 LASSERT(rset->srs_nslot && rset->srs_rules);
271 memcpy(rules, rset->srs_rules,
272 rset->srs_nrule * sizeof(*rset->srs_rules));
274 OBD_FREE_PTR_ARRAY(rset->srs_rules, rset->srs_nslot);
277 rset->srs_rules = rules;
278 rset->srs_nslot = nslot;
282 static inline int rule_spec_dir(struct sptlrpc_rule *rule)
284 return (rule->sr_from != LUSTRE_SP_ANY ||
285 rule->sr_to != LUSTRE_SP_ANY);
287 static inline int rule_spec_net(struct sptlrpc_rule *rule)
289 return (rule->sr_netid != LNET_NET_ANY);
291 static inline int rule_match_dir(struct sptlrpc_rule *r1,
292 struct sptlrpc_rule *r2)
294 return (r1->sr_from == r2->sr_from && r1->sr_to == r2->sr_to);
296 static inline int rule_match_net(struct sptlrpc_rule *r1,
297 struct sptlrpc_rule *r2)
299 return (r1->sr_netid == r2->sr_netid);
303 * merge @rule into @rset.
304 * the @rset slots might be expanded.
306 int sptlrpc_rule_set_merge(struct sptlrpc_rule_set *rset,
307 struct sptlrpc_rule *rule)
309 struct sptlrpc_rule *p = rset->srs_rules;
310 int spec_dir, spec_net;
311 int rc, n, match = 0;
315 spec_net = rule_spec_net(rule);
316 spec_dir = rule_spec_dir(rule);
318 for (n = 0; n < rset->srs_nrule; n++) {
319 p = &rset->srs_rules[n];
321 /* test network match, if failed:
322 * - spec rule: skip rules which is also spec rule match, until
323 * we hit a wild rule, which means no more chance
324 * - wild rule: skip until reach the one which is also wild
327 if (!rule_match_net(p, rule)) {
329 if (rule_spec_net(p))
338 /* test dir match, same logic as net matching */
339 if (!rule_match_dir(p, rule)) {
341 if (rule_spec_dir(p))
356 LASSERT(n >= 0 && n < rset->srs_nrule);
358 if (rule->sr_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
359 /* remove this rule */
360 if (n < rset->srs_nrule - 1)
361 memmove(&rset->srs_rules[n],
362 &rset->srs_rules[n + 1],
363 (rset->srs_nrule - n - 1) *
367 /* override the rule */
368 memcpy(&rset->srs_rules[n], rule, sizeof(*rule));
371 LASSERT(n >= 0 && n <= rset->srs_nrule);
373 if (rule->sr_flvr.sf_rpc != SPTLRPC_FLVR_INVALID) {
374 rc = sptlrpc_rule_set_expand(rset);
378 if (n < rset->srs_nrule)
379 memmove(&rset->srs_rules[n + 1],
381 (rset->srs_nrule - n) * sizeof(*rule));
382 memcpy(&rset->srs_rules[n], rule, sizeof(*rule));
385 CDEBUG(D_CONFIG, "ignore the unmatched deletion\n");
391 EXPORT_SYMBOL(sptlrpc_rule_set_merge);
394 * given from/to/nid, determine a matching flavor in ruleset.
395 * return 1 if a match found, otherwise return 0.
397 int sptlrpc_rule_set_choose(struct sptlrpc_rule_set *rset,
398 enum lustre_sec_part from,
399 enum lustre_sec_part to,
401 struct sptlrpc_flavor *sf)
403 struct sptlrpc_rule *r;
406 for (n = 0; n < rset->srs_nrule; n++) {
407 r = &rset->srs_rules[n];
409 if (LNET_NIDNET(nid) != LNET_NET_ANY &&
410 r->sr_netid != LNET_NET_ANY &&
411 LNET_NIDNET(nid) != r->sr_netid)
414 if (from != LUSTRE_SP_ANY && r->sr_from != LUSTRE_SP_ANY &&
418 if (to != LUSTRE_SP_ANY && r->sr_to != LUSTRE_SP_ANY &&
429 void sptlrpc_rule_set_dump(struct sptlrpc_rule_set *rset)
431 struct sptlrpc_rule *r;
434 for (n = 0; n < rset->srs_nrule; n++) {
435 r = &rset->srs_rules[n];
436 CDEBUG(D_SEC, "<%02d> from %x to %x, net %x, rpc %x\n", n,
437 r->sr_from, r->sr_to, r->sr_netid, r->sr_flvr.sf_rpc);
441 static int sptlrpc_rule_set_extract(struct sptlrpc_rule_set *gen,
442 struct sptlrpc_rule_set *tgt,
443 enum lustre_sec_part from,
444 enum lustre_sec_part to,
445 struct sptlrpc_rule_set *rset)
447 struct sptlrpc_rule_set *src[2] = { gen, tgt };
448 struct sptlrpc_rule *rule;
453 /* merge general rules firstly, then target-specific rules */
454 for (i = 0; i < 2; i++) {
458 for (n = 0; n < src[i]->srs_nrule; n++) {
459 rule = &src[i]->srs_rules[n];
461 if (from != LUSTRE_SP_ANY &&
462 rule->sr_from != LUSTRE_SP_ANY &&
463 rule->sr_from != from)
465 if (to != LUSTRE_SP_ANY &&
466 rule->sr_to != LUSTRE_SP_ANY &&
470 rc = sptlrpc_rule_set_merge(rset, rule);
472 CERROR("can't merge: %d\n", rc);
481 /**********************************
482 * sptlrpc configuration support *
483 **********************************/
485 struct sptlrpc_conf_tgt {
486 struct list_head sct_list;
487 char sct_name[MAX_OBD_NAME];
488 struct sptlrpc_rule_set sct_rset;
491 struct sptlrpc_conf {
492 struct list_head sc_list;
493 char sc_fsname[MTI_NAME_MAXLEN];
494 unsigned int sc_modified; /* modified during updating */
495 unsigned int sc_updated:1, /* updated copy from MGS */
496 sc_local:1; /* local copy from target */
497 struct sptlrpc_rule_set sc_rset; /* fs general rules */
498 struct list_head sc_tgts; /* target-specific rules */
501 static struct mutex sptlrpc_conf_lock;
502 static LIST_HEAD(sptlrpc_confs);
504 static void sptlrpc_conf_free_rsets(struct sptlrpc_conf *conf)
506 struct sptlrpc_conf_tgt *conf_tgt, *conf_tgt_next;
508 sptlrpc_rule_set_free(&conf->sc_rset);
510 list_for_each_entry_safe(conf_tgt, conf_tgt_next,
511 &conf->sc_tgts, sct_list) {
512 sptlrpc_rule_set_free(&conf_tgt->sct_rset);
513 list_del(&conf_tgt->sct_list);
514 OBD_FREE_PTR(conf_tgt);
516 LASSERT(list_empty(&conf->sc_tgts));
518 conf->sc_updated = 0;
522 static void sptlrpc_conf_free(struct sptlrpc_conf *conf)
524 CDEBUG(D_SEC, "free sptlrpc conf %s\n", conf->sc_fsname);
526 sptlrpc_conf_free_rsets(conf);
527 list_del(&conf->sc_list);
532 struct sptlrpc_conf_tgt *sptlrpc_conf_get_tgt(struct sptlrpc_conf *conf,
536 struct sptlrpc_conf_tgt *conf_tgt;
538 list_for_each_entry(conf_tgt, &conf->sc_tgts, sct_list) {
539 if (strcmp(conf_tgt->sct_name, name) == 0)
546 OBD_ALLOC_PTR(conf_tgt);
548 strlcpy(conf_tgt->sct_name, name, sizeof(conf_tgt->sct_name));
549 sptlrpc_rule_set_init(&conf_tgt->sct_rset);
550 list_add(&conf_tgt->sct_list, &conf->sc_tgts);
557 struct sptlrpc_conf *sptlrpc_conf_get(const char *fsname,
560 struct sptlrpc_conf *conf;
562 list_for_each_entry(conf, &sptlrpc_confs, sc_list) {
563 if (strcmp(conf->sc_fsname, fsname) == 0)
574 if (strlcpy(conf->sc_fsname, fsname, sizeof(conf->sc_fsname)) >=
575 sizeof(conf->sc_fsname)) {
579 sptlrpc_rule_set_init(&conf->sc_rset);
580 INIT_LIST_HEAD(&conf->sc_tgts);
581 list_add(&conf->sc_list, &sptlrpc_confs);
583 CDEBUG(D_SEC, "create sptlrpc conf %s\n", conf->sc_fsname);
588 * caller must hold conf_lock already.
590 static int sptlrpc_conf_merge_rule(struct sptlrpc_conf *conf,
592 struct sptlrpc_rule *rule)
594 struct sptlrpc_conf_tgt *conf_tgt;
595 struct sptlrpc_rule_set *rule_set;
597 /* fsname == target means general rules for the whole fs */
598 if (strcmp(conf->sc_fsname, target) == 0) {
599 rule_set = &conf->sc_rset;
601 conf_tgt = sptlrpc_conf_get_tgt(conf, target, 1);
603 rule_set = &conf_tgt->sct_rset;
605 CERROR("out of memory, can't merge rule!\n");
610 return sptlrpc_rule_set_merge(rule_set, rule);
614 * process one LCFG_SPTLRPC_CONF record. if \a conf is NULL, we
615 * find one through the target name in the record inside conf_lock;
616 * otherwise means caller already hold conf_lock.
618 static int __sptlrpc_process_config(char *target, const char *fsname,
619 struct sptlrpc_rule *rule,
620 struct sptlrpc_conf *conf)
629 mutex_lock(&sptlrpc_conf_lock);
630 conf = sptlrpc_conf_get(fsname, 0);
632 CERROR("can't find conf\n");
635 rc = sptlrpc_conf_merge_rule(conf, target, rule);
637 mutex_unlock(&sptlrpc_conf_lock);
639 LASSERT(mutex_is_locked(&sptlrpc_conf_lock));
640 rc = sptlrpc_conf_merge_rule(conf, target, rule);
649 int sptlrpc_process_config(struct lustre_cfg *lcfg)
651 char fsname[MTI_NAME_MAXLEN];
652 struct sptlrpc_rule rule;
653 char *target, *param;
656 print_lustre_cfg(lcfg);
658 target = lustre_cfg_string(lcfg, 1);
660 CERROR("missing target name\n");
664 param = lustre_cfg_string(lcfg, 2);
666 CERROR("missing parameter\n");
670 /* parse rule to make sure the format is correct */
671 if (strncmp(param, PARAM_SRPC_FLVR,
672 sizeof(PARAM_SRPC_FLVR) - 1) != 0) {
673 CERROR("Invalid sptlrpc parameter: %s\n", param);
676 param += sizeof(PARAM_SRPC_FLVR) - 1;
678 CDEBUG(D_SEC, "processing rule: %s.%s\n", target, param);
681 * Three types of targets exist for sptlrpc using conf_param
682 * 1. '_mgs' which targets mgc srpc settings. Treat it as
683 * as a special file system name.
684 * 2. target is a device which can be fsname-MDTXXXX or
685 * fsname-OSTXXXX. This can be verified by the function
686 * server_name2fsname.
687 * 3. If both above conditions are not meet then the target
688 * is a actual filesystem.
690 if (server_name2fsname(target, fsname, NULL))
691 strlcpy(fsname, target, sizeof(target));
693 rc = sptlrpc_parse_rule(param, &rule);
697 return __sptlrpc_process_config(target, fsname, &rule, NULL);
699 EXPORT_SYMBOL(sptlrpc_process_config);
701 static int logname2fsname(const char *logname, char *buf, int buflen)
706 ptr = strrchr(logname, '-');
707 if (ptr == NULL || strcmp(ptr, "-sptlrpc")) {
708 CERROR("%s is not a sptlrpc config log\n", logname);
712 len = min((int) (ptr - logname), buflen - 1);
714 memcpy(buf, logname, len);
719 void sptlrpc_conf_log_update_begin(const char *logname)
721 struct sptlrpc_conf *conf;
724 if (logname2fsname(logname, fsname, sizeof(fsname)))
727 mutex_lock(&sptlrpc_conf_lock);
729 conf = sptlrpc_conf_get(fsname, 0);
731 if (conf->sc_local) {
732 LASSERT(conf->sc_updated == 0);
733 sptlrpc_conf_free_rsets(conf);
735 conf->sc_modified = 0;
738 mutex_unlock(&sptlrpc_conf_lock);
740 EXPORT_SYMBOL(sptlrpc_conf_log_update_begin);
743 * mark a config log has been updated
745 void sptlrpc_conf_log_update_end(const char *logname)
747 struct sptlrpc_conf *conf;
750 if (logname2fsname(logname, fsname, sizeof(fsname)))
753 mutex_lock(&sptlrpc_conf_lock);
755 conf = sptlrpc_conf_get(fsname, 0);
758 * if original state is not updated, make sure the
759 * modified counter > 0 to enforce updating local copy.
761 if (conf->sc_updated == 0)
764 conf->sc_updated = 1;
767 mutex_unlock(&sptlrpc_conf_lock);
769 EXPORT_SYMBOL(sptlrpc_conf_log_update_end);
771 void sptlrpc_conf_log_start(const char *logname)
775 if (logname2fsname(logname, fsname, sizeof(fsname)))
778 mutex_lock(&sptlrpc_conf_lock);
779 sptlrpc_conf_get(fsname, 1);
780 mutex_unlock(&sptlrpc_conf_lock);
782 EXPORT_SYMBOL(sptlrpc_conf_log_start);
784 void sptlrpc_conf_log_stop(const char *logname)
786 struct sptlrpc_conf *conf;
789 if (logname2fsname(logname, fsname, sizeof(fsname)))
792 mutex_lock(&sptlrpc_conf_lock);
793 conf = sptlrpc_conf_get(fsname, 0);
795 sptlrpc_conf_free(conf);
796 mutex_unlock(&sptlrpc_conf_lock);
798 EXPORT_SYMBOL(sptlrpc_conf_log_stop);
800 static void inline flavor_set_flags(struct sptlrpc_flavor *sf,
801 enum lustre_sec_part from,
802 enum lustre_sec_part to,
803 unsigned int fl_udesc)
806 * null flavor doesn't need to set any flavor, and in fact
807 * we'd better not do that because everybody share a single sec.
809 if (sf->sf_rpc == SPTLRPC_FLVR_NULL)
812 if (from == LUSTRE_SP_MDT) {
813 /* MDT->MDT; MDT->OST */
814 sf->sf_flags |= PTLRPC_SEC_FL_ROOTONLY;
815 } else if (from == LUSTRE_SP_CLI && to == LUSTRE_SP_OST) {
817 sf->sf_flags |= PTLRPC_SEC_FL_ROOTONLY | PTLRPC_SEC_FL_BULK;
818 } else if (from == LUSTRE_SP_CLI && to == LUSTRE_SP_MDT) {
820 if (fl_udesc && sf->sf_rpc != SPTLRPC_FLVR_NULL)
821 sf->sf_flags |= PTLRPC_SEC_FL_UDESC;
824 /* Some flavors use a single uid (0) context */
825 if (flvr_is_rootonly(sf->sf_rpc))
826 sf->sf_flags |= PTLRPC_SEC_FL_ROOTONLY;
828 /* User descriptor might need to be cleared */
829 if (flvr_allows_user_desc(sf->sf_rpc) == 0)
830 sf->sf_flags &= ~PTLRPC_SEC_FL_UDESC;
833 void sptlrpc_conf_choose_flavor(enum lustre_sec_part from,
834 enum lustre_sec_part to,
835 struct obd_uuid *target,
836 struct lnet_nid *nid,
837 struct sptlrpc_flavor *sf)
839 struct sptlrpc_conf *conf;
840 struct sptlrpc_conf_tgt *conf_tgt;
841 char name[MTI_NAME_MAXLEN];
844 obd_uuid2fsname(name, target->uuid, sizeof(name));
846 mutex_lock(&sptlrpc_conf_lock);
848 conf = sptlrpc_conf_get(name, 0);
852 /* convert uuid name (supposed end with _UUID) to target name */
853 len = strlen(target->uuid);
855 memcpy(name, target->uuid, len - 5);
856 name[len - 5] = '\0';
858 conf_tgt = sptlrpc_conf_get_tgt(conf, name, 0);
860 rc = sptlrpc_rule_set_choose(&conf_tgt->sct_rset,
861 from, to, lnet_nid_to_nid4(nid), sf);
866 rc = sptlrpc_rule_set_choose(&conf->sc_rset, from, to,
867 lnet_nid_to_nid4(nid), sf);
869 mutex_unlock(&sptlrpc_conf_lock);
872 get_default_flavor(sf);
874 flavor_set_flags(sf, from, to, 1);
878 * called by target devices, determine the expected flavor from
879 * certain peer (from, nid).
881 void sptlrpc_target_choose_flavor(struct sptlrpc_rule_set *rset,
882 enum lustre_sec_part from,
884 struct sptlrpc_flavor *sf)
886 if (sptlrpc_rule_set_choose(rset, from, LUSTRE_SP_ANY, nid, sf) == 0)
887 get_default_flavor(sf);
890 #define SEC_ADAPT_DELAY (10)
893 * called by client devices, notify the sptlrpc config has changed and
894 * do import_sec_adapt later.
896 void sptlrpc_conf_client_adapt(struct obd_device *obd)
898 struct obd_import *imp;
902 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
903 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
904 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) == 0 ||
905 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) == 0);
906 CDEBUG(D_SEC, "obd %s\n", obd->u.cli.cl_target_uuid.uuid);
908 /* serialize with connect/disconnect import */
909 with_imp_locked_nested(obd, imp, rc, OBD_CLI_SEM_MDCOSC) {
910 write_lock(&imp->imp_sec_lock);
912 imp->imp_sec_expire = ktime_get_real_seconds() +
914 write_unlock(&imp->imp_sec_lock);
919 EXPORT_SYMBOL(sptlrpc_conf_client_adapt);
922 * called by target devices, extract sptlrpc rules which applies to
923 * this target, to be used for future rpc flavor checking.
925 int sptlrpc_conf_target_get_rules(struct obd_device *obd,
926 struct sptlrpc_rule_set *rset)
928 struct sptlrpc_conf *conf;
929 struct sptlrpc_conf_tgt *conf_tgt;
930 enum lustre_sec_part sp_dst;
931 char fsname[MTI_NAME_MAXLEN];
935 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDT_NAME) == 0) {
936 sp_dst = LUSTRE_SP_MDT;
937 } else if (strcmp(obd->obd_type->typ_name, LUSTRE_OST_NAME) == 0) {
938 sp_dst = LUSTRE_SP_OST;
940 CERROR("unexpected obd type %s\n", obd->obd_type->typ_name);
944 obd_uuid2fsname(fsname, obd->obd_uuid.uuid, sizeof(fsname));
946 mutex_lock(&sptlrpc_conf_lock);
947 conf = sptlrpc_conf_get(fsname, 0);
949 CERROR("missing sptlrpc config log\n");
952 /* extract rule set for this target */
953 conf_tgt = sptlrpc_conf_get_tgt(conf, obd->obd_name, 0);
955 rc = sptlrpc_rule_set_extract(&conf->sc_rset,
956 conf_tgt ? &conf_tgt->sct_rset : NULL,
957 LUSTRE_SP_ANY, sp_dst, rset);
959 mutex_unlock(&sptlrpc_conf_lock);
964 int sptlrpc_conf_init(void)
966 mutex_init(&sptlrpc_conf_lock);
970 void sptlrpc_conf_fini(void)
972 struct sptlrpc_conf *conf, *conf_next;
974 mutex_lock(&sptlrpc_conf_lock);
975 list_for_each_entry_safe(conf, conf_next, &sptlrpc_confs, sc_list)
976 sptlrpc_conf_free(conf);
977 LASSERT(list_empty(&sptlrpc_confs));
978 mutex_unlock(&sptlrpc_conf_lock);