Linux XFS filesystem development
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: djwong@kernel.org, cem@kernel.org
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 3/5] xfs_copy: distinguish short writes to EOD from runtime errors
Date: Wed, 20 Dec 2023 09:12:12 -0800	[thread overview]
Message-ID: <170309218403.1607770.4299633539281504295.stgit@frogsfrogsfrogs> (raw)
In-Reply-To: <170309218362.1607770.1848898546436984000.stgit@frogsfrogsfrogs>

From: Darrick J. Wong <djwong@kernel.org>

Detect short writes to the end of the destination device and report
them.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 copy/xfs_copy.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)


diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c
index 79f65946..d9a14a95 100644
--- a/copy/xfs_copy.c
+++ b/copy/xfs_copy.c
@@ -889,18 +889,28 @@ main(int argc, char **argv)
 		} else  {
 			char	*lb[XFS_MAX_SECTORSIZE] = { NULL };
 			off64_t	off;
+			ssize_t	len;
 
 			/* ensure device files are sufficiently large */
 
 			off = mp->m_sb.sb_dblocks * source_blocksize;
 			off -= sizeof(lb);
-			if (pwrite(target[i].fd, lb, sizeof(lb), off) < 0)  {
+			len = pwrite(target[i].fd, lb, XFS_MAX_SECTORSIZE, off);
+			if (len < 0) {
 				do_log(_("%s:  failed to write last block\n"),
 					progname);
 				do_log(_("\tIs target \"%s\" too small?\n"),
 					target[i].name);
 				die_perror();
 			}
+			if (len != XFS_MAX_SECTORSIZE) {
+				do_log(
+ _("%s:  short write to last block: %zd bytes, %zu expected\n"),
+					progname, len, XFS_MAX_SECTORSIZE);
+				do_log(_("\tIs target \"%s\" too small?\n"),
+					target[i].name);
+				exit(1);
+			}
 		}
 	}
 


  parent reply	other threads:[~2023-12-20 17:12 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-20 17:06 [PATCHBOMB] xfsprogs: pending changes for 6.6 Darrick J. Wong
2023-12-20 17:10 ` [PATCHSET 1/4] xfsprogs: various bug fixes " Darrick J. Wong
2023-12-20 17:11   ` [PATCH 1/5] libfrog: move 64-bit division wrappers to libfrog Darrick J. Wong
2023-12-20 17:11   ` [PATCH 2/5] libxfs: don't UAF a requeued EFI Darrick J. Wong
2023-12-20 17:12   ` Darrick J. Wong [this message]
2023-12-21  5:29     ` [PATCH 3/5] xfs_copy: distinguish short writes to EOD from runtime errors Christoph Hellwig
2023-12-20 17:12   ` [PATCH 4/5] xfs_copy: actually do directio writes to block devices Darrick J. Wong
2023-12-21  5:30     ` Christoph Hellwig
2023-12-20 17:12   ` [PATCH 5/5] xfs_db: report the device associated with each io cursor Darrick J. Wong
2023-12-21  5:30     ` Christoph Hellwig
2023-12-20 17:10 ` [PATCHSET 2/4] xfs_metadump: various bug fixes Darrick J. Wong
2023-12-20 17:12   ` [PATCH 1/6] xfs_metadump.8: update for external log device options Darrick J. Wong
2023-12-20 17:13   ` [PATCH 2/6] xfs_mdrestore: fix uninitialized variables in mdrestore main Darrick J. Wong
2023-12-20 17:13   ` [PATCH 3/6] xfs_mdrestore: emit newlines for fatal errors Darrick J. Wong
2023-12-20 17:13   ` [PATCH 4/6] xfs_mdrestore: EXTERNALLOG is a compat value, not incompat Darrick J. Wong
2023-12-20 17:14   ` [PATCH 5/6] xfs_mdrestore: fix missed progress reporting Darrick J. Wong
2023-12-20 17:14   ` [PATCH 6/6] xfs_mdrestore: refactor progress printing and sb fixup code Darrick J. Wong
2023-12-21  5:32     ` Christoph Hellwig
2023-12-20 17:11 ` [PATCHSET v28.3 3/4] xfs_io: clean up scrub subcommand code Darrick J. Wong
2023-12-20 17:14   ` [PATCH 1/4] xfs_io: set exitcode = 1 on parsing errors in scrub/repair command Darrick J. Wong
2023-12-21  5:32     ` Christoph Hellwig
2023-12-20 17:14   ` [PATCH 2/4] xfs_io: collapse trivial helpers Darrick J. Wong
2023-12-21  5:48     ` Christoph Hellwig
2023-12-20 17:15   ` [PATCH 3/4] xfs_io: extract contorl number parsing routines Darrick J. Wong
2023-12-21  5:49     ` Christoph Hellwig
2023-12-21  5:50       ` Christoph Hellwig
2023-12-20 17:15   ` [PATCH 4/4] xfs_io: support passing the FORCE_REBUILD flag to online repair Darrick J. Wong
2023-12-20 17:11 ` [PATCHSET v28.3 4/4] xfsprogs: force rebuilding of metadata Darrick J. Wong
2023-12-20 17:15   ` [PATCH 1/3] xfs_scrub: handle spurious wakeups in scan_fs_tree Darrick J. Wong
2023-12-20 17:15   ` [PATCH 2/3] xfs_scrub: don't retry unsupported optimizations Darrick J. Wong
2023-12-20 17:16   ` [PATCH 3/3] xfs_scrub: try to use XFS_SCRUB_IFLAG_FORCE_REBUILD Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=170309218403.1607770.4299633539281504295.stgit@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=cem@kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox