The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/ufs/ffs/softdep.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: ced84f942d1be1fcdf2dc355b24c568b


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.