]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: pass lsn param to log clear and record header logging helpers
authorBrian Foster <bfoster@redhat.com>
Tue, 13 Oct 2015 23:58:24 +0000 (10:58 +1100)
committerDave Chinner <david@fromorbit.com>
Tue, 13 Oct 2015 23:58:24 +0000 (10:58 +1100)
In preparation to support the ability to format the log with an
arbitrary cycle number, the log clear and record logging helpers must be
updated to receive the desired cycle and LSN values as parameters.

Update libxfs_log_clear() to receive the desired cycle number to format
the log with. Define a preprocessor directive to represent the currently
hardcoded case of cycle 1. Update libxfs_log_header() to receive the lsn
and tail_lsn of the record to write. Use a NULL value LSN to represent
the currently hardcoded behavior.

All callers are updated to use the current default values. As such, this
patch does not change behavior in any way.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
copy/xfs_copy.c
db/sb.c
include/libxfs.h
libxfs/rdwr.c
mkfs/xfs_mkfs.c
repair/phase2.c

index 2f4f5cbb34493b12b35bfa5ab810eabbbf405424..949be5f05751b1a1cb010f53301b07c667550987 100644 (file)
@@ -1212,8 +1212,8 @@ write_log_header(int fd, wbuf *buf, xfs_mount_t *mp)
 
        offset = libxfs_log_header(p, &buf->owner->uuid,
                        xfs_sb_version_haslogv2(&mp->m_sb) ? 2 : 1,
-                       mp->m_sb.sb_logsunit, XLOG_FMT,
-                       next_log_chunk, buf);
+                       mp->m_sb.sb_logsunit, XLOG_FMT, NULLCOMMITLSN,
+                       NULLCOMMITLSN, next_log_chunk, buf);
        do_write(buf->owner);
 
        return roundup(logstart + offset, buf->length);
diff --git a/db/sb.c b/db/sb.c
index 598e787d458f8987e62e098b40f6704d72b7283a..560e6533252f2551d49c04a7d8dd4cf2a4ee1af8 100644 (file)
--- a/db/sb.c
+++ b/db/sb.c
@@ -278,7 +278,7 @@ sb_logzero(uuid_t *uuidp)
                        (xfs_extlen_t)XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks),
                        uuidp,
                        xfs_sb_version_haslogv2(&mp->m_sb) ? 2 : 1,
-                       mp->m_sb.sb_logsunit, XLOG_FMT)) {
+                       mp->m_sb.sb_logsunit, XLOG_FMT, XLOG_INIT_CYCLE)) {
                dbprintf(_("ERROR: cannot clear the log\n"));
                return 0;
        }
index cc06fc65f8ad31b175fb2c58bbd37024fb12090d..6c8793433952ee452aa7e609e032f81debdccbab 100644 (file)
@@ -149,10 +149,14 @@ extern int        platform_nproc(void);
 /* check or write log footer: specify device, log size in blocks & uuid */
 typedef char   *(libxfs_get_block_t)(char *, int, void *);
 
-extern int     libxfs_log_clear (struct xfs_buftarg *, xfs_daddr_t, uint,
-                               uuid_t *, int, int, int);
-extern int     libxfs_log_header (char *, uuid_t *, int, int, int,
-                               libxfs_get_block_t *, void *);
+/*
+ * Helpers to clear the log to a particular log cycle.
+ */
+#define XLOG_INIT_CYCLE        1
+extern int     libxfs_log_clear(struct xfs_buftarg *, xfs_daddr_t, uint,
+                                uuid_t *, int, int, int, int);
+extern int     libxfs_log_header(char *, uuid_t *, int, int, int, xfs_lsn_t,
+                                 xfs_lsn_t, libxfs_get_block_t *, void *);
 
 
 /* Shared utility routines */
