]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: modify argument errors of mremap command
authorZorro Lang <zlang@redhat.com>
Tue, 10 May 2016 07:16:05 +0000 (17:16 +1000)
committerDave Chinner <david@fromorbit.com>
Tue, 10 May 2016 07:16:05 +0000 (17:16 +1000)
There are two argument parsing errors in mremap command:

1. "mremap 1024 8192" won't return error and will run "mremap 1024"
silently.

2. The "-f" option can't be used, due to it needing a new address
argument as the fifth argument of mremap() syscall.

Signed-off-by: Zorro Lang <zlang@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
io/mmap.c
man/man8/xfs_io.8

index 5970069cb86bb9ca4b2e216013ef1b3d85b76387..568102ead4ba90dbfd18be704ca51d18f02dffa8 100644 (file)
--- a/io/mmap.c
+++ b/io/mmap.c
@@ -589,7 +589,7 @@ mremap_help(void)
 "\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"
+" -f <new_address> -- use MREMAP_FIXED flag to mremap on new_address\n"
 " -m -- use the MREMAP_MAYMOVE flag\n"
 "\n"));
 }
@@ -600,15 +600,19 @@ mremap_f(
        char            **argv)
 {
        ssize_t         new_length;
-       void            *new_addr;
+       void            *new_addr = NULL;
        int             flags = 0;
        int             c;
        size_t          blocksize, sectsize;
 
-       while ((c = getopt(argc, argv, "fm")) != EOF) {
+       init_cvtnum(&blocksize, &sectsize);
+
+       while ((c = getopt(argc, argv, "f:m")) != EOF) {
                switch (c) {
                case 'f':
                        flags = MREMAP_FIXED|MREMAP_MAYMOVE;
+                       new_addr = (void *)cvtnum(blocksize, sectsize,
+                                                 optarg);
                        break;
                case 'm':
                        flags = MREMAP_MAYMOVE;
@@ -618,7 +622,9 @@ mremap_f(
                }
        }
 
-       init_cvtnum(&blocksize, &sectsize);
+       if (optind != argc - 1)
+               return command_usage(&mremap_cmd);
+
        new_length = cvtnum(blocksize, sectsize, argv[optind]);
        if (new_length < 0) {
                printf(_("non-numeric offset argument -- %s\n"),
@@ -626,7 +632,12 @@ mremap_f(
                return 0;
        }
 
-       new_addr = mremap(mapping->addr, mapping->length, new_length, flags);
+       if (!new_addr)
+               new_addr = mremap(mapping->addr, mapping->length,
+                                 new_length, flags);
+       else
+               new_addr = mremap(mapping->addr, mapping->length,
+                                 new_length, flags, new_addr);
        if (new_addr == MAP_FAILED)
                perror("mremap");
        else {
@@ -697,9 +708,9 @@ mmap_init(void)
        mremap_cmd.altname = "mrm";
        mremap_cmd.cfunc = mremap_f;
        mremap_cmd.argmin = 1;
-       mremap_cmd.argmax = 2;
+       mremap_cmd.argmax = 3;
        mremap_cmd.flags = CMD_NOFILE_OK | CMD_FOREIGN_OK;
-       mremap_cmd.args = _("[-m|-f] newsize");
+       mremap_cmd.args = _("[-m|-f <new_address>] newsize");
        mremap_cmd.oneline =
                _("alters the size of the current memory mapping");
        mremap_cmd.help = mremap_help;
index 33fbe6a53137f930fbefa821d279d2e9484a29aa..984b55121abf6d97c027e59b80c924ec9482ab57 100644 (file)
@@ -581,7 +581,7 @@ See the
 .B mmap
 command.
 .TP
-.BI "mremap [ \-f ] [ \-m ] " new_length
+.BI "mremap [ \-f <new_address> ] [ \-m ] " new_length
 Changes the current mapping size to
 .IR new_length .
 Whether the mapping may be moved is controlled by the flags passed;
@@ -589,6 +589,9 @@ MREMAP_FIXED
 .RB ( \-f ),
 or MREMAP_MAYMOVE
 .RB ( \-m ).
+.IR new_length
+specifies a page-aligned address to which the mapping must be moved. It
+can be setted to 139946004389888, 4096k or 1g etc.
 .TP
 .B mrm
 See the