Whamcloud - gitweb
Use a centrally stored current time for "now" which
authorTheodore Ts'o <tytso@mit.edu>
Thu, 14 Apr 2005 18:07:53 +0000 (14:07 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 14 Apr 2005 18:07:53 +0000 (14:07 -0400)
can be overridden using the E2FSCK_TIME environment
variable, for better reproducibility for regression tests.

e2fsck/ChangeLog
e2fsck/e2fsck.c
e2fsck/e2fsck.h
e2fsck/journal.c
e2fsck/pass1.c
e2fsck/pass1b.c
e2fsck/pass2.c
e2fsck/pass3.c
e2fsck/pass4.c
e2fsck/super.c
e2fsck/unix.c

index a4e3cf3..7317628 100644 (file)
@@ -1,3 +1,11 @@
+2005-04-14  Theodore Ts'o  <tytso@mit.edu>
+
+       * e2fsck.c, e2fsck.h, journal.c, pass1.c, pass1b.c, pass2.c,
+               pass3.c, pass4.c, super.c, unix.c: Use a centrally stored
+               current time for "now" which can be overridden using the
+               E2FSCK_TIME environment variable, for better
+               reproducibility for regression tests.
+
 2005-04-06  Theodore Ts'o  <tytso@mit.edu>
 
        * pass1.c (e2fsck_pass1): If the superblock last mount time (not
index 2a84c51..7d2ccf6 100644 (file)
@@ -21,6 +21,7 @@ errcode_t e2fsck_allocate_context(e2fsck_t *ret)
 {
        e2fsck_t        context;
        errcode_t       retval;
+       char            *time_env;
 
        retval = ext2fs_get_mem(sizeof(struct e2fsck_struct), &context);
        if (retval)
@@ -30,6 +31,12 @@ errcode_t e2fsck_allocate_context(e2fsck_t *ret)
 
        context->process_inode_size = 256;
        context->ext_attr_ver = 2;
+       
+       time_env = getenv("E2FSCK_TIME");
+       if (time_env)
+               context->now = strtoul(time_env, NULL, 0);
+       else
+               context->now = time(0);
 
        *ret = context;
        return 0;
index 6dec935..898b9a3 100644 (file)
@@ -322,6 +322,8 @@ struct e2fsck_struct {
        int fs_ext_attr_inodes;
        int fs_ext_attr_blocks;
 
+       time_t now;
+
        int ext_attr_ver;
 
        /*
index eb4b38d..a5f156c 100644 (file)
@@ -939,7 +939,7 @@ void e2fsck_move_ext3_journal(e2fsck_t ctx)
        ext2fs_mark_super_dirty(fs);
        fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
        inode.i_links_count = 0;
-       inode.i_dtime = time(0);
+       inode.i_dtime = ctx->now;
        if ((retval = ext2fs_write_inode(fs, ino, &inode)) != 0)
                goto err_out;
 
index 33729ee..4595cbc 100644 (file)
@@ -597,7 +597,7 @@ void e2fsck_pass1(e2fsck_t ctx)
                         */
                        if (!LINUX_S_ISDIR(inode->i_mode)) {
                                if (fix_problem(ctx, PR_1_ROOT_NO_DIR, &pctx)) {
-                                       inode->i_dtime = time(0);
+                                       inode->i_dtime = ctx->now;
                                        inode->i_links_count = 0;
                                        ext2fs_icount_store(ctx->inode_link_info,
                                                            ino, 0);
@@ -691,7 +691,7 @@ void e2fsck_pass1(e2fsck_t ctx)
                    inode->i_dtime < ctx->fs->super->s_inodes_count) {
                        if (fix_problem(ctx, PR_1_LOW_DTIME, &pctx)) {
                                inode->i_dtime = inode->i_links_count ?
-                                       0 : time(0);
+                                       0 : ctx->now;
                                e2fsck_write_inode(ctx, ino, inode,
                                                   "pass1");
                        }
@@ -705,7 +705,7 @@ void e2fsck_pass1(e2fsck_t ctx)
                        if (!inode->i_dtime && inode->i_mode) {
                                if (fix_problem(ctx,
                                            PR_1_ZERO_DTIME, &pctx)) {
-                                       inode->i_dtime = time(0);
+                                       inode->i_dtime = ctx->now;
                                        e2fsck_write_inode(ctx, ino, inode,
                                                           "pass1");
                                }
@@ -876,6 +876,11 @@ void e2fsck_pass1(e2fsck_t ctx)
                        ctx->flags |= E2F_FLAG_ABORT;
                        return;
                }
+               e2fsck_read_inode(ctx, EXT2_RESIZE_INO, inode,
+                                 "recreate inode");
+               inode->i_mtime = ctx->now;
+               e2fsck_write_inode(ctx, EXT2_RESIZE_INO, inode, 
+                                  "recreate inode");
                fs->block_map = save_bmap;
                ctx->flags &= ~E2F_FLAG_RESIZE_INODE;
        }
@@ -1422,7 +1427,7 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx,
        if (pb.clear) {
                inode->i_links_count = 0;
                ext2fs_icount_store(ctx->inode_link_info, ino, 0);
-               inode->i_dtime = time(0);
+               inode->i_dtime = ctx->now;
                dirty_inode++;
                ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino);
                ext2fs_unmark_inode_bitmap(ctx->inode_reg_map, ino);
@@ -1455,7 +1460,7 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx,
                if (fix_problem(ctx, PR_1_ZERO_LENGTH_DIR, pctx)) {
                        inode->i_links_count = 0;
                        ext2fs_icount_store(ctx->inode_link_info, ino, 0);
-                       inode->i_dtime = time(0);
+                       inode->i_dtime = ctx->now;
                        dirty_inode++;
                        ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino);
                        ext2fs_unmark_inode_bitmap(ctx->inode_reg_map, ino);
index 527ead8..733c027 100644 (file)
@@ -595,7 +595,7 @@ static void delete_file(e2fsck_t ctx, ext2_ino_t ino,
        /* Inode may have changed by block_iterate, so reread it */
        e2fsck_read_inode(ctx, ino, &inode, "delete_file");
        inode.i_links_count = 0;
-       inode.i_dtime = time(0);
+       inode.i_dtime = ctx->now;
        if (inode.i_file_acl &&
            (fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR)) {
                count = 1;
index 69599ff..52fdcba 100644 (file)
@@ -1097,7 +1097,7 @@ static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf)
        ext2fs_icount_store(ctx->inode_link_info, ino, 0);
        e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode");
        inode.i_links_count = 0;
-       inode.i_dtime = time(0);
+       inode.i_dtime = ctx->now;
        e2fsck_write_inode(ctx, ino, &inode, "deallocate_inode");
        clear_problem_context(&pctx);
        pctx.ino = ino;
index a92c890..66ffc46 100644 (file)
@@ -222,7 +222,7 @@ static void check_root(e2fsck_t ctx)
        memset(&inode, 0, sizeof(inode));
        inode.i_mode = 040755;
        inode.i_size = fs->blocksize;
-       inode.i_atime = inode.i_ctime = inode.i_mtime = time(0);
+       inode.i_atime = inode.i_ctime = inode.i_mtime = ctx->now;
        inode.i_links_count = 2;
        inode.i_blocks = fs->blocksize / 512;
        inode.i_block[0] = blk;
@@ -470,7 +470,7 @@ ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix)
        memset(&inode, 0, sizeof(inode));
        inode.i_mode = 040700;
        inode.i_size = fs->blocksize;
-       inode.i_atime = inode.i_ctime = inode.i_mtime = time(0);
+       inode.i_atime = inode.i_ctime = inode.i_mtime = ctx->now;
        inode.i_links_count = 2;
        inode.i_blocks = fs->blocksize / 512;
        inode.i_block[0] = blk;
index a9e49f1..985e8f6 100644 (file)
@@ -45,7 +45,7 @@ static int disconnect_inode(e2fsck_t ctx, ext2_ino_t i)
                if (fix_problem(ctx, PR_4_ZERO_LEN_INODE, &pctx)) {
                        ext2fs_icount_store(ctx->inode_link_info, i, 0);
                        inode.i_links_count = 0;
-                       inode.i_dtime = time(0);
+                       inode.i_dtime = ctx->now;
                        e2fsck_write_inode(ctx, i, &inode,
                                           "disconnect_inode");
                        /*
index 294cd80..0855fb5 100644 (file)
@@ -298,7 +298,7 @@ static int release_orphan_inodes(e2fsck_t ctx)
                if (!inode.i_links_count) {
                        ext2fs_inode_alloc_stats2(fs, ino, -1,
                                                  LINUX_S_ISDIR(inode.i_mode));
-                       inode.i_dtime = time(0);
+                       inode.i_dtime = ctx->now;
                } else {
                        inode.i_dtime = 0;
                }
@@ -346,7 +346,7 @@ void check_resize_inode(e2fsck_t ctx)
                }
        }
 
-       /* Read the resizde inode */
+       /* Read the resize inode */
        pctx.ino = EXT2_RESIZE_INO;
        retval = ext2fs_read_inode(fs, EXT2_RESIZE_INO, &inode);
        if (retval) {
index a8ac53d..2b6e476 100644 (file)
@@ -256,7 +256,6 @@ static void check_if_skip(e2fsck_t ctx)
        unsigned int reason_arg = 0;
        long next_check;
        int batt = is_on_batt();
-       time_t now = time(0);
        
        if ((ctx->options & E2F_OPT_FORCE) || bad_blocks_file ||
            cflag || swapfs)
@@ -276,11 +275,11 @@ static void check_if_skip(e2fsck_t ctx)
                             (unsigned) fs->super->s_max_mnt_count*2))
                        reason = 0;
        } else if (fs->super->s_checkinterval &&
-                  ((now - fs->super->s_lastcheck) >= 
+                  ((ctx->now - fs->super->s_lastcheck) >= 
                    fs->super->s_checkinterval)) {
                reason = _(" has gone %u days without being checked");
-               reason_arg = (now - fs->super->s_lastcheck)/(3600*24);
-               if (batt && ((now - fs->super->s_lastcheck) < 
+               reason_arg = (ctx->now - fs->super->s_lastcheck)/(3600*24);
+               if (batt && ((ctx->now - fs->super->s_lastcheck) < 
                             fs->super->s_checkinterval*2))
                        reason = 0;
        }
@@ -302,7 +301,7 @@ static void check_if_skip(e2fsck_t ctx)
                        next_check = 1;
        }
        if (fs->super->s_checkinterval &&
-           ((now - fs->super->s_lastcheck) >= fs->super->s_checkinterval))
+           ((ctx->now - fs->super->s_lastcheck) >= fs->super->s_checkinterval))
                next_check = 1;
        if (next_check <= 5) {
                if (next_check == 1)
@@ -1155,7 +1154,7 @@ restart:
                        } else
                                sb->s_state &= ~EXT2_VALID_FS;
                        sb->s_mnt_count = 0;
-                       sb->s_lastcheck = time(NULL);
+                       sb->s_lastcheck = ctx->now;
                        ext2fs_mark_super_dirty(fs);
                }
        }