[PATCH v2 4/5] dumpe2fs: add JSON output of journal

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch adds JSON output of journal information

Signed-off-by: Viktor Prutyanov <viktor.prutyanov@xxxxxxxxxxxxx>
---
 lib/e2p/e2p.h   |  2 ++
 lib/e2p/ljs.c   | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 misc/dumpe2fs.c | 20 +++++++++++++-------
 3 files changed, 72 insertions(+), 7 deletions(-)

diff --git a/lib/e2p/e2p.h b/lib/e2p/e2p.h
index 88c08d73..cd3793e5 100644
--- a/lib/e2p/e2p.h
+++ b/lib/e2p/e2p.h
@@ -83,3 +83,5 @@ int e2p_string2os(char *str);
 unsigned int e2p_percent(int percent, unsigned int base);
 
 void fill_json_super(struct json_obj *obj, struct ext2_super_block * s);
+void e2p_fill_json_journal_super(struct json_obj *obj, char *journal_sb_buf,
+			    int exp_block_size, int flags);
diff --git a/lib/e2p/ljs.c b/lib/e2p/ljs.c
index 2db700b0..c75610b8 100644
--- a/lib/e2p/ljs.c
+++ b/lib/e2p/ljs.c
@@ -111,3 +111,60 @@ void e2p_list_journal_super(FILE *f, char *journal_sb_buf,
 		fprintf(f, "Journal errno:            %d\n",
 			(int) ntohl(jsb->s_errno));
 }
+
+void e2p_fill_json_journal_super(struct json_obj *obj, char *journal_sb_buf,
+			    int exp_block_size, int flags)
+{
+	journal_superblock_t *jsb = (journal_superblock_t *) journal_sb_buf;
+	__u32 *mask_ptr, mask, m;
+	unsigned int size;
+	int i, j, printed = 0;
+	unsigned int nr_users;
+	struct json_obj *journal_obj = json_obj_create_in_obj(obj, "journal");
+	struct json_list *features_list, *users_list;
+	char buf[64];
+
+	features_list = json_list_create_in_obj(journal_obj, "journal-features", JSON_VAL_STRING);
+	for (i=0, mask_ptr=&jsb->s_feature_compat; i <3; i++,mask_ptr++) {
+		mask = e2p_be32(*mask_ptr);
+		for (j=0,m=1; j < 32; j++, m<<=1) {
+			if (mask & m)
+				json_list_add_str(features_list, e2p_jrnl_feature2string(i, m));
+		}
+	}
+	size = (ntohl(jsb->s_blocksize) / 1024) * ntohl(jsb->s_maxlen);
+	if (size < 8192)
+		json_obj_add_fmt_buf_str(journal_obj, "journal-size", buf, sizeof(buf), "%uk", size);
+	else
+		json_obj_add_fmt_buf_str(journal_obj, "journal-size", buf, sizeof(buf), "%uM", size >> 10);
+	nr_users = (unsigned int) ntohl(jsb->s_nr_users);
+	if (exp_block_size != ntohl(jsb->s_blocksize))
+		json_obj_add_fmt_buf_str(journal_obj, "journal-block-size", buf, sizeof(buf), "%u",
+			(unsigned int)ntohl(jsb->s_blocksize));
+	json_obj_add_fmt_buf_str(journal_obj, "journal-length", buf, sizeof(buf), "%u",
+		(unsigned int)ntohl(jsb->s_maxlen));
+	if (ntohl(jsb->s_first) != 1)
+		json_obj_add_fmt_buf_str(journal_obj, "journal-first-block", buf, sizeof(buf), "%u",
+			(unsigned int)ntohl(jsb->s_first));
+	json_obj_add_fmt_buf_str(journal_obj, "journal-sequence", buf, sizeof(buf), "0x%08x", (unsigned int)ntohl(jsb->s_sequence));
+	json_obj_add_fmt_buf_str(journal_obj, "journal-start", buf, sizeof(buf), "%u", (unsigned int)ntohl(jsb->s_start));
+	if (nr_users != 1)
+		json_obj_add_fmt_buf_str(journal_obj, "journal-number-of-users", buf, sizeof(buf), "%u", nr_users);
+	if (jsb->s_feature_compat & e2p_be32(JFS_FEATURE_COMPAT_CHECKSUM))
+		json_obj_add_str(journal_obj, "journal-checksum-type", "crc32");
+	if ((jsb->s_feature_incompat &
+	     e2p_be32(JFS_FEATURE_INCOMPAT_CSUM_V3)) ||
+	    (jsb->s_feature_incompat &
+	     e2p_be32(JFS_FEATURE_INCOMPAT_CSUM_V2))) {
+		json_obj_add_str(journal_obj, "journal-checksum-type", journal_checksum_type_str(jsb->s_checksum_type));
+		json_obj_add_fmt_buf_str(journal_obj, "journal-checksum", buf, sizeof(buf), "0x%08x", e2p_be32(jsb->s_checksum));
+	}
+	if ((nr_users > 1) ||
+	    !e2p_is_null_uuid(&jsb->s_users[0])) {
+		users_list = json_list_create_in_obj(journal_obj, "journal-users", JSON_VAL_STRING);
+		for (i=0; i < nr_users; i++)
+			json_list_add_str(users_list, e2p_uuid2str(&jsb->s_users[i*16]));
+	}
+	if (jsb->s_errno != 0)
+		json_obj_add_fmt_buf_str(journal_obj, "journal-errno", buf, sizeof(buf), "%d", (int) ntohl(jsb->s_errno));
+}
diff --git a/misc/dumpe2fs.c b/misc/dumpe2fs.c
index 6896b6f1..58362ec2 100644
--- a/misc/dumpe2fs.c
+++ b/misc/dumpe2fs.c
@@ -607,7 +607,7 @@ static void list_bad_blocks(ext2_filsys fs, int dump)
 	ext2fs_badblocks_list_free(bb_list);
 }
 
