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