Deleted Added
full compact
softdep.h (62976) softdep.h (76357)
1/*
2 * Copyright 1998, 2000 Marshall Kirk McKusick. All Rights Reserved.
3 *
4 * The soft updates code is derived from the appendix of a University
5 * of Michigan technical report (Gregory R. Ganger and Yale N. Patt,
6 * "Soft Updates: A Solution to the Metadata Update Problem in File
7 * Systems", CSE-TR-254-95, August 1995).
8 *
9 * Further information about soft updates can be obtained from:
10 *
11 * Marshall Kirk McKusick http://www.mckusick.com/softdep/
12 * 1614 Oxford Street mckusick@mckusick.com
13 * Berkeley, CA 94709-1608 +1-510-843-9542
14 * USA
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 *
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY MARSHALL KIRK MCKUSICK ``AS IS'' AND ANY
27 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 * DISCLAIMED. IN NO EVENT SHALL MARSHALL KIRK MCKUSICK BE LIABLE FOR
30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)softdep.h 9.7 (McKusick) 6/21/00
1/*
2 * Copyright 1998, 2000 Marshall Kirk McKusick. All Rights Reserved.
3 *
4 * The soft updates code is derived from the appendix of a University
5 * of Michigan technical report (Gregory R. Ganger and Yale N. Patt,
6 * "Soft Updates: A Solution to the Metadata Update Problem in File
7 * Systems", CSE-TR-254-95, August 1995).
8 *
9 * Further information about soft updates can be obtained from:
10 *
11 * Marshall Kirk McKusick http://www.mckusick.com/softdep/
12 * 1614 Oxford Street mckusick@mckusick.com
13 * Berkeley, CA 94709-1608 +1-510-843-9542
14 * USA
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 *
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY MARSHALL KIRK MCKUSICK ``AS IS'' AND ANY
27 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 * DISCLAIMED. IN NO EVENT SHALL MARSHALL KIRK MCKUSICK BE LIABLE FOR
30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)softdep.h 9.7 (McKusick) 6/21/00
39 * $FreeBSD: head/sys/ufs/ffs/softdep.h 62976 2000-07-11 22:07:57Z mckusick $
39 * $FreeBSD: head/sys/ufs/ffs/softdep.h 76357 2001-05-08 07:42:20Z mckusick $
40 */
41
42#include <sys/queue.h>
43
44/*
45 * Allocation dependencies are handled with undo/redo on the in-memory
46 * copy of the data. A particular data dependency is eliminated when
47 * it is ALLCOMPLETE: that is ATTACHED, DEPCOMPLETE, and COMPLETE.
48 *
49 * ATTACHED means that the data is not currently being written to
50 * disk. UNDONE means that the data has been rolled back to a safe
51 * state for writing to the disk. When the I/O completes, the data is
52 * restored to its current form and the state reverts to ATTACHED.
53 * The data must be locked throughout the rollback, I/O, and roll
54 * forward so that the rolled back information is never visible to
55 * user processes. The COMPLETE flag indicates that the item has been
56 * written. For example, a dependency that requires that an inode be
57 * written will be marked COMPLETE after the inode has been written
58 * to disk. The DEPCOMPLETE flag indicates the completion of any other
59 * dependencies such as the writing of a cylinder group map has been
60 * completed. A dependency structure may be freed only when both it
61 * and its dependencies have completed and any rollbacks that are in
62 * progress have finished as indicated by the set of ALLCOMPLETE flags
63 * all being set. The two MKDIR flags indicate additional dependencies
64 * that must be done when creating a new directory. MKDIR_BODY is
65 * cleared when the directory data block containing the "." and ".."
66 * entries has been written. MKDIR_PARENT is cleared when the parent
67 * inode with the increased link count for ".." has been written. When
68 * both MKDIR flags have been cleared, the DEPCOMPLETE flag is set to
69 * indicate that the directory dependencies have been completed. The
70 * writing of the directory inode itself sets the COMPLETE flag which
71 * then allows the directory entry for the new directory to be written
72 * to disk. The RMDIR flag marks a dirrem structure as representing
73 * the removal of a directory rather than a file. When the removal
74 * dependencies are completed, additional work needs to be done
75 * (truncation of the "." and ".." entries, an additional decrement
76 * of the associated inode, and a decrement of the parent inode). The
77 * DIRCHG flag marks a diradd structure as representing the changing
78 * of an existing entry rather than the addition of a new one. When
79 * the update is complete the dirrem associated with the inode for
80 * the old name must be added to the worklist to do the necessary
81 * reference count decrement. The GOINGAWAY flag indicates that the
82 * data structure is frozen from further change until its dependencies
83 * have been completed and its resources freed after which it will be
84 * discarded. The IOSTARTED flag prevents multiple calls to the I/O
40 */
41
42#include <sys/queue.h>
43
44/*
45 * Allocation dependencies are handled with undo/redo on the in-memory
46 * copy of the data. A particular data dependency is eliminated when
47 * it is ALLCOMPLETE: that is ATTACHED, DEPCOMPLETE, and COMPLETE.
48 *
49 * ATTACHED means that the data is not currently being written to
50 * disk. UNDONE means that the data has been rolled back to a safe
51 * state for writing to the disk. When the I/O completes, the data is
52 * restored to its current form and the state reverts to ATTACHED.
53 * The data must be locked throughout the rollback, I/O, and roll
54 * forward so that the rolled back information is never visible to
55 * user processes. The COMPLETE flag indicates that the item has been
56 * written. For example, a dependency that requires that an inode be
57 * written will be marked COMPLETE after the inode has been written
58 * to disk. The DEPCOMPLETE flag indicates the completion of any other
59 * dependencies such as the writing of a cylinder group map has been
60 * completed. A dependency structure may be freed only when both it
61 * and its dependencies have completed and any rollbacks that are in
62 * progress have finished as indicated by the set of ALLCOMPLETE flags
63 * all being set. The two MKDIR flags indicate additional dependencies
64 * that must be done when creating a new directory. MKDIR_BODY is
65 * cleared when the directory data block containing the "." and ".."
66 * entries has been written. MKDIR_PARENT is cleared when the parent
67 * inode with the increased link count for ".." has been written. When
68 * both MKDIR flags have been cleared, the DEPCOMPLETE flag is set to
69 * indicate that the directory dependencies have been completed. The
70 * writing of the directory inode itself sets the COMPLETE flag which
71 * then allows the directory entry for the new directory to be written
72 * to disk. The RMDIR flag marks a dirrem structure as representing
73 * the removal of a directory rather than a file. When the removal
74 * dependencies are completed, additional work needs to be done
75 * (truncation of the "." and ".." entries, an additional decrement
76 * of the associated inode, and a decrement of the parent inode). The
77 * DIRCHG flag marks a diradd structure as representing the changing
78 * of an existing entry rather than the addition of a new one. When
79 * the update is complete the dirrem associated with the inode for
80 * the old name must be added to the worklist to do the necessary
81 * reference count decrement. The GOINGAWAY flag indicates that the
82 * data structure is frozen from further change until its dependencies
83 * have been completed and its resources freed after which it will be
84 * discarded. The IOSTARTED flag prevents multiple calls to the I/O
85 * start routine from doing multiple rollbacks. The ONWORKLIST flag
86 * shows whether the structure is currently linked onto a worklist.
85 * start routine from doing multiple rollbacks. The SPACECOUNTED flag
86 * says that the files space has been accounted to the pending free
87 * space count. The ONWORKLIST flag shows whether the structure is
88 * currently linked onto a worklist.
87 */
88#define ATTACHED 0x0001
89#define UNDONE 0x0002
90#define COMPLETE 0x0004
91#define DEPCOMPLETE 0x0008
92#define MKDIR_PARENT 0x0010
93#define MKDIR_BODY 0x0020
94#define RMDIR 0x0040
95#define DIRCHG 0x0080
96#define GOINGAWAY 0x0100
97#define IOSTARTED 0x0200
89 */
90#define ATTACHED 0x0001
91#define UNDONE 0x0002
92#define COMPLETE 0x0004
93#define DEPCOMPLETE 0x0008
94#define MKDIR_PARENT 0x0010
95#define MKDIR_BODY 0x0020
96#define RMDIR 0x0040
97#define DIRCHG 0x0080
98#define GOINGAWAY 0x0100
99#define IOSTARTED 0x0200
100#define SPACECOUNTED 0x0400
98#define ONWORKLIST 0x8000
99
100#define ALLCOMPLETE (ATTACHED | COMPLETE | DEPCOMPLETE)
101
102/*
103 * The workitem queue.
104 *
105 * It is sometimes useful and/or necessary to clean up certain dependencies
106 * in the background rather than during execution of an application process
107 * or interrupt service routine. To realize this, we append dependency
108 * structures corresponding to such tasks to a "workitem" queue. In a soft
109 * updates implementation, most pending workitems should not wait for more
110 * than a couple of seconds, so the filesystem syncer process awakens once
111 * per second to process the items on the queue.
112 */
113
114/* LIST_HEAD(workhead, worklist); -- declared in buf.h */
115
116/*
117 * Each request can be linked onto a work queue through its worklist structure.
118 * To avoid the need for a pointer to the structure itself, this structure
119 * MUST be declared FIRST in each type in which it appears! If more than one
120 * worklist is needed in the structure, then a wk_data field must be added
121 * and the macros below changed to use it.
122 */
123struct worklist {
124 LIST_ENTRY(worklist) wk_list; /* list of work requests */
125 unsigned short wk_type; /* type of request */
126 unsigned short wk_state; /* state flags */
127};
128#define WK_DATA(wk) ((void *)(wk))
129#define WK_PAGEDEP(wk) ((struct pagedep *)(wk))
130#define WK_INODEDEP(wk) ((struct inodedep *)(wk))
131#define WK_NEWBLK(wk) ((struct newblk *)(wk))
132#define WK_BMSAFEMAP(wk) ((struct bmsafemap *)(wk))
133#define WK_ALLOCDIRECT(wk) ((struct allocdirect *)(wk))
134#define WK_INDIRDEP(wk) ((struct indirdep *)(wk))
135#define WK_ALLOCINDIR(wk) ((struct allocindir *)(wk))
136#define WK_FREEFRAG(wk) ((struct freefrag *)(wk))
137#define WK_FREEBLKS(wk) ((struct freeblks *)(wk))
138#define WK_FREEFILE(wk) ((struct freefile *)(wk))
139#define WK_DIRADD(wk) ((struct diradd *)(wk))
140#define WK_MKDIR(wk) ((struct mkdir *)(wk))
141#define WK_DIRREM(wk) ((struct dirrem *)(wk))
142
143/*
144 * Various types of lists
145 */
146LIST_HEAD(dirremhd, dirrem);
147LIST_HEAD(diraddhd, diradd);
148LIST_HEAD(newblkhd, newblk);
149LIST_HEAD(inodedephd, inodedep);
150LIST_HEAD(allocindirhd, allocindir);
151LIST_HEAD(allocdirecthd, allocdirect);
152TAILQ_HEAD(allocdirectlst, allocdirect);
153
154/*
155 * The "pagedep" structure tracks the various dependencies related to
156 * a particular directory page. If a directory page has any dependencies,
157 * it will have a pagedep linked to its associated buffer. The
158 * pd_dirremhd list holds the list of dirrem requests which decrement
159 * inode reference counts. These requests are processed after the
160 * directory page with the corresponding zero'ed entries has been
161 * written. The pd_diraddhd list maintains the list of diradd requests
162 * which cannot be committed until their corresponding inode has been
163 * written to disk. Because a directory may have many new entries
164 * being created, several lists are maintained hashed on bits of the
165 * offset of the entry into the directory page to keep the lists from
166 * getting too long. Once a new directory entry has been cleared to
167 * be written, it is moved to the pd_pendinghd list. After the new
168 * entry has been written to disk it is removed from the pd_pendinghd
169 * list, any removed operations are done, and the dependency structure
170 * is freed.
171 */
172#define DAHASHSZ 6
173#define DIRADDHASH(offset) (((offset) >> 2) % DAHASHSZ)
174struct pagedep {
175 struct worklist pd_list; /* page buffer */
176# define pd_state pd_list.wk_state /* check for multiple I/O starts */
177 LIST_ENTRY(pagedep) pd_hash; /* hashed lookup */
178 struct mount *pd_mnt; /* associated mount point */
179 ino_t pd_ino; /* associated file */
180 ufs_lbn_t pd_lbn; /* block within file */
181 struct dirremhd pd_dirremhd; /* dirrem's waiting for page */
182 struct diraddhd pd_diraddhd[DAHASHSZ]; /* diradd dir entry updates */
183 struct diraddhd pd_pendinghd; /* directory entries awaiting write */
184};
185
186/*
187 * The "inodedep" structure tracks the set of dependencies associated
188 * with an inode. One task that it must manage is delayed operations
189 * (i.e., work requests that must be held until the inodedep's associated
190 * inode has been written to disk). Getting an inode from its incore
191 * state to the disk requires two steps to be taken by the filesystem
192 * in this order: first the inode must be copied to its disk buffer by
193 * the VOP_UPDATE operation; second the inode's buffer must be written
194 * to disk. To ensure that both operations have happened in the required
195 * order, the inodedep maintains two lists. Delayed operations are
196 * placed on the id_inowait list. When the VOP_UPDATE is done, all
197 * operations on the id_inowait list are moved to the id_bufwait list.
198 * When the buffer is written, the items on the id_bufwait list can be
199 * safely moved to the work queue to be processed. A second task of the
200 * inodedep structure is to track the status of block allocation within
201 * the inode. Each block that is allocated is represented by an
202 * "allocdirect" structure (see below). It is linked onto the id_newinoupdt
203 * list until both its contents and its allocation in the cylinder
204 * group map have been written to disk. Once these dependencies have been
205 * satisfied, it is removed from the id_newinoupdt list and any followup
206 * actions such as releasing the previous block or fragment are placed
207 * on the id_inowait list. When an inode is updated (a VOP_UPDATE is
208 * done), the "inodedep" structure is linked onto the buffer through
209 * its worklist. Thus, it will be notified when the buffer is about
210 * to be written and when it is done. At the update time, all the
211 * elements on the id_newinoupdt list are moved to the id_inoupdt list
212 * since those changes are now relevant to the copy of the inode in the
213 * buffer. Also at update time, the tasks on the id_inowait list are
214 * moved to the id_bufwait list so that they will be executed when
215 * the updated inode has been written to disk. When the buffer containing
216 * the inode is written to disk, any updates listed on the id_inoupdt
217 * list are rolled back as they are not yet safe. Following the write,
218 * the changes are once again rolled forward and any actions on the
219 * id_bufwait list are processed (since those actions are now safe).
220 * The entries on the id_inoupdt and id_newinoupdt lists must be kept
221 * sorted by logical block number to speed the calculation of the size
222 * of the rolled back inode (see explanation in initiate_write_inodeblock).
223 * When a directory entry is created, it is represented by a diradd.
224 * The diradd is added to the id_inowait list as it cannot be safely
225 * written to disk until the inode that it represents is on disk. After
226 * the inode is written, the id_bufwait list is processed and the diradd
227 * entries are moved to the id_pendinghd list where they remain until
228 * the directory block containing the name has been written to disk.
229 * The purpose of keeping the entries on the id_pendinghd list is so that
230 * the softdep_fsync function can find and push the inode's directory
231 * name(s) as part of the fsync operation for that file.
232 */
233struct inodedep {
234 struct worklist id_list; /* buffer holding inode block */
235# define id_state id_list.wk_state /* inode dependency state */
236 LIST_ENTRY(inodedep) id_hash; /* hashed lookup */
237 struct fs *id_fs; /* associated filesystem */
238 ino_t id_ino; /* dependent inode */
239 nlink_t id_nlinkdelta; /* saved effective link count */
240 struct dinode *id_savedino; /* saved dinode contents */
241 LIST_ENTRY(inodedep) id_deps; /* bmsafemap's list of inodedep's */
242 struct buf *id_buf; /* related bmsafemap (if pending) */
243 off_t id_savedsize; /* file size saved during rollback */
244 struct workhead id_pendinghd; /* entries awaiting directory write */
245 struct workhead id_bufwait; /* operations after inode written */
246 struct workhead id_inowait; /* operations waiting inode update */
247 struct allocdirectlst id_inoupdt; /* updates before inode written */
248 struct allocdirectlst id_newinoupdt; /* updates when inode written */
249};
250
251/*
252 * A "newblk" structure is attached to a bmsafemap structure when a block
253 * or fragment is allocated from a cylinder group. Its state is set to
254 * DEPCOMPLETE when its cylinder group map is written. It is consumed by
255 * an associated allocdirect or allocindir allocation which will attach
256 * themselves to the bmsafemap structure if the newblk's DEPCOMPLETE flag
257 * is not set (i.e., its cylinder group map has not been written).
258 */
259struct newblk {
260 LIST_ENTRY(newblk) nb_hash; /* hashed lookup */
261 struct fs *nb_fs; /* associated filesystem */
262 ufs_daddr_t nb_newblkno; /* allocated block number */
263 int nb_state; /* state of bitmap dependency */
264 LIST_ENTRY(newblk) nb_deps; /* bmsafemap's list of newblk's */
265 struct bmsafemap *nb_bmsafemap; /* associated bmsafemap */
266};
267
268/*
269 * A "bmsafemap" structure maintains a list of dependency structures
270 * that depend on the update of a particular cylinder group map.
271 * It has lists for newblks, allocdirects, allocindirs, and inodedeps.
272 * It is attached to the buffer of a cylinder group block when any of
273 * these things are allocated from the cylinder group. It is freed
274 * after the cylinder group map is written and the state of its
275 * dependencies are updated with DEPCOMPLETE to indicate that it has
276 * been processed.
277 */
278struct bmsafemap {
279 struct worklist sm_list; /* cylgrp buffer */
280 struct buf *sm_buf; /* associated buffer */
281 struct allocdirecthd sm_allocdirecthd; /* allocdirect deps */
282 struct allocindirhd sm_allocindirhd; /* allocindir deps */
283 struct inodedephd sm_inodedephd; /* inodedep deps */
284 struct newblkhd sm_newblkhd; /* newblk deps */
285};
286
287/*
288 * An "allocdirect" structure is attached to an "inodedep" when a new block
289 * or fragment is allocated and pointed to by the inode described by
290 * "inodedep". The worklist is linked to the buffer that holds the block.
291 * When the block is first allocated, it is linked to the bmsafemap
292 * structure associated with the buffer holding the cylinder group map
293 * from which it was allocated. When the cylinder group map is written
294 * to disk, ad_state has the DEPCOMPLETE flag set. When the block itself
295 * is written, the COMPLETE flag is set. Once both the cylinder group map
296 * and the data itself have been written, it is safe to write the inode
297 * that claims the block. If there was a previous fragment that had been
298 * allocated before the file was increased in size, the old fragment may
299 * be freed once the inode claiming the new block is written to disk.
300 * This ad_fragfree request is attached to the id_inowait list of the
301 * associated inodedep (pointed to by ad_inodedep) for processing after
302 * the inode is written.
303 */
304struct allocdirect {
305 struct worklist ad_list; /* buffer holding block */
306# define ad_state ad_list.wk_state /* block pointer state */
307 TAILQ_ENTRY(allocdirect) ad_next; /* inodedep's list of allocdirect's */
308 ufs_lbn_t ad_lbn; /* block within file */
309 ufs_daddr_t ad_newblkno; /* new value of block pointer */
310 ufs_daddr_t ad_oldblkno; /* old value of block pointer */
311 long ad_newsize; /* size of new block */
312 long ad_oldsize; /* size of old block */
313 LIST_ENTRY(allocdirect) ad_deps; /* bmsafemap's list of allocdirect's */
314 struct buf *ad_buf; /* cylgrp buffer (if pending) */
315 struct inodedep *ad_inodedep; /* associated inodedep */
316 struct freefrag *ad_freefrag; /* fragment to be freed (if any) */
317};
318
319/*
320 * A single "indirdep" structure manages all allocation dependencies for
321 * pointers in an indirect block. The up-to-date state of the indirect
322 * block is stored in ir_savedata. The set of pointers that may be safely
323 * written to the disk is stored in ir_safecopy. The state field is used
324 * only to track whether the buffer is currently being written (in which
325 * case it is not safe to update ir_safecopy). Ir_deplisthd contains the
326 * list of allocindir structures, one for each block that needs to be
327 * written to disk. Once the block and its bitmap allocation have been
328 * written the safecopy can be updated to reflect the allocation and the
329 * allocindir structure freed. If ir_state indicates that an I/O on the
330 * indirect block is in progress when ir_safecopy is to be updated, the
331 * update is deferred by placing the allocindir on the ir_donehd list.
332 * When the I/O on the indirect block completes, the entries on the
333 * ir_donehd list are processed by updating their corresponding ir_safecopy
334 * pointers and then freeing the allocindir structure.
335 */
336struct indirdep {
337 struct worklist ir_list; /* buffer holding indirect block */
338# define ir_state ir_list.wk_state /* indirect block pointer state */
339 caddr_t ir_saveddata; /* buffer cache contents */
340 struct buf *ir_savebp; /* buffer holding safe copy */
341 struct allocindirhd ir_donehd; /* done waiting to update safecopy */
342 struct allocindirhd ir_deplisthd; /* allocindir deps for this block */
343};
344
345/*
346 * An "allocindir" structure is attached to an "indirdep" when a new block
347 * is allocated and pointed to by the indirect block described by the
348 * "indirdep". The worklist is linked to the buffer that holds the new block.
349 * When the block is first allocated, it is linked to the bmsafemap
350 * structure associated with the buffer holding the cylinder group map
351 * from which it was allocated. When the cylinder group map is written
352 * to disk, ai_state has the DEPCOMPLETE flag set. When the block itself
353 * is written, the COMPLETE flag is set. Once both the cylinder group map
354 * and the data itself have been written, it is safe to write the entry in
355 * the indirect block that claims the block; the "allocindir" dependency
356 * can then be freed as it is no longer applicable.
357 */
358struct allocindir {
359 struct worklist ai_list; /* buffer holding indirect block */
360# define ai_state ai_list.wk_state /* indirect block pointer state */
361 LIST_ENTRY(allocindir) ai_next; /* indirdep's list of allocindir's */
362 int ai_offset; /* pointer offset in indirect block */
363 ufs_daddr_t ai_newblkno; /* new block pointer value */
364 ufs_daddr_t ai_oldblkno; /* old block pointer value */
365 struct freefrag *ai_freefrag; /* block to be freed when complete */
366 struct indirdep *ai_indirdep; /* address of associated indirdep */
367 LIST_ENTRY(allocindir) ai_deps; /* bmsafemap's list of allocindir's */
368 struct buf *ai_buf; /* cylgrp buffer (if pending) */
369};
370
371/*
372 * A "freefrag" structure is attached to an "inodedep" when a previously
373 * allocated fragment is replaced with a larger fragment, rather than extended.
374 * The "freefrag" structure is constructed and attached when the replacement
375 * block is first allocated. It is processed after the inode claiming the
376 * bigger block that replaces it has been written to disk. Note that the
377 * ff_state field is is used to store the uid, so may lose data. However,
378 * the uid is used only in printing an error message, so is not critical.
379 * Keeping it in a short keeps the data structure down to 32 bytes.
380 */
381struct freefrag {
382 struct worklist ff_list; /* id_inowait or delayed worklist */
383# define ff_state ff_list.wk_state /* owning user; should be uid_t */
384 struct vnode *ff_devvp; /* filesystem device vnode */
385 struct mount *ff_mnt; /* associated mount point */
386 ufs_daddr_t ff_blkno; /* fragment physical block number */
387 long ff_fragsize; /* size of fragment being deleted */
388 ino_t ff_inum; /* owning inode number */
389};
390
391/*
392 * A "freeblks" structure is attached to an "inodedep" when the
393 * corresponding file's length is reduced to zero. It records all
394 * the information needed to free the blocks of a file after its
395 * zero'ed inode has been written to disk.
396 */
397struct freeblks {
398 struct worklist fb_list; /* id_inowait or delayed worklist */
399 ino_t fb_previousinum; /* inode of previous owner of blocks */
400 struct vnode *fb_devvp; /* filesystem device vnode */
401 struct mount *fb_mnt; /* associated mount point */
402 off_t fb_oldsize; /* previous file size */
403 off_t fb_newsize; /* new file size */
404 int fb_chkcnt; /* used to check cnt of blks released */
405 uid_t fb_uid; /* uid of previous owner of blocks */
406 ufs_daddr_t fb_dblks[NDADDR]; /* direct blk ptrs to deallocate */
407 ufs_daddr_t fb_iblks[NIADDR]; /* indirect blk ptrs to deallocate */
408};
409
410/*
411 * A "freefile" structure is attached to an inode when its
412 * link count is reduced to zero. It marks the inode as free in
413 * the cylinder group map after the zero'ed inode has been written
414 * to disk and any associated blocks and fragments have been freed.
415 */
416struct freefile {
417 struct worklist fx_list; /* id_inowait or delayed worklist */
418 mode_t fx_mode; /* mode of inode */
419 ino_t fx_oldinum; /* inum of the unlinked file */
420 struct vnode *fx_devvp; /* filesystem device vnode */
421 struct mount *fx_mnt; /* associated mount point */
422};
423
424/*
425 * A "diradd" structure is linked to an "inodedep" id_inowait list when a
426 * new directory entry is allocated that references the inode described
427 * by "inodedep". When the inode itself is written (either the initial
428 * allocation for new inodes or with the increased link count for
429 * existing inodes), the COMPLETE flag is set in da_state. If the entry
430 * is for a newly allocated inode, the "inodedep" structure is associated
431 * with a bmsafemap which prevents the inode from being written to disk
432 * until the cylinder group has been updated. Thus the da_state COMPLETE
433 * flag cannot be set until the inode bitmap dependency has been removed.
434 * When creating a new file, it is safe to write the directory entry that
435 * claims the inode once the referenced inode has been written. Since
436 * writing the inode clears the bitmap dependencies, the DEPCOMPLETE flag
437 * in the diradd can be set unconditionally when creating a file. When
438 * creating a directory, there are two additional dependencies described by
439 * mkdir structures (see their description below). When these dependencies
440 * are resolved the DEPCOMPLETE flag is set in the diradd structure.
441 * If there are multiple links created to the same inode, there will be
442 * a separate diradd structure created for each link. The diradd is
443 * linked onto the pg_diraddhd list of the pagedep for the directory
444 * page that contains the entry. When a directory page is written,
445 * the pg_diraddhd list is traversed to rollback any entries that are
446 * not yet ready to be written to disk. If a directory entry is being
447 * changed (by rename) rather than added, the DIRCHG flag is set and
448 * the da_previous entry points to the entry that will be "removed"
449 * once the new entry has been committed. During rollback, entries
450 * with da_previous are replaced with the previous inode number rather
451 * than zero.
452 *
453 * The overlaying of da_pagedep and da_previous is done to keep the
454 * structure down to 32 bytes in size on a 32-bit machine. If a
455 * da_previous entry is present, the pointer to its pagedep is available
456 * in the associated dirrem entry. If the DIRCHG flag is set, the
457 * da_previous entry is valid; if not set the da_pagedep entry is valid.
458 * The DIRCHG flag never changes; it is set when the structure is created
459 * if appropriate and is never cleared.
460 */
461struct diradd {
462 struct worklist da_list; /* id_inowait or id_pendinghd list */
463# define da_state da_list.wk_state /* state of the new directory entry */
464 LIST_ENTRY(diradd) da_pdlist; /* pagedep holding directory block */
465 doff_t da_offset; /* offset of new dir entry in dir blk */
466 ino_t da_newinum; /* inode number for the new dir entry */
467 union {
468 struct dirrem *dau_previous; /* entry being replaced in dir change */
469 struct pagedep *dau_pagedep; /* pagedep dependency for addition */
470 } da_un;
471};
472#define da_previous da_un.dau_previous
473#define da_pagedep da_un.dau_pagedep
474
475/*
476 * Two "mkdir" structures are needed to track the additional dependencies
477 * associated with creating a new directory entry. Normally a directory
478 * addition can be committed as soon as the newly referenced inode has been
479 * written to disk with its increased link count. When a directory is
480 * created there are two additional dependencies: writing the directory
481 * data block containing the "." and ".." entries (MKDIR_BODY) and writing
482 * the parent inode with the increased link count for ".." (MKDIR_PARENT).
483 * These additional dependencies are tracked by two mkdir structures that
484 * reference the associated "diradd" structure. When they have completed,
485 * they set the DEPCOMPLETE flag on the diradd so that it knows that its
486 * extra dependencies have been completed. The md_state field is used only
487 * to identify which type of dependency the mkdir structure is tracking.
488 * It is not used in the mainline code for any purpose other than consistency
489 * checking. All the mkdir structures in the system are linked together on
490 * a list. This list is needed so that a diradd can find its associated
491 * mkdir structures and deallocate them if it is prematurely freed (as for
492 * example if a mkdir is immediately followed by a rmdir of the same directory).
493 * Here, the free of the diradd must traverse the list to find the associated
494 * mkdir structures that reference it. The deletion would be faster if the
495 * diradd structure were simply augmented to have two pointers that referenced
496 * the associated mkdir's. However, this would increase the size of the diradd
497 * structure from 32 to 64-bits to speed a very infrequent operation.
498 */
499struct mkdir {
500 struct worklist md_list; /* id_inowait or buffer holding dir */
501# define md_state md_list.wk_state /* type: MKDIR_PARENT or MKDIR_BODY */
502 struct diradd *md_diradd; /* associated diradd */
503 struct buf *md_buf; /* MKDIR_BODY: buffer holding dir */
504 LIST_ENTRY(mkdir) md_mkdirs; /* list of all mkdirs */
505};
506LIST_HEAD(mkdirlist, mkdir) mkdirlisthd;
507
508/*
509 * A "dirrem" structure describes an operation to decrement the link
510 * count on an inode. The dirrem structure is attached to the pg_dirremhd
511 * list of the pagedep for the directory page that contains the entry.
512 * It is processed after the directory page with the deleted entry has
513 * been written to disk.
514 *
515 * The overlaying of dm_pagedep and dm_dirinum is done to keep the
516 * structure down to 32 bytes in size on a 32-bit machine. It works
517 * because they are never used concurrently.
518 */
519struct dirrem {
520 struct worklist dm_list; /* delayed worklist */
521# define dm_state dm_list.wk_state /* state of the old directory entry */
522 LIST_ENTRY(dirrem) dm_next; /* pagedep's list of dirrem's */
523 struct mount *dm_mnt; /* associated mount point */
524 ino_t dm_oldinum; /* inum of the removed dir entry */
525 union {
526 struct pagedep *dmu_pagedep; /* pagedep dependency for remove */
527 ino_t dmu_dirinum; /* parent inode number (for rmdir) */
528 } dm_un;
529};
530#define dm_pagedep dm_un.dmu_pagedep
531#define dm_dirinum dm_un.dmu_dirinum
101#define ONWORKLIST 0x8000
102
103#define ALLCOMPLETE (ATTACHED | COMPLETE | DEPCOMPLETE)
104
105/*
106 * The workitem queue.
107 *
108 * It is sometimes useful and/or necessary to clean up certain dependencies
109 * in the background rather than during execution of an application process
110 * or interrupt service routine. To realize this, we append dependency
111 * structures corresponding to such tasks to a "workitem" queue. In a soft
112 * updates implementation, most pending workitems should not wait for more
113 * than a couple of seconds, so the filesystem syncer process awakens once
114 * per second to process the items on the queue.
115 */
116
117/* LIST_HEAD(workhead, worklist); -- declared in buf.h */
118
119/*
120 * Each request can be linked onto a work queue through its worklist structure.
121 * To avoid the need for a pointer to the structure itself, this structure
122 * MUST be declared FIRST in each type in which it appears! If more than one
123 * worklist is needed in the structure, then a wk_data field must be added
124 * and the macros below changed to use it.
125 */
126struct worklist {
127 LIST_ENTRY(worklist) wk_list; /* list of work requests */
128 unsigned short wk_type; /* type of request */
129 unsigned short wk_state; /* state flags */
130};
131#define WK_DATA(wk) ((void *)(wk))
132#define WK_PAGEDEP(wk) ((struct pagedep *)(wk))
133#define WK_INODEDEP(wk) ((struct inodedep *)(wk))
134#define WK_NEWBLK(wk) ((struct newblk *)(wk))
135#define WK_BMSAFEMAP(wk) ((struct bmsafemap *)(wk))
136#define WK_ALLOCDIRECT(wk) ((struct allocdirect *)(wk))
137#define WK_INDIRDEP(wk) ((struct indirdep *)(wk))
138#define WK_ALLOCINDIR(wk) ((struct allocindir *)(wk))
139#define WK_FREEFRAG(wk) ((struct freefrag *)(wk))
140#define WK_FREEBLKS(wk) ((struct freeblks *)(wk))
141#define WK_FREEFILE(wk) ((struct freefile *)(wk))
142#define WK_DIRADD(wk) ((struct diradd *)(wk))
143#define WK_MKDIR(wk) ((struct mkdir *)(wk))
144#define WK_DIRREM(wk) ((struct dirrem *)(wk))
145
146/*
147 * Various types of lists
148 */
149LIST_HEAD(dirremhd, dirrem);
150LIST_HEAD(diraddhd, diradd);
151LIST_HEAD(newblkhd, newblk);
152LIST_HEAD(inodedephd, inodedep);
153LIST_HEAD(allocindirhd, allocindir);
154LIST_HEAD(allocdirecthd, allocdirect);
155TAILQ_HEAD(allocdirectlst, allocdirect);
156
157/*
158 * The "pagedep" structure tracks the various dependencies related to
159 * a particular directory page. If a directory page has any dependencies,
160 * it will have a pagedep linked to its associated buffer. The
161 * pd_dirremhd list holds the list of dirrem requests which decrement
162 * inode reference counts. These requests are processed after the
163 * directory page with the corresponding zero'ed entries has been
164 * written. The pd_diraddhd list maintains the list of diradd requests
165 * which cannot be committed until their corresponding inode has been
166 * written to disk. Because a directory may have many new entries
167 * being created, several lists are maintained hashed on bits of the
168 * offset of the entry into the directory page to keep the lists from
169 * getting too long. Once a new directory entry has been cleared to
170 * be written, it is moved to the pd_pendinghd list. After the new
171 * entry has been written to disk it is removed from the pd_pendinghd
172 * list, any removed operations are done, and the dependency structure
173 * is freed.
174 */
175#define DAHASHSZ 6
176#define DIRADDHASH(offset) (((offset) >> 2) % DAHASHSZ)
177struct pagedep {
178 struct worklist pd_list; /* page buffer */
179# define pd_state pd_list.wk_state /* check for multiple I/O starts */
180 LIST_ENTRY(pagedep) pd_hash; /* hashed lookup */
181 struct mount *pd_mnt; /* associated mount point */
182 ino_t pd_ino; /* associated file */
183 ufs_lbn_t pd_lbn; /* block within file */
184 struct dirremhd pd_dirremhd; /* dirrem's waiting for page */
185 struct diraddhd pd_diraddhd[DAHASHSZ]; /* diradd dir entry updates */
186 struct diraddhd pd_pendinghd; /* directory entries awaiting write */
187};
188
189/*
190 * The "inodedep" structure tracks the set of dependencies associated
191 * with an inode. One task that it must manage is delayed operations
192 * (i.e., work requests that must be held until the inodedep's associated
193 * inode has been written to disk). Getting an inode from its incore
194 * state to the disk requires two steps to be taken by the filesystem
195 * in this order: first the inode must be copied to its disk buffer by
196 * the VOP_UPDATE operation; second the inode's buffer must be written
197 * to disk. To ensure that both operations have happened in the required
198 * order, the inodedep maintains two lists. Delayed operations are
199 * placed on the id_inowait list. When the VOP_UPDATE is done, all
200 * operations on the id_inowait list are moved to the id_bufwait list.
201 * When the buffer is written, the items on the id_bufwait list can be
202 * safely moved to the work queue to be processed. A second task of the
203 * inodedep structure is to track the status of block allocation within
204 * the inode. Each block that is allocated is represented by an
205 * "allocdirect" structure (see below). It is linked onto the id_newinoupdt
206 * list until both its contents and its allocation in the cylinder
207 * group map have been written to disk. Once these dependencies have been
208 * satisfied, it is removed from the id_newinoupdt list and any followup
209 * actions such as releasing the previous block or fragment are placed
210 * on the id_inowait list. When an inode is updated (a VOP_UPDATE is
211 * done), the "inodedep" structure is linked onto the buffer through
212 * its worklist. Thus, it will be notified when the buffer is about
213 * to be written and when it is done. At the update time, all the
214 * elements on the id_newinoupdt list are moved to the id_inoupdt list
215 * since those changes are now relevant to the copy of the inode in the
216 * buffer. Also at update time, the tasks on the id_inowait list are
217 * moved to the id_bufwait list so that they will be executed when
218 * the updated inode has been written to disk. When the buffer containing
219 * the inode is written to disk, any updates listed on the id_inoupdt
220 * list are rolled back as they are not yet safe. Following the write,
221 * the changes are once again rolled forward and any actions on the
222 * id_bufwait list are processed (since those actions are now safe).
223 * The entries on the id_inoupdt and id_newinoupdt lists must be kept
224 * sorted by logical block number to speed the calculation of the size
225 * of the rolled back inode (see explanation in initiate_write_inodeblock).
226 * When a directory entry is created, it is represented by a diradd.
227 * The diradd is added to the id_inowait list as it cannot be safely
228 * written to disk until the inode that it represents is on disk. After
229 * the inode is written, the id_bufwait list is processed and the diradd
230 * entries are moved to the id_pendinghd list where they remain until
231 * the directory block containing the name has been written to disk.
232 * The purpose of keeping the entries on the id_pendinghd list is so that
233 * the softdep_fsync function can find and push the inode's directory
234 * name(s) as part of the fsync operation for that file.
235 */
236struct inodedep {
237 struct worklist id_list; /* buffer holding inode block */
238# define id_state id_list.wk_state /* inode dependency state */
239 LIST_ENTRY(inodedep) id_hash; /* hashed lookup */
240 struct fs *id_fs; /* associated filesystem */
241 ino_t id_ino; /* dependent inode */
242 nlink_t id_nlinkdelta; /* saved effective link count */
243 struct dinode *id_savedino; /* saved dinode contents */
244 LIST_ENTRY(inodedep) id_deps; /* bmsafemap's list of inodedep's */
245 struct buf *id_buf; /* related bmsafemap (if pending) */
246 off_t id_savedsize; /* file size saved during rollback */
247 struct workhead id_pendinghd; /* entries awaiting directory write */
248 struct workhead id_bufwait; /* operations after inode written */
249 struct workhead id_inowait; /* operations waiting inode update */
250 struct allocdirectlst id_inoupdt; /* updates before inode written */
251 struct allocdirectlst id_newinoupdt; /* updates when inode written */
252};
253
254/*
255 * A "newblk" structure is attached to a bmsafemap structure when a block
256 * or fragment is allocated from a cylinder group. Its state is set to
257 * DEPCOMPLETE when its cylinder group map is written. It is consumed by
258 * an associated allocdirect or allocindir allocation which will attach
259 * themselves to the bmsafemap structure if the newblk's DEPCOMPLETE flag
260 * is not set (i.e., its cylinder group map has not been written).
261 */
262struct newblk {
263 LIST_ENTRY(newblk) nb_hash; /* hashed lookup */
264 struct fs *nb_fs; /* associated filesystem */
265 ufs_daddr_t nb_newblkno; /* allocated block number */
266 int nb_state; /* state of bitmap dependency */
267 LIST_ENTRY(newblk) nb_deps; /* bmsafemap's list of newblk's */
268 struct bmsafemap *nb_bmsafemap; /* associated bmsafemap */
269};
270
271/*
272 * A "bmsafemap" structure maintains a list of dependency structures
273 * that depend on the update of a particular cylinder group map.
274 * It has lists for newblks, allocdirects, allocindirs, and inodedeps.
275 * It is attached to the buffer of a cylinder group block when any of
276 * these things are allocated from the cylinder group. It is freed
277 * after the cylinder group map is written and the state of its
278 * dependencies are updated with DEPCOMPLETE to indicate that it has
279 * been processed.
280 */
281struct bmsafemap {
282 struct worklist sm_list; /* cylgrp buffer */
283 struct buf *sm_buf; /* associated buffer */
284 struct allocdirecthd sm_allocdirecthd; /* allocdirect deps */
285 struct allocindirhd sm_allocindirhd; /* allocindir deps */
286 struct inodedephd sm_inodedephd; /* inodedep deps */
287 struct newblkhd sm_newblkhd; /* newblk deps */
288};
289
290/*
291 * An "allocdirect" structure is attached to an "inodedep" when a new block
292 * or fragment is allocated and pointed to by the inode described by
293 * "inodedep". The worklist is linked to the buffer that holds the block.
294 * When the block is first allocated, it is linked to the bmsafemap
295 * structure associated with the buffer holding the cylinder group map
296 * from which it was allocated. When the cylinder group map is written
297 * to disk, ad_state has the DEPCOMPLETE flag set. When the block itself
298 * is written, the COMPLETE flag is set. Once both the cylinder group map
299 * and the data itself have been written, it is safe to write the inode
300 * that claims the block. If there was a previous fragment that had been
301 * allocated before the file was increased in size, the old fragment may
302 * be freed once the inode claiming the new block is written to disk.
303 * This ad_fragfree request is attached to the id_inowait list of the
304 * associated inodedep (pointed to by ad_inodedep) for processing after
305 * the inode is written.
306 */
307struct allocdirect {
308 struct worklist ad_list; /* buffer holding block */
309# define ad_state ad_list.wk_state /* block pointer state */
310 TAILQ_ENTRY(allocdirect) ad_next; /* inodedep's list of allocdirect's */
311 ufs_lbn_t ad_lbn; /* block within file */
312 ufs_daddr_t ad_newblkno; /* new value of block pointer */
313 ufs_daddr_t ad_oldblkno; /* old value of block pointer */
314 long ad_newsize; /* size of new block */
315 long ad_oldsize; /* size of old block */
316 LIST_ENTRY(allocdirect) ad_deps; /* bmsafemap's list of allocdirect's */
317 struct buf *ad_buf; /* cylgrp buffer (if pending) */
318 struct inodedep *ad_inodedep; /* associated inodedep */
319 struct freefrag *ad_freefrag; /* fragment to be freed (if any) */
320};
321
322/*
323 * A single "indirdep" structure manages all allocation dependencies for
324 * pointers in an indirect block. The up-to-date state of the indirect
325 * block is stored in ir_savedata. The set of pointers that may be safely
326 * written to the disk is stored in ir_safecopy. The state field is used
327 * only to track whether the buffer is currently being written (in which
328 * case it is not safe to update ir_safecopy). Ir_deplisthd contains the
329 * list of allocindir structures, one for each block that needs to be
330 * written to disk. Once the block and its bitmap allocation have been
331 * written the safecopy can be updated to reflect the allocation and the
332 * allocindir structure freed. If ir_state indicates that an I/O on the
333 * indirect block is in progress when ir_safecopy is to be updated, the
334 * update is deferred by placing the allocindir on the ir_donehd list.
335 * When the I/O on the indirect block completes, the entries on the
336 * ir_donehd list are processed by updating their corresponding ir_safecopy
337 * pointers and then freeing the allocindir structure.
338 */
339struct indirdep {
340 struct worklist ir_list; /* buffer holding indirect block */
341# define ir_state ir_list.wk_state /* indirect block pointer state */
342 caddr_t ir_saveddata; /* buffer cache contents */
343 struct buf *ir_savebp; /* buffer holding safe copy */
344 struct allocindirhd ir_donehd; /* done waiting to update safecopy */
345 struct allocindirhd ir_deplisthd; /* allocindir deps for this block */
346};
347
348/*
349 * An "allocindir" structure is attached to an "indirdep" when a new block
350 * is allocated and pointed to by the indirect block described by the
351 * "indirdep". The worklist is linked to the buffer that holds the new block.
352 * When the block is first allocated, it is linked to the bmsafemap
353 * structure associated with the buffer holding the cylinder group map
354 * from which it was allocated. When the cylinder group map is written
355 * to disk, ai_state has the DEPCOMPLETE flag set. When the block itself
356 * is written, the COMPLETE flag is set. Once both the cylinder group map
357 * and the data itself have been written, it is safe to write the entry in
358 * the indirect block that claims the block; the "allocindir" dependency
359 * can then be freed as it is no longer applicable.
360 */
361struct allocindir {
362 struct worklist ai_list; /* buffer holding indirect block */
363# define ai_state ai_list.wk_state /* indirect block pointer state */
364 LIST_ENTRY(allocindir) ai_next; /* indirdep's list of allocindir's */
365 int ai_offset; /* pointer offset in indirect block */
366 ufs_daddr_t ai_newblkno; /* new block pointer value */
367 ufs_daddr_t ai_oldblkno; /* old block pointer value */
368 struct freefrag *ai_freefrag; /* block to be freed when complete */
369 struct indirdep *ai_indirdep; /* address of associated indirdep */
370 LIST_ENTRY(allocindir) ai_deps; /* bmsafemap's list of allocindir's */
371 struct buf *ai_buf; /* cylgrp buffer (if pending) */
372};
373
374/*
375 * A "freefrag" structure is attached to an "inodedep" when a previously
376 * allocated fragment is replaced with a larger fragment, rather than extended.
377 * The "freefrag" structure is constructed and attached when the replacement
378 * block is first allocated. It is processed after the inode claiming the
379 * bigger block that replaces it has been written to disk. Note that the
380 * ff_state field is is used to store the uid, so may lose data. However,
381 * the uid is used only in printing an error message, so is not critical.
382 * Keeping it in a short keeps the data structure down to 32 bytes.
383 */
384struct freefrag {
385 struct worklist ff_list; /* id_inowait or delayed worklist */
386# define ff_state ff_list.wk_state /* owning user; should be uid_t */
387 struct vnode *ff_devvp; /* filesystem device vnode */
388 struct mount *ff_mnt; /* associated mount point */
389 ufs_daddr_t ff_blkno; /* fragment physical block number */
390 long ff_fragsize; /* size of fragment being deleted */
391 ino_t ff_inum; /* owning inode number */
392};
393
394/*
395 * A "freeblks" structure is attached to an "inodedep" when the
396 * corresponding file's length is reduced to zero. It records all
397 * the information needed to free the blocks of a file after its
398 * zero'ed inode has been written to disk.
399 */
400struct freeblks {
401 struct worklist fb_list; /* id_inowait or delayed worklist */
402 ino_t fb_previousinum; /* inode of previous owner of blocks */
403 struct vnode *fb_devvp; /* filesystem device vnode */
404 struct mount *fb_mnt; /* associated mount point */
405 off_t fb_oldsize; /* previous file size */
406 off_t fb_newsize; /* new file size */
407 int fb_chkcnt; /* used to check cnt of blks released */
408 uid_t fb_uid; /* uid of previous owner of blocks */
409 ufs_daddr_t fb_dblks[NDADDR]; /* direct blk ptrs to deallocate */
410 ufs_daddr_t fb_iblks[NIADDR]; /* indirect blk ptrs to deallocate */
411};
412
413/*
414 * A "freefile" structure is attached to an inode when its
415 * link count is reduced to zero. It marks the inode as free in
416 * the cylinder group map after the zero'ed inode has been written
417 * to disk and any associated blocks and fragments have been freed.
418 */
419struct freefile {
420 struct worklist fx_list; /* id_inowait or delayed worklist */
421 mode_t fx_mode; /* mode of inode */
422 ino_t fx_oldinum; /* inum of the unlinked file */
423 struct vnode *fx_devvp; /* filesystem device vnode */
424 struct mount *fx_mnt; /* associated mount point */
425};
426
427/*
428 * A "diradd" structure is linked to an "inodedep" id_inowait list when a
429 * new directory entry is allocated that references the inode described
430 * by "inodedep". When the inode itself is written (either the initial
431 * allocation for new inodes or with the increased link count for
432 * existing inodes), the COMPLETE flag is set in da_state. If the entry
433 * is for a newly allocated inode, the "inodedep" structure is associated
434 * with a bmsafemap which prevents the inode from being written to disk
435 * until the cylinder group has been updated. Thus the da_state COMPLETE
436 * flag cannot be set until the inode bitmap dependency has been removed.
437 * When creating a new file, it is safe to write the directory entry that
438 * claims the inode once the referenced inode has been written. Since
439 * writing the inode clears the bitmap dependencies, the DEPCOMPLETE flag
440 * in the diradd can be set unconditionally when creating a file. When
441 * creating a directory, there are two additional dependencies described by
442 * mkdir structures (see their description below). When these dependencies
443 * are resolved the DEPCOMPLETE flag is set in the diradd structure.
444 * If there are multiple links created to the same inode, there will be
445 * a separate diradd structure created for each link. The diradd is
446 * linked onto the pg_diraddhd list of the pagedep for the directory
447 * page that contains the entry. When a directory page is written,
448 * the pg_diraddhd list is traversed to rollback any entries that are
449 * not yet ready to be written to disk. If a directory entry is being
450 * changed (by rename) rather than added, the DIRCHG flag is set and
451 * the da_previous entry points to the entry that will be "removed"
452 * once the new entry has been committed. During rollback, entries
453 * with da_previous are replaced with the previous inode number rather
454 * than zero.
455 *
456 * The overlaying of da_pagedep and da_previous is done to keep the
457 * structure down to 32 bytes in size on a 32-bit machine. If a
458 * da_previous entry is present, the pointer to its pagedep is available
459 * in the associated dirrem entry. If the DIRCHG flag is set, the
460 * da_previous entry is valid; if not set the da_pagedep entry is valid.
461 * The DIRCHG flag never changes; it is set when the structure is created
462 * if appropriate and is never cleared.
463 */
464struct diradd {
465 struct worklist da_list; /* id_inowait or id_pendinghd list */
466# define da_state da_list.wk_state /* state of the new directory entry */
467 LIST_ENTRY(diradd) da_pdlist; /* pagedep holding directory block */
468 doff_t da_offset; /* offset of new dir entry in dir blk */
469 ino_t da_newinum; /* inode number for the new dir entry */
470 union {
471 struct dirrem *dau_previous; /* entry being replaced in dir change */
472 struct pagedep *dau_pagedep; /* pagedep dependency for addition */
473 } da_un;
474};
475#define da_previous da_un.dau_previous
476#define da_pagedep da_un.dau_pagedep
477
478/*
479 * Two "mkdir" structures are needed to track the additional dependencies
480 * associated with creating a new directory entry. Normally a directory
481 * addition can be committed as soon as the newly referenced inode has been
482 * written to disk with its increased link count. When a directory is
483 * created there are two additional dependencies: writing the directory
484 * data block containing the "." and ".." entries (MKDIR_BODY) and writing
485 * the parent inode with the increased link count for ".." (MKDIR_PARENT).
486 * These additional dependencies are tracked by two mkdir structures that
487 * reference the associated "diradd" structure. When they have completed,
488 * they set the DEPCOMPLETE flag on the diradd so that it knows that its
489 * extra dependencies have been completed. The md_state field is used only
490 * to identify which type of dependency the mkdir structure is tracking.
491 * It is not used in the mainline code for any purpose other than consistency
492 * checking. All the mkdir structures in the system are linked together on
493 * a list. This list is needed so that a diradd can find its associated
494 * mkdir structures and deallocate them if it is prematurely freed (as for
495 * example if a mkdir is immediately followed by a rmdir of the same directory).
496 * Here, the free of the diradd must traverse the list to find the associated
497 * mkdir structures that reference it. The deletion would be faster if the
498 * diradd structure were simply augmented to have two pointers that referenced
499 * the associated mkdir's. However, this would increase the size of the diradd
500 * structure from 32 to 64-bits to speed a very infrequent operation.
501 */
502struct mkdir {
503 struct worklist md_list; /* id_inowait or buffer holding dir */
504# define md_state md_list.wk_state /* type: MKDIR_PARENT or MKDIR_BODY */
505 struct diradd *md_diradd; /* associated diradd */
506 struct buf *md_buf; /* MKDIR_BODY: buffer holding dir */
507 LIST_ENTRY(mkdir) md_mkdirs; /* list of all mkdirs */
508};
509LIST_HEAD(mkdirlist, mkdir) mkdirlisthd;
510
511/*
512 * A "dirrem" structure describes an operation to decrement the link
513 * count on an inode. The dirrem structure is attached to the pg_dirremhd
514 * list of the pagedep for the directory page that contains the entry.
515 * It is processed after the directory page with the deleted entry has
516 * been written to disk.
517 *
518 * The overlaying of dm_pagedep and dm_dirinum is done to keep the
519 * structure down to 32 bytes in size on a 32-bit machine. It works
520 * because they are never used concurrently.
521 */
522struct dirrem {
523 struct worklist dm_list; /* delayed worklist */
524# define dm_state dm_list.wk_state /* state of the old directory entry */
525 LIST_ENTRY(dirrem) dm_next; /* pagedep's list of dirrem's */
526 struct mount *dm_mnt; /* associated mount point */
527 ino_t dm_oldinum; /* inum of the removed dir entry */
528 union {
529 struct pagedep *dmu_pagedep; /* pagedep dependency for remove */
530 ino_t dmu_dirinum; /* parent inode number (for rmdir) */
531 } dm_un;
532};
533#define dm_pagedep dm_un.dmu_pagedep
534#define dm_dirinum dm_un.dmu_dirinum