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,
48 LCFG_SET_AUDIT = 0x00cf010,
49 LCFG_LMV_ADD_MDC = 0x00cf011,
52 struct lustre_cfg_bufs {
53 void *lcfg_buf[LUSTRE_CFG_MAX_BUFCOUNT];
54 uint32_t lcfg_buflen[LUSTRE_CFG_MAX_BUFCOUNT];
55 uint32_t lcfg_bufcount;
59 uint32_t lcfg_version;
60 uint32_t lcfg_command;
67 uint32_t lcfg_bufcount;
68 uint32_t lcfg_buflens[0];
71 #define LUSTRE_CFG_BUFLEN(lcfg, idx) \
72 ((lcfg)->lcfg_bufcount <= (idx) \
74 : (lcfg)->lcfg_buflens[(idx)])
76 static inline void lustre_cfg_bufs_set(struct lustre_cfg_bufs *bufs,
81 if (index >= LUSTRE_CFG_MAX_BUFCOUNT)
86 if (bufs->lcfg_bufcount <= index)
87 bufs->lcfg_bufcount = index + 1;
89 bufs->lcfg_buf[index] = buf;
90 bufs->lcfg_buflen[index] = buflen;
93 static inline void lustre_cfg_bufs_set_string(struct lustre_cfg_bufs *bufs,
97 lustre_cfg_bufs_set(bufs, index, str, str ? strlen(str) + 1 : 0);
100 static inline void lustre_cfg_bufs_reset(struct lustre_cfg_bufs *bufs, char *name)
102 memset((bufs), 0, sizeof(*bufs));
104 lustre_cfg_bufs_set_string(bufs, 0, name);
107 static inline void *lustre_cfg_buf(struct lustre_cfg *lcfg, int index)
112 LASSERT (lcfg != NULL);
113 LASSERT (index >= 0);
115 bufcount = lcfg->lcfg_bufcount;
116 if (index >= bufcount)
119 offset = LCFG_HDR_SIZE(lcfg->lcfg_bufcount);
120 for (i = 0; i < index; i++)
121 offset += size_round(lcfg->lcfg_buflens[i]);
122 return (char *)lcfg + offset;
125 static inline void lustre_cfg_bufs_init(struct lustre_cfg_bufs *bufs,
126 struct lustre_cfg *lcfg)
129 bufs->lcfg_bufcount = lcfg->lcfg_bufcount;
130 for (i = 0; i < bufs->lcfg_bufcount; i++) {
131 bufs->lcfg_buflen[i] = lcfg->lcfg_buflens[i];
132 bufs->lcfg_buf[i] = lustre_cfg_buf(lcfg, i);
136 static inline char *lustre_cfg_string(struct lustre_cfg *lcfg, int index)
140 if (!lcfg->lcfg_buflens[index])
143 s = lustre_cfg_buf(lcfg, index);
147 /* make sure it's NULL terminated, even if this kills a char
150 s[lcfg->lcfg_buflens[index] - 1] = '\0';
154 static inline int lustre_cfg_len(uint32_t bufcount, uint32_t *buflens)
160 len = LCFG_HDR_SIZE(bufcount);
161 for (i = 0; i < bufcount; i++)
162 len += size_round(buflens[i]);
164 RETURN(size_round(len));
168 #include <linux/obd_support.h>
170 static inline struct lustre_cfg *lustre_cfg_new(int cmd,
171 struct lustre_cfg_bufs *bufs)
173 struct lustre_cfg *lcfg;
179 OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount,
184 lcfg->lcfg_version = LUSTRE_CFG_VERSION;
185 lcfg->lcfg_command = cmd;
186 lcfg->lcfg_bufcount = bufs->lcfg_bufcount;
188 ptr = (char *)lcfg + LCFG_HDR_SIZE(lcfg->lcfg_bufcount);
189 for (i = 0; i < lcfg->lcfg_bufcount; i++) {
190 lcfg->lcfg_buflens[i] = bufs->lcfg_buflen[i];
191 LOGL((char *)bufs->lcfg_buf[i], bufs->lcfg_buflen[i], ptr);
196 static inline void lustre_cfg_free(struct lustre_cfg *lcfg)
200 len = lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens);
207 static inline int lustre_cfg_sanity_check(void *buf, int len)
209 struct lustre_cfg *lcfg = (struct lustre_cfg *)buf;
214 /* check that the first bits of the struct are valid */
215 if (len < LCFG_HDR_SIZE(0))
218 if (lcfg->lcfg_version != LUSTRE_CFG_VERSION)
220 if (lcfg->lcfg_bufcount >= LUSTRE_CFG_MAX_BUFCOUNT)
223 /* check that the buflens are valid */
224 if (len < LCFG_HDR_SIZE(lcfg->lcfg_bufcount))
227 /* make sure all the pointers point inside the data */
228 if (len < lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens))
234 #define NOBODY_UID 99
235 #define NOBODY_GID 99
237 /* Passed by mount */
238 struct lustre_mount_data {
240 uint32_t lmd_version;
241 uint64_t lmd_local_nid;
242 uint64_t lmd_server_nid;
244 uint32_t lmd_server_ipaddr;
247 uint64_t lmd_remote_flag;
251 uint32_t lmd_padding;
252 char lmd_mds_security[16];
253 char lmd_oss_security[16];
255 char lmd_profile[64];
259 #endif // _LUSTRE_CFG_H