]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - fs/xfs/libxfs/xfs_da_btree.h
xfs: fail _dir_open when readahead fails
[mirror_ubuntu-zesty-kernel.git] / fs / xfs / libxfs / xfs_da_btree.h
CommitLineData
1da177e4 1/*
7b718769 2 * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
f5ea1100 3 * Copyright (c) 2013 Red Hat, Inc.
7b718769 4 * All Rights Reserved.
1da177e4 5 *
7b718769
NS
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
1da177e4
LT
8 * published by the Free Software Foundation.
9 *
7b718769
NS
10 * This program is distributed in the hope that it would be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
1da177e4 14 *
7b718769
NS
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1da177e4
LT
18 */
19#ifndef __XFS_DA_BTREE_H__
20#define __XFS_DA_BTREE_H__
21
310a75a3 22struct xfs_defer_ops;
1da177e4 23struct xfs_inode;
1da177e4
LT
24struct xfs_trans;
25struct zone;
32c5483a 26struct xfs_dir_ops;
1da177e4 27
0650b554
DC
28/*
29 * Directory/attribute geometry information. There will be one of these for each
30 * data fork type, and it will be passed around via the xfs_da_args. Global
31 * structures will be attached to the xfs_mount.
32 */
33struct xfs_da_geometry {
34 int blksize; /* da block size in bytes */
35 int fsbcount; /* da block size in filesystem blocks */
36 uint8_t fsblog; /* log2 of _filesystem_ block size */
37 uint8_t blklog; /* log2 of da block size */
38 uint node_ents; /* # of entries in a danode */
39 int magicpct; /* 37% of block size in bytes */
40 xfs_dablk_t datablk; /* blockno of dir data v2 */
41 xfs_dablk_t leafblk; /* blockno of leaf data v2 */
42 xfs_dablk_t freeblk; /* blockno of free data v2 */
43};
44
1da177e4
LT
45/*========================================================================
46 * Btree searching and modification structure definitions.
47 *========================================================================*/
48
5163f95a
BN
49/*
50 * Search comparison results
51 */
52enum xfs_dacmp {
53 XFS_CMP_DIFFERENT, /* names are completely different */
54 XFS_CMP_EXACT, /* names are exactly the same */
55 XFS_CMP_CASE /* names are same but differ in case */
56};
57
1da177e4
LT
58/*
59 * Structure to ease passing around component names.
60 */
61typedef struct xfs_da_args {
0650b554 62 struct xfs_da_geometry *geo; /* da block geometry */
a5687787 63 const __uint8_t *name; /* string (maybe not NULL terminated) */
1da177e4 64 int namelen; /* length of string (maybe no NULL) */
0cb97766 65 __uint8_t filetype; /* filetype of inode for directories */
a5687787 66 __uint8_t *value; /* set of bytes (maybe contain NULLs) */
1da177e4
LT
67 int valuelen; /* length of value */
68 int flags; /* argument flags (eg: ATTR_NOCREATE) */
69 xfs_dahash_t hashval; /* hash value of name */
70 xfs_ino_t inumber; /* input/output inode number */
71 struct xfs_inode *dp; /* directory inode to manipulate */
72 xfs_fsblock_t *firstblock; /* ptr to firstblock for bmap calls */
2c3234d1 73 struct xfs_defer_ops *dfops; /* ptr to freelist for bmap_finish */
1da177e4
LT
74 struct xfs_trans *trans; /* current trans (changes over time) */
75 xfs_extlen_t total; /* total blocks needed, for 1st bmap */
76 int whichfork; /* data or attribute fork */
77 xfs_dablk_t blkno; /* blkno of attr leaf of interest */
78 int index; /* index of attr of interest in blk */
79 xfs_dablk_t rmtblkno; /* remote attr value starting blkno */
80 int rmtblkcnt; /* remote attr value block count */
8275cdd0 81 int rmtvaluelen; /* remote attr value length in bytes */
1da177e4
LT
82 xfs_dablk_t blkno2; /* blkno of 2nd attr leaf of interest */
83 int index2; /* index of 2nd attr in blk */
84 xfs_dablk_t rmtblkno2; /* remote attr value starting blkno */
85 int rmtblkcnt2; /* remote attr value block count */
8275cdd0 86 int rmtvaluelen2; /* remote attr value length in bytes */
6a178100 87 int op_flags; /* operation flags */
5163f95a 88 enum xfs_dacmp cmpresult; /* name compare result for lookups */
1da177e4
LT
89} xfs_da_args_t;
90
6a178100
BN
91/*
92 * Operation flags:
93 */
94#define XFS_DA_OP_JUSTCHECK 0x0001 /* check for ok with no space */
95#define XFS_DA_OP_RENAME 0x0002 /* this is an atomic rename op */
96#define XFS_DA_OP_ADDNAME 0x0004 /* this is an add operation */
97#define XFS_DA_OP_OKNOENT 0x0008 /* lookup/add op, ENOENT ok, else die */
384f3ced 98#define XFS_DA_OP_CILOOKUP 0x0010 /* lookup to return CI name if found */
6a178100 99
0b1b213f
CH
100#define XFS_DA_OP_FLAGS \
101 { XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \
102 { XFS_DA_OP_RENAME, "RENAME" }, \
103 { XFS_DA_OP_ADDNAME, "ADDNAME" }, \
104 { XFS_DA_OP_OKNOENT, "OKNOENT" }, \
105 { XFS_DA_OP_CILOOKUP, "CILOOKUP" }
106
1da177e4
LT
107/*
108 * Storage for holding state during Btree searches and split/join ops.
109 *
110 * Only need space for 5 intermediate nodes. With a minimum of 62-way
111 * fanout to the Btree, we can support over 900 million directory blocks,
112 * which is slightly more than enough.
113 */
114typedef struct xfs_da_state_blk {
1d9025e5 115 struct xfs_buf *bp; /* buffer containing block */
1da177e4
LT
116 xfs_dablk_t blkno; /* filesystem blkno of buffer */
117 xfs_daddr_t disk_blkno; /* on-disk blkno (in BBs) of buffer */
118 int index; /* relevant index into block */
119 xfs_dahash_t hashval; /* last hash value in block */
120 int magic; /* blk's magic number, ie: blk type */
121} xfs_da_state_blk_t;
122
123typedef struct xfs_da_state_path {
124 int active; /* number of active levels */
125 xfs_da_state_blk_t blk[XFS_DA_NODE_MAXDEPTH];
126} xfs_da_state_path_t;
127
128typedef struct xfs_da_state {
129 xfs_da_args_t *args; /* filename arguments */
130 struct xfs_mount *mp; /* filesystem mount point */
1da177e4
LT
131 xfs_da_state_path_t path; /* search/split paths */
132 xfs_da_state_path_t altpath; /* alternate path for join */
133 unsigned char inleaf; /* insert into 1->lf, 0->splf */
134 unsigned char extravalid; /* T/F: extrablk is in use */
135 unsigned char extraafter; /* T/F: extrablk is after new */
9da096fd 136 xfs_da_state_blk_t extrablk; /* for double-splits on leaves */
1da177e4
LT
137 /* for dirv2 extrablk is data */
138} xfs_da_state_t;
139
140/*
141 * Utility macros to aid in logging changed structure fields.
142 */
143#define XFS_DA_LOGOFF(BASE, ADDR) ((char *)(ADDR) - (char *)(BASE))
144#define XFS_DA_LOGRANGE(BASE, ADDR, SIZE) \
145 (uint)(XFS_DA_LOGOFF(BASE, ADDR)), \
146 (uint)(XFS_DA_LOGOFF(BASE, ADDR)+(SIZE)-1)
147
5163f95a
BN
148/*
149 * Name ops for directory and/or attr name operations
150 */
151struct xfs_nameops {
152 xfs_dahash_t (*hashname)(struct xfs_name *);
2bc75421
DC
153 enum xfs_dacmp (*compname)(struct xfs_da_args *,
154 const unsigned char *, int);
5163f95a
BN
155};
156
1da177e4 157
1da177e4 158/*========================================================================
847fff5c 159 * Function prototypes.
1da177e4
LT
160 *========================================================================*/
161
162/*
163 * Routines used for growing the Btree.
164 */
f5ea1100
DC
165int xfs_da3_node_create(struct xfs_da_args *args, xfs_dablk_t blkno,
166 int level, struct xfs_buf **bpp, int whichfork);
167int xfs_da3_split(xfs_da_state_t *state);
1da177e4
LT
168
169/*
170 * Routines used for shrinking the Btree.
171 */
f5ea1100
DC
172int xfs_da3_join(xfs_da_state_t *state);
173void xfs_da3_fixhashpath(struct xfs_da_state *state,
174 struct xfs_da_state_path *path_to_to_fix);
1da177e4
LT
175
176/*
177 * Routines used for finding things in the Btree.
178 */
f5ea1100
DC
179int xfs_da3_node_lookup_int(xfs_da_state_t *state, int *result);
180int xfs_da3_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path,
1da177e4
LT
181 int forward, int release, int *result);
182/*
183 * Utility routines.
184 */
f5ea1100 185int xfs_da3_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk,
1da177e4 186 xfs_da_state_blk_t *new_blk);
f5ea1100 187int xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp,
d9392a4b
DC
188 xfs_dablk_t bno, xfs_daddr_t mappedbno,
189 struct xfs_buf **bpp, int which_fork);
1da177e4
LT
190
191/*
192 * Utility routines.
193 */
194int xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno);
77936d02
CH
195int xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno,
196 int count);
1da177e4
LT
197int xfs_da_get_buf(struct xfs_trans *trans, struct xfs_inode *dp,
198 xfs_dablk_t bno, xfs_daddr_t mappedbno,
1d9025e5 199 struct xfs_buf **bp, int whichfork);
1da177e4
LT
200int xfs_da_read_buf(struct xfs_trans *trans, struct xfs_inode *dp,
201 xfs_dablk_t bno, xfs_daddr_t mappedbno,
4bb20a83 202 struct xfs_buf **bpp, int whichfork,
1813dd64 203 const struct xfs_buf_ops *ops);
84a3fe64 204int xfs_da_reada_buf(struct xfs_inode *dp, xfs_dablk_t bno,
9df2dd0b
ES
205 xfs_daddr_t mapped_bno, int whichfork,
206 const struct xfs_buf_ops *ops);
1da177e4 207int xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno,
1d9025e5 208 struct xfs_buf *dead_buf);
1da177e4 209
a5687787 210uint xfs_da_hashname(const __uint8_t *name_string, int name_length);
5163f95a 211enum xfs_dacmp xfs_da_compname(struct xfs_da_args *args,
2bc75421 212 const unsigned char *name, int len);
5163f95a
BN
213
214
1da177e4
LT
215xfs_da_state_t *xfs_da_state_alloc(void);
216void xfs_da_state_free(xfs_da_state_t *state);
1da177e4 217
1da177e4 218extern struct kmem_zone *xfs_da_state_zone;
24418492 219extern const struct xfs_nameops xfs_default_nameops;
1da177e4
LT
220
221#endif /* __XFS_DA_BTREE_H__ */