diff options
author | Stewart Smith <stewart@linux.vnet.ibm.com> | 2017-11-30 18:43:56 +1100 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2017-11-30 18:52:23 +1100 |
commit | 6bd1a1fe3ec12e177278303e6db0c79b1a14b631 (patch) | |
tree | 18cd0e0f28e71e089962eda1741a12cb4d93d8ce /fcp | |
parent | 1ccd69266b2b71113d17de0d799e0de64aac2fb5 (diff) | |
download | ffs-6bd1a1fe3ec12e177278303e6db0c79b1a14b631.tar.gz ffs-6bd1a1fe3ec12e177278303e6db0c79b1a14b631.zip |
fix high memory usage during any operation with '--buffer'
The --buffer command line option was passed to setvbuf(3).
Computers are fast enough and libc is good enough that
we realistically do not need this.
Hostboot's buildpnor.pl would pass --buffer 0x40000000
which resulted in a malloc(2GB), which would fail on systems
with less than 2GB of memory because sometimes
libc and the kernel are sane.
So, we keep the command line option for backwards compatibility
but completely ignore it.
In the few places where it was used to allocate a buffer to do
work in (and this was via a rather round-about way), we instead
just allocate something the size of the PNOR image.
Fixes: https://github.com/open-power/ffs/issues/7
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'fcp')
-rw-r--r-- | fcp/src/cmd_copy.c | 10 | ||||
-rw-r--r-- | fcp/src/cmd_erase.c | 8 | ||||
-rw-r--r-- | fcp/src/cmd_read.c | 8 | ||||
-rw-r--r-- | fcp/src/cmd_trunc.c | 8 | ||||
-rw-r--r-- | fcp/src/cmd_user.c | 8 | ||||
-rw-r--r-- | fcp/src/cmd_write.c | 8 | ||||
-rw-r--r-- | fcp/src/main.c | 12 | ||||
-rw-r--r-- | fcp/src/main.h | 1 | ||||
-rw-r--r-- | fcp/src/misc.c | 30 |
9 files changed, 17 insertions, 76 deletions
diff --git a/fcp/src/cmd_copy.c b/fcp/src/cmd_copy.c index be6bbe9..cc333b6 100644 --- a/fcp/src/cmd_copy.c +++ b/fcp/src/cmd_copy.c @@ -425,16 +425,6 @@ static int __copy_compare(args_t * args, off_t offset, entry_list_t * done_list) if (__ffs_info(src_ffs, FFS_INFO_BLOCK_SIZE, &block_size) < 0) return -1; - if (args->buffer != NULL) { - uint32_t buffer; - if (parse_size(args->buffer, &buffer) < 0) - return -1; - if (__ffs_buffer(src_ffs, buffer) < 0) - return -1; - if (__ffs_buffer(dst_ffs, buffer) < 0) - return -1; - } - ffs_entry_t src_parent; ffs_entry_t dst_parent; diff --git a/fcp/src/cmd_erase.c b/fcp/src/cmd_erase.c index 17fc9b7..608ad95 100644 --- a/fcp/src/cmd_erase.c +++ b/fcp/src/cmd_erase.c @@ -91,14 +91,6 @@ static int __erase(args_t * args, off_t offset, entry_list_t * done_list) if (__ffs_info(ffs, FFS_INFO_BLOCK_SIZE, &block_size) < 0) return -1; - if (args->buffer != NULL) { - uint32_t buffer; - if (parse_size(args->buffer, &buffer) < 0) - return -1; - if (__ffs_buffer(ffs, buffer) < 0) - return -1; - } - ffs_entry_t parent; if (__ffs_entry_find(ffs, name, &parent) == false) { UNEXPECTED("partition entry '%s' not found\n", name); diff --git a/fcp/src/cmd_read.c b/fcp/src/cmd_read.c index 0745c21..2f183d7 100644 --- a/fcp/src/cmd_read.c +++ b/fcp/src/cmd_read.c @@ -83,14 +83,6 @@ static int __read(args_t * args, off_t offset, entry_list_t * done_list) if (__ffs_info(ffs, FFS_INFO_BLOCK_SIZE, &block_size) < 0) return -1; - if (args->buffer != NULL) { - uint32_t buffer; - if (parse_size(args->buffer, &buffer) < 0) - return -1; - if (__ffs_buffer(ffs, buffer) < 0) - return -1; - } - ffs_entry_t entry; if (__ffs_entry_find(ffs, name, &entry) == false) { UNEXPECTED("partition entry '%s' not found\n", name); diff --git a/fcp/src/cmd_trunc.c b/fcp/src/cmd_trunc.c index 7ee11ca..3f86c12 100644 --- a/fcp/src/cmd_trunc.c +++ b/fcp/src/cmd_trunc.c @@ -80,14 +80,6 @@ static int __trunc(args_t * args, off_t offset) if (__ffs_info(ffs, FFS_INFO_BLOCK_SIZE, &block_size) < 0) return -1; - if (args->buffer != NULL) { - uint32_t buffer; - if (parse_size(args->buffer, &buffer) < 0) - return -1; - if (__ffs_buffer(ffs, buffer) < 0) - return -1; - } - ffs_entry_t entry; if (__ffs_entry_find(ffs, name, &entry) == false) { UNEXPECTED("partition entry '%s' not found\n", name); diff --git a/fcp/src/cmd_user.c b/fcp/src/cmd_user.c index 8496f7a..bc754dc 100644 --- a/fcp/src/cmd_user.c +++ b/fcp/src/cmd_user.c @@ -82,14 +82,6 @@ static int __user(args_t * args, off_t offset) if (__ffs_info(ffs, FFS_INFO_BLOCK_SIZE, &block_size) < 0) return -1; - if (args->buffer != NULL) { - uint32_t buffer; - if (parse_size(args->buffer, &buffer) < 0) - return -1; - if (__ffs_buffer(ffs, buffer) < 0) - return -1; - } - ffs_entry_t entry; if (__ffs_entry_find(ffs, name, &entry) == false) { UNEXPECTED("partition entry '%s' not found\n", name); diff --git a/fcp/src/cmd_write.c b/fcp/src/cmd_write.c index b3ef89b..310ba71 100644 --- a/fcp/src/cmd_write.c +++ b/fcp/src/cmd_write.c @@ -85,14 +85,6 @@ static int __write(args_t * args, off_t offset, entry_list_t * done_list) if (__ffs_info(ffs, FFS_INFO_BLOCK_SIZE, &block_size) < 0) return -1; - if (args->buffer != NULL) { - uint32_t buffer; - if (parse_size(args->buffer, &buffer) < 0) - return -1; - if (__ffs_buffer(ffs, buffer) < 0) - return -1; - } - ffs_entry_t entry; if (__ffs_entry_find(ffs, name, &entry) == false) { UNEXPECTED("partition entry '%s' not found\n", name); diff --git a/fcp/src/main.c b/fcp/src/main.c index 335bcf2..00ca3b3 100644 --- a/fcp/src/main.c +++ b/fcp/src/main.c @@ -205,9 +205,7 @@ static void usage(bool verbose) fprintf(e, " -b, --buffer <value>\n"); if (verbose) fprintf(e, - "\n Specifies the buffer size used by --read, --write," - " --copy and --compare\n commands <value> is a " - "decimal (or hex) number, default is buffer size.\n\n"); + "\n Ignored.\n\n"); fprintf(e, "\n"); /* =============================== */ @@ -266,7 +264,7 @@ static int process_argument(args_t * args, int opt, const char *optarg) args->offset = strdup(optarg); break; case o_BUFFER: /* buffer */ - args->buffer = strdup(optarg); + /* We ignore it, it's useless but kept for backwards compat */ break; case f_FORCE: /* force */ args->force = (flag_t) opt; @@ -449,7 +447,6 @@ static int validate_args(args_t * args) return -1; } - UNSUP_OPT(buffer, probe); } else if (args->cmd == c_LIST) { void syntax(void) { fprintf(stderr, "Syntax: %s [<dst_type>:]<dst_target>" @@ -462,7 +459,6 @@ static int validate_args(args_t * args) return -1; } - UNSUP_OPT(buffer, list); } else if (args->cmd == c_READ) { void syntax(void) { fprintf(stderr, "Syntax: %s [<src_type>:]<src_source>" @@ -520,7 +516,6 @@ static int validate_args(args_t * args) REQ_FIELD(dst_name, trunc); - UNSUP_OPT(buffer, trunc); } else if (args->cmd == c_USER) { void syntax(void) { fprintf(stderr, "Syntax: %s [<dst_type>:]<dst_target>" @@ -531,7 +526,6 @@ static int validate_args(args_t * args) REQ_FIELD(dst_name, user); - UNSUP_OPT(buffer, user); } else if (args->cmd == c_COPY) { void syntax(void) { fprintf(stderr, "Syntax: %s [<src_type>:]<src_target>" @@ -614,8 +608,6 @@ static void args_dump(args_t * args) printf("cmd[%c]\n", args->cmd); if (args->offset != NULL) printf("offset[%s]\n", args->offset); - if (args->buffer != NULL) - printf("buffer[%s]\n", args->buffer); if (args->force != 0) printf("force[%c]\n", args->force); if (args->protected != 0) diff --git a/fcp/src/main.h b/fcp/src/main.h index 823abcf..adfbc4f 100644 --- a/fcp/src/main.h +++ b/fcp/src/main.h @@ -90,7 +90,6 @@ typedef struct { /* options */ const char *offset; - const char *buffer; /* flags */ flag_t force; diff --git a/fcp/src/misc.c b/fcp/src/misc.c index 004db7d..519ea1d 100644 --- a/fcp/src/misc.c +++ b/fcp/src/misc.c @@ -551,11 +551,11 @@ int fcp_read_entry(ffs_t * src, const char * name, FILE * out) if (__ffs_info(src, FFS_INFO_BLOCK_SIZE, &block_size) < 0) return -1; - uint32_t buffer_count; - if (__ffs_info(src, FFS_INFO_BUFFER_COUNT, &buffer_count) < 0) + uint32_t block_count; + if (__ffs_info(src, FFS_INFO_BLOCK_COUNT, &block_count) < 0) return -1; - size_t buffer_size = block_size * buffer_count; + size_t buffer_size = block_size * block_count; RAII(void*, buffer, malloc(buffer_size), free); if (buffer == NULL) { ERRNO(errno); @@ -621,11 +621,11 @@ int fcp_write_entry(ffs_t * dst, const char * name, FILE * in) if (__ffs_info(dst, FFS_INFO_BLOCK_SIZE, &block_size) < 0) return -1; - uint32_t buffer_count; - if (__ffs_info(dst, FFS_INFO_BUFFER_COUNT, &buffer_count) < 0) + uint32_t block_count; + if (__ffs_info(dst, FFS_INFO_BLOCK_COUNT, &block_count) < 0) return -1; - size_t buffer_size = block_size * buffer_count; + size_t buffer_size = block_size * block_count; RAII(void*, buffer, malloc(buffer_size), free); if (buffer == NULL) { ERRNO(errno); @@ -697,11 +697,11 @@ int fcp_erase_entry(ffs_t * dst, const char * name, char fill) if (__ffs_info(dst, FFS_INFO_BLOCK_SIZE, &block_size) < 0) return -1; - uint32_t buffer_count; - if (__ffs_info(dst, FFS_INFO_BUFFER_COUNT, &buffer_count) < 0) + uint32_t block_count; + if (__ffs_info(dst, FFS_INFO_BLOCK_COUNT, &block_count) < 0) return -1; - size_t buffer_size = block_size * buffer_count; + size_t buffer_size = block_size * block_count; RAII(void*, buffer, malloc(buffer_size), free); if (buffer == NULL) { ERRNO(errno); @@ -774,11 +774,11 @@ int fcp_copy_entry(ffs_t * src, const char * src_name, if (__ffs_info(src, FFS_INFO_BLOCK_SIZE, &block_size) < 0) return -1; - uint32_t buffer_count; - if (__ffs_info(dst, FFS_INFO_BUFFER_COUNT, &buffer_count) < 0) + uint32_t block_count; + if (__ffs_info(dst, FFS_INFO_BLOCK_COUNT, &block_count) < 0) return -1; - size_t buffer_size = block_size * buffer_count; + size_t buffer_size = block_size * block_count; RAII(void*, buffer, malloc(buffer_size), free); if (buffer == NULL) { ERRNO(errno); @@ -851,11 +851,11 @@ int fcp_compare_entry(ffs_t * src, const char * src_name, if (__ffs_info(src, FFS_INFO_BLOCK_SIZE, &block_size) < 0) return -1; - uint32_t buffer_count; - if (__ffs_info(dst, FFS_INFO_BUFFER_COUNT, &buffer_count) < 0) + uint32_t block_count; + if (__ffs_info(dst, FFS_INFO_BLOCK_COUNT, &block_count) < 0) return -1; - size_t buffer_size = block_size * buffer_count; + size_t buffer_size = block_size * block_count; RAII(void*, src_buffer, malloc(buffer_size), free); if (src_buffer == NULL) { |