From: Brian Foster <bfoster@redhat.com>
To: "Jan Ťulák" <jtulak@redhat.com>
Cc: xfs@oss.sgi.com
Subject: Re: [PATCH 16/17] mkfs fix: handling of files
Date: Fri, 26 Jun 2015 15:32:35 -0400 [thread overview]
Message-ID: <20150626193235.GL40750@bfoster.bfoster> (raw)
In-Reply-To: <1434711726-13092-17-git-send-email-jtulak@redhat.com>
On Fri, Jun 19, 2015 at 01:02:05PM +0200, Jan Ťulák wrote:
> If mkfs is making a FS in a file, then the new FS should take host FS blocksize
> as sectorsize. This patch is ensuring it by using statfs() instead of stat()
> and platform_findsizes().
>
> Signed-off-by: Jan Ťulák <jtulak@redhat.com>
> ---
> libxfs/init.c | 7 +++++--
> mkfs/xfs_mkfs.c | 54 +++++++++++++++++++++++++++++-------------------------
> 2 files changed, 34 insertions(+), 27 deletions(-)
>
> diff --git a/libxfs/init.c b/libxfs/init.c
> index ed97043..02d152c 100644
> --- a/libxfs/init.c
> +++ b/libxfs/init.c
> @@ -17,6 +17,7 @@
> */
>
> #include <sys/stat.h>
> +#include <sys/vfs.h>
> #include "init.h"
>
> #include "libxfs_priv.h"
> @@ -247,6 +248,7 @@ libxfs_init(libxfs_init_t *a)
> int rval = 0;
> int flags;
> struct stat st;
> + struct statfs stfs;
>
> dpath[0] = logpath[0] = rtpath[0] = '\0';
> dname = a->dname;
> @@ -280,8 +282,9 @@ libxfs_init(libxfs_init_t *a)
> a->setblksize);
> a->dfd = libxfs_device_to_fd(a->ddev);
> stat(dname, &st);
> - a->dsize = st.st_size;
> - a->dbsize = st.st_blksize;
> + statfs(dname, &stfs);
> + a->dsize = st.st_size/BBSIZE;
Ok, if this should be in basic blocks, can we fix it in the previous
patch where the code was introduced? Otherwise this seems Ok.
Brian
> + a->dbsize = stfs.f_bsize;
> } else {
> if (!check_open(dname, flags, &rawfile, &blockfile))
> goto done;
> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> index ce64230..2e455db 100644
> --- a/mkfs/xfs_mkfs.c
> +++ b/mkfs/xfs_mkfs.c
> @@ -18,6 +18,7 @@
>
> #include <xfs/libxfs.h>
> #include <ctype.h>
> +#include <sys/vfs.h>
> #ifdef ENABLE_BLKID
> #include <blkid/blkid.h>
> #else
> @@ -865,31 +866,23 @@ static void get_topology(
> struct fs_topology *ft,
> int force_overwrite)
> {
> - if (!xi->disfile) {
> - char *dfile = xi->volname ? xi->volname : xi->dname;
> - struct stat statbuf;
> + char *dfile = xi->volname ? xi->volname : xi->dname;
> + struct stat statbuf;
> + struct statfs statfsbuf;
>
> - /*
> - * If our target is a regular file, and xi->disfile isn't
> - * set (i.e. no "-d file" invocation), use platform_findsizes
> - * to try to obtain the underlying filesystem's requirements
> - * for direct IO; we'll set our sector size to that if possible.
> - */
> - if (!stat(dfile, &statbuf) && S_ISREG(statbuf.st_mode)) {
> - int fd;
> - long long dummy;
> -
> - fd = open(dfile, O_RDONLY);
> - if (fd >= 0) {
> - platform_findsizes(dfile, fd, &dummy,
> - &ft->lsectorsize);
> - close(fd);
> - }
> - } else {
> - blkid_get_topology(dfile, &ft->dsunit, &ft->dswidth,
> - &ft->lsectorsize, &ft->psectorsize,
> - force_overwrite);
> - }
> + /*
> + * If our target is a regular file, use statfs
> + * to try to obtain the underlying filesystem's blocksize.
> + */
> + if (xi->disfile ||
> + (!stat(dfile, &statbuf) && S_ISREG(statbuf.st_mode))) {
> +
> + statfs(dfile, &statfsbuf);
> + ft->lsectorsize = statfsbuf.f_bsize;
> + } else {
> + blkid_get_topology(dfile, &ft->dsunit, &ft->dswidth,
> + &ft->lsectorsize, &ft->psectorsize,
> + force_overwrite);
> }
>
> if (xi->rtname && !xi->risfile) {
> @@ -930,9 +923,20 @@ static void get_topology(
> {
>
> char *dfile = xi->volname ? xi->volname : xi->dname;
> + struct stat statbuf;
> + struct statfs statfsbuf;
> int bsz = BBSIZE;
>
> - if (!xi->disfile) {
> + /*
> + * If our target is a regular file, use statfs
> + * to try to obtain the underlying filesystem's blocksize.
> + */
> + if (xi->disfile ||
> + (!stat(dfile, &statbuf) && S_ISREG(statbuf.st_mode))) {
> +
> + statfs(dfile, &statfsbuf);
> + bsz = statfsbuf.f_bsize;
> + } else {
> int fd;
> long long dummy;
>
> --
> 2.1.0
>
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2015-06-26 19:32 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-19 11:01 [PATCH 00/17] mkfs: sanitise input parameters Jan Ťulák
2015-06-19 11:01 ` [PATCH 01/17] xfsprogs: use common code for multi-disk detection Jan Ťulák
2015-06-19 11:10 ` Christoph Hellwig
2015-06-19 11:51 ` Jan Tulak
2015-06-25 19:37 ` Brian Foster
2015-07-02 12:47 ` Jan Tulak
2015-07-02 14:14 ` Brian Foster
2015-07-02 23:05 ` Dave Chinner
2015-07-03 13:22 ` Brian Foster
2015-07-08 16:14 ` Jan Tulak
2015-07-09 0:45 ` Dave Chinner
2015-07-09 8:24 ` Jan Tulak
2015-07-03 10:06 ` Jan Tulak
2015-06-19 11:01 ` [PATCH 02/17] mkfs: sanitise ftype parameter values Jan Ťulák
2015-06-25 19:37 ` Brian Foster
2015-06-19 11:01 ` [PATCH 03/17] mkfs: Sanitise the superblock feature macros Jan Ťulák
2015-06-25 19:38 ` Brian Foster
2015-07-03 9:53 ` Jan Tulak
2015-07-03 13:24 ` Brian Foster
2015-06-19 11:01 ` [PATCH 04/17] mkfs: validate all input values Jan Ťulák
2015-06-25 19:38 ` Brian Foster
2015-06-19 11:01 ` [PATCH 05/17] mkfs: factor boolean option parsing Jan Ťulák
2015-06-25 19:38 ` Brian Foster
2015-06-19 11:01 ` [PATCH 06/17] mkfs: validate logarithmic parameters sanely Jan Ťulák
2015-06-26 17:16 ` Brian Foster
2015-06-19 11:01 ` [PATCH 07/17] mkfs: structify input parameter passing Jan Ťulák
2015-06-26 17:16 ` Brian Foster
2015-06-19 11:01 ` [PATCH 08/17] mkfs: getbool is redundant Jan Ťulák
2015-06-26 17:17 ` Brian Foster
2015-06-30 1:32 ` Dave Chinner
2015-06-19 11:01 ` [PATCH 09/17] mkfs: use getnum_checked for all ranged parameters Jan Ťulák
2015-06-26 17:17 ` Brian Foster
2015-06-19 11:01 ` [PATCH 10/17] mkfs: add respecification detection to generic parsing Jan Ťulák
2015-06-26 17:17 ` Brian Foster
2015-06-19 11:02 ` [PATCH 11/17] mkfs: table based parsing for converted parameters Jan Ťulák
2015-06-26 17:17 ` Brian Foster
2015-06-19 11:02 ` [PATCH 12/17] mkfs: merge getnum Jan Ťulák
2015-06-26 17:17 ` Brian Foster
2015-06-19 11:02 ` [PATCH 13/17] mkfs: encode conflicts into parsing table Jan Ťulák
2015-06-26 17:17 ` Brian Foster
2015-06-30 3:57 ` Dave Chinner
2015-06-30 11:27 ` Brian Foster
2015-07-01 8:30 ` Jan Tulak
2015-06-19 11:02 ` [PATCH 14/17] mkfs: add string options to generic parsing Jan Ťulák
2015-06-26 19:32 ` Brian Foster
2015-06-19 11:02 ` [PATCH 15/17] mkfs: don't treat files as though they are block devices Jan Ťulák
2015-06-26 19:32 ` Brian Foster
2015-06-19 11:02 ` [PATCH 16/17] mkfs fix: handling of files Jan Ťulák
2015-06-26 19:32 ` Brian Foster [this message]
2015-06-19 11:02 ` [PATCH 17/17] mkfs: move spinodes crc check Jan Ťulák
2015-06-26 19:32 ` Brian Foster
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=20150626193235.GL40750@bfoster.bfoster \
--to=bfoster@redhat.com \
--cc=jtulak@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