Commit | Line | Data |
---|---|---|
d7e09d03 PT |
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) 2008, 2010, Oracle and/or its affiliates. All rights reserved. | |
28 | * Use is subject to license terms. | |
29 | * | |
30 | * Copyright (c) 2011, 2012, 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 | * libcfs/libcfs/linux/linux-curproc.c | |
37 | * | |
38 | * Lustre curproc API implementation for Linux kernel | |
39 | * | |
40 | * Author: Nikita Danilov <nikita@clusterfs.com> | |
41 | */ | |
42 | ||
43 | #include <linux/sched.h> | |
44 | #include <linux/fs_struct.h> | |
45 | ||
46 | #include <linux/compat.h> | |
47 | #include <linux/thread_info.h> | |
48 | ||
49 | #define DEBUG_SUBSYSTEM S_LNET | |
50 | ||
9fdaf8c0 | 51 | #include "../../../include/linux/libcfs/libcfs.h" |
d7e09d03 PT |
52 | |
53 | /* | |
54 | * Implementation of cfs_curproc API (see portals/include/libcfs/curproc.h) | |
55 | * for Linux kernel. | |
56 | */ | |
57 | ||
d7e09d03 PT |
58 | void cfs_cap_raise(cfs_cap_t cap) |
59 | { | |
60 | struct cred *cred; | |
a95cdab3 | 61 | |
4a87df3e CP |
62 | cred = prepare_creds(); |
63 | if (cred) { | |
9a28b188 | 64 | cap_raise(cred->cap_effective, cap); |
d7e09d03 PT |
65 | commit_creds(cred); |
66 | } | |
67 | } | |
68 | ||
69 | void cfs_cap_lower(cfs_cap_t cap) | |
70 | { | |
71 | struct cred *cred; | |
a95cdab3 | 72 | |
4a87df3e CP |
73 | cred = prepare_creds(); |
74 | if (cred) { | |
9a28b188 | 75 | cap_lower(cred->cap_effective, cap); |
d7e09d03 PT |
76 | commit_creds(cred); |
77 | } | |
78 | } | |
79 | ||
80 | int cfs_cap_raised(cfs_cap_t cap) | |
81 | { | |
9a28b188 | 82 | return cap_raised(current_cap(), cap); |
d7e09d03 PT |
83 | } |
84 | ||
85 | void cfs_kernel_cap_pack(kernel_cap_t kcap, cfs_cap_t *cap) | |
86 | { | |
d7e09d03 | 87 | /* XXX lost high byte */ |
9a28b188 | 88 | *cap = kcap.cap[0]; |
d7e09d03 PT |
89 | } |
90 | ||
91 | void cfs_kernel_cap_unpack(kernel_cap_t *kcap, cfs_cap_t cap) | |
92 | { | |
9a28b188 | 93 | kcap->cap[0] = cap; |
d7e09d03 PT |
94 | } |
95 | ||
96 | cfs_cap_t cfs_curproc_cap_pack(void) | |
97 | { | |
98 | cfs_cap_t cap; | |
99 | cfs_kernel_cap_pack(current_cap(), &cap); | |
100 | return cap; | |
101 | } | |
102 | ||
d7e09d03 PT |
103 | EXPORT_SYMBOL(cfs_cap_raise); |
104 | EXPORT_SYMBOL(cfs_cap_lower); | |
105 | EXPORT_SYMBOL(cfs_cap_raised); | |
106 | EXPORT_SYMBOL(cfs_curproc_cap_pack); | |
d7e09d03 PT |
107 | |
108 | /* | |
109 | * Local variables: | |
110 | * c-indentation-style: "K&R" | |
111 | * c-basic-offset: 8 | |
112 | * tab-width: 8 | |
113 | * fill-column: 80 | |
114 | * scroll-step: 1 | |
115 | * End: | |
116 | */ |