Whamcloud - gitweb
Branch: HEAD
[fs/lustre-release.git] / lustre / include / linux / lustre_gs.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001-2003 Cluster File Systems, Inc. <info@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * GS data structures.
22  * See also lustre_idl.h for wire formats of requests.
23  *
24  */
25
26 #ifndef _LUSTRE_GS_H
27 #define _LUSTRE_GS_H
28
29 #define LUSTRE_GKS_NAME "gks"
30 #define LUSTRE_GKT_NAME "gkt"
31 #define LUSTRE_GKC_NAME "gkc"
32
33
34 /*define gsk type*/
35 #define NO_CRYPTO 0
36 #define GKS_TYPE  1
37 #define MKS_TYPE  2  
38
39 struct crypto_ops_item {
40         struct crypto_helper_ops *cops;
41         struct list_head clist;
42         char   *ctype;
43 };
44
45 #define DECRYPT_DATA      0x00000001
46 #define ENCRYPT_DATA      0x00000002
47 struct lustre_key {
48         struct crypto_key   lk_ck;
49         atomic_t            lk_refcount;
50         __u32               lk_key_type;
51         __u32               lk_flags; 
52         __u8                lk_dk[KEY_SIZE];
53 };
54  
55 static inline struct lustre_key *
56 lustre_key_get(struct lustre_key *lkey)
57 {
58         if (lkey) { 
59                 atomic_inc(&lkey->lk_refcount);
60         }
61         return lkey;
62 }
63
64
65 static inline void
66 lustre_key_release(struct lustre_key *lkey)
67 {
68         if (lkey && atomic_dec_and_test(&lkey->lk_refcount))
69                 kfree(lkey);
70 }
71
72 #define SET_CRYPTO_FLAGS(flags, type, offset, width)           \
73 do {                                                           \
74         flags &= ~(((1 << width) - 1) << offset);              \
75         flags |= (type & ((1 << width) - 1)) << offset;        \
76 } while(0)
77
78 #define CPT_TYPE_OFFSET 0
79 #define CPT_TYPE_WIDTH  2 
80 #define GKS_CRYPTO_TYPE 1
81 #define MKS_CRYPTO_TYPE 2
82
83 #define SET_CRYPTO_TYPE(flags, type)                           \
84 SET_CRYPTO_FLAGS(flags, type, CPT_TYPE_OFFSET, CPT_TYPE_WIDTH)
85
86 #define IS_GKS_TYPE(flags)                                      \
87 (((flags >> CPT_TYPE_OFFSET) & ((1 << CPT_TYPE_WIDTH) - 1)) == GKS_CRYPTO_TYPE)
88
89 #define IS_MKS_TYPE(flags)                                      \
90 (((flags >> CPT_TYPE_OFFSET) & ((1 << CPT_TYPE_WIDTH) - 1)) == MKS_CRYPTO_TYPE)
91
92 #define CPT_ENCRYPT_OFFSET 2 
93 #define CPT_ENCRYPT_WIDTH  1 
94 #define ENABLE_ENCRYPT_FLAG 1
95 #define DISABLE_ENCRYPT_FLAG 0 
96
97 #define ENABLE_ENCRYPT(flag) \
98 SET_CRYPTO_FLAGS(flag, ENABLE_ENCRYPT_FLAG, CPT_ENCRYPT_OFFSET, CPT_ENCRYPT_WIDTH)
99
100 #define DISABLE_ENCRYPT(flag) \
101 SET_CRYPTO_FLAGS(flag, DISABLE_ENCRYPT_FLAG, CPT_ENCRYPT_OFFSET, CPT_ENCRYPT_WIDTH)
102
103 #define IS_ENABLE_ENCRYPT(flags)                                 \
104 (((flags >> CPT_ENCRYPT_OFFSET) & ((1 << CPT_ENCRYPT_WIDTH) - 1)) \
105                                 == ENABLE_ENCRYPT_FLAG)
106
107 #define CPT_DECRYPT_OFFSET 3 
108 #define CPT_DECRYPT_WIDTH  1 
109 #define ENABLE_DECRYPT_FLAG 1
110 #define DISABLE_DECRYPT_FLAG 2
111
112 #define ENABLE_DECRYPT(flag) \
113 SET_CRYPTO_FLAGS(flag, ENABLE_DECRYPT_FLAG, CPT_DECRYPT_OFFSET, CPT_DECRYPT_WIDTH)
114
115 #define DISABLE_DECRYPT(flag) \
116 SET_CRYPTO_FLAGS(flag, DISABLE_DECRYPT_FLAG, CPT_DECRYPT_OFFSET, CPT_DECRYPT_WIDTH)
117
118 #define IS_ENABLE_DECRYPT(flags)                                 \
119 (((flags >> CPT_DECRYPT_OFFSET) & ((1 << CPT_DECRYPT_WIDTH) - 1)) \
120                                 == ENABLE_DECRYPT_FLAG)
121
122 #define CPT_DECRYPTED_OFFSET 4 
123 #define CPT_DECRYPTED_WIDTH  1 
124 #define DECRYPTED_FLAG 1
125 #define ENCRYPTED_FLAG 0 
126
127 #define SET_DECRYPTED(flag) \
128 SET_CRYPTO_FLAGS(flag, DECRYPTED_FLAG, CPT_DECRYPTED_OFFSET, CPT_DECRYPTED_WIDTH)
129
130 #define SET_UNDECRYPTED(flag) \
131 SET_CRYPTO_FLAGS(flag, ENCRYPTED_FLAG, CPT_DECRYPTED_OFFSET, CPT_DECRYPTED_WIDTH)
132
133 #define IS_DECRYPTED(flags) \
134 (((flags >> CPT_DECRYPTED_OFFSET) & ((1 << CPT_DECRYPTED_WIDTH) - 1)) \
135                                 == DECRYPTED_FLAG)
136
137
138
139 #define MD_KEY_MAGIC 0x19760218
140 struct crypto_key_md {
141         struct crypto_key md_ck;
142         __u32             md_magic;
143 };
144
145 struct key_parms {
146         struct key_context *context;
147         struct key_perm    *perm; 
148         int                 context_size;
149         int                 perm_size;
150 };
151
152 static inline int crypto_kcontext_size(int acl_count) 
153 {
154        return (sizeof(struct key_context) + acl_count * 
155                sizeof(struct posix_acl_entry));
156 }
157 static inline int crypto_kperm_size(int acl_count)
158 {
159         return (sizeof(struct key_perm) + acl_count * 
160                        sizeof(struct posix_acl_entry));
161 }
162 #endif /*LUSTRE_GS_H*/