[PATCH v2 10/15] hfsplus: implement functionality of getting transaction's block info

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

 



From: Vyacheslav Dubeyko <slava@xxxxxxxxxxx>
Subject: [PATCH v2 10/15] hfsplus: implement functionality of getting transaction's block info

This patch implements functionality of getting access to concrete
binfo in block list by means of index. If cached portion of block
list doesn't contain requested binfo then it will be read and be
cached a sector that it contains binfo for requested index.

The journal log is a circular buffer. Thereby, block list can be
splitted by journal end on two parts in some situations. A first
part will be located at end of journal buffer when second one
will continue the block list from journal buffer's begin.
As a result, method of getting binfo by index wraps around
reading from journal buffer in such case.

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 |  122 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 122 insertions(+)

diff --git a/fs/hfsplus/journal.c b/fs/hfsplus/journal.c
index d155114..8e27631 100644
--- a/fs/hfsplus/journal.c
+++ b/fs/hfsplus/journal.c
@@ -46,6 +46,10 @@
 	(le64_to_cpu(((struct hfsplus_journal_header *)(jh))->start))
 #define LAST_TR_END(jh) \
 	(le64_to_cpu(((struct hfsplus_journal_header *)(jh))->end))
+#define JOURNAL_SIZE(jh) \
+	(le64_to_cpu(((struct hfsplus_journal_header *)(jh))->size))
+#define BLHDR_SIZE(jh) \
+	(le32_to_cpu(((struct hfsplus_journal_header *)(jh))->blhdr_size))
 #define JHDR_SIZE(jh) \
 	(le32_to_cpu(((struct hfsplus_journal_header *)(jh))->jhdr_size))
 
@@ -61,6 +65,23 @@
 	(le32_to_cpu(((struct hfsplus_blhdr *)(blhdr))->flags) & \
 	 HFSPLUS_BLHDR_CHECK_CHECKSUMS)
 
+#define BNUM(binfo) \
+	(le64_to_cpu(((struct hfsplus_block_info *)(binfo))->bnum))
+#define BSIZE(binfo) \
+	(le32_to_cpu(((struct hfsplus_block_info *)(binfo))->bsize))
+#define BINFO_OFFSET(index) \
+	(offsetof(struct hfsplus_blhdr, binfo) + \
+	 (index * sizeof(struct hfsplus_block_info)))
+
+static inline u16 BINFO_INDEX(size_t offset)
+{
+	if (offset <= offsetof(struct hfsplus_blhdr, binfo))
+		return 0;
+
+	return (offset - offsetof(struct hfsplus_blhdr, binfo)) /
+		sizeof(struct hfsplus_block_info);
+}
+
 /*
  * struct hfsplus_blist_desc - descriptor of block list buffer
  * @start_sec: start sector of block list
@@ -263,6 +284,12 @@ static int hfsplus_create_journal(struct super_block *sb,
 	return 0;
 }
 
+static inline bool need_to_wrap_journal(struct hfsplus_journal_header *jh,
+					u64 cur_off, u32 req_size)
+{
+	return (cur_off + req_size) > JOURNAL_SIZE(jh);
+}
+
 static void hfsplus_deinit_block_list_desc(struct hfsplus_blist_desc *desc);
 
 static int hfsplus_init_block_list_desc(struct super_block *sb,
@@ -339,6 +366,101 @@ static struct hfsplus_blhdr *hfsplus_get_blhdr(struct super_block *sb,
 }
 
 static inline
+bool is_binfo_available(u16 index, struct hfsplus_blist_desc *desc)
+{
+	size_t lower_bound;
+	size_t upper_bound;
+	size_t req_off;
+
+	lower_bound = BINFO_OFFSET(desc->cur_index);
+	upper_bound = ((lower_bound >> HFSPLUS_SECTOR_SHIFT) <<
+			HFSPLUS_SECTOR_SHIFT) + desc->available_bytes;
+	req_off = BINFO_OFFSET(index);
+
+	return lower_bound <= req_off && req_off < upper_bound;
+}
+
+static
+struct hfsplus_block_info *hfsplus_get_binfo(struct super_block *sb,
+					     u16 index,
+					     struct hfsplus_blist_desc *desc)
+{
+	u16 diff;
+
+	BUG_ON(!desc->blist_buf || !desc->binfo);
+
+	hfs_dbg(JOURNAL, "get binfo[%u], is_binfo_available %u\n",
+		index, is_binfo_available(index, desc));
+
+	if (index >= TR_MAX_BLOCKS(&desc->blhdr)) {
+		pr_err("invalid block index: index %u, max_blocks %u\n",
+			index, TR_MAX_BLOCKS(&desc->blhdr));
+		return NULL;
+	}
+
+	if (!is_binfo_available(index, desc)) {
+		struct hfsplus_journal *jnl = HFSPLUS_SB(sb)->jnl;
+		struct hfsplus_journal_header *jh = jnl->jh;
+		u64 jh_off;
+		sector_t jh_sec;
+		u64 blhdr_off;
+		sector_t start_sec;
+		size_t secs;
+		size_t secs_size;
+		struct hfsplus_block_info *binfo;
+		int err;
+
+		jh_off = be64_to_cpu(jnl->jib->offset);
+		jh_sec = (jh_off >> HFSPLUS_SECTOR_SHIFT) +
+				HFSPLUS_SB(sb)->blockoffset;
+		blhdr_off = (desc->start_sec - jh_sec) << HFSPLUS_SECTOR_SHIFT;
+
+		secs = BINFO_OFFSET(index) >> HFSPLUS_SECTOR_SHIFT;
+		secs_size = secs << HFSPLUS_SECTOR_SHIFT;
+
+		if (need_to_wrap_journal(jh, blhdr_off,
+					 secs_size + HFSPLUS_SECTOR_SIZE)) {
+			u64 end_bytes;
+			u64 begin_bytes;
+
+			BUG_ON(JOURNAL_SIZE(jh) < blhdr_off);
+			end_bytes = JOURNAL_SIZE(jh) - blhdr_off;
+			BUG_ON(secs_size < end_bytes);
+			begin_bytes = secs_size - end_bytes;
+
+			start_sec = jh_sec;
+			start_sec += JHDR_SIZE(jh) >> HFSPLUS_SECTOR_SHIFT;
+			start_sec += begin_bytes >> HFSPLUS_SECTOR_SHIFT;
+		} else
+			start_sec = desc->start_sec + secs;
+
+		hfs_dbg(JOURNAL, "start sector %lu of blist's part\n",
+			start_sec);
+
+		err = hfsplus_submit_bio(sb, start_sec,
+					 desc->blist_buf, (void **)&binfo,
+					 READ, &desc->available_bytes);
+		if (err) {
+			pr_err("unable to read sector %lu of block list\n",
+				start_sec);
+			return NULL;
+		}
+
+		desc->cur_sec = start_sec;
+		desc->cur_index = BINFO_INDEX((secs << HFSPLUS_SECTOR_SHIFT));
+
+		if (desc->cur_index == 0) {
+			desc->binfo =
+				&((struct hfsplus_blhdr *)binfo)->binfo[0];
+		} else
+			desc->binfo = binfo;
+	}
+
+	diff = (desc->cur_index == 0 ? index : index - desc->cur_index);
+	return &desc->binfo[diff];
+}
+
+static inline
 bool hfsplus_journal_empty(struct hfsplus_journal_header *jh)
 {
 	return TR_START(jh) == LAST_TR_END(jh);
-- 
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