From e3545bf88db356f085a034bc14a229c3c2bf161c Mon Sep 17 00:00:00 2001 From: dmh Date: Fri, 7 Mar 2014 12:04:38 -0700 Subject: [PATCH] 1. Allow files to be opened by name multiple times, but returning the same ncid. 2. Separate out the dap auth tests and make them disabled by default. 3. turn of ncdap_test/test_varm3 until we can find a copy of coads_climatology.nc --- cf | 5 ++++- configure.ac | 17 +++++++++++++++++ include/nc.h | 4 +++- libdispatch/ddispatch.c | 9 ++------- libdispatch/dfile.c | 31 +++++++++++++++++++++++++++---- libdispatch/nclistmgr.c | 30 ++++++++++++++++++++++++++++++ ncdap_test/CMakeLists.txt | 8 +++++++- ncdap_test/Makefile.am | 19 ++++++++++++++----- ncdap_test/t_misc.c | 2 +- ncdump/env | 6 ++++++ 10 files changed, 111 insertions(+), 20 deletions(-) create mode 100644 ncdump/env diff --git a/cf b/cf index f36128ef3..440032a0f 100644 --- a/cf +++ b/cf @@ -16,6 +16,8 @@ DAP=1 #M32=1 #M64=1 +FORCE="-i" + #INSTALL=1 PREFIX=/usr/local @@ -153,6 +155,7 @@ FLAGS="$FLAGS --disable-examples" #FLAGS="$FLAGS --enable-large-file-tests" #FLAGS="$FLAGS --disable-testsets" #FLAGS="$FLAGS --disable-dap-remote-tests" +#FLAGS="$FLAGS --enable-dap-auth-tests" #FLAGS="$FLAGS --enable-doxygen" #FLAGS="$FLAGS --enable-logging" #FLAGS="$FLAGS --disable-diskless" @@ -215,6 +218,6 @@ export DISTCHECK_CONFIGURE_FLAGS if test -f Makefile ; then ${MAKE} distclean >/dev/null 2>&1 ; fi sh $X ./configure ${FLAGS} for c in $cmds; do - ${MAKE} $c + ${MAKE} ${FORCE} $c done exit 0 diff --git a/configure.ac b/configure.ac index d2321c37b..261ace42a 100644 --- a/configure.ac +++ b/configure.ac @@ -304,6 +304,22 @@ if test "x$enable_dap" = "xno" ; then fi AC_MSG_RESULT($enable_dap_remote_tests) +# Default is now to do the remote authorization tests +AC_MSG_CHECKING([whether dap remote authorization testing should be enabled (default off)]) +AC_ARG_ENABLE([dap-auth-test], + [AS_HELP_STRING([--enable-dap-auth-tests], + [enable dap remote authorization tests])]) +test "x$enable_dap_auth_tests" = xyes || enable_dap_auth_tests=no +# dap must be enabled +if test "x$enable_dap" = "xno" ; then + enable_dap_auth_tests=no +fi +# if remote tests are disabled, then so is this +if test "x$enable_dap_remote_tests" = "xno" ; then + enable_dap_remote_tests=no +fi +AC_MSG_RESULT($enable_dap_auth_tests) + # Control if groups are supported in [netcdf4]dap2 code AC_MSG_CHECKING([whether [netcdf4] group names should be enabled (default on)]) AC_ARG_ENABLE([dap-groups], @@ -811,6 +827,7 @@ AM_CONDITIONAL(TEST_PARALLEL, [test "x$enable_parallel" = xyes -a "x$enable_para AM_CONDITIONAL(BUILD_DAP, [test "x$enable_dap" = xyes]) AM_CONDITIONAL(USE_DAP, [test "x$enable_dap" = xyes]) # Alias AM_CONDITIONAL(ENABLE_DAP_REMOTE_TESTS, [test "x$enable_dap_remote_tests" = xyes]) +AM_CONDITIONAL(ENABLE_DAP_AUTH_TESTS, [test "x$enable_dap_auth_tests" = xyes]) AM_CONDITIONAL(ENABLE_DAP_LONG_TESTS, [test "x$enable_dap_long_tests" = xyes]) AM_CONDITIONAL(EXTRA_EXAMPLE_TESTS, [test "x$enable_extra_example_tests" = xyes]) AM_CONDITIONAL(USE_SZIP, [test "x$ac_cv_func_H5Z_SZIP" = xyes]) diff --git a/include/nc.h b/include/nc.h index 6653ebad6..8c44edc74 100644 --- a/include/nc.h +++ b/include/nc.h @@ -27,7 +27,8 @@ typedef struct NC { void* dispatchdata; /*per-'file' data; points to e.g. NC3_INFO data*/ char* path; int mode; /* as provided to nc_open/nc_create */ - int substrate; + int substrate; + int refcount; /* To enable multiple name-based opens */ } NC; /* @@ -76,6 +77,7 @@ extern int nc_get_default_format(void); extern int add_to_NCList(NC*); extern void del_from_NCList(NC*);/* does not free object */ extern NC* find_in_NCList(int ext_ncid); +extern NC* find_in_NCList_by_name(const char*); extern void free_NCList(void);/* reclaim whole list */ extern int count_NCList(void); /* return # of entries in NClist */ diff --git a/libdispatch/ddispatch.c b/libdispatch/ddispatch.c index c2e36dbf8..24a80d573 100644 --- a/libdispatch/ddispatch.c +++ b/libdispatch/ddispatch.c @@ -31,15 +31,10 @@ static struct NCPROTOCOLLIST { against future changes. */ static const char* servers[] = { -"http://thredds-test.ucar.edu", -"http://thredds.ucar.edu", -"http://motherlode.ucar.edu:8081", -"http://motherlode.ucar.edu:8080", -"http://motherlode.ucar.edu", "http://remotetest.unidata.ucar.edu", +"http://thredds-test.unidata.ucar.edu", "http://remotetest.ucar.edu", -"http://remotetests.unidata.ucar.edu", -"http://remotetests.ucar.edu", +"http://thredds-test.ucar.edu", NULL }; diff --git a/libdispatch/dfile.c b/libdispatch/dfile.c index e3f17709f..08ed93f50 100644 --- a/libdispatch/dfile.c +++ b/libdispatch/dfile.c @@ -1033,6 +1033,11 @@ nc_abort(int ncid) NC* ncp; int stat = NC_check_id(ncid, &ncp); if(stat != NC_NOERR) return stat; + + /* What to do if refcount > 0? */ + /* currently, forcibly abort */ + ncp->refcount = 0; + stat = ncp->dispatch->abort(ncid); del_from_NCList(ncp); free_NC(ncp); @@ -1085,10 +1090,15 @@ nc_close(int ncid) NC* ncp; int stat = NC_check_id(ncid, &ncp); if(stat != NC_NOERR) return stat; - stat = ncp->dispatch->close(ncid); - /* Remove from the nc list */ - del_from_NCList(ncp); - free_NC(ncp); + + ncp->refcount--; + if(ncp->refcount <= 0) + { + stat = ncp->dispatch->close(ncid); + /* Remove from the nc list */ + del_from_NCList(ncp); + free_NC(ncp); + } return stat; } @@ -1505,6 +1515,11 @@ NC_create(const char *path, int cmode, size_t initialsz, nc_initialized = 1; } + /* If this path is already open, then fail */ + ncp = find_in_NCList_by_name(path); + if(ncp != NULL) + return NC_ENFILE; + if((isurl = NC_testurl(path))) model = NC_urlmodel(path); @@ -1636,6 +1651,14 @@ NC_open(const char *path, int cmode, nc_initialized = 1; } + /* If this path is already open, then bump the refcount and return it */ + ncp = find_in_NCList_by_name(path); + if(ncp != NULL) { + ncp->refcount++; + if(ncidp) *ncidp = ncp->ext_ncid; + return NC_NOERR; + } + isurl = NC_testurl(path); if(isurl) model = NC_urlmodel(path); diff --git a/libdispatch/nclistmgr.c b/libdispatch/nclistmgr.c index ad521ac7b..afc7b447b 100644 --- a/libdispatch/nclistmgr.c +++ b/libdispatch/nclistmgr.c @@ -42,6 +42,10 @@ add_to_NCList(NC* ncp) return NC_ENOMEM; numfiles = 0; } + /* Check the refcount */ + if(ncp->refcount > 0) + return NC_NOERR; + new_id = 0; /* id's begin at 1 */ for(i=1; i < NCFILELISTLENGTH; i++) { if(nc_filelist[i] == NULL) {new_id = i; break;} @@ -60,6 +64,10 @@ del_from_NCList(NC* ncp) unsigned int ncid = ((unsigned int)ncp->ext_ncid) >> ID_SHIFT; if(numfiles == 0 || ncid == 0 || nc_filelist == NULL) return; if(nc_filelist[ncid] != ncp) return; + /* Check the refcount */ + if(ncp->refcount > 0) + return; /* assume caller has decrecmented */ + nc_filelist[ncid] = NULL; numfiles--; @@ -78,3 +86,25 @@ find_in_NCList(int ext_ncid) return f; } +/* +Added to support open by name +*/ +NC* +find_in_NCList_by_name(const char* path) +{ + int i; + NC* f = NULL; + if(nc_filelist == NULL) + return NULL; + for(i=1; i < NCFILELISTLENGTH; i++) { + if(nc_filelist[i] != NULL) { + if(strcmp(nc_filelist[i]->path,path)==0) { + f = nc_filelist[i]; + break; + } + } + } + return f; +} + + diff --git a/ncdap_test/CMakeLists.txt b/ncdap_test/CMakeLists.txt index 85905c4c9..c58290d28 100644 --- a/ncdap_test/CMakeLists.txt +++ b/ncdap_test/CMakeLists.txt @@ -40,10 +40,16 @@ IF(ENABLE_TESTS) ENDIF() add_bin_test(ncdap test_nstride_cached) add_bin_test(ncdap test_partvar) - add_bin_test(ncdap test_varm3) add_bin_test(ncdap t_auth) add_bin_test(ncdap t_misc) +# test_varm3 did not survive the transition +# to remotetest.unidata.ucar.edu; the +# coads_climatology.nc file cannot be found. +# Can restore if/when we find that file +# and put it in testdods directory on remotetest. +# add_bin_test(ncdap test_varm3) + ENDIF() ADD_SUBDIRECTORY(testdata3) ADD_SUBDIRECTORY(expected3) diff --git a/ncdap_test/Makefile.am b/ncdap_test/Makefile.am index ef07d4d8b..e5dce4f70 100644 --- a/ncdap_test/Makefile.am +++ b/ncdap_test/Makefile.am @@ -34,26 +34,35 @@ endif test_cvt3_SOURCES = test_cvt.c test_vara_SOURCES = test_vara.c test_partvar_SOURCES = test_partvar.c -test_varm3_SOURCES = test_varm3.c t_dap3a_SOURCES = t_dap3a.c test_nstride_cached_SOURCE = test_nstride_cached.c t_auth_SOURCES = t_auth.c t_misc_SOURCES = t_misc.c TESTS += t_dap3a test_cvt3 test_vara test_partvar -TESTS += test_varm3 TESTS += t_dap3a TESTS += test_nstride_cached -TESTS += t_auth TESTS += t_misc check_PROGRAMS += t_dap3a test_cvt3 test_vara test_partvar -check_PROGRAMS += test_varm3 check_PROGRAMS += t_dap3a check_PROGRAMS += test_nstride_cached -check_PROGRAMS += t_auth check_PROGRAMS += t_misc +# test_varm3 did not survive the transition +# to remotetest.unidata.ucar.edu; the +# coads_climatology.nc file cannot be found. +# Can restore if/when we find that file +# and put it in testdods directory on remotetest. +# test_varm3_SOURCES = test_varm3.c +# check_PROGRAMS += test_varm3 +# TESTS += test_varm3 + +if ENABLE_DAP_AUTH_TESTS +check_PROGRAMS += t_auth +TESTS += t_auth +endif + endif #ENABLE_DAP_REMOTE_TESTS diff --git a/ncdap_test/t_misc.c b/ncdap_test/t_misc.c index 2c2ad2500..579d516fc 100644 --- a/ncdap_test/t_misc.c +++ b/ncdap_test/t_misc.c @@ -5,7 +5,7 @@ #include -#define URL1 "http://thredds-test.ucar.edu" /* test that no trailing / is ok */ +#define URL1 "http://remotetest.unidata.ucar.edu" /* test that no trailing / is ok */ static void CHECK(int e, const char* msg) diff --git a/ncdump/env b/ncdump/env new file mode 100644 index 000000000..a998e21b8 --- /dev/null +++ b/ncdump/env @@ -0,0 +1,6 @@ +F="tst_small.nc" + +alias q0="./ncdump $F" +alias qh="./ncdump -h $F" +alias qq="gdb --args ./ncdump $F" +alias qqh="gdb --args ./ncdump -h $F"