Skip to contentSkip to conversation

hfsplus: implement functionality of journal log wrapping

PATCH Superseded Vyacheslav Dubeyko 1 participant 1 message Feb 12, 2014

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Vyacheslav Dubeyko

author maintainer
#0 lore raw

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

From: Vyacheslav Dubeyko <[email protected]>
Subject: [PATCH v3 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 |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
fs/hfsplus/journal.c +42 -0
index 4562187..c40ef77 100644
@@ -304,6 +304,36 @@ static inline bool need_to_wrap_journal(struct hfsplus_journal_header *jh,
 	return (cur_off + req_size) > JOURNAL_SIZE(jh);
 }
 
+static inline void __hfsplus_wrap_journal(struct super_block *sb)
+{
+	struct hfsplus_journal *jnl = HFSPLUS_SB(sb)->jnl;
+
+	jnl->jh->start = jnl->jh->jhdr_size;
+}
+
+/* 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;
+	struct hfsplus_journal_header *jh = jnl->jh;
+	u32 used_bytes;
+	u32 rest_bytes;
+
+	hfs_dbg(JOURNAL, "cur_off %llu, req_size %u, JOURNAL_SIZE(jh) %llu\n",
+		cur_off, req_size, JOURNAL_SIZE(jh));
+
+	BUG_ON(cur_off > JOURNAL_SIZE(jh));
+	BUG_ON((cur_off + req_size) < JOURNAL_SIZE(jh));
+
+	used_bytes = JOURNAL_SIZE(jh) - 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)
 {
 	kfree(desc->blist_buf);
@@ -557,6 +587,9 @@ static int hfsplus_replay_journal(struct super_block *sb)
 		struct hfsplus_block_info *binfo;
 		u32 i;
 
+		if (TR_START(jh) == JOURNAL_SIZE(jh))
+			__hfsplus_wrap_journal(sb);
+
 		blhdr = hfsplus_get_blhdr(sb, JOURNAL_OFF_TO_SEC(sb), &desc);
 		if (!blhdr) {
 			err = -EIO;
@@ -572,6 +605,15 @@ static int hfsplus_replay_journal(struct super_block *sb)
 
 		last_seq_num = TR_SEQ_NUM(blhdr);
 
+		if (need_to_wrap_journal(jh, TR_START(jh), BLHDR_SIZE(jh))) {
+			u32 rest;
+
+			rest = hfsplus_wrap_journal(sb, TR_START(jh),
+							BLHDR_SIZE(jh));
+			le64_add_cpu(&jh->start, rest);
+		} else
+			le64_add_cpu(&jh->start, BLHDR_SIZE(jh));
+
 		/* Check transaction */
 		for (i = 1; i < TR_BLOCKS(blhdr); i++) {
 			binfo = hfsplus_get_binfo(sb, i, &desc);
Signature · 1 line
1.7.9.5