1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
26 #define LUSTRE_CFG_VERSION 0x00010001
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,
44 uint32_t lcfg_version;
45 uint32_t lcfg_command;
52 /* inline buffers for various arguments */
53 uint32_t lcfg_dev_namelen;
55 uint32_t lcfg_inllen1;
57 uint32_t lcfg_inllen2;
59 uint32_t lcfg_inllen3;
61 uint32_t lcfg_inllen4;
63 uint32_t lcfg_inllen5;
65 uint32_t lcfg_inllen6;
72 #define LCFG_INIT(l, cmd, name) \
74 memset(&(l), 0, sizeof(l)); \
75 (l).lcfg_version = LUSTRE_CFG_VERSION; \
76 (l).lcfg_command = (cmd); \
78 (l).lcfg_dev_namelen = strlen(name) + 1; \
79 (l).lcfg_dev_name = name; \
85 static inline int lustre_cfg_packlen(struct lustre_cfg *lcfg)
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);
98 static inline int lustre_cfg_pack(struct lustre_cfg *data, char **pbuf,
102 struct lustre_cfg *overlay;
105 len = lustre_cfg_packlen(data);
107 data->lcfg_version = LUSTRE_CFG_VERSION;
109 if (*pbuf && len > max)
116 overlay = (struct lustre_cfg *)*pbuf;
117 memcpy(*pbuf, data, sizeof(*data));
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);
140 static inline int lustre_cfg_unpack(struct lustre_cfg *data, char *pbuf,
144 struct lustre_cfg *overlay;
148 overlay = (struct lustre_cfg *)pbuf;
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;
159 memcpy(data, pbuf, sizeof(*data));
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);
181 #include <linux/obd_support.h>
183 static inline int lustre_cfg_getdata(char **buf, int len, void *arg, int kernel)
185 struct lustre_cfg *lcfg;
189 if (len > OBD_MAX_IOCTL_BUFFER) {
190 CERROR("User buffer len %d exceeds %d max buffer\n",
191 len, OBD_MAX_IOCTL_BUFFER);
195 if (len < sizeof(struct lustre_cfg)) {
196 CERROR("OBD: user buffer too small for lustre_cfg\n");
200 /* XXX allocate this more intelligently, using kmalloc when
202 OBD_ALLOC(*buf, len);
204 CERROR("Cannot allocate control buffer of len %d\n", len);
209 memcpy(*buf, (void *)arg, len);
211 err = copy_from_user(*buf, (void *)arg, len);
216 lcfg = (struct lustre_cfg *)*buf;
218 if (lcfg->lcfg_version != LUSTRE_CFG_VERSION) {
219 CERROR("Version mismatch kernel: %#x application: %#x\n",
220 LUSTRE_CFG_VERSION, lcfg->lcfg_version);
225 if (lcfg->lcfg_dev_name) {
226 lcfg->lcfg_dev_name = &lcfg->lcfg_bulk[0];
227 offset += size_round(lcfg->lcfg_dev_namelen);
230 if (lcfg->lcfg_inllen1) {
231 lcfg->lcfg_inlbuf1 = &lcfg->lcfg_bulk[0] + offset;
232 offset += size_round(lcfg->lcfg_inllen1);
235 if (lcfg->lcfg_inllen2) {
236 lcfg->lcfg_inlbuf2 = &lcfg->lcfg_bulk[0] + offset;
237 offset += size_round(lcfg->lcfg_inllen2);
240 if (lcfg->lcfg_inllen3) {
241 lcfg->lcfg_inlbuf3 = &lcfg->lcfg_bulk[0] + offset;
242 offset += size_round(lcfg->lcfg_inllen3);
245 if (lcfg->lcfg_inllen4) {
246 lcfg->lcfg_inlbuf4 = &lcfg->lcfg_bulk[0] + offset;
247 offset += size_round(lcfg->lcfg_inllen4);
250 if (lcfg->lcfg_inllen5) {
251 lcfg->lcfg_inlbuf5 = &lcfg->lcfg_bulk[0] + offset;
252 offset += size_round(lcfg->lcfg_inllen5);
255 if (lcfg->lcfg_inllen6)
256 lcfg->lcfg_inlbuf6 = &lcfg->lcfg_bulk[0] + offset;
262 static inline void lustre_cfg_freedata(char *buf, int len)
271 /* Passed by mount */
272 struct lustre_mount_data {
274 uint32_t lmd_version;
275 uint64_t lmd_local_nid;
276 uint64_t lmd_server_nid;
278 uint32_t lmd_server_ipaddr;
281 char lmd_profile[64];
285 #endif // _LUSTRE_CFG_H