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/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #define DEBUG_SUBSYSTEM S_SEC
35 #include <libcfs/libcfs.h>
36 #include <linux/crypto.h>
37 #include <linux/key.h>
40 #include <obd_class.h>
41 #include <obd_support.h>
42 #include <lustre_net.h>
43 #include <lustre_import.h>
44 #include <lustre_log.h>
45 #include <lustre_disk.h>
46 #include <lustre_dlm.h>
47 #include <uapi/linux/lustre/lustre_param.h>
48 #include <lustre_sec.h>
50 #include "ptlrpc_internal.h"
52 const char *sptlrpc_part2name(enum lustre_sec_part part)
71 EXPORT_SYMBOL(sptlrpc_part2name);
73 enum lustre_sec_part sptlrpc_target_sec_part(struct obd_device *obd)
75 const char *type = obd->obd_type->typ_name;
77 if (!strcmp(type, LUSTRE_MDT_NAME))
79 if (!strcmp(type, LUSTRE_OST_NAME))
81 if (!strcmp(type, LUSTRE_MGS_NAME))
84 CERROR("unknown target %p(%s)\n", obd, type);
88 /****************************************
89 * user supplied flavor string parsing *
90 ****************************************/
93 * format: <base_flavor>[-<bulk_type:alg_spec>]
95 int sptlrpc_parse_flavor(const char *str, struct sptlrpc_flavor *flvr)
100 memset(flvr, 0, sizeof(*flvr));
102 if (str == NULL || str[0] == '\0') {
103 flvr->sf_rpc = SPTLRPC_FLVR_INVALID;
107 strlcpy(buf, str, sizeof(buf));
109 bulk = strchr(buf, '-');
113 flvr->sf_rpc = sptlrpc_name2flavor_base(buf);
114 if (flvr->sf_rpc == SPTLRPC_FLVR_INVALID)
118 * currently only base flavor "plain" can have bulk specification.
120 if (flvr->sf_rpc == SPTLRPC_FLVR_PLAIN) {
121 flvr->u_bulk.hash.hash_alg = BULK_HASH_ALG_ADLER32;
124 * format: plain-hash:<hash_alg>
126 alg = strchr(bulk, ':');
131 if (strcmp(bulk, "hash"))
134 flvr->u_bulk.hash.hash_alg = sptlrpc_get_hash_alg(alg);
135 if (flvr->u_bulk.hash.hash_alg >= BULK_HASH_ALG_MAX)
139 if (flvr->u_bulk.hash.hash_alg == BULK_HASH_ALG_NULL)
140 flvr_set_bulk_svc(&flvr->sf_rpc, SPTLRPC_BULK_SVC_NULL);
142 flvr_set_bulk_svc(&flvr->sf_rpc, SPTLRPC_BULK_SVC_INTG);
152 CERROR("invalid flavor string: %s\n", str);
155 EXPORT_SYMBOL(sptlrpc_parse_flavor);
157 /****************************************
159 ****************************************/
161 static void get_default_flavor(struct sptlrpc_flavor *sf)
163 memset(sf, 0, sizeof(*sf));
165 sf->sf_rpc = SPTLRPC_FLVR_NULL;
169 static void sptlrpc_rule_init(struct sptlrpc_rule *rule)
171 rule->sr_netid = LNET_NIDNET(LNET_NID_ANY);
172 rule->sr_from = LUSTRE_SP_ANY;
173 rule->sr_to = LUSTRE_SP_ANY;
174 rule->sr_padding = 0;
176 get_default_flavor(&rule->sr_flvr);
180 * format: network[.direction]=flavor
182 int sptlrpc_parse_rule(char *param, struct sptlrpc_rule *rule)
187 sptlrpc_rule_init(rule);
189 flavor = strchr(param, '=');
190 if (flavor == NULL) {
191 CERROR("invalid param, no '='\n");
196 dir = strchr(param, '.');
201 if (strcmp(param, "default")) {
202 rule->sr_netid = libcfs_str2net(param);
203 if (rule->sr_netid == LNET_NIDNET(LNET_NID_ANY)) {
204 CERROR("invalid network name: %s\n", param);
211 if (!strcmp(dir, "mdt2ost")) {
212 rule->sr_from = LUSTRE_SP_MDT;
213 rule->sr_to = LUSTRE_SP_OST;
214 } else if (!strcmp(dir, "mdt2mdt")) {
215 rule->sr_from = LUSTRE_SP_MDT;
216 rule->sr_to = LUSTRE_SP_MDT;
217 } else if (!strcmp(dir, "cli2ost")) {
218 rule->sr_from = LUSTRE_SP_CLI;
219 rule->sr_to = LUSTRE_SP_OST;
220 } else if (!strcmp(dir, "cli2mdt")) {
221 rule->sr_from = LUSTRE_SP_CLI;
222 rule->sr_to = LUSTRE_SP_MDT;
224 CERROR("invalid rule dir segment: %s\n", dir);
230 rc = sptlrpc_parse_flavor(flavor, &rule->sr_flvr);
236 EXPORT_SYMBOL(sptlrpc_parse_rule);
238 void sptlrpc_rule_set_free(struct sptlrpc_rule_set *rset)
240 LASSERT(rset->srs_nslot ||
241 (rset->srs_nrule == 0 && rset->srs_rules == NULL));
243 if (rset->srs_nslot) {
244 OBD_FREE_PTR_ARRAY(rset->srs_rules, rset->srs_nslot);
245 sptlrpc_rule_set_init(rset);
248 EXPORT_SYMBOL(sptlrpc_rule_set_free);
251 * return 0 if the rule set could accomodate one more rule.
253 int sptlrpc_rule_set_expand(struct sptlrpc_rule_set *rset)
255 struct sptlrpc_rule *rules;
260 if (rset->srs_nrule < rset->srs_nslot)
263 nslot = rset->srs_nslot + 8;
265 /* better use realloc() if available */
266 OBD_ALLOC_PTR_ARRAY(rules, nslot);
270 if (rset->srs_nrule) {
271 LASSERT(rset->srs_nslot && rset->srs_rules);
272 memcpy(rules, rset->srs_rules,
273 rset->srs_nrule * sizeof(*rset->srs_rules));
275 OBD_FREE_PTR_ARRAY(rset->srs_rules, rset->srs_nslot);
278 rset->srs_rules = rules;
279 rset->srs_nslot = nslot;
283 static inline int rule_spec_dir(struct sptlrpc_rule *rule)
285 return (rule->sr_from != LUSTRE_SP_ANY ||
286 rule->sr_to != LUSTRE_SP_ANY);
288 static inline int rule_spec_net(struct sptlrpc_rule *rule)
290 return (rule->sr_netid != LNET_NIDNET(LNET_NID_ANY));
292 static inline int rule_match_dir(struct sptlrpc_rule *r1,
293 struct sptlrpc_rule *r2)
295 return (r1->sr_from == r2->sr_from && r1->sr_to == r2->sr_to);
297 static inline int rule_match_net(struct sptlrpc_rule *r1,
298 struct sptlrpc_rule *r2)
300 return (r1->sr_netid == r2->sr_netid);
304 * merge @rule into @rset.
305 * the @rset slots might be expanded.
307 int sptlrpc_rule_set_merge(struct sptlrpc_rule_set *rset,
308 struct sptlrpc_rule *rule)
310 struct sptlrpc_rule *p = rset->srs_rules;
311 int spec_dir, spec_net;
312 int rc, n, match = 0;
316 spec_net = rule_spec_net(rule);
317 spec_dir = rule_spec_dir(rule);
319 for (n = 0; n < rset->srs_nrule; n++) {
320 p = &rset->srs_rules[n];
322 /* test network match, if failed:
323 * - spec rule: skip rules which is also spec rule match, until
324 * we hit a wild rule, which means no more chance
325 * - wild rule: skip until reach the one which is also wild
328 if (!rule_match_net(p, rule)) {
330 if (rule_spec_net(p))
339 /* test dir match, same logic as net matching */
340 if (!rule_match_dir(p, rule)) {
342 if (rule_spec_dir(p))
357 LASSERT(n >= 0 && n < rset->srs_nrule);
359 if (rule->sr_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
360 /* remove this rule */
361 if (n < rset->srs_nrule - 1)
362 memmove(&rset->srs_rules[n],
363 &rset->srs_rules[n + 1],
364 (rset->srs_nrule - n - 1) *
368 /* override the rule */
369 memcpy(&rset->srs_rules[n], rule, sizeof(*rule));
372 LASSERT(n >= 0 && n <= rset->srs_nrule);
374 if (rule->sr_flvr.sf_rpc != SPTLRPC_FLVR_INVALID) {
375 rc = sptlrpc_rule_set_expand(rset);
379 if (n < rset->srs_nrule)
380 memmove(&rset->srs_rules[n + 1],
382 (rset->srs_nrule - n) * sizeof(*rule));
383 memcpy(&rset->srs_rules[n], rule, sizeof(*rule));
386 CDEBUG(D_CONFIG, "ignore the unmatched deletion\n");
392 EXPORT_SYMBOL(sptlrpc_rule_set_merge);
395 * given from/to/nid, determine a matching flavor in ruleset.
396 * return 1 if a match found, otherwise return 0.
398 int sptlrpc_rule_set_choose(struct sptlrpc_rule_set *rset,
399 enum lustre_sec_part from,
400 enum lustre_sec_part to,
402 struct sptlrpc_flavor *sf)
404 struct sptlrpc_rule *r;
407 for (n = 0; n < rset->srs_nrule; n++) {
408 r = &rset->srs_rules[n];
410 if (LNET_NIDNET(nid) != LNET_NIDNET(LNET_NID_ANY) &&
411 r->sr_netid != LNET_NIDNET(LNET_NID_ANY) &&
412 LNET_NIDNET(nid) != r->sr_netid)
415 if (from != LUSTRE_SP_ANY && r->sr_from != LUSTRE_SP_ANY &&
419 if (to != LUSTRE_SP_ANY && r->sr_to != LUSTRE_SP_ANY &&
430 void sptlrpc_rule_set_dump(struct sptlrpc_rule_set *rset)
432 struct sptlrpc_rule *r;
435 for (n = 0; n < rset->srs_nrule; n++) {
436 r = &rset->srs_rules[n];
437 CDEBUG(D_SEC, "<%02d> from %x to %x, net %x, rpc %x\n", n,
438 r->sr_from, r->sr_to, r->sr_netid, r->sr_flvr.sf_rpc);
442 static int sptlrpc_rule_set_extract(struct sptlrpc_rule_set *gen,
443 struct sptlrpc_rule_set *tgt,
444 enum lustre_sec_part from,
445 enum lustre_sec_part to,
446 struct sptlrpc_rule_set *rset)
448 struct sptlrpc_rule_set *src[2] = { gen, tgt };
449 struct sptlrpc_rule *rule;
454 /* merge general rules firstly, then target-specific rules */
455 for (i = 0; i < 2; i++) {
459 for (n = 0; n < src[i]->srs_nrule; n++) {
460 rule = &src[i]->srs_rules[n];
462 if (from != LUSTRE_SP_ANY &&
463 rule->sr_from != LUSTRE_SP_ANY &&
464 rule->sr_from != from)
466 if (to != LUSTRE_SP_ANY &&
467 rule->sr_to != LUSTRE_SP_ANY &&
471 rc = sptlrpc_rule_set_merge(rset, rule);
473 CERROR("can't merge: %d\n", rc);
482 /**********************************
483 * sptlrpc configuration support *
484 **********************************/
486 struct sptlrpc_conf_tgt {
487 struct list_head sct_list;
488 char sct_name[MAX_OBD_NAME];
489 struct sptlrpc_rule_set sct_rset;
492 struct sptlrpc_conf {
493 struct list_head sc_list;
494 char sc_fsname[MTI_NAME_MAXLEN];
495 unsigned int sc_modified; /* modified during updating */
496 unsigned int sc_updated:1, /* updated copy from MGS */
497 sc_local:1; /* local copy from target */
498 struct sptlrpc_rule_set sc_rset; /* fs general rules */
499 struct list_head sc_tgts; /* target-specific rules */
502 static struct mutex sptlrpc_conf_lock;
503 static LIST_HEAD(sptlrpc_confs);
505 static void sptlrpc_conf_free_rsets(struct sptlrpc_conf *conf)
507 struct sptlrpc_conf_tgt *conf_tgt, *conf_tgt_next;
509 sptlrpc_rule_set_free(&conf->sc_rset);
511 list_for_each_entry_safe(conf_tgt, conf_tgt_next,
512 &conf->sc_tgts, sct_list) {
513 sptlrpc_rule_set_free(&conf_tgt->sct_rset);
514 list_del(&conf_tgt->sct_list);
515 OBD_FREE_PTR(conf_tgt);
517 LASSERT(list_empty(&conf->sc_tgts));
519 conf->sc_updated = 0;
523 static void sptlrpc_conf_free(struct sptlrpc_conf *conf)
525 CDEBUG(D_SEC, "free sptlrpc conf %s\n", conf->sc_fsname);
527 sptlrpc_conf_free_rsets(conf);
528 list_del(&conf->sc_list);
533 struct sptlrpc_conf_tgt *sptlrpc_conf_get_tgt(struct sptlrpc_conf *conf,
537 struct sptlrpc_conf_tgt *conf_tgt;
539 list_for_each_entry(conf_tgt, &conf->sc_tgts, sct_list) {
540 if (strcmp(conf_tgt->sct_name, name) == 0)
547 OBD_ALLOC_PTR(conf_tgt);
549 strlcpy(conf_tgt->sct_name, name, sizeof(conf_tgt->sct_name));
550 sptlrpc_rule_set_init(&conf_tgt->sct_rset);
551 list_add(&conf_tgt->sct_list, &conf->sc_tgts);
558 struct sptlrpc_conf *sptlrpc_conf_get(const char *fsname,
561 struct sptlrpc_conf *conf;
563 list_for_each_entry(conf, &sptlrpc_confs, sc_list) {
564 if (strcmp(conf->sc_fsname, fsname) == 0)
575 if (strlcpy(conf->sc_fsname, fsname, sizeof(conf->sc_fsname)) >=
576 sizeof(conf->sc_fsname)) {
580 sptlrpc_rule_set_init(&conf->sc_rset);
581 INIT_LIST_HEAD(&conf->sc_tgts);
582 list_add(&conf->sc_list, &sptlrpc_confs);
584 CDEBUG(D_SEC, "create sptlrpc conf %s\n", conf->sc_fsname);
589 * caller must hold conf_lock already.
591 static int sptlrpc_conf_merge_rule(struct sptlrpc_conf *conf,
593 struct sptlrpc_rule *rule)
595 struct sptlrpc_conf_tgt *conf_tgt;
596 struct sptlrpc_rule_set *rule_set;
598 /* fsname == target means general rules for the whole fs */
599 if (strcmp(conf->sc_fsname, target) == 0) {
600 rule_set = &conf->sc_rset;
602 conf_tgt = sptlrpc_conf_get_tgt(conf, target, 1);
604 rule_set = &conf_tgt->sct_rset;
606 CERROR("out of memory, can't merge rule!\n");
611 return sptlrpc_rule_set_merge(rule_set, rule);
615 * process one LCFG_SPTLRPC_CONF record. if \a conf is NULL, we
616 * find one through the target name in the record inside conf_lock;
617 * otherwise means caller already hold conf_lock.
619 static int __sptlrpc_process_config(char *target, const char *fsname,
620 struct sptlrpc_rule *rule,
621 struct sptlrpc_conf *conf)
630 mutex_lock(&sptlrpc_conf_lock);
631 conf = sptlrpc_conf_get(fsname, 0);
633 CERROR("can't find conf\n");
636 rc = sptlrpc_conf_merge_rule(conf, target, rule);
638 mutex_unlock(&sptlrpc_conf_lock);
640 LASSERT(mutex_is_locked(&sptlrpc_conf_lock));
641 rc = sptlrpc_conf_merge_rule(conf, target, rule);
650 int sptlrpc_process_config(struct lustre_cfg *lcfg)
652 char fsname[MTI_NAME_MAXLEN];
653 struct sptlrpc_rule rule;
654 char *target, *param;
657 print_lustre_cfg(lcfg);
659 target = lustre_cfg_string(lcfg, 1);
661 CERROR("missing target name\n");
665 param = lustre_cfg_string(lcfg, 2);
667 CERROR("missing parameter\n");
671 /* parse rule to make sure the format is correct */
672 if (strncmp(param, PARAM_SRPC_FLVR,
673 sizeof(PARAM_SRPC_FLVR) - 1) != 0) {
674 CERROR("Invalid sptlrpc parameter: %s\n", param);
677 param += sizeof(PARAM_SRPC_FLVR) - 1;
679 CDEBUG(D_SEC, "processing rule: %s.%s\n", target, param);
682 * Three types of targets exist for sptlrpc using conf_param
683 * 1. '_mgs' which targets mgc srpc settings. Treat it as
684 * as a special file system name.
685 * 2. target is a device which can be fsname-MDTXXXX or
686 * fsname-OSTXXXX. This can be verified by the function
687 * server_name2fsname.
688 * 3. If both above conditions are not meet then the target
689 * is a actual filesystem.
691 if (server_name2fsname(target, fsname, NULL))
692 strlcpy(fsname, target, sizeof(target));
694 rc = sptlrpc_parse_rule(param, &rule);
698 return __sptlrpc_process_config(target, fsname, &rule, NULL);
700 EXPORT_SYMBOL(sptlrpc_process_config);
702 static int logname2fsname(const char *logname, char *buf, int buflen)
707 ptr = strrchr(logname, '-');
708 if (ptr == NULL || strcmp(ptr, "-sptlrpc")) {
709 CERROR("%s is not a sptlrpc config log\n", logname);
713 len = min((int) (ptr - logname), buflen - 1);
715 memcpy(buf, logname, len);
720 void sptlrpc_conf_log_update_begin(const char *logname)
722 struct sptlrpc_conf *conf;
725 if (logname2fsname(logname, fsname, sizeof(fsname)))
728 mutex_lock(&sptlrpc_conf_lock);
730 conf = sptlrpc_conf_get(fsname, 0);
732 if (conf->sc_local) {
733 LASSERT(conf->sc_updated == 0);
734 sptlrpc_conf_free_rsets(conf);
736 conf->sc_modified = 0;
739 mutex_unlock(&sptlrpc_conf_lock);
741 EXPORT_SYMBOL(sptlrpc_conf_log_update_begin);
744 * mark a config log has been updated
746 void sptlrpc_conf_log_update_end(const char *logname)
748 struct sptlrpc_conf *conf;
751 if (logname2fsname(logname, fsname, sizeof(fsname)))
754 mutex_lock(&sptlrpc_conf_lock);
756 conf = sptlrpc_conf_get(fsname, 0);
759 * if original state is not updated, make sure the
760 * modified counter > 0 to enforce updating local copy.
762 if (conf->sc_updated == 0)
765 conf->sc_updated = 1;
768 mutex_unlock(&sptlrpc_conf_lock);
770 EXPORT_SYMBOL(sptlrpc_conf_log_update_end);
772 void sptlrpc_conf_log_start(const char *logname)
776 if (logname2fsname(logname, fsname, sizeof(fsname)))
779 mutex_lock(&sptlrpc_conf_lock);
780 sptlrpc_conf_get(fsname, 1);
781 mutex_unlock(&sptlrpc_conf_lock);
783 EXPORT_SYMBOL(sptlrpc_conf_log_start);
785 void sptlrpc_conf_log_stop(const char *logname)
787 struct sptlrpc_conf *conf;
790 if (logname2fsname(logname, fsname, sizeof(fsname)))
793 mutex_lock(&sptlrpc_conf_lock);
794 conf = sptlrpc_conf_get(fsname, 0);
796 sptlrpc_conf_free(conf);
797 mutex_unlock(&sptlrpc_conf_lock);
799 EXPORT_SYMBOL(sptlrpc_conf_log_stop);
801 static void inline flavor_set_flags(struct sptlrpc_flavor *sf,
802 enum lustre_sec_part from,
803 enum lustre_sec_part to,
804 unsigned int fl_udesc)
807 * null flavor doesn't need to set any flavor, and in fact
808 * we'd better not do that because everybody share a single sec.
810 if (sf->sf_rpc == SPTLRPC_FLVR_NULL)
813 if (from == LUSTRE_SP_MDT) {
814 /* MDT->MDT; MDT->OST */
815 sf->sf_flags |= PTLRPC_SEC_FL_ROOTONLY;
816 } else if (from == LUSTRE_SP_CLI && to == LUSTRE_SP_OST) {
818 sf->sf_flags |= PTLRPC_SEC_FL_ROOTONLY | PTLRPC_SEC_FL_BULK;
819 } else if (from == LUSTRE_SP_CLI && to == LUSTRE_SP_MDT) {
821 if (fl_udesc && sf->sf_rpc != SPTLRPC_FLVR_NULL)
822 sf->sf_flags |= PTLRPC_SEC_FL_UDESC;
825 /* Some flavors use a single uid (0) context */
826 if (flvr_is_rootonly(sf->sf_rpc))
827 sf->sf_flags |= PTLRPC_SEC_FL_ROOTONLY;
829 /* User descriptor might need to be cleared */
830 if (flvr_allows_user_desc(sf->sf_rpc) == 0)
831 sf->sf_flags &= ~PTLRPC_SEC_FL_UDESC;
834 void sptlrpc_conf_choose_flavor(enum lustre_sec_part from,
835 enum lustre_sec_part to,
836 struct obd_uuid *target,
838 struct sptlrpc_flavor *sf)
840 struct sptlrpc_conf *conf;
841 struct sptlrpc_conf_tgt *conf_tgt;
842 char name[MTI_NAME_MAXLEN];
845 obd_uuid2fsname(name, target->uuid, sizeof(name));
847 mutex_lock(&sptlrpc_conf_lock);
849 conf = sptlrpc_conf_get(name, 0);
853 /* convert uuid name (supposed end with _UUID) to target name */
854 len = strlen(target->uuid);
856 memcpy(name, target->uuid, len - 5);
857 name[len - 5] = '\0';
859 conf_tgt = sptlrpc_conf_get_tgt(conf, name, 0);
861 rc = sptlrpc_rule_set_choose(&conf_tgt->sct_rset,
867 rc = sptlrpc_rule_set_choose(&conf->sc_rset, from, to, 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;
901 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
902 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
903 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) == 0 ||
904 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) == 0);
905 CDEBUG(D_SEC, "obd %s\n", obd->u.cli.cl_target_uuid.uuid);
907 /* serialize with connect/disconnect import */
908 down_read_nested(&obd->u.cli.cl_sem, OBD_CLI_SEM_MDCOSC);
910 imp = obd->u.cli.cl_import;
912 write_lock(&imp->imp_sec_lock);
914 imp->imp_sec_expire = ktime_get_real_seconds() +
916 write_unlock(&imp->imp_sec_lock);
919 up_read(&obd->u.cli.cl_sem);
922 EXPORT_SYMBOL(sptlrpc_conf_client_adapt);
925 * called by target devices, extract sptlrpc rules which applies to
926 * this target, to be used for future rpc flavor checking.
928 int sptlrpc_conf_target_get_rules(struct obd_device *obd,
929 struct sptlrpc_rule_set *rset)
931 struct sptlrpc_conf *conf;
932 struct sptlrpc_conf_tgt *conf_tgt;
933 enum lustre_sec_part sp_dst;
934 char fsname[MTI_NAME_MAXLEN];
938 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDT_NAME) == 0) {
939 sp_dst = LUSTRE_SP_MDT;
940 } else if (strcmp(obd->obd_type->typ_name, LUSTRE_OST_NAME) == 0) {
941 sp_dst = LUSTRE_SP_OST;
943 CERROR("unexpected obd type %s\n", obd->obd_type->typ_name);
947 obd_uuid2fsname(fsname, obd->obd_uuid.uuid, sizeof(fsname));
949 mutex_lock(&sptlrpc_conf_lock);
950 conf = sptlrpc_conf_get(fsname, 0);
952 CERROR("missing sptlrpc config log\n");
955 /* extract rule set for this target */
956 conf_tgt = sptlrpc_conf_get_tgt(conf, obd->obd_name, 0);
958 rc = sptlrpc_rule_set_extract(&conf->sc_rset,
959 conf_tgt ? &conf_tgt->sct_rset : NULL,
960 LUSTRE_SP_ANY, sp_dst, rset);
962 mutex_unlock(&sptlrpc_conf_lock);
967 int sptlrpc_conf_init(void)
969 mutex_init(&sptlrpc_conf_lock);
973 void sptlrpc_conf_fini(void)
975 struct sptlrpc_conf *conf, *conf_next;
977 mutex_lock(&sptlrpc_conf_lock);
978 list_for_each_entry_safe(conf, conf_next, &sptlrpc_confs, sc_list)
979 sptlrpc_conf_free(conf);
980 LASSERT(list_empty(&sptlrpc_confs));
981 mutex_unlock(&sptlrpc_conf_lock);