index 282f22d7990357d394013519b0ef89b46972d084..da781daa47257747244ff30dd5e55429f4066cf8 100644 (file)
@@ -150,14 +150,21 @@ libxfs_log_clear(
        uuid_t                  *fs_uuid,
        int                     version,
        int                     sunit,
-       int                     fmt)
+       int                     fmt,
+       int                     cycle)
 {
        xfs_buf_t               *bp;
        int                     len;
+       xfs_lsn_t               lsn;
 
        if (!btp->dev || !fs_uuid)
                return -EINVAL;
 
+       if (cycle != XLOG_INIT_CYCLE)
+               return -EINVAL;
+
+       lsn = xlog_assign_lsn(cycle, 0);
+
        /* first zero the log */
        libxfs_device_zero(btp, start, length);
 
@@ -165,8 +172,8 @@ libxfs_log_clear(
        len = ((version == 2) && sunit) ? BTOBB(sunit) : 2;
        len = MAX(len, 2);
        bp = libxfs_getbufr(btp, start, len);
-       libxfs_log_header(XFS_BUF_PTR(bp),
-                         fs_uuid, version, sunit, fmt, next, bp);
+       libxfs_log_header(XFS_BUF_PTR(bp), fs_uuid, version, sunit, fmt, lsn,
+                         lsn, next, bp);
        bp->b_flags |= LIBXFS_B_DIRTY;
        libxfs_putbufr(bp);
        return 0;
@@ -179,6 +186,8 @@ libxfs_log_header(
        int                     version,
        int                     sunit,
        int                     fmt,
+       xfs_lsn_t               lsn,
+       xfs_lsn_t               tail_lsn,
        libxfs_get_block_t      *nextfunc,
        void                    *private)
 {
@@ -187,11 +196,16 @@ libxfs_log_header(
        __be32                  cycle_lsn;
        int                     i, len;
 
+       if (lsn == NULLCOMMITLSN)
+               lsn = xlog_assign_lsn(XLOG_INIT_CYCLE, 0);
+       if (tail_lsn == NULLCOMMITLSN)
+               tail_lsn = lsn;
+
        len = ((version == 2) && sunit) ? BTOBB(sunit) : 1;
 
        memset(p, 0, BBSIZE);
        head->h_magicno = cpu_to_be32(XLOG_HEADER_MAGIC_NUM);
-       head->h_cycle = cpu_to_be32(1);
+       head->h_cycle = cpu_to_be32(CYCLE_LSN(lsn));
        head->h_version = cpu_to_be32(version);
        if (len != 1)
                head->h_len = cpu_to_be32(sunit - BBSIZE);
@@ -203,8 +217,8 @@ libxfs_log_header(
        head->h_fmt = cpu_to_be32(fmt);
        head->h_size = cpu_to_be32(XLOG_HEADER_CYCLE_SIZE);
 
-       head->h_lsn = cpu_to_be64(xlog_assign_lsn(1, 0));
-       head->h_tail_lsn = cpu_to_be64(xlog_assign_lsn(1, 0));
+       head->h_lsn = cpu_to_be64(lsn);
+       head->h_tail_lsn = cpu_to_be64(tail_lsn);
 
        memcpy(&head->h_fs_uuid, fs_uuid, sizeof(uuid_t));
 
index 903911175a73a16530b53f5b31cc65e109fdadb3..9fb811e0d35c4f87c18d5d04db2d0c50fb24de12 100644 (file)
@@ -2713,7 +2713,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
        libxfs_log_clear(mp->m_logdev_targp,
                XFS_FSB_TO_DADDR(mp, logstart),
                (xfs_extlen_t)XFS_FSB_TO_BB(mp, logblocks),
-               &sbp->sb_uuid, logversion, lsunit, XLOG_FMT);
+               &sbp->sb_uuid, logversion, lsunit, XLOG_FMT, XLOG_INIT_CYCLE);
 
        mp = libxfs_mount(mp, sbp, xi.ddev, xi.logdev, xi.rtdev, 0);
        if (mp == NULL) {
index 7e264c41af031add845fba139bc98fdf02e4c372..0673a0cd57082506969e70018a8725c334592b1f 100644 (file)
@@ -98,7 +98,7 @@ zero_log(xfs_mount_t *mp)
                (xfs_extlen_t)XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks),
                &mp->m_sb.sb_uuid,
                xfs_sb_version_haslogv2(&mp->m_sb) ? 2 : 1,
-               mp->m_sb.sb_logsunit, XLOG_FMT);
+               mp->m_sb.sb_logsunit, XLOG_FMT, XLOG_INIT_CYCLE);
 }
 
 /*