linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHSET 0/2] xfs_io: small fixes to funshare command
@ 2021-07-28 21:15 Darrick J. Wong
  2021-07-28 21:16 ` [PATCH 1/2] xfs_io: fix broken funshare_cmd usage Darrick J. Wong
  2021-07-28 21:16 ` [PATCH 2/2] xfs_io: clean up the funshare command a bit Darrick J. Wong
  0 siblings, 2 replies; 4+ messages in thread
From: Darrick J. Wong @ 2021-07-28 21:15 UTC (permalink / raw)
  To: sandeen, djwong; +Cc: Christoph Hellwig, Carlos Maiolino, linux-xfs

Hi all,

A couple of small fixes to the funshare command.

If you're going to start using this mess, you probably ought to just
pull from my git trees, which are linked below.

This is an extraordinary way to destroy everything.  Enjoy!
Comments and questions are, as always, welcome.

--D

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=funshare-fixes
---
 io/prealloc.c |   33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] xfs_io: fix broken funshare_cmd usage
  2021-07-28 21:15 [PATCHSET 0/2] xfs_io: small fixes to funshare command Darrick J. Wong
@ 2021-07-28 21:16 ` Darrick J. Wong
  2021-07-28 21:16 ` [PATCH 2/2] xfs_io: clean up the funshare command a bit Darrick J. Wong
  1 sibling, 0 replies; 4+ messages in thread
From: Darrick J. Wong @ 2021-07-28 21:16 UTC (permalink / raw)
  To: sandeen, djwong; +Cc: Christoph Hellwig, Carlos Maiolino, linux-xfs

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

Create a funshare_cmd and use that to store information about the
xfs_io funshare command instead of overwriting the contents of
fzero_cmd.  This fixes confusing output like:

$ xfs_io -c 'fzero 2 3 --help' /
fzero: invalid option -- '-'
funshare off len -- unshares shared blocks within the range

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
---
 io/prealloc.c |   17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)


diff --git a/io/prealloc.c b/io/prealloc.c
index 382e8119..2ae8afe9 100644
--- a/io/prealloc.c
+++ b/io/prealloc.c
@@ -43,6 +43,7 @@ static cmdinfo_t fpunch_cmd;
 static cmdinfo_t fcollapse_cmd;
 static cmdinfo_t finsert_cmd;
 static cmdinfo_t fzero_cmd;
+static cmdinfo_t funshare_cmd;
 #endif
 
 static int
@@ -467,14 +468,14 @@ prealloc_init(void)
 	_("zeroes space and eliminates holes by preallocating");
 	add_command(&fzero_cmd);
 
-	fzero_cmd.name = "funshare";
-	fzero_cmd.cfunc = funshare_f;
-	fzero_cmd.argmin = 2;
-	fzero_cmd.argmax = 2;
-	fzero_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
-	fzero_cmd.args = _("off len");
-	fzero_cmd.oneline =
+	funshare_cmd.name = "funshare";
+	funshare_cmd.cfunc = funshare_f;
+	funshare_cmd.argmin = 2;
+	funshare_cmd.argmax = 2;
+	funshare_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
+	funshare_cmd.args = _("off len");
+	funshare_cmd.oneline =
 	_("unshares shared blocks within the range");
-	add_command(&fzero_cmd);
+	add_command(&funshare_cmd);
 #endif	/* HAVE_FALLOCATE */
 }


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] xfs_io: clean up the funshare command a bit
  2021-07-28 21:15 [PATCHSET 0/2] xfs_io: small fixes to funshare command Darrick J. Wong
  2021-07-28 21:16 ` [PATCH 1/2] xfs_io: fix broken funshare_cmd usage Darrick J. Wong
@ 2021-07-28 21:16 ` Darrick J. Wong
  1 sibling, 0 replies; 4+ messages in thread
From: Darrick J. Wong @ 2021-07-28 21:16 UTC (permalink / raw)
  To: sandeen, djwong; +Cc: Carlos Maiolino, linux-xfs

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

Add proper argument parsing to the funshare command so that when you
pass it nonexistent --help it will print the help instead of complaining
that it can't convert that to a number.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
---
 io/prealloc.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)


diff --git a/io/prealloc.c b/io/prealloc.c
index 2ae8afe9..a8831c1b 100644
--- a/io/prealloc.c
+++ b/io/prealloc.c
@@ -346,16 +346,24 @@ funshare_f(
 	char		**argv)
 {
 	xfs_flock64_t	segment;
+	int		c;
 	int		mode = FALLOC_FL_UNSHARE_RANGE;
-	int		index = 1;
 
-	if (!offset_length(argv[index], argv[index + 1], &segment)) {
+	while ((c = getopt(argc, argv, "")) != EOF) {
+		switch (c) {
+		default:
+			command_usage(&funshare_cmd);
+		}
+	}
+	if (optind != argc - 2)
+		return command_usage(&funshare_cmd);
+
+	if (!offset_length(argv[optind], argv[optind + 1], &segment)) {
 		exitcode = 1;
 		return 0;
 	}
 
-	if (fallocate(file->fd, mode,
-			segment.l_start, segment.l_len)) {
+	if (fallocate(file->fd, mode, segment.l_start, segment.l_len)) {
 		perror("fallocate");
 		exitcode = 1;
 		return 0;


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCHSET 0/2] xfs_io: small fixes to funshare command
@ 2021-07-03  2:57 Darrick J. Wong
  0 siblings, 0 replies; 4+ messages in thread
From: Darrick J. Wong @ 2021-07-03  2:57 UTC (permalink / raw)
  To: sandeen, djwong; +Cc: linux-xfs

Hi all,

A couple of small fixes to the funshare command.

If you're going to start using this mess, you probably ought to just
pull from my git trees, which are linked below.

This is an extraordinary way to destroy everything.  Enjoy!
Comments and questions are, as always, welcome.

--D

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=funshare-fixes
---
 io/prealloc.c |   33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-28 21:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-28 21:15 [PATCHSET 0/2] xfs_io: small fixes to funshare command Darrick J. Wong
2021-07-28 21:16 ` [PATCH 1/2] xfs_io: fix broken funshare_cmd usage Darrick J. Wong
2021-07-28 21:16 ` [PATCH 2/2] xfs_io: clean up the funshare command a bit Darrick J. Wong
  -- strict thread matches above, loose matches on Subject: below --
2021-07-03  2:57 [PATCHSET 0/2] xfs_io: small fixes to funshare command Darrick J. Wong

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).