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