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) 2013, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/obdclass/lu_ucred.c
34 * Lustre user credentials context infrastructure.
36 * Author: Nikita Danilov <nikita.danilov@sun.com>
37 * Author: Fan Yong <fan.yong@intel.com>
38 * Author: Vitaly Fertman <vitaly_fertman@xyratex.com>
41 #define DEBUG_SUBSYSTEM S_CLASS
43 #include <libcfs/libcfs.h>
44 #include <obd_support.h>
45 #include <lu_object.h>
46 #include <md_object.h>
48 /* context key constructor/destructor: lu_ucred_key_init, lu_ucred_key_fini */
49 LU_KEY_INIT_FINI(lu_ucred, struct lu_ucred);
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
58 * Get ucred key if session exists and ucred key is allocated on it.
59 * Return NULL otherwise.
61 struct lu_ucred *lu_ucred(const struct lu_env *env)
65 return lu_context_key_get(env->le_ses, &lu_ucred_key);
67 EXPORT_SYMBOL(lu_ucred);
70 * Get ucred key and check if it is properly initialized.
71 * Return NULL otherwise.
73 struct lu_ucred *lu_ucred_check(const struct lu_env *env)
75 struct lu_ucred *uc = lu_ucred(env);
76 if (uc && uc->uc_valid != UCRED_OLD && uc->uc_valid != UCRED_NEW)
80 EXPORT_SYMBOL(lu_ucred_check);
83 * Get ucred key, which must exist and must be properly initialized.
86 struct lu_ucred *lu_ucred_assert(const struct lu_env *env)
88 struct lu_ucred *uc = lu_ucred_check(env);
92 EXPORT_SYMBOL(lu_ucred_assert);
94 int lu_ucred_global_init(void)
96 LU_CONTEXT_KEY_INIT(&lu_ucred_key);
97 return lu_context_key_register(&lu_ucred_key);
100 void lu_ucred_global_fini(void)
102 lu_context_key_degister(&lu_ucred_key);