-static void print_inline_journal_information(ext2_filsys fs)
+static void print_inline_journal_information(ext2_filsys fs, struct json_obj *obj)
 {
 	journal_superblock_t	*jsb;
 	struct ext2_inode	inode;
@@ -643,10 +643,13 @@ static void print_inline_journal_information(ext2_filsys fs)
 			_("Journal superblock magic number invalid!\n"));
 		exit(1);
 	}
-	e2p_list_journal_super(stdout, buf, fs->blocksize, 0);
+	if (obj)
+		e2p_fill_json_journal_super(obj, buf, fs->blocksize, 0);
+	else
+		e2p_list_journal_super(stdout, buf, fs->blocksize, 0);
 }
 
-static void print_journal_information(ext2_filsys fs)
+static void print_journal_information(ext2_filsys fs, struct json_obj *obj)
 {
 	errcode_t	retval;
 	char		buf[1024];
@@ -668,7 +671,10 @@ static void print_journal_information(ext2_filsys fs)
 			_("Couldn't find journal superblock magic numbers"));
 		exit(1);
 	}
-	e2p_list_journal_super(stdout, buf, fs->blocksize, 0);
+	if (obj)
+		e2p_fill_json_journal_super(obj, buf, fs->blocksize, 0);
+	else
+		e2p_list_journal_super(stdout, buf, fs->blocksize, 0);
 }
 
 static void parse_extended_opts(const char *opts, blk64_t *superblock,
@@ -762,7 +768,7 @@ int main (int argc, char ** argv)
 	int		c;
 	int		grp_only = 0;
 	int		json = 0;
-	struct json_obj *dump_obj;
+	struct json_obj *dump_obj = NULL;
 
 #ifdef ENABLE_NLS
 	setlocale(LC_MESSAGES, "");
@@ -877,9 +883,9 @@ try_open_again:
 			ext2fs_close_free(&fs);
 			exit(0);
 		}
-		if (!json && ext2fs_has_feature_journal(fs->super) &&
+		if (ext2fs_has_feature_journal(fs->super) &&
 		    (fs->super->s_journal_inum != 0))
-			print_inline_journal_information(fs);
+			print_inline_journal_information(fs, dump_obj);
 		if (!json)
 			list_bad_blocks(fs, 0);
 		if (header_only) {
-- 
2.14.1




[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux