All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs_io: add mremap command
@ 2014-09-11  3:25 Eric Sandeen
  2014-09-11  3:29 ` [PATCH V2] " Eric Sandeen
  2014-09-12 16:54 ` [PATCH V3] " Eric Sandeen
  0 siblings, 2 replies; 6+ messages in thread
From: Eric Sandeen @ 2014-09-11  3:25 UTC (permalink / raw)
  To: xfs-oss

This adds a simple mremap command to xfs_io.

It does not take a start address; it uses the existing
start address, so the sized passed will be the new total
size of the mapping.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/io/mmap.c b/io/mmap.c
index ea7498f..565a541 100644
--- a/io/mmap.c
+++ b/io/mmap.c
@@ -29,6 +29,7 @@ static cmdinfo_t mread_cmd;
  static cmdinfo_t msync_cmd;
  static cmdinfo_t munmap_cmd;
  static cmdinfo_t mwrite_cmd;
+static cmdinfo_t mremap_cmd;
  
  mmap_region_t	*maptable;
  int		mapcount;
@@ -574,6 +575,66 @@ mwrite_f(
  	return 0;
  }
  
+static void
+mremap_help(void)
+{
+	printf(_(
+"\n"
+" resizes the current memory mapping\n"
+"\n"
+" Examples:\n"
+" 'mremap 8192' - resizes the current mapping to 8192 bytes.\n"
+"\n"
+" Resizes the mappping, growing or shrinking from the current size.\n"
+" The default stored value is 'X', repeated to fill the range specified.\n"
+" -f -- use the MREMAP_FIXED flag\n"
+" -m -- use the MREMAP_MAYMOVE flag\n"
+"\n"));
+}
+
+int
+mremap_f(
+	int		argc,
+	char		**argv)
+{
+	ssize_t		new_length;
+	void		*new_addr;
+	int		flags = 0;
+	int		c;
+	size_t		blocksize, sectsize;
+
+	while ((c = getopt(argc, argv, "fm")) != EOF) {
+		switch (c) {
+		case 'f':
+			flags = MREMAP_FIXED|MREMAP_MAYMOVE;
+			break;
+		case 'm':
+			flags = MREMAP_MAYMOVE;
+			break;
+		default:
+			return command_usage(&mremap_cmd);
+		}
+	}
+
+	init_cvtnum(&blocksize, &sectsize);
+	new_length = cvtnum(blocksize, sectsize, argv[optind]);
+	if (new_length < 0) {
+		printf(_("non-numeric offset argument -- %s\n"),
+			argv[optind]);
+		return 0;
+	}
+
+	new_addr = mremap(mapping->addr, mapping->length, new_length, flags);
+	if (new_addr == MAP_FAILED)
+		perror("mremap");
+	else {
+		mapping->addr = new_addr;
+		mapping->length = new_length;
+	}
+
+	return 0;
+}
+
  void
  mmap_init(void)
  {
@@ -628,9 +689,21 @@ mmap_init(void)
  		_("writes data into a region in the current memory mapping");
  	mwrite_cmd.help = mwrite_help;
  
+	mremap_cmd.name = "mremap";
+	mremap_cmd.altname = "mrm";
+	mremap_cmd.cfunc = mremap_f;
+	mremap_cmd.argmin = 1;
+	mremap_cmd.argmax = 2;
+	mremap_cmd.flags = CMD_NOFILE_OK | CMD_FOREIGN_OK;
+	mremap_cmd.args = _("[-f|-m] newsize");
+	mremap_cmd.oneline =
+		_("alters the size of the current memory mapping");
+	mremap_cmd.help = mremap_help;
+
  	add_command(&mmap_cmd);
  	add_command(&mread_cmd);
  	add_command(&msync_cmd);
  	add_command(&munmap_cmd);
  	add_command(&mwrite_cmd);
+	add_command(&mremap_cmd);
  }
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index e1a3e1a..e40fbf9 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -501,6 +501,20 @@ See the
  .B mmap
  command.
  .TP
