linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 11/15] hfsplus: implement functionality of journal log wrapping
@ 2014-02-23 15:34 Vyacheslav Dubeyko
  0 siblings, 0 replies; only message in thread
From: Vyacheslav Dubeyko @ 2014-02-23 15:34 UTC (permalink / raw)
  To: Linux FS devel list
  Cc: Al Viro, ChristophHellwig, Hin-Tak Leung, Andrew Morton

From: Vyacheslav Dubeyko <slava@dubeyko.com>
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@dubeyko.com>
CC: Al Viro <viro@zeniv.linux.org.uk>
CC: Christoph Hellwig <hch@infradead.org>
CC: Hin-Tak Leung <htl10@users.sourceforge.net>
---
 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




^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2014-02-23 15:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-23 15:34 [PATCH v4 11/15] hfsplus: implement functionality of journal log wrapping Vyacheslav Dubeyko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).