Whamcloud - gitweb
LU-6698 kernel: kernel update RHEL 6.6 [2.6.32-504.23.4.el6]
[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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2013, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/obdclass/lu_ucred.c
37  *
38  * Lustre user credentials context infrastructure.
39  *
40  *   Author: Nikita Danilov <nikita.danilov@sun.com>
41  *   Author: Fan Yong <fan.yong@intel.com>
42  *   Author: Vitaly Fertman <vitaly_fertman@xyratex.com>
43  */
44
45 #define DEBUG_SUBSYSTEM S_CLASS
46
47 #include <libcfs/libcfs.h>
48 #include <obd_support.h>
49 #include <lu_object.h>
50 #include <md_object.h>
51
52 /* context key constructor/destructor: lu_ucred_key_init, lu_ucred_key_fini */
53 LU_KEY_INIT_FINI(lu_ucred, struct lu_ucred);
54
55 static struct lu_context_key lu_ucred_key = {
56         .lct_tags = LCT_SERVER_SESSION,
57         .lct_init = lu_ucred_key_init,
58         .lct_fini = lu_ucred_key_fini
59 };
60
61 /**
62  * Get ucred key if session exists and ucred key is allocated on it.
63  * Return NULL otherwise.
64  */
65 struct lu_ucred *lu_ucred(const struct lu_env *env)
66 {
67         if (!env->le_ses)
68                 return NULL;
69         return lu_context_key_get(env->le_ses, &lu_ucred_key);
70 }
71 EXPORT_SYMBOL(lu_ucred);
72
73 /**
74  * Get ucred key and check if it is properly initialized.
75  * Return NULL otherwise.
76  */
77 struct lu_ucred *lu_ucred_check(const struct lu_env *env)
78 {
79         struct lu_ucred *uc = lu_ucred(env);
80         if (uc && uc->uc_valid != UCRED_OLD && uc->uc_valid != UCRED_NEW)
81                 return NULL;
82         return uc;
83 }
84 EXPORT_SYMBOL(lu_ucred_check);
85
86 /**
87  * Get ucred key, which must exist and must be properly initialized.
88  * Assert otherwise.
89  */
90 struct lu_ucred *lu_ucred_assert(const struct lu_env *env)
91 {
92         struct lu_ucred *uc = lu_ucred_check(env);
93         LASSERT(uc != NULL);
94         return uc;
95 }
96 EXPORT_SYMBOL(lu_ucred_assert);
97
98 int lu_ucred_global_init(void)
99 {
100         LU_CONTEXT_KEY_INIT(&lu_ucred_key);
101         return lu_context_key_register(&lu_ucred_key);
102 }
103
104 void lu_ucred_global_fini(void)
105 {
106         lu_context_key_degister(&lu_ucred_key);
107 }