aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/lustre/lustre/obdclass/lu_ucred.c
blob: 229db6c39b78de13dd5937f9cbdb2d18d3a0f6e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * GPL HEADER START
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 only,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License version 2 for more details (a copy is included
 * in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU General Public License
 * version 2 along with this program; If not, see
 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 *
 * GPL HEADER END
 */
/*
 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
 * Use is subject to license terms.
 *
 * Copyright (c) 2011, 2012, Intel Corporation.
 */
/*
 * This file is part of Lustre, http://www.lustre.org/
 * Lustre is a trademark of Sun Microsystems, Inc.
 *
 * lustre/obdclass/lu_object.c
 *
 * Lustre Object.
 * These are the only exported functions, they provide some generic
 * infrastructure for managing object devices
 *
 *   Author: Nikita Danilov <nikita.danilov@sun.com>
 */

#define DEBUG_SUBSYSTEM S_CLASS

#include <linux/libcfs/libcfs.h>
#include <obd_support.h>
#include <lu_object.h>
#include <md_object.h>

/* context key constructor/destructor: lu_ucred_key_init, lu_ucred_key_fini */
LU_KEY_INIT_FINI(lu_ucred, struct lu_ucred);

static struct lu_context_key lu_ucred_key = {
	.lct_tags = LCT_SESSION,
	.lct_init = lu_ucred_key_init,
	.lct_fini = lu_ucred_key_fini
};

/**
 * Get ucred key if session exists and ucred key is allocated on it.
 * Return NULL otherwise.
 */
struct lu_ucred *lu_ucred(const struct lu_env *env)
{
	if (!env->le_ses)
		return NULL;
	return lu_context_key_get(env->le_ses, &lu_ucred_key);
}
EXPORT_SYMBOL(lu_ucred);

/**
 * Get ucred key and check if it is properly initialized.
 * Return NULL otherwise.
 */
struct lu_ucred *lu_ucred_check(const struct lu_env *env)
{
	struct lu_ucred *uc = lu_ucred(env);
	if (uc && uc->uc_valid != UCRED_OLD && uc->uc_valid != UCRED_NEW)
		return NULL;
	return uc;
}
EXPORT_SYMBOL(lu_ucred_check);

/**
 * Get ucred key, which must exist and must be properly initialized.
 * Assert otherwise.
 */
struct lu_ucred *lu_ucred_assert(const struct lu_env *env)
{
	struct lu_ucred *uc = lu_ucred_check(env);
	LASSERT(uc != NULL);
	return uc;
}
EXPORT_SYMBOL(lu_ucred_assert);

int lu_ucred_global_init(void)
{
	LU_CONTEXT_KEY_INIT(&lu_ucred_key);
	return lu_context_key_register(&lu_ucred_key);
}

void lu_ucred_global_fini(void)
{
	lu_context_key_degister(&lu_ucred_key);
}