1
1

Update the data types used in opaldf to minimize the chance of overflow when

determining the amount of available space. Thanks to Eugene for pointing out the
issue.

This commit was SVN r27436.
Этот коммит содержится в:
Samuel Gutierrez 2012-10-11 16:11:23 +00:00
родитель 21be553e21
Коммит 1f24f1d305
6 изменённых файлов: 37 добавлений и 31 удалений

Просмотреть файл

@ -49,5 +49,5 @@ file). It is likely that your MPI job will now either abort or experience
performance degradation. performance degradation.
Local host: %s Local host: %s
Space Requested: %ld B Space Requested: %lu B
Space Available: %ld B Space Available: %llu B

Просмотреть файл

@ -49,6 +49,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#endif /* HAVE_SYS_STAT_H */ #endif /* HAVE_SYS_STAT_H */
#include "opal_stdint.h"
#include "opal/constants.h" #include "opal/constants.h"
#include "opal/util/output.h" #include "opal/util/output.h"
#include "opal/util/path.h" #include "opal/util/path.h"
@ -90,8 +91,8 @@ module_finalize(void);
static int static int
enough_space(const char *filename, enough_space(const char *filename,
long space_req, size_t space_req,
long *space_avail, uint64_t *space_avail,
bool *result); bool *result);
/* /*
@ -141,12 +142,12 @@ shmem_ds_reset(opal_shmem_ds_t *ds_buf)
/* ////////////////////////////////////////////////////////////////////////// */ /* ////////////////////////////////////////////////////////////////////////// */
static int static int
enough_space(const char *filename, enough_space(const char *filename,
long space_req, size_t space_req,
long *space_avail, uint64_t *space_avail,
bool *result) bool *result)
{ {
long avail = 0; uint64_t avail = 0;
long fluff = (long)(.05 * space_req); size_t fluff = (size_t)(.05 * space_req);
bool enough = false; bool enough = false;
char *last_sep = NULL; char *last_sep = NULL;
/* the target file name is passed here, but we need to check the parent /* the target file name is passed here, but we need to check the parent
@ -177,8 +178,8 @@ enough_space(const char *filename,
OPAL_OUTPUT_VERBOSE( OPAL_OUTPUT_VERBOSE(
(70, opal_shmem_base_output, (70, opal_shmem_base_output,
"WARNING: not enough space on %s to meet request!" "WARNING: not enough space on %s to meet request!"
"available: %ld requested: %ld", target_dir, "available: %"PRIu64 "requested: %lu", target_dir,
avail, space_req + fluff) avail, (unsigned long)space_req + fluff)
); );
} }
@ -303,7 +304,7 @@ segment_create(opal_shmem_ds_t *ds_buf,
char *real_file_name = NULL; char *real_file_name = NULL;
pid_t my_pid = getpid(); pid_t my_pid = getpid();
bool space_available = false; bool space_available = false;
long amount_space_avail = 0; uint64_t amount_space_avail = 0;
/* the real size of the shared memory segment. this includes enough space /* the real size of the shared memory segment. this includes enough space
* to store our segment header. * to store our segment header.
@ -375,7 +376,7 @@ segment_create(opal_shmem_ds_t *ds_buf,
} }
/* let's make sure we have enough space for the backing file */ /* let's make sure we have enough space for the backing file */
if (OPAL_SUCCESS != (rc = enough_space(real_file_name, if (OPAL_SUCCESS != (rc = enough_space(real_file_name,
(long)real_size, real_size,
&amount_space_avail, &amount_space_avail,
&space_available))) { &space_available))) {
opal_output(0, "shmem: mmap: an error occurred while determining " opal_output(0, "shmem: mmap: an error occurred while determining "
@ -389,7 +390,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
hn[MAXHOSTNAMELEN - 1] = '\0'; hn[MAXHOSTNAMELEN - 1] = '\0';
rc = OPAL_ERR_OUT_OF_RESOURCE; rc = OPAL_ERR_OUT_OF_RESOURCE;
opal_show_help("help-opal-shmem-mmap.txt", "target full", 1, opal_show_help("help-opal-shmem-mmap.txt", "target full", 1,
real_file_name, hn, (long)real_size, amount_space_avail); real_file_name, hn, (unsigned long)real_size,
(unsigned long long)amount_space_avail);
goto out; goto out;
} }
/* enough space is available, so create the segment */ /* enough space is available, so create the segment */

Просмотреть файл

@ -27,5 +27,5 @@ file). It is likely that your MPI job will now either abort or experience
performance degradation. performance degradation.
Local host: %s Local host: %s
Space Requested: %ld B Space Requested: %lu B
Space Available: %ld B Space Available: %llu B

Просмотреть файл

@ -40,6 +40,7 @@
#include <string.h> #include <string.h>
#endif /* HAVE_STRING_H */ #endif /* HAVE_STRING_H */
#include "opal_stdint.h"
#include "opal/constants.h" #include "opal/constants.h"
#include "opal_stdint.h" #include "opal_stdint.h"
#include "opal/util/output.h" #include "opal/util/output.h"
@ -82,8 +83,8 @@ module_finalize(void);
static int static int
enough_space(const char *filename, enough_space(const char *filename,
long space_req, size_t space_req,
long *space_avail, uint64_t *space_avail,
bool *result); bool *result);
/* /*
@ -132,12 +133,12 @@ shmem_ds_reset(opal_shmem_ds_t *ds_buf)
/* ////////////////////////////////////////////////////////////////////////// */ /* ////////////////////////////////////////////////////////////////////////// */
static int static int
enough_space(const char *filename, enough_space(const char *filename,
long space_req, size_t space_req,
long *space_avail, uint64_t *space_avail,
bool *result) bool *result)
{ {
long avail = 0; uint64_t avail = 0;
long fluff = (long)(.05 * space_req); size_t fluff = (size_t)(.05 * space_req);
bool enough = false; bool enough = false;
char *last_sep = NULL; char *last_sep = NULL;
/* the target file name is passed here, but we need to check the parent /* the target file name is passed here, but we need to check the parent
@ -168,8 +169,8 @@ enough_space(const char *filename,
OPAL_OUTPUT_VERBOSE( OPAL_OUTPUT_VERBOSE(
(70, opal_shmem_base_output, (70, opal_shmem_base_output,
"WARNING: not enough space on %s to meet request!" "WARNING: not enough space on %s to meet request!"
"available: %ld requested: %ld", target_dir, "available: %"PRIu64 "requested: %lu", target_dir,
avail, space_req + fluff) avail, (unsigned long)space_req + fluff)
); );
} }
@ -231,7 +232,7 @@ segment_create(opal_shmem_ds_t *ds_buf,
pid_t my_pid = getpid(); pid_t my_pid = getpid();
char *temp1 = NULL, *temp2 = NULL; char *temp1 = NULL, *temp2 = NULL;
bool space_available = false; bool space_available = false;
long amount_space_avail = 0; uint64_t amount_space_avail = 0;
/* the real size of the shared memory segment. this includes enough space /* the real size of the shared memory segment. this includes enough space
* to store our segment header. * to store our segment header.
@ -263,7 +264,7 @@ segment_create(opal_shmem_ds_t *ds_buf,
} }
/* let's make sure we have enough space for the backing file */ /* let's make sure we have enough space for the backing file */
if (OPAL_SUCCESS != (rc = enough_space(temp1, if (OPAL_SUCCESS != (rc = enough_space(temp1,
(long)real_size, real_size,
&amount_space_avail, &amount_space_avail,
&space_available))) { &space_available))) {
opal_output(0, "shmem: windows: an error occurred while determining " opal_output(0, "shmem: windows: an error occurred while determining "
@ -278,7 +279,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
hn[MAXHOSTNAMELEN - 1] = '\0'; hn[MAXHOSTNAMELEN - 1] = '\0';
rc = OPAL_ERR_OUT_OF_RESOURCE; rc = OPAL_ERR_OUT_OF_RESOURCE;
opal_show_help("help-opal-shmem-windows.txt", "target full", 1, opal_show_help("help-opal-shmem-windows.txt", "target full", 1,
temp1, hn, (long)real_size, amount_space_avail); temp1, hn, (unsigned long)real_size,
(unsigned long long)amount_space_avail);
free(temp1); free(temp1);
goto out; goto out;
} }

Просмотреть файл

@ -49,6 +49,7 @@
#include <sys/mount.h> #include <sys/mount.h>
#endif #endif
#include "opal_stdint.h"
#include "opal/util/output.h" #include "opal/util/output.h"
#include "opal/util/path.h" #include "opal/util/path.h"
#include "opal/util/os_path.h" #include "opal/util/os_path.h"
@ -537,7 +538,7 @@ found:
int int
opal_path_df(const char *path, opal_path_df(const char *path,
long *out_avail) uint64_t *out_avail)
{ {
#if !defined(__WINDOWS__) #if !defined(__WINDOWS__)
int rc = -1; int rc = -1;
@ -553,6 +554,7 @@ opal_path_df(const char *path,
if (NULL == path || NULL == out_avail) { if (NULL == path || NULL == out_avail) {
return OPAL_ERROR; return OPAL_ERROR;
} }
*out_avail = 0;
do { do {
#if defined(__SVR4) && defined(__sun) #if defined(__SVR4) && defined(__sun)
@ -576,7 +578,7 @@ opal_path_df(const char *path,
*out_avail = buf.f_bsize * ((int)buf.f_bavail < 0 ? 0 : buf.f_bavail); *out_avail = buf.f_bsize * ((int)buf.f_bavail < 0 ? 0 : buf.f_bavail);
OPAL_OUTPUT_VERBOSE((10, 2, "opal_path_df: stat(v)fs states " OPAL_OUTPUT_VERBOSE((10, 2, "opal_path_df: stat(v)fs states "
"path: %s has %ld B of free space.", "path: %s has %"PRIu64 " B of free space.",
path, *out_avail)); path, *out_avail));
return OPAL_SUCCESS; return OPAL_SUCCESS;
@ -594,11 +596,11 @@ opal_path_df(const char *path,
path, err, strerror(err))); path, err, strerror(err)));
return OPAL_ERROR; return OPAL_ERROR;
} }
*out_avail = dwFreeClusters * dwSectorsPerCluster * dwBytesPerSector; *out_avail = dwFreeClusters * dwSectorsPerCluster * dwBytesPerSector;
} }
OPAL_OUTPUT_VERBOSE((10, 2, "opal_path_df: stat(v)fs states " OPAL_OUTPUT_VERBOSE((10, 2, "opal_path_df: stat(v)fs states "
"path: %s has %ld B of free space.", "path: %s has %"PRIu64 " B of free space.",
path, *out_avail)); path, *out_avail));
return OPAL_SUCCESS; return OPAL_SUCCESS;

Просмотреть файл

@ -151,7 +151,7 @@ OPAL_DECLSPEC bool opal_path_nfs(char *fname) __opal_attribute_warn_unused_resul
*/ */
OPAL_DECLSPEC int OPAL_DECLSPEC int
opal_path_df(const char *path, opal_path_df(const char *path,
long *out_avail)__opal_attribute_warn_unused_result__; uint64_t *out_avail)__opal_attribute_warn_unused_result__;
END_C_DECLS END_C_DECLS
#endif /* OPAL_PATH_H */ #endif /* OPAL_PATH_H */