xfs
[Top] [All Lists]

[PATCH v3 17/18] xfs_copy: refactor log format code into new helper

To: xfs@xxxxxxxxxxx
Subject: [PATCH v3 17/18] xfs_copy: refactor log format code into new helper
From: Brian Foster <bfoster@xxxxxxxxxx>
Date: Fri, 2 Oct 2015 14:19:54 -0400
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1443809995-20395-1-git-send-email-bfoster@xxxxxxxxxx>
References: <1443809995-20395-1-git-send-email-bfoster@xxxxxxxxxx>
The xfs_copy log format code is mostly open-coded into the main()
function of the application. Support for v5 superblock log formatting
will require an alternate mechanism than that utilized for v4
superblocks and older.

As such, refactor the log formatting code into new helper functions. The
top-level helper iterates the copy target devices and another helper
implements the log format magic. This patch does not change existing
behavior.

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

diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c
index e03796a..a5f25ad 100644
--- a/copy/xfs_copy.c
+++ b/copy/xfs_copy.c
@@ -62,8 +62,9 @@ pthread_mutex_t       mainwait;
 #define ACTIVE         1
 #define INACTIVE       2
 
-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);
+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 *);
 
 /* general purpose message reporting routine */
 
@@ -518,7 +519,7 @@ main(int argc, char **argv)
        int             i, j;
        int             howfar = 0;
        int             open_flags;
-       xfs_off_t       pos, end_pos;
+       xfs_off_t       pos;
        size_t          length;
        int             c;
        __uint64_t      size, sizeb;
@@ -1160,29 +1161,11 @@ main(int argc, char **argv)
        }
 
        if (kids > 0)  {
-               if (!duplicate)  {
-
+               if (!duplicate)
                        /* write a clean log using the specified UUID */
-                       for (j = 0, tcarg = targ; j < num_targets; j++)  {
-                               w_buf.owner = tcarg;
-                               w_buf.length = rounddown(w_buf.size,
-                                                        w_buf.min_io_size);
-                               pos = write_log_header(
-                                                       source_fd, &w_buf, mp);
-                               end_pos = write_log_trailer(
-                                                       source_fd, &w_buf, mp);
-                               w_buf.position = pos;
-                               memset(w_buf.data, 0, w_buf.length);
-
-                               while (w_buf.position < end_pos)  {
-                                       do_write(tcarg, NULL);
-                                       w_buf.position += w_buf.length;
-                               }
-                               tcarg++;
-                       }
-               } else {
+                       format_logs(mp);
+               else
                        num_ags = 1;
-               }
 
                /* reread and rewrite superblocks (UUID and in-progress) */
                /* [backwards, so inprogress bit only updated when done] */
@@ -1284,3 +1267,41 @@ write_log_trailer(int fd, wbuf *buf, xfs_mount_t *mp)
 
        return buf->position;
 }
+
+/*
+ * Clear a log by writing a record at the head, the tail and zeroing everything
+ * in between.
+ */
+static void
+clear_log(
+       struct xfs_mount        *mp,
+       thread_args             *tcarg)
+{
+       xfs_off_t               pos;
+       xfs_off_t               end_pos;
+
+       w_buf.owner = tcarg;
+       w_buf.length = rounddown(w_buf.size, w_buf.min_io_size);
+       pos = write_log_header(source_fd, &w_buf, mp);
+       end_pos = write_log_trailer(source_fd, &w_buf, mp);
+       w_buf.position = pos;
+       memset(w_buf.data, 0, w_buf.length);
+
+       while (w_buf.position < end_pos)  {
+               do_write(tcarg, NULL);
+               w_buf.position += w_buf.length;
+       }
+}
+
+static void
+format_logs(
+       struct xfs_mount        *mp)
+{
+       thread_args             *tcarg;
+       int                     i;
+
+       for (i = 0, tcarg = targ; i < num_targets; i++)  {
+               clear_log(mp, tcarg);
+               tcarg++;
+       }
+}
-- 
2.1.0

<Prev in Thread] Current Thread [Next in Thread>