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, 2016, 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(rset->srs_rules,
245 rset->srs_nslot * sizeof(*rset->srs_rules));
246 sptlrpc_rule_set_init(rset);
249 EXPORT_SYMBOL(sptlrpc_rule_set_free);
252 * return 0 if the rule set could accomodate one more rule.
254 int sptlrpc_rule_set_expand(struct sptlrpc_rule_set *rset)
256 struct sptlrpc_rule *rules;
261 if (rset->srs_nrule < rset->srs_nslot)
264 nslot = rset->srs_nslot + 8;
266 /* better use realloc() if available */
267 OBD_ALLOC(rules, nslot * sizeof(*rset->srs_rules));
271 if (rset->srs_nrule) {
272 LASSERT(rset->srs_nslot && rset->srs_rules);
273 memcpy(rules, rset->srs_rules,
274 rset->srs_nrule * sizeof(*rset->srs_rules));
276 OBD_FREE(rset->srs_rules,
277 rset->srs_nslot * sizeof(*rset->srs_rules));
280 rset->srs_rules = rules;
281 rset->srs_nslot = nslot;
285 static inline int rule_spec_dir(struct sptlrpc_rule *rule)
287 return (rule->sr_from != LUSTRE_SP_ANY ||
288 rule->sr_to != LUSTRE_SP_ANY);
290 static inline int rule_spec_net(struct sptlrpc_rule *rule)
292 return (rule->sr_netid != LNET_NIDNET(LNET_NID_ANY));
294 static inline int rule_match_dir(struct sptlrpc_rule *r1,
295 struct sptlrpc_rule *r2)
297 return (r1->sr_from == r2->sr_from && r1->sr_to == r2->sr_to);
299 static inline int rule_match_net(struct sptlrpc_rule *r1,
300 struct sptlrpc_rule *r2)
302 return (r1->sr_netid == r2->sr_netid);
306 * merge @rule into @rset.
307 * the @rset slots might be expanded.
309 int sptlrpc_rule_set_merge(struct sptlrpc_rule_set *rset,
310 struct sptlrpc_rule *rule)
312 struct sptlrpc_rule *p = rset->srs_rules;
313 int spec_dir, spec_net;
314 int rc, n, match = 0;
318 spec_net = rule_spec_net(rule);
319 spec_dir = rule_spec_dir(rule);
321 for (n = 0; n < rset->srs_nrule; n++) {
322 p = &rset->srs_rules[n];
324 /* test network match, if failed:
325 * - spec rule: skip rules which is also spec rule match, until
326 * we hit a wild rule, which means no more chance
327 * - wild rule: skip until reach the one which is also wild
330 if (!rule_match_net(p, rule)) {
332 if (rule_spec_net(p))
341 /* test dir match, same logic as net matching */
342 if (!rule_match_dir(p, rule)) {
344 if (rule_spec_dir(p))
359 LASSERT(n >= 0 && n < rset->srs_nrule);
361 if (rule->sr_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
362 /* remove this rule */
363 if (n < rset->srs_nrule - 1)
364 memmove(&rset->srs_rules[n],
365 &rset->srs_rules[n + 1],
366 (rset->srs_nrule - n - 1) *
370 /* override the rule */
371 memcpy(&rset->srs_rules[n], rule, sizeof(*rule));
374 LASSERT(n >= 0 && n <= rset->srs_nrule);
376 if (rule->sr_flvr.sf_rpc != SPTLRPC_FLVR_INVALID) {
377 rc = sptlrpc_rule_set_expand(rset);
381 if (n < rset->srs_nrule)
382 memmove(&rset->srs_rules[n + 1],
384 (rset->srs_nrule - n) * sizeof(*rule));
385 memcpy(&rset->srs_rules[n], rule, sizeof(*rule));
388 CDEBUG(D_CONFIG, "ignore the unmatched deletion\n");
394 EXPORT_SYMBOL(sptlrpc_rule_set_merge);
397 * given from/to/nid, determine a matching flavor in ruleset.
398 * return 1 if a match found, otherwise return 0.
400 int sptlrpc_rule_set_choose(struct sptlrpc_rule_set *rset,
401 enum lustre_sec_part from,
402 enum lustre_sec_part to,
404 struct sptlrpc_flavor *sf)
406 struct sptlrpc_rule *r;
409 for (n = 0; n < rset->srs_nrule; n++) {
410 r = &rset->srs_rules[n];
412 if (LNET_NIDNET(nid) != LNET_NIDNET(LNET_NID_ANY) &&
413 r->sr_netid != LNET_NIDNET(LNET_NID_ANY) &&
414 LNET_NIDNET(nid) != r->sr_netid)
417 if (from != LUSTRE_SP_ANY && r->sr_from != LUSTRE_SP_ANY &&
421 if (to != LUSTRE_SP_ANY && r->sr_to != LUSTRE_SP_ANY &&
432 void sptlrpc_rule_set_dump(struct sptlrpc_rule_set *rset)
434 struct sptlrpc_rule *r;
437 for (n = 0; n < rset->srs_nrule; n++) {
438 r = &rset->srs_rules[n];
439 CDEBUG(D_SEC, "<%02d> from %x to %x, net %x, rpc %x\n", n,
440 r->sr_from, r->sr_to, r->sr_netid, r->sr_flvr.sf_rpc);
444 static int sptlrpc_rule_set_extract(struct sptlrpc_rule_set *gen,
445 struct sptlrpc_rule_set *tgt,
446 enum lustre_sec_part from,
447 enum lustre_sec_part to,
448 struct sptlrpc_rule_set *rset)
450 struct sptlrpc_rule_set *src[2] = { gen, tgt };
451 struct sptlrpc_rule *rule;
456 /* merge general rules firstly, then target-specific rules */
457 for (i = 0; i < 2; i++) {
461 for (n = 0; n < src[i]->srs_nrule; n++) {
462 rule = &src[i]->srs_rules[n];
464 if (from != LUSTRE_SP_ANY &&
465 rule->sr_from != LUSTRE_SP_ANY &&
466 rule->sr_from != from)
468 if (to != LUSTRE_SP_ANY &&
469 rule->sr_to != LUSTRE_SP_ANY &&
473 rc = sptlrpc_rule_set_merge(rset, rule);
475 CERROR("can't merge: %d\n", rc);
484 /**********************************
485 * sptlrpc configuration support *
486 **********************************/
488 struct sptlrpc_conf_tgt {
489 struct list_head sct_list;
490 char sct_name[MAX_OBD_NAME];
491 struct sptlrpc_rule_set sct_rset;
494 struct sptlrpc_conf {
495 struct list_head sc_list;
496 char sc_fsname[MTI_NAME_MAXLEN];
497 unsigned int sc_modified; /* modified during updating */
498 unsigned int sc_updated:1, /* updated copy from MGS */
499 sc_local:1; /* local copy from target */
500 struct sptlrpc_rule_set sc_rset; /* fs general rules */
501 struct list_head sc_tgts; /* target-specific rules */
504 static struct mutex sptlrpc_conf_lock;
505 static struct list_head sptlrpc_confs;
508 * The goal of this function is to extract the file system name
509 * from the obd name. This can come in two flavors. One is
510 * fsname-MDTXXXX or fsname-XXXXXXX were X is a hexadecimal
511 * number. In both cases we should be returned fsname. If it is
512 * not a valid obd name it is assumed to be the file system
515 static void obdname2fsname(const char *tgt, char *fsname, size_t buflen)
520 ptr = strrchr(tgt, '-');
522 if ((!strncmp(ptr, "-MDT", 4) ||
523 !strncmp(ptr, "-OST", 4)) &&
524 (isxdigit(ptr[4]) && isxdigit(ptr[5]) &&
525 isxdigit(ptr[6]) && isxdigit(ptr[7])))
528 /* The length of the obdname can vary on different platforms */
531 if (!isxdigit(ptr[len])) {
539 /* if we didn't find the pattern, treat the whole string as fsname */
545 len = min(len, buflen - 1);
546 memcpy(fsname, tgt, len);
550 static void sptlrpc_conf_free_rsets(struct sptlrpc_conf *conf)
552 struct sptlrpc_conf_tgt *conf_tgt, *conf_tgt_next;
554 sptlrpc_rule_set_free(&conf->sc_rset);
556 list_for_each_entry_safe(conf_tgt, conf_tgt_next,
557 &conf->sc_tgts, sct_list) {
558 sptlrpc_rule_set_free(&conf_tgt->sct_rset);
559 list_del(&conf_tgt->sct_list);
560 OBD_FREE_PTR(conf_tgt);
562 LASSERT(list_empty(&conf->sc_tgts));
564 conf->sc_updated = 0;
568 static void sptlrpc_conf_free(struct sptlrpc_conf *conf)
570 CDEBUG(D_SEC, "free sptlrpc conf %s\n", conf->sc_fsname);
572 sptlrpc_conf_free_rsets(conf);
573 list_del(&conf->sc_list);
578 struct sptlrpc_conf_tgt *sptlrpc_conf_get_tgt(struct sptlrpc_conf *conf,
582 struct sptlrpc_conf_tgt *conf_tgt;
584 list_for_each_entry(conf_tgt, &conf->sc_tgts, sct_list) {
585 if (strcmp(conf_tgt->sct_name, name) == 0)
592 OBD_ALLOC_PTR(conf_tgt);
594 strlcpy(conf_tgt->sct_name, name, sizeof(conf_tgt->sct_name));
595 sptlrpc_rule_set_init(&conf_tgt->sct_rset);
596 list_add(&conf_tgt->sct_list, &conf->sc_tgts);
603 struct sptlrpc_conf *sptlrpc_conf_get(const char *fsname,
606 struct sptlrpc_conf *conf;
608 list_for_each_entry(conf, &sptlrpc_confs, sc_list) {
609 if (strcmp(conf->sc_fsname, fsname) == 0)
620 if (strlcpy(conf->sc_fsname, fsname, sizeof(conf->sc_fsname)) >=
621 sizeof(conf->sc_fsname)) {
625 sptlrpc_rule_set_init(&conf->sc_rset);
626 INIT_LIST_HEAD(&conf->sc_tgts);
627 list_add(&conf->sc_list, &sptlrpc_confs);
629 CDEBUG(D_SEC, "create sptlrpc conf %s\n", conf->sc_fsname);
634 * caller must hold conf_lock already.
636 static int sptlrpc_conf_merge_rule(struct sptlrpc_conf *conf,
638 struct sptlrpc_rule *rule)
640 struct sptlrpc_conf_tgt *conf_tgt;
641 struct sptlrpc_rule_set *rule_set;
643 /* fsname == target means general rules for the whole fs */
644 if (strcmp(conf->sc_fsname, target) == 0) {
645 rule_set = &conf->sc_rset;
647 conf_tgt = sptlrpc_conf_get_tgt(conf, target, 1);
649 rule_set = &conf_tgt->sct_rset;
651 CERROR("out of memory, can't merge rule!\n");
656 return sptlrpc_rule_set_merge(rule_set, rule);
660 * process one LCFG_SPTLRPC_CONF record. if \a conf is NULL, we
661 * find one through the target name in the record inside conf_lock;
662 * otherwise means caller already hold conf_lock.
664 static int __sptlrpc_process_config(struct lustre_cfg *lcfg,
665 struct sptlrpc_conf *conf)
667 char *target, *param;
668 char fsname[MTI_NAME_MAXLEN];
669 struct sptlrpc_rule rule;
673 target = lustre_cfg_string(lcfg, 1);
674 if (target == NULL) {
675 CERROR("missing target name\n");
679 param = lustre_cfg_string(lcfg, 2);
681 CERROR("missing parameter\n");
685 CDEBUG(D_SEC, "processing rule: %s.%s\n", target, param);
687 /* parse rule to make sure the format is correct */
688 if (strncmp(param, PARAM_SRPC_FLVR, sizeof(PARAM_SRPC_FLVR) - 1) != 0) {
689 CERROR("Invalid sptlrpc parameter: %s\n", param);
692 param += sizeof(PARAM_SRPC_FLVR) - 1;
694 rc = sptlrpc_parse_rule(param, &rule);
699 obdname2fsname(target, fsname, sizeof(fsname));
701 mutex_lock(&sptlrpc_conf_lock);
702 conf = sptlrpc_conf_get(fsname, 0);
704 CERROR("can't find conf\n");
707 rc = sptlrpc_conf_merge_rule(conf, target, &rule);
709 mutex_unlock(&sptlrpc_conf_lock);
711 LASSERT(mutex_is_locked(&sptlrpc_conf_lock));
712 rc = sptlrpc_conf_merge_rule(conf, target, &rule);
721 int sptlrpc_process_config(struct lustre_cfg *lcfg)
723 return __sptlrpc_process_config(lcfg, NULL);
725 EXPORT_SYMBOL(sptlrpc_process_config);
727 static int logname2fsname(const char *logname, char *buf, int buflen)
732 ptr = strrchr(logname, '-');
733 if (ptr == NULL || strcmp(ptr, "-sptlrpc")) {
734 CERROR("%s is not a sptlrpc config log\n", logname);
738 len = min((int) (ptr - logname), buflen - 1);
740 memcpy(buf, logname, len);
745 void sptlrpc_conf_log_update_begin(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);
757 if (conf->sc_local) {
758 LASSERT(conf->sc_updated == 0);
759 sptlrpc_conf_free_rsets(conf);
761 conf->sc_modified = 0;
764 mutex_unlock(&sptlrpc_conf_lock);
766 EXPORT_SYMBOL(sptlrpc_conf_log_update_begin);
769 * mark a config log has been updated
771 void sptlrpc_conf_log_update_end(const char *logname)
773 struct sptlrpc_conf *conf;
776 if (logname2fsname(logname, fsname, sizeof(fsname)))
779 mutex_lock(&sptlrpc_conf_lock);
781 conf = sptlrpc_conf_get(fsname, 0);
784 * if original state is not updated, make sure the
785 * modified counter > 0 to enforce updating local copy.
787 if (conf->sc_updated == 0)
790 conf->sc_updated = 1;
793 mutex_unlock(&sptlrpc_conf_lock);
795 EXPORT_SYMBOL(sptlrpc_conf_log_update_end);
797 void sptlrpc_conf_log_start(const char *logname)
801 if (logname2fsname(logname, fsname, sizeof(fsname)))
804 mutex_lock(&sptlrpc_conf_lock);
805 sptlrpc_conf_get(fsname, 1);
806 mutex_unlock(&sptlrpc_conf_lock);
808 EXPORT_SYMBOL(sptlrpc_conf_log_start);
810 void sptlrpc_conf_log_stop(const char *logname)
812 struct sptlrpc_conf *conf;
815 if (logname2fsname(logname, fsname, sizeof(fsname)))
818 mutex_lock(&sptlrpc_conf_lock);
819 conf = sptlrpc_conf_get(fsname, 0);
821 sptlrpc_conf_free(conf);
822 mutex_unlock(&sptlrpc_conf_lock);
824 EXPORT_SYMBOL(sptlrpc_conf_log_stop);
826 static void inline flavor_set_flags(struct sptlrpc_flavor *sf,
827 enum lustre_sec_part from,
828 enum lustre_sec_part to,
829 unsigned int fl_udesc)
832 * null flavor doesn't need to set any flavor, and in fact
833 * we'd better not do that because everybody share a single sec.
835 if (sf->sf_rpc == SPTLRPC_FLVR_NULL)
838 if (from == LUSTRE_SP_MDT) {
839 /* MDT->MDT; MDT->OST */
840 sf->sf_flags |= PTLRPC_SEC_FL_ROOTONLY;
841 } else if (from == LUSTRE_SP_CLI && to == LUSTRE_SP_OST) {
843 sf->sf_flags |= PTLRPC_SEC_FL_ROOTONLY | PTLRPC_SEC_FL_BULK;
844 } else if (from == LUSTRE_SP_CLI && to == LUSTRE_SP_MDT) {
846 if (fl_udesc && sf->sf_rpc != SPTLRPC_FLVR_NULL)
847 sf->sf_flags |= PTLRPC_SEC_FL_UDESC;
850 /* Some flavors use a single uid (0) context */
851 if (flvr_is_rootonly(sf->sf_rpc))
852 sf->sf_flags |= PTLRPC_SEC_FL_ROOTONLY;
854 /* User descriptor might need to be cleared */
855 if (flvr_allows_user_desc(sf->sf_rpc) == 0)
856 sf->sf_flags &= ~PTLRPC_SEC_FL_UDESC;
859 void sptlrpc_conf_choose_flavor(enum lustre_sec_part from,
860 enum lustre_sec_part to,
861 struct obd_uuid *target,
863 struct sptlrpc_flavor *sf)
865 struct sptlrpc_conf *conf;
866 struct sptlrpc_conf_tgt *conf_tgt;
867 char name[MTI_NAME_MAXLEN];
870 obd_uuid2fsname(name, target->uuid, sizeof(name));
872 mutex_lock(&sptlrpc_conf_lock);
874 conf = sptlrpc_conf_get(name, 0);
878 /* convert uuid name (supposed end with _UUID) to target name */
879 len = strlen(target->uuid);
881 memcpy(name, target->uuid, len - 5);
882 name[len - 5] = '\0';
884 conf_tgt = sptlrpc_conf_get_tgt(conf, name, 0);
886 rc = sptlrpc_rule_set_choose(&conf_tgt->sct_rset,
892 rc = sptlrpc_rule_set_choose(&conf->sc_rset, from, to, nid, sf);
894 mutex_unlock(&sptlrpc_conf_lock);
897 get_default_flavor(sf);
899 flavor_set_flags(sf, from, to, 1);
903 * called by target devices, determine the expected flavor from
904 * certain peer (from, nid).
906 void sptlrpc_target_choose_flavor(struct sptlrpc_rule_set *rset,
907 enum lustre_sec_part from,
909 struct sptlrpc_flavor *sf)
911 if (sptlrpc_rule_set_choose(rset, from, LUSTRE_SP_ANY, nid, sf) == 0)
912 get_default_flavor(sf);
915 #define SEC_ADAPT_DELAY (10)
918 * called by client devices, notify the sptlrpc config has changed and
919 * do import_sec_adapt later.
921 void sptlrpc_conf_client_adapt(struct obd_device *obd)
923 struct obd_import *imp;
926 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
927 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
928 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) == 0 ||
929 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) == 0);
930 CDEBUG(D_SEC, "obd %s\n", obd->u.cli.cl_target_uuid.uuid);
932 /* serialize with connect/disconnect import */
933 down_read_nested(&obd->u.cli.cl_sem, OBD_CLI_SEM_MDCOSC);
935 imp = obd->u.cli.cl_import;
937 spin_lock(&imp->imp_lock);
939 imp->imp_sec_expire = ktime_get_real_seconds() +
941 spin_unlock(&imp->imp_lock);
944 up_read(&obd->u.cli.cl_sem);
947 EXPORT_SYMBOL(sptlrpc_conf_client_adapt);
950 * called by target devices, extract sptlrpc rules which applies to
951 * this target, to be used for future rpc flavor checking.
953 int sptlrpc_conf_target_get_rules(struct obd_device *obd,
954 struct sptlrpc_rule_set *rset)
956 struct sptlrpc_conf *conf;
957 struct sptlrpc_conf_tgt *conf_tgt;
958 enum lustre_sec_part sp_dst;
959 char fsname[MTI_NAME_MAXLEN];
963 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDT_NAME) == 0) {
964 sp_dst = LUSTRE_SP_MDT;
965 } else if (strcmp(obd->obd_type->typ_name, LUSTRE_OST_NAME) == 0) {
966 sp_dst = LUSTRE_SP_OST;
968 CERROR("unexpected obd type %s\n", obd->obd_type->typ_name);
972 obd_uuid2fsname(fsname, obd->obd_uuid.uuid, sizeof(fsname));
974 mutex_lock(&sptlrpc_conf_lock);
975 conf = sptlrpc_conf_get(fsname, 0);
977 CERROR("missing sptlrpc config log\n");
980 /* extract rule set for this target */
981 conf_tgt = sptlrpc_conf_get_tgt(conf, obd->obd_name, 0);
983 rc = sptlrpc_rule_set_extract(&conf->sc_rset,
984 conf_tgt ? &conf_tgt->sct_rset : NULL,
985 LUSTRE_SP_ANY, sp_dst, rset);
987 mutex_unlock(&sptlrpc_conf_lock);
992 int sptlrpc_conf_init(void)
994 INIT_LIST_HEAD(&sptlrpc_confs);
995 mutex_init(&sptlrpc_conf_lock);
999 void sptlrpc_conf_fini(void)
1001 struct sptlrpc_conf *conf, *conf_next;
1003 mutex_lock(&sptlrpc_conf_lock);
1004 list_for_each_entry_safe(conf, conf_next, &sptlrpc_confs, sc_list)
1005 sptlrpc_conf_free(conf);
1006 LASSERT(list_empty(&sptlrpc_confs));
1007 mutex_unlock(&sptlrpc_conf_lock);