]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
mdrestore: Extract target device size verification into a function
authorChandan Babu R <chandan.babu@oracle.com>
Mon, 6 Nov 2023 13:10:52 +0000 (18:40 +0530)
committerCarlos Maiolino <cem@kernel.org>
Tue, 21 Nov 2023 13:09:36 +0000 (14:09 +0100)
A future commit will need to perform the device size verification on an
external log device. In preparation for this, this commit extracts the
relevant portions into a new function. No functional changes have been
introduced.

Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandan.babu@oracle.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
mdrestore/xfs_mdrestore.c

index b247a4bfb118a42df88f453d03c7afaf60cc4f82..0fdbfce7afea487476c1e4143cf138377e3b0c02 100644 (file)
@@ -89,6 +89,30 @@ open_device(
        return fd;
 }
 
+static void
+verify_device_size(
+       int             dev_fd,
+       bool            is_file,
+       xfs_rfsblock_t  nr_blocks,
+       uint32_t        blocksize)
+{
+       if (is_file) {
+               /* ensure regular files are correctly sized */
+               if (ftruncate(dev_fd, nr_blocks * blocksize))
+                       fatal("cannot set filesystem image size: %s\n",
+                               strerror(errno));
+       } else {
+               /* ensure device is sufficiently large enough */
+               char            lb[XFS_MAX_SECTORSIZE] = { 0 };
+               off64_t         off;
+
+               off = nr_blocks * blocksize - sizeof(lb);
+               if (pwrite(dev_fd, lb, sizeof(lb), off) < 0)
+                       fatal("failed to write last block, is target too "
+                               "small? (error: %s)\n", strerror(errno));
+       }
+}
+
 static void
 read_header_v1(
        union mdrestore_headers *h,
@@ -173,23 +197,8 @@ restore_v1(
 
        ((struct xfs_dsb*)block_buffer)->sb_inprogress = 1;
 
-       if (is_target_file)  {
-               /* ensure regular files are correctly sized */
-
-               if (ftruncate(ddev_fd, sb.sb_dblocks * sb.sb_blocksize))
-                       fatal("cannot set filesystem image size: %s\n",
-                               strerror(errno));
-       } else  {
-               /* ensure device is sufficiently large enough */
-
-               char            lb[XFS_MAX_SECTORSIZE] = { 0 };
-               off64_t         off;
-
-               off = sb.sb_dblocks * sb.sb_blocksize - sizeof(lb);
-               if (pwrite(ddev_fd, lb, sizeof(lb), off) < 0)
-                       fatal("failed to write last block, is target too "
-                               "small? (error: %s)\n", strerror(errno));
-       }
+       verify_device_size(ddev_fd, is_target_file, sb.sb_dblocks,
+                       sb.sb_blocksize);
 
        bytes_read = 0;