Whamcloud - gitweb
LU-15496 tests: fix sanity/398c to use proper OSC name
[fs/lustre-release.git] / lustre / include / lustre / libiam.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  */
26 /*
27  * This file is part of Lustre, http://www.lustre.org/
28  *
29  * lustre/include/lustre/libiam.h
30  *
31  * iam user level library
32  *
33  * Author: Wang Di <wangdi@clusterfs.com>
34  * Author: Nikita Danilov <nikita@clusterfs.com>
35  * Author: Fan Yong <fanyong@clusterfs.com>
36  */
37
38 /* lustre/libiam.h */
39 #ifndef __IAM_ULIB_H__
40 #define __IAM_ULIB_H__
41
42 #define DX_FMT_NAME_LEN 16
43
44 #define IAM_LFIX_ROOT_MAGIC  0xbedabb1edULL
45 #define IAM_LVAR_ROOT_MAGIC  0xb01dfaceULL
46
47 enum {
48         IAM_LEAF_HEADER_MAGIC = 0x1976,
49         IAM_LVAR_LEAF_MAGIC   = 0x1973,
50         IAM_IDLE_HEADER_MAGIC = 0x7903
51 };
52
53 enum iam_fmt_t {
54         FMT_LFIX = 0,
55         FMT_LVAR = 1,
56 };
57
58 struct dx_countlimit {
59         u_int16_t limit;
60         u_int16_t count;
61 } __attribute__((packed));
62
63 struct iam_lfix_root {
64         u_int64_t  ilr_magic;
65         u_int16_t  ilr_keysize;
66         u_int16_t  ilr_recsize;
67         u_int16_t  ilr_ptrsize;
68         u_int8_t   ilr_indirect_levels;
69         u_int8_t   ilr_padding;
70         struct dx_countlimit limit;
71         u_int32_t idle_blocks;
72         u_int8_t  ilr_paddingdd2[12];
73         unsigned char entries[0];
74 } __attribute__((packed));
75
76 struct iam_leaf_head {
77         u_int16_t ill_magic;
78         u_int16_t ill_count;
79 } __attribute__((packed));
80
81 struct lvar_leaf_header {
82         u_int16_t vlh_magic; /* magic number IAM_LVAR_LEAF_MAGIC */
83         u_int16_t vlh_used;  /* used bytes, including header */
84 } __attribute__((packed));
85
86 /*
87  * Header structure to record idle blocks.
88  */
89 struct iam_idle_head {
90         __le16 iih_magic;
91         __le16 iih_count; /* how many idle blocks in this head */
92         __le32 iih_next; /* next head for idle blocks */
93         __le32 iih_blks[0];
94 } __attribute__((packed));
95
96 struct iam_index_head {
97         struct dx_countlimit limit;
98         u_int8_t  paddingdd[16];
99         unsigned char entries[0];
100 } __attribute__((packed));
101
102 struct lvar_root {
103         u_int32_t vr_magic;
104         u_int16_t vr_recsize;
105         u_int16_t vr_ptrsize;
106         u_int8_t  vr_indirect_levels;
107         u_int8_t  vr_padding0;
108         u_int16_t vr_padding1;
109 } __attribute__((packed));
110
111
112 struct lvar_leaf_entry {
113         u_int32_t vle_hash;
114         u_int16_t vle_keysize;
115         u_int8_t  vle_key[0];
116 } __attribute__((packed));
117
118 struct osd_inode_id {
119         __u32 oii_ino;
120         __u32 oii_gen;
121 } __attribute__ ((packed));
122
123
124 enum {
125         LVAR_PAD   = 4,
126         LVAR_ROUND = LVAR_PAD - 1
127 };
128
129 static inline unsigned int node_limit(unsigned int node_gap,
130                                       unsigned int block_size,
131                                       unsigned int size)
132 {
133         return (block_size - node_gap) / size;
134 }
135
136 static inline unsigned int root_limit(unsigned int root_gap,
137                                       unsigned int node_gap,
138                                       unsigned int block_size,
139                                       unsigned int size)
140 {
141         unsigned int limit;
142
143         limit = (block_size - root_gap) / size;
144         if (limit == node_limit(node_gap, block_size, size))
145                 limit--;
146         return limit;
147 }
148
149 struct iam_uapi_info {
150         __u16 iui_keysize;
151         __u16 iui_recsize;
152         __u16 iui_ptrsize;
153         __u16 iui_height;
154         char  iui_fmt_name[DX_FMT_NAME_LEN];
155 };
156
157 /*
158  * Creat an iam file, but do NOT open it.
159  * Return 0 if success, else -1.
160  */
161 int iam_creat(char *filename, enum iam_fmt_t fmt,
162               int blocksize, int keysize, int recsize, int ptrsize);
163
164 /*
165  * Open an iam file, but do NOT creat it if the file doesn't exist.
166  * Please use iam_creat for creating the file before use iam_open.
167  * Return file id (fd) if success, else -1.
168  */
169 int iam_open(char *filename, struct iam_uapi_info *ua);
170
171 /*
172  * Close file opened by iam_open.
173  */
174 int iam_close(int fd);
175
176 /*
177  * Please use iam_open before use this function.
178  */
179 int iam_insert(int fd, struct iam_uapi_info *ua, int key_need_convert,
180                char *keybuf, int rec_need_convert, char *recbuf);
181
182 /*
183  * Please use iam_open before use this function.
184  */
185 int iam_lookup(int fd, struct iam_uapi_info *ua,
186                int key_need_convert, char *key_buf, int *keysize,
187                char *save_key, int rec_need_convert, char *rec_buf,
188                int *recsize, char *save_rec);
189
190 /*
191  * Please use iam_open before use this function.
192  */
193 int iam_delete(int fd, struct iam_uapi_info *ua, int key_need_convert,
194                char *keybuf, int rec_need_convert, char *recbuf);
195
196 /*
197  * Please use iam_open before use this function.
198  */
199 int iam_it_start(int fd, struct iam_uapi_info *ua, int key_need_convert,
200                  char *key_buf, int *keysize, char *save_key,
201                  int rec_need_convert, char *rec_buf, int *recsize,
202                  char *save_rec);
203
204 /*
205  * Please use iam_open before use this function.
206  */
207 int iam_it_next(int fd, struct iam_uapi_info *ua, int key_need_convert,
208                 char *key_buf, int *keysize, char *save_key,
209                 int rec_need_convert, char *rec_buf, int *recsize,
210                 char *save_rec);
211
212 /*
213  * Please use iam_open before use this function.
214  */
215 int iam_it_stop(int fd, struct iam_uapi_info *ua, int key_need_convert,
216                 char *keybuf, int rec_need_convert, char *recbuf);
217
218 /*
219  * Change iam file mode.
220  */
221 int iam_polymorph(char *filename, unsigned long mode);
222
223 #endif