Whamcloud - gitweb
land b_hd_sec onto HEAD:
[fs/lustre-release.git] / lustre / include / linux / lustre_cfg.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@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  */
22
23 #ifndef _LUSTRE_CFG_H
24 #define _LUSTRE_CFG_H
25
26 #define LUSTRE_CFG_VERSION 0x00010001
27
28 enum lcfg_command_type {
29         LCFG_ATTACH         = 0x00cf001,
30         LCFG_DETACH         = 0x00cf002,
31         LCFG_SETUP          = 0x00cf003,
32         LCFG_CLEANUP        = 0x00cf004,
33         LCFG_ADD_UUID       = 0x00cf005,
34         LCFG_DEL_UUID       = 0x00cf006,
35         LCFG_MOUNTOPT       = 0x00cf007,
36         LCFG_DEL_MOUNTOPT   = 0x00cf008,
37         LCFG_SET_TIMEOUT    = 0x00cf009,
38         LCFG_SET_UPCALL     = 0x00cf00a,
39         LCFG_LOV_ADD_OBD    = 0x00cf00b,
40         LCFG_LOV_DEL_OBD    = 0x00cf00c,
41         LCFG_ADD_CONN       = 0x00cf00d,
42         LCFG_DEL_CONN       = 0x00cf00e,
43         LCFG_SET_SECURITY   = 0x00cf00f,
44 };
45
46 struct lustre_cfg {
47         uint32_t lcfg_version;
48         uint32_t lcfg_command;
49
50         uint32_t lcfg_num; 
51         uint32_t lcfg_flags;
52         uint64_t lcfg_nid;
53         uint32_t lcfg_nal;
54
55         /* inline buffers for various arguments */
56         uint32_t lcfg_dev_namelen;
57         char    *lcfg_dev_name;
58         uint32_t lcfg_inllen1;
59         char    *lcfg_inlbuf1;
60         uint32_t lcfg_inllen2;
61         char    *lcfg_inlbuf2;
62         uint32_t lcfg_inllen3;
63         char    *lcfg_inlbuf3;
64         uint32_t lcfg_inllen4;
65         char    *lcfg_inlbuf4;
66         uint32_t lcfg_inllen5;
67         char    *lcfg_inlbuf5;
68         uint32_t lcfg_inllen6;
69         char    *lcfg_inlbuf6;
70
71
72         char    lcfg_bulk[0];
73 };
74
75 #define LCFG_INIT(l, cmd, name)                                 \
76 do {                                                            \
77         memset(&(l), 0, sizeof(l));                             \
78         (l).lcfg_version = LUSTRE_CFG_VERSION;                  \
79         (l).lcfg_command = (cmd);                               \
80         if (name) {                                             \
81                 (l).lcfg_dev_namelen = strlen(name) + 1;        \
82                 (l).lcfg_dev_name = name;                       \
83         }                                                       \
84                                                                 \
85 } while (0)
86
87 #ifndef __KERNEL__
88 static inline int lustre_cfg_packlen(struct lustre_cfg *lcfg)
89 {
90         int len = size_round(sizeof(struct lustre_cfg));
91         len += size_round(lcfg->lcfg_dev_namelen);
92         len += size_round(lcfg->lcfg_inllen1);
93         len += size_round(lcfg->lcfg_inllen2);
94         len += size_round(lcfg->lcfg_inllen3);
95         len += size_round(lcfg->lcfg_inllen4);
96         len += size_round(lcfg->lcfg_inllen5);
97         len += size_round(lcfg->lcfg_inllen6);
98         return size_round(len);
99 }
100
101 static inline int lustre_cfg_pack(struct lustre_cfg *data, char **pbuf,
102                                  int max, int *plen)
103 {
104         char *ptr;
105         struct lustre_cfg *overlay;
106         int len;
107
108         len = lustre_cfg_packlen(data);
109
110         data->lcfg_version = LUSTRE_CFG_VERSION;
111
112         if (*pbuf && len > max)
113                 return 1;
114         if (*pbuf == NULL) {
115                 *pbuf = malloc(len);
116         }
117         if (!*pbuf)
118                 return 1;
119         overlay = (struct lustre_cfg *)*pbuf;
120         memcpy(*pbuf, data, sizeof(*data));
121
122         ptr = overlay->lcfg_bulk;
123         if (data->lcfg_dev_name)
124                 LOGL(data->lcfg_dev_name, data->lcfg_dev_namelen, ptr);
125         if (data->lcfg_inlbuf1)
126                 LOGL(data->lcfg_inlbuf1, data->lcfg_inllen1, ptr);
127         if (data->lcfg_inlbuf2)
128                 LOGL(data->lcfg_inlbuf2, data->lcfg_inllen2, ptr);
129         if (data->lcfg_inlbuf3)
130                 LOGL(data->lcfg_inlbuf3, data->lcfg_inllen3, ptr);
131         if (data->lcfg_inlbuf4)
132                 LOGL(data->lcfg_inlbuf4, data->lcfg_inllen4, ptr);
133         if (data->lcfg_inlbuf5)
134                 LOGL(data->lcfg_inlbuf5, data->lcfg_inllen5, ptr);
135         if (data->lcfg_inlbuf6)
136                 LOGL(data->lcfg_inlbuf6, data->lcfg_inllen6, ptr);
137
138         *plen = len;
139
140         return 0;
141 }
142
143 static inline int lustre_cfg_unpack(struct lustre_cfg *data, char *pbuf,
144                                    int max)
145 {
146         char *ptr;
147         struct lustre_cfg *overlay;
148
149         if (!pbuf)
150                 return 1;
151         overlay = (struct lustre_cfg *)pbuf;
152
153         /* Preserve the caller's buffer pointers */
154         overlay->lcfg_dev_name = data->lcfg_dev_name;
155         overlay->lcfg_inlbuf1 = data->lcfg_inlbuf1;
156         overlay->lcfg_inlbuf2 = data->lcfg_inlbuf2;
157         overlay->lcfg_inlbuf3 = data->lcfg_inlbuf3;
158         overlay->lcfg_inlbuf4 = data->lcfg_inlbuf4;
159         overlay->lcfg_inlbuf5 = data->lcfg_inlbuf5;
160         overlay->lcfg_inlbuf6 = data->lcfg_inlbuf6;
161
162         memcpy(data, pbuf, sizeof(*data));
163
164         ptr = overlay->lcfg_bulk;
165         if (data->lcfg_dev_name)
166                 LOGU(data->lcfg_dev_name, data->lcfg_dev_namelen, ptr);
167         if (data->lcfg_inlbuf1)
168                 LOGU(data->lcfg_inlbuf1, data->lcfg_inllen1, ptr);
169         if (data->lcfg_inlbuf2)
170                 LOGU(data->lcfg_inlbuf2, data->lcfg_inllen2, ptr);
171         if (data->lcfg_inlbuf3)
172                 LOGU(data->lcfg_inlbuf3, data->lcfg_inllen3, ptr);
173         if (data->lcfg_inlbuf4)
174                 LOGU(data->lcfg_inlbuf4, data->lcfg_inllen4, ptr);
175         if (data->lcfg_inlbuf5)
176                 LOGU(data->lcfg_inlbuf5, data->lcfg_inllen5, ptr);
177         if (data->lcfg_inlbuf6)
178                 LOGU(data->lcfg_inlbuf6, data->lcfg_inllen6, ptr);
179
180         return 0;
181 }
182 #endif
183
184 #include <linux/obd_support.h>
185
186 static inline int lustre_cfg_getdata(char **buf, int len, void *arg, int kernel)
187 {
188         struct lustre_cfg *lcfg;
189         int err;
190         int offset = 0;
191         ENTRY;
192         if (len > OBD_MAX_IOCTL_BUFFER) {
193                 CERROR("User buffer len %d exceeds %d max buffer\n",
194                        len, OBD_MAX_IOCTL_BUFFER);
195                 return -EINVAL;
196         }
197
198         if (len < sizeof(struct lustre_cfg)) {
199                 CERROR("OBD: user buffer too small for lustre_cfg\n");
200                 return -EINVAL;
201         }
202
203         /* XXX allocate this more intelligently, using kmalloc when
204          * appropriate */
205         OBD_ALLOC(*buf, len);
206         if (*buf == NULL) {
207                 CERROR("Cannot allocate control buffer of len %d\n", len);
208                 RETURN(-EINVAL);
209         }
210
211         if (kernel) {
212                 memcpy(*buf, (void *)arg, len);
213         } else {
214                 err = copy_from_user(*buf, (void *)arg, len);
215                 if (err) 
216                         RETURN(err);
217         }
218
219         lcfg = (struct lustre_cfg *)*buf;
220
221         if (lcfg->lcfg_version != LUSTRE_CFG_VERSION) {
222                 CERROR("Version mismatch kernel: %#x application: %#x\n",
223                        LUSTRE_CFG_VERSION, lcfg->lcfg_version);
224                 return -EINVAL;
225         }
226
227
228         if (lcfg->lcfg_dev_name) {
229                 lcfg->lcfg_dev_name = &lcfg->lcfg_bulk[0];
230                 offset += size_round(lcfg->lcfg_dev_namelen);
231         }
232
233         if (lcfg->lcfg_inllen1) {
234                 lcfg->lcfg_inlbuf1 = &lcfg->lcfg_bulk[0] + offset;
235                 offset += size_round(lcfg->lcfg_inllen1);
236         }
237
238         if (lcfg->lcfg_inllen2) {
239                 lcfg->lcfg_inlbuf2 = &lcfg->lcfg_bulk[0] + offset;
240                 offset += size_round(lcfg->lcfg_inllen2);
241         }
242
243         if (lcfg->lcfg_inllen3) {
244                 lcfg->lcfg_inlbuf3 = &lcfg->lcfg_bulk[0] + offset;
245                 offset += size_round(lcfg->lcfg_inllen3);
246         }
247
248         if (lcfg->lcfg_inllen4) {
249                 lcfg->lcfg_inlbuf4 = &lcfg->lcfg_bulk[0] + offset;
250                 offset += size_round(lcfg->lcfg_inllen4);
251         }
252
253         if (lcfg->lcfg_inllen5) {
254                 lcfg->lcfg_inlbuf5 = &lcfg->lcfg_bulk[0] + offset;
255                 offset += size_round(lcfg->lcfg_inllen5);
256         }
257         
258         if (lcfg->lcfg_inllen6)
259                 lcfg->lcfg_inlbuf6 = &lcfg->lcfg_bulk[0] + offset;
260        
261         EXIT;
262         return 0;
263 }
264
265 static inline void lustre_cfg_freedata(char *buf, int len)
266 {
267         ENTRY;
268
269         OBD_FREE(buf, len);
270         EXIT;
271         return;
272 }
273
274 #define NOBODY_UID      99
275 #define NOBODY_GID      99
276
277 /* Passed by mount */
278 struct lustre_mount_data {
279         uint32_t lmd_magic;
280         uint32_t lmd_version;
281         uint64_t lmd_local_nid;
282         uint64_t lmd_server_nid;
283         uint32_t lmd_nal;
284         uint32_t lmd_server_ipaddr;
285         uint32_t lmd_port;
286         uint32_t lmd_async;
287         uint64_t lmd_remote_flag;
288         uint32_t lmd_nllu;
289         uint32_t lmd_nllg;
290         char     lmd_security[16];
291         char     lmd_mds[64];
292         char     lmd_profile[64];
293 };
294
295
296 #endif // _LUSTRE_CFG_H