+.BI "mremap [ \-f ] [ \-m ] " new_length
+Changes the current mapping size to
+.IR new_length .
+Whether the mapping may be moved is controlled by the flags passed;
+MREMAP_FIXED
+.RB ( \-f ),
+or MREMAP_MAYMOVE
+.RB ( \-m ).
+.TP
+.B mrm
+See the
+.B mremap
+command.
+.TP
  .B munmap
  Unmaps the current memory mapping.
  .TP

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH V2] xfs_io: add mremap command
  2014-09-11  3:25 [PATCH] xfs_io: add mremap command Eric Sandeen
@ 2014-09-11  3:29 ` Eric Sandeen
  2014-09-12 16:22   ` Eric Sandeen
  2014-09-12 16:54 ` [PATCH V3] " Eric Sandeen
  1 sibling, 1 reply; 6+ messages in thread
From: Eric Sandeen @ 2014-09-11  3:29 UTC (permalink / raw)
  To: Eric Sandeen, xfs-oss

This adds a simple mremap command to xfs_io.

It does not take a start address; it uses the existing
start address, so the sized passed will be the new total
size of the mapping.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

V2: fix stray line in help.
Why was it only visible after I sent V1... :/

diff --git a/io/mmap.c b/io/mmap.c
index ea7498f..f1809e0 100644
--- a/io/mmap.c
+++ b/io/mmap.c
@@ -29,6 +29,7 @@ static cmdinfo_t mread_cmd;
  static cmdinfo_t msync_cmd;
  static cmdinfo_t munmap_cmd;
  static cmdinfo_t mwrite_cmd;
+static cmdinfo_t mremap_cmd;
  
  mmap_region_t	*maptable;
  int		mapcount;
@@ -574,6 +575,65 @@ mwrite_f(
  	return 0;
  }
  
+static void
+mremap_help(void)
+{
+	printf(_(
+"\n"
+" resizes the current memory mapping\n"
+"\n"
+" Examples:\n"
+" 'mremap 8192' - resizes the current mapping to 8192 bytes.\n"
+"\n"
+" Resizes the mappping, growing or shrinking from the current size.\n"
+" -f -- use the MREMAP_FIXED flag\n"
+" -m -- use the MREMAP_MAYMOVE flag\n"
+"\n"));
+}
+
+int
+mremap_f(
+	int		argc,
+	char		**argv)
+{
+	ssize_t		new_length;
+	void		*new_addr;
+	int		flags = 0;
+	int		c;
+	size_t		blocksize, sectsize;
+
+	while ((c = getopt(argc, argv, "fm")) != EOF) {
+		switch (c) {
+		case 'f':
+			flags = MREMAP_FIXED|MREMAP_MAYMOVE;
+			break;
+		case 'm':
+			flags = MREMAP_MAYMOVE;
+			break;
+		default:
+			return command_usage(&mremap_cmd);
+		}
+	}
+
+	init_cvtnum(&blocksize, &sectsize);
+	new_length = cvtnum(blocksize, sectsize, argv[optind]);
+	if (new_length < 0) {
+		printf(_("non-numeric offset argument -- %s\n"),
+			argv[optind]);
+		return 0;
+	}
+
+	new_addr = mremap(mapping->addr, mapping->length, new_length, flags);
+	if (new_addr == MAP_FAILED)
+		perror("mremap");
+	else {
+		mapping->addr = new_addr;
+		mapping->length = new_length;
+	}
+
+	return 0;
+}
+
  void
  mmap_init(void)
  {
@@ -628,9 +688,21 @@ mmap_init(void)
  		_("writes data into a region in the current memory mapping");
  	mwrite_cmd.help = mwrite_help;
  
+	mremap_cmd.name = "mremap";
+	mremap_cmd.altname = "mrm";
+	mremap_cmd.cfunc = mremap_f;
+	mremap_cmd.argmin = 1;
+	mremap_cmd.argmax = 2;
+	mremap_cmd.flags = CMD_NOFILE_OK | CMD_FOREIGN_OK;
+	mremap_cmd.args = _("[-m|-f] newsize");
+	mremap_cmd.oneline =
+		_("alters the size of the current memory mapping");
+	mremap_cmd.help = mremap_help;
+
  	add_command(&mmap_cmd);
  	add_command(&mread_cmd);
  	add_command(&msync_cmd);
  	add_command(&munmap_cmd);
  	add_command(&mwrite_cmd);
+	add_command(&mremap_cmd);
  }
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index e1a3e1a..e40fbf9 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -501,6 +501,20 @@ See the
  .B mmap
  command.
  .TP
+.BI "mremap [ \-f ] [ \-m ] " new_length
+Changes the current mapping size to
+.IR new_length .
+Whether the mapping may be moved is controlled by the flags passed;
+MREMAP_FIXED
+.RB ( \-f ),
+or MREMAP_MAYMOVE
+.RB ( \-m ).
+.TP
+.B mrm
+See the
+.B mremap
+command.
+.TP
  .B munmap
  Unmaps the current memory mapping.
  .TP


_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH V2] xfs_io: add mremap command
  2014-09-11  3:29 ` [PATCH V2] " Eric Sandeen
