Browse Source

Debug system refactoring (prefixes & flags)

pull/11/head
gkostka 9 years ago
parent
commit
aff43c4a6a
  1. 2
      blockdev/test_lwext4.c
  2. 4
      lwext4/ext4_bcache.c
  3. 19
      lwext4/ext4_debug.c
  4. 119
      lwext4/ext4_debug.h
  5. 182
      lwext4/ext4_fs.c

2
blockdev/test_lwext4.c

@ -350,7 +350,7 @@ bool test_lwext4_mount(struct ext4_blockdev *bdev, struct ext4_bcache *bcache)
return false;
}
ext4_dmask_set(EXT4_DEBUG_ALL);
ext4_dmask_set(DEBUG_ALL);
r = ext4_device_register(bd, bc ? bc : 0, "ext4_fs");
if (r != EOK) {

4
lwext4/ext4_bcache.c

@ -166,8 +166,8 @@ int ext4_bcache_alloc(struct ext4_bcache *bc, struct ext4_block *b,
return EOK;
}
ext4_dprintf(EXT4_DEBUG_BCACHE,
"ext4_bcache_alloc: FAIL, unable to alloc block cache!\n");
ext4_dbg(DEBUG_BCACHE, DBG_ERROR
"unable to alloc block cache!\n");
return ENOMEM;
}

19
lwext4/ext4_debug.c

@ -40,11 +40,24 @@
#include <stdarg.h>
#include <stdio.h>
static uint32_t __dbg_mask__;
static uint32_t debug_mask;
void ext4_dmask_set(uint32_t m)
{
debug_mask |= m;
}
void ext4_dmask_clr(uint32_t m)
{
debug_mask &= ~m;
}
uint32_t ext4_dmask_get(void)
{
return debug_mask;
}
void ext4_dmask_set(uint32_t m) { __dbg_mask__ = m; }
uint32_t ext4_dmask_get(void) { return __dbg_mask__; }
/**
* @}

119
lwext4/ext4_debug.h

@ -47,70 +47,101 @@
#include <stdint.h>
#include <stdio.h>
/**@brief Debug mask: ext4_blockdev.c*/
#define EXT4_DEBUG_BLOCKDEV (1 << 0)
/**@brief Debug mask: ext4_fs.c*/
#define EXT4_DEBUG_FS (1 << 1)
/**@brief Debug mask: ext4_balloc.c*/
#define EXT4_DEBUG_BALLOC (1 << 2)
/**@brief Debug mask: ext4_bitmap.c*/
#define EXT4_DEBUG_BITMAP (1 << 3)
/**@brief Debug mask: ext4_dir_idx.c*/
#define EXT4_DEBUG_DIR_IDX (1 << 4)
/**@brief Debug mask: ext4_dir.c*/
#define EXT4_DEBUG_DIR (1 << 5)
/**@brief Debug mask: ext4_ialloc.c*/
#define EXT4_DEBUG_IALLOC (1 << 6)
/**@brief Debug mask: ext4_inode.c*/
#define EXT4_DEBUG_INODE (1 << 7)
/**@brief Debug mask: ext4_super.c*/
#define EXT4_DEBUG_SUPER (1 << 8)
/**@brief Debug mask: ext4_bcache.c*/
#define EXT4_DEBUG_BCACHE (1 << 9)
/**@brief Debug mask: ext4_extents.c*/
#define EXT4_DEBUG_EXTENTS (1 << 10)
/**@brief All debug printf enabled.*/
#define EXT4_DEBUG_ALL (0xFFFFFFFF)
/**@brief Global mask debug settings.
#define DEBUG_BALLOC (1 << 0)
#define DEBUG_BCACHE (1 << 1)
#define DEBUG_BITMAP (1 << 2)
#define DEBUG_BLOCK_GROUP (1 << 3)
#define DEBUG_BLOCKDEV (1 << 4)
#define DEBUG_DIR_IDX (1 << 5)
#define DEBUG_DIR (1 << 6)
#define DEBUG_EXTENT (1 << 7)
#define DEBUG_FS (1 << 8)
#define DEBUG_HASH (1 << 9)
#define DEBUG_IALLOC (1 << 10)
#define DEBUG_INODE (1 << 11)
#define DEBUG_SUPER (1 << 12)
#define DEBUG_XATTR (1 << 13)
#define DEBUG_EXT4 (1 << 14)
#define DEBUG_ALL (0xFFFFFFFF)
static inline const char *ext4_dmask_id2str(uint32_t m)
{
switch(m) {
case DEBUG_BALLOC:
return "ext4_balloc: ";
case DEBUG_BCACHE:
return "ext4_bcache: ";
case DEBUG_BITMAP:
return "ext4_bitmap: ";
case DEBUG_BLOCK_GROUP:
return "ext4_block_group: ";
case DEBUG_BLOCKDEV:
return "ext4_blockdev: ";
case DEBUG_DIR_IDX:
return "ext4_dir_idx: ";
case DEBUG_DIR:
return "ext4_dir: ";
case DEBUG_EXTENT:
return "ext4_extent: ";
case DEBUG_FS:
return "ext4_fs: ";
case DEBUG_HASH:
return "ext4_hash: ";
case DEBUG_IALLOC:
return "ext4_ialloc: ";
case DEBUG_INODE:
return "ext4_inode: ";
case DEBUG_SUPER:
return "ext4_super: ";
case DEBUG_XATTR:
return "ext4_xattr: ";
case DEBUG_EXT4:
return "ext4: ";
}
return "";
}
#define DBG_NONE " "
#define DBG_INFO "[info] "
#define DBG_WARN "[warn] "
#define DBG_ERROR "[error] "
/**@brief Global mask debug set.
* @brief m new debug mask.*/
void ext4_dmask_set(uint32_t m);
/**@brief Global mask debug clear.
* @brief m new debug mask.*/
void ext4_dmask_clr(uint32_t m);
/**@brief Global debug mask get.
* @return debug mask*/
uint32_t ext4_dmask_get(void);
#if CONFIG_DEBUG_PRINTF
/**@brief Debug printf.*/
#define ext4_dprintf(m, ...) \
#define ext4_dbg(m, ...) \
do { \
if (m & ext4_dmask_get()) \
printf(__VA_ARGS__); \
fflush(stdout); \
if (m & ext4_dmask_get()) { \
printf(ext4_dmask_id2str(m)); \
printf(__VA_ARGS__); \
fflush(stdout); \
} \
} while (0)
#else
#define ext4_dprintf(m, ...)
#define ext4_dbg(m, ...) do { } while (0)
#endif
#if CONFIG_DEBUG_ASSERT
/**@brief Debug assertion.*/
#if CONFIG_HAVE_OWN_ASSERT
#define ext4_assert(_v) \
#define ext4_assert(_v) \
do { \
if (!(_v)) { \
printf("Assertion failed:\nmodule: %s\nline: %d\n", \
printf("assertion failed:\nfile: %s\nline: %d\n", \
__FILE__, __LINE__); \
while (1) \
; \
} \
} while (0)
#else

182
lwext4/ext4_fs.c

@ -98,9 +98,10 @@ int ext4_fs_init(struct ext4_fs *fs, struct ext4_blockdev *bdev)
/*Validate FS*/
tmp = ext4_get16(&fs->sb, state);
if (tmp & EXT4_SUPERBLOCK_STATE_ERROR_FS) {
ext4_dprintf(EXT4_DEBUG_FS, "last umount error\n");
}
if (tmp & EXT4_SUPERBLOCK_STATE_ERROR_FS)
ext4_dbg(DEBUG_FS, DBG_WARN
"last umount error: superblock fs_error flag\n");
/* Mark system as mounted */
ext4_set16(&fs->sb, state, EXT4_SUPERBLOCK_STATE_ERROR_FS);
@ -124,106 +125,75 @@ int ext4_fs_fini(struct ext4_fs *fs)
return ext4_sb_write(fs->bdev, &fs->sb);
}
static void ext4_fs_debug_features_incomp(uint32_t features_incompatible)
static void ext4_fs_debug_features_inc(uint32_t features_incompatible)
{
if (features_incompatible & EXT4_FEATURE_INCOMPAT_COMPRESSION) {
ext4_dprintf(EXT4_DEBUG_FS, "compression\n");
}
if (features_incompatible & EXT4_FEATURE_INCOMPAT_FILETYPE) {
ext4_dprintf(EXT4_DEBUG_FS, "filetype\n");
}
if (features_incompatible & EXT4_FEATURE_INCOMPAT_RECOVER) {
ext4_dprintf(EXT4_DEBUG_FS, "recover\n");
}
if (features_incompatible & EXT4_FEATURE_INCOMPAT_JOURNAL_DEV) {
ext4_dprintf(EXT4_DEBUG_FS, "journal_dev\n");
}
if (features_incompatible & EXT4_FEATURE_INCOMPAT_META_BG) {
ext4_dprintf(EXT4_DEBUG_FS, "meta_bg\n");
}
if (features_incompatible & EXT4_FEATURE_INCOMPAT_EXTENTS) {
ext4_dprintf(EXT4_DEBUG_FS, "extents\n");
}
if (features_incompatible & EXT4_FEATURE_INCOMPAT_64BIT) {
ext4_dprintf(EXT4_DEBUG_FS, "64bit\n");
}
if (features_incompatible & EXT4_FEATURE_INCOMPAT_MMP) {
ext4_dprintf(EXT4_DEBUG_FS, "mnp\n");
}
if (features_incompatible & EXT4_FEATURE_INCOMPAT_FLEX_BG) {
ext4_dprintf(EXT4_DEBUG_FS, "flex_bg\n");
}
if (features_incompatible & EXT4_FEATURE_INCOMPAT_EA_INODE) {
ext4_dprintf(EXT4_DEBUG_FS, "ea_inode\n");
}
if (features_incompatible & EXT4_FEATURE_INCOMPAT_DIRDATA) {
ext4_dprintf(EXT4_DEBUG_FS, "dirdata\n");
}
if (features_incompatible & EXT4_FEATURE_INCOMPAT_BG_USE_META_CSUM) {
ext4_dprintf(EXT4_DEBUG_FS, "meta_csum\n");
}
if (features_incompatible & EXT4_FEATURE_INCOMPAT_LARGEDIR) {
ext4_dprintf(EXT4_DEBUG_FS, "largedir\n");
}
if (features_incompatible & EXT4_FEATURE_INCOMPAT_INLINE_DATA) {
ext4_dprintf(EXT4_DEBUG_FS, "inline_data\n");
}
if (features_incompatible & EXT4_FEATURE_INCOMPAT_COMPRESSION)
ext4_dbg(DEBUG_FS, DBG_NONE "compression\n");
if (features_incompatible & EXT4_FEATURE_INCOMPAT_FILETYPE)
ext4_dbg(DEBUG_FS, DBG_NONE "filetype\n");
if (features_incompatible & EXT4_FEATURE_INCOMPAT_RECOVER)
ext4_dbg(DEBUG_FS, DBG_NONE "recover\n");
if (features_incompatible & EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)
ext4_dbg(DEBUG_FS, DBG_NONE "journal_dev\n");
if (features_incompatible & EXT4_FEATURE_INCOMPAT_META_BG)
ext4_dbg(DEBUG_FS, DBG_NONE "meta_bg\n");
if (features_incompatible & EXT4_FEATURE_INCOMPAT_EXTENTS)
ext4_dbg(DEBUG_FS, DBG_NONE "extents\n");
if (features_incompatible & EXT4_FEATURE_INCOMPAT_64BIT)
ext4_dbg(DEBUG_FS, DBG_NONE "64bit\n");
if (features_incompatible & EXT4_FEATURE_INCOMPAT_MMP)
ext4_dbg(DEBUG_FS, DBG_NONE "mnp\n");
if (features_incompatible & EXT4_FEATURE_INCOMPAT_FLEX_BG)
ext4_dbg(DEBUG_FS, DBG_NONE "flex_bg\n");
if (features_incompatible & EXT4_FEATURE_INCOMPAT_EA_INODE)
ext4_dbg(DEBUG_FS, DBG_NONE "ea_inode\n");
if (features_incompatible & EXT4_FEATURE_INCOMPAT_DIRDATA)
ext4_dbg(DEBUG_FS, DBG_NONE "dirdata\n");
if (features_incompatible & EXT4_FEATURE_INCOMPAT_BG_USE_META_CSUM)
ext4_dbg(DEBUG_FS, DBG_NONE "meta_csum\n");
if (features_incompatible & EXT4_FEATURE_INCOMPAT_LARGEDIR)
ext4_dbg(DEBUG_FS, DBG_NONE "largedir\n");
if (features_incompatible & EXT4_FEATURE_INCOMPAT_INLINE_DATA)
ext4_dbg(DEBUG_FS, DBG_NONE "inline_data\n");
}
static void ext4_fs_debug_features_comp(uint32_t features_compatible)
{
if (features_compatible & EXT4_FEATURE_COMPAT_DIR_PREALLOC) {
ext4_dprintf(EXT4_DEBUG_FS, " dir_prealloc\n");
}
if (features_compatible & EXT4_FEATURE_COMPAT_IMAGIC_INODES) {
ext4_dprintf(EXT4_DEBUG_FS, "imagic_inodes\n");
}
if (features_compatible & EXT4_FEATURE_COMPAT_HAS_JOURNAL) {
ext4_dprintf(EXT4_DEBUG_FS, "has_journal\n");
}
if (features_compatible & EXT4_FEATURE_COMPAT_EXT_ATTR) {
ext4_dprintf(EXT4_DEBUG_FS, "ext_attr\n");
}
if (features_compatible & EXT4_FEATURE_COMPAT_RESIZE_INODE) {
ext4_dprintf(EXT4_DEBUG_FS, "resize_inode\n");
}
if (features_compatible & EXT4_FEATURE_COMPAT_DIR_INDEX) {
ext4_dprintf(EXT4_DEBUG_FS, "dir_index\n");
}
if (features_compatible & EXT4_FEATURE_COMPAT_DIR_PREALLOC)
ext4_dbg(DEBUG_FS, DBG_NONE "dir_prealloc\n");
if (features_compatible & EXT4_FEATURE_COMPAT_IMAGIC_INODES)
ext4_dbg(DEBUG_FS, DBG_NONE "imagic_inodes\n");
if (features_compatible & EXT4_FEATURE_COMPAT_HAS_JOURNAL)
ext4_dbg(DEBUG_FS, DBG_NONE "has_journal\n");
if (features_compatible & EXT4_FEATURE_COMPAT_EXT_ATTR)
ext4_dbg(DEBUG_FS, DBG_NONE "ext_attr\n");
if (features_compatible & EXT4_FEATURE_COMPAT_RESIZE_INODE)
ext4_dbg(DEBUG_FS, DBG_NONE "resize_inode\n");
if (features_compatible & EXT4_FEATURE_COMPAT_DIR_INDEX)
ext4_dbg(DEBUG_FS, DBG_NONE "dir_index\n");
}
static void ext4_fs_debug_features_ro(uint32_t features_ro)
{
if (features_ro & EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) {
ext4_dprintf(EXT4_DEBUG_FS, "sparse_super\n");
}
if (features_ro & EXT4_FEATURE_RO_COMPAT_LARGE_FILE) {
ext4_dprintf(EXT4_DEBUG_FS, "large_file\n");
}
if (features_ro & EXT4_FEATURE_RO_COMPAT_BTREE_DIR) {
ext4_dprintf(EXT4_DEBUG_FS, "btree_dir\n");
}
if (features_ro & EXT4_FEATURE_RO_COMPAT_HUGE_FILE) {
ext4_dprintf(EXT4_DEBUG_FS, "huge_file\n");
}
if (features_ro & EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
ext4_dprintf(EXT4_DEBUG_FS, "gtd_csum\n");
}
if (features_ro & EXT4_FEATURE_RO_COMPAT_DIR_NLINK) {
ext4_dprintf(EXT4_DEBUG_FS, "dir_nlink\n");
}
if (features_ro & EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE) {
ext4_dprintf(EXT4_DEBUG_FS, "extra_isize\n");
}
if (features_ro & EXT4_FEATURE_RO_COMPAT_QUOTA) {
ext4_dprintf(EXT4_DEBUG_FS, "quota\n");
}
if (features_ro & EXT4_FEATURE_RO_COMPAT_BIGALLOC) {
ext4_dprintf(EXT4_DEBUG_FS, "bigalloc\n");
}
if (features_ro & EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) {
ext4_dprintf(EXT4_DEBUG_FS, "metadata_csum\n");
}
if (features_ro & EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER)
ext4_dbg(DEBUG_FS, DBG_NONE "sparse_super\n");
if (features_ro & EXT4_FEATURE_RO_COMPAT_LARGE_FILE)
ext4_dbg(DEBUG_FS, DBG_NONE "large_file\n");
if (features_ro & EXT4_FEATURE_RO_COMPAT_BTREE_DIR)
ext4_dbg(DEBUG_FS, DBG_NONE "btree_dir\n");
if (features_ro & EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
ext4_dbg(DEBUG_FS, DBG_NONE "huge_file\n");
if (features_ro & EXT4_FEATURE_RO_COMPAT_GDT_CSUM)
ext4_dbg(DEBUG_FS, DBG_NONE "gtd_csum\n");
if (features_ro & EXT4_FEATURE_RO_COMPAT_DIR_NLINK)
ext4_dbg(DEBUG_FS, DBG_NONE "dir_nlink\n");
if (features_ro & EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)
ext4_dbg(DEBUG_FS, DBG_NONE "extra_isize\n");
if (features_ro & EXT4_FEATURE_RO_COMPAT_QUOTA)
ext4_dbg(DEBUG_FS, DBG_NONE "quota\n");
if (features_ro & EXT4_FEATURE_RO_COMPAT_BIGALLOC)
ext4_dbg(DEBUG_FS, DBG_NONE "bigalloc\n");
if (features_ro & EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)
ext4_dbg(DEBUG_FS, DBG_NONE "metadata_csum\n");
}
int ext4_fs_check_features(struct ext4_fs *fs, bool *read_only)
@ -235,22 +205,22 @@ int ext4_fs_check_features(struct ext4_fs *fs, bool *read_only)
return EOK;
}
ext4_dprintf(EXT4_DEBUG_FS, "\nSB features_incompatible:\n");
ext4_fs_debug_features_incomp(
ext4_get32(&fs->sb, features_incompatible));
ext4_dbg(DEBUG_FS, DBG_INFO "sblock features_incompatible:\n");
ext4_fs_debug_features_inc(ext4_get32(&fs->sb, features_incompatible));
ext4_dprintf(EXT4_DEBUG_FS, "\nSB features_compatible:\n");
ext4_dbg(DEBUG_FS, DBG_INFO "sblock features_compatible:\n");
ext4_fs_debug_features_comp(ext4_get32(&fs->sb, features_compatible));
ext4_dprintf(EXT4_DEBUG_FS, "\nSB features_read_only:\n");
ext4_dbg(DEBUG_FS, DBG_INFO "sblock features_read_only:\n");
ext4_fs_debug_features_ro(ext4_get32(&fs->sb, features_read_only));
/*Check features_incompatible*/
v = (ext4_get32(&fs->sb, features_incompatible) &
(~CONFIG_FEATURE_INCOMPAT_SUPP));
if (v) {
ext4_dprintf(EXT4_DEBUG_FS, "SB features_incompatible: fail\n");
ext4_fs_debug_features_incomp(v);
ext4_dbg(DEBUG_FS, DBG_ERROR
"sblock has unsupported features incompatible:\n");
ext4_fs_debug_features_inc(v);
return ENOTSUP;
}
@ -258,11 +228,9 @@ int ext4_fs_check_features(struct ext4_fs *fs, bool *read_only)
v = (ext4_get32(&fs->sb, features_read_only) &
(~CONFIG_FEATURE_RO_COMPAT_SUPP));
if (v) {
ext4_dprintf(
EXT4_DEBUG_FS,
"\nERROR sblock features_read_only . Unsupported:\n");
ext4_fs_debug_features_incomp(v);
ext4_dbg(DEBUG_FS, DBG_WARN
"sblock has unsupported features read only:\n");
ext4_fs_debug_features_ro(v);
*read_only = true;
return EOK;
}

Loading…
Cancel
Save