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/
31 * lustre/obdclass/lu_ucred.c
33 * Lustre user credentials context infrastructure.
35 * Author: Nikita Danilov <nikita.danilov@sun.com>
36 * Author: Fan Yong <fan.yong@intel.com>
37 * Author: Vitaly Fertman <vitaly_fertman@xyratex.com>
40 #define DEBUG_SUBSYSTEM S_CLASS
42 #include <libcfs/libcfs.h>
43 #include <obd_support.h>
44 #include <lu_object.h>
45 #include <md_object.h>
47 /* context key constructor/destructor: lu_ucred_key_init, lu_ucred_key_fini */
48 LU_KEY_INIT_FINI(lu_ucred, struct lu_ucred);
50 static struct lu_context_key lu_ucred_key = {
51 .lct_tags = LCT_SERVER_SESSION,
52 .lct_init = lu_ucred_key_init,
53 .lct_fini = lu_ucred_key_fini
57 * Get ucred key if session exists and ucred key is allocated on it.
58 * Return NULL otherwise.
60 struct lu_ucred *lu_ucred(const struct lu_env *env)
64 return lu_context_key_get(env->le_ses, &lu_ucred_key);
66 EXPORT_SYMBOL(lu_ucred);
69 * Get ucred key and check if it is properly initialized.
70 * Return NULL otherwise.
72 struct lu_ucred *lu_ucred_check(const struct lu_env *env)
74 struct lu_ucred *uc = lu_ucred(env);
75 if (uc && uc->uc_valid != UCRED_OLD && uc->uc_valid != UCRED_NEW)
79 EXPORT_SYMBOL(lu_ucred_check);
82 * Get ucred key, which must exist and must be properly initialized.
85 struct lu_ucred *lu_ucred_assert(const struct lu_env *env)
87 struct lu_ucred *uc = lu_ucred_check(env);
91 EXPORT_SYMBOL(lu_ucred_assert);
93 int lu_ucred_global_init(void)
95 LU_CONTEXT_KEY_INIT(&lu_ucred_key);
96 return lu_context_key_register(&lu_ucred_key);
99 void lu_ucred_global_fini(void)
101 lu_context_key_degister(&lu_ucred_key);