⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jbd-journal-chksum-2.6.18-vanilla.patch

📁 lustre 1.6.5 source code
💻 PATCH
📖 第 1 页 / 共 2 页
字号:
Index: linux-2.6.18.8/fs/jbd/commit.c===================================================================--- linux-2.6.18.8.orig/fs/jbd/commit.c+++ linux-2.6.18.8/fs/jbd/commit.c@@ -22,6 +22,7 @@ #include <linux/mm.h> #include <linux/pagemap.h> #include <linux/smp_lock.h>+#include <linux/crc32.h>   /*@@ -95,19 +96,23 @@ static int inverted_lock(journal_t *jour 	return 1; } -/* Done it all: now write the commit record.  We should have+/*+ * Done it all: now submit the commit record.  We should have  * cleaned up our previous buffers by now, so if we are in abort  * mode we can now just skip the rest of the journal write  * entirely.  *  * Returns 1 if the journal needs to be aborted or 0 on success  */-static int journal_write_commit_record(journal_t *journal,-					transaction_t *commit_transaction)+static int journal_submit_commit_record(journal_t *journal,+					transaction_t *commit_transaction,+					struct buffer_head **cbh,+					__u32 crc32_sum) { 	struct journal_head *descriptor;+	struct commit_header *tmp; 	struct buffer_head *bh;-	int i, ret;+	int ret; 	int barrier_done = 0;  	if (is_journal_aborted(journal))@@ -119,21 +124,35 @@ static int journal_write_commit_record(j  	bh = jh2bh(descriptor); -	/* AKPM: buglet - add `i' to tmp! */-	for (i = 0; i < bh->b_size; i += 512) {-		journal_header_t *tmp = (journal_header_t*)bh->b_data;-		tmp->h_magic = cpu_to_be32(JFS_MAGIC_NUMBER);-		tmp->h_blocktype = cpu_to_be32(JFS_COMMIT_BLOCK);-		tmp->h_sequence = cpu_to_be32(commit_transaction->t_tid);+	tmp = (struct commit_header *)bh->b_data;+	tmp->h_magic = cpu_to_be32(JFS_MAGIC_NUMBER);+	tmp->h_blocktype = cpu_to_be32(JFS_COMMIT_BLOCK);+	tmp->h_sequence = cpu_to_be32(commit_transaction->t_tid);+ 		 		+	if (JFS_HAS_COMPAT_FEATURE(journal,+				JFS_FEATURE_COMPAT_CHECKSUM)) {+		tmp->h_chksum_type 	= JFS_CRC32_CHKSUM;+		tmp->h_chksum_size 	= JFS_CRC32_CHKSUM_SIZE;+		tmp->h_chksum[0] 	= cpu_to_be32(crc32_sum); 	} -	JBUFFER_TRACE(descriptor, "write commit block");+	JBUFFER_TRACE(descriptor, "submit commit block");+	lock_buffer(bh);+	get_bh(bh);+ 	set_buffer_dirty(bh);-	if (journal->j_flags & JFS_BARRIER) {+	set_buffer_uptodate(bh);+	bh->b_end_io = journal_end_buffer_io_sync;++	if (journal->j_flags & JFS_BARRIER &&+		!JFS_HAS_INCOMPAT_FEATURE(journal,+					 JFS_FEATURE_INCOMPAT_ASYNC_COMMIT)) {+ 		set_buffer_ordered(bh); 		barrier_done = 1; 	}-	ret = sync_dirty_buffer(bh);+	ret = submit_bh(WRITE, bh);+ 	/* is it possible for another commit to fail at roughly 	 * the same time as this one?  If so, we don't want to 	 * trust the barrier flag in the super, but instead want@@ -154,12 +173,70 @@ static int journal_write_commit_record(j 		clear_buffer_ordered(bh); 		set_buffer_uptodate(bh); 		set_buffer_dirty(bh);-		ret = sync_dirty_buffer(bh);+		ret = submit_bh(WRITE, bh); 	}-	put_bh(bh);		/* One for getblk() */-	journal_put_journal_head(descriptor);+	*cbh = bh;+	return ret;+}++/*+ * This function along with journal_submit_commit_record+ * allows to write the commit record asynchronously.+ */+static int journal_wait_on_commit_record(struct buffer_head *bh)+{+	int ret = 0;++	clear_buffer_dirty(bh);+	wait_on_buffer(bh);+	+	if (unlikely(!buffer_uptodate(bh)))+		ret = -EIO;+	put_bh(bh);            /* One for getblk() */+	journal_put_journal_head(bh2jh(bh));+	+	return ret;+}++/*+ * Wait for all submitted IO to complete.+ */+static int journal_wait_on_locked_list(journal_t *journal,+				       transaction_t *commit_transaction)+{+	int ret = 0;+	struct journal_head *jh; -	return (ret == -EIO);+	while (commit_transaction->t_locked_list) {+		struct buffer_head *bh;++		jh = commit_transaction->t_locked_list->b_tprev;+		bh = jh2bh(jh);+		get_bh(bh);+		if (buffer_locked(bh)) {+			spin_unlock(&journal->j_list_lock);+			wait_on_buffer(bh);+			if (unlikely(!buffer_uptodate(bh)))+				ret = -EIO;+			spin_lock(&journal->j_list_lock);+		}+		if (!inverted_lock(journal, bh)) {+			put_bh(bh);+			spin_lock(&journal->j_list_lock);+			continue;+		}+		if (buffer_jbd(bh) && jh->b_jlist == BJ_Locked) {+			__journal_unfile_buffer(jh);+			jbd_unlock_bh_state(bh);+			journal_remove_journal_head(bh);+			put_bh(bh);+		} else {+			jbd_unlock_bh_state(bh);+		}+		put_bh(bh);+		cond_resched_lock(&journal->j_list_lock);+	}+	return ret; }  void journal_do_submit_data(struct buffer_head **wbuf, int bufs)@@ -273,6 +350,20 @@ write_out_data: 	journal_do_submit_data(wbuf, bufs); } +static inline __u32 jbd_checksum_data(__u32 crc32_sum, struct buffer_head *bh)+{+	struct page *page = bh->b_page;+	char *addr;+	__u32 checksum;++	addr = kmap_atomic(page, KM_USER0);+	checksum = crc32_be(crc32_sum,+			    (void *)(addr + offset_in_page(bh->b_data)),+			    bh->b_size);+	kunmap_atomic(addr, KM_USER0);+	return checksum;+}+ /*  * journal_commit_transaction  *@@ -296,6 +387,8 @@ void journal_commit_transaction(journal_ 	int first_tag = 0; 	int tag_flag; 	int i;+	struct buffer_head *cbh = NULL; /* For transactional checksums */+	__u32 crc32_sum = ~0;  	/* 	 * First job: lock down the current transaction and wait for@@ -439,38 +532,14 @@ void journal_commit_transaction(journal_ 	journal_submit_data_buffers(journal, commit_transaction);  	/*-	 * Wait for all previously submitted IO to complete.+	 * Wait for all previously submitted IO to complete if commit+	 * record is to be written synchronously. 	 */ 	spin_lock(&journal->j_list_lock);-	while (commit_transaction->t_locked_list) {-		struct buffer_head *bh;--		jh = commit_transaction->t_locked_list->b_tprev;-		bh = jh2bh(jh);-		get_bh(bh);-		if (buffer_locked(bh)) {-			spin_unlock(&journal->j_list_lock);-			wait_on_buffer(bh);-			if (unlikely(!buffer_uptodate(bh)))-				err = -EIO;-			spin_lock(&journal->j_list_lock);-		}-		if (!inverted_lock(journal, bh)) {-			put_bh(bh);-			spin_lock(&journal->j_list_lock);-			continue;-		}-		if (buffer_jbd(bh) && jh->b_jlist == BJ_Locked) {-			__journal_unfile_buffer(jh);-			jbd_unlock_bh_state(bh);-			journal_remove_journal_head(bh);-			put_bh(bh);-		} else {-			jbd_unlock_bh_state(bh);-		}-		put_bh(bh);-		cond_resched_lock(&journal->j_list_lock);-	}+	if (!JFS_HAS_INCOMPAT_FEATURE(journal,+		JFS_FEATURE_INCOMPAT_ASYNC_COMMIT))+		err = journal_wait_on_locked_list(journal,+						  commit_transaction); 	spin_unlock(&journal->j_list_lock);  	if (err)@@ -643,6 +712,16 @@ void journal_commit_transaction(journal_ start_journal_io: 			for (i = 0; i < bufs; i++) { 				struct buffer_head *bh = wbuf[i];+				/*+				 * Compute checksum.+				 */+				if (JFS_HAS_COMPAT_FEATURE(journal,+					JFS_FEATURE_COMPAT_CHECKSUM)) {+					crc32_sum =+						jbd_checksum_data(crc32_sum,+								   bh);+				}+ 				lock_buffer(bh); 				clear_buffer_dirty(bh); 				set_buffer_uptodate(bh);@@ -659,6 +738,23 @@ start_journal_io: 		} 	} +	/* Done it all: now write the commit record asynchronously. */++	if (JFS_HAS_INCOMPAT_FEATURE(journal,+		JFS_FEATURE_INCOMPAT_ASYNC_COMMIT)) {+		err = journal_submit_commit_record(journal, commit_transaction,+						 &cbh, crc32_sum);+		if (err)+			__journal_abort_hard(journal);++		spin_lock(&journal->j_list_lock);+		err = journal_wait_on_locked_list(journal,+						commit_transaction);+		spin_unlock(&journal->j_list_lock);+		if (err)+			__journal_abort_hard(journal);+	}+ 	/* Lo and behold: we have just managed to send a transaction to            the log.  Before we can commit it, wait for the IO so far to            complete.  Control buffers being written are on the@@ -757,9 +853,15 @@ wait_for_iobuf: 	}  	jbd_debug(3, "JBD: commit phase 6\n");--	if (journal_write_commit_record(journal, commit_transaction))-		err = -EIO;+		+	if (!JFS_HAS_INCOMPAT_FEATURE(journal,+		JFS_FEATURE_INCOMPAT_ASYNC_COMMIT)) {+		err = journal_submit_commit_record(journal, commit_transaction,+						&cbh, crc32_sum);+		if (err)+			__journal_abort_hard(journal);+	}+	err = journal_wait_on_commit_record(cbh);  	if (err) 		__journal_abort_hard(journal);Index: linux-2.6.18.8/include/linux/jbd.h===================================================================--- linux-2.6.18.8.orig/include/linux/jbd.h+++ linux-2.6.18.8/include/linux/jbd.h@@ -148,6 +148,29 @@ typedef struct journal_header_s 	__be32		h_sequence; } journal_header_t; +/*+ * Checksum types.+ */+#define JFS_CRC32_CHKSUM   1+#define JFS_MD5_CHKSUM     2+#define JFS_SHA1_CHKSUM    3++#define JFS_CRC32_CHKSUM_SIZE 4++#define JFS_CHECKSUM_BYTES (32 / sizeof(u32))+/*+ * Commit block header for storing transactional checksums:+ */+struct commit_header+{+	__be32		h_magic;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -