Whamcloud - gitweb
current branches now use lnet from HEAD
[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 0x1cf60001
27 #define LUSTRE_CFG_MAX_BUFCOUNT 8
28
29 #define LCFG_HDR_SIZE(count) \
30     size_round(offsetof (struct lustre_cfg, lcfg_buflens[(count)]))
31
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,
50 };
51
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;
56 };
57
58 struct lustre_cfg {
59         uint32_t lcfg_version;
60         uint32_t lcfg_command;
61
62         uint32_t lcfg_num; 
63         uint32_t lcfg_flags;
64         uint64_t lcfg_nid;
65         uint32_t lcfg_nal;
66
67         uint32_t lcfg_bufcount;
68         uint32_t lcfg_buflens[0];
69 };
70
71 #define LUSTRE_CFG_BUFLEN(lcfg, idx)            \
72         ((lcfg)->lcfg_bufcount <= (idx)         \
73          ? 0                                    \
74          : (lcfg)->lcfg_buflens[(idx)])
75
76 static inline void lustre_cfg_bufs_set(struct lustre_cfg_bufs *bufs,
77                                        uint32_t                index,
78                                        void                   *buf,
79                                        uint32_t                buflen)
80 {
81         if (index >= LUSTRE_CFG_MAX_BUFCOUNT)
82                 return;
83         if (bufs == NULL)
84                 return;
85
86         if (bufs->lcfg_bufcount <= index)
87                 bufs->lcfg_bufcount = index + 1;
88
89         bufs->lcfg_buf[index]    = buf;
90         bufs->lcfg_buflen[index] = buflen;
91 }
92
93 static inline void lustre_cfg_bufs_set_string(struct lustre_cfg_bufs *bufs,
94                                               uint32_t index,
95                                               char *str)
96 {
97         lustre_cfg_bufs_set(bufs, index, str, str ? strlen(str) + 1 : 0);
98 }
99
100 static inline void lustre_cfg_bufs_reset(struct lustre_cfg_bufs *bufs, char *name)
101 {
102         memset((bufs), 0, sizeof(*bufs));
103         if (name)
104                 lustre_cfg_bufs_set_string(bufs, 0, name);
105 }
106
107 static inline void *lustre_cfg_buf(struct lustre_cfg *lcfg, int index)
108 {
109         int i;
110         int offset;
111         int bufcount;
112         LASSERT (lcfg != NULL);
113         LASSERT (index >= 0);
114
115         bufcount = lcfg->lcfg_bufcount;
116         if (index >= bufcount)
117                 return NULL;
118
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;
123 }
124
125 static inline void lustre_cfg_bufs_init(struct lustre_cfg_bufs *bufs,
126                                         struct lustre_cfg *lcfg)
127 {
128         int i;
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);
133         }
134 }
135
136 static inline char *lustre_cfg_string(struct lustre_cfg *lcfg, int index)
137 {
138         char *s;
139
140         if (!lcfg->lcfg_buflens[index])
141                 return NULL;
142
143         s = lustre_cfg_buf(lcfg, index);
144         if (!s)
145                 return NULL;
146
147         /* make sure it's NULL terminated, even if this kills a char
148          * of data
149          */
150         s[lcfg->lcfg_buflens[index] - 1] = '\0';
151         return s;
152 }
153
154 static inline int lustre_cfg_len(uint32_t bufcount, uint32_t *buflens)
155 {
156         int i;
157         int len;
158         ENTRY;
159
160         len = LCFG_HDR_SIZE(bufcount);
161         for (i = 0; i < bufcount; i++)
162                 len += size_round(buflens[i]);
163
164         RETURN(size_round(len));
165 }
166
167
168 #include <linux/obd_support.h>
169
170 static inline struct lustre_cfg *lustre_cfg_new(int cmd,
171                                                 struct lustre_cfg_bufs *bufs)
172 {
173         struct lustre_cfg *lcfg;
174         char *ptr;
175         int i;
176
177         ENTRY;
178
179         OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount,
180                                        bufs->lcfg_buflen));
181         if (!lcfg)
182                 RETURN(lcfg);
183
184         lcfg->lcfg_version = LUSTRE_CFG_VERSION;
185         lcfg->lcfg_command = cmd;
186         lcfg->lcfg_bufcount = bufs->lcfg_bufcount;
187
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);
192         }
193         RETURN(lcfg);
194 }
195
196 static inline void lustre_cfg_free(struct lustre_cfg *lcfg)
197 {
198         int len;
199
200         len = lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens);
201
202         OBD_FREE(lcfg, len);
203         EXIT;
204         return;
205 }
206
207 static inline int lustre_cfg_sanity_check(void *buf, int len)
208 {
209         struct lustre_cfg *lcfg = (struct lustre_cfg *)buf;
210         ENTRY;
211         if (!lcfg)
212                 RETURN(-EINVAL);
213
214         /* check that the first bits of the struct are valid */
215         if (len < LCFG_HDR_SIZE(0))
216                 RETURN(-EINVAL);
217
218         if (lcfg->lcfg_version != LUSTRE_CFG_VERSION)
219                 RETURN(-EINVAL);
220         if (lcfg->lcfg_bufcount >= LUSTRE_CFG_MAX_BUFCOUNT)
221                 RETURN(-EINVAL);
222
223         /* check that the buflens are valid */
224         if (len < LCFG_HDR_SIZE(lcfg->lcfg_bufcount))
225                 RETURN(-EINVAL);
226
227         /* make sure all the pointers point inside the data */
228         if (len < lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens))
229                 RETURN(-EINVAL);
230
231         RETURN(0);
232 }
233
234 #define NOBODY_UID      99
235 #define NOBODY_GID      99
236
237 /* Passed by mount */
238 struct lustre_mount_data {
239         uint32_t lmd_magic;
240         uint32_t lmd_version;
241         uint64_t lmd_local_nid;
242         uint64_t lmd_server_nid;
243         uint32_t lmd_nal;
244         uint32_t lmd_server_ipaddr;
245         uint32_t lmd_port;
246         uint32_t lmd_async;
247         uint64_t lmd_remote_flag;
248         uint32_t lmd_nllu;
249         uint32_t lmd_nllg;
250         uint32_t lmd_pag;
251         uint32_t lmd_padding;
252         char     lmd_mds_security[16];
253         char     lmd_oss_security[16];
254         char     lmd_mds[64];
255         char     lmd_profile[64];
256 };
257
258
259 #endif // _LUSTRE_CFG_H