From: Brian Foster <bfoster@redhat.com>
To: xfs@oss.sgi.com
Subject: [PATCH] mkfs: don't zero old superblocks if file was truncated
Date: Thu, 26 Mar 2015 12:48:48 -0400 [thread overview]
Message-ID: <1427388528-62906-1-git-send-email-bfoster@redhat.com> (raw)
If the force overwrite option is passed to mkfs, we attempt to zero old
superblock metadata on the mkfs target. We attempt to read the primary
superblock to identify the secondary superblocks.
If the mkfs target is a regular file, it is truncated on open and the
secondary superblock zeroing operation returns a spurious and incorrect
error message due to a 0-byte read:
$ mkfs.xfs -f -d file=1,name=xfs.fs,size=32m
...
existing superblock read failed: Inappropriate ioctl for device
Fix the error reporting in zero_old_xfs_structures() to only print an
error string if the pread() call returns an error. Warn the user if the
read doesn't match the sector size. Finally, detect the case where we
know we've already truncated a regular file and skip the sb zeroing.
Reported-by: Alexander Tsvetkov <alexander.tsvetkov@oracle.com>
Signed-off-by: Brian Foster <bfoster@redhat.com>
---
mkfs/xfs_mkfs.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 484e7a8..5084d75 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -817,6 +817,13 @@ zero_old_xfs_structures(
__uint32_t bsize;
int i;
xfs_off_t off;
+ int tmp;
+
+ /*
+ * We open regular files with O_TRUNC|O_CREAT. Nothing to do here...
+ */
+ if (xi->disfile && xi->dcreat)
+ return;
/*
* read in existing filesystem superblock, use its geometry
@@ -830,11 +837,16 @@ zero_old_xfs_structures(
}
memset(buf, 0, new_sb->sb_sectsize);
- if (pread(xi->dfd, buf, new_sb->sb_sectsize, 0) != new_sb->sb_sectsize) {
+ tmp = pread(xi->dfd, buf, new_sb->sb_sectsize, 0);
+ if (tmp < 0) {
fprintf(stderr, _("existing superblock read failed: %s\n"),
strerror(errno));
- free(buf);
- return;
+ goto done;
+ }
+ if (tmp != new_sb->sb_sectsize) {
+ fprintf(stderr,
+ _("warning: could not read existing superblock, skip zeroing\n"));
+ goto done;
}
libxfs_sb_from_disk(&sb, buf);
--
1.9.3
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
reply other threads:[~2015-03-26 16:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1427388528-62906-1-git-send-email-bfoster@redhat.com \
--to=bfoster@redhat.com \
--cc=xfs@oss.sgi.com \
/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