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

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

 



From: Vyacheslav Dubeyko <slava@xxxxxxxxxxx>
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.

Signed-off-by: Vyacheslav Dubeyko <slava@xxxxxxxxxxx>
CC: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
CC: Christoph Hellwig <hch@xxxxxxxxxxxxx>
CC: Hin-Tak Leung <htl10@xxxxxxxxxxxxxxxxxxxxx>
---
 fs/hfsplus/journal.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/fs/hfsplus/journal.c b/fs/hfsplus/journal.c
index 51c5cfb..5b430b6 100644
--- a/fs/hfsplus/journal.c
+++ b/fs/hfsplus/journal.c
@@ -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);
-- 
1.7.9.5



--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux