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.sun.com/software/products/lustre/docs/GPLv2.pdf
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
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/obdclass/lu_ucred.c
38 * Lustre user credentials context infrastructure.
40 * Author: Nikita Danilov <nikita.danilov@sun.com>
41 * Author: Fan Yong <fan.yong@intel.com>
42 * Author: Vitaly Fertman <vitaly_fertman@xyratex.com>
45 #define DEBUG_SUBSYSTEM S_CLASS
47 #include <libcfs/libcfs.h>
48 #include <obd_support.h>
49 #include <lu_object.h>
50 #include <md_object.h>
52 /* context key constructor/destructor: lu_ucred_key_init, lu_ucred_key_fini */
53 LU_KEY_INIT_FINI(lu_ucred, struct lu_ucred);
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
62 * Get ucred key if session exists and ucred key is allocated on it.
63 * Return NULL otherwise.
65 struct lu_ucred *lu_ucred(const struct lu_env *env)
69 return lu_context_key_get(env->le_ses, &lu_ucred_key);
71 EXPORT_SYMBOL(lu_ucred);
74 * Get ucred key and check if it is properly initialized.
75 * Return NULL otherwise.
77 struct lu_ucred *lu_ucred_check(const struct lu_env *env)
79 struct lu_ucred *uc = lu_ucred(env);
80 if (uc && uc->uc_valid != UCRED_OLD && uc->uc_valid != UCRED_NEW)
84 EXPORT_SYMBOL(lu_ucred_check);
87 * Get ucred key, which must exist and must be properly initialized.
90 struct lu_ucred *lu_ucred_assert(const struct lu_env *env)
92 struct lu_ucred *uc = lu_ucred_check(env);
96 EXPORT_SYMBOL(lu_ucred_assert);
98 int lu_ucred_global_init(void)
100 LU_CONTEXT_KEY_INIT(&lu_ucred_key);
101 return lu_context_key_register(&lu_ucred_key);
104 void lu_ucred_global_fini(void)
106 lu_context_key_degister(&lu_ucred_key);