@ 2014-09-12 16:22   ` Eric Sandeen
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Sandeen @ 2014-09-12 16:22 UTC (permalink / raw)
  To: Eric Sandeen, xfs-oss

On 9/10/14 10:29 PM, Eric Sandeen wrote:
> This adds a simple mremap command to xfs_io.
>
> It does not take a start address; it uses the existing
> start address, so the sized passed will be the new total
> size of the mapping.
>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---


> +int
> +mremap_f(
> +    int        argc,
> +    char        **argv)
> +{
> +    ssize_t        new_length;
> +    void        *new_addr;
> +    int        flags = 0;
> +    int        c;
> +    size_t        blocksize, sectsize;
> +

Crap, and I just realized my mailer has started swapping tabs for spaces; my last several patches are probably corrupted this way.  Grumble.

-Eric

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH V3] xfs_io: add mremap command
  2014-09-11  3:25 [PATCH] xfs_io: add mremap command Eric Sandeen
  2014-09-11  3:29 ` [PATCH V2] " Eric Sandeen
@ 2014-09-12 16:54 ` Eric Sandeen
  2014-09-13 19:45   ` Christoph Hellwig
  1 sibling, 1 reply; 6+ messages in thread
From: Eric Sandeen @ 2014-09-12 16:54 UTC (permalink / raw)
  To: Eric Sandeen, xfs-oss

This adds a simple mremap command to xfs_io.

It does not take a start address; it uses the existing
start address, so the sized passed will be the new total
size of the mapping.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

V2: fix stray line in help.
	- Why was it only visible after I sent V1... :/ 
V3: Unmangle whitespace, yay me!

diff --git a/io/mmap.c b/io/mmap.c
index ea7498f..565a541 100644
--- a/io/mmap.c
+++ b/io/mmap.c
@@ -29,6 +29,7 @@ static cmdinfo_t mread_cmd;
 static cmdinfo_t msync_cmd;
 static cmdinfo_t munmap_cmd;
 static cmdinfo_t mwrite_cmd;
+static cmdinfo_t mremap_cmd;
 
 mmap_region_t	*maptable;
 int		mapcount;
@@ -574,6 +575,66 @@ mwrite_f(
 	return 0;
 }
 
