[PATCH v3 18/18] xfs_copy: format v5 sb logs correctly

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

 



xfs_copy formats the target filesystem log in non-duplicate copy mode to
stamp the new fs UUID into the log. The current format mechanism resets
the current LSN of the target filesystem to cycle 1, which is invalid
for v5 superblocks. The current LSN of v5 superblocks must always move
forward and remain ahead of metadata LSNs stored in filesystem metadata.

Update the log format helper to detect and use an alternate format
mechanism for v5 superblock logs. Allocate an independent log format
buffer based on the size of the log and format the buffer with an
incremented cycle count using the libxfs log format mechanism.

Note that the new libxfs log format mechanism could be used for both v5
and older superblock formats. The new mechanism requires a new, full log
sized buffer allocation as well as doing I/O to the entire log whereas
the pre-v5 sb mechanism only writes to the log head and tail. This is
due to how xfs_copy uses its own internal buffer data structure rather
than libxfs buftarg structures. As such, keep the original mechanism
around to avoid potential disruption for non-v5 users. The old mechanism
can be removed at some point in the future when the new mechanism is
shaken out and v5 filesystems tend to outnumber v4.

Signed-off-by: Brian Foster <bfoster@xxxxxxxxxx>
---
 copy/xfs_copy.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 59 insertions(+), 2 deletions(-)

diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c
index a5f25ad..1dc7c65 100644
--- a/copy/xfs_copy.c
+++ b/copy/xfs_copy.c
@@ -64,7 +64,7 @@ pthread_mutex_t	mainwait;
 
 xfs_off_t	write_log_trailer(int fd, wbuf *w, xfs_mount_t *mp);
 xfs_off_t	write_log_header(int fd, wbuf *w, xfs_mount_t *mp);
-static void	format_logs(struct xfs_mount *);
+static int	format_logs(struct xfs_mount *);
 
 /* general purpose message reporting routine */
 
@@ -1293,15 +1293,72 @@ clear_log(
 	}
 }
 
+/*
+ * Format the log to a particular cycle number. This is required for version 5
+ * superblock filesystems to provide metadata LSN validity guarantees.
+ */
 static void
+format_log(
+	struct xfs_mount	*mp,
+	thread_args		*tcarg,
+	wbuf			*buf)
+{
+	int			logstart;
+	int			length;
+	int			cycle = XLOG_INIT_CYCLE;
+
+	buf->owner = tcarg;
+	buf->length = buf->size;
+	buf->position = XFS_FSB_TO_DADDR(mp, mp->m_sb.sb_logstart) << BBSHIFT;
+
+	logstart = XFS_FSB_TO_BB(mp, mp->m_sb.sb_logstart);
+	length = XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks);
+
+	/*
+	 * Bump the cycle number on v5 superblock filesystems to guarantee that
+	 * all existing metadata LSNs are valid (behind the current LSN) on the
+	 * target fs.
+	 */
+	if (xfs_sb_version_hascrc(&mp->m_sb))
+		cycle = mp->m_log->l_curr_cycle + 1;
+
+	/*
+	 * Format the entire log into the memory buffer and write it out. If the
+	 * write fails, mark the target inactive so the failure is reported.
+	 */
+	libxfs_log_clear(NULL, buf->data, logstart, length, &buf->owner->uuid,
+			 xfs_sb_version_haslogv2(&mp->m_sb) ? 2 : 1,
+			 mp->m_sb.sb_logsunit, XLOG_FMT, cycle);
+	if (do_write(buf->owner, buf))
+		target[tcarg->id].state = INACTIVE;
+}
+
+static int
 format_logs(
 	struct xfs_mount	*mp)
 {
 	thread_args		*tcarg;
 	int			i;
+	wbuf			logbuf;
+	int			logsize;
+
+	if (xfs_sb_version_hascrc(&mp->m_sb)) {
+		logsize = XFS_FSB_TO_B(mp, mp->m_sb.sb_logblocks);
+		if (!wbuf_init(&logbuf, logsize, w_buf.data_align,
+			       w_buf.min_io_size, w_buf.id))
+			return -ENOMEM;
+	}
 
 	for (i = 0, tcarg = targ; i < num_targets; i++)  {
-		clear_log(mp, tcarg);
+		if (xfs_sb_version_hascrc(&mp->m_sb))
+			format_log(mp, tcarg, &logbuf);
+		else
+			clear_log(mp, tcarg);
 		tcarg++;
 	}
+
+	if (xfs_sb_version_hascrc(&mp->m_sb))
+		free(logbuf.data);
+
+	return 0;
 }
-- 
2.1.0

_______________________________________________
xfs mailing list
xfs@xxxxxxxxxxx
http://oss.sgi.com/mailman/listinfo/xfs



[Index of Archives]     [Linux XFS Devel]     [Linux Filesystem Development]     [Filesystem Testing]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux