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) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2012, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
34 * Author: Eric Mei <ericm@clusterfs.com>
37 #define DEBUG_SUBSYSTEM S_SEC
39 #include "../../include/linux/libcfs/libcfs.h"
40 #include <linux/crypto.h>
41 #include <linux/key.h>
43 #include "../include/obd.h"
44 #include "../include/obd_class.h"
45 #include "../include/obd_support.h"
46 #include "../include/lustre_net.h"
47 #include "../include/lustre_import.h"
48 #include "../include/lustre_dlm.h"
49 #include "../include/lustre_sec.h"
51 #include "ptlrpc_internal.h"
53 /***********************************************
55 ***********************************************/
57 static rwlock_t policy_lock;
58 static struct ptlrpc_sec_policy *policies[SPTLRPC_POLICY_MAX] = {
62 int sptlrpc_register_policy(struct ptlrpc_sec_policy *policy)
64 __u16 number = policy->sp_policy;
66 LASSERT(policy->sp_name);
67 LASSERT(policy->sp_cops);
68 LASSERT(policy->sp_sops);
70 if (number >= SPTLRPC_POLICY_MAX)
73 write_lock(&policy_lock);
74 if (unlikely(policies[number])) {
75 write_unlock(&policy_lock);
78 policies[number] = policy;
79 write_unlock(&policy_lock);
81 CDEBUG(D_SEC, "%s: registered\n", policy->sp_name);
84 EXPORT_SYMBOL(sptlrpc_register_policy);
86 int sptlrpc_unregister_policy(struct ptlrpc_sec_policy *policy)
88 __u16 number = policy->sp_policy;
90 LASSERT(number < SPTLRPC_POLICY_MAX);
92 write_lock(&policy_lock);
93 if (unlikely(!policies[number])) {
94 write_unlock(&policy_lock);
95 CERROR("%s: already unregistered\n", policy->sp_name);
99 LASSERT(policies[number] == policy);
100 policies[number] = NULL;
101 write_unlock(&policy_lock);
103 CDEBUG(D_SEC, "%s: unregistered\n", policy->sp_name);
106 EXPORT_SYMBOL(sptlrpc_unregister_policy);
109 struct ptlrpc_sec_policy *sptlrpc_wireflavor2policy(__u32 flavor)
111 static DEFINE_MUTEX(load_mutex);
112 static atomic_t loaded = ATOMIC_INIT(0);
113 struct ptlrpc_sec_policy *policy;
114 __u16 number = SPTLRPC_FLVR_POLICY(flavor);
117 if (number >= SPTLRPC_POLICY_MAX)
121 read_lock(&policy_lock);
122 policy = policies[number];
123 if (policy && !try_module_get(policy->sp_owner))
126 flag = atomic_read(&loaded);
127 read_unlock(&policy_lock);
129 if (policy || flag != 0 ||
130 number != SPTLRPC_POLICY_GSS)
133 /* try to load gss module, once */
134 mutex_lock(&load_mutex);
135 if (atomic_read(&loaded) == 0) {
136 if (request_module("ptlrpc_gss") == 0)
138 "module ptlrpc_gss loaded on demand\n");
140 CERROR("Unable to load module ptlrpc_gss\n");
142 atomic_set(&loaded, 1);
144 mutex_unlock(&load_mutex);
150 __u32 sptlrpc_name2flavor_base(const char *name)
152 if (!strcmp(name, "null"))
153 return SPTLRPC_FLVR_NULL;
154 if (!strcmp(name, "plain"))
155 return SPTLRPC_FLVR_PLAIN;
156 if (!strcmp(name, "krb5n"))
157 return SPTLRPC_FLVR_KRB5N;
158 if (!strcmp(name, "krb5a"))
159 return SPTLRPC_FLVR_KRB5A;
160 if (!strcmp(name, "krb5i"))
161 return SPTLRPC_FLVR_KRB5I;
162 if (!strcmp(name, "krb5p"))
163 return SPTLRPC_FLVR_KRB5P;
165 return SPTLRPC_FLVR_INVALID;
167 EXPORT_SYMBOL(sptlrpc_name2flavor_base);
169 const char *sptlrpc_flavor2name_base(__u32 flvr)
171 __u32 base = SPTLRPC_FLVR_BASE(flvr);
173 if (base == SPTLRPC_FLVR_BASE(SPTLRPC_FLVR_NULL))
175 else if (base == SPTLRPC_FLVR_BASE(SPTLRPC_FLVR_PLAIN))
177 else if (base == SPTLRPC_FLVR_BASE(SPTLRPC_FLVR_KRB5N))
179 else if (base == SPTLRPC_FLVR_BASE(SPTLRPC_FLVR_KRB5A))
181 else if (base == SPTLRPC_FLVR_BASE(SPTLRPC_FLVR_KRB5I))
183 else if (base == SPTLRPC_FLVR_BASE(SPTLRPC_FLVR_KRB5P))
186 CERROR("invalid wire flavor 0x%x\n", flvr);
189 EXPORT_SYMBOL(sptlrpc_flavor2name_base);
191 char *sptlrpc_flavor2name_bulk(struct sptlrpc_flavor *sf,
192 char *buf, int bufsize)
194 if (SPTLRPC_FLVR_POLICY(sf->sf_rpc) == SPTLRPC_POLICY_PLAIN)
195 snprintf(buf, bufsize, "hash:%s",
196 sptlrpc_get_hash_name(sf->u_bulk.hash.hash_alg));
198 snprintf(buf, bufsize, "%s",
199 sptlrpc_flavor2name_base(sf->sf_rpc));
201 buf[bufsize - 1] = '\0';
204 EXPORT_SYMBOL(sptlrpc_flavor2name_bulk);
206 char *sptlrpc_flavor2name(struct sptlrpc_flavor *sf, char *buf, int bufsize)
208 strlcpy(buf, sptlrpc_flavor2name_base(sf->sf_rpc), bufsize);
211 * currently we don't support customized bulk specification for
212 * flavors other than plain
214 if (SPTLRPC_FLVR_POLICY(sf->sf_rpc) == SPTLRPC_POLICY_PLAIN) {
218 sptlrpc_flavor2name_bulk(sf, &bspec[1], sizeof(bspec) - 1);
219 strlcat(buf, bspec, bufsize);
224 EXPORT_SYMBOL(sptlrpc_flavor2name);
226 static char *sptlrpc_secflags2str(__u32 flags, char *buf, int bufsize)
230 if (flags & PTLRPC_SEC_FL_REVERSE)
231 strlcat(buf, "reverse,", bufsize);
232 if (flags & PTLRPC_SEC_FL_ROOTONLY)
233 strlcat(buf, "rootonly,", bufsize);
234 if (flags & PTLRPC_SEC_FL_UDESC)
235 strlcat(buf, "udesc,", bufsize);
236 if (flags & PTLRPC_SEC_FL_BULK)
237 strlcat(buf, "bulk,", bufsize);
239 strlcat(buf, "-,", bufsize);
244 /**************************************************
245 * client context APIs *
246 **************************************************/
249 struct ptlrpc_cli_ctx *get_my_ctx(struct ptlrpc_sec *sec)
251 struct vfs_cred vcred;
252 int create = 1, remove_dead = 1;
255 LASSERT(sec->ps_policy->sp_cops->lookup_ctx);
257 if (sec->ps_flvr.sf_flags & (PTLRPC_SEC_FL_REVERSE |
258 PTLRPC_SEC_FL_ROOTONLY)) {
261 if (sec->ps_flvr.sf_flags & PTLRPC_SEC_FL_REVERSE) {
266 vcred.vc_uid = from_kuid(&init_user_ns, current_uid());
267 vcred.vc_gid = from_kgid(&init_user_ns, current_gid());
270 return sec->ps_policy->sp_cops->lookup_ctx(sec, &vcred,
271 create, remove_dead);
274 struct ptlrpc_cli_ctx *sptlrpc_cli_ctx_get(struct ptlrpc_cli_ctx *ctx)
276 atomic_inc(&ctx->cc_refcount);
279 EXPORT_SYMBOL(sptlrpc_cli_ctx_get);
281 void sptlrpc_cli_ctx_put(struct ptlrpc_cli_ctx *ctx, int sync)
283 struct ptlrpc_sec *sec = ctx->cc_sec;
286 LASSERT_ATOMIC_POS(&ctx->cc_refcount);
288 if (!atomic_dec_and_test(&ctx->cc_refcount))
291 sec->ps_policy->sp_cops->release_ctx(sec, ctx, sync);
293 EXPORT_SYMBOL(sptlrpc_cli_ctx_put);
295 static int import_sec_check_expire(struct obd_import *imp)
299 spin_lock(&imp->imp_lock);
300 if (imp->imp_sec_expire &&
301 imp->imp_sec_expire < ktime_get_real_seconds()) {
303 imp->imp_sec_expire = 0;
305 spin_unlock(&imp->imp_lock);
310 CDEBUG(D_SEC, "found delayed sec adapt expired, do it now\n");
311 return sptlrpc_import_sec_adapt(imp, NULL, NULL);
314 static int import_sec_validate_get(struct obd_import *imp,
315 struct ptlrpc_sec **sec)
319 if (unlikely(imp->imp_sec_expire)) {
320 rc = import_sec_check_expire(imp);
325 *sec = sptlrpc_import_sec_ref(imp);
327 CERROR("import %p (%s) with no sec\n",
328 imp, ptlrpc_import_state_name(imp->imp_state));
332 if (unlikely((*sec)->ps_dying)) {
333 CERROR("attempt to use dying sec %p\n", sec);
334 sptlrpc_sec_put(*sec);
342 * Given a \a req, find or allocate a appropriate context for it.
343 * \pre req->rq_cli_ctx == NULL.
345 * \retval 0 succeed, and req->rq_cli_ctx is set.
346 * \retval -ev error number, and req->rq_cli_ctx == NULL.
348 int sptlrpc_req_get_ctx(struct ptlrpc_request *req)
350 struct obd_import *imp = req->rq_import;
351 struct ptlrpc_sec *sec;
354 LASSERT(!req->rq_cli_ctx);
357 rc = import_sec_validate_get(imp, &sec);
361 req->rq_cli_ctx = get_my_ctx(sec);
363 sptlrpc_sec_put(sec);
365 if (!req->rq_cli_ctx) {
366 CERROR("req %p: fail to get context\n", req);
374 * Drop the context for \a req.
375 * \pre req->rq_cli_ctx != NULL.
376 * \post req->rq_cli_ctx == NULL.
378 * If \a sync == 0, this function should return quickly without sleep;
379 * otherwise it might trigger and wait for the whole process of sending
380 * an context-destroying rpc to server.
382 void sptlrpc_req_put_ctx(struct ptlrpc_request *req, int sync)
385 LASSERT(req->rq_cli_ctx);
387 /* request might be asked to release earlier while still
388 * in the context waiting list.
390 if (!list_empty(&req->rq_ctx_chain)) {
391 spin_lock(&req->rq_cli_ctx->cc_lock);
392 list_del_init(&req->rq_ctx_chain);
393 spin_unlock(&req->rq_cli_ctx->cc_lock);
396 sptlrpc_cli_ctx_put(req->rq_cli_ctx, sync);
397 req->rq_cli_ctx = NULL;
401 int sptlrpc_req_ctx_switch(struct ptlrpc_request *req,
402 struct ptlrpc_cli_ctx *oldctx,
403 struct ptlrpc_cli_ctx *newctx)
405 struct sptlrpc_flavor old_flvr;
406 char *reqmsg = NULL; /* to workaround old gcc */
410 LASSERT(req->rq_reqmsg);
411 LASSERT(req->rq_reqlen);
412 LASSERT(req->rq_replen);
414 CDEBUG(D_SEC, "req %p: switch ctx %p(%u->%s) -> %p(%u->%s), switch sec %p(%s) -> %p(%s)\n",
416 oldctx, oldctx->cc_vcred.vc_uid, sec2target_str(oldctx->cc_sec),
417 newctx, newctx->cc_vcred.vc_uid, sec2target_str(newctx->cc_sec),
418 oldctx->cc_sec, oldctx->cc_sec->ps_policy->sp_name,
419 newctx->cc_sec, newctx->cc_sec->ps_policy->sp_name);
422 old_flvr = req->rq_flvr;
424 /* save request message */
425 reqmsg_size = req->rq_reqlen;
426 if (reqmsg_size != 0) {
427 reqmsg = libcfs_kvzalloc(reqmsg_size, GFP_NOFS);
430 memcpy(reqmsg, req->rq_reqmsg, reqmsg_size);
433 /* release old req/rep buf */
434 req->rq_cli_ctx = oldctx;
435 sptlrpc_cli_free_reqbuf(req);
436 sptlrpc_cli_free_repbuf(req);
437 req->rq_cli_ctx = newctx;
439 /* recalculate the flavor */
440 sptlrpc_req_set_flavor(req, 0);
442 /* alloc new request buffer
443 * we don't need to alloc reply buffer here, leave it to the
444 * rest procedure of ptlrpc
446 if (reqmsg_size != 0) {
447 rc = sptlrpc_cli_alloc_reqbuf(req, reqmsg_size);
449 LASSERT(req->rq_reqmsg);
450 memcpy(req->rq_reqmsg, reqmsg, reqmsg_size);
452 CWARN("failed to alloc reqbuf: %d\n", rc);
453 req->rq_flvr = old_flvr;
462 * If current context of \a req is dead somehow, e.g. we just switched flavor
463 * thus marked original contexts dead, we'll find a new context for it. if
464 * no switch is needed, \a req will end up with the same context.
466 * \note a request must have a context, to keep other parts of code happy.
467 * In any case of failure during the switching, we must restore the old one.
469 static int sptlrpc_req_replace_dead_ctx(struct ptlrpc_request *req)
471 struct ptlrpc_cli_ctx *oldctx = req->rq_cli_ctx;
472 struct ptlrpc_cli_ctx *newctx;
477 sptlrpc_cli_ctx_get(oldctx);
478 sptlrpc_req_put_ctx(req, 0);
480 rc = sptlrpc_req_get_ctx(req);
482 LASSERT(!req->rq_cli_ctx);
484 /* restore old ctx */
485 req->rq_cli_ctx = oldctx;
489 newctx = req->rq_cli_ctx;
492 if (unlikely(newctx == oldctx &&
493 test_bit(PTLRPC_CTX_DEAD_BIT, &oldctx->cc_flags))) {
495 * still get the old dead ctx, usually means system too busy
498 "ctx (%p, fl %lx) doesn't switch, relax a little bit\n",
499 newctx, newctx->cc_flags);
501 set_current_state(TASK_INTERRUPTIBLE);
502 schedule_timeout(HZ);
505 * it's possible newctx == oldctx if we're switching
506 * subflavor with the same sec.
508 rc = sptlrpc_req_ctx_switch(req, oldctx, newctx);
510 /* restore old ctx */
511 sptlrpc_req_put_ctx(req, 0);
512 req->rq_cli_ctx = oldctx;
516 LASSERT(req->rq_cli_ctx == newctx);
519 sptlrpc_cli_ctx_put(oldctx, 1);
524 int ctx_check_refresh(struct ptlrpc_cli_ctx *ctx)
526 if (cli_ctx_is_refreshed(ctx))
532 int ctx_refresh_timeout(void *data)
534 struct ptlrpc_request *req = data;
537 /* conn_cnt is needed in expire_one_request */
538 lustre_msg_set_conn_cnt(req->rq_reqmsg, req->rq_import->imp_conn_cnt);
540 rc = ptlrpc_expire_one_request(req, 1);
541 /* if we started recovery, we should mark this ctx dead; otherwise
542 * in case of lgssd died nobody would retire this ctx, following
543 * connecting will still find the same ctx thus cause deadlock.
544 * there's an assumption that expire time of the request should be
545 * later than the context refresh expire time.
548 req->rq_cli_ctx->cc_ops->force_die(req->rq_cli_ctx, 0);
553 void ctx_refresh_interrupt(void *data)
555 struct ptlrpc_request *req = data;
557 spin_lock(&req->rq_lock);
559 spin_unlock(&req->rq_lock);
563 void req_off_ctx_list(struct ptlrpc_request *req, struct ptlrpc_cli_ctx *ctx)
565 spin_lock(&ctx->cc_lock);
566 if (!list_empty(&req->rq_ctx_chain))
567 list_del_init(&req->rq_ctx_chain);
568 spin_unlock(&ctx->cc_lock);
572 * To refresh the context of \req, if it's not up-to-date.
575 * - = 0: wait until success or fatal error occur
576 * - > 0: timeout value (in seconds)
578 * The status of the context could be subject to be changed by other threads
579 * at any time. We allow this race, but once we return with 0, the caller will
580 * suppose it's uptodated and keep using it until the owning rpc is done.
582 * \retval 0 only if the context is uptodated.
583 * \retval -ev error number.
585 int sptlrpc_req_refresh_ctx(struct ptlrpc_request *req, long timeout)
587 struct ptlrpc_cli_ctx *ctx = req->rq_cli_ctx;
588 struct ptlrpc_sec *sec;
589 struct l_wait_info lwi;
594 if (req->rq_ctx_init || req->rq_ctx_fini)
598 * during the process a request's context might change type even
599 * (e.g. from gss ctx to null ctx), so each loop we need to re-check
603 rc = import_sec_validate_get(req->rq_import, &sec);
607 if (sec->ps_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
608 CDEBUG(D_SEC, "req %p: flavor has changed %x -> %x\n",
609 req, req->rq_flvr.sf_rpc, sec->ps_flvr.sf_rpc);
610 req_off_ctx_list(req, ctx);
611 sptlrpc_req_replace_dead_ctx(req);
612 ctx = req->rq_cli_ctx;
614 sptlrpc_sec_put(sec);
616 if (cli_ctx_is_eternal(ctx))
619 if (unlikely(test_bit(PTLRPC_CTX_NEW_BIT, &ctx->cc_flags))) {
620 LASSERT(ctx->cc_ops->refresh);
621 ctx->cc_ops->refresh(ctx);
623 LASSERT(test_bit(PTLRPC_CTX_NEW_BIT, &ctx->cc_flags) == 0);
625 LASSERT(ctx->cc_ops->validate);
626 if (ctx->cc_ops->validate(ctx) == 0) {
627 req_off_ctx_list(req, ctx);
631 if (unlikely(test_bit(PTLRPC_CTX_ERROR_BIT, &ctx->cc_flags))) {
632 spin_lock(&req->rq_lock);
634 spin_unlock(&req->rq_lock);
635 req_off_ctx_list(req, ctx);
640 * There's a subtle issue for resending RPCs, suppose following
642 * 1. the request was sent to server.
643 * 2. recovery was kicked start, after finished the request was
645 * 3. resend the request.
646 * 4. old reply from server received, we accept and verify the reply.
647 * this has to be success, otherwise the error will be aware
649 * 5. new reply from server received, dropped by LNet.
651 * Note the xid of old & new request is the same. We can't simply
652 * change xid for the resent request because the server replies on
653 * it for reply reconstruction.
655 * Commonly the original context should be uptodate because we
656 * have a expiry nice time; server will keep its context because
657 * we at least hold a ref of old context which prevent context
658 * destroying RPC being sent. So server still can accept the request
659 * and finish the RPC. But if that's not the case:
660 * 1. If server side context has been trimmed, a NO_CONTEXT will
661 * be returned, gss_cli_ctx_verify/unseal will switch to new
663 * 2. Current context never be refreshed, then we are fine: we
664 * never really send request with old context before.
666 if (test_bit(PTLRPC_CTX_UPTODATE_BIT, &ctx->cc_flags) &&
667 unlikely(req->rq_reqmsg) &&
668 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT) {
669 req_off_ctx_list(req, ctx);
673 if (unlikely(test_bit(PTLRPC_CTX_DEAD_BIT, &ctx->cc_flags))) {
674 req_off_ctx_list(req, ctx);
676 * don't switch ctx if import was deactivated
678 if (req->rq_import->imp_deactive) {
679 spin_lock(&req->rq_lock);
681 spin_unlock(&req->rq_lock);
685 rc = sptlrpc_req_replace_dead_ctx(req);
687 LASSERT(ctx == req->rq_cli_ctx);
688 CERROR("req %p: failed to replace dead ctx %p: %d\n",
690 spin_lock(&req->rq_lock);
692 spin_unlock(&req->rq_lock);
696 ctx = req->rq_cli_ctx;
701 * Now we're sure this context is during upcall, add myself into
704 spin_lock(&ctx->cc_lock);
705 if (list_empty(&req->rq_ctx_chain))
706 list_add(&req->rq_ctx_chain, &ctx->cc_req_list);
707 spin_unlock(&ctx->cc_lock);
712 /* Clear any flags that may be present from previous sends */
713 LASSERT(req->rq_receiving_reply == 0);
714 spin_lock(&req->rq_lock);
716 req->rq_timedout = 0;
719 spin_unlock(&req->rq_lock);
721 lwi = LWI_TIMEOUT_INTR(timeout * HZ, ctx_refresh_timeout,
722 ctx_refresh_interrupt, req);
723 rc = l_wait_event(req->rq_reply_waitq, ctx_check_refresh(ctx), &lwi);
726 * following cases could lead us here:
727 * - successfully refreshed;
729 * - timedout, and we don't want recover from the failure;
730 * - timedout, and waked up upon recovery finished;
731 * - someone else mark this ctx dead by force;
732 * - someone invalidate the req and call ptlrpc_client_wake_req(),
733 * e.g. ptlrpc_abort_inflight();
735 if (!cli_ctx_is_refreshed(ctx)) {
736 /* timed out or interrupted */
737 req_off_ctx_list(req, ctx);
747 * Initialize flavor settings for \a req, according to \a opcode.
749 * \note this could be called in two situations:
750 * - new request from ptlrpc_pre_req(), with proper @opcode
751 * - old request which changed ctx in the middle, with @opcode == 0
753 void sptlrpc_req_set_flavor(struct ptlrpc_request *req, int opcode)
755 struct ptlrpc_sec *sec;
757 LASSERT(req->rq_import);
758 LASSERT(req->rq_cli_ctx);
759 LASSERT(req->rq_cli_ctx->cc_sec);
760 LASSERT(req->rq_bulk_read == 0 || req->rq_bulk_write == 0);
762 /* special security flags according to opcode */
766 case MGS_CONFIG_READ:
768 req->rq_bulk_read = 1;
772 req->rq_bulk_write = 1;
775 req->rq_ctx_init = 1;
778 req->rq_ctx_fini = 1;
781 /* init/fini rpc won't be resend, so can't be here */
782 LASSERT(req->rq_ctx_init == 0);
783 LASSERT(req->rq_ctx_fini == 0);
785 /* cleanup flags, which should be recalculated */
786 req->rq_pack_udesc = 0;
787 req->rq_pack_bulk = 0;
791 sec = req->rq_cli_ctx->cc_sec;
793 spin_lock(&sec->ps_lock);
794 req->rq_flvr = sec->ps_flvr;
795 spin_unlock(&sec->ps_lock);
797 /* force SVC_NULL for context initiation rpc, SVC_INTG for context
800 if (unlikely(req->rq_ctx_init))
801 flvr_set_svc(&req->rq_flvr.sf_rpc, SPTLRPC_SVC_NULL);
802 else if (unlikely(req->rq_ctx_fini))
803 flvr_set_svc(&req->rq_flvr.sf_rpc, SPTLRPC_SVC_INTG);
805 /* user descriptor flag, null security can't do it anyway */
806 if ((sec->ps_flvr.sf_flags & PTLRPC_SEC_FL_UDESC) &&
807 (req->rq_flvr.sf_rpc != SPTLRPC_FLVR_NULL))
808 req->rq_pack_udesc = 1;
810 /* bulk security flag */
811 if ((req->rq_bulk_read || req->rq_bulk_write) &&
812 sptlrpc_flavor_has_bulk(&req->rq_flvr))
813 req->rq_pack_bulk = 1;
816 void sptlrpc_request_out_callback(struct ptlrpc_request *req)
818 if (SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc) != SPTLRPC_SVC_PRIV)
821 LASSERT(req->rq_clrbuf);
822 if (req->rq_pool || !req->rq_reqbuf)
825 kfree(req->rq_reqbuf);
826 req->rq_reqbuf = NULL;
827 req->rq_reqbuf_len = 0;
831 * Given an import \a imp, check whether current user has a valid context
832 * or not. We may create a new context and try to refresh it, and try
833 * repeatedly try in case of non-fatal errors. Return 0 means success.
835 int sptlrpc_import_check_ctx(struct obd_import *imp)
837 struct ptlrpc_sec *sec;
838 struct ptlrpc_cli_ctx *ctx;
839 struct ptlrpc_request *req = NULL;
844 sec = sptlrpc_import_sec_ref(imp);
845 ctx = get_my_ctx(sec);
846 sptlrpc_sec_put(sec);
851 if (cli_ctx_is_eternal(ctx) ||
852 ctx->cc_ops->validate(ctx) == 0) {
853 sptlrpc_cli_ctx_put(ctx, 1);
857 if (cli_ctx_is_error(ctx)) {
858 sptlrpc_cli_ctx_put(ctx, 1);
862 req = ptlrpc_request_cache_alloc(GFP_NOFS);
866 ptlrpc_cli_req_init(req);
867 atomic_set(&req->rq_refcount, 10000);
869 req->rq_import = imp;
870 req->rq_flvr = sec->ps_flvr;
871 req->rq_cli_ctx = ctx;
873 rc = sptlrpc_req_refresh_ctx(req, 0);
874 LASSERT(list_empty(&req->rq_ctx_chain));
875 sptlrpc_cli_ctx_put(req->rq_cli_ctx, 1);
876 ptlrpc_request_cache_free(req);
882 * Used by ptlrpc client, to perform the pre-defined security transformation
883 * upon the request message of \a req. After this function called,
884 * req->rq_reqmsg is still accessible as clear text.
886 int sptlrpc_cli_wrap_request(struct ptlrpc_request *req)
888 struct ptlrpc_cli_ctx *ctx = req->rq_cli_ctx;
892 LASSERT(ctx->cc_sec);
893 LASSERT(req->rq_reqbuf || req->rq_clrbuf);
895 /* we wrap bulk request here because now we can be sure
896 * the context is uptodate.
899 rc = sptlrpc_cli_wrap_bulk(req, req->rq_bulk);
904 switch (SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc)) {
905 case SPTLRPC_SVC_NULL:
906 case SPTLRPC_SVC_AUTH:
907 case SPTLRPC_SVC_INTG:
908 LASSERT(ctx->cc_ops->sign);
909 rc = ctx->cc_ops->sign(ctx, req);
911 case SPTLRPC_SVC_PRIV:
912 LASSERT(ctx->cc_ops->seal);
913 rc = ctx->cc_ops->seal(ctx, req);
920 LASSERT(req->rq_reqdata_len);
921 LASSERT(req->rq_reqdata_len % 8 == 0);
922 LASSERT(req->rq_reqdata_len <= req->rq_reqbuf_len);
928 static int do_cli_unwrap_reply(struct ptlrpc_request *req)
930 struct ptlrpc_cli_ctx *ctx = req->rq_cli_ctx;
934 LASSERT(ctx->cc_sec);
935 LASSERT(req->rq_repbuf);
936 LASSERT(req->rq_repdata);
937 LASSERT(!req->rq_repmsg);
939 req->rq_rep_swab_mask = 0;
941 rc = __lustre_unpack_msg(req->rq_repdata, req->rq_repdata_len);
944 lustre_set_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
948 CERROR("failed unpack reply: x%llu\n", req->rq_xid);
952 if (req->rq_repdata_len < sizeof(struct lustre_msg)) {
953 CERROR("replied data length %d too small\n",
954 req->rq_repdata_len);
958 if (SPTLRPC_FLVR_POLICY(req->rq_repdata->lm_secflvr) !=
959 SPTLRPC_FLVR_POLICY(req->rq_flvr.sf_rpc)) {
960 CERROR("reply policy %u doesn't match request policy %u\n",
961 SPTLRPC_FLVR_POLICY(req->rq_repdata->lm_secflvr),
962 SPTLRPC_FLVR_POLICY(req->rq_flvr.sf_rpc));
966 switch (SPTLRPC_FLVR_SVC(req->rq_flvr.sf_rpc)) {
967 case SPTLRPC_SVC_NULL:
968 case SPTLRPC_SVC_AUTH:
969 case SPTLRPC_SVC_INTG:
970 LASSERT(ctx->cc_ops->verify);
971 rc = ctx->cc_ops->verify(ctx, req);
973 case SPTLRPC_SVC_PRIV:
974 LASSERT(ctx->cc_ops->unseal);
975 rc = ctx->cc_ops->unseal(ctx, req);
980 LASSERT(rc || req->rq_repmsg || req->rq_resend);
982 if (SPTLRPC_FLVR_POLICY(req->rq_flvr.sf_rpc) != SPTLRPC_POLICY_NULL &&
984 req->rq_rep_swab_mask = 0;
989 * Used by ptlrpc client, to perform security transformation upon the reply
990 * message of \a req. After return successfully, req->rq_repmsg points to
991 * the reply message in clear text.
993 * \pre the reply buffer should have been un-posted from LNet, so nothing is
996 int sptlrpc_cli_unwrap_reply(struct ptlrpc_request *req)
998 LASSERT(req->rq_repbuf);
999 LASSERT(!req->rq_repdata);
1000 LASSERT(!req->rq_repmsg);
1001 LASSERT(req->rq_reply_off + req->rq_nob_received <= req->rq_repbuf_len);
1003 if (req->rq_reply_off == 0 &&
1004 (lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT)) {
1005 CERROR("real reply with offset 0\n");
1009 if (req->rq_reply_off % 8 != 0) {
1010 CERROR("reply at odd offset %u\n", req->rq_reply_off);
1014 req->rq_repdata = (struct lustre_msg *)
1015 (req->rq_repbuf + req->rq_reply_off);
1016 req->rq_repdata_len = req->rq_nob_received;
1018 return do_cli_unwrap_reply(req);
1022 * Used by ptlrpc client, to perform security transformation upon the early
1023 * reply message of \a req. We expect the rq_reply_off is 0, and
1024 * rq_nob_received is the early reply size.
1026 * Because the receive buffer might be still posted, the reply data might be
1027 * changed at any time, no matter we're holding rq_lock or not. For this reason
1028 * we allocate a separate ptlrpc_request and reply buffer for early reply
1031 * \retval 0 success, \a req_ret is filled with a duplicated ptlrpc_request.
1032 * Later the caller must call sptlrpc_cli_finish_early_reply() on the returned
1033 * \a *req_ret to release it.
1034 * \retval -ev error number, and \a req_ret will not be set.
1036 int sptlrpc_cli_unwrap_early_reply(struct ptlrpc_request *req,
1037 struct ptlrpc_request **req_ret)
1039 struct ptlrpc_request *early_req;
1041 int early_bufsz, early_size;
1044 early_req = ptlrpc_request_cache_alloc(GFP_NOFS);
1048 ptlrpc_cli_req_init(early_req);
1050 early_size = req->rq_nob_received;
1051 early_bufsz = size_roundup_power2(early_size);
1052 early_buf = libcfs_kvzalloc(early_bufsz, GFP_NOFS);
1058 /* sanity checkings and copy data out, do it inside spinlock */
1059 spin_lock(&req->rq_lock);
1061 if (req->rq_replied) {
1062 spin_unlock(&req->rq_lock);
1067 LASSERT(req->rq_repbuf);
1068 LASSERT(!req->rq_repdata);
1069 LASSERT(!req->rq_repmsg);
1071 if (req->rq_reply_off != 0) {
1072 CERROR("early reply with offset %u\n", req->rq_reply_off);
1073 spin_unlock(&req->rq_lock);
1078 if (req->rq_nob_received != early_size) {
1079 /* even another early arrived the size should be the same */
1080 CERROR("data size has changed from %u to %u\n",
1081 early_size, req->rq_nob_received);
1082 spin_unlock(&req->rq_lock);
1087 if (req->rq_nob_received < sizeof(struct lustre_msg)) {
1088 CERROR("early reply length %d too small\n",
1089 req->rq_nob_received);
1090 spin_unlock(&req->rq_lock);
1095 memcpy(early_buf, req->rq_repbuf, early_size);
1096 spin_unlock(&req->rq_lock);
1098 early_req->rq_cli_ctx = sptlrpc_cli_ctx_get(req->rq_cli_ctx);
1099 early_req->rq_flvr = req->rq_flvr;
1100 early_req->rq_repbuf = early_buf;
1101 early_req->rq_repbuf_len = early_bufsz;
1102 early_req->rq_repdata = (struct lustre_msg *)early_buf;
1103 early_req->rq_repdata_len = early_size;
1104 early_req->rq_early = 1;
1105 early_req->rq_reqmsg = req->rq_reqmsg;
1107 rc = do_cli_unwrap_reply(early_req);
1109 DEBUG_REQ(D_ADAPTTO, early_req,
1110 "error %d unwrap early reply", rc);
1114 LASSERT(early_req->rq_repmsg);
1115 *req_ret = early_req;
1119 sptlrpc_cli_ctx_put(early_req->rq_cli_ctx, 1);
1123 ptlrpc_request_cache_free(early_req);
1128 * Used by ptlrpc client, to release a processed early reply \a early_req.
1130 * \pre \a early_req was obtained from calling sptlrpc_cli_unwrap_early_reply().
1132 void sptlrpc_cli_finish_early_reply(struct ptlrpc_request *early_req)
1134 LASSERT(early_req->rq_repbuf);
1135 LASSERT(early_req->rq_repdata);
1136 LASSERT(early_req->rq_repmsg);
1138 sptlrpc_cli_ctx_put(early_req->rq_cli_ctx, 1);
1139 kvfree(early_req->rq_repbuf);
1140 ptlrpc_request_cache_free(early_req);
1143 /**************************************************
1145 **************************************************/
1148 * "fixed" sec (e.g. null) use sec_id < 0
1150 static atomic_t sptlrpc_sec_id = ATOMIC_INIT(1);
1152 int sptlrpc_get_next_secid(void)
1154 return atomic_inc_return(&sptlrpc_sec_id);
1156 EXPORT_SYMBOL(sptlrpc_get_next_secid);
1158 /**************************************************
1159 * client side high-level security APIs *
1160 **************************************************/
1162 static int sec_cop_flush_ctx_cache(struct ptlrpc_sec *sec, uid_t uid,
1163 int grace, int force)
1165 struct ptlrpc_sec_policy *policy = sec->ps_policy;
1167 LASSERT(policy->sp_cops);
1168 LASSERT(policy->sp_cops->flush_ctx_cache);
1170 return policy->sp_cops->flush_ctx_cache(sec, uid, grace, force);
1173 static void sec_cop_destroy_sec(struct ptlrpc_sec *sec)
1175 struct ptlrpc_sec_policy *policy = sec->ps_policy;
1177 LASSERT_ATOMIC_ZERO(&sec->ps_refcount);
1178 LASSERT_ATOMIC_ZERO(&sec->ps_nctx);
1179 LASSERT(policy->sp_cops->destroy_sec);
1181 CDEBUG(D_SEC, "%s@%p: being destroyed\n", sec->ps_policy->sp_name, sec);
1183 policy->sp_cops->destroy_sec(sec);
1184 sptlrpc_policy_put(policy);
1187 static void sptlrpc_sec_kill(struct ptlrpc_sec *sec)
1189 LASSERT_ATOMIC_POS(&sec->ps_refcount);
1191 if (sec->ps_policy->sp_cops->kill_sec) {
1192 sec->ps_policy->sp_cops->kill_sec(sec);
1194 sec_cop_flush_ctx_cache(sec, -1, 1, 1);
1198 static struct ptlrpc_sec *sptlrpc_sec_get(struct ptlrpc_sec *sec)
1201 atomic_inc(&sec->ps_refcount);
1206 void sptlrpc_sec_put(struct ptlrpc_sec *sec)
1209 LASSERT_ATOMIC_POS(&sec->ps_refcount);
1211 if (atomic_dec_and_test(&sec->ps_refcount)) {
1212 sptlrpc_gc_del_sec(sec);
1213 sec_cop_destroy_sec(sec);
1217 EXPORT_SYMBOL(sptlrpc_sec_put);
1220 * policy module is responsible for taking reference of import
1223 struct ptlrpc_sec *sptlrpc_sec_create(struct obd_import *imp,
1224 struct ptlrpc_svc_ctx *svc_ctx,
1225 struct sptlrpc_flavor *sf,
1226 enum lustre_sec_part sp)
1228 struct ptlrpc_sec_policy *policy;
1229 struct ptlrpc_sec *sec;
1233 LASSERT(imp->imp_dlm_fake == 1);
1235 CDEBUG(D_SEC, "%s %s: reverse sec using flavor %s\n",
1236 imp->imp_obd->obd_type->typ_name,
1237 imp->imp_obd->obd_name,
1238 sptlrpc_flavor2name(sf, str, sizeof(str)));
1240 policy = sptlrpc_policy_get(svc_ctx->sc_policy);
1241 sf->sf_flags |= PTLRPC_SEC_FL_REVERSE | PTLRPC_SEC_FL_ROOTONLY;
1243 LASSERT(imp->imp_dlm_fake == 0);
1245 CDEBUG(D_SEC, "%s %s: select security flavor %s\n",
1246 imp->imp_obd->obd_type->typ_name,
1247 imp->imp_obd->obd_name,
1248 sptlrpc_flavor2name(sf, str, sizeof(str)));
1250 policy = sptlrpc_wireflavor2policy(sf->sf_rpc);
1252 CERROR("invalid flavor 0x%x\n", sf->sf_rpc);
1257 sec = policy->sp_cops->create_sec(imp, svc_ctx, sf);
1259 atomic_inc(&sec->ps_refcount);
1263 if (sec->ps_gc_interval && policy->sp_cops->gc_ctx)
1264 sptlrpc_gc_add_sec(sec);
1266 sptlrpc_policy_put(policy);
1272 struct ptlrpc_sec *sptlrpc_import_sec_ref(struct obd_import *imp)
1274 struct ptlrpc_sec *sec;
1276 spin_lock(&imp->imp_lock);
1277 sec = sptlrpc_sec_get(imp->imp_sec);
1278 spin_unlock(&imp->imp_lock);
1282 EXPORT_SYMBOL(sptlrpc_import_sec_ref);
1284 static void sptlrpc_import_sec_install(struct obd_import *imp,
1285 struct ptlrpc_sec *sec)
1287 struct ptlrpc_sec *old_sec;
1289 LASSERT_ATOMIC_POS(&sec->ps_refcount);
1291 spin_lock(&imp->imp_lock);
1292 old_sec = imp->imp_sec;
1294 spin_unlock(&imp->imp_lock);
1297 sptlrpc_sec_kill(old_sec);
1299 /* balance the ref taken by this import */
1300 sptlrpc_sec_put(old_sec);
1305 int flavor_equal(struct sptlrpc_flavor *sf1, struct sptlrpc_flavor *sf2)
1307 return (memcmp(sf1, sf2, sizeof(*sf1)) == 0);
1311 void flavor_copy(struct sptlrpc_flavor *dst, struct sptlrpc_flavor *src)
1316 static void sptlrpc_import_sec_adapt_inplace(struct obd_import *imp,
1317 struct ptlrpc_sec *sec,
1318 struct sptlrpc_flavor *sf)
1320 char str1[32], str2[32];
1322 if (sec->ps_flvr.sf_flags != sf->sf_flags)
1323 CDEBUG(D_SEC, "changing sec flags: %s -> %s\n",
1324 sptlrpc_secflags2str(sec->ps_flvr.sf_flags,
1325 str1, sizeof(str1)),
1326 sptlrpc_secflags2str(sf->sf_flags,
1327 str2, sizeof(str2)));
1329 spin_lock(&sec->ps_lock);
1330 flavor_copy(&sec->ps_flvr, sf);
1331 spin_unlock(&sec->ps_lock);
1335 * To get an appropriate ptlrpc_sec for the \a imp, according to the current
1336 * configuration. Upon called, imp->imp_sec may or may not be NULL.
1338 * - regular import: \a svc_ctx should be NULL and \a flvr is ignored;
1339 * - reverse import: \a svc_ctx and \a flvr are obtained from incoming request.
1341 int sptlrpc_import_sec_adapt(struct obd_import *imp,
1342 struct ptlrpc_svc_ctx *svc_ctx,
1343 struct sptlrpc_flavor *flvr)
1345 struct ptlrpc_connection *conn;
1346 struct sptlrpc_flavor sf;
1347 struct ptlrpc_sec *sec, *newsec;
1348 enum lustre_sec_part sp;
1357 conn = imp->imp_connection;
1360 struct client_obd *cliobd = &imp->imp_obd->u.cli;
1362 * normal import, determine flavor from rule set, except
1363 * for mgc the flavor is predetermined.
1365 if (cliobd->cl_sp_me == LUSTRE_SP_MGC)
1366 sf = cliobd->cl_flvr_mgc;
1368 sptlrpc_conf_choose_flavor(cliobd->cl_sp_me,
1370 &cliobd->cl_target_uuid,
1373 sp = imp->imp_obd->u.cli.cl_sp_me;
1375 /* reverse import, determine flavor from incoming request */
1378 if (sf.sf_rpc != SPTLRPC_FLVR_NULL)
1379 sf.sf_flags = PTLRPC_SEC_FL_REVERSE |
1380 PTLRPC_SEC_FL_ROOTONLY;
1382 sp = sptlrpc_target_sec_part(imp->imp_obd);
1385 sec = sptlrpc_import_sec_ref(imp);
1389 if (flavor_equal(&sf, &sec->ps_flvr))
1392 CDEBUG(D_SEC, "import %s->%s: changing flavor %s -> %s\n",
1393 imp->imp_obd->obd_name,
1394 obd_uuid2str(&conn->c_remote_uuid),
1395 sptlrpc_flavor2name(&sec->ps_flvr, str, sizeof(str)),
1396 sptlrpc_flavor2name(&sf, str2, sizeof(str2)));
1398 if (SPTLRPC_FLVR_POLICY(sf.sf_rpc) ==
1399 SPTLRPC_FLVR_POLICY(sec->ps_flvr.sf_rpc) &&
1400 SPTLRPC_FLVR_MECH(sf.sf_rpc) ==
1401 SPTLRPC_FLVR_MECH(sec->ps_flvr.sf_rpc)) {
1402 sptlrpc_import_sec_adapt_inplace(imp, sec, &sf);
1405 } else if (SPTLRPC_FLVR_BASE(sf.sf_rpc) !=
1406 SPTLRPC_FLVR_BASE(SPTLRPC_FLVR_NULL)) {
1407 CDEBUG(D_SEC, "import %s->%s netid %x: select flavor %s\n",
1408 imp->imp_obd->obd_name,
1409 obd_uuid2str(&conn->c_remote_uuid),
1410 LNET_NIDNET(conn->c_self),
1411 sptlrpc_flavor2name(&sf, str, sizeof(str)));
1414 mutex_lock(&imp->imp_sec_mutex);
1416 newsec = sptlrpc_sec_create(imp, svc_ctx, &sf, sp);
1418 sptlrpc_import_sec_install(imp, newsec);
1420 CERROR("import %s->%s: failed to create new sec\n",
1421 imp->imp_obd->obd_name,
1422 obd_uuid2str(&conn->c_remote_uuid));
1426 mutex_unlock(&imp->imp_sec_mutex);
1428 sptlrpc_sec_put(sec);
1432 void sptlrpc_import_sec_put(struct obd_import *imp)
1435 sptlrpc_sec_kill(imp->imp_sec);
1437 sptlrpc_sec_put(imp->imp_sec);
1438 imp->imp_sec = NULL;
1442 static void import_flush_ctx_common(struct obd_import *imp,
1443 uid_t uid, int grace, int force)
1445 struct ptlrpc_sec *sec;
1450 sec = sptlrpc_import_sec_ref(imp);
1454 sec_cop_flush_ctx_cache(sec, uid, grace, force);
1455 sptlrpc_sec_put(sec);
1458 void sptlrpc_import_flush_my_ctx(struct obd_import *imp)
1460 import_flush_ctx_common(imp, from_kuid(&init_user_ns, current_uid()),
1463 EXPORT_SYMBOL(sptlrpc_import_flush_my_ctx);
1465 void sptlrpc_import_flush_all_ctx(struct obd_import *imp)
1467 import_flush_ctx_common(imp, -1, 1, 1);
1469 EXPORT_SYMBOL(sptlrpc_import_flush_all_ctx);
1472 * Used by ptlrpc client to allocate request buffer of \a req. Upon return
1473 * successfully, req->rq_reqmsg points to a buffer with size \a msgsize.
1475 int sptlrpc_cli_alloc_reqbuf(struct ptlrpc_request *req, int msgsize)
1477 struct ptlrpc_cli_ctx *ctx = req->rq_cli_ctx;
1478 struct ptlrpc_sec_policy *policy;
1482 LASSERT(ctx->cc_sec);
1483 LASSERT(ctx->cc_sec->ps_policy);
1484 LASSERT(!req->rq_reqmsg);
1485 LASSERT_ATOMIC_POS(&ctx->cc_refcount);
1487 policy = ctx->cc_sec->ps_policy;
1488 rc = policy->sp_cops->alloc_reqbuf(ctx->cc_sec, req, msgsize);
1490 LASSERT(req->rq_reqmsg);
1491 LASSERT(req->rq_reqbuf || req->rq_clrbuf);
1493 /* zeroing preallocated buffer */
1495 memset(req->rq_reqmsg, 0, msgsize);
1502 * Used by ptlrpc client to free request buffer of \a req. After this
1503 * req->rq_reqmsg is set to NULL and should not be accessed anymore.
1505 void sptlrpc_cli_free_reqbuf(struct ptlrpc_request *req)
1507 struct ptlrpc_cli_ctx *ctx = req->rq_cli_ctx;
1508 struct ptlrpc_sec_policy *policy;
1511 LASSERT(ctx->cc_sec);
1512 LASSERT(ctx->cc_sec->ps_policy);
1513 LASSERT_ATOMIC_POS(&ctx->cc_refcount);
1515 if (!req->rq_reqbuf && !req->rq_clrbuf)
1518 policy = ctx->cc_sec->ps_policy;
1519 policy->sp_cops->free_reqbuf(ctx->cc_sec, req);
1520 req->rq_reqmsg = NULL;
1524 * NOTE caller must guarantee the buffer size is enough for the enlargement
1526 void _sptlrpc_enlarge_msg_inplace(struct lustre_msg *msg,
1527 int segment, int newsize)
1530 int oldsize, oldmsg_size, movesize;
1532 LASSERT(segment < msg->lm_bufcount);
1533 LASSERT(msg->lm_buflens[segment] <= newsize);
1535 if (msg->lm_buflens[segment] == newsize)
1538 /* nothing to do if we are enlarging the last segment */
1539 if (segment == msg->lm_bufcount - 1) {
1540 msg->lm_buflens[segment] = newsize;
1544 oldsize = msg->lm_buflens[segment];
1546 src = lustre_msg_buf(msg, segment + 1, 0);
1547 msg->lm_buflens[segment] = newsize;
1548 dst = lustre_msg_buf(msg, segment + 1, 0);
1549 msg->lm_buflens[segment] = oldsize;
1551 /* move from segment + 1 to end segment */
1552 LASSERT(msg->lm_magic == LUSTRE_MSG_MAGIC_V2);
1553 oldmsg_size = lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
1554 movesize = oldmsg_size - ((unsigned long)src - (unsigned long)msg);
1555 LASSERT(movesize >= 0);
1558 memmove(dst, src, movesize);
1560 /* note we don't clear the ares where old data live, not secret */
1562 /* finally set new segment size */
1563 msg->lm_buflens[segment] = newsize;
1565 EXPORT_SYMBOL(_sptlrpc_enlarge_msg_inplace);
1568 * Used by ptlrpc client to enlarge the \a segment of request message pointed
1569 * by req->rq_reqmsg to size \a newsize, all previously filled-in data will be
1570 * preserved after the enlargement. this must be called after original request
1571 * buffer being allocated.
1573 * \note after this be called, rq_reqmsg and rq_reqlen might have been changed,
1574 * so caller should refresh its local pointers if needed.
1576 int sptlrpc_cli_enlarge_reqbuf(struct ptlrpc_request *req,
1577 int segment, int newsize)
1579 struct ptlrpc_cli_ctx *ctx = req->rq_cli_ctx;
1580 struct ptlrpc_sec_cops *cops;
1581 struct lustre_msg *msg = req->rq_reqmsg;
1585 LASSERT(msg->lm_bufcount > segment);
1586 LASSERT(msg->lm_buflens[segment] <= newsize);
1588 if (msg->lm_buflens[segment] == newsize)
1591 cops = ctx->cc_sec->ps_policy->sp_cops;
1592 LASSERT(cops->enlarge_reqbuf);
1593 return cops->enlarge_reqbuf(ctx->cc_sec, req, segment, newsize);
1595 EXPORT_SYMBOL(sptlrpc_cli_enlarge_reqbuf);
1598 * Used by ptlrpc client to allocate reply buffer of \a req.
1600 * \note After this, req->rq_repmsg is still not accessible.
1602 int sptlrpc_cli_alloc_repbuf(struct ptlrpc_request *req, int msgsize)
1604 struct ptlrpc_cli_ctx *ctx = req->rq_cli_ctx;
1605 struct ptlrpc_sec_policy *policy;
1608 LASSERT(ctx->cc_sec);
1609 LASSERT(ctx->cc_sec->ps_policy);
1614 policy = ctx->cc_sec->ps_policy;
1615 return policy->sp_cops->alloc_repbuf(ctx->cc_sec, req, msgsize);
1619 * Used by ptlrpc client to free reply buffer of \a req. After this
1620 * req->rq_repmsg is set to NULL and should not be accessed anymore.
1622 void sptlrpc_cli_free_repbuf(struct ptlrpc_request *req)
1624 struct ptlrpc_cli_ctx *ctx = req->rq_cli_ctx;
1625 struct ptlrpc_sec_policy *policy;
1628 LASSERT(ctx->cc_sec);
1629 LASSERT(ctx->cc_sec->ps_policy);
1630 LASSERT_ATOMIC_POS(&ctx->cc_refcount);
1632 if (!req->rq_repbuf)
1634 LASSERT(req->rq_repbuf_len);
1636 policy = ctx->cc_sec->ps_policy;
1637 policy->sp_cops->free_repbuf(ctx->cc_sec, req);
1638 req->rq_repmsg = NULL;
1641 static int sptlrpc_svc_install_rvs_ctx(struct obd_import *imp,
1642 struct ptlrpc_svc_ctx *ctx)
1644 struct ptlrpc_sec_policy *policy = ctx->sc_policy;
1646 if (!policy->sp_sops->install_rctx)
1648 return policy->sp_sops->install_rctx(imp, ctx);
1651 /****************************************
1652 * server side security *
1653 ****************************************/
1655 static int flavor_allowed(struct sptlrpc_flavor *exp,
1656 struct ptlrpc_request *req)
1658 struct sptlrpc_flavor *flvr = &req->rq_flvr;
1660 if (exp->sf_rpc == SPTLRPC_FLVR_ANY || exp->sf_rpc == flvr->sf_rpc)
1663 if ((req->rq_ctx_init || req->rq_ctx_fini) &&
1664 SPTLRPC_FLVR_POLICY(exp->sf_rpc) ==
1665 SPTLRPC_FLVR_POLICY(flvr->sf_rpc) &&
1666 SPTLRPC_FLVR_MECH(exp->sf_rpc) == SPTLRPC_FLVR_MECH(flvr->sf_rpc))
1672 #define EXP_FLVR_UPDATE_EXPIRE (OBD_TIMEOUT_DEFAULT + 10)
1675 * Given an export \a exp, check whether the flavor of incoming \a req
1676 * is allowed by the export \a exp. Main logic is about taking care of
1677 * changing configurations. Return 0 means success.
1679 int sptlrpc_target_export_check(struct obd_export *exp,
1680 struct ptlrpc_request *req)
1682 struct sptlrpc_flavor flavor;
1687 /* client side export has no imp_reverse, skip
1688 * FIXME maybe we should check flavor this as well???
1690 if (!exp->exp_imp_reverse)
1693 /* don't care about ctx fini rpc */
1694 if (req->rq_ctx_fini)
1697 spin_lock(&exp->exp_lock);
1699 /* if flavor just changed (exp->exp_flvr_changed != 0), we wait for
1700 * the first req with the new flavor, then treat it as current flavor,
1701 * adapt reverse sec according to it.
1702 * note the first rpc with new flavor might not be with root ctx, in
1703 * which case delay the sec_adapt by leaving exp_flvr_adapt == 1.
1705 if (unlikely(exp->exp_flvr_changed) &&
1706 flavor_allowed(&exp->exp_flvr_old[1], req)) {
1707 /* make the new flavor as "current", and old ones as
1710 CDEBUG(D_SEC, "exp %p: just changed: %x->%x\n", exp,
1711 exp->exp_flvr.sf_rpc, exp->exp_flvr_old[1].sf_rpc);
1712 flavor = exp->exp_flvr_old[1];
1713 exp->exp_flvr_old[1] = exp->exp_flvr_old[0];
1714 exp->exp_flvr_expire[1] = exp->exp_flvr_expire[0];
1715 exp->exp_flvr_old[0] = exp->exp_flvr;
1716 exp->exp_flvr_expire[0] = ktime_get_real_seconds() +
1717 EXP_FLVR_UPDATE_EXPIRE;
1718 exp->exp_flvr = flavor;
1720 /* flavor change finished */
1721 exp->exp_flvr_changed = 0;
1722 LASSERT(exp->exp_flvr_adapt == 1);
1724 /* if it's gss, we only interested in root ctx init */
1725 if (req->rq_auth_gss &&
1726 !(req->rq_ctx_init &&
1727 (req->rq_auth_usr_root || req->rq_auth_usr_mdt ||
1728 req->rq_auth_usr_ost))) {
1729 spin_unlock(&exp->exp_lock);
1730 CDEBUG(D_SEC, "is good but not root(%d:%d:%d:%d:%d)\n",
1731 req->rq_auth_gss, req->rq_ctx_init,
1732 req->rq_auth_usr_root, req->rq_auth_usr_mdt,
1733 req->rq_auth_usr_ost);
1737 exp->exp_flvr_adapt = 0;
1738 spin_unlock(&exp->exp_lock);
1740 return sptlrpc_import_sec_adapt(exp->exp_imp_reverse,
1741 req->rq_svc_ctx, &flavor);
1744 /* if it equals to the current flavor, we accept it, but need to
1745 * dealing with reverse sec/ctx
1747 if (likely(flavor_allowed(&exp->exp_flvr, req))) {
1748 /* most cases should return here, we only interested in
1751 if (!req->rq_auth_gss || !req->rq_ctx_init ||
1752 (!req->rq_auth_usr_root && !req->rq_auth_usr_mdt &&
1753 !req->rq_auth_usr_ost)) {
1754 spin_unlock(&exp->exp_lock);
1758 /* if flavor just changed, we should not proceed, just leave
1759 * it and current flavor will be discovered and replaced
1760 * shortly, and let _this_ rpc pass through
1762 if (exp->exp_flvr_changed) {
1763 LASSERT(exp->exp_flvr_adapt);
1764 spin_unlock(&exp->exp_lock);
1768 if (exp->exp_flvr_adapt) {
1769 exp->exp_flvr_adapt = 0;
1770 CDEBUG(D_SEC, "exp %p (%x|%x|%x): do delayed adapt\n",
1771 exp, exp->exp_flvr.sf_rpc,
1772 exp->exp_flvr_old[0].sf_rpc,
1773 exp->exp_flvr_old[1].sf_rpc);
1774 flavor = exp->exp_flvr;
1775 spin_unlock(&exp->exp_lock);
1777 return sptlrpc_import_sec_adapt(exp->exp_imp_reverse,
1781 CDEBUG(D_SEC, "exp %p (%x|%x|%x): is current flavor, install rvs ctx\n",
1782 exp, exp->exp_flvr.sf_rpc,
1783 exp->exp_flvr_old[0].sf_rpc,
1784 exp->exp_flvr_old[1].sf_rpc);
1785 spin_unlock(&exp->exp_lock);
1787 return sptlrpc_svc_install_rvs_ctx(exp->exp_imp_reverse,
1792 if (exp->exp_flvr_expire[0]) {
1793 if (exp->exp_flvr_expire[0] >= ktime_get_real_seconds()) {
1794 if (flavor_allowed(&exp->exp_flvr_old[0], req)) {
1795 CDEBUG(D_SEC, "exp %p (%x|%x|%x): match the middle one (%lld)\n", exp,
1796 exp->exp_flvr.sf_rpc,
1797 exp->exp_flvr_old[0].sf_rpc,
1798 exp->exp_flvr_old[1].sf_rpc,
1799 (s64)(exp->exp_flvr_expire[0] -
1800 ktime_get_real_seconds()));
1801 spin_unlock(&exp->exp_lock);
1805 CDEBUG(D_SEC, "mark middle expired\n");
1806 exp->exp_flvr_expire[0] = 0;
1808 CDEBUG(D_SEC, "exp %p (%x|%x|%x): %x not match middle\n", exp,
1809 exp->exp_flvr.sf_rpc,
1810 exp->exp_flvr_old[0].sf_rpc, exp->exp_flvr_old[1].sf_rpc,
1811 req->rq_flvr.sf_rpc);
1814 /* now it doesn't match the current flavor, the only chance we can
1815 * accept it is match the old flavors which is not expired.
1817 if (exp->exp_flvr_changed == 0 && exp->exp_flvr_expire[1]) {
1818 if (exp->exp_flvr_expire[1] >= ktime_get_real_seconds()) {
1819 if (flavor_allowed(&exp->exp_flvr_old[1], req)) {
1820 CDEBUG(D_SEC, "exp %p (%x|%x|%x): match the oldest one (%lld)\n",
1822 exp->exp_flvr.sf_rpc,
1823 exp->exp_flvr_old[0].sf_rpc,
1824 exp->exp_flvr_old[1].sf_rpc,
1825 (s64)(exp->exp_flvr_expire[1] -
1826 ktime_get_real_seconds()));
1827 spin_unlock(&exp->exp_lock);
1831 CDEBUG(D_SEC, "mark oldest expired\n");
1832 exp->exp_flvr_expire[1] = 0;
1834 CDEBUG(D_SEC, "exp %p (%x|%x|%x): %x not match found\n",
1835 exp, exp->exp_flvr.sf_rpc,
1836 exp->exp_flvr_old[0].sf_rpc, exp->exp_flvr_old[1].sf_rpc,
1837 req->rq_flvr.sf_rpc);
1839 CDEBUG(D_SEC, "exp %p (%x|%x|%x): skip the last one\n",
1840 exp, exp->exp_flvr.sf_rpc, exp->exp_flvr_old[0].sf_rpc,
1841 exp->exp_flvr_old[1].sf_rpc);
1844 spin_unlock(&exp->exp_lock);
1846 CWARN("exp %p(%s): req %p (%u|%u|%u|%u|%u|%u) with unauthorized flavor %x, expect %x|%x(%+lld)|%x(%+lld)\n",
1847 exp, exp->exp_obd->obd_name,
1848 req, req->rq_auth_gss, req->rq_ctx_init, req->rq_ctx_fini,
1849 req->rq_auth_usr_root, req->rq_auth_usr_mdt, req->rq_auth_usr_ost,
1850 req->rq_flvr.sf_rpc,
1851 exp->exp_flvr.sf_rpc,
1852 exp->exp_flvr_old[0].sf_rpc,
1853 exp->exp_flvr_expire[0] ?
1854 (s64)(exp->exp_flvr_expire[0] - ktime_get_real_seconds()) : 0,
1855 exp->exp_flvr_old[1].sf_rpc,
1856 exp->exp_flvr_expire[1] ?
1857 (s64)(exp->exp_flvr_expire[1] - ktime_get_real_seconds()) : 0);
1860 EXPORT_SYMBOL(sptlrpc_target_export_check);
1862 static int sptlrpc_svc_check_from(struct ptlrpc_request *req, int svc_rc)
1864 /* peer's claim is unreliable unless gss is being used */
1865 if (!req->rq_auth_gss || svc_rc == SECSVC_DROP)
1868 switch (req->rq_sp_from) {
1870 if (req->rq_auth_usr_mdt || req->rq_auth_usr_ost) {
1871 DEBUG_REQ(D_ERROR, req, "faked source CLI");
1872 svc_rc = SECSVC_DROP;
1876 if (!req->rq_auth_usr_mdt) {
1877 DEBUG_REQ(D_ERROR, req, "faked source MDT");
1878 svc_rc = SECSVC_DROP;
1882 if (!req->rq_auth_usr_ost) {
1883 DEBUG_REQ(D_ERROR, req, "faked source OST");
1884 svc_rc = SECSVC_DROP;
1889 if (!req->rq_auth_usr_root && !req->rq_auth_usr_mdt &&
1890 !req->rq_auth_usr_ost) {
1891 DEBUG_REQ(D_ERROR, req, "faked source MGC/MGS");
1892 svc_rc = SECSVC_DROP;
1897 DEBUG_REQ(D_ERROR, req, "invalid source %u", req->rq_sp_from);
1898 svc_rc = SECSVC_DROP;
1905 * Used by ptlrpc server, to perform transformation upon request message of
1906 * incoming \a req. This must be the first thing to do with a incoming
1907 * request in ptlrpc layer.
1909 * \retval SECSVC_OK success, and req->rq_reqmsg point to request message in
1910 * clear text, size is req->rq_reqlen; also req->rq_svc_ctx is set.
1911 * \retval SECSVC_COMPLETE success, the request has been fully processed, and
1912 * reply message has been prepared.
1913 * \retval SECSVC_DROP failed, this request should be dropped.
1915 int sptlrpc_svc_unwrap_request(struct ptlrpc_request *req)
1917 struct ptlrpc_sec_policy *policy;
1918 struct lustre_msg *msg = req->rq_reqbuf;
1922 LASSERT(!req->rq_reqmsg);
1923 LASSERT(!req->rq_repmsg);
1924 LASSERT(!req->rq_svc_ctx);
1926 req->rq_req_swab_mask = 0;
1928 rc = __lustre_unpack_msg(msg, req->rq_reqdata_len);
1931 lustre_set_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
1935 CERROR("error unpacking request from %s x%llu\n",
1936 libcfs_id2str(req->rq_peer), req->rq_xid);
1940 req->rq_flvr.sf_rpc = WIRE_FLVR(msg->lm_secflvr);
1941 req->rq_sp_from = LUSTRE_SP_ANY;
1942 req->rq_auth_uid = -1;
1943 req->rq_auth_mapped_uid = -1;
1945 policy = sptlrpc_wireflavor2policy(req->rq_flvr.sf_rpc);
1947 CERROR("unsupported rpc flavor %x\n", req->rq_flvr.sf_rpc);
1951 LASSERT(policy->sp_sops->accept);
1952 rc = policy->sp_sops->accept(req);
1953 sptlrpc_policy_put(policy);
1954 LASSERT(req->rq_reqmsg || rc != SECSVC_OK);
1955 LASSERT(req->rq_svc_ctx || rc == SECSVC_DROP);
1958 * if it's not null flavor (which means embedded packing msg),
1959 * reset the swab mask for the coming inner msg unpacking.
1961 if (SPTLRPC_FLVR_POLICY(req->rq_flvr.sf_rpc) != SPTLRPC_POLICY_NULL)
1962 req->rq_req_swab_mask = 0;
1964 /* sanity check for the request source */
1965 rc = sptlrpc_svc_check_from(req, rc);
1970 * Used by ptlrpc server, to allocate reply buffer for \a req. If succeed,
1971 * req->rq_reply_state is set, and req->rq_reply_state->rs_msg point to
1972 * a buffer of \a msglen size.
1974 int sptlrpc_svc_alloc_rs(struct ptlrpc_request *req, int msglen)
1976 struct ptlrpc_sec_policy *policy;
1977 struct ptlrpc_reply_state *rs;
1980 LASSERT(req->rq_svc_ctx);
1981 LASSERT(req->rq_svc_ctx->sc_policy);
1983 policy = req->rq_svc_ctx->sc_policy;
1984 LASSERT(policy->sp_sops->alloc_rs);
1986 rc = policy->sp_sops->alloc_rs(req, msglen);
1987 if (unlikely(rc == -ENOMEM)) {
1988 struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
1990 if (svcpt->scp_service->srv_max_reply_size <
1991 msglen + sizeof(struct ptlrpc_reply_state)) {
1992 /* Just return failure if the size is too big */
1993 CERROR("size of message is too big (%zd), %d allowed\n",
1994 msglen + sizeof(struct ptlrpc_reply_state),
1995 svcpt->scp_service->srv_max_reply_size);
1999 /* failed alloc, try emergency pool */
2000 rs = lustre_get_emerg_rs(svcpt);
2004 req->rq_reply_state = rs;
2005 rc = policy->sp_sops->alloc_rs(req, msglen);
2007 lustre_put_emerg_rs(rs);
2008 req->rq_reply_state = NULL;
2013 (req->rq_reply_state && req->rq_reply_state->rs_msg));
2019 * Used by ptlrpc server, to perform transformation upon reply message.
2021 * \post req->rq_reply_off is set to appropriate server-controlled reply offset.
2022 * \post req->rq_repmsg and req->rq_reply_state->rs_msg becomes inaccessible.
2024 int sptlrpc_svc_wrap_reply(struct ptlrpc_request *req)
2026 struct ptlrpc_sec_policy *policy;
2029 LASSERT(req->rq_svc_ctx);
2030 LASSERT(req->rq_svc_ctx->sc_policy);
2032 policy = req->rq_svc_ctx->sc_policy;
2033 LASSERT(policy->sp_sops->authorize);
2035 rc = policy->sp_sops->authorize(req);
2036 LASSERT(rc || req->rq_reply_state->rs_repdata_len);
2042 * Used by ptlrpc server, to free reply_state.
2044 void sptlrpc_svc_free_rs(struct ptlrpc_reply_state *rs)
2046 struct ptlrpc_sec_policy *policy;
2047 unsigned int prealloc;
2049 LASSERT(rs->rs_svc_ctx);
2050 LASSERT(rs->rs_svc_ctx->sc_policy);
2052 policy = rs->rs_svc_ctx->sc_policy;
2053 LASSERT(policy->sp_sops->free_rs);
2055 prealloc = rs->rs_prealloc;
2056 policy->sp_sops->free_rs(rs);
2059 lustre_put_emerg_rs(rs);
2062 void sptlrpc_svc_ctx_addref(struct ptlrpc_request *req)
2064 struct ptlrpc_svc_ctx *ctx = req->rq_svc_ctx;
2067 atomic_inc(&ctx->sc_refcount);
2070 void sptlrpc_svc_ctx_decref(struct ptlrpc_request *req)
2072 struct ptlrpc_svc_ctx *ctx = req->rq_svc_ctx;
2077 LASSERT_ATOMIC_POS(&ctx->sc_refcount);
2078 if (atomic_dec_and_test(&ctx->sc_refcount)) {
2079 if (ctx->sc_policy->sp_sops->free_ctx)
2080 ctx->sc_policy->sp_sops->free_ctx(ctx);
2082 req->rq_svc_ctx = NULL;
2085 /****************************************
2087 ****************************************/
2090 * Perform transformation upon bulk data pointed by \a desc. This is called
2091 * before transforming the request message.
2093 int sptlrpc_cli_wrap_bulk(struct ptlrpc_request *req,
2094 struct ptlrpc_bulk_desc *desc)
2096 struct ptlrpc_cli_ctx *ctx;
2098 LASSERT(req->rq_bulk_read || req->rq_bulk_write);
2100 if (!req->rq_pack_bulk)
2103 ctx = req->rq_cli_ctx;
2104 if (ctx->cc_ops->wrap_bulk)
2105 return ctx->cc_ops->wrap_bulk(ctx, req, desc);
2108 EXPORT_SYMBOL(sptlrpc_cli_wrap_bulk);
2111 * This is called after unwrap the reply message.
2112 * return nob of actual plain text size received, or error code.
2114 int sptlrpc_cli_unwrap_bulk_read(struct ptlrpc_request *req,
2115 struct ptlrpc_bulk_desc *desc,
2118 struct ptlrpc_cli_ctx *ctx;
2121 LASSERT(req->rq_bulk_read && !req->rq_bulk_write);
2123 if (!req->rq_pack_bulk)
2124 return desc->bd_nob_transferred;
2126 ctx = req->rq_cli_ctx;
2127 if (ctx->cc_ops->unwrap_bulk) {
2128 rc = ctx->cc_ops->unwrap_bulk(ctx, req, desc);
2132 return desc->bd_nob_transferred;
2134 EXPORT_SYMBOL(sptlrpc_cli_unwrap_bulk_read);
2137 * This is called after unwrap the reply message.
2138 * return 0 for success or error code.
2140 int sptlrpc_cli_unwrap_bulk_write(struct ptlrpc_request *req,
2141 struct ptlrpc_bulk_desc *desc)
2143 struct ptlrpc_cli_ctx *ctx;
2146 LASSERT(!req->rq_bulk_read && req->rq_bulk_write);
2148 if (!req->rq_pack_bulk)
2151 ctx = req->rq_cli_ctx;
2152 if (ctx->cc_ops->unwrap_bulk) {
2153 rc = ctx->cc_ops->unwrap_bulk(ctx, req, desc);
2159 * if everything is going right, nob should equals to nob_transferred.
2160 * in case of privacy mode, nob_transferred needs to be adjusted.
2162 if (desc->bd_nob != desc->bd_nob_transferred) {
2163 CERROR("nob %d doesn't match transferred nob %d\n",
2164 desc->bd_nob, desc->bd_nob_transferred);
2170 EXPORT_SYMBOL(sptlrpc_cli_unwrap_bulk_write);
2172 /****************************************
2173 * user descriptor helpers *
2174 ****************************************/
2176 int sptlrpc_current_user_desc_size(void)
2180 ngroups = current_ngroups;
2182 if (ngroups > LUSTRE_MAX_GROUPS)
2183 ngroups = LUSTRE_MAX_GROUPS;
2184 return sptlrpc_user_desc_size(ngroups);
2186 EXPORT_SYMBOL(sptlrpc_current_user_desc_size);
2188 int sptlrpc_pack_user_desc(struct lustre_msg *msg, int offset)
2190 struct ptlrpc_user_desc *pud;
2192 pud = lustre_msg_buf(msg, offset, 0);
2197 pud->pud_uid = from_kuid(&init_user_ns, current_uid());
2198 pud->pud_gid = from_kgid(&init_user_ns, current_gid());
2199 pud->pud_fsuid = from_kuid(&init_user_ns, current_fsuid());
2200 pud->pud_fsgid = from_kgid(&init_user_ns, current_fsgid());
2201 pud->pud_cap = cfs_curproc_cap_pack();
2202 pud->pud_ngroups = (msg->lm_buflens[offset] - sizeof(*pud)) / 4;
2205 if (pud->pud_ngroups > current_ngroups)
2206 pud->pud_ngroups = current_ngroups;
2207 memcpy(pud->pud_groups, current_cred()->group_info->blocks[0],
2208 pud->pud_ngroups * sizeof(__u32));
2209 task_unlock(current);
2213 EXPORT_SYMBOL(sptlrpc_pack_user_desc);
2215 int sptlrpc_unpack_user_desc(struct lustre_msg *msg, int offset, int swabbed)
2217 struct ptlrpc_user_desc *pud;
2220 pud = lustre_msg_buf(msg, offset, sizeof(*pud));
2225 __swab32s(&pud->pud_uid);
2226 __swab32s(&pud->pud_gid);
2227 __swab32s(&pud->pud_fsuid);
2228 __swab32s(&pud->pud_fsgid);
2229 __swab32s(&pud->pud_cap);
2230 __swab32s(&pud->pud_ngroups);
2233 if (pud->pud_ngroups > LUSTRE_MAX_GROUPS) {
2234 CERROR("%u groups is too large\n", pud->pud_ngroups);
2238 if (sizeof(*pud) + pud->pud_ngroups * sizeof(__u32) >
2239 msg->lm_buflens[offset]) {
2240 CERROR("%u groups are claimed but bufsize only %u\n",
2241 pud->pud_ngroups, msg->lm_buflens[offset]);
2246 for (i = 0; i < pud->pud_ngroups; i++)
2247 __swab32s(&pud->pud_groups[i]);
2252 EXPORT_SYMBOL(sptlrpc_unpack_user_desc);
2254 /****************************************
2256 ****************************************/
2258 const char *sec2target_str(struct ptlrpc_sec *sec)
2260 if (!sec || !sec->ps_import || !sec->ps_import->imp_obd)
2262 if (sec_is_reverse(sec))
2264 return obd_uuid2str(&sec->ps_import->imp_obd->u.cli.cl_target_uuid);
2266 EXPORT_SYMBOL(sec2target_str);
2269 * return true if the bulk data is protected
2271 bool sptlrpc_flavor_has_bulk(struct sptlrpc_flavor *flvr)
2273 switch (SPTLRPC_FLVR_BULK_SVC(flvr->sf_rpc)) {
2274 case SPTLRPC_BULK_SVC_INTG:
2275 case SPTLRPC_BULK_SVC_PRIV:
2281 EXPORT_SYMBOL(sptlrpc_flavor_has_bulk);
2283 /****************************************
2284 * crypto API helper/alloc blkciper *
2285 ****************************************/
2287 /****************************************
2288 * initialize/finalize *
2289 ****************************************/
2291 int sptlrpc_init(void)
2295 rwlock_init(&policy_lock);
2297 rc = sptlrpc_gc_init();
2301 rc = sptlrpc_conf_init();
2305 rc = sptlrpc_enc_pool_init();
2309 rc = sptlrpc_null_init();
2313 rc = sptlrpc_plain_init();
2317 rc = sptlrpc_lproc_init();
2324 sptlrpc_plain_fini();
2326 sptlrpc_null_fini();
2328 sptlrpc_enc_pool_fini();
2330 sptlrpc_conf_fini();
2337 void sptlrpc_fini(void)
2339 sptlrpc_lproc_fini();
2340 sptlrpc_plain_fini();
2341 sptlrpc_null_fini();
2342 sptlrpc_enc_pool_fini();
2343 sptlrpc_conf_fini();