Whamcloud - gitweb
LU-19098 hsm: don't print progname twice with lhsmtool
[fs/lustre-release.git] / lustre / include / lustre / libiam.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2
3 /*
4  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
5  * Use is subject to license terms.
6  */
7
8 /*
9  * This file is part of Lustre, http://www.lustre.org/
10  *
11  * iam user level library
12  *
13  * Author: Wang Di <wangdi@clusterfs.com>
14  * Author: Nikita Danilov <nikita@clusterfs.com>
15  * Author: Fan Yong <fanyong@clusterfs.com>
16  */
17
18 /* lustre/libiam.h */
19 #ifndef __IAM_ULIB_H__
20 #define __IAM_ULIB_H__
21
22 #define DX_FMT_NAME_LEN 16
23
24 #define IAM_LFIX_ROOT_MAGIC  0xbedabb1edULL
25 #define IAM_LVAR_ROOT_MAGIC  0xb01dfaceULL
26
27 enum {
28         IAM_LEAF_HEADER_MAGIC = 0x1976,
29         IAM_LVAR_LEAF_MAGIC   = 0x1973,
30         IAM_IDLE_HEADER_MAGIC = 0x7903
31 };
32
33 enum iam_fmt_t {
34         FMT_LFIX = 0,
35         FMT_LVAR = 1,
36 };
37
38 struct dx_countlimit {
39         u_int16_t limit;
40         u_int16_t count;
41 } __attribute__((packed));
42
43 struct iam_lfix_root {
44         __le64  ilr_magic;
45         __le16  ilr_keysize;
46         __le16  ilr_recsize;
47         __le16  ilr_ptrsize;
48         __u8    ilr_indirect_levels;
49         __u8    ilr_padding;
50 };
51
52 struct iam_leaf_head {
53         u_int16_t ill_magic;
54         u_int16_t ill_count;
55 } __attribute__((packed));
56
57 struct lvar_leaf_header {
58         u_int16_t vlh_magic; /* magic number IAM_LVAR_LEAF_MAGIC */
59         u_int16_t vlh_used;  /* used bytes, including header */
60 } __attribute__((packed));
61
62 /*
63  * Header structure to record idle blocks.
64  */
65 struct iam_idle_head {
66         __le16 iih_magic;
67         __le16 iih_count; /* how many idle blocks in this head */
68         __le32 iih_next; /* next head for idle blocks */
69         __le32 iih_blks[];
70 } __attribute__((packed));
71
72 struct iam_index_head {
73         struct dx_countlimit limit;
74         u_int8_t  paddingdd[16];
75         unsigned char entries[];
76 } __attribute__((packed));
77
78 typedef __u32 lvar_hash_t;
79
80 struct lvar_root {
81         u_int32_t vr_magic;
82         u_int16_t vr_recsize;
83         u_int16_t vr_ptrsize;
84         u_int8_t  vr_indirect_levels;
85         u_int8_t  vr_padding0;
86         u_int16_t vr_padding1;
87 } __attribute__((packed));
88
89
90 struct lvar_leaf_entry {
91         u_int32_t vle_hash;
92         u_int16_t vle_keysize;
93         u_int8_t  vle_key[];
94 } __attribute__((packed));
95
96 struct osd_inode_id {
97         __u32 oii_ino;
98         __u32 oii_gen;
99 } __attribute__ ((packed));
100
101
102 enum {
103         LVAR_PAD   = 4,
104         LVAR_ROUND = LVAR_PAD - 1
105 };
106
107 static inline unsigned int node_limit(unsigned int node_gap,
108                                       unsigned int block_size,
109                                       unsigned int size)
110 {
111         return (block_size - node_gap) / size;
112 }
113
114 static inline unsigned int root_limit(unsigned int root_gap,
115                                       unsigned int node_gap,
116                                       unsigned int block_size,
117                                       unsigned int size)
118 {
119         unsigned int limit;
120
121         limit = (block_size - root_gap) / size;
122         if (limit == node_limit(node_gap, block_size, size))
123                 limit--;
124         return limit;
125 }
126
127 struct iam_uapi_info {
128         __u16 iui_keysize;
129         __u16 iui_recsize;
130         __u16 iui_ptrsize;
131         __u16 iui_height;
132         char  iui_fmt_name[DX_FMT_NAME_LEN];
133 };
134
135 /*
136  * Creat an iam file, but do NOT open it.
137  * Return 0 if success, else -1.
138  */
139 int iam_creat(char *filename, enum iam_fmt_t fmt,
140               int blocksize, int keysize, int recsize, int ptrsize);
141
142 /*
143  * Open an iam file, but do NOT creat it if the file doesn't exist.
144  * Please use iam_creat for creating the file before use iam_open.
145  * Return file id (fd) if success, else -1.
146  */
147 int iam_open(char *filename, struct iam_uapi_info *ua);
148
149 /*
150  * Close file opened by iam_open.
151  */
152 int iam_close(int fd);
153
154 /*
155  * Please use iam_open before use this function.
156  */
157 int iam_insert(int fd, struct iam_uapi_info *ua, int key_need_convert,
158                char *keybuf, int rec_need_convert, char *recbuf);
159
160 /*
161  * Please use iam_open before use this function.
162  */
163 int iam_lookup(int fd, struct iam_uapi_info *ua,
164                int key_need_convert, char *key_buf, int *keysize,
165                char *save_key, int rec_need_convert, char *rec_buf,
166                int *recsize, char *save_rec);
167
168 /*
169  * Please use iam_open before use this function.
170  */
171 int iam_delete(int fd, struct iam_uapi_info *ua, int key_need_convert,
172                char *keybuf, int rec_need_convert, char *recbuf);
173
174 /*
175  * Please use iam_open before use this function.
176  */
177 int iam_it_start(int fd, struct iam_uapi_info *ua, int key_need_convert,
178                  char *key_buf, int *keysize, char *save_key,
179                  int rec_need_convert, char *rec_buf, int *recsize,
180                  char *save_rec);
181
182 /*
183  * Please use iam_open before use this function.
184  */
185 int iam_it_next(int fd, struct iam_uapi_info *ua, int key_need_convert,
186                 char *key_buf, int *keysize, char *save_key,
187                 int rec_need_convert, char *rec_buf, int *recsize,
188                 char *save_rec);
189
190 /*
191  * Please use iam_open before use this function.
192  */
193 int iam_it_stop(int fd, struct iam_uapi_info *ua, int key_need_convert,
194                 char *keybuf, int rec_need_convert, char *recbuf);
195
196 /*
197  * Change iam file mode.
198  */
199 int iam_polymorph(char *filename, unsigned long mode);
200
201 #endif