diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/lib/h5tools.c | 96 | ||||
-rw-r--r-- | tools/src/h5ls/h5ls.c | 68 |
2 files changed, 133 insertions, 31 deletions
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index 470df63..ef7dae1 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -16,6 +16,8 @@ * readable format. */ +#include <libgen.h> + #include "h5tools.h" #include "h5tools_dump.h" #include "h5tools_ref.h" @@ -52,21 +54,11 @@ H5_iter_order_t sort_order = H5_ITER_INC; /*sort_order [ascending | descendi /* module-scoped variables */ static int h5tools_init_g; /* if h5tools lib has been initialized */ -/* Names of VFDs */ -static const char *drivernames[]={ - "sec2", - "family", - "split", - "multi", -#ifdef H5_HAVE_PARALLEL - "mpio", -#endif /* H5_HAVE_PARALLEL */ -}; - -/* This enum should match the entries in the above drivers_list since they +/* This enum should match the entries in the below drivers_list since they * are indexes into the drivers_list array. */ typedef enum { - SEC2_IDX = 0 + SWMR_IDX = 0 + ,SEC2_IDX ,FAMILY_IDX ,SPLIT_IDX ,MULTI_IDX @@ -74,6 +66,19 @@ typedef enum { ,MPIO_IDX #endif /* H5_HAVE_PARALLEL */ } driver_idx; + +/* Names of VFDs */ +static const char *drivernames[]={ + [SWMR_IDX] = "swmr", + [SEC2_IDX] = "sec2", + [FAMILY_IDX] = "family", + [SPLIT_IDX] = "split", + [MULTI_IDX] = "multi", +#ifdef H5_HAVE_PARALLEL + [MPIO_IDX] = "mpio", +#endif /* H5_HAVE_PARALLEL */ +}; + #define NUM_DRIVERS (sizeof(drivernames) / sizeof(drivernames[0])) /*------------------------------------------------------------------------- @@ -422,6 +427,55 @@ h5tools_set_error_file(const char *fname, int is_bin) return retvalue; } +static hid_t +swmr_fapl_augment(hid_t fapl, const char *fname) +{ + H5F_vfd_swmr_config_t *config = NULL; /* Configuration for VFD SWMR */ + const char *dname; + char *tname; + + /* + * Set up to open the file with VFD SWMR configured. + */ + /* Enable page buffering */ + if(H5Pset_page_buffer_size(fapl, 4096, 100, 0) < 0) { + HDfprintf(rawerrorstream, "H5Pset_page_buffer_size failed\n"); + return H5I_INVALID_HID; + } + + /* Allocate memory for the configuration structure */ + config = (H5F_vfd_swmr_config_t *)HDmalloc(sizeof(H5F_vfd_swmr_config_t)); + if(config == NULL) { + HDfprintf(rawerrorstream, "VFD SWMR config allocation failed\n"); + return H5I_INVALID_HID; + } + + config->version = H5F__CURR_VFD_SWMR_CONFIG_VERSION; + config->tick_len = 4; + config->max_lag = 5; + config->vfd_swmr_writer = FALSE; + config->md_pages_reserved = 128; +#if 0 + config->md_open_tries = 1; +#endif + + if ((tname = strdup(fname)) == NULL) { + HDfprintf(rawerrorstream, "temporary string allocation failed\n"); + return H5I_INVALID_HID; + } + dname = dirname(tname); + snprintf(config->md_file_path, sizeof(config->md_file_path), + "%s/my_md_file", dname); + free(tname); + + /* Enable VFD SWMR configuration */ + if(H5Pset_vfd_swmr_config(fapl, config) < 0) { + HDfprintf(rawerrorstream, "H5Pset_vrd_swmr_config failed\n"); + return H5I_INVALID_HID; + } + return fapl; +} + /*------------------------------------------------------------------------- * Function: h5tools_get_fapl * @@ -432,7 +486,8 @@ h5tools_set_error_file(const char *fname, int is_bin) *------------------------------------------------------------------------- */ static hid_t -h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum) +h5tools_get_fapl(hid_t fapl, const char *fname, const char *driver, + unsigned *drivernum) { hid_t new_fapl = -1; /* Copy of file access property list passed in, or new property list */ int ret_value = SUCCEED; @@ -449,7 +504,13 @@ h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum) /* Determine which driver the user wants to open the file with. Try * that driver. If it can't open it, then fail. */ - if (!HDstrcmp(driver, drivernames[SEC2_IDX])) { + if (!HDstrcmp(driver, drivernames[SWMR_IDX])) { + /* SWMR driver */ + if (swmr_fapl_augment(new_fapl, fname) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "swmr_fapl_augment failed"); + if (drivernum) + *drivernum = SWMR_IDX; + } else if (!HDstrcmp(driver, drivernames[SEC2_IDX])) { /* SEC2 driver */ if (H5Pset_fapl_sec2(new_fapl) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pset_fapl_sec2 failed"); @@ -545,7 +606,7 @@ h5tools_fopen(const char *fname, unsigned flags, hid_t fapl, const char *driver, if (driver && *driver) { /* Get the correct FAPL for the given driver */ - if ((my_fapl = h5tools_get_fapl(fapl, driver, &drivernum)) < 0) + if ((my_fapl = h5tools_get_fapl(fapl, fname, driver, &drivernum)) < 0) goto done; /* allow error stack display if enable-error-stack has optional arg number */ @@ -566,7 +627,8 @@ h5tools_fopen(const char *fname, unsigned flags, hid_t fapl, const char *driver, /* Try to open the file using each of the drivers */ for (drivernum = 0; drivernum < NUM_DRIVERS; drivernum++) { /* Get the correct FAPL for the given driver */ - if((my_fapl = h5tools_get_fapl(fapl, drivernames[drivernum], NULL)) < 0) + if((my_fapl = h5tools_get_fapl(fapl, fname, drivernames[drivernum], + NULL)) < 0) goto done; /* allow error stack display if enable-error-stack has optional arg number */ diff --git a/tools/src/h5ls/h5ls.c b/tools/src/h5ls/h5ls.c index 4bc1526..cf03b30 100644 --- a/tools/src/h5ls/h5ls.c +++ b/tools/src/h5ls/h5ls.c @@ -16,7 +16,6 @@ * Monday, March 23, 1998 */ - /* * We include the private header file so we can get to the uniform * programming environment it declares. Other than that, h5ls only calls @@ -121,6 +120,7 @@ typedef struct { /* Command-line switches */ static int verbose_g = 0; /* lots of extra output */ static int width_g = 80; /* output width in characters */ +static hbool_t vfd_swmr_poll_g = FALSE; /* poll for changes using VFD SWMR */ static hbool_t address_g = FALSE; /* print raw data addresses */ static hbool_t data_g = FALSE; /* display dataset values? */ static hbool_t label_g = FALSE; /* label compound values? */ @@ -178,6 +178,7 @@ usage (void) { FLUSHSTREAM(rawoutstream); PRINTVALSTREAM(rawoutstream, "usage: h5ls [OPTIONS] file[/OBJECT] [file[/[OBJECT]...]\n"); + PRINTVALSTREAM(rawoutstream, " h5ls [OPTIONS] --poll file\n"); PRINTVALSTREAM(rawoutstream, " OPTIONS\n"); PRINTVALSTREAM(rawoutstream, " -h, -?, --help Print a usage message and exit\n"); PRINTVALSTREAM(rawoutstream, " -a, --address Print raw data address. If dataset is contiguous, address\n"); @@ -208,6 +209,7 @@ usage (void) PRINTVALSTREAM(rawoutstream, " -f, --full Print full path names instead of base names\n"); PRINTVALSTREAM(rawoutstream, " -g, --group Show information about a group, not its contents\n"); PRINTVALSTREAM(rawoutstream, " -l, --label Label members of compound datasets\n"); + PRINTVALSTREAM(rawoutstream, " -p, --poll Continuously re-read and re-display the input file using VFD SWMR\n"); PRINTVALSTREAM(rawoutstream, " -r, --recursive List all groups recursively, avoiding cycles\n"); PRINTVALSTREAM(rawoutstream, " -s, --string Print 1-byte integer datasets as ASCII\n"); PRINTVALSTREAM(rawoutstream, " -S, --simple Use a machine-readable output format\n"); @@ -1462,6 +1464,8 @@ dump_dataset_values(hid_t dset) h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0); ctx.need_prefix = TRUE; ctx.cur_column = (size_t)curr_pos; + if (vfd_swmr_poll_g) + H5Drefresh(dset); if (h5tools_dump_dset(rawoutstream, info, &ctx, dset, NULL) < 0) { h5tools_str_reset(&buffer); h5tools_str_append(&buffer, " Unable to print data."); @@ -2597,11 +2601,12 @@ main(int argc, const char *argv[]) char *fname = NULL, *oname = NULL, *x; const char *s = NULL; char *rest; - int argno; + int argno, times; static char root_name[] = "/"; char drivername[50]; const char *preferred_driver = NULL; int err_exit = 0; + uint64_t poll_nanosecs = 1000; h5tools_setprogname(PROGRAMNAME); h5tools_setstatus(EXIT_SUCCESS); @@ -2643,6 +2648,19 @@ main(int argc, const char *argv[]) follow_elink_g = TRUE; } else if(!HDstrcmp(argv[argno], "--full")) { fullname_g = TRUE; + } else if(!HDstrncmp(argv[argno], "--poll=", strlen("--poll="))) { + int nscanned = 0, rc; + uint64_t poll_millisecs; + rc = sscanf(argv[argno], "--poll=%" SCNu64 "%n", &poll_millisecs, + &nscanned); + if (rc != 1 || argv[argno][nscanned] != '\0') { + usage(); + leave(EXIT_FAILURE); + } + poll_nanosecs = poll_millisecs * 1000000; + vfd_swmr_poll_g = TRUE; + } else if(!HDstrcmp(argv[argno], "--poll")) { + vfd_swmr_poll_g = TRUE; } else if(!HDstrcmp(argv[argno], "--group")) { grp_literal_g = TRUE; } else if(!HDstrcmp(argv[argno], "--label")) { @@ -2740,6 +2758,10 @@ main(int argc, const char *argv[]) label_g = TRUE; break; + case 'p': /* --poll */ + vfd_swmr_poll_g = TRUE; + break; + case 'r': /* --recursive */ recursive_g = TRUE; fullname_g = TRUE; @@ -2784,6 +2806,10 @@ main(int argc, const char *argv[]) leave(EXIT_FAILURE); } /* end if */ + if (vfd_swmr_poll_g && argc > 1 + argno) { + HDfprintf(rawerrorstream, "Error: -p / --poll is limited to only one file[/OBJECT]\n\n"); + leave(EXIT_FAILURE); + } /* Check for conflicting arguments */ if (!is_valid_args()) { @@ -2815,6 +2841,10 @@ main(int argc, const char *argv[]) symlink_trav_t symlink_list; size_t u; + if (vfd_swmr_poll_g) { + preferred_driver = "swmr"; + } + fname = HDstrdup(argv[argno++]); oname = NULL; file = -1; @@ -2826,8 +2856,8 @@ main(int argc, const char *argv[]) if(verbose_g) PRINTSTREAM(rawoutstream, "Opened \"%s\" with %s driver.\n", fname, drivername); break; /*success*/ - } /* end if */ - + } else if (vfd_swmr_poll_g) + break; /* Shorten the file name; lengthen the object name */ x = oname; oname = HDstrrchr(fname, '/'); @@ -2903,16 +2933,26 @@ main(int argc, const char *argv[]) else li.type = H5L_TYPE_HARD; - /* Open the object and display it's information */ - if(li.type == H5L_TYPE_HARD) { - if(visit_obj(file, oname, &iter) < 0) - leave(EXIT_FAILURE); - } /* end if(li.type == H5L_TYPE_HARD) */ - else { - /* Specified name is not for object -- list that link */ - /* Use file ID for root group ID */ - iter.gid = file; - list_lnk(oname, &li, &iter); + for (times = 0; vfd_swmr_poll_g || times < 1; times++) { + if (vfd_swmr_poll_g) { + int i; + for (i = 0; i < 3; i++) + printf("\n"); + } + /* Open the object and display it's information */ + if(li.type == H5L_TYPE_HARD) { + if(visit_obj(file, oname, &iter) < 0) + leave(EXIT_FAILURE); + } /* end if(li.type == H5L_TYPE_HARD) */ + else { + /* Specified name is not for object -- list that link */ + /* Use file ID for root group ID */ + iter.gid = file; + list_lnk(oname, &li, &iter); + } +#if 1 + H5_nanosleep(poll_nanosecs); +#endif } H5Fclose(file); HDfree(fname); |