]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - sys/fs/nandfs/nandfs_subr.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / sys / fs / nandfs / nandfs_subr.h
1 /*-
2  * Copyright (c) 2010-2012 Semihalf
3  * Copyright (c) 2008, 2009 Reinoud Zandijk
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * From: NetBSD: nilfs_subr.h,v 1.1 2009/07/18 16:31:42 reinoud
27  *
28  * $FreeBSD$
29  */
30
31 #ifndef _FS_NANDFS_NANDFS_SUBR_H_
32 #define _FS_NANDFS_NANDFS_SUBR_H_
33
34 struct nandfs_mdt;
35
36 struct nandfs_alloc_request
37 {
38         uint64_t        entrynum;
39         struct buf      *bp_desc;
40         struct buf      *bp_bitmap;
41         struct buf      *bp_entry;
42 };
43
44 /* Segment creation */
45 void nandfs_wakeup_wait_sync(struct nandfs_device *, int);
46 int nandfs_segment_constructor(struct nandfsmount *, int);
47 int nandfs_sync_file(struct vnode *);
48
49 /* Basic calculators */
50 uint64_t nandfs_get_segnum_of_block(struct nandfs_device *, nandfs_daddr_t);
51 void nandfs_get_segment_range(struct nandfs_device *, uint64_t, uint64_t *,
52     uint64_t *);
53 void nandfs_calc_mdt_consts(struct nandfs_device *, struct nandfs_mdt *, int);
54
55 /* Log reading / volume helpers */
56 int nandfs_search_super_root(struct nandfs_device *);
57
58 /* Reading */
59 int nandfs_dev_bread(struct nandfs_device *, nandfs_daddr_t, struct ucred *,
60     int, struct buf **);
61 int nandfs_bread(struct nandfs_node *, nandfs_lbn_t, struct ucred *, int,
62     struct buf **);
63 int nandfs_bread_meta(struct nandfs_node *, nandfs_lbn_t, struct ucred *, int,
64     struct buf **);
65 int nandfs_bdestroy(struct nandfs_node *, nandfs_daddr_t);
66 int nandfs_bcreate(struct nandfs_node *, nandfs_lbn_t, struct ucred *, int,
67     struct buf **);
68 int nandfs_bcreate_meta(struct nandfs_node *, nandfs_lbn_t, struct ucred *,
69     int, struct buf **);
70 int nandfs_bread_create(struct nandfs_node *, nandfs_lbn_t, struct ucred *,
71     int, struct buf **);
72
73 /* vtop operations */
74 int nandfs_vtop(struct nandfs_node *, nandfs_daddr_t, nandfs_daddr_t *);
75
76 /* Node action implementators */
77 int nandfs_vinit(struct vnode *, uint64_t);
78 int nandfs_get_node(struct nandfsmount *, uint64_t, struct nandfs_node **);
79 int nandfs_get_node_raw(struct nandfs_device *, struct nandfsmount *, uint64_t,
80     struct nandfs_inode *, struct nandfs_node **);
81 void nandfs_dispose_node(struct nandfs_node **);
82
83 void nandfs_itimes(struct vnode *);
84 int nandfs_lookup_name_in_dir(struct vnode *, const char *, int, uint64_t *,
85     int *, uint64_t *);
86 int nandfs_create_node(struct vnode *, struct vnode **, struct vattr *,
87     struct componentname *);
88 void nandfs_delete_node(struct nandfs_node *);
89
90 int nandfs_chsize(struct vnode *, u_quad_t, struct ucred *);
91 int nandfs_dir_detach(struct nandfsmount *, struct nandfs_node *,
92     struct nandfs_node *, struct componentname *);
93 int nandfs_dir_attach(struct nandfsmount *, struct nandfs_node *,
94     struct nandfs_node *, struct vattr *, struct componentname *);
95
96 int nandfs_dirty_buf(struct buf *, int);
97 int nandfs_dirty_buf_meta(struct buf *, int);
98 int nandfs_fs_full(struct nandfs_device *);
99 void nandfs_undirty_buf_fsdev(struct nandfs_device *, struct buf *);
100 void nandfs_undirty_buf(struct buf *);
101
102 void nandfs_clear_buf(struct buf *);
103 void nandfs_buf_set(struct buf *, uint32_t);
104 void nandfs_buf_clear(struct buf *, uint32_t);
105 int nandfs_buf_check(struct buf *, uint32_t);
106
107 int  nandfs_find_free_entry(struct nandfs_mdt *, struct nandfs_node *,
108     struct nandfs_alloc_request *);
109 int  nandfs_find_entry(struct nandfs_mdt *, struct nandfs_node *,
110     struct nandfs_alloc_request *);
111 int  nandfs_alloc_entry(struct nandfs_mdt *, struct nandfs_alloc_request *);
112 void nandfs_abort_entry(struct nandfs_alloc_request *);
113 int  nandfs_free_entry(struct nandfs_mdt *, struct nandfs_alloc_request *);
114 int nandfs_get_entry_block(struct nandfs_mdt *, struct nandfs_node *,
115     struct nandfs_alloc_request *, uint32_t *, int);
116
117 /* inode managment */
118 int  nandfs_node_create(struct nandfsmount *, struct nandfs_node **, uint16_t);
119 int nandfs_node_destroy(struct nandfs_node *);
120 int nandfs_node_update(struct nandfs_node *);
121 int nandfs_get_node_entry(struct nandfsmount *, struct nandfs_inode **,
122     uint64_t, struct buf **);
123 void nandfs_mdt_trans_blk(struct nandfs_mdt *, uint64_t, uint64_t *,
124     uint64_t *, nandfs_lbn_t *, uint32_t *);
125
126 /* vblock management */
127 void nandfs_mdt_trans(struct nandfs_mdt *, uint64_t, nandfs_lbn_t *, uint32_t *);
128 int nandfs_vblock_alloc(struct nandfs_device *, nandfs_daddr_t *);
129 int nandfs_vblock_end(struct nandfs_device *, nandfs_daddr_t);
130 int nandfs_vblock_assign(struct nandfs_device *, nandfs_daddr_t,
131     nandfs_lbn_t);
132 int nandfs_vblock_free(struct nandfs_device *, nandfs_daddr_t);
133
134 /* Checkpoint management */
135 int nandfs_get_checkpoint(struct nandfs_device *, struct nandfs_node *,
136     uint64_t);
137 int nandfs_set_checkpoint(struct nandfs_device *, struct nandfs_node *,
138     uint64_t, struct nandfs_inode *, uint64_t);
139
140 /* Segment management */
141 int nandfs_alloc_segment(struct nandfs_device *, uint64_t *);
142 int nandfs_update_segment(struct nandfs_device *, uint64_t, uint32_t);
143 int nandfs_free_segment(struct nandfs_device *, uint64_t);
144 int nandfs_clear_segment(struct nandfs_device *, uint64_t);
145 int nandfs_touch_segment(struct nandfs_device *, uint64_t);
146 int nandfs_markgc_segment(struct nandfs_device *, uint64_t);
147
148 int nandfs_bmap_insert_block(struct nandfs_node *, nandfs_lbn_t, struct buf *);
149 int nandfs_bmap_update_block(struct nandfs_node *, struct buf *, nandfs_lbn_t);
150 int nandfs_bmap_update_dat(struct nandfs_node *, nandfs_daddr_t, struct buf *);
151 int nandfs_bmap_dirty_blocks(struct nandfs_node *, struct buf *, int);
152 int nandfs_bmap_truncate_mapping(struct nandfs_node *, nandfs_lbn_t,
153     nandfs_lbn_t);
154 int nandfs_bmap_lookup(struct nandfs_node *, nandfs_lbn_t, nandfs_daddr_t *);
155
156 /* dirent */
157 int nandfs_add_dirent(struct vnode *, uint64_t, char *, long, uint8_t);
158 int nandfs_remove_dirent(struct vnode *, struct nandfs_node *,
159     struct componentname *);
160 int nandfs_update_dirent(struct vnode *, struct nandfs_node *,
161     struct nandfs_node *);
162 int nandfs_init_dir(struct vnode *, uint64_t, uint64_t);
163 int nandfs_update_parent_dir(struct vnode *, uint64_t);
164
165 void nandfs_vblk_set(struct buf *, nandfs_daddr_t);
166 nandfs_daddr_t nandfs_vblk_get(struct buf *);
167
168 void nandfs_inode_init(struct nandfs_inode *, uint16_t);
169 void nandfs_inode_destroy(struct nandfs_inode *);
170
171 /* ioctl */
172 int nandfs_get_seg_stat(struct nandfs_device *, struct nandfs_seg_stat *);
173 int nandfs_chng_cpmode(struct nandfs_node *, struct nandfs_cpmode *);
174 int nandfs_get_cpinfo_ioctl(struct nandfs_node *, struct nandfs_argv *);
175 int nandfs_delete_cp(struct nandfs_node *, uint64_t start, uint64_t);
176 int nandfs_make_snap(struct nandfs_device *, uint64_t *);
177 int nandfs_delete_snap(struct nandfs_device *, uint64_t);
178 int nandfs_get_cpstat(struct nandfs_node *, struct nandfs_cpstat *);
179 int nandfs_get_segment_info_ioctl(struct nandfs_device *, struct nandfs_argv *);
180 int nandfs_get_dat_vinfo_ioctl(struct nandfs_device *, struct nandfs_argv *);
181 int nandfs_get_dat_bdescs_ioctl(struct nandfs_device *, struct nandfs_argv *);
182 int nandfs_get_fsinfo(struct nandfsmount *, struct nandfs_fsinfo *);
183
184 int nandfs_get_cpinfo(struct nandfs_node *, uint64_t, uint16_t,
185     struct nandfs_cpinfo *, uint32_t, uint32_t *);
186
187 nandfs_lbn_t nandfs_get_maxfilesize(struct nandfs_device *);
188
189 int nandfs_write_superblock(struct nandfs_device *);
190
191 extern int nandfs_sync_interval;
192 extern int nandfs_max_dirty_segs;
193 extern int nandfs_cps_between_sblocks;
194
195 struct buf *nandfs_geteblk(int, int);
196
197 void nandfs_dirty_bufs_increment(struct nandfs_device *);
198 void nandfs_dirty_bufs_decrement(struct nandfs_device *);
199
200 int nandfs_start_cleaner(struct nandfs_device *);
201 int nandfs_stop_cleaner(struct nandfs_device *);
202
203 int nandfs_segsum_valid(struct nandfs_segment_summary *);
204 int nandfs_load_segsum(struct nandfs_device *, nandfs_daddr_t,
205     struct nandfs_segment_summary *);
206 int nandfs_get_segment_info(struct nandfs_device *, struct nandfs_suinfo *,
207     uint32_t, uint64_t);
208 int nandfs_get_segment_info_filter(struct nandfs_device *,
209     struct nandfs_suinfo *, uint32_t, uint64_t, uint64_t *, uint32_t, uint32_t);
210 int nandfs_get_dat_vinfo(struct nandfs_device *, struct nandfs_vinfo *,
211     uint32_t);
212 int nandfs_get_dat_bdescs(struct nandfs_device *, struct nandfs_bdesc *,
213     uint32_t);
214
215 #define NANDFS_VBLK_ASSIGNED    1
216
217 #define NANDFS_IS_INDIRECT(bp)  ((bp)->b_lblkno < 0)
218
219 int nandfs_erase(struct nandfs_device *, off_t, size_t);
220
221 #define NANDFS_VOP_ISLOCKED(vp) nandfs_vop_islocked((vp))
222 int nandfs_vop_islocked(struct vnode *vp);
223
224 nandfs_daddr_t nandfs_block_to_dblock(struct nandfs_device *, nandfs_lbn_t);
225
226 #define DEBUG_MODE
227 #if defined(DEBUG_MODE)
228 #define nandfs_error            panic
229 #define nandfs_warning          printf
230 #elif defined(TEST_MODE)
231 #define nandfs_error    printf
232 #define nandfs_warning  printf
233 #else
234 #define nandfs_error(...)
235 #define nandfs_warning(...)
236 #endif
237
238 #endif  /* !_FS_NANDFS_NANDFS_SUBR_H_ */