linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Allison Collins <allison.henderson@oracle.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>, sandeen@sandeen.net
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 8/9] libfrog: create xfd_open function
Date: Sun, 1 Sep 2019 13:55:12 -0700	[thread overview]
Message-ID: <98cd2e1b-17d9-617a-87f4-d5c46bf231ab@oracle.com> (raw)
In-Reply-To: <156713887587.386621.8656028056753211579.stgit@magnolia>

On 8/29/19 9:21 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Create a helper to open a file and initialize the xfd structure.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Looks good
Reviewed-by: Allison Collins <allison.henderson@oracle.com>

> ---
>   fsr/xfs_fsr.c    |   26 ++++++--------------------
>   include/xfrog.h  |    1 +
>   libfrog/fsgeom.c |   22 ++++++++++++++++++++++
>   quota/quot.c     |    7 ++++---
>   scrub/phase1.c   |   25 ++++++++-----------------
>   5 files changed, 41 insertions(+), 40 deletions(-)
> 
> 
> diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
> index 36402252..e8d41aaf 100644
> --- a/fsr/xfs_fsr.c
> +++ b/fsr/xfs_fsr.c
> @@ -592,18 +592,10 @@ fsrfs(char *mntdir, xfs_ino_t startino, int targetrange)
>   		return -1;
>   	}
>   
> -	if ((fsxfd.fd = open(mntdir, O_RDONLY)) < 0) {
> -		fsrprintf(_("unable to open: %s: %s\n"),
> -		          mntdir, strerror( errno ));
> -		free(fshandlep);
> -		return -1;
> -	}
> -
> -	ret = xfd_prepare_geometry(&fsxfd);
> +	ret = xfd_open(&fsxfd, mntdir, O_RDONLY);
>   	if (ret) {
> -		fsrprintf(_("Skipping %s: could not get XFS geometry\n"),
> -			  mntdir);
> -		xfd_close(&fsxfd);
> +		fsrprintf(_("unable to open XFS file: %s: %s\n"),
> +		          mntdir, strerror(ret));
>   		free(fshandlep);
>   		return -1;
>   	}
> @@ -725,16 +717,10 @@ fsrfile(
>   	 * Need to open something on the same filesystem as the
>   	 * file.  Open the parent.
>   	 */
> -	fsxfd.fd = open(getparent(fname), O_RDONLY);
> -	if (fsxfd.fd < 0) {
> -		fsrprintf(_("unable to open sys handle for %s: %s\n"),
> -			fname, strerror(errno));
> -		goto out;
> -	}
> -
> -	error = xfd_prepare_geometry(&fsxfd);
> +	error = xfd_open(&fsxfd, getparent(fname), O_RDONLY);
>   	if (error) {
> -		fsrprintf(_("Unable to get geom on fs for: %s\n"), fname);
> +		fsrprintf(_("unable to open sys handle for XFS file %s: %s\n"),
> +			fname, strerror(error));
>   		goto out;
>   	}
>   
> diff --git a/include/xfrog.h b/include/xfrog.h
> index 7bda9810..3a49acc3 100644
> --- a/include/xfrog.h
> +++ b/include/xfrog.h
> @@ -52,6 +52,7 @@ struct xfs_fd {
>   #define XFS_FD_INIT_EMPTY	XFS_FD_INIT(-1)
>   
>   int xfd_prepare_geometry(struct xfs_fd *xfd);
> +int xfd_open(struct xfs_fd *xfd, const char *pathname, int flags);
>   int xfd_close(struct xfs_fd *xfd);
>   
>   /* Convert AG number and AG inode number into fs inode number. */
> diff --git a/libfrog/fsgeom.c b/libfrog/fsgeom.c
> index cf9323c1..47644dc3 100644
> --- a/libfrog/fsgeom.c
> +++ b/libfrog/fsgeom.c
> @@ -117,6 +117,28 @@ xfd_prepare_geometry(
>   	return 0;
>   }
>   
> +/* Open a file on an XFS filesystem.  Returns zero or a positive error code. */
> +int
> +xfd_open(
> +	struct xfs_fd		*xfd,
> +	const char		*pathname,
> +	int			flags)
> +{
> +	int			ret;
> +
> +	xfd->fd = open(pathname, O_RDONLY);
> +	if (xfd->fd < 0)
> +		return errno;
> +
> +	ret = xfd_prepare_geometry(xfd);
> +	if (ret) {
> +		xfd_close(xfd);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
>   /*
>    * Release any resources associated with this xfs_fd structure.  Returns zero
>    * or a positive error code.
> diff --git a/quota/quot.c b/quota/quot.c
> index 1e970819..4614f684 100644
> --- a/quota/quot.c
> +++ b/quota/quot.c
> @@ -131,7 +131,7 @@ quot_bulkstat_mount(
>   	struct xfs_bstat	*buf;
>   	uint64_t		last = 0;
>   	uint32_t		count;
> -	int			i, sts;
> +	int			i, sts, ret;
>   	du_t			**dp;
>   
>   	/*
> @@ -146,8 +146,9 @@ quot_bulkstat_mount(
>   			*dp = NULL;
>   	ndu[0] = ndu[1] = ndu[2] = 0;
>   
> -	fsxfd.fd = open(fsdir, O_RDONLY);
> -	if (fsxfd.fd < 0) {
> +	ret = xfd_open(&fsxfd, fsdir, O_RDONLY);
> +	if (ret) {
> +		errno = ret;
>   		perror(fsdir);
>   		return;
>   	}
> diff --git a/scrub/phase1.c b/scrub/phase1.c
> index cbdbd010..15e67e37 100644
> --- a/scrub/phase1.c
> +++ b/scrub/phase1.c
> @@ -84,13 +84,17 @@ xfs_setup_fs(
>   	 * CAP_SYS_ADMIN, which we probably need to do anything fancy
>   	 * with the (XFS driver) kernel.
>   	 */
> -	ctx->mnt.fd = open(ctx->mntpoint, O_RDONLY | O_NOATIME | O_DIRECTORY);
> -	if (ctx->mnt.fd < 0) {
> -		if (errno == EPERM)
> +	error = xfd_open(&ctx->mnt, ctx->mntpoint,
> +			O_RDONLY | O_NOATIME | O_DIRECTORY);
> +	if (error) {
> +		if (error == EPERM)
>   			str_info(ctx, ctx->mntpoint,
>   _("Must be root to run scrub."));
> +		else if (error == ENOTTY)
> +			str_error(ctx, ctx->mntpoint,
> +_("Not an XFS filesystem."));
>   		else
> -			str_errno(ctx, ctx->mntpoint);
> +			str_liberror(ctx, error, ctx->mntpoint);
>   		return false;
>   	}
>   
> @@ -110,12 +114,6 @@ _("Must be root to run scrub."));
>   		return false;
>   	}
>   
> -	if (!platform_test_xfs_fd(ctx->mnt.fd)) {
> -		str_info(ctx, ctx->mntpoint,
> -_("Does not appear to be an XFS filesystem!"));
> -		return false;
> -	}
> -
>   	/*
>   	 * Flush everything out to disk before we start checking.
>   	 * This seems to reduce the incidence of stale file handle
> @@ -127,13 +125,6 @@ _("Does not appear to be an XFS filesystem!"));
>   		return false;
>   	}
>   
> -	/* Retrieve XFS geometry. */
> -	error = xfd_prepare_geometry(&ctx->mnt);
> -	if (error) {
> -		str_liberror(ctx, error, _("Retrieving XFS geometry"));
> -		return false;
> -	}
> -
>   	if (!xfs_action_lists_alloc(ctx->mnt.fsgeom.agcount,
>   				&ctx->action_lists)) {
>   		str_error(ctx, ctx->mntpoint, _("Not enough memory."));
> 

  reply	other threads:[~2019-09-01 20:55 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-30  4:20 [PATCH v2 0/9] libxfrog: wrap version ioctl calls Darrick J. Wong
2019-08-30  4:20 ` [PATCH 1/9] libxfs: revert FSGEOMETRY v5 -> v4 hack Darrick J. Wong
2019-08-30 21:03   ` Allison Collins
2019-09-02 22:49   ` Dave Chinner
2019-09-03  6:14     ` Christoph Hellwig
2019-08-30  4:20 ` [PATCH 2/9] xfsprogs: update spdx tags in LICENSES/ Darrick J. Wong
2019-08-30 21:03   ` Allison Collins
2019-08-30  4:20 ` [PATCH 3/9] libfrog: refactor online geometry queries Darrick J. Wong
2019-08-30 21:03   ` Allison Collins
2019-09-03 22:51   ` Dave Chinner
2019-08-30  4:20 ` [PATCH 4/9] libfrog: introduce xfs_fd to wrap an fd to a file on an xfs filesystem Darrick J. Wong
2019-08-30 23:29   ` Allison Collins
2019-08-30 23:31     ` Darrick J. Wong
2019-09-03 22:53   ` Dave Chinner
2019-08-30  4:20 ` [PATCH 5/9] libfrog: store more inode and block geometry in struct xfs_fd Darrick J. Wong
2019-08-31  0:37   ` Allison Collins
2019-08-30  4:21 ` [PATCH 6/9] libfrog: create online fs geometry converters Darrick J. Wong
2019-08-31  5:11   ` Allison Collins
2019-09-03 22:55   ` Dave Chinner
2019-08-30  4:21 ` [PATCH 7/9] libfrog: refactor open-coded bulkstat calls Darrick J. Wong
2019-08-30 23:26   ` Darrick J. Wong
2019-08-31  0:42   ` [PATCH v2 " Darrick J. Wong
2019-09-03 22:57     ` Dave Chinner
2019-09-01 20:55   ` [PATCH " Allison Collins
2019-09-01 21:05     ` Darrick J. Wong
2019-08-30  4:21 ` [PATCH 8/9] libfrog: create xfd_open function Darrick J. Wong
2019-09-01 20:55   ` Allison Collins [this message]
2019-09-03 23:01   ` Dave Chinner
2019-09-03 23:37     ` Darrick J. Wong
2019-08-30  4:21 ` [PATCH 9/9] libfrog: refactor open-coded INUMBERS calls Darrick J. Wong
2019-09-01 20:55   ` Allison Collins

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=98cd2e1b-17d9-617a-87f4-d5c46bf231ab@oracle.com \
    --to=allison.henderson@oracle.com \
    --cc=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@sandeen.net \
    /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;
as well as URLs for NNTP newsgroup(s).