public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: Carlos Maiolino <cmaiolino@redhat.com>
Cc: xfs@oss.sgi.com
Subject: Re: [PATCH] xfs_io: implement 'inode' command V6
Date: Fri, 19 Feb 2016 12:55:08 -0500	[thread overview]
Message-ID: <20160219175508.GD27263@bfoster.bfoster> (raw)
In-Reply-To: <1455814159-14191-1-git-send-email-cmaiolino@redhat.com>

On Thu, Feb 18, 2016 at 05:49:19PM +0100, Carlos Maiolino wrote:
> Implements a new xfs_io command, named 'inode', which is supposed to be
> used to query information about inode's existence and its physical size
> in the filesystem.
> 
> Supported options:
> 
> Default:     -- Return true(1) or false(0) if any inode greater than
>                 32bits has been found in the filesystem
> [num]        -- Return inode number or 0 if the inode [num] is in use
> -n [num]     -- Return the next valid inode after [num]
> -v           -- verbose mode
>                 Display the inode number and its physical size according to the
> 		argument used
> 
> No manpage sent because there were changes in the supported options and its
> descriptions.
> I'll send the manpage after the options and descriptions are reviewed.
> 
> - Changelog
> 
> V3:
> 	- Merge all 3 patches from the V2 together in a single patch
> 	- Rework of '-n [num]' and 'num' only arguments algorithm
> 	- Argument -n now relies on bulkreq.count to check for next inodes, not
> 	  on bstat.bs_ino anymore.
> 	- for loop in ret_lsize or ret_largest case, now relies on count being 0
> 	  to break the loop
> 
> V4:
> 	- Refactor inode_f function to reduce its size and easier logic
> 	- Implement error handlers for invalid command combination (hopefully
> 	  all invalid combinations).
> 	- use a single xfs_inogrp array for keep track of inodes
> 	- Fix missing newline in inode_help()
> 	- Rewrite help message in inode_help()
> 	- Fix indentation
> 
> V5:
> 	- Reduce the amount of options
> 	- remove igrp_rec variable, and use igroup[lastgrp] directly to get
> 	  information from the last inode groups returned by ioctl
> 
> V6:
> 	- Re-use userino variable to reduce code duplication for command output
> 	- Use verbose option as an extension to another commands
> 	- report usage message when -n option is passed stand-alone
> 	- Refactor command outputs
> 	- Add a few comments to the code
> 
> Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
> ---
>  io/open.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 150 insertions(+)
> 
> diff --git a/io/open.c b/io/open.c
> index 037843d..5e607f1 100644
...
> +
> +static int
> +inode_f(
> +	  int			argc,
> +	  char			**argv)
> +{
...
> +
> +	/*
> +	 * Inode number can be passed with or without extra arguments, so we
> +	 * should handle inode numbers passed by user out of getopt()
> +	 */
> +	if (optind < argc) {
> +
> +		if (ret_next) {
> +			cmd = XFS_IOC_FSBULKSTAT;
> +		} else {
> +			if (argc > 2)
> +				return command_usage(&inode_cmd);

FYI, this means one can't do the following:

  xfs_io -c "inode -v 123" <mnt>

Otherwise it looks good to me:

Reviewed-by: Brian Foster <bfoster@redhat.com>

> +			else
> +				cmd = XFS_IOC_FSBULKSTAT_SINGLE;
> +		}
> +
> +		userino = strtoull(argv[optind], &p, 10);
> +		if ((*p != '\0')) {
> +			printf(_("[num] must be a numeric value\n"));
> +			exitcode = 1;
> +			return 0;
> +		}
> +
> +		bulkreq.lastip = &userino;
> +		bulkreq.icount = 1;
> +		bulkreq.ubuffer = &bstat;
> +		bulkreq.ocount = &count;
> +
> +		if (xfsctl(file->name, file->fd, cmd, &bulkreq)) {
> +			if (errno == EINVAL) {
> +				if (!ret_next)
> +					printf("0\n");
> +			} else {
> +				perror("xfsctl");
> +			}
> +			exitcode = 1;
> +			return 0;
> +		}
> +
> +		if (ret_next)
> +			userino = bstat.bs_ino;
> +
> +		if (verbose)
> +			printf("%llu:%d\n",
> +			       userino,
> +			       userino > XFS_MAXINUMBER_32 ? 64 : 32);
> +		else
> +			/* Inode in use */
> +			printf("%llu\n", userino);
> +		return 0;
> +
> +	/* -n option must not be used stand alone */
> +	} else if (ret_next) {
> +		return command_usage(&inode_cmd);
> +	}
> +
> +	bulkreq.lastip = &last;
> +	bulkreq.icount = 1024; /* User-defined maybe!? */
> +	bulkreq.ubuffer = &igroup;
> +	bulkreq.ocount = &count;
> +
> +	for (;;) {
> +		if (xfsctl(file->name, file->fd, XFS_IOC_FSINUMBERS,
> +				&bulkreq)) {
> +			perror("XFS_IOC_FSINUMBERS");
> +			exitcode = 1;
> +			return 0;
> +		}
> +
> +		if (count == 0)
> +			break;
> +
> +		lastgrp = count;
> +	}
> +
> +	lastgrp--;
> +	lastino = igroup[lastgrp].xi_startino +
> +		  xfs_highbit64(igroup[lastgrp].xi_allocmask);
> +
> +	if (verbose)
> +		printf("%llu:%d\n", lastino,
> +			lastino > XFS_MAXINUMBER_32 ? 64 : 32);
> +	else
> +		printf("%d\n", lastino > XFS_MAXINUMBER_32 ? 1 : 0);
> +
> +	return 0;
> +}
> +
>  void
>  open_init(void)
>  {
> @@ -815,6 +954,16 @@ open_init(void)
>  		_("get/set preferred extent size (in bytes) for the open file");
>  	extsize_cmd.help = extsize_help;
>  
> +	inode_cmd.name = "inode";
> +	inode_cmd.cfunc = inode_f;
> +	inode_cmd.args = _("[-n | -v] [num]");
> +	inode_cmd.argmin = 0;
> +	inode_cmd.argmax = 2;
> +	inode_cmd.flags = CMD_NOMAP_OK;
> +	inode_cmd.oneline =
> +		_("Query inode number usage in the filesystem");
> +	inode_cmd.help = inode_help;
> +
>  	add_command(&open_cmd);
>  	add_command(&stat_cmd);
>  	add_command(&close_cmd);
> @@ -822,4 +971,5 @@ open_init(void)
>  	add_command(&chproj_cmd);
>  	add_command(&lsproj_cmd);
>  	add_command(&extsize_cmd);
> +	add_command(&inode_cmd);
>  }
> -- 
> 2.4.3
> 
> _______________________________________________
> 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

  parent reply	other threads:[~2016-02-19 17:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-18 16:49 [PATCH] xfs_io: implement 'inode' command V6 Carlos Maiolino
2016-02-18 17:02 ` Bill O'Donnell
2016-02-19 17:55 ` Brian Foster [this message]
2016-02-22 10:25   ` Carlos Maiolino

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=20160219175508.GD27263@bfoster.bfoster \
    --to=bfoster@redhat.com \
    --cc=cmaiolino@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