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.
30 #define LUSTRE_CFG_VERSION 0x1cf60001
31 #define LUSTRE_CFG_MAX_BUFCOUNT 8
33 #define LCFG_HDR_SIZE(count) \
34 size_round(offsetof (struct lustre_cfg, lcfg_buflens[(count)]))
36 /* If not LCFG_REQUIRED, we can ignore this cmd and go on. */
37 #define LCFG_REQUIRED 0x0001000
39 enum lcfg_command_type {
40 LCFG_ATTACH = 0x00cf001,
41 LCFG_DETACH = 0x00cf002,
42 LCFG_SETUP = 0x00cf003,
43 LCFG_CLEANUP = 0x00cf004,
44 LCFG_ADD_UUID = 0x00cf005,
45 LCFG_DEL_UUID = 0x00cf006,
46 LCFG_MOUNTOPT = 0x00cf007,
47 LCFG_DEL_MOUNTOPT = 0x00cf008,
48 LCFG_SET_TIMEOUT = 0x00cf009,
49 LCFG_SET_UPCALL = 0x00cf00a,
50 LCFG_ADD_CONN = 0x00cf00b,
51 LCFG_DEL_CONN = 0x00cf00c,
52 LCFG_LOV_ADD_OBD = 0x00cf00d,
53 LCFG_LOV_DEL_OBD = 0x00cf00e,
54 LCFG_PARAM = 0x00ce00f,
55 LCFG_MARKER = 0x00ce010,
56 LCFG_LOG_START = 0x00ce011,
57 LCFG_LOG_END = 0x00ce012,
58 LCFG_LOV_ADD_INA = 0x00ce013,
59 LCFG_ADD_MDC = 0x00cf014,
60 LCFG_DEL_MDC = 0x00cf015,
63 struct lustre_cfg_bufs {
64 void *lcfg_buf[LUSTRE_CFG_MAX_BUFCOUNT];
65 uint32_t lcfg_buflen[LUSTRE_CFG_MAX_BUFCOUNT];
66 uint32_t lcfg_bufcount;
69 /* Mountconf transitional hack, should go away after 1.6 */
70 #define LCFG_FLG_MOUNTCONF 0x400
73 uint32_t lcfg_version;
74 uint32_t lcfg_command;
79 uint32_t lcfg_nal; /* not used any more */
81 uint32_t lcfg_bufcount;
82 uint32_t lcfg_buflens[0];
85 #define LUSTRE_CFG_BUFLEN(lcfg, idx) \
86 ((lcfg)->lcfg_bufcount <= (idx) \
88 : (lcfg)->lcfg_buflens[(idx)])
90 static inline void lustre_cfg_bufs_set(struct lustre_cfg_bufs *bufs,
95 if (index >= LUSTRE_CFG_MAX_BUFCOUNT)
100 if (bufs->lcfg_bufcount <= index)
101 bufs->lcfg_bufcount = index + 1;
103 bufs->lcfg_buf[index] = buf;
104 bufs->lcfg_buflen[index] = buflen;
107 static inline void lustre_cfg_bufs_set_string(struct lustre_cfg_bufs *bufs,
111 lustre_cfg_bufs_set(bufs, index, str, str ? strlen(str) + 1 : 0);
114 static inline void lustre_cfg_bufs_reset(struct lustre_cfg_bufs *bufs, char *name)
116 memset((bufs), 0, sizeof(*bufs));
118 lustre_cfg_bufs_set_string(bufs, 0, name);
121 static inline void *lustre_cfg_buf(struct lustre_cfg *lcfg, int index)
126 LASSERT (lcfg != NULL);
127 LASSERT (index >= 0);
129 bufcount = lcfg->lcfg_bufcount;
130 if (index >= bufcount)
133 offset = LCFG_HDR_SIZE(lcfg->lcfg_bufcount);
134 for (i = 0; i < index; i++)
135 offset += size_round(lcfg->lcfg_buflens[i]);
136 return (char *)lcfg + offset;
139 static inline void lustre_cfg_bufs_init(struct lustre_cfg_bufs *bufs,
140 struct lustre_cfg *lcfg)
143 bufs->lcfg_bufcount = lcfg->lcfg_bufcount;
144 for (i = 0; i < bufs->lcfg_bufcount; i++) {
145 bufs->lcfg_buflen[i] = lcfg->lcfg_buflens[i];
146 bufs->lcfg_buf[i] = lustre_cfg_buf(lcfg, i);
150 static inline char *lustre_cfg_string(struct lustre_cfg *lcfg, int index)
154 if (!lcfg->lcfg_buflens[index])
157 s = lustre_cfg_buf(lcfg, index);
161 /* make sure it's NULL terminated, even if this kills a char
162 * of data. Try to use the padding first though.
164 if (s[lcfg->lcfg_buflens[index] - 1] != '\0') {
165 int last = min((int)lcfg->lcfg_buflens[index],
166 size_round(lcfg->lcfg_buflens[index]) - 1);
168 CWARN("Truncating buf %d to '%s'\n", index, s);
173 static inline int lustre_cfg_len(uint32_t bufcount, uint32_t *buflens)
179 len = LCFG_HDR_SIZE(bufcount);
180 for (i = 0; i < bufcount; i++)
181 len += size_round(buflens[i]);
183 RETURN(size_round(len));
187 #include <linux/obd_support.h>
189 static inline struct lustre_cfg *lustre_cfg_new(int cmd,
190 struct lustre_cfg_bufs *bufs)
192 struct lustre_cfg *lcfg;
198 OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount,
203 lcfg->lcfg_version = LUSTRE_CFG_VERSION;
204 lcfg->lcfg_command = cmd;
205 lcfg->lcfg_bufcount = bufs->lcfg_bufcount;
207 ptr = (char *)lcfg + LCFG_HDR_SIZE(lcfg->lcfg_bufcount);
208 for (i = 0; i < lcfg->lcfg_bufcount; i++) {
209 lcfg->lcfg_buflens[i] = bufs->lcfg_buflen[i];
210 LOGL((char *)bufs->lcfg_buf[i], bufs->lcfg_buflen[i], ptr);
215 static inline void lustre_cfg_free(struct lustre_cfg *lcfg)
219 len = lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens);
226 static inline int lustre_cfg_sanity_check(void *buf, int len)
228 struct lustre_cfg *lcfg = (struct lustre_cfg *)buf;
233 /* check that the first bits of the struct are valid */
234 if (len < LCFG_HDR_SIZE(0))
237 if (lcfg->lcfg_version != LUSTRE_CFG_VERSION)
240 if (lcfg->lcfg_bufcount >= LUSTRE_CFG_MAX_BUFCOUNT)
243 /* check that the buflens are valid */
244 if (len < LCFG_HDR_SIZE(lcfg->lcfg_bufcount))
247 /* make sure all the pointers point inside the data */
248 if (len < lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens))
254 #endif // _LUSTRE_CFG_H