Author: pfg
Date: Tue Jun  7 14:37:43 2016
New Revision: 301548
URL: https://svnweb.freebsd.org/changeset/base/301548

Log:
  ext2fs: cleanup generation number management.
  
  Ext2/3/4 manages generation numbers differently than UFS so adopt
  some rules that should work well. When allocating a new inode,
  make sure we generate a "good" random value specifically avoiding
  zero.
  
  Don't interfere with the numbers that are already generated in
  the filesystem: ext2fs doesn't have the backwards compatibility
  issues  where there were no generation numbers.
  
  Reviewed by:  kevlo
  MFC after:    1 week

Modified:
  head/sys/fs/ext2fs/ext2_alloc.c
  head/sys/fs/ext2fs/ext2_vfsops.c

Modified: head/sys/fs/ext2fs/ext2_alloc.c
==============================================================================
--- head/sys/fs/ext2fs/ext2_alloc.c     Tue Jun  7 14:16:10 2016        
(r301547)
+++ head/sys/fs/ext2fs/ext2_alloc.c     Tue Jun  7 14:37:43 2016        
(r301548)
@@ -407,9 +407,11 @@ ext2_valloc(struct vnode *pvp, int mode,
 
        /*
         * Set up a new generation number for this inode.
+        * Avoid zero values.
         */
-       while (ip->i_gen == 0 || ++ip->i_gen == 0)
+       do {
                ip->i_gen = arc4random();
+       } while ( ip->i_gen == 0);
 
        vfs_timestamp(&ts);
        ip->i_birthtime = ts.tv_sec;

Modified: head/sys/fs/ext2fs/ext2_vfsops.c
==============================================================================
--- head/sys/fs/ext2fs/ext2_vfsops.c    Tue Jun  7 14:16:10 2016        
(r301547)
+++ head/sys/fs/ext2fs/ext2_vfsops.c    Tue Jun  7 14:37:43 2016        
(r301548)
@@ -993,16 +993,6 @@ ext2_vget(struct mount *mp, ino_t ino, i
         * Finish inode initialization.
         */
 
-       /*
-        * Set up a generation number for this inode if it does not
-        * already have one. This should only happen on old filesystems.
-        */
-       if (ip->i_gen == 0) {
-               while (ip->i_gen == 0)
-                       ip->i_gen = arc4random();
-               if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
-                       ip->i_flag |= IN_MODIFIED;
-       }
        *vpp = vp;
        return (0);
 }
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to