mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-12-21 08:39:46 +08:00
49737888ca
## Improvements to S3 Documentation * Create a new document *quickstart_paths.md* that give a summary of the legal path formats used by netcdf-c. This includes both file paths and URL paths. * Modify *nczarr.md* to remove most of the S3 related text. * Move the S3 text from *nczarr.md* to a new document *cloud.md*. * Add some S3-related text to the *byterange.md* document. Hopefully, this will make it easier for users to find the information they want. ## Rebuild NCZarr Testing In order to avoid problems with running make check in parallel, two changes were made: 1. The *nczarr_test* test system was rebuilt. Now, for each test. any generated files are kept in a test-specific directory, isolated from all other test executions. 2. Similarly, since the S3 test bucket is shared, any generated S3 objects are isolated using a test-specific key path. ## Other S3 Related Changes * Add code to ensure that files created on S3 are reclaimed at end of testing. * Used the bash "trap" command to ensure S3 cleanup even if the test fails. * Cleanup the S3 related configure.ac flag set since S3 is used in several places. So now one should use the option *--enable-s3* instead of *--enable-nczarr-s3*, although the latter is still kept as a deprecated alias for the former. * Get some of the github actions yml to work with S3; required fixing various test scripts adding a secret to access the Unidata S3 bucket. * Cleanup S3 portion of libnetcdf.settings.in and netcdf_meta.h.in and test_common.in. * Merge partial S3 support into dhttp.c. * Create an experimental s3 access library especially for use with Windows. It is enabled by using the options *--enable-s3-internal* (automake) or *-DENABLE_S3_INTERNAL=ON* (CMake). Also add a unit-test for it. * Move some definitions from ncrc.h to ncs3sdk.h ## Other Changes * Provide a default implementation of strlcpy and move this and similar defaults into *dmissing.c*.
202 lines
5.7 KiB
C
202 lines
5.7 KiB
C
/*
|
|
* Copyright 2018, University Corporation for Atmospheric Research
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "netcdf.h"
|
|
#include "ncio.h"
|
|
#include "fbits.h"
|
|
#include "ncuri.h"
|
|
#include "ncrc.h"
|
|
|
|
/* With the advent of diskless io, we need to provide
|
|
for multiple ncio packages at the same time,
|
|
so we have multiple versions of ncio_create.
|
|
*/
|
|
|
|
/* Define known ncio packages */
|
|
extern int posixio_create(const char*,int,size_t,off_t,size_t,size_t*,void*,ncio**,void** const);
|
|
extern int posixio_open(const char*,int,off_t,size_t,size_t*,void*,ncio**,void** const);
|
|
|
|
extern int stdio_create(const char*,int,size_t,off_t,size_t,size_t*,void*,ncio**,void** const);
|
|
extern int stdio_open(const char*,int,off_t,size_t,size_t*,void*,ncio**,void** const);
|
|
|
|
#ifdef USE_FFIO
|
|
extern int ffio_create(const char*,int,size_t,off_t,size_t,size_t*,void*,ncio**,void** const);
|
|
extern int ffio_open(const char*,int,off_t,size_t,size_t*,void*,ncio**,void** const);
|
|
#endif
|
|
|
|
# ifdef USE_MMAP
|
|
extern int mmapio_create(const char*,int,size_t,off_t,size_t,size_t*,void*,ncio**,void** const);
|
|
extern int mmapio_open(const char*,int,off_t,size_t,size_t*,void*,ncio**,void** const);
|
|
# endif
|
|
|
|
#ifdef ENABLE_BYTERANGE
|
|
extern int httpio_open(const char*,int,off_t,size_t,size_t*,void*,ncio**,void** const);
|
|
#endif
|
|
|
|
#ifdef ENABLE_S3
|
|
extern int s3io_open(const char*,int,off_t,size_t,size_t*,void*,ncio**,void** const);
|
|
#endif
|
|
|
|
extern int memio_create(const char*,int,size_t,off_t,size_t,size_t*,void*,ncio**,void** const);
|
|
extern int memio_open(const char*,int,off_t,size_t,size_t*,void*,ncio**,void** const);
|
|
|
|
/* Forward */
|
|
#ifdef ENABLE_BYTERANGE
|
|
static int urlmodetest(const char* path);
|
|
#endif
|
|
|
|
int
|
|
ncio_create(const char *path, int ioflags, size_t initialsz,
|
|
off_t igeto, size_t igetsz, size_t *sizehintp,
|
|
void* parameters,
|
|
ncio** iopp, void** const mempp)
|
|
{
|
|
if(fIsSet(ioflags,NC_DISKLESS)) {
|
|
return memio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
} else if(fIsSet(ioflags,NC_INMEMORY)) {
|
|
return memio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
}
|
|
# ifdef USE_MMAP
|
|
else if(fIsSet(ioflags,NC_MMAP)) {
|
|
return mmapio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
}
|
|
# endif /*USE_MMAP*/
|
|
|
|
#ifdef USE_STDIO
|
|
return stdio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
#elif defined(USE_FFIO)
|
|
return ffio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
#else
|
|
return posixio_create(path,ioflags,initialsz,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
#endif
|
|
}
|
|
|
|
int
|
|
ncio_open(const char *path, int ioflags,
|
|
off_t igeto, size_t igetsz, size_t *sizehintp,
|
|
void* parameters,
|
|
ncio** iopp, void** const mempp)
|
|
{
|
|
#ifdef ENABLE_BYTERANGE
|
|
int modetest = urlmodetest(path);
|
|
#endif
|
|
|
|
/* Diskless open has the following constraints:
|
|
1. file must be classic version 1 or 2 or 5
|
|
*/
|
|
if(fIsSet(ioflags,NC_DISKLESS)) {
|
|
return memio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
}
|
|
if(fIsSet(ioflags,NC_INMEMORY)) {
|
|
return memio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
}
|
|
# ifdef USE_MMAP
|
|
if(fIsSet(ioflags,NC_MMAP)) {
|
|
return mmapio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
}
|
|
# endif /*USE_MMAP*/
|
|
# ifdef ENABLE_BYTERANGE
|
|
if(modetest == NC_HTTP) {
|
|
return httpio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
}
|
|
# ifdef ENABLE_S3
|
|
if(modetest == NC_S3SDK) {
|
|
return s3io_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
}
|
|
# endif
|
|
# endif /*ENABLE_BYTERANGE*/
|
|
|
|
#ifdef USE_STDIO
|
|
return stdio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
#elif defined(USE_FFIO)
|
|
return ffio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
#else
|
|
return posixio_open(path,ioflags,igeto,igetsz,sizehintp,parameters,iopp,mempp);
|
|
#endif
|
|
}
|
|
|
|
/**************************************************/
|
|
/* wrapper functions for the ncio dispatch table */
|
|
|
|
int
|
|
ncio_rel(ncio* const nciop, off_t offset, int rflags)
|
|
{
|
|
return nciop->rel(nciop,offset,rflags);
|
|
}
|
|
|
|
int
|
|
ncio_get(ncio* const nciop, off_t offset, size_t extent,
|
|
int rflags, void **const vpp)
|
|
{
|
|
return nciop->get(nciop,offset,extent,rflags,vpp);
|
|
}
|
|
|
|
int
|
|
ncio_move(ncio* const nciop, off_t to, off_t from, size_t nbytes, int rflags)
|
|
{
|
|
return nciop->move(nciop,to,from,nbytes,rflags);
|
|
}
|
|
|
|
int
|
|
ncio_sync(ncio* const nciop)
|
|
{
|
|
return nciop->sync(nciop);
|
|
}
|
|
|
|
int
|
|
ncio_filesize(ncio* const nciop, off_t *filesizep)
|
|
{
|
|
return nciop->filesize(nciop,filesizep);
|
|
}
|
|
|
|
int
|
|
ncio_pad_length(ncio* const nciop, off_t length)
|
|
{
|
|
return nciop->pad_length(nciop,length);
|
|
}
|
|
|
|
int
|
|
ncio_close(ncio* const nciop, int doUnlink)
|
|
{
|
|
/* close and release all resources associated
|
|
with nciop, including nciop
|
|
*/
|
|
int status = nciop->close(nciop,doUnlink);
|
|
return status;
|
|
}
|
|
|
|
/* URL utilities */
|
|
|
|
/*
|
|
Check mode flags and return:
|
|
NC_HTTP => byterange
|
|
NC_S3SDK => s3
|
|
0 => Not URL
|
|
*/
|
|
#ifdef ENABLE_BYTERANGE
|
|
static int
|
|
urlmodetest(const char* path)
|
|
{
|
|
int kind = 0;
|
|
NCURI* uri = NULL;
|
|
|
|
ncuriparse(path,&uri);
|
|
if(uri == NULL) return 0; /* Not URL */
|
|
if(NC_testmode(uri, "bytes")) {
|
|
/* NC_S3SDK takes priority over NC_HTTP */
|
|
if(NC_testmode(uri, "s3")) kind = NC_S3SDK; else kind = NC_HTTP;
|
|
} else
|
|
kind = 0;
|
|
ncurifree(uri);
|
|
return kind;
|
|
}
|
|
#endif
|