From 52c18fefc7cea7524955f53f286a485d9c26c0fd Mon Sep 17 00:00:00 2001 From: Thomas Bertschinger Date: Thu, 23 May 2024 14:08:03 -0600 Subject: [PATCH 1/5] switch config flags to use unsigned instead of signed int This will make FFI with Rust easier, as Rust expects the config flags to be unsigned types. --- src/api/testing/test_marfsapi.c | 2 +- src/config/config.c | 2 +- src/config/config.h | 2 +- src/config/testing/test_config.c | 2 +- src/config/verifyconf.c | 2 +- src/datastream/testing/test_datastream.c | 2 +- src/datastream/testing/test_datastream_rebuilds.c | 2 +- src/datastream/testing/test_datastream_repack.c | 2 +- src/mdal/mdal.h | 2 +- src/mdal/posix_mdal.c | 2 +- src/rsrc_mgr/new_rsrc_mgr.c | 2 +- src/rsrc_mgr/rsrc_mgr.c | 2 +- src/rsrc_mgr/testing/test_resourcelog.c | 2 +- src/rsrc_mgr/testing/test_resourceprocessing.c | 2 +- src/rsrc_mgr/testing/test_resourcethreads.c | 2 +- src/rsrc_mgr/testing/test_rsrc_mgr.c | 2 +- src/rsrc_mgr/testing/test_rsrc_mgr_nopack.c | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/api/testing/test_marfsapi.c b/src/api/testing/test_marfsapi.c index 811c5025..bb9b692a 100644 --- a/src/api/testing/test_marfsapi.c +++ b/src/api/testing/test_marfsapi.c @@ -137,7 +137,7 @@ int main( int argc, char** argv ) { return -1; } marfs_config* verconf = config_init( "testing/config.xml", &erasurelock ); - int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; + unsigned int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; if ( config_verify( verconf, ".", flags ) ) { printf( "failed to verify batch ctxt config\n" ); return -1; diff --git a/src/config/config.c b/src/config/config.c index 0e93156b..60081a2c 100644 --- a/src/config/config.c +++ b/src/config/config.c @@ -3235,7 +3235,7 @@ HASH_TABLE config_genreftable( HASH_NODE** refnodes, size_t* refnodecount, size_ * @param int flags : flags to control behavior of the verification * @return int : A count of uncorrected errors encountered, or -1 if a failure occurred */ -int config_verify( marfs_config* config, const char* tgtNS, int flags ) { +int config_verify( marfs_config* config, const char* tgtNS, unsigned int flags ) { int MDALcheck = flags & CFG_MDALCHECK; int NEcheck = flags & CFG_DALCHECK; diff --git a/src/config/config.h b/src/config/config.h index f35b3469..a1c33510 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -232,7 +232,7 @@ HASH_TABLE config_genreftable( HASH_NODE** refnodes, size_t* refnodecount, size_ * @param int flags : flags to control behavior of the verification * @return int : A count of uncorrected errors encountered, or -1 if a failure occurred */ -int config_verify( marfs_config* config, const char* tgtNS, int flags ); +int config_verify( marfs_config* config, const char* tgtNS, unsigned int flags ); /** * Traverse the given path, idetifying a final NS target and resulting subpath diff --git a/src/config/testing/test_config.c b/src/config/testing/test_config.c index 32dc19bf..d206c564 100644 --- a/src/config/testing/test_config.c +++ b/src/config/testing/test_config.c @@ -556,7 +556,7 @@ int main(int argc, char **argv) // prepare for full path traversal by actually creating config namespaces - int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; + unsigned int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; if ( config_verify(config,"/campaign/",flags ) ) { printf( "Config validation failure\n" ); return -1; diff --git a/src/config/verifyconf.c b/src/config/verifyconf.c index 5d5749a9..86d27f81 100644 --- a/src/config/verifyconf.c +++ b/src/config/verifyconf.c @@ -81,7 +81,7 @@ int main(int argc, const char** argv) { char* config_path = getenv( "MARFS_CONFIG_PATH" ); // check for config env var char* ns_path = "."; char* user_name = NULL; - int flags = CFG_OWNERCHECK; + unsigned int flags = CFG_OWNERCHECK; // parse all position-independent arguments char pr_usage = 0; diff --git a/src/datastream/testing/test_datastream.c b/src/datastream/testing/test_datastream.c index d6f5a124..99fb7293 100644 --- a/src/datastream/testing/test_datastream.c +++ b/src/datastream/testing/test_datastream.c @@ -151,7 +151,7 @@ int main(int argc, char **argv) } // create all namespaces associated with the config - int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; + unsigned int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; if ( config_verify( config, "./.", flags ) ) { printf( "Failed to validate the marfs config\n" ); return -1; diff --git a/src/datastream/testing/test_datastream_rebuilds.c b/src/datastream/testing/test_datastream_rebuilds.c index 44f4da3d..dbe6e124 100644 --- a/src/datastream/testing/test_datastream_rebuilds.c +++ b/src/datastream/testing/test_datastream_rebuilds.c @@ -121,7 +121,7 @@ int main(int argc, char **argv) // Initialize the libxml lib and check for API mismatches LIBXML_TEST_VERSION - int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; + unsigned int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; // create the dirs necessary for DAL/MDAL initialization (ignore EEXIST) errno = 0; diff --git a/src/datastream/testing/test_datastream_repack.c b/src/datastream/testing/test_datastream_repack.c index a471cb0f..61142669 100644 --- a/src/datastream/testing/test_datastream_repack.c +++ b/src/datastream/testing/test_datastream_repack.c @@ -151,7 +151,7 @@ int main(int argc, char **argv) } // create all namespaces associated with the config - int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; + unsigned int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; if ( config_verify( config, "./.", flags ) ) { printf( "Failed to validate the marfs config\n" ); return -1; diff --git a/src/mdal/mdal.h b/src/mdal/mdal.h index 40ae45cf..4969c2d8 100644 --- a/src/mdal/mdal.h +++ b/src/mdal/mdal.h @@ -142,7 +142,7 @@ typedef struct MDAL_struct { * matches current user if true) * @return int : A count of uncorrected security issues, or -1 if a failure occurred */ - int (*checksec) ( const MDAL_CTXT ctxt, int flags ); + int (*checksec) ( const MDAL_CTXT ctxt, unsigned int flags ); // Namespace Functions diff --git a/src/mdal/posix_mdal.c b/src/mdal/posix_mdal.c index e7967a02..bf60c3b5 100644 --- a/src/mdal/posix_mdal.c +++ b/src/mdal/posix_mdal.c @@ -356,7 +356,7 @@ int posixmdal_cleanup( MDAL mdal ) { * matches current user if true) * @return int : A count of uncorrected security issues, or -1 if a failure occurred */ -int posixmdal_checksec( const MDAL_CTXT ctxt, int flags ) { +int posixmdal_checksec( const MDAL_CTXT ctxt, unsigned int flags ) { int fix = flags & CFG_FIX; int check_uid = flags & CFG_OWNERCHECK; diff --git a/src/rsrc_mgr/new_rsrc_mgr.c b/src/rsrc_mgr/new_rsrc_mgr.c index 0b7f2ade..b8241a06 100644 --- a/src/rsrc_mgr/new_rsrc_mgr.c +++ b/src/rsrc_mgr/new_rsrc_mgr.c @@ -1490,7 +1490,7 @@ int main(int argc, char** argv) { } if (config_v) { - int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; + unsigned int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; if (config_verify(cfg, ".", flags)) { fprintf(stderr, OUTPREFX "Rank %d: Failed to verify config: %s\n", rank, strerror(errno)); config_term(cfg); diff --git a/src/rsrc_mgr/rsrc_mgr.c b/src/rsrc_mgr/rsrc_mgr.c index 4ea83f6c..77f84c05 100644 --- a/src/rsrc_mgr/rsrc_mgr.c +++ b/src/rsrc_mgr/rsrc_mgr.c @@ -1478,7 +1478,7 @@ int main(int argc, char** argv) { } if (config_v) { - int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; + unsigned int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; if (config_verify(cfg, ".", flags)) { fprintf(stderr, OUTPREFX "Rank %d: Failed to verify config: %s\n", rank, strerror(errno)); config_term(cfg); diff --git a/src/rsrc_mgr/testing/test_resourcelog.c b/src/rsrc_mgr/testing/test_resourcelog.c index 1047be80..d6d57f2c 100644 --- a/src/rsrc_mgr/testing/test_resourcelog.c +++ b/src/rsrc_mgr/testing/test_resourcelog.c @@ -140,7 +140,7 @@ int main(int argc, char **argv) printf( "failed to initalize marfs config\n" ); return -1; } - int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; + unsigned int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; if ( config_verify(config,"/campaign/",flags) ) { printf( "Config validation failure\n" ); return -1; diff --git a/src/rsrc_mgr/testing/test_resourceprocessing.c b/src/rsrc_mgr/testing/test_resourceprocessing.c index aa6495bf..2564579d 100644 --- a/src/rsrc_mgr/testing/test_resourceprocessing.c +++ b/src/rsrc_mgr/testing/test_resourceprocessing.c @@ -154,7 +154,7 @@ int main(int argc, char **argv) } // create all namespaces associated with the config - int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; + unsigned int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; if ( config_verify( config, "./.", flags ) ) { printf( "Failed to validate the marfs config\n" ); return -1; diff --git a/src/rsrc_mgr/testing/test_resourcethreads.c b/src/rsrc_mgr/testing/test_resourcethreads.c index af5ffbf1..aa179227 100644 --- a/src/rsrc_mgr/testing/test_resourcethreads.c +++ b/src/rsrc_mgr/testing/test_resourcethreads.c @@ -158,7 +158,7 @@ int main(int argc, char **argv) } // create all namespaces associated with the config - int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; + unsigned int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; if ( config_verify( config, "./.", flags ) ) { printf( "Failed to validate the marfs config\n" ); return -1; diff --git a/src/rsrc_mgr/testing/test_rsrc_mgr.c b/src/rsrc_mgr/testing/test_rsrc_mgr.c index 71ef4c0d..b387b6e5 100644 --- a/src/rsrc_mgr/testing/test_rsrc_mgr.c +++ b/src/rsrc_mgr/testing/test_rsrc_mgr.c @@ -98,7 +98,7 @@ int main(int argc, char** argv) { } // create all namespaces associated with the config - int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; + unsigned int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; if (config_verify(config, "/campaign", flags)) { printf("Failed to validate the marfs config\n"); return -1; diff --git a/src/rsrc_mgr/testing/test_rsrc_mgr_nopack.c b/src/rsrc_mgr/testing/test_rsrc_mgr_nopack.c index fa8ab4b0..af2d5226 100644 --- a/src/rsrc_mgr/testing/test_rsrc_mgr_nopack.c +++ b/src/rsrc_mgr/testing/test_rsrc_mgr_nopack.c @@ -99,7 +99,7 @@ int main(int argc, char** argv) { } // create all namespaces associated with the config - int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; + unsigned int flags = CFG_FIX | CFG_OWNERCHECK | CFG_MDALCHECK | CFG_DALCHECK | CFG_RECURSE; if (config_verify(config, ".././campaign", flags)) { printf("Failed to validate the marfs config\n"); return -1; From 401855a1d4da20c48624b214c130ab33096fbb00 Mon Sep 17 00:00:00 2001 From: Thomas Bertschinger Date: Thu, 23 May 2024 14:10:05 -0600 Subject: [PATCH 2/5] switch gitignore from allowlist style to denylist style This makes it easier to catch all new files when adding new code such as the new Rust code. --- .gitignore | 239 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 145 insertions(+), 94 deletions(-) diff --git a/.gitignore b/.gitignore index 9dc81949..1bcf52de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,5 @@ <<<<<<< HEAD ### # pattern "*", even when followed by "!*/", was hiding sockets/marfs_obj (IGNORING: isn't that path in erasureUtils?) -* -*.* !*/ !*.c @@ -50,103 +48,118 @@ install-sh missing stamp-h1 +*.trs +*.deps +*.libs +libtool + +.dirstamp + +### Rust ### +debug/ +target/ + +# These are backup files generated by rustfmt +**/*.rs.bk + +tags # Created by https://www.gitignore.io/api/c,macos,python,autotools # KEPT FOR FUTURE REFERENCE # Edit at https://www.gitignore.io/?templates=c,macos,python,autotools # -# ### Autotools ### -# # http://www.gnu.org/software/automake -# -# Makefile.in -# /ar-lib -# /mdate-sh -# /py-compile -# /test-driver -# /ylwrap -# -# # http://www.gnu.org/software/autoconf -# -# autom4te.cache -# /autoscan.log -# /autoscan-*.log -# /aclocal.m4 -# /compile -# /config.guess -# /config.h.in -# /config.log -# /config.status -# /config.sub -# /configure -# /configure.scan -# /depcomp -# /install-sh -# /missing -# /stamp-h1 -# -# # https://www.gnu.org/software/libtool/ -# -# /ltmain.sh -# -# # http://www.gnu.org/software/texinfo -# -# /texinfo.tex -# -# # http://www.gnu.org/software/m4/ -# -# m4/libtool.m4 -# m4/ltoptions.m4 -# m4/ltsugar.m4 -# m4/ltversion.m4 -# m4/lt~obsolete.m4 -# -# ### Autotools Patch ### -# -# ### C ### -# # Prerequisites -# *.d -# -# # Object files -# *.o -# *.ko -# *.obj -# *.elf -# -# # Linker output -# *.ilk -# *.map -# *.exp -# -# # Precompiled Headers -# *.gch -# *.pch -# -# # Libraries -# *.lib -# *.a -# *.la -# *.lo -# -# # Shared objects (inc. Windows DLLs) -# *.dll -# *.so -# *.so.* -# *.dylib -# -# # Executables -# *.exe -# *.out -# *.app -# *.i*86 -# *.x86_64 -# *.hex -# -# # Debug files -# *.dSYM/ -# *.su -# *.idb -# *.pdb -# +### Autotools ### +# http://www.gnu.org/software/automake + +Makefile.in +ar-lib +/mdate-sh +/py-compile +/test-driver +/ylwrap + +# http://www.gnu.org/software/autoconf + +autom4te.cache +/autoscan.log +/autoscan-*.log +/aclocal.m4 +/compile +/config.guess +/config.h.in +/config.log +/config.status +/config.sub +/configure +/configure.scan +/depcomp +/install-sh +/missing +/stamp-h1 + +# https://www.gnu.org/software/libtool/ + +/ltmain.sh + +# http://www.gnu.org/software/texinfo + +/texinfo.tex + +# http://www.gnu.org/software/m4/ + +m4/libtool.m4 +m4/ltoptions.m4 +m4/ltsugar.m4 +m4/ltversion.m4 +m4/lt~obsolete.m4 + +### Autotools Patch ### + +### C ### +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + # # Kernel Module Compile Results # *.mod* # *.cmd @@ -289,3 +302,41 @@ stamp-h1 # .pyre/ # End of https://www.gitignore.io/api/c,macos,python,autotools +# marfs executables +marfs-verifyconf +dalverify +emerg_reb +test_dal +test_dal_abort +test_dal_fuzzing +test_dal_fuzzing_put +test_dal_migrate +test_dal_noop +test_dal_oflags +test_dal_timer +test_dal_timer_abort +test_dal_timer_migrate +test_dal_verify +marfs-streamutil +marfs-streamwalker +marfs-fuse +test_ioqueue +test_iothreads +marfs_auto_config.h.in +erasurePerf +neutil +test_libne_fuzzing +test_libne_io +test_libne_noop +test_libne_seek +test_libne_timer +wrkdir_errasureTest +marfs-rman +test_threadqueue +test_threadqueue_enqueue +test_threadqueue_getflags +test_threadqueue_getopts +test_threadqueue_mastercons +test_threadqueue_masterprod +test_threadqueue_nocons +test_threadqueue_noprod From 0390a1dd785f353d5362ad8cb3bfad75ba50aca2 Mon Sep 17 00:00:00 2001 From: Thomas Bertschinger Date: Thu, 23 May 2024 14:12:40 -0600 Subject: [PATCH 3/5] add Rust wrappers for config types/functions The purpose of these Rust wrappers is to create an API for the marfs config that does not expose pthread_mutex_t to the Rust side. --- src/config/config.c | 39 +++++++++++++++++++++++++++++++++++++++ src/config/config.h | 10 +++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/config/config.c b/src/config/config.c index 60081a2c..032087ab 100644 --- a/src/config/config.c +++ b/src/config/config.c @@ -2838,6 +2838,30 @@ marfs_config* config_init( const char* cpath, pthread_mutex_t* erasurelock ) { return config; } +/** + * Initialize memory structures based on the given config file + * @param const char* cpath : Path of the config file to be parsed + * @return marfs_config_rust_wrapper : newly populated config + * + * On error, the marfs_config* field of marfs_config_rust_wrapper + * will be NULL + */ +marfs_config_rust_wrapper config_init_rust_helper( const char* cpath ) { + marfs_config_rust_wrapper c; + c.config = NULL; + + if ( pthread_mutex_init( &c.erasureLock, NULL ) ) { + LOG( LOG_ERR, "ERROR: failed to initialize erasure lock\n" ); + return c; + } + + marfs_config* config = config_init(cpath, &c.erasureLock); + + c.config = config; + + return c; +} + /** * Destroy the given config structures * @param marfs_config* config : Reference to the config to be destroyed @@ -2867,6 +2891,21 @@ int config_term( marfs_config* config ) { return retval; } +/** + * Destroy the given config structures + * @param marfs_config* config : Reference to the config to be destroyed + * @return int : Zero on success, or -1 on failure + */ +int config_term_rust_helper( marfs_config_rust_wrapper c ) { + pthread_mutex_destroy(&c.erasureLock); + + if (c.config) { + return config_term( c.config ); + } + + return 0; +} + /** * Duplicate the reference to a given NS * @param marfs_ns* ns : NS ref to duplicate diff --git a/src/config/config.h b/src/config/config.h index a1c33510..e5d5fc8a 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -139,6 +139,11 @@ typedef struct marfs_config_struct { marfs_repo* repolist; } marfs_config; +typedef struct { + marfs_config *config; + pthread_mutex_t erasureLock; +} marfs_config_rust_wrapper; + typedef struct marfs_position_struct { marfs_ns* ns; unsigned int depth; @@ -146,7 +151,7 @@ typedef struct marfs_position_struct { } marfs_position; // flags for config_verify -enum { +enum config_flags { CFG_FIX = 0x1, // fix problems found with the config CFG_OWNERCHECK = 0x2, // check owner of MDAL "security directory" CFG_MDALCHECK = 0x4, // check MDAL @@ -169,6 +174,9 @@ marfs_config* config_init( const char* cpath, pthread_mutex_t* erasurelock ); */ int config_term( marfs_config* config ); +marfs_config_rust_wrapper config_init_rust_helper( const char* cpath ); +int config_term_rust_helper( marfs_config_rust_wrapper config ); + /** * Duplicate the reference to a given NS * @param marfs_ns* ns : NS ref to duplicate From 71edfe12814dc590363a32c87dd2503285929919 Mon Sep 17 00:00:00 2001 From: Thomas Bertschinger Date: Thu, 23 May 2024 14:14:05 -0600 Subject: [PATCH 4/5] designate some non-public functions as 'static' These functions end up being defined in multiple object files. Those object files get linked together into the Rust binary that statically links various MarFS libraries. This resulted in the linker giving "multiple definition" errors for these symbols. Designate these functions 'static' so that they are not defined in multiple shared object files. --- src/dal/noop_dal.c | 4 ++-- src/dal/posix_dal.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dal/noop_dal.c b/src/dal/noop_dal.c index dccdfcd1..695ffff9 100644 --- a/src/dal/noop_dal.c +++ b/src/dal/noop_dal.c @@ -110,7 +110,7 @@ typedef struct noop_block_context_struct * @param xmlNode* node : Node to be parsed * @return int : Zero on success, -1 on error */ -int parse_int_node( int* target, xmlNode* node ) { +static int parse_int_node( int* target, xmlNode* node ) { // check for an included value if ( node->children != NULL && node->children->type == XML_TEXT_NODE && @@ -142,7 +142,7 @@ int parse_int_node( int* target, xmlNode* node ) { * @param xmlNode* node : Node to be parsed * @return int : Zero on success, -1 on error */ -int parse_size_node( ssize_t* target, xmlNode* node ) { +static int parse_size_node( ssize_t* target, xmlNode* node ) { // check for unexpected node format if ( node->children == NULL || node->children->type != XML_TEXT_NODE ) { LOG( LOG_ERR, "unexpected format of size node: \"%s\"\n", (char*)node->name ); diff --git a/src/dal/posix_dal.c b/src/dal/posix_dal.c index 3d69b334..02c4334f 100644 --- a/src/dal/posix_dal.c +++ b/src/dal/posix_dal.c @@ -641,7 +641,7 @@ int tgtMatch(DAL_location* loc, POSIX_REBUILD_LOC tgt) { * @param const char* string : String to hash * @return uint64_t : hash of the string */ -uint64_t polyhash(const char* string) { +static uint64_t polyhash(const char* string) { // According to http://www.cse.yorku.ca/~oz/hash.html // 33 is a magical number that inexplicably works the best. const int salt = 33; @@ -659,7 +659,7 @@ uint64_t polyhash(const char* string) { * @param uint64_t a : second value to hash * @return uint64_t : hash of the two values */ -uint64_t h_a(const uint64_t key, uint64_t a) { +static uint64_t h_a(const uint64_t key, uint64_t a) { return ((a * key) >> 32); } From 8dd852e14c424cce264c80ba2bac4744ac40f419 Mon Sep 17 00:00:00 2001 From: Thomas Bertschinger Date: Thu, 23 May 2024 14:24:00 -0600 Subject: [PATCH 5/5] Initial Rust implementation of config verify command This is an initial work-in-progress config verify command that demonstrates the use of Rust bindings to call the C MarFS functions from Rust code. --- rust_src/Cargo.lock | 373 +++++++++++++++++++++++++++++++++++++ rust_src/Cargo.toml | 68 +++++++ rust_src/bindgen_wrapper.h | 60 ++++++ rust_src/build.rs | 98 ++++++++++ rust_src/src/c.rs | 64 +++++++ rust_src/src/config.rs | 112 +++++++++++ rust_src/src/main.rs | 73 ++++++++ 7 files changed, 848 insertions(+) create mode 100644 rust_src/Cargo.lock create mode 100644 rust_src/Cargo.toml create mode 100644 rust_src/bindgen_wrapper.h create mode 100644 rust_src/build.rs create mode 100644 rust_src/src/c.rs create mode 100644 rust_src/src/config.rs create mode 100644 rust_src/src/main.rs diff --git a/rust_src/Cargo.lock b/rust_src/Cargo.lock new file mode 100644 index 00000000..1532e4dc --- /dev/null +++ b/rust_src/Cargo.lock @@ -0,0 +1,373 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" + +[[package]] +name = "bindgen" +version = "0.69.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "itertools", + "lazy_static", + "lazycell", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", + "which", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clang-sys" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "either" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "libloading" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" +dependencies = [ + "cfg-if", + "windows-targets", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "marfs" +version = "0.1.0" +dependencies = [ + "anyhow", + "bindgen", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "prettyplease" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "syn" +version = "2.0.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/rust_src/Cargo.toml b/rust_src/Cargo.toml new file mode 100644 index 00000000..ebf9c5c5 --- /dev/null +++ b/rust_src/Cargo.toml @@ -0,0 +1,68 @@ +# Copyright (c) 2015, Los Alamos National Security, LLC +# All rights reserved. +# +# Copyright 2015. Los Alamos National Security, LLC. This software was +# produced under U.S. Government contract DE-AC52-06NA25396 for Los +# Alamos National Laboratory (LANL), which is operated by Los Alamos +# National Security, LLC for the U.S. Department of Energy. The +# U.S. Government has rights to use, reproduce, and distribute this +# software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, +# LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY +# FOR THE USE OF THIS SOFTWARE. If software is modified to produce +# derivative works, such modified software should be clearly marked, so +# as not to confuse it with the version available from LANL. +# +# Additionally, redistribution and use in source and binary forms, with +# or without modification, are permitted provided that the following +# conditions are met: 1. Redistributions of source code must retain the +# above copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of Los Alamos National Security, LLC, Los Alamos +# National Laboratory, LANL, the U.S. Government, nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND +# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, +# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS +# ALAMOS NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# ----- +# NOTE: +# ----- +# MarFS is released under the BSD license. +# +# MarFS was reviewed and released by LANL under Los Alamos Computer Code +# identifier: LA-CC-15-039. +# +# MarFS uses libaws4c for Amazon S3 object communication. The original version +# is at https://aws.amazon.com/code/Amazon-S3/2601 and under the LGPL license. +# LANL added functionality to the original work. The original work plus +# LANL contributions is found at https://github.com/jti-lanl/aws4c. +# +# GNU licenses can be found at http://www.gnu.org/licenses/. + +[package] +name = "marfs" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1.0.86" + +[build-dependencies] +bindgen = "0.69.4" diff --git a/rust_src/bindgen_wrapper.h b/rust_src/bindgen_wrapper.h new file mode 100644 index 00000000..0767c8b9 --- /dev/null +++ b/rust_src/bindgen_wrapper.h @@ -0,0 +1,60 @@ +/* +Copyright (c) 2015, Los Alamos National Security, LLC +All rights reserved. + +Copyright 2015. Los Alamos National Security, LLC. This software was +produced under U.S. Government contract DE-AC52-06NA25396 for Los +Alamos National Laboratory (LANL), which is operated by Los Alamos +National Security, LLC for the U.S. Department of Energy. The +U.S. Government has rights to use, reproduce, and distribute this +software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, +LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY +FOR THE USE OF THIS SOFTWARE. If software is modified to produce +derivative works, such modified software should be clearly marked, so +as not to confuse it with the version available from LANL. + +Additionally, redistribution and use in source and binary forms, with +or without modification, are permitted provided that the following +conditions are met: 1. Redistributions of source code must retain the +above copyright notice, this list of conditions and the following +disclaimer. + +2. Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +3. Neither the name of Los Alamos National Security, LLC, Los Alamos +National Laboratory, LANL, the U.S. Government, nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS +ALAMOS NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +----- +NOTE: +----- +MarFS is released under the BSD license. + +MarFS was reviewed and released by LANL under Los Alamos Computer Code +identifier: LA-CC-15-039. + +MarFS uses libaws4c for Amazon S3 object communication. The original version +is at https://aws.amazon.com/code/Amazon-S3/2601 and under the LGPL license. +LANL added functionality to the original work. The original work plus +LANL contributions is found at https://github.com/jti-lanl/aws4c. + +GNU licenses can be found at http://www.gnu.org/licenses/. +*/ + +/* Include headers that should have Rust bindings generated. */ +#include "config/config.h" diff --git a/rust_src/build.rs b/rust_src/build.rs new file mode 100644 index 00000000..8935d873 --- /dev/null +++ b/rust_src/build.rs @@ -0,0 +1,98 @@ +/* +Copyright (c) 2015, Los Alamos National Security, LLC +All rights reserved. + +Copyright 2015. Los Alamos National Security, LLC. This software was +produced under U.S. Government contract DE-AC52-06NA25396 for Los +Alamos National Laboratory (LANL), which is operated by Los Alamos +National Security, LLC for the U.S. Department of Energy. The +U.S. Government has rights to use, reproduce, and distribute this +software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, +LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY +FOR THE USE OF THIS SOFTWARE. If software is modified to produce +derivative works, such modified software should be clearly marked, so +as not to confuse it with the version available from LANL. + +Additionally, redistribution and use in source and binary forms, with +or without modification, are permitted provided that the following +conditions are met: 1. Redistributions of source code must retain the +above copyright notice, this list of conditions and the following +disclaimer. + +2. Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +3. Neither the name of Los Alamos National Security, LLC, Los Alamos +National Laboratory, LANL, the U.S. Government, nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS +ALAMOS NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +----- +NOTE: +----- +MarFS is released under the BSD license. + +MarFS was reviewed and released by LANL under Los Alamos Computer Code +identifier: LA-CC-15-039. + +MarFS uses libaws4c for Amazon S3 object communication. The original version +is at https://aws.amazon.com/code/Amazon-S3/2601 and under the LGPL license. +LANL added functionality to the original work. The original work plus +LANL contributions is found at https://github.com/jti-lanl/aws4c. + +GNU licenses can be found at http://www.gnu.org/licenses/. +*/ + +use std::env; +use std::path::PathBuf; + +fn main() { + println!("cargo:rustc-link-search=../src"); + + println!("cargo:rustc-link-search=../src/config/.libs"); + println!("cargo:rustc-link-lib=static=Config"); + + println!("cargo:rustc-link-search=../src/logging/.libs"); + println!("cargo:rustc-link-lib=static=logging"); + + println!("cargo:rustc-link-search=../src/ne/.libs"); + println!("cargo:rustc-link-lib=static=ne"); + + println!("cargo:rustc-link-search=../src/thread_queue/.libs"); + println!("cargo:rustc-link-lib=static=TQ"); + + println!("cargo:rustc-link-lib=xml2"); + println!("cargo:rustc-link-lib=isal"); + + let bindings = bindgen::Builder::default() + .header("bindgen_wrapper.h") + .clang_arg("-I../src") + .clang_arg("-I/usr/include/libxml2") + // Tell cargo to invalidate the built crate whenever any of the + // included header files changed. + .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) + .allowlist_type("marfs_.*") + .allowlist_type("CFG_.*") + .allowlist_type("config_.*") + .allowlist_function("config_.*") + .generate() + .expect("Unable to generate bindings"); + + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect("Couldn't write bindings!"); +} diff --git a/rust_src/src/c.rs b/rust_src/src/c.rs new file mode 100644 index 00000000..3caccfb7 --- /dev/null +++ b/rust_src/src/c.rs @@ -0,0 +1,64 @@ +/* +Copyright (c) 2015, Los Alamos National Security, LLC +All rights reserved. + +Copyright 2015. Los Alamos National Security, LLC. This software was +produced under U.S. Government contract DE-AC52-06NA25396 for Los +Alamos National Laboratory (LANL), which is operated by Los Alamos +National Security, LLC for the U.S. Department of Energy. The +U.S. Government has rights to use, reproduce, and distribute this +software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, +LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY +FOR THE USE OF THIS SOFTWARE. If software is modified to produce +derivative works, such modified software should be clearly marked, so +as not to confuse it with the version available from LANL. + +Additionally, redistribution and use in source and binary forms, with +or without modification, are permitted provided that the following +conditions are met: 1. Redistributions of source code must retain the +above copyright notice, this list of conditions and the following +disclaimer. + +2. Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +3. Neither the name of Los Alamos National Security, LLC, Los Alamos +National Laboratory, LANL, the U.S. Government, nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS +ALAMOS NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +----- +NOTE: +----- +MarFS is released under the BSD license. + +MarFS was reviewed and released by LANL under Los Alamos Computer Code +identifier: LA-CC-15-039. + +MarFS uses libaws4c for Amazon S3 object communication. The original version +is at https://aws.amazon.com/code/Amazon-S3/2601 and under the LGPL license. +LANL added functionality to the original work. The original work plus +LANL contributions is found at https://github.com/jti-lanl/aws4c. + +GNU licenses can be found at http://www.gnu.org/licenses/. +*/ + +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(dead_code)] + +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); diff --git a/rust_src/src/config.rs b/rust_src/src/config.rs new file mode 100644 index 00000000..87e2a7e0 --- /dev/null +++ b/rust_src/src/config.rs @@ -0,0 +1,112 @@ +/* +Copyright (c) 2015, Los Alamos National Security, LLC +All rights reserved. + +Copyright 2015. Los Alamos National Security, LLC. This software was +produced under U.S. Government contract DE-AC52-06NA25396 for Los +Alamos National Laboratory (LANL), which is operated by Los Alamos +National Security, LLC for the U.S. Department of Energy. The +U.S. Government has rights to use, reproduce, and distribute this +software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, +LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY +FOR THE USE OF THIS SOFTWARE. If software is modified to produce +derivative works, such modified software should be clearly marked, so +as not to confuse it with the version available from LANL. + +Additionally, redistribution and use in source and binary forms, with +or without modification, are permitted provided that the following +conditions are met: 1. Redistributions of source code must retain the +above copyright notice, this list of conditions and the following +disclaimer. + +2. Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +3. Neither the name of Los Alamos National Security, LLC, Los Alamos +National Laboratory, LANL, the U.S. Government, nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS +ALAMOS NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +----- +NOTE: +----- +MarFS is released under the BSD license. + +MarFS was reviewed and released by LANL under Los Alamos Computer Code +identifier: LA-CC-15-039. + +MarFS uses libaws4c for Amazon S3 object communication. The original version +is at https://aws.amazon.com/code/Amazon-S3/2601 and under the LGPL license. +LANL added functionality to the original work. The original work plus +LANL contributions is found at https://github.com/jti-lanl/aws4c. + +GNU licenses can be found at http://www.gnu.org/licenses/. +*/ + +use std::ffi::CString; +use std::os::raw::c_char; + +use anyhow::{anyhow, Result}; + +use crate::c; + +pub struct MarfsConfig { + raw: c::marfs_config_rust_wrapper, +} + +impl MarfsConfig { + pub fn new(path: &str) -> Result { + let path = CString::new(path).unwrap(); + let path: *const c_char = path.as_ptr(); + + let raw = unsafe { c::config_init_rust_helper(path) }; + + if raw.config.is_null() { + Err(anyhow!("Failed to initialize config")) + } else { + Ok(MarfsConfig { raw }) + } + } + + pub fn verify(&self) -> Result<()> { + println!("config verify"); + + let ns_path = CString::new(".").unwrap(); + let ns_path: *const c_char = ns_path.as_ptr(); + + let flags = c::config_flags_CFG_FIX + & c::config_flags_CFG_MDALCHECK + & c::config_flags_CFG_DALCHECK + & c::config_flags_CFG_RECURSE; + + let res = unsafe { c::config_verify(self.raw.config, ns_path, flags) }; + + if res == 0 { + Ok(()) + } else { + Err(anyhow!("Failed to verify config")) + } + } +} + +impl Drop for MarfsConfig { + fn drop(&mut self) { + println!("config term"); + unsafe { + c::config_term_rust_helper(self.raw); + } + } +} diff --git a/rust_src/src/main.rs b/rust_src/src/main.rs new file mode 100644 index 00000000..f44d9036 --- /dev/null +++ b/rust_src/src/main.rs @@ -0,0 +1,73 @@ +/* +Copyright (c) 2015, Los Alamos National Security, LLC +All rights reserved. + +Copyright 2015. Los Alamos National Security, LLC. This software was +produced under U.S. Government contract DE-AC52-06NA25396 for Los +Alamos National Laboratory (LANL), which is operated by Los Alamos +National Security, LLC for the U.S. Department of Energy. The +U.S. Government has rights to use, reproduce, and distribute this +software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, +LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY +FOR THE USE OF THIS SOFTWARE. If software is modified to produce +derivative works, such modified software should be clearly marked, so +as not to confuse it with the version available from LANL. + +Additionally, redistribution and use in source and binary forms, with +or without modification, are permitted provided that the following +conditions are met: 1. Redistributions of source code must retain the +above copyright notice, this list of conditions and the following +disclaimer. + +2. Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +3. Neither the name of Los Alamos National Security, LLC, Los Alamos +National Laboratory, LANL, the U.S. Government, nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS +ALAMOS NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +----- +NOTE: +----- +MarFS is released under the BSD license. + +MarFS was reviewed and released by LANL under Los Alamos Computer Code +identifier: LA-CC-15-039. + +MarFS uses libaws4c for Amazon S3 object communication. The original version +is at https://aws.amazon.com/code/Amazon-S3/2601 and under the LGPL license. +LANL added functionality to the original work. The original work plus +LANL contributions is found at https://github.com/jti-lanl/aws4c. + +GNU licenses can be found at http://www.gnu.org/licenses/. +*/ + +use anyhow::Result; +use std::env; + +pub mod c; +pub mod config; + +fn main() -> Result<()> { + let args: Vec = env::args().collect(); + + let config = config::MarfsConfig::new(&args[1])?; + + config.verify()?; + + Ok(()) +}