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,
400 struct lnet_nid *nid,
401 struct sptlrpc_flavor *sf)
403 struct sptlrpc_rule *r;
407 /* do not enforce any sec flavor on loopback connection */
410 for (n = 0; n < rset->srs_nrule; n++) {
411 r = &rset->srs_rules[n];
413 if (!LNET_NID_IS_ANY(nid) &&
414 r->sr_netid != LNET_NET_ANY &&
415 __be16_to_cpu(nid->nid_num) != r->sr_netid)
418 if (from != LUSTRE_SP_ANY && r->sr_from != LUSTRE_SP_ANY &&
422 if (to != LUSTRE_SP_ANY && r->sr_to != LUSTRE_SP_ANY &&
433 void sptlrpc_rule_set_dump(struct sptlrpc_rule_set *rset)
435 struct sptlrpc_rule *r;
438 for (n = 0; n < rset->srs_nrule; n++) {
439 r = &rset->srs_rules[n];
440 CDEBUG(D_SEC, "<%02d> from %x to %x, net %x, rpc %x\n", n,
441 r->sr_from, r->sr_to, r->sr_netid, r->sr_flvr.sf_rpc);
445 static int sptlrpc_rule_set_extract(struct sptlrpc_rule_set *gen,
446 struct sptlrpc_rule_set *tgt,
447 enum lustre_sec_part from,
448 enum lustre_sec_part to,
449 struct sptlrpc_rule_set *rset)
451 struct sptlrpc_rule_set *src[2] = { gen, tgt };
452 struct sptlrpc_rule *rule;
457 /* merge general rules firstly, then target-specific rules */
458 for (i = 0; i < 2; i++) {
462 for (n = 0; n < src[i]->srs_nrule; n++) {
463 rule = &src[i]->srs_rules[n];
465 if (from != LUSTRE_SP_ANY &&
466 rule->sr_from != LUSTRE_SP_ANY &&
467 rule->sr_from != from)
469 if (to != LUSTRE_SP_ANY &&
470 rule->sr_to != LUSTRE_SP_ANY &&
474 rc = sptlrpc_rule_set_merge(rset, rule);
476 CERROR("can't merge: %d\n", rc);
485 /**********************************
486 * sptlrpc configuration support *
487 **********************************/
489 struct sptlrpc_conf_tgt {
490 struct list_head sct_list;
491 char sct_name[MAX_OBD_NAME];
492 struct sptlrpc_rule_set sct_rset;
495 struct sptlrpc_conf {
496 struct list_head sc_list;
497 char sc_fsname[MTI_NAME_MAXLEN];
498 unsigned int sc_modified; /* modified during updating */
499 unsigned int sc_updated:1, /* updated copy from MGS */
500 sc_local:1; /* local copy from target */
501 struct sptlrpc_rule_set sc_rset; /* fs general rules */
502 struct list_head sc_tgts; /* target-specific rules */
505 static struct mutex sptlrpc_conf_lock;
506 static LIST_HEAD(sptlrpc_confs);
508 static void sptlrpc_conf_free_rsets(struct sptlrpc_conf *conf)
510 struct sptlrpc_conf_tgt *conf_tgt, *conf_tgt_next;
512 sptlrpc_rule_set_free(&conf->sc_rset);
514 list_for_each_entry_safe(conf_tgt, conf_tgt_next,
515 &conf->sc_tgts, sct_list) {
516 sptlrpc_rule_set_free(&conf_tgt->sct_rset);
517 list_del(&conf_tgt->sct_list);
518 OBD_FREE_PTR(conf_tgt);
520 LASSERT(list_empty(&conf->sc_tgts));
522 conf->sc_updated = 0;
526 static void sptlrpc_conf_free(struct sptlrpc_conf *conf)
528 CDEBUG(D_SEC, "free sptlrpc conf %s\n", conf->sc_fsname);
530 sptlrpc_conf_free_rsets(conf);
531 list_del(&conf->sc_list);
536 struct sptlrpc_conf_tgt *sptlrpc_conf_get_tgt(struct sptlrpc_conf *conf,
540 struct sptlrpc_conf_tgt *conf_tgt;
542 list_for_each_entry(conf_tgt, &conf->sc_tgts, sct_list) {
543 if (strcmp(conf_tgt->sct_name, name) == 0)
550 OBD_ALLOC_PTR(conf_tgt);
552 strlcpy(conf_tgt->sct_name, name, sizeof(conf_tgt->sct_name));
553 sptlrpc_rule_set_init(&conf_tgt->sct_rset);
554 list_add(&conf_tgt->sct_list, &conf->sc_tgts);
561 struct sptlrpc_conf *sptlrpc_conf_get(const char *fsname,
564 struct sptlrpc_conf *conf;
566 list_for_each_entry(conf, &sptlrpc_confs, sc_list) {
567 if (strcmp(conf->sc_fsname, fsname) == 0)
578 if (strlcpy(conf->sc_fsname, fsname, sizeof(conf->sc_fsname)) >=
579 sizeof(conf->sc_fsname)) {
583 sptlrpc_rule_set_init(&conf->sc_rset);
584 INIT_LIST_HEAD(&conf->sc_tgts);
585 list_add(&conf->sc_list, &sptlrpc_confs);
587 CDEBUG(D_SEC, "create sptlrpc conf %s\n", conf->sc_fsname);
592 * caller must hold conf_lock already.
594 static int sptlrpc_conf_merge_rule(struct sptlrpc_conf *conf,
596 struct sptlrpc_rule *rule)
598 struct sptlrpc_conf_tgt *conf_tgt;
599 struct sptlrpc_rule_set *rule_set;
601 /* fsname == target means general rules for the whole fs */
602 if (strcmp(conf->sc_fsname, target) == 0) {
603 rule_set = &conf->sc_rset;
605 conf_tgt = sptlrpc_conf_get_tgt(conf, target, 1);
607 rule_set = &conf_tgt->sct_rset;
609 CERROR("out of memory, can't merge rule!\n");
614 return sptlrpc_rule_set_merge(rule_set, rule);
618 * process one LCFG_SPTLRPC_CONF record. if \a conf is NULL, we
619 * find one through the target name in the record inside conf_lock;
620 * otherwise means caller already hold conf_lock.
622 static int __sptlrpc_process_config(char *target, const char *fsname,
623 struct sptlrpc_rule *rule,
624 struct sptlrpc_conf *conf)
633 mutex_lock(&sptlrpc_conf_lock);
634 conf = sptlrpc_conf_get(fsname, 0);
636 CERROR("can't find conf\n");
639 rc = sptlrpc_conf_merge_rule(conf, target, rule);
641 mutex_unlock(&sptlrpc_conf_lock);
643 LASSERT(mutex_is_locked(&sptlrpc_conf_lock));
644 rc = sptlrpc_conf_merge_rule(conf, target, rule);
653 int sptlrpc_process_config(struct lustre_cfg *lcfg)
655 char fsname[MTI_NAME_MAXLEN];
656 struct sptlrpc_rule rule;
657 char *target, *param;
660 print_lustre_cfg(lcfg);
662 target = lustre_cfg_string(lcfg, 1);
664 CERROR("missing target name\n");
668 param = lustre_cfg_string(lcfg, 2);
670 CERROR("missing parameter\n");
674 /* parse rule to make sure the format is correct */
675 if (strncmp(param, PARAM_SRPC_FLVR,
676 sizeof(PARAM_SRPC_FLVR) - 1) != 0) {
677 CERROR("Invalid sptlrpc parameter: %s\n", param);
680 param += sizeof(PARAM_SRPC_FLVR) - 1;
682 CDEBUG(D_SEC, "processing rule: %s.%s\n", target, param);
685 * Three types of targets exist for sptlrpc using conf_param
686 * 1. '_mgs' which targets mgc srpc settings. Treat it as
687 * as a special file system name.
688 * 2. target is a device which can be fsname-MDTXXXX or
689 * fsname-OSTXXXX. This can be verified by the function
690 * server_name2fsname.
691 * 3. If both above conditions are not meet then the target
692 * is a actual filesystem.
694 if (server_name2fsname(target, fsname, NULL))
695 strlcpy(fsname, target, sizeof(fsname));
697 rc = sptlrpc_parse_rule(param, &rule);
701 return __sptlrpc_process_config(target, fsname, &rule, NULL);
703 EXPORT_SYMBOL(sptlrpc_process_config);
705 static int logname2fsname(const char *logname, char *buf, int buflen)
710 ptr = strrchr(logname, '-');
711 if (ptr == NULL || strcmp(ptr, "-sptlrpc")) {
712 CERROR("%s is not a sptlrpc config log\n", logname);
716 len = min((int) (ptr - logname), buflen - 1);
718 memcpy(buf, logname, len);
723 void sptlrpc_conf_log_update_begin(const char *logname)
725 struct sptlrpc_conf *conf;
728 if (logname2fsname(logname, fsname, sizeof(fsname)))
731 mutex_lock(&sptlrpc_conf_lock);
733 conf = sptlrpc_conf_get(fsname, 0);
735 if (conf->sc_local) {
736 LASSERT(conf->sc_updated == 0);
737 sptlrpc_conf_free_rsets(conf);
739 conf->sc_modified = 0;
742 mutex_unlock(&sptlrpc_conf_lock);
744 EXPORT_SYMBOL(sptlrpc_conf_log_update_begin);
747 * mark a config log has been updated
749 void sptlrpc_conf_log_update_end(const char *logname)
751 struct sptlrpc_conf *conf;
754 if (logname2fsname(logname, fsname, sizeof(fsname)))
757 mutex_lock(&sptlrpc_conf_lock);
759 conf = sptlrpc_conf_get(fsname, 0);
762 * if original state is not updated, make sure the
763 * modified counter > 0 to enforce updating local copy.
765 if (conf->sc_updated == 0)
768 conf->sc_updated = 1;
771 mutex_unlock(&sptlrpc_conf_lock);
773 EXPORT_SYMBOL(sptlrpc_conf_log_update_end);
775 void sptlrpc_conf_log_start(const char *logname)
779 if (logname2fsname(logname, fsname, sizeof(fsname)))
782 mutex_lock(&sptlrpc_conf_lock);
783 sptlrpc_conf_get(fsname, 1);
784 mutex_unlock(&sptlrpc_conf_lock);
786 EXPORT_SYMBOL(sptlrpc_conf_log_start);
788 void sptlrpc_conf_log_stop(const char *logname)
790 struct sptlrpc_conf *conf;
793 if (logname2fsname(logname, fsname, sizeof(fsname)))
796 mutex_lock(&sptlrpc_conf_lock);
797 conf = sptlrpc_conf_get(fsname, 0);
799 sptlrpc_conf_free(conf);
800 mutex_unlock(&sptlrpc_conf_lock);
802 EXPORT_SYMBOL(sptlrpc_conf_log_stop);
804 static void inline flavor_set_flags(struct sptlrpc_flavor *sf,
805 enum lustre_sec_part from,
806 enum lustre_sec_part to,
807 unsigned int fl_udesc)
810 * null flavor doesn't need to set any flavor, and in fact
811 * we'd better not do that because everybody share a single sec.
813 if (sf->sf_rpc == SPTLRPC_FLVR_NULL)
816 if (from == LUSTRE_SP_MDT) {
817 /* MDT->MDT; MDT->OST */
818 sf->sf_flags |= PTLRPC_SEC_FL_ROOTONLY;
819 } else if (from == LUSTRE_SP_CLI && to == LUSTRE_SP_OST) {
821 sf->sf_flags |= PTLRPC_SEC_FL_ROOTONLY | PTLRPC_SEC_FL_BULK;
822 } else if (from == LUSTRE_SP_CLI && to == LUSTRE_SP_MDT) {
824 if (fl_udesc && sf->sf_rpc != SPTLRPC_FLVR_NULL)
825 sf->sf_flags |= PTLRPC_SEC_FL_UDESC;
828 /* Some flavors use a single uid (0) context */
829 if (flvr_is_rootonly(sf->sf_rpc))
830 sf->sf_flags |= PTLRPC_SEC_FL_ROOTONLY;
832 /* User descriptor might need to be cleared */
833 if (flvr_allows_user_desc(sf->sf_rpc) == 0)
834 sf->sf_flags &= ~PTLRPC_SEC_FL_UDESC;
837 void sptlrpc_conf_choose_flavor(enum lustre_sec_part from,
838 enum lustre_sec_part to,
839 struct obd_uuid *target,
840 struct lnet_nid *nid,
841 struct sptlrpc_flavor *sf)
843 struct sptlrpc_conf *conf;
844 struct sptlrpc_conf_tgt *conf_tgt;
845 char name[MTI_NAME_MAXLEN];
848 obd_uuid2fsname(name, target->uuid, sizeof(name));
850 mutex_lock(&sptlrpc_conf_lock);
852 conf = sptlrpc_conf_get(name, 0);
856 /* convert uuid name (supposed end with _UUID) to target name */
857 len = strlen(target->uuid);
859 memcpy(name, target->uuid, len - 5);
860 name[len - 5] = '\0';
862 conf_tgt = sptlrpc_conf_get_tgt(conf, name, 0);
864 rc = sptlrpc_rule_set_choose(&conf_tgt->sct_rset,
870 rc = sptlrpc_rule_set_choose(&conf->sc_rset, from, to,
873 mutex_unlock(&sptlrpc_conf_lock);
876 get_default_flavor(sf);
878 flavor_set_flags(sf, from, to, 1);
882 * called by target devices, determine the expected flavor from
883 * certain peer (from, nid).
885 void sptlrpc_target_choose_flavor(struct sptlrpc_rule_set *rset,
886 enum lustre_sec_part from,
887 struct lnet_nid *nid,
888 struct sptlrpc_flavor *sf)
890 if (sptlrpc_rule_set_choose(rset, from, LUSTRE_SP_ANY, nid, sf) == 0)
891 get_default_flavor(sf);
894 #define SEC_ADAPT_DELAY (10)
897 * called by client devices, notify the sptlrpc config has changed and
898 * do import_sec_adapt later.
900 void sptlrpc_conf_client_adapt(struct obd_device *obd)
902 struct obd_import *imp;
906 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
907 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
908 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) == 0 ||
909 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) == 0);
910 CDEBUG(D_SEC, "obd %s\n", obd->u.cli.cl_target_uuid.uuid);
912 /* serialize with connect/disconnect import */
913 with_imp_locked_nested(obd, imp, rc, OBD_CLI_SEM_MDCOSC) {
914 write_lock(&imp->imp_sec_lock);
916 imp->imp_sec_expire = ktime_get_real_seconds() +
918 write_unlock(&imp->imp_sec_lock);
923 EXPORT_SYMBOL(sptlrpc_conf_client_adapt);
926 * called by target devices, extract sptlrpc rules which applies to
927 * this target, to be used for future rpc flavor checking.
929 int sptlrpc_conf_target_get_rules(struct obd_device *obd,
930 struct sptlrpc_rule_set *rset)
932 struct sptlrpc_conf *conf;
933 struct sptlrpc_conf_tgt *conf_tgt;
934 enum lustre_sec_part sp_dst;
935 char fsname[MTI_NAME_MAXLEN];
939 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDT_NAME) == 0) {
940 sp_dst = LUSTRE_SP_MDT;
941 } else if (strcmp(obd->obd_type->typ_name, LUSTRE_OST_NAME) == 0) {
942 sp_dst = LUSTRE_SP_OST;
944 CERROR("unexpected obd type %s\n", obd->obd_type->typ_name);
948 obd_uuid2fsname(fsname, obd->obd_uuid.uuid, sizeof(fsname));
950 mutex_lock(&sptlrpc_conf_lock);
951 conf = sptlrpc_conf_get(fsname, 0);
953 CERROR("missing sptlrpc config log\n");
956 /* extract rule set for this target */
957 conf_tgt = sptlrpc_conf_get_tgt(conf, obd->obd_name, 0);
959 rc = sptlrpc_rule_set_extract(&conf->sc_rset,
960 conf_tgt ? &conf_tgt->sct_rset : NULL,
961 LUSTRE_SP_ANY, sp_dst, rset);
963 mutex_unlock(&sptlrpc_conf_lock);
968 int sptlrpc_conf_init(void)
970 mutex_init(&sptlrpc_conf_lock);
974 void sptlrpc_conf_fini(void)
976 struct sptlrpc_conf *conf, *conf_next;
978 mutex_lock(&sptlrpc_conf_lock);
979 list_for_each_entry_safe(conf, conf_next, &sptlrpc_confs, sc_list)
980 sptlrpc_conf_free(conf);
981 LASSERT(list_empty(&sptlrpc_confs));
982 mutex_unlock(&sptlrpc_conf_lock);