+static void
+mremap_help(void)
+{
+	printf(_(
+"\n"
+" resizes the current memory mapping\n"
+"\n"
+" Examples:\n"
+" 'mremap 8192' - resizes the current mapping to 8192 bytes.\n"
+"\n"
+" Resizes the mappping, growing or shrinking from the current size.\n"
+" The default stored value is 'X', repeated to fill the range specified.\n"
+" -f -- use the MREMAP_FIXED flag\n"
+" -m -- use the MREMAP_MAYMOVE flag\n"
+"\n"));
+}
+
+int
+mremap_f(
+	int		argc,
+	char		**argv)
+{
+	ssize_t		new_length;
+	void		*new_addr;
+	int		flags = 0;
+	int		c;
+	size_t		blocksize, sectsize;
+
+	while ((c = getopt(argc, argv, "fm")) != EOF) {
+		switch (c) {
+		case 'f':
+			flags = MREMAP_FIXED|MREMAP_MAYMOVE;
+			break;
+		case 'm':
+			flags = MREMAP_MAYMOVE;
+			break;
+		default:
+			return command_usage(&mremap_cmd);
+		}
+	}
+
+	init_cvtnum(&blocksize, &sectsize);
+	new_length = cvtnum(blocksize, sectsize, argv[optind]);
+	if (new_length < 0) {
+		printf(_("non-numeric offset argument -- %s\n"),
+			argv[optind]);
+		return 0;
+	}
+
+	new_addr = mremap(mapping->addr, mapping->length, new_length, flags);
+	if (new_addr == MAP_FAILED)
+		perror("mremap");
+	else {
+		mapping->addr = new_addr;
+		mapping->length = new_length;
+	}
+
+	return 0;
+}
+
 void
 mmap_init(void)
 {
@@ -628,9 +689,21 @@ mmap_init(void)
 		_("writes data into a region in the current memory mapping");
 	mwrite_cmd.help = mwrite_help;
 
+	mremap_cmd.name = "mremap";
+	mremap_cmd.altname = "mrm";
+	mremap_cmd.cfunc = mremap_f;
+	mremap_cmd.argmin = 1;
+	mremap_cmd.argmax = 2;
+	mremap_cmd.flags = CMD_NOFILE_OK | CMD_FOREIGN_OK;
+	mremap_cmd.args = _("[-m|-f] newsize");
+	mremap_cmd.oneline =
+		_("alters the size of the current memory mapping");
+	mremap_cmd.help = mremap_help;
+
 	add_command(&mmap_cmd);
 	add_command(&mread_cmd);
 	add_command(&msync_cmd);
 	add_command(&munmap_cmd);
 	add_command(&mwrite_cmd);
+	add_command(&mremap_cmd);
 }
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index e1a3e1a..e40fbf9 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -501,6 +501,20 @@ See the
 .B mmap
 command.
 .TP
+.BI "mremap [ \-f ] [ \-m ] " new_length
+Changes the current mapping size to
+.IR new_length .
+Whether the mapping may be moved is controlled by the flags passed;
+MREMAP_FIXED
+.RB ( \-f ),
+or MREMAP_MAYMOVE
+.RB ( \-m ).
+.TP
+.B mrm
+See the
+.B mremap
+command.
+.TP
 .B munmap
 Unmaps the current memory mapping.
 .TP

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH V3] xfs_io: add mremap command
  2014-09-12 16:54 ` [PATCH V3] " Eric Sandeen
@ 2014-09-13 19:45   ` Christoph Hellwig
  2014-09-13 20:12     ` Eric Sandeen
  0 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2014-09-13 19:45 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: Eric Sandeen, xfs-oss

On Fri, Sep 12, 2014 at 11:54:43AM -0500, Eric Sandeen wrote:
> This adds a simple mremap command to xfs_io.
> 
> It does not take a start address; it uses the existing
> start address, so the sized passed will be the new total
> size of the mapping.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Looks good to me, but I'd feel much more comfortable about merging it
if we had an xfstests test case that actually exercises it.

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH V3] xfs_io: add mremap command
  2014-09-13 19:45   ` Christoph Hellwig
@ 2014-09-13 20:12     ` Eric Sandeen
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Sandeen @ 2014-09-13 20:12 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Eric Sandeen, xfs-oss

On 9/13/14 2:45 PM, Christoph Hellwig wrote:
> On Fri, Sep 12, 2014 at 11:54:43AM -0500, Eric Sandeen wrote:
>> This adds a simple mremap command to xfs_io.
>>
>> It does not take a start address; it uses the existing
>> start address, so the sized passed will be the new total
>> size of the mapping.
>>
>> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> 
> Looks good to me, but I'd feel much more comfortable about merging it
> if we had an xfstests test case that actually exercises it.
> 

I did it for a crazy mremap failure we saw, I'll probably end up
writing a testcase for that which uses it.

I could easily enough write a test to exercise this directly too,
I'll look into it.

Thanks,
-Eric

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

end of thread, other threads:[~2014-09-13 20:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-11  3:25 [PATCH] xfs_io: add mremap command Eric Sandeen
2014-09-11  3:29 ` [PATCH V2] " Eric Sandeen
2014-09-12 16:22   ` Eric Sandeen
2014-09-12 16:54 ` [PATCH V3] " Eric Sandeen
2014-09-13 19:45   ` Christoph Hellwig
2014-09-13 20:12     ` Eric Sandeen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.