Whamcloud - gitweb
LU-10467 ptlrpc: convert final users of LWI_TIMEOUT_INTERVAL
[fs/lustre-release.git] / lustre / obdclass / lu_ucred.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2013, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lustre/obdclass/lu_ucred.c
33  *
34  * Lustre user credentials context infrastructure.
35  *
36  *   Author: Nikita Danilov <nikita.danilov@sun.com>
37  *   Author: Fan Yong <fan.yong@intel.com>
38  *   Author: Vitaly Fertman <vitaly_fertman@xyratex.com>
39  */
40
41 #define DEBUG_SUBSYSTEM S_CLASS
42
43 #include <libcfs/libcfs.h>
44 #include <obd_support.h>
45 #include <lu_object.h>
46 #include <md_object.h>
47
48 /* context key constructor/destructor: lu_ucred_key_init, lu_ucred_key_fini */
49 LU_KEY_INIT_FINI(lu_ucred, struct lu_ucred);
50
51 static struct lu_context_key lu_ucred_key = {
52         .lct_tags = LCT_SERVER_SESSION,
53         .lct_init = lu_ucred_key_init,
54         .lct_fini = lu_ucred_key_fini
55 };
56
57 /**
58  * Get ucred key if session exists and ucred key is allocated on it.
59  * Return NULL otherwise.
60  */
61 struct lu_ucred *lu_ucred(const struct lu_env *env)
62 {
63         if (!env->le_ses)
64                 return NULL;
65         return lu_context_key_get(env->le_ses, &lu_ucred_key);
66 }
67 EXPORT_SYMBOL(lu_ucred);
68
69 /**
70  * Get ucred key and check if it is properly initialized.
71  * Return NULL otherwise.
72  */
73 struct lu_ucred *lu_ucred_check(const struct lu_env *env)
74 {
75         struct lu_ucred *uc = lu_ucred(env);
76         if (uc && uc->uc_valid != UCRED_OLD && uc->uc_valid != UCRED_NEW)
77                 return NULL;
78         return uc;
79 }
80 EXPORT_SYMBOL(lu_ucred_check);
81
82 /**
83  * Get ucred key, which must exist and must be properly initialized.
84  * Assert otherwise.
85  */
86 struct lu_ucred *lu_ucred_assert(const struct lu_env *env)
87 {
88         struct lu_ucred *uc = lu_ucred_check(env);
89         LASSERT(uc != NULL);
90         return uc;
91 }
92 EXPORT_SYMBOL(lu_ucred_assert);
93
94 int lu_ucred_global_init(void)
95 {
96         LU_CONTEXT_KEY_INIT(&lu_ucred_key);
97         return lu_context_key_register(&lu_ucred_key);
98 }
99
100 void lu_ucred_global_fini(void)
101 {
102         lu_context_key_degister(&lu_ucred_key);
103 }