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