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 /* user supplied flavor string parsing */
89 /* format: <base_flavor>[-<bulk_type:alg_spec>] */
90 int sptlrpc_parse_flavor(const char *str, struct sptlrpc_flavor *flvr)
95 memset(flvr, 0, sizeof(*flvr));
97 if (str == NULL || str[0] == '\0') {
98 flvr->sf_rpc = SPTLRPC_FLVR_INVALID;
102 strscpy(buf, str, sizeof(buf));
104 bulk = strchr(buf, '-');
108 flvr->sf_rpc = sptlrpc_name2flavor_base(buf);
109 if (flvr->sf_rpc == SPTLRPC_FLVR_INVALID)
112 /* currently only base flavor "plain" can have bulk specification. */
113 if (flvr->sf_rpc == SPTLRPC_FLVR_PLAIN) {
114 flvr->u_bulk.hash.hash_alg = BULK_HASH_ALG_ADLER32;
116 /* format: plain-hash:<hash_alg> */
117 alg = strchr(bulk, ':');
122 if (strcmp(bulk, "hash"))
125 flvr->u_bulk.hash.hash_alg = sptlrpc_get_hash_alg(alg);
126 if (flvr->u_bulk.hash.hash_alg >= BULK_HASH_ALG_MAX)
130 if (flvr->u_bulk.hash.hash_alg == BULK_HASH_ALG_NULL)
131 flvr_set_bulk_svc(&flvr->sf_rpc, SPTLRPC_BULK_SVC_NULL);
133 flvr_set_bulk_svc(&flvr->sf_rpc, SPTLRPC_BULK_SVC_INTG);
143 CERROR("invalid flavor string: %s\n", str);
146 EXPORT_SYMBOL(sptlrpc_parse_flavor);
148 /* configure rules */
150 static void get_default_flavor(struct sptlrpc_flavor *sf)
152 memset(sf, 0, sizeof(*sf));
154 sf->sf_rpc = SPTLRPC_FLVR_NULL;
158 static void sptlrpc_rule_init(struct sptlrpc_rule *rule)
160 rule->sr_netid = LNET_NET_ANY;
161 rule->sr_from = LUSTRE_SP_ANY;
162 rule->sr_to = LUSTRE_SP_ANY;
163 rule->sr_padding = 0;
165 get_default_flavor(&rule->sr_flvr);
168 /* format: network[.direction]=flavor */
169 int sptlrpc_parse_rule(char *param, struct sptlrpc_rule *rule)
174 sptlrpc_rule_init(rule);
176 flavor = strchr(param, '=');
177 if (flavor == NULL) {
178 CERROR("invalid param, no '='\n");
183 dir = strchr(param, '.');
188 if (strcmp(param, "default")) {
189 rule->sr_netid = libcfs_str2net(param);
190 if (rule->sr_netid == LNET_NET_ANY) {
191 CERROR("invalid network name: %s\n", param);
198 if (!strcmp(dir, "mdt2ost")) {
199 rule->sr_from = LUSTRE_SP_MDT;
200 rule->sr_to = LUSTRE_SP_OST;
201 } else if (!strcmp(dir, "mdt2mdt")) {
202 rule->sr_from = LUSTRE_SP_MDT;
203 rule->sr_to = LUSTRE_SP_MDT;
204 } else if (!strcmp(dir, "cli2ost")) {
205 rule->sr_from = LUSTRE_SP_CLI;
206 rule->sr_to = LUSTRE_SP_OST;
207 } else if (!strcmp(dir, "cli2mdt")) {
208 rule->sr_from = LUSTRE_SP_CLI;
209 rule->sr_to = LUSTRE_SP_MDT;
211 CERROR("invalid rule dir segment: %s\n", dir);
217 rc = sptlrpc_parse_flavor(flavor, &rule->sr_flvr);
223 EXPORT_SYMBOL(sptlrpc_parse_rule);
225 void sptlrpc_rule_set_free(struct sptlrpc_rule_set *rset)
227 LASSERT(rset->srs_nslot ||
228 (rset->srs_nrule == 0 && rset->srs_rules == NULL));
230 if (rset->srs_nslot) {
231 OBD_FREE_PTR_ARRAY(rset->srs_rules, rset->srs_nslot);
232 sptlrpc_rule_set_init(rset);
235 EXPORT_SYMBOL(sptlrpc_rule_set_free);
237 /* return 0 if the rule set could accomodate one more rule. */
238 int sptlrpc_rule_set_expand(struct sptlrpc_rule_set *rset)
240 struct sptlrpc_rule *rules;
245 if (rset->srs_nrule < rset->srs_nslot)
248 nslot = rset->srs_nslot + 8;
250 /* better use realloc() if available */
251 OBD_ALLOC_PTR_ARRAY(rules, nslot);
255 if (rset->srs_nrule) {
256 LASSERT(rset->srs_nslot && rset->srs_rules);
257 memcpy(rules, rset->srs_rules,
258 rset->srs_nrule * sizeof(*rset->srs_rules));
260 OBD_FREE_PTR_ARRAY(rset->srs_rules, rset->srs_nslot);
263 rset->srs_rules = rules;
264 rset->srs_nslot = nslot;
268 static inline int rule_spec_dir(struct sptlrpc_rule *rule)
270 return (rule->sr_from != LUSTRE_SP_ANY ||
271 rule->sr_to != LUSTRE_SP_ANY);
273 static inline int rule_spec_net(struct sptlrpc_rule *rule)
275 return (rule->sr_netid != LNET_NET_ANY);
277 static inline int rule_match_dir(struct sptlrpc_rule *r1,
278 struct sptlrpc_rule *r2)
280 return (r1->sr_from == r2->sr_from && r1->sr_to == r2->sr_to);
282 static inline int rule_match_net(struct sptlrpc_rule *r1,
283 struct sptlrpc_rule *r2)
285 return (r1->sr_netid == r2->sr_netid);
289 * merge @rule into @rset.
290 * the @rset slots might be expanded.
292 int sptlrpc_rule_set_merge(struct sptlrpc_rule_set *rset,
293 struct sptlrpc_rule *rule)
295 struct sptlrpc_rule *p = rset->srs_rules;
296 int spec_dir, spec_net;
297 int rc, n, match = 0;
301 spec_net = rule_spec_net(rule);
302 spec_dir = rule_spec_dir(rule);
304 for (n = 0; n < rset->srs_nrule; n++) {
305 p = &rset->srs_rules[n];
307 /* test network match, if failed:
308 * - spec rule: skip rules which is also spec rule match, until
309 * we hit a wild rule, which means no more chance
310 * - wild rule: skip until reach the one which is also wild
313 if (!rule_match_net(p, rule)) {
315 if (rule_spec_net(p))
324 /* test dir match, same logic as net matching */
325 if (!rule_match_dir(p, rule)) {
327 if (rule_spec_dir(p))
342 LASSERT(n >= 0 && n < rset->srs_nrule);
344 if (rule->sr_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
345 /* remove this rule */
346 if (n < rset->srs_nrule - 1)
347 memmove(&rset->srs_rules[n],
348 &rset->srs_rules[n + 1],
349 (rset->srs_nrule - n - 1) *
353 /* override the rule */
354 memcpy(&rset->srs_rules[n], rule, sizeof(*rule));
357 LASSERT(n >= 0 && n <= rset->srs_nrule);
359 if (rule->sr_flvr.sf_rpc != SPTLRPC_FLVR_INVALID) {
360 rc = sptlrpc_rule_set_expand(rset);
364 if (n < rset->srs_nrule)
365 memmove(&rset->srs_rules[n + 1],
367 (rset->srs_nrule - n) * sizeof(*rule));
368 memcpy(&rset->srs_rules[n], rule, sizeof(*rule));
371 CDEBUG(D_CONFIG, "ignore the unmatched deletion\n");
377 EXPORT_SYMBOL(sptlrpc_rule_set_merge);
380 * given from/to/nid, determine a matching flavor in ruleset.
381 * return 1 if a match found, otherwise return 0.
383 int sptlrpc_rule_set_choose(struct sptlrpc_rule_set *rset,
384 enum lustre_sec_part from,
385 enum lustre_sec_part to,
386 struct lnet_nid *nid,
387 struct sptlrpc_flavor *sf)
389 struct sptlrpc_rule *r;
393 /* do not enforce any sec flavor on loopback connection */
396 for (n = 0; n < rset->srs_nrule; n++) {
397 r = &rset->srs_rules[n];
399 if (!LNET_NID_IS_ANY(nid) &&
400 r->sr_netid != LNET_NET_ANY &&
401 __be16_to_cpu(nid->nid_num) != r->sr_netid)
404 if (from != LUSTRE_SP_ANY && r->sr_from != LUSTRE_SP_ANY &&
408 if (to != LUSTRE_SP_ANY && r->sr_to != LUSTRE_SP_ANY &&
419 void sptlrpc_rule_set_dump(struct sptlrpc_rule_set *rset)
421 struct sptlrpc_rule *r;
424 for (n = 0; n < rset->srs_nrule; n++) {
425 r = &rset->srs_rules[n];
426 CDEBUG(D_SEC, "<%02d> from %x to %x, net %x, rpc %x\n", n,
427 r->sr_from, r->sr_to, r->sr_netid, r->sr_flvr.sf_rpc);
431 static int sptlrpc_rule_set_extract(struct sptlrpc_rule_set *gen,
432 struct sptlrpc_rule_set *tgt,
433 enum lustre_sec_part from,
434 enum lustre_sec_part to,
435 struct sptlrpc_rule_set *rset)
437 struct sptlrpc_rule_set *src[2] = { gen, tgt };
438 struct sptlrpc_rule *rule;
443 /* merge general rules firstly, then target-specific rules */
444 for (i = 0; i < 2; i++) {
448 for (n = 0; n < src[i]->srs_nrule; n++) {
449 rule = &src[i]->srs_rules[n];
451 if (from != LUSTRE_SP_ANY &&
452 rule->sr_from != LUSTRE_SP_ANY &&
453 rule->sr_from != from)
455 if (to != LUSTRE_SP_ANY &&
456 rule->sr_to != LUSTRE_SP_ANY &&
460 rc = sptlrpc_rule_set_merge(rset, rule);
462 CERROR("can't merge: %d\n", rc);
471 /* sptlrpc configuration support */
473 struct sptlrpc_conf_tgt {
474 struct list_head sct_list;
475 char sct_name[MAX_OBD_NAME];
476 struct sptlrpc_rule_set sct_rset;
479 struct sptlrpc_conf {
480 struct list_head sc_list;
481 char sc_fsname[MTI_NAME_MAXLEN];
482 unsigned int sc_modified; /* modified during updating */
483 unsigned int sc_updated:1, /* updated copy from MGS */
484 sc_local:1; /* local copy from target */
485 struct sptlrpc_rule_set sc_rset; /* fs general rules */
486 struct list_head sc_tgts; /* target-specific rules */
489 static struct mutex sptlrpc_conf_lock;
490 static LIST_HEAD(sptlrpc_confs);
492 static void sptlrpc_conf_free_rsets(struct sptlrpc_conf *conf)
494 struct sptlrpc_conf_tgt *conf_tgt, *conf_tgt_next;
496 sptlrpc_rule_set_free(&conf->sc_rset);
498 list_for_each_entry_safe(conf_tgt, conf_tgt_next,
499 &conf->sc_tgts, sct_list) {
500 sptlrpc_rule_set_free(&conf_tgt->sct_rset);
501 list_del(&conf_tgt->sct_list);
502 OBD_FREE_PTR(conf_tgt);
504 LASSERT(list_empty(&conf->sc_tgts));
506 conf->sc_updated = 0;
510 static void sptlrpc_conf_free(struct sptlrpc_conf *conf)
512 CDEBUG(D_SEC, "free sptlrpc conf %s\n", conf->sc_fsname);
514 sptlrpc_conf_free_rsets(conf);
515 list_del(&conf->sc_list);
520 struct sptlrpc_conf_tgt *sptlrpc_conf_get_tgt(struct sptlrpc_conf *conf,
524 struct sptlrpc_conf_tgt *conf_tgt;
526 list_for_each_entry(conf_tgt, &conf->sc_tgts, sct_list) {
527 if (strcmp(conf_tgt->sct_name, name) == 0)
534 OBD_ALLOC_PTR(conf_tgt);
536 strscpy(conf_tgt->sct_name, name, sizeof(conf_tgt->sct_name));
537 sptlrpc_rule_set_init(&conf_tgt->sct_rset);
538 list_add(&conf_tgt->sct_list, &conf->sc_tgts);
545 struct sptlrpc_conf *sptlrpc_conf_get(const char *fsname,
548 struct sptlrpc_conf *conf;
550 list_for_each_entry(conf, &sptlrpc_confs, sc_list) {
551 if (strcmp(conf->sc_fsname, fsname) == 0)
561 if (strscpy(conf->sc_fsname, fsname, sizeof(conf->sc_fsname)) < 0) {
565 sptlrpc_rule_set_init(&conf->sc_rset);
566 INIT_LIST_HEAD(&conf->sc_tgts);
567 list_add(&conf->sc_list, &sptlrpc_confs);
569 CDEBUG(D_SEC, "create sptlrpc conf %s\n", conf->sc_fsname);
573 /* caller must hold conf_lock already. */
574 static int sptlrpc_conf_merge_rule(struct sptlrpc_conf *conf,
576 struct sptlrpc_rule *rule)
578 struct sptlrpc_conf_tgt *conf_tgt;
579 struct sptlrpc_rule_set *rule_set;
581 /* fsname == target means general rules for the whole fs */
582 if (strcmp(conf->sc_fsname, target) == 0) {
583 rule_set = &conf->sc_rset;
585 conf_tgt = sptlrpc_conf_get_tgt(conf, target, 1);
587 rule_set = &conf_tgt->sct_rset;
589 CERROR("out of memory, can't merge rule!\n");
594 return sptlrpc_rule_set_merge(rule_set, rule);
598 * process one LCFG_SPTLRPC_CONF record. if \a conf is NULL, we
599 * find one through the target name in the record inside conf_lock;
600 * otherwise means caller already hold conf_lock.
602 static int __sptlrpc_process_config(char *target, const char *fsname,
603 struct sptlrpc_rule *rule,
604 struct sptlrpc_conf *conf)
613 mutex_lock(&sptlrpc_conf_lock);
614 conf = sptlrpc_conf_get(fsname, 0);
616 CERROR("can't find conf\n");
619 rc = sptlrpc_conf_merge_rule(conf, target, rule);
621 mutex_unlock(&sptlrpc_conf_lock);
623 LASSERT(mutex_is_locked(&sptlrpc_conf_lock));
624 rc = sptlrpc_conf_merge_rule(conf, target, rule);
633 int sptlrpc_process_config(struct lustre_cfg *lcfg)
635 char fsname[MTI_NAME_MAXLEN];
636 struct sptlrpc_rule rule;
637 char *target, *param;
640 print_lustre_cfg(lcfg);
642 target = lustre_cfg_string(lcfg, 1);
644 CERROR("missing target name\n");
648 param = lustre_cfg_string(lcfg, 2);
650 CERROR("missing parameter\n");
654 /* parse rule to make sure the format is correct */
655 if (strncmp(param, PARAM_SRPC_FLVR,
656 sizeof(PARAM_SRPC_FLVR) - 1) != 0) {
657 CERROR("Invalid sptlrpc parameter: %s\n", param);
660 param += sizeof(PARAM_SRPC_FLVR) - 1;
662 CDEBUG(D_SEC, "processing rule: %s.%s\n", target, param);
665 * Three types of targets exist for sptlrpc using conf_param
666 * 1. '_mgs' which targets mgc srpc settings. Treat it as
667 * as a special file system name.
668 * 2. target is a device which can be fsname-MDTXXXX or
669 * fsname-OSTXXXX. This can be verified by the function
670 * server_name2fsname.
671 * 3. If both above conditions are not meet then the target
672 * is a actual filesystem.
674 if (server_name2fsname(target, fsname, NULL))
675 strscpy(fsname, target, sizeof(fsname));
677 rc = sptlrpc_parse_rule(param, &rule);
681 return __sptlrpc_process_config(target, fsname, &rule, NULL);
683 EXPORT_SYMBOL(sptlrpc_process_config);
685 static int logname2fsname(const char *logname, char *buf, int buflen)
690 ptr = strrchr(logname, '-');
691 if (ptr == NULL || strcmp(ptr, "-sptlrpc")) {
692 CERROR("%s is not a sptlrpc config log\n", logname);
696 len = min((int) (ptr - logname), buflen - 1);
698 memcpy(buf, logname, len);
703 void sptlrpc_conf_log_update_begin(const char *logname)
705 struct sptlrpc_conf *conf;
708 if (logname2fsname(logname, fsname, sizeof(fsname)))
711 mutex_lock(&sptlrpc_conf_lock);
713 conf = sptlrpc_conf_get(fsname, 0);
715 if (conf->sc_local) {
716 LASSERT(conf->sc_updated == 0);
717 sptlrpc_conf_free_rsets(conf);
719 conf->sc_modified = 0;
722 mutex_unlock(&sptlrpc_conf_lock);
724 EXPORT_SYMBOL(sptlrpc_conf_log_update_begin);
726 /* mark a config log has been updated */
727 void sptlrpc_conf_log_update_end(const char *logname)
729 struct sptlrpc_conf *conf;
732 if (logname2fsname(logname, fsname, sizeof(fsname)))
735 mutex_lock(&sptlrpc_conf_lock);
737 conf = sptlrpc_conf_get(fsname, 0);
739 /* if original state is not updated, make sure the
740 * modified counter > 0 to enforce updating local copy.
742 if (conf->sc_updated == 0)
745 conf->sc_updated = 1;
748 mutex_unlock(&sptlrpc_conf_lock);
750 EXPORT_SYMBOL(sptlrpc_conf_log_update_end);
752 void sptlrpc_conf_log_start(const char *logname)
756 if (logname2fsname(logname, fsname, sizeof(fsname)))
759 mutex_lock(&sptlrpc_conf_lock);
760 sptlrpc_conf_get(fsname, 1);
761 mutex_unlock(&sptlrpc_conf_lock);
763 EXPORT_SYMBOL(sptlrpc_conf_log_start);
765 void sptlrpc_conf_log_stop(const char *logname)
767 struct sptlrpc_conf *conf;
770 if (logname2fsname(logname, fsname, sizeof(fsname)))
773 mutex_lock(&sptlrpc_conf_lock);
774 conf = sptlrpc_conf_get(fsname, 0);
776 sptlrpc_conf_free(conf);
777 mutex_unlock(&sptlrpc_conf_lock);
779 EXPORT_SYMBOL(sptlrpc_conf_log_stop);
781 static inline void flavor_set_flags(struct sptlrpc_flavor *sf,
782 enum lustre_sec_part from,
783 enum lustre_sec_part to,
784 unsigned int fl_udesc)
786 /* null flavor doesn't need to set any flavor, and in fact
787 * we'd better not do that because everybody share a single sec.
789 if (sf->sf_rpc == SPTLRPC_FLVR_NULL)
792 if (from == LUSTRE_SP_MDT) {
793 /* MDT->MDT; MDT->OST */
794 sf->sf_flags |= PTLRPC_SEC_FL_ROOTONLY;
795 } else if (from == LUSTRE_SP_CLI && to == LUSTRE_SP_OST) {
797 sf->sf_flags |= PTLRPC_SEC_FL_ROOTONLY | PTLRPC_SEC_FL_BULK;
798 } else if (from == LUSTRE_SP_CLI && to == LUSTRE_SP_MDT) {
800 if (fl_udesc && sf->sf_rpc != SPTLRPC_FLVR_NULL)
801 sf->sf_flags |= PTLRPC_SEC_FL_UDESC;
804 /* Some flavors use a single uid (0) context */
805 if (flvr_is_rootonly(sf->sf_rpc))
806 sf->sf_flags |= PTLRPC_SEC_FL_ROOTONLY;
808 /* User descriptor might need to be cleared */
809 if (flvr_allows_user_desc(sf->sf_rpc) == 0)
810 sf->sf_flags &= ~PTLRPC_SEC_FL_UDESC;
813 void sptlrpc_conf_choose_flavor(enum lustre_sec_part from,
814 enum lustre_sec_part to,
815 struct obd_uuid *target,
816 struct lnet_nid *nid,
817 struct sptlrpc_flavor *sf)
819 struct sptlrpc_conf *conf;
820 struct sptlrpc_conf_tgt *conf_tgt;
821 char name[MTI_NAME_MAXLEN];
824 obd_uuid2fsname(name, target->uuid, sizeof(name));
826 mutex_lock(&sptlrpc_conf_lock);
828 conf = sptlrpc_conf_get(name, 0);
832 /* convert uuid name (supposed end with _UUID) to target name */
833 len = strlen(target->uuid);
835 memcpy(name, target->uuid, len - 5);
836 name[len - 5] = '\0';
838 conf_tgt = sptlrpc_conf_get_tgt(conf, name, 0);
840 rc = sptlrpc_rule_set_choose(&conf_tgt->sct_rset,
846 rc = sptlrpc_rule_set_choose(&conf->sc_rset, from, to,
849 mutex_unlock(&sptlrpc_conf_lock);
852 get_default_flavor(sf);
854 flavor_set_flags(sf, from, to, 1);
858 * called by target devices, determine the expected flavor from
859 * certain peer (from, nid).
861 void sptlrpc_target_choose_flavor(struct sptlrpc_rule_set *rset,
862 enum lustre_sec_part from,
863 struct lnet_nid *nid,
864 struct sptlrpc_flavor *sf)
866 if (sptlrpc_rule_set_choose(rset, from, LUSTRE_SP_ANY, nid, sf) == 0)
867 get_default_flavor(sf);
870 #define SEC_ADAPT_DELAY (10)
873 * called by client devices, notify the sptlrpc config has changed and
874 * do import_sec_adapt later.
876 void sptlrpc_conf_client_adapt(struct obd_device *obd)
878 struct obd_import *imp;
883 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
884 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
885 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) == 0 ||
886 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) == 0);
887 CDEBUG(D_SEC, "obd %s\n", obd->u.cli.cl_target_uuid.uuid);
889 /* serialize with connect/disconnect import */
890 with_imp_locked_nested(obd, imp, rc, OBD_CLI_SEM_MDCOSC) {
891 write_lock(&imp->imp_sec_lock);
893 imp->imp_sec_expire = ktime_get_real_seconds() +
895 write_unlock(&imp->imp_sec_lock);
900 EXPORT_SYMBOL(sptlrpc_conf_client_adapt);
903 * called by target devices, extract sptlrpc rules which applies to
904 * this target, to be used for future rpc flavor checking.
906 int sptlrpc_conf_target_get_rules(struct obd_device *obd,
907 struct sptlrpc_rule_set *rset)
909 struct sptlrpc_conf *conf;
910 struct sptlrpc_conf_tgt *conf_tgt;
911 enum lustre_sec_part sp_dst;
912 char fsname[MTI_NAME_MAXLEN];
917 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDT_NAME) == 0) {
918 sp_dst = LUSTRE_SP_MDT;
919 } else if (strcmp(obd->obd_type->typ_name, LUSTRE_OST_NAME) == 0) {
920 sp_dst = LUSTRE_SP_OST;
922 CERROR("unexpected obd type %s\n", obd->obd_type->typ_name);
926 obd_uuid2fsname(fsname, obd->obd_uuid.uuid, sizeof(fsname));
928 mutex_lock(&sptlrpc_conf_lock);
929 conf = sptlrpc_conf_get(fsname, 0);
931 CERROR("missing sptlrpc config log\n");
934 /* extract rule set for this target */
935 conf_tgt = sptlrpc_conf_get_tgt(conf, obd->obd_name, 0);
937 rc = sptlrpc_rule_set_extract(&conf->sc_rset,
938 conf_tgt ? &conf_tgt->sct_rset : NULL,
939 LUSTRE_SP_ANY, sp_dst, rset);
941 mutex_unlock(&sptlrpc_conf_lock);
946 int sptlrpc_conf_init(void)
948 mutex_init(&sptlrpc_conf_lock);
952 void sptlrpc_conf_fini(void)
954 struct sptlrpc_conf *conf, *conf_next;
956 mutex_lock(&sptlrpc_conf_lock);
957 list_for_each_entry_safe(conf, conf_next, &sptlrpc_confs, sc_list)
958 sptlrpc_conf_free(conf);
959 LASSERT(list_empty(&sptlrpc_confs));
960 mutex_unlock(&sptlrpc_conf_lock);