Whamcloud - gitweb
c426cfcce9c3b189a2b6a9f79d83e46cd3ee60ea
[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     = 0x00cf010,
39 };
40
41 struct lustre_cfg {
42         uint32_t lcfg_version;
43         uint32_t lcfg_command;
44
45         uint32_t lcfg_num; 
46         uint32_t lcfg_flags;
47         uint64_t lcfg_nid;
48         uint32_t lcfg_nal;
49
50         /* inline buffers for various arguments */
51         uint32_t lcfg_dev_namelen;
52         char    *lcfg_dev_name;
53         uint32_t lcfg_inllen1;
54         char    *lcfg_inlbuf1;
55         uint32_t lcfg_inllen2;
56         char    *lcfg_inlbuf2;
57         uint32_t lcfg_inllen3;
58         char    *lcfg_inlbuf3;
59         uint32_t lcfg_inllen4;
60         char    *lcfg_inlbuf4;
61         uint32_t lcfg_inllen5;
62         char    *lcfg_inlbuf5;
63         uint32_t lcfg_inllen6;
64         char    *lcfg_inlbuf6;
65
66
67         char    lcfg_bulk[0];
68 };
69
70 #define LCFG_INIT(l, cmd, name)                                 \
71 do {                                                            \
72         memset(&(l), 0, sizeof(l));                             \
73         (l).lcfg_version = LUSTRE_CFG_VERSION;                  \
74         (l).lcfg_command = (cmd);                               \
75         if (name) {                                             \
76                 (l).lcfg_dev_namelen = strlen(name) + 1;        \
77                 (l).lcfg_dev_name = name;                       \
78         }                                                       \
79                                                                 \
80 } while (0)
81
82 #ifndef __KERNEL__
83 static inline int lustre_cfg_packlen(struct lustre_cfg *lcfg)
84 {
85         int len = size_round(sizeof(struct lustre_cfg));
86         len += size_round(lcfg->lcfg_dev_namelen);
87         len += size_round(lcfg->lcfg_inllen1);
88         len += size_round(lcfg->lcfg_inllen2);
89         len += size_round(lcfg->lcfg_inllen3);
90         len += size_round(lcfg->lcfg_inllen4);
91         len += size_round(lcfg->lcfg_inllen5);
92         len += size_round(lcfg->lcfg_inllen6);
93         return size_round(len);
94 }
95
96 static inline int lustre_cfg_pack(struct lustre_cfg *data, char **pbuf,
97                                  int max, int *plen)
98 {
99         char *ptr;
100         struct lustre_cfg *overlay;
101         int len;
102
103         len = lustre_cfg_packlen(data);
104
105         data->lcfg_version = LUSTRE_CFG_VERSION;
106
107         if (*pbuf && len > max)
108                 return 1;
109         if (*pbuf == NULL) {
110                 *pbuf = malloc(len);
111         }
112         if (!*pbuf)
113                 return 1;
114         overlay = (struct lustre_cfg *)*pbuf;
115         memcpy(*pbuf, data, sizeof(*data));
116
117         ptr = overlay->lcfg_bulk;
118         if (data->lcfg_dev_name)
119                 LOGL(data->lcfg_dev_name, data->lcfg_dev_namelen, ptr);
120         if (data->lcfg_inlbuf1)
121                 LOGL(data->lcfg_inlbuf1, data->lcfg_inllen1, ptr);
122         if (data->lcfg_inlbuf2)
123                 LOGL(data->lcfg_inlbuf2, data->lcfg_inllen2, ptr);
124         if (data->lcfg_inlbuf3)
125                 LOGL(data->lcfg_inlbuf3, data->lcfg_inllen3, ptr);
126         if (data->lcfg_inlbuf4)
127                 LOGL(data->lcfg_inlbuf4, data->lcfg_inllen4, ptr);
128         if (data->lcfg_inlbuf5)
129                 LOGL(data->lcfg_inlbuf5, data->lcfg_inllen5, ptr);
130         if (data->lcfg_inlbuf6)
131                 LOGL(data->lcfg_inlbuf6, data->lcfg_inllen6, ptr);
132
133         *plen = len;
134
135         return 0;
136 }
137
138 static inline int lustre_cfg_unpack(struct lustre_cfg *data, char *pbuf,
139                                    int max)
140 {
141         char *ptr;
142         struct lustre_cfg *overlay;
143
144         if (!pbuf)
145                 return 1;
146         overlay = (struct lustre_cfg *)pbuf;
147
148         /* Preserve the caller's buffer pointers */
149         overlay->lcfg_dev_name = data->lcfg_dev_name;
150         overlay->lcfg_inlbuf1 = data->lcfg_inlbuf1;
151         overlay->lcfg_inlbuf2 = data->lcfg_inlbuf2;
152         overlay->lcfg_inlbuf3 = data->lcfg_inlbuf3;
153         overlay->lcfg_inlbuf4 = data->lcfg_inlbuf4;
154         overlay->lcfg_inlbuf5 = data->lcfg_inlbuf5;
155         overlay->lcfg_inlbuf6 = data->lcfg_inlbuf6;
156
157         memcpy(data, pbuf, sizeof(*data));
158
159         ptr = overlay->lcfg_bulk;
160         if (data->lcfg_dev_name)
161                 LOGU(data->lcfg_dev_name, data->lcfg_dev_namelen, ptr);
162         if (data->lcfg_inlbuf1)
163                 LOGU(data->lcfg_inlbuf1, data->lcfg_inllen1, ptr);
164         if (data->lcfg_inlbuf2)
165                 LOGU(data->lcfg_inlbuf2, data->lcfg_inllen2, ptr);
166         if (data->lcfg_inlbuf3)
167                 LOGU(data->lcfg_inlbuf3, data->lcfg_inllen3, ptr);
168         if (data->lcfg_inlbuf4)
169                 LOGU(data->lcfg_inlbuf4, data->lcfg_inllen4, ptr);
170         if (data->lcfg_inlbuf5)
171                 LOGU(data->lcfg_inlbuf5, data->lcfg_inllen5, ptr);
172         if (data->lcfg_inlbuf6)
173                 LOGU(data->lcfg_inlbuf6, data->lcfg_inllen6, ptr);
174
175         return 0;
176 }
177 #endif
178
179 #include <linux/obd_support.h>
180
181 static inline int lustre_cfg_getdata(char **buf, int len, void *arg, int kernel)
182 {
183         struct lustre_cfg *lcfg;
184         int err;
185         int offset = 0;
186         ENTRY;
187         if (len > OBD_MAX_IOCTL_BUFFER) {
188                 CERROR("User buffer len %d exceeds %d max buffer\n",
189                        len, OBD_MAX_IOCTL_BUFFER);
190                 return -EINVAL;
191         }
192
193         if (len < sizeof(struct lustre_cfg)) {
194                 CERROR("OBD: user buffer too small for lustre_cfg\n");
195                 return -EINVAL;
196         }
197
198         /* XXX allocate this more intelligently, using kmalloc when
199          * appropriate */
200         OBD_ALLOC(*buf, len);
201         if (*buf == NULL) {
202                 CERROR("Cannot allocate control buffer of len %d\n", len);
203                 RETURN(-EINVAL);
204         }
205
206         if (kernel) {
207                 memcpy(*buf, (void *)arg, len);
208         } else {
209                 err = copy_from_user(*buf, (void *)arg, len);
210                 if (err) 
211                         RETURN(err);
212         }
213
214         lcfg = (struct lustre_cfg *)*buf;
215
216         if (lcfg->lcfg_version != LUSTRE_CFG_VERSION) {
217                 CERROR("Version mismatch kernel: %#x application: %#x\n",
218                        LUSTRE_CFG_VERSION, lcfg->lcfg_version);
219                 return -EINVAL;
220         }
221
222
223         if (lcfg->lcfg_dev_name) {
224                 lcfg->lcfg_dev_name = &lcfg->lcfg_bulk[0];
225                 offset += size_round(lcfg->lcfg_dev_namelen);
226         }
227
228         if (lcfg->lcfg_inllen1) {
229                 lcfg->lcfg_inlbuf1 = &lcfg->lcfg_bulk[0] + offset;
230                 offset += size_round(lcfg->lcfg_inllen1);
231         }
232
233         if (lcfg->lcfg_inllen2) {
234                 lcfg->lcfg_inlbuf2 = &lcfg->lcfg_bulk[0] + offset;
235                 offset += size_round(lcfg->lcfg_inllen2);
236         }
237
238         if (lcfg->lcfg_inllen3) {
239                 lcfg->lcfg_inlbuf3 = &lcfg->lcfg_bulk[0] + offset;
240                 offset += size_round(lcfg->lcfg_inllen3);
241         }
242
243         if (lcfg->lcfg_inllen4) {
244                 lcfg->lcfg_inlbuf4 = &lcfg->lcfg_bulk[0] + offset;
245                 offset += size_round(lcfg->lcfg_inllen4);
246         }
247
248         if (lcfg->lcfg_inllen5) {
249                 lcfg->lcfg_inlbuf5 = &lcfg->lcfg_bulk[0] + offset;
250                 offset += size_round(lcfg->lcfg_inllen5);
251         }
252         
253         if (lcfg->lcfg_inllen6)
254                 lcfg->lcfg_inlbuf6 = &lcfg->lcfg_bulk[0] + offset;
255        
256         EXIT;
257         return 0;
258 }
259
260 static inline void lustre_cfg_freedata(char *buf, int len)
261 {
262         ENTRY;
263
264         OBD_FREE(buf, len);
265         EXIT;
266         return;
267 }
268
269 /* Passed by mount */
270 struct lustre_mount_data {
271         uint32_t lmd_magic;
272         uint32_t lmd_version;
273         uint64_t lmd_local_nid;
274         uint64_t lmd_server_nid;
275         uint32_t lmd_nal;
276         uint32_t lmd_server_ipaddr;
277         uint32_t lmd_port;
278         char     lmd_mds[64];
279         char     lmd_profile[64];
280 };
281
282
283 #endif // _LUSTRE_CFG_H