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