Skip to contentSkip to conversation

hfsplus: implement functionality of journal log wrapping

PATCH In review Vyacheslav Dubeyko 1 participant 1 message Feb 23, 2014

Subsystems (2)
lore
Share & tools
lore

Vyacheslav Dubeyko

author maintainer
#0 lore raw

PATCH v4 11/15 hfsplus: implement functionality of journal log wrapping

From: Vyacheslav Dubeyko <[email protected]>
Subject: [PATCH v4 11/15] hfsplus: implement functionality of journal log wrapping

The journal log is a circular buffer. Thereby, journal log's content can be splitted by journal end on two parts in some situations. When reading or writing the journal buffer, the I/O operation must stop at the end of the journal buffer and resume (wrap around) immediately following the journal header.

This patch implements functionality of wrapping of journal log for such situation. Namely, it means setting of "start" field of journal header by journal header size value.

CC Al Viro <[email protected]>
CC Christoph Hellwig <[email protected]>
CC Hin-Tak Leung <[email protected]>
---
 fs/hfsplus/journal.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
fs/hfsplus/journal.c +47 -0
index 51c5cfb..5b430b6 100644
@@ -82,6 +82,9 @@ static inline sector_t JOURNAL_OFF_TO_SEC(struct super_block *sb)
 	(le32_to_cpu(JNL_SWAP32(jnl, HFSPLUS_JH(jnl)->blhdr_size)))
 #define JHDR_SIZE(jnl) \
 	(le32_to_cpu(JNL_SWAP32(jnl, HFSPLUS_JH(jnl)->jhdr_size)))
+#define JH_START_ADD(jnl, val) \
+	(HFSPLUS_JH(jnl)->start = \
+	 JNL_SWAP64(jnl, cpu_to_le64(TR_START(jnl) + val)))
 
 #define TR_MAX_BLOCKS(jnl, blhdr) \
 	(le16_to_cpu(JNL_SWAP16(jnl, HFSPLUS_BLHDR_PTR(blhdr)->max_blocks)))
@@ -362,6 +365,38 @@ static inline bool need_to_wrap_journal(struct hfsplus_journal *jnl,
 	return (cur_off + req_size) > JOURNAL_SIZE(jnl);
 }
 
+static inline void __hfsplus_wrap_journal(struct super_block *sb)
+{
+	struct hfsplus_journal *jnl = HFSPLUS_SB(sb)->jnl;
+	u64 start;
+	u32 jhdr_size;
+
+	jhdr_size = le32_to_cpu(JNL_SWAP32(jnl, jnl->jh->jhdr_size));
+	start = jhdr_size;
+	jnl->jh->start = JNL_SWAP64(jnl, cpu_to_le64(start));
+}
+
+/* Return rest bytes of binfo or blhdr from the journal begin */
+static inline u32 hfsplus_wrap_journal(struct super_block *sb,
+					u64 cur_off, u32 req_size)
+{
+	struct hfsplus_journal *jnl = HFSPLUS_SB(sb)->jnl;
+	u32 used_bytes;
+	u32 rest_bytes;
+
+	hfs_dbg(JOURNAL, "cur_off %llu, req_size %u, JOURNAL_SIZE(jnl) %llu\n",
+		cur_off, req_size, JOURNAL_SIZE(jnl));
+
+	BUG_ON(cur_off > JOURNAL_SIZE(jnl));
+	BUG_ON((cur_off + req_size) < JOURNAL_SIZE(jnl));
+
+	used_bytes = JOURNAL_SIZE(jnl) - cur_off;
+	rest_bytes = req_size - used_bytes;
+
+	__hfsplus_wrap_journal(sb);
+
+	return rest_bytes;
+}
 
 static void hfsplus_deinit_block_list_desc(struct hfsplus_blist_desc *desc)
 {
@@ -617,6 +652,9 @@ static int hfsplus_replay_journal(struct super_block *sb)
 		struct hfsplus_block_info *binfo;
 		u32 i;
 
+		if (TR_START(jnl) == JOURNAL_SIZE(jnl))
+			__hfsplus_wrap_journal(sb);
+
 		blhdr = hfsplus_get_blhdr(sb, JOURNAL_OFF_TO_SEC(sb), &desc);
 		if (!blhdr) {
 			err = -EIO;
@@ -632,6 +670,15 @@ static int hfsplus_replay_journal(struct super_block *sb)
 
 		last_seq_num = TR_SEQ_NUM(jnl, blhdr);
 
+		if (need_to_wrap_journal(jnl, TR_START(jnl), BLHDR_SIZE(jnl))) {
+			u32 rest;
+
+			rest = hfsplus_wrap_journal(sb, TR_START(jnl),
+							BLHDR_SIZE(jnl));
+			JH_START_ADD(jnl, rest);
+		} else
+			JH_START_ADD(jnl, BLHDR_SIZE(jnl));
+
 		/* Check transaction */
 		for (i = 1; i < TR_BLOCKS(jnl, blhdr); i++) {
 			binfo = hfsplus_get_binfo(sb, i, &desc);
Signature · 1 line
1.7.9.5