Add logging to ext4_mkfs.
authorCarl Hetherington <cth@carlh.net>
Wed, 18 Jan 2023 23:49:42 +0000 (00:49 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 19 Jan 2023 21:24:04 +0000 (22:24 +0100)
blockdev/linux/file_dev.c
src/ext4_blockdev.c
src/ext4_mkfs.c

index 4e4cc6780625a5a5186138ffc64733ae5f88bfb3..79f9d692ef07b6cd548ccf7a18ef55a6f8b9bcb0 100644 (file)
@@ -149,16 +149,20 @@ static void drop_cache(void)
 static int file_dev_bwrite(struct ext4_blockdev *bdev, const void *buf,
                          uint64_t blk_id, uint32_t blk_cnt)
 {
+       printf("lseek() %ld\n", blk_id * bdev->bdif->ph_bsize);
        if (lseek(dev_file, blk_id * bdev->bdif->ph_bsize, SEEK_SET) < 0) {
                printf("fseeko failed %d\n", errno);
                return EIO;
        }
+       printf("lseek() ok\n");
        if (!blk_cnt)
                return EOK;
+       printf("write() %d\n", bdev->bdif->ph_bsize * blk_cnt);
        if (write(dev_file, buf, bdev->bdif->ph_bsize * blk_cnt) < 0) {
                printf("write failed %d\n", errno);
                return EIO;
        }
+       printf("write() ok\n");
 
        drop_cache();
        return EOK;
index c01093ad9c98fdeabe4ad4d9862704ec2ca8b4d4..fba79e4769b19716240df72ea445451d8ffea433 100644 (file)
@@ -78,10 +78,12 @@ static int ext4_bdif_bread(struct ext4_blockdev *bdev, void *buf,
 static int ext4_bdif_bwrite(struct ext4_blockdev *bdev, const void *buf,
                            uint64_t blk_id, uint32_t blk_cnt)
 {
+       ext4_dbg(DEBUG_BLOCKDEV, DBG_NONE "Writing blk_id=%lu cnt=%d", blk_id, blk_cnt);
        ext4_bdif_lock(bdev);
        int r = bdev->bdif->bwrite(bdev, buf, blk_id, blk_cnt);
        bdev->bdif->bwrite_ctr++;
        ext4_bdif_unlock(bdev);
+       ext4_dbg(DEBUG_BLOCKDEV, DBG_NONE "Result was %d", r);
        return r;
 }
 
index 4765926a845fa53f0d0a66c4162e41669e7b15f3..a2a1a346f5941478ccc79954d3854988360ae1fb 100644 (file)
@@ -317,6 +317,7 @@ static int write_bgroups(struct ext4_fs *fs, struct ext4_blockdev *bd, struct fs
        uint64_t sb_free_blk = 0;
 
        for (uint32_t i = 0; i < aux_info->groups; i++) {
+               ext4_dbg(DEBUG_MKFS, DBG_NONE "Writing aux_info group %d of %d", i, aux_info->groups);
                uint64_t bg_start_block = aux_info->first_data_block +
                        aux_info->first_data_block + i * info->blocks_per_group;
                uint32_t blk_off = 0;
@@ -375,6 +376,7 @@ static int write_bgroups(struct ext4_fs *fs, struct ext4_blockdev *bd, struct fs
        int r = EOK;
 
        for (uint32_t i = 0; i < aux_info->groups; i++) {
+               ext4_dbg(DEBUG_MKFS, DBG_NONE "Writing block group header %d of %d", i, aux_info->groups);
                if (progress) {
                        progress(progress_context, (float) i / aux_info->groups);
                }
@@ -480,10 +482,12 @@ static int mkfs_init(struct ext4_fs *fs, struct ext4_blockdev *bd, struct ext4_m
        fill_sb(&aux_info, info);
        memcpy(&fs->sb, aux_info.sb, sizeof(struct ext4_sblock));
 
+       ext4_dbg(DEBUG_MKFS, DBG_NONE "mkfs_init: write_bgroups");
        r = write_bgroups(fs, bd, &aux_info, info, progress, progress_context);
        if (r != EOK)
                goto Finish;
 
+       ext4_dbg(DEBUG_MKFS, DBG_NONE "mkfs_init: write_sblocks");
        r = write_sblocks(bd, &aux_info, info);
        if (r != EOK)
                goto Finish;
@@ -665,6 +669,10 @@ int ext4_mkfs(struct ext4_fs *fs, struct ext4_blockdev *bd,
 {
        int r;
 
+       ext4_dbg(DEBUG_MKFS, DBG_NONE "ext4_mkfs start");
+
+       ext4_dbg(DEBUG_MKFS, DBG_NONE "ext4_block_init");
+
        r = ext4_block_init(bd);
        if (r != EOK)
                return r;
@@ -771,16 +779,22 @@ int ext4_mkfs(struct ext4_fs *fs, struct ext4_blockdev *bd,
        memset(&bc, 0, sizeof(struct ext4_bcache));
        ext4_block_set_lb_size(bd, info->block_size);
 
+       ext4_dbg(DEBUG_MKFS, DBG_NONE "ext4_bcache_init_dynamic");
+
        r = ext4_bcache_init_dynamic(&bc, CONFIG_BLOCK_DEV_CACHE_SIZE,
                                      info->block_size);
        if (r != EOK)
                goto block_fini;
 
+       ext4_dbg(DEBUG_MKFS, DBG_NONE "ext4_block_bind_bcache");
+
        /*Bind block cache to block device*/
        r = ext4_block_bind_bcache(bd, &bc);
        if (r != EOK)
                goto cache_fini;
 
+       ext4_dbg(DEBUG_MKFS, DBG_NONE "ext4_block_cache_write_back");
+
        r = ext4_block_cache_write_back(bd, 1);
        if (r != EOK)
                goto cache_fini;
@@ -788,34 +802,49 @@ int ext4_mkfs(struct ext4_fs *fs, struct ext4_blockdev *bd,
        fs->bdev = bd;
        fs->read_only = false;
 
+       ext4_dbg(DEBUG_MKFS, DBG_NONE "mkfs_init");
+
        r = mkfs_init(fs, bd, info, progress, progress_context);
        if (r != EOK)
                goto cache_fini;
 
+       ext4_dbg(DEBUG_MKFS, DBG_NONE "ext4_fs_init");
+
        r = ext4_fs_init(fs, bd, false);
        if (r != EOK)
                goto cache_fini;
 
+       ext4_dbg(DEBUG_MKFS, DBG_NONE "alloc_inodes");
+
        r = alloc_inodes(fs);
        if (r != EOK)
                goto fs_fini;
 
+       ext4_dbg(DEBUG_MKFS, DBG_NONE "create_dirs");
+
        r = create_dirs(fs);
        if (r != EOK)
                goto fs_fini;
 
+       ext4_dbg(DEBUG_MKFS, DBG_NONE "create_journal_inode");
+
        r = create_journal_inode(fs, info);
        if (r != EOK)
                goto fs_fini;
 
        fs_fini:
+       ext4_dbg(DEBUG_MKFS, DBG_NONE "ext4_fs_fini");
        ext4_fs_fini(fs);
 
        cache_fini:
+       ext4_dbg(DEBUG_MKFS, DBG_NONE "ext4_block_cache_write_back");
        ext4_block_cache_write_back(bd, 0);
+
+       ext4_dbg(DEBUG_MKFS, DBG_NONE "ext4_bcache_fini_dynamic");
        ext4_bcache_fini_dynamic(&bc);
 
        block_fini:
+       ext4_dbg(DEBUG_MKFS, DBG_NONE "ext4_block_fini");
        ext4_block_fini(bd);
 
        return r;