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 0x1cf60001
27 #define LUSTRE_CFG_MAX_BUFCOUNT 8
29 #define LCFG_HDR_SIZE(count) \
30 size_round(offsetof (struct lustre_cfg, lcfg_buflens[(count)]))
32 enum lcfg_command_type {
33 LCFG_ATTACH = 0x00cf001,
34 LCFG_DETACH = 0x00cf002,
35 LCFG_SETUP = 0x00cf003,
36 LCFG_CLEANUP = 0x00cf004,
37 LCFG_ADD_UUID = 0x00cf005,
38 LCFG_DEL_UUID = 0x00cf006,
39 LCFG_MOUNTOPT = 0x00cf007,
40 LCFG_DEL_MOUNTOPT = 0x00cf008,
41 LCFG_SET_TIMEOUT = 0x00cf009,
42 LCFG_SET_UPCALL = 0x00cf00a,
43 LCFG_LOV_ADD_OBD = 0x00cf00b,
44 LCFG_LOV_DEL_OBD = 0x00cf00c,
45 LCFG_ADD_CONN = 0x00cf00d,
46 LCFG_DEL_CONN = 0x00cf00e,
47 LCFG_SET_SECURITY = 0x00cf00f,
50 struct lustre_cfg_bufs {
51 void *lcfg_buf[LUSTRE_CFG_MAX_BUFCOUNT];
52 uint32_t lcfg_buflen[LUSTRE_CFG_MAX_BUFCOUNT];
53 uint32_t lcfg_bufcount;
57 uint32_t lcfg_version;
58 uint32_t lcfg_command;
65 uint32_t lcfg_bufcount;
66 uint32_t lcfg_buflens[0];
69 #define LUSTRE_CFG_BUFLEN(lcfg, idx) \
70 ((lcfg)->lcfg_bufcount <= (idx) \
72 : (lcfg)->lcfg_buflens[(idx)])
74 static inline void lustre_cfg_bufs_set(struct lustre_cfg_bufs *bufs,
79 if (index >= LUSTRE_CFG_MAX_BUFCOUNT)
84 if (bufs->lcfg_bufcount <= index)
85 bufs->lcfg_bufcount = index + 1;
87 bufs->lcfg_buf[index] = buf;
88 bufs->lcfg_buflen[index] = buflen;
91 static inline void lustre_cfg_bufs_set_string(struct lustre_cfg_bufs *bufs,
95 lustre_cfg_bufs_set(bufs, index, str, str ? strlen(str) + 1 : 0);
98 static inline void lustre_cfg_bufs_reset(struct lustre_cfg_bufs *bufs, char *name)
100 memset((bufs), 0, sizeof(*bufs));
102 lustre_cfg_bufs_set_string(bufs, 0, name);
105 static inline void *lustre_cfg_buf(struct lustre_cfg *lcfg, int index)
110 LASSERT (lcfg != NULL);
111 LASSERT (index >= 0);
113 bufcount = lcfg->lcfg_bufcount;
114 if (index >= bufcount)
117 offset = LCFG_HDR_SIZE(lcfg->lcfg_bufcount);
118 for (i = 0; i < index; i++)
119 offset += size_round(lcfg->lcfg_buflens[i]);
120 return (char *)lcfg + offset;
123 static inline void lustre_cfg_bufs_init(struct lustre_cfg_bufs *bufs,
124 struct lustre_cfg *lcfg)
127 bufs->lcfg_bufcount = lcfg->lcfg_bufcount;
128 for (i = 0; i < bufs->lcfg_bufcount; i++) {
129 bufs->lcfg_buflen[i] = lcfg->lcfg_buflens[i];
130 bufs->lcfg_buf[i] = lustre_cfg_buf(lcfg, i);
134 static inline char *lustre_cfg_string(struct lustre_cfg *lcfg, int index)
138 if (!lcfg->lcfg_buflens[index])
141 s = lustre_cfg_buf(lcfg, index);
145 /* make sure it's NULL terminated, even if this kills a char
148 s[lcfg->lcfg_buflens[index] - 1] = '\0';
152 static inline int lustre_cfg_len(uint32_t bufcount, uint32_t *buflens)
158 len = LCFG_HDR_SIZE(bufcount);
159 for (i = 0; i < bufcount; i++)
160 len += size_round(buflens[i]);
162 RETURN(size_round(len));
166 #include <linux/obd_support.h>
168 static inline struct lustre_cfg *lustre_cfg_new(int cmd,
169 struct lustre_cfg_bufs *bufs)
171 struct lustre_cfg *lcfg;
177 OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount,
182 lcfg->lcfg_version = LUSTRE_CFG_VERSION;
183 lcfg->lcfg_command = cmd;
184 lcfg->lcfg_bufcount = bufs->lcfg_bufcount;
186 ptr = (char *)lcfg + LCFG_HDR_SIZE(lcfg->lcfg_bufcount);
187 for (i = 0; i < lcfg->lcfg_bufcount; i++) {
188 lcfg->lcfg_buflens[i] = bufs->lcfg_buflen[i];
189 LOGL((char *)bufs->lcfg_buf[i], bufs->lcfg_buflen[i], ptr);
194 static inline void lustre_cfg_free(struct lustre_cfg *lcfg)
198 len = lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens);
205 static inline int lustre_cfg_sanity_check(void *buf, int len)
207 struct lustre_cfg *lcfg = (struct lustre_cfg *)buf;
212 /* check that the first bits of the struct are valid */
213 if (len < LCFG_HDR_SIZE(0))
216 if (lcfg->lcfg_version != LUSTRE_CFG_VERSION)
218 if (lcfg->lcfg_bufcount >= LUSTRE_CFG_MAX_BUFCOUNT)
221 /* check that the buflens are valid */
222 if (len < LCFG_HDR_SIZE(lcfg->lcfg_bufcount))
225 /* make sure all the pointers point inside the data */
226 if (len < lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens))
232 #define NOBODY_UID 99
233 #define NOBODY_GID 99
235 /* Passed by mount */
236 struct lustre_mount_data {
238 uint32_t lmd_version;
239 uint64_t lmd_local_nid;
240 uint64_t lmd_server_nid;
242 uint32_t lmd_server_ipaddr;
245 uint64_t lmd_remote_flag;
248 char lmd_mds_security[16];
249 char lmd_oss_security[16];
251 char lmd_profile[64];
255 #endif // _LUSTRE_CFG_H