From bbcccd6e9816ebb16ca33d2003d563b24625a053 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Fri, 21 May 2021 23:34:31 +0900 Subject: [PATCH] Make storage class a string (#1663) This allows non-standard storage classes like Google Cloud Storage Nearline. Fixes #1613. --- src/curl.cpp | 18 +++++++------- src/curl.h | 6 ++--- src/s3fs.cpp | 13 +++------- src/types.h | 70 ---------------------------------------------------- 4 files changed, 16 insertions(+), 91 deletions(-) diff --git a/src/curl.cpp b/src/curl.cpp index 43829a8..79a64bc 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -94,7 +94,7 @@ time_t S3fsCurl::readwrite_timeout = 120; // default int S3fsCurl::retries = 5; // default bool S3fsCurl::is_public_bucket = false; acl_t S3fsCurl::default_acl = acl_t::PRIVATE; -storage_class_t S3fsCurl::storage_class = storage_class_t::STANDARD; +std::string S3fsCurl::storage_class = "STANDARD"; sseckeylist_t S3fsCurl::sseckeys; std::string S3fsCurl::ssekmsid; sse_type_t S3fsCurl::ssetype = sse_type_t::SSE_DISABLE; @@ -774,9 +774,9 @@ acl_t S3fsCurl::GetDefaultAcl() return S3fsCurl::default_acl; } -storage_class_t S3fsCurl::SetStorageClass(storage_class_t storage_class) +std::string S3fsCurl::SetStorageClass(const std::string& storage_class) { - storage_class_t old = S3fsCurl::storage_class; + std::string old = S3fsCurl::storage_class; S3fsCurl::storage_class = storage_class; return old; } @@ -3138,8 +3138,8 @@ int S3fsCurl::PutHeadRequest(const char* tpath, headers_t& meta, bool is_copy) if(S3fsCurl::default_acl != acl_t::PRIVATE){ requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-acl", S3fsCurl::default_acl.str()); } - if(GetStorageClass() != storage_class_t::STANDARD){ - requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", GetStorageClass().str()); + if(strcasecmp(GetStorageClass().c_str(), "STANDARD") != 0){ + requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", GetStorageClass().c_str()); } // SSE if(!is_copy){ @@ -3248,8 +3248,8 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd) if(S3fsCurl::default_acl != acl_t::PRIVATE){ requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-acl", S3fsCurl::default_acl.str()); } - if(GetStorageClass() != storage_class_t::STANDARD){ - requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", GetStorageClass().str()); + if(strcasecmp(GetStorageClass().c_str(), "STANDARD") != 0){ + requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", GetStorageClass().c_str()); } // SSE std::string ssevalue; @@ -3514,8 +3514,8 @@ int S3fsCurl::PreMultipartPostRequest(const char* tpath, headers_t& meta, std::s if(S3fsCurl::default_acl != acl_t::PRIVATE){ requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-acl", S3fsCurl::default_acl.str()); } - if(GetStorageClass() != storage_class_t::STANDARD){ - requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", GetStorageClass().str()); + if(strcasecmp(GetStorageClass().c_str(), "STANDARD") != 0){ + requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", GetStorageClass().c_str()); } // SSE if(!is_copy){ diff --git a/src/curl.h b/src/curl.h index 3076a72..f45fbea 100644 --- a/src/curl.h +++ b/src/curl.h @@ -127,7 +127,7 @@ class S3fsCurl static int retries; static bool is_public_bucket; static acl_t default_acl; - static storage_class_t storage_class; + static std::string storage_class; static sseckeylist_t sseckeys; static std::string ssekmsid; static sse_type_t ssetype; @@ -303,8 +303,8 @@ class S3fsCurl static bool IsPublicBucket() { return S3fsCurl::is_public_bucket; } static acl_t SetDefaultAcl(acl_t acl); static acl_t GetDefaultAcl(); - static storage_class_t SetStorageClass(storage_class_t storage_class); - static storage_class_t GetStorageClass() { return S3fsCurl::storage_class; } + static std::string SetStorageClass(const std::string& storage_class); + static std::string GetStorageClass() { return S3fsCurl::storage_class; } static bool LoadEnvSse() { return (S3fsCurl::LoadEnvSseCKeys() && S3fsCurl::LoadEnvSseKmsid()); } static sse_type_t SetSseType(sse_type_t type); static sse_type_t GetSseType() { return S3fsCurl::ssetype; } diff --git a/src/s3fs.cpp b/src/s3fs.cpp index a441405..1132444 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -4296,9 +4296,9 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar rrs = cvt_strtoofft(strchr(arg, '=') + sizeof(char)); } if(0 == rrs){ - S3fsCurl::SetStorageClass(storage_class_t::STANDARD); + S3fsCurl::SetStorageClass("STANDARD"); }else if(1 == rrs){ - S3fsCurl::SetStorageClass(storage_class_t::REDUCED_REDUNDANCY); + S3fsCurl::SetStorageClass("REDUCED_REDUNDANCY"); }else{ S3FS_PRN_EXIT("poorly formed argument to option: use_rrs"); return -1; @@ -4306,12 +4306,7 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar return 0; } if(is_prefix(arg, "storage_class=")){ - const char *storage_class_str = strchr(arg, '=') + sizeof(char); - storage_class_t storage_class = storage_class_t::from_str(storage_class_str); - if(storage_class == storage_class_t::UNKNOWN){ - S3FS_PRN_EXIT("unknown value for storage_class: %s", storage_class_str); - return -1; - } + const char *storage_class = strchr(arg, '=') + sizeof(char); S3fsCurl::SetStorageClass(storage_class); return 0; } @@ -5023,7 +5018,7 @@ int main(int argc, char* argv[]) // [NOTE] // exclusive option check here. // - if(storage_class_t::REDUCED_REDUNDANCY == S3fsCurl::GetStorageClass() && !S3fsCurl::IsSseDisable()){ + if(strcasecmp(S3fsCurl::GetStorageClass().c_str(), "REDUCED_REDUNDANCY") == 0 && !S3fsCurl::IsSseDisable()){ S3FS_PRN_EXIT("use_sse option could not be specified with storage class reduced_redundancy."); S3fsCurl::DestroyS3fsCurl(); s3fs_destroy_global_ssl(); diff --git a/src/types.h b/src/types.h index ca4f2b4..5be183b 100644 --- a/src/types.h +++ b/src/types.h @@ -67,76 +67,6 @@ typedef struct xattr_value typedef std::map xattrs_t; -//------------------------------------------------------------------- -// storage_class_t -//------------------------------------------------------------------- -class storage_class_t{ - public: - enum Value{ - STANDARD, - STANDARD_IA, - ONEZONE_IA, - REDUCED_REDUNDANCY, - INTELLIGENT_TIERING, - GLACIER, - DEEP_ARCHIVE, - UNKNOWN - }; - - // cppcheck-suppress noExplicitConstructor - storage_class_t(Value value) : value_(value) {} - - operator Value() const { return value_; } - - const char* str() const - { - switch(value_){ - case STANDARD: - return "STANDARD"; - case STANDARD_IA: - return "STANDARD_IA"; - case ONEZONE_IA: - return "ONEZONE_IA"; - case REDUCED_REDUNDANCY: - return "REDUCED_REDUNDANCY"; - case INTELLIGENT_TIERING: - return "INTELLIGENT_TIERING"; - case GLACIER: - return "GLACIER"; - case DEEP_ARCHIVE: - return "DEEP_ARCHIVE"; - case UNKNOWN: - return NULL; - } - abort(); - } - - static storage_class_t from_str(const char* str) - { - if(0 == strcmp(str, "standard")){ - return STANDARD; - }else if(0 == strcmp(str, "standard_ia")){ - return STANDARD_IA; - }else if(0 == strcmp(str, "onezone_ia")){ - return ONEZONE_IA; - }else if(0 == strcmp(str, "reduced_redundancy")){ - return REDUCED_REDUNDANCY; - }else if(0 == strcmp(str, "intelligent_tiering")){ - return INTELLIGENT_TIERING; - }else if(0 == strcmp(str, "glacier")){ - return GLACIER; - }else if(0 == strcmp(str, "deep_archive")){ - return DEEP_ARCHIVE; - }else{ - return UNKNOWN; - } - } - - private: - OPERATOR_EXPLICIT operator bool(); - Value value_; -}; - //------------------------------------------------------------------- // acl_t //-------------------------------------------------------------------