diff --git a/src/cache.cpp b/src/cache.cpp index 18c6bd4..7deddde 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -147,12 +148,12 @@ bool StatCache::GetStat(string& key, struct stat* pst, headers_t* meta, bool ove } if(is_delete_cache){ // not hit by different ETag - FGPRINT(" stat cache not hit by ETag[path=%s][time=%ld][hit count=%lu][ETag(%s)!=(%s)]\n", + DPRNNN("stat cache not hit by ETag[path=%s][time=%ld][hit count=%lu][ETag(%s)!=(%s)]", strpath.c_str(), (*iter).second.cache_date, (*iter).second.hit_count, petag ? petag : "null", (*iter).second.meta["ETag"].c_str()); }else{ // hit - FGPRINT(" stat cache hit [path=%s] [time=%ld] [hit count=%lu]\n", + DPRNNN("stat cache hit [path=%s] [time=%ld] [hit count=%lu]", strpath.c_str(), (*iter).second.cache_date, (*iter).second.hit_count); if(pst!= NULL){ @@ -229,7 +230,7 @@ bool StatCache::AddStat(std::string& key, headers_t& meta, bool forcedir) if(CacheSize< 1){ return true; } - FGPRINT(" add_stat_cache_entry[path=%s]\n", key.c_str()); + DPRNNN("add stat cache entry[path=%s]", key.c_str()); if(stat_cache.size() > CacheSize){ if(!TruncateCache()){ @@ -284,7 +285,7 @@ bool StatCache::AddNoObjectCache(string& key) if(CacheSize < 1){ return true; } - FGPRINT(" add_stat_cache_entry - noobjcache[path=%s]\n", key.c_str()); + DPRNNN("add no object cache entry[path=%s]", key.c_str()); if(stat_cache.size() > CacheSize){ if(!TruncateCache()){ @@ -326,7 +327,7 @@ bool StatCache::TruncateCache(void) stat_cache.erase(path_to_delete); pthread_mutex_unlock(&StatCache::stat_cache_lock); - FGPRINT(" truncate_stat_cache_entry[path=%s]\n", path_to_delete.c_str()); + DPRNNN("truncate stat cache[path=%s]", path_to_delete.c_str()); return true; } @@ -336,7 +337,7 @@ bool StatCache::DelStat(const char* key) if(!key){ return false; } - FGPRINT(" delete_stat_cache_entry[path=%s]\n", key); + DPRNNN("delete stat cache entry[path=%s]", key); pthread_mutex_lock(&StatCache::stat_cache_lock); stat_cache_t::iterator iter = stat_cache.find(key); diff --git a/src/common.h b/src/common.h index 1bcffb6..3b933d1 100644 --- a/src/common.h +++ b/src/common.h @@ -4,32 +4,59 @@ // // Macro // -#define SYSLOGINFO(...) syslog(LOG_INFO, __VA_ARGS__); -#define SYSLOGERR(...) syslog(LOG_ERR, __VA_ARGS__); -#define SYSLOGCRIT(...) syslog(LOG_CRIT, __VA_ARGS__); - -#define SYSLOGDBG(...) \ - if(debug){ \ - syslog(LOG_DEBUG, __VA_ARGS__); \ - } - -#define SYSLOGDBGERR(...) \ - if(debug){ \ - syslog(LOG_ERR, __VA_ARGS__); \ - } - -#define FGPRINT(...) \ - if(foreground){ \ - printf(__VA_ARGS__); \ - } - -#define FGPRINT2(...) \ - if(foreground2){ \ - printf(__VA_ARGS__); \ - } - #define SAFESTRPTR(strptr) (strptr ? strptr : "") +// for debug +#define FPRINT_NEST_SPACE_0 "" +#define FPRINT_NEST_SPACE_1 " " +#define FPRINT_NEST_SPACE_2 " " +#define FPRINT_NEST_CHECK(NEST) \ + (0 == NEST ? FPRINT_NEST_SPACE_0 : 1 == NEST ? FPRINT_NEST_SPACE_1 : FPRINT_NEST_SPACE_2) + +#define LOWFPRINT(NEST, ...) \ + printf("%s%s(%d): ", FPRINT_NEST_CHECK(NEST), __func__, __LINE__); \ + printf(__VA_ARGS__); \ + printf("\n"); \ + +#define FPRINT(NEST, ...) \ + if(foreground){ \ + LOWFPRINT(NEST, __VA_ARGS__); \ + } + +#define FPRINT2(NEST, ...) \ + if(foreground2){ \ + LOWFPRINT(NEST, __VA_ARGS__); \ + } + +#define LOWSYSLOGPRINT(LEVEL, ...) \ + syslog(LEVEL, __VA_ARGS__); + +#define SYSLOGPRINT(LEVEL, ...) \ + if(LEVEL <= LOG_CRIT || debug){ \ + LOWSYSLOGPRINT(LEVEL, __VA_ARGS__); \ + } + +#define DPRINT(LEVEL, NEST, ...) \ + FPRINT(NEST, __VA_ARGS__); \ + SYSLOGPRINT(LEVEL, __VA_ARGS__); + +#define DPRINT2(LEVEL, ...) \ + FPRINT2(2, __VA_ARGS__); \ + SYSLOGPRINT(LEVEL, __VA_ARGS__); + +// print debug message +#define FPRN(...) FPRINT(0, __VA_ARGS__) +#define FPRNN(...) FPRINT(1, __VA_ARGS__) +#define FPRNNN(...) FPRINT(2, __VA_ARGS__) +#define FPRNINFO(...) FPRINT2(2, __VA_ARGS__) + +// print debug message with putting syslog +#define DPRNCRIT(...) DPRINT(LOG_CRIT, 0, __VA_ARGS__) +#define DPRN(...) DPRINT(LOG_ERR, 0, __VA_ARGS__) +#define DPRNN(...) DPRINT(LOG_DEBUG, 1, __VA_ARGS__) +#define DPRNNN(...) DPRINT(LOG_DEBUG, 2, __VA_ARGS__) +#define DPRNINFO(...) DPRINT2(LOG_INFO, __VA_ARGS__) + // // Typedef // diff --git a/src/curl.cpp b/src/curl.cpp index 97ef690..2d8ce51 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -78,8 +78,7 @@ bool BodyData::Resize(size_t addbytes) } // realloc if(NULL == (text = (char*)realloc(text, (bufsize + need_size)))){ - FGPRINT("BodyData::Resize() not enough memory (realloc returned NULL)\n"); - SYSLOGDBGERR("not enough memory (realloc returned NULL)\n"); + DPRNCRIT("not enough memory (realloc returned NULL)"); return false; } bufsize += need_size; @@ -204,8 +203,7 @@ bool S3fsCurl::InitGlobalCurl(void) return false; } if(CURLE_OK != curl_global_init(CURL_GLOBAL_ALL)){ - FGPRINT("init_curl_global_all returns error.\n"); - SYSLOGERR("init_curl_global_all returns error."); + DPRN("init_curl_global_all returns error."); return false; } S3fsCurl::is_initglobal_done = true; @@ -230,38 +228,31 @@ bool S3fsCurl::InitShareCurl(void) return false; } if(!S3fsCurl::is_initglobal_done){ - FGPRINT("S3fsCurl::InitShareCurl : Dose not initialize global curl.\n"); - SYSLOGERR("S3fsCurl::InitShareCurl : Dose not initialize global curl."); + DPRN("could not initialize global curl."); return false; } if(S3fsCurl::hCurlShare){ - FGPRINT("S3fsCurl::InitShareCurl : already initiated.\n"); - SYSLOGERR("S3fsCurl::InitShareCurl : already initiated."); + DPRN("already initiated."); return false; } if(NULL == (S3fsCurl::hCurlShare = curl_share_init())){ - FGPRINT("S3fsCurl::InitShareCurl : curl_share_init failed\n"); - SYSLOGERR("S3fsCurl::InitShareCurl : curl_share_init failed"); + DPRN("curl_share_init failed"); return false; } if(CURLSHE_OK != (nSHCode = curl_share_setopt(S3fsCurl::hCurlShare, CURLSHOPT_LOCKFUNC, S3fsCurl::LockCurlShare))){ - FGPRINT("S3fsCurl::InitShareCurl : curl_share_setopt(LOCKFUNC) returns %d(%s)\n", nSHCode, curl_share_strerror(nSHCode)); - SYSLOGERR("S3fsCurl::InitShareCurl : %d(%s)", nSHCode, curl_share_strerror(nSHCode)); + DPRN("curl_share_setopt(LOCKFUNC) returns %d(%s)", nSHCode, curl_share_strerror(nSHCode)); return false; } if(CURLSHE_OK != (nSHCode = curl_share_setopt(S3fsCurl::hCurlShare, CURLSHOPT_UNLOCKFUNC, S3fsCurl::UnlockCurlShare))){ - FGPRINT("S3fsCurl::InitShareCurl : curl_share_setopt(UNLOCKFUNC) returns %d(%s)\n", nSHCode, curl_share_strerror(nSHCode)); - SYSLOGERR("S3fsCurl::InitShareCurl : %d(%s)", nSHCode, curl_share_strerror(nSHCode)); + DPRN("curl_share_setopt(UNLOCKFUNC) returns %d(%s)", nSHCode, curl_share_strerror(nSHCode)); return false; } if(CURLSHE_OK != (nSHCode = curl_share_setopt(S3fsCurl::hCurlShare, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS))){ - FGPRINT("S3fsCurl::InitShareCurl : curl_share_setopt(DNS) returns %d(%s)\n", nSHCode, curl_share_strerror(nSHCode)); - SYSLOGERR("S3fsCurl::InitShareCurl : %d(%s)", nSHCode, curl_share_strerror(nSHCode)); + DPRN("curl_share_setopt(DNS) returns %d(%s)", nSHCode, curl_share_strerror(nSHCode)); return false; } if(CURLSHE_OK != (nSHCode = curl_share_setopt(S3fsCurl::hCurlShare, CURLSHOPT_USERDATA, (void*)&S3fsCurl::curl_share_lock))){ - FGPRINT("S3fsCurl::InitShareCurl : curl_share_setopt(USERDATA) returns %d(%s)\n", nSHCode, curl_share_strerror(nSHCode)); - SYSLOGERR("S3fsCurl::InitShareCurl : %d(%s)", nSHCode, curl_share_strerror(nSHCode)); + DPRN("curl_share_setopt(USERDATA) returns %d(%s)", nSHCode, curl_share_strerror(nSHCode)); return false; } return true; @@ -270,14 +261,12 @@ bool S3fsCurl::InitShareCurl(void) bool S3fsCurl::DestroyShareCurl(void) { if(!S3fsCurl::is_initglobal_done){ - FGPRINT("S3fsCurl::DestroyShareCurl : already destroy global curl.\n"); - SYSLOGERR("S3fsCurl::DestroyShareCurl : already destroy global curl."); + DPRN("already destroy global curl."); return false; } if(!S3fsCurl::hCurlShare){ if(S3fsCurl::is_dns_cache){ - FGPRINT("S3fsCurl::DestroyShareCurl : already destroy share curl.\n"); - SYSLOGERR("S3fsCurl::DestroyShareCurl : already destroy share curl."); + DPRN("already destroy share curl."); } return false; } @@ -322,7 +311,7 @@ int S3fsCurl::CurlProgress(void *clientp, double dltotal, double dlnow, double u // timeout? if(now - S3fsCurl::curl_times[curl] > readwrite_timeout){ pthread_mutex_unlock(&S3fsCurl::curl_handles_lock); - SYSLOGERR("timeout now: %li, curl_times[curl]: %lil, readwrite_timeout: %li", + DPRN("timeout now: %li, curl_times[curl]: %lil, readwrite_timeout: %li", (long int)now, S3fsCurl::curl_times[curl], (long int)readwrite_timeout); return CURLE_ABORTED_BY_CALLBACK; } @@ -436,7 +425,7 @@ bool S3fsCurl::LocateBundle(void) // check for existance and readability of the file ifstream BF(CURL_CA_BUNDLE); if(!BF.good()){ - SYSLOGERR("%s: file specified by CURL_CA_BUNDLE environment variable is not readable", program_name.c_str()); + DPRN("%s: file specified by CURL_CA_BUNDLE environment variable is not readable", program_name.c_str()); return false; } BF.close(); @@ -474,7 +463,7 @@ size_t S3fsCurl::WriteMemoryCallback(void* ptr, size_t blockSize, size_t numBloc BodyData* body = (BodyData*)data; if(!body->Append(ptr, blockSize, numBlocks)){ - FGPRINT("WriteMemoryCallback(): BodyData.Append() returned false.\n"); + DPRNCRIT("BodyData.Append() returned false."); S3FS_FUSE_EXIT(); return -1; } @@ -543,8 +532,7 @@ size_t S3fsCurl::UploadReadCallback(void* ptr, size_t size, size_t nmemb, void* break; }else if(-1 == readbytes){ // error - FGPRINT("S3fsCurl::UploadReadCallback: read file error(%d).\n", errno); - SYSLOGERR("read file error(%d).", errno); + DPRN("read file error(%d).", errno); return 0; } } @@ -578,8 +566,7 @@ size_t S3fsCurl::DownloadWriteCallback(void* ptr, size_t size, size_t nmemb, voi break; }else if(-1 == writebytes){ // error - FGPRINT("S3fsCurl::DownloadWriteCallback: write file error(%d).\n", errno); - SYSLOGERR("write file error(%d).", errno); + DPRN("write file error(%d).", errno); return 0; } } @@ -722,8 +709,7 @@ S3fsCurl* S3fsCurl::UploadMultipartPostRetryCallback(S3fsCurl* s3fscurl) // setup new curl object if(!newcurl->UploadMultipartPostSetup(s3fscurl->path.c_str(), part_num, upload_id)){ - FGPRINT(" S3fsCurl::UploadMultipartPostRetryCallback : Could not duplicate curl object(%s:%d).\n", s3fscurl->path.c_str(), part_num); - SYSLOGERR("Could not duplicate curl object(%s:%d).", s3fscurl->path.c_str(), part_num); + DPRN("Could not duplicate curl object(%s:%d).", s3fscurl->path.c_str(), part_num); delete newcurl; return NULL; } @@ -742,27 +728,25 @@ int S3fsCurl::ParallelMultipartUploadRequest(const char* tpath, headers_t& meta, unsigned char* buf; S3fsCurl s3fscurl; - FGPRINT(" S3fsCurl::ParallelMultipartUploadRequest[tpath=%s][fd=%d]\n", SAFESTRPTR(tpath), fd); + FPRNNN("[tpath=%s][fd=%d]", SAFESTRPTR(tpath), fd); // duplicate fd if(-1 == (fd2 = dup(fd)) || 0 != lseek(fd2, 0, SEEK_SET) || NULL == (file = fdopen(fd2, "rb"))){ - FGPRINT("S3fsCurl::ParallelMultipartUploadRequest: Cloud not duplicate file discriptor(errno=%d)\n", errno); - SYSLOGERR("Cloud not duplicate file discriptor(errno=%d)", errno); + DPRN("Cloud not duplicate file discriptor(errno=%d)", errno); if(-1 != fd2){ close(fd2); } return -errno; } if(-1 == fstat(fd2, &st)){ - FGPRINT("S3fsCurl::ParallelMultipartUploadRequest: Invalid file discriptor(errno=%d)\n", errno); - SYSLOGERR("Invalid file discriptor(errno=%d)", errno); + DPRN("Invalid file discriptor(errno=%d)", errno); fclose(file); return -errno; } // make Tempolary buf(maximum size + 4) if(NULL == (buf = (unsigned char*)malloc(sizeof(unsigned char) * (MULTIPART_SIZE + 4)))){ - SYSLOGCRIT("Could not allocate memory for buffer\n"); + DPRNCRIT("Could not allocate memory for buffer"); fclose(file); S3FS_FUSE_EXIT(); return -ENOMEM; @@ -799,8 +783,7 @@ int S3fsCurl::ParallelMultipartUploadRequest(const char* tpath, headers_t& meta, // initiate upload part for parallel if(0 != (result = s3fscurl_para->UploadMultipartPostSetup(tpath, list.size(), upload_id))){ - FGPRINT("S3fsCurl::ParallelMultipartUploadRequest: failed uploading part setup(%d)\n", result); - SYSLOGERR("failed uploading part setup(%d)", result); + DPRN("failed uploading part setup(%d)", result); free(buf); fclose(file); delete s3fscurl_para; @@ -809,8 +792,7 @@ int S3fsCurl::ParallelMultipartUploadRequest(const char* tpath, headers_t& meta, // set into parallel object if(!curlmulti.SetS3fsCurlObject(s3fscurl_para)){ - FGPRINT("S3fsCurl::ParallelMultipartUploadRequest: Could not set curl object into multi curl(%s).\n", tpath); - SYSLOGERR("Could not make curl object into multi curl(%s).", tpath); + DPRN("Could not make curl object into multi curl(%s).", tpath); free(buf); fclose(file); delete s3fscurl_para; @@ -820,8 +802,7 @@ int S3fsCurl::ParallelMultipartUploadRequest(const char* tpath, headers_t& meta, // Multi request if(0 != (result = curlmulti.Request())){ - FGPRINT("S3fsCurl::ParallelMultipartUploadRequest: error occuered in multi request(errno=%d).\n", result); - SYSLOGERR("error occuered in multi request(errno=%d).", result); + DPRN("error occuered in multi request(errno=%d).", result); break; } @@ -848,8 +829,7 @@ S3fsCurl* S3fsCurl::ParallelGetObjectRetryCallback(S3fsCurl* s3fscurl) S3fsCurl* newcurl = new S3fsCurl(); if(0 != (result = newcurl->PreGetObjectRequest( s3fscurl->path.c_str(), s3fscurl->partdata.fd, s3fscurl->partdata.startpos, s3fscurl->partdata.size))){ - FGPRINT("S3fsCurl::ParallelGetObjectRetryCallback: failed downloading part setup(%d)\n", result); - SYSLOGERR("failed downloading part setup(%d)", result); + DPRN("failed downloading part setup(%d)", result); delete newcurl; return NULL;; } @@ -858,7 +838,7 @@ S3fsCurl* S3fsCurl::ParallelGetObjectRetryCallback(S3fsCurl* s3fscurl) int S3fsCurl::ParallelGetObjectRequest(const char* tpath, int fd, off_t start, ssize_t size) { - FGPRINT(" S3fsCurl::ParallelGetObjectRequest[tpath=%s][fd=%d]\n", SAFESTRPTR(tpath), fd); + FPRNNN("[tpath=%s][fd=%d]", SAFESTRPTR(tpath), fd); int result = 0; ssize_t remaining_bytes; @@ -881,16 +861,14 @@ int S3fsCurl::ParallelGetObjectRequest(const char* tpath, int fd, off_t start, s // s3fscurl sub object S3fsCurl* s3fscurl_para = new S3fsCurl(); if(0 != (result = s3fscurl_para->PreGetObjectRequest(tpath, fd, (start + size - remaining_bytes), chunk))){ - FGPRINT("S3fsCurl::ParallelGetObjectRequest: failed downloading part setup(%d)\n", result); - SYSLOGERR("failed downloading part setup(%d)", result); + DPRN("failed downloading part setup(%d)", result); delete s3fscurl_para; return result; } // set into parallel object if(!curlmulti.SetS3fsCurlObject(s3fscurl_para)){ - FGPRINT("S3fsCurl::ParallelGetObjectRequest: Could not set curl object into multi curl(%s).\n", tpath); - SYSLOGERR("Could not make curl object into multi curl(%s).", tpath); + DPRN("Could not make curl object into multi curl(%s).", tpath); delete s3fscurl_para; return -1; } @@ -898,8 +876,7 @@ int S3fsCurl::ParallelGetObjectRequest(const char* tpath, int fd, off_t start, s // Multi request if(0 != (result = curlmulti.Request())){ - FGPRINT("S3fsCurl::ParallelGetObjectRequest: error occuered in multi request(errno=%d).\n", result); - SYSLOGERR("error occuered in multi request(errno=%d).", result); + DPRN("error occuered in multi request(errno=%d).", result); break; } @@ -929,19 +906,19 @@ bool S3fsCurl::CreateCurlHandle(bool force) if(hCurl){ if(!force){ - FGPRINT("S3fsCurl::CreateCurlHandle: already create handle.\n"); + DPRN("already create handle."); return false; } if(!DestroyCurlHandle()){ - FGPRINT("S3fsCurl::CreateCurlHandle: could not destroy handle.\n"); + DPRN("could not destroy handle."); return false; } ClearInternalData(); - FGPRINT("S3fsCurl::CreateCurlHandle: has handle, so destroied it.\n"); + DPRN("already has handle, so destroied it."); } if(NULL == (hCurl = curl_easy_init())){ - FGPRINT("S3fsCurl::CreateCurlHandle: Failed to create handle.\n"); + DPRN("Failed to create handle."); return false; } curl_easy_reset(hCurl); @@ -1037,7 +1014,7 @@ int S3fsCurl::RequestPerform(FILE* file) if(debug){ char* ptr_url = NULL; curl_easy_getinfo(hCurl, CURLINFO_EFFECTIVE_URL , &ptr_url); - SYSLOGDBG("connecting to URL %s", SAFESTRPTR(ptr_url)); + DPRNNN("connecting to URL %s", SAFESTRPTR(ptr_url)); } // curl_easy_setopt(curl, CURLOPT_VERBOSE, true); @@ -1061,16 +1038,16 @@ int S3fsCurl::RequestPerform(FILE* file) case CURLE_OK: // Need to look at the HTTP response code if(0 != curl_easy_getinfo(hCurl, CURLINFO_RESPONSE_CODE, &LastResponseCode)){ - SYSLOGERR("curl_easy_getinfo failed while trying to retrieve HTTP response code"); + DPRNNN("curl_easy_getinfo failed while trying to retrieve HTTP response code"); return -EIO; } - SYSLOGDBG("HTTP response code %ld", LastResponseCode); + DPRNNN("HTTP response code %ld", LastResponseCode); if(400 > LastResponseCode){ return 0; } if(500 <= LastResponseCode){ - SYSLOGERR("###HTTP response=%ld", LastResponseCode); + DPRNNN("###HTTP response=%ld", LastResponseCode); sleep(4); break; } @@ -1078,74 +1055,70 @@ int S3fsCurl::RequestPerform(FILE* file) // Service response codes which are >= 400 && < 500 switch(LastResponseCode){ case 400: - SYSLOGDBGERR("HTTP response code 400 was returned"); - SYSLOGDBGERR("Body Text: %s", (bodydata ? bodydata->str() : "")); - SYSLOGDBG("Now returning EIO"); + DPRNNN("HTTP response code 400 was returned, returing EIO."); + DPRNINFO("Body Text: %s", (bodydata ? bodydata->str() : "")); return -EIO; case 403: - SYSLOGDBGERR("HTTP response code 403 was returned"); - SYSLOGDBGERR("Body Text: %s", (bodydata ? bodydata->str() : "")); + DPRNNN("HTTP response code 403 was returned, returning EPERM"); + DPRNINFO("Body Text: %s", (bodydata ? bodydata->str() : "")); return -EPERM; case 404: - SYSLOGDBG("HTTP response code 404 was returned"); - SYSLOGDBG("Body Text: %s", (bodydata ? bodydata->str() : "")); - SYSLOGDBG("Now returning ENOENT"); + DPRNNN("HTTP response code 404 was returned, returning ENOENT"); + DPRNINFO("Body Text: %s", (bodydata ? bodydata->str() : "")); return -ENOENT; default: - SYSLOGERR("###response=%ld", LastResponseCode); - SYSLOGDBG("Body Text: %s", (bodydata ? bodydata->str() : "")); - FGPRINT("responseCode %ld\n", LastResponseCode); - FGPRINT("Body Text: %s", (bodydata ? bodydata->str() : "")); + DPRNNN("HTTP response code = %ld, returning EIO", LastResponseCode); + DPRNINFO("Body Text: %s", (bodydata ? bodydata->str() : "")); return -EIO; } break; case CURLE_WRITE_ERROR: - SYSLOGERR("### CURLE_WRITE_ERROR"); + DPRN("### CURLE_WRITE_ERROR"); sleep(2); break; case CURLE_OPERATION_TIMEDOUT: - SYSLOGERR("### CURLE_OPERATION_TIMEDOUT"); + DPRN("### CURLE_OPERATION_TIMEDOUT"); sleep(2); break; case CURLE_COULDNT_RESOLVE_HOST: - SYSLOGERR("### CURLE_COULDNT_RESOLVE_HOST"); + DPRN("### CURLE_COULDNT_RESOLVE_HOST"); sleep(2); break; case CURLE_COULDNT_CONNECT: - SYSLOGERR("### CURLE_COULDNT_CONNECT"); + DPRN("### CURLE_COULDNT_CONNECT"); sleep(4); break; case CURLE_GOT_NOTHING: - SYSLOGERR("### CURLE_GOT_NOTHING"); + DPRN("### CURLE_GOT_NOTHING"); sleep(4); break; case CURLE_ABORTED_BY_CALLBACK: - SYSLOGERR("### CURLE_ABORTED_BY_CALLBACK"); + DPRN("### CURLE_ABORTED_BY_CALLBACK"); sleep(4); S3fsCurl::curl_times[hCurl] = time(0); break; case CURLE_PARTIAL_FILE: - SYSLOGERR("### CURLE_PARTIAL_FILE"); + DPRN("### CURLE_PARTIAL_FILE"); sleep(4); break; case CURLE_SEND_ERROR: - SYSLOGERR("### CURLE_SEND_ERROR"); + DPRN("### CURLE_SEND_ERROR"); sleep(2); break; case CURLE_RECV_ERROR: - SYSLOGERR("### CURLE_RECV_ERROR"); + DPRN("### CURLE_RECV_ERROR"); sleep(2); break; @@ -1163,8 +1136,7 @@ int S3fsCurl::RequestPerform(FILE* file) break; } } - SYSLOGERR("curlCode: %i msg: %s", curlCode, curl_easy_strerror(curlCode)); - FGPRINT("%s: curlCode: %i -- %s\n", program_name.c_str(), curlCode, curl_easy_strerror(curlCode)); + DPRNCRIT("curlCode: %i msg: %s", curlCode, curl_easy_strerror(curlCode)); exit(EXIT_FAILURE); break; @@ -1172,13 +1144,13 @@ int S3fsCurl::RequestPerform(FILE* file) case CURLE_PEER_FAILED_VERIFICATION: first_pos = bucket.find_first_of("."); if(first_pos != string::npos){ - FGPRINT("%s: curl returned a CURL_PEER_FAILED_VERIFICATION error\n", program_name.c_str()); - FGPRINT("%s: security issue found: buckets with periods in their name are incompatible with https\n", program_name.c_str()); - FGPRINT("%s: This check can be over-ridden by using the -o ssl_verify_hostname=0\n", program_name.c_str()); - FGPRINT("%s: The certificate will still be checked but the hostname will not be verified.\n", program_name.c_str()); - FGPRINT("%s: A more secure method would be to use a bucket name without periods.\n", program_name.c_str()); - }else{ - FGPRINT("%s: my_curl_easy_perform: curlCode: %i -- %s\n", program_name.c_str(), curlCode, curl_easy_strerror(curlCode)); + FPRNNN("curl returned a CURL_PEER_FAILED_VERIFICATION error"); + FPRNNN("security issue found: buckets with periods in their name are incompatible with http"); + FPRNNN("This check can be over-ridden by using the -o ssl_verify_hostname=0"); + FPRNNN("The certificate will still be checked but the hostname will not be verified."); + FPRNNN("A more secure method would be to use a bucket name without periods."); + }else + DPRNNN("my_curl_easy_perform: curlCode: %i -- %s", curlCode, curl_easy_strerror(curlCode)); } exit(EXIT_FAILURE); break; @@ -1186,12 +1158,12 @@ int S3fsCurl::RequestPerform(FILE* file) // This should be invalid since curl option HTTP FAILONERROR is now off case CURLE_HTTP_RETURNED_ERROR: - SYSLOGERR("### CURLE_HTTP_RETURNED_ERROR"); + DPRN("### CURLE_HTTP_RETURNED_ERROR"); if(0 != curl_easy_getinfo(hCurl, CURLINFO_RESPONSE_CODE, &LastResponseCode)){ return -EIO; } - SYSLOGERR("###response=%ld", LastResponseCode); + DPRN("HTTP response code =%ld", LastResponseCode); // Let's try to retrieve the if(404 == LastResponseCode){ @@ -1204,13 +1176,13 @@ int S3fsCurl::RequestPerform(FILE* file) // Unknown CURL return code default: - SYSLOGERR("###curlCode: %i msg: %s", curlCode, curl_easy_strerror(curlCode)); + DPRNCRIT("###curlCode: %i msg: %s", curlCode, curl_easy_strerror(curlCode)); exit(EXIT_FAILURE); break; } - SYSLOGERR("###retrying..."); + DPRNNN("### retrying..."); } - SYSLOGERR("###giving up"); + DPRN("### giving up"); return -EIO; } @@ -1272,14 +1244,14 @@ string S3fsCurl::CalcSignature(string method, string strMD5, string content_type continue; } // Too many write attempts - SYSLOGERR("Failure during BIO_write, returning null String"); + DPRNNN("Failure during BIO_write, returning null String"); BIO_free_all(b64); Signature.clear(); return Signature; }else{ // If not a retry then it is an error - SYSLOGERR("Failure during BIO_write, returning null String"); + DPRNNN("Failure during BIO_write, returning null String"); BIO_free_all(b64); Signature.clear(); return Signature; @@ -1300,7 +1272,7 @@ string S3fsCurl::CalcSignature(string method, string strMD5, string content_type // Flush the data ret = BIO_flush(b64); if(ret <= 0){ - SYSLOGERR("Failure during BIO_flush, returning null String"); + DPRNNN("Failure during BIO_flush, returning null String"); BIO_free_all(b64); Signature.clear(); return Signature; @@ -1359,7 +1331,7 @@ bool S3fsCurl::GetUploadId(string& upload_id) int S3fsCurl::DeleteRequest(const char* tpath) { - FGPRINT(" S3fsCurl::DeleteRequest [tpath=%s]\n", SAFESTRPTR(tpath)); + FPRNNN("[tpath=%s]", SAFESTRPTR(tpath)); if(!tpath){ return -1; @@ -1400,7 +1372,7 @@ int S3fsCurl::DeleteRequest(const char* tpath) // bool S3fsCurl::PreHeadRequest(const char* tpath, const char* bpath, const char* savedpath) { -//FGPRINT(" S3fsCurl::PreHeadRequest [tpath=%s][bpath=%s][save=%s]\n", SAFESTRPTR(tpath), SAFESTRPTR(bpath), SAFESTRPTR(savedpath)); + FPRNINFO("[tpath=%s][bpath=%s][save=%s]", SAFESTRPTR(tpath), SAFESTRPTR(bpath), SAFESTRPTR(savedpath)); if(!tpath){ return false; @@ -1447,7 +1419,7 @@ int S3fsCurl::HeadRequest(const char* tpath, headers_t& meta) { int result; - FGPRINT(" S3fsCurl::HeadRequest [tpath=%s]\n", SAFESTRPTR(tpath)); + FPRNNN("[tpath=%s]", SAFESTRPTR(tpath)); if(!PreHeadRequest(tpath)){ return -1; @@ -1485,7 +1457,7 @@ int S3fsCurl::HeadRequest(const char* tpath, headers_t& meta) int S3fsCurl::PutHeadRequest(const char* tpath, headers_t& meta, bool ow_sse_flg) { - FGPRINT(" S3fsCurl::PutHeadRequest [tpath=%s]\n", SAFESTRPTR(tpath)); + FPRNNN("[tpath=%s]", SAFESTRPTR(tpath)); if(!tpath){ return -1; @@ -1548,8 +1520,7 @@ int S3fsCurl::PutHeadRequest(const char* tpath, headers_t& meta, bool ow_sse_flg curl_easy_setopt(hCurl, CURLOPT_INFILESIZE, 0); // Content-Length curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); - FGPRINT(" copying... [path=%s]\n", tpath); - SYSLOGDBG("copy path=%s", tpath); + DPRNNN("copying... [path=%s]", tpath); int result = RequestPerform(); delete bodydata; @@ -1564,7 +1535,7 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd, bool ow_sse FILE* file = NULL; int fd2; - FGPRINT(" S3fsCurl::PutRequest [tpath=%s]\n", SAFESTRPTR(tpath)); + FPRNNN("[tpath=%s]", SAFESTRPTR(tpath)); if(!tpath){ return -1; @@ -1572,13 +1543,12 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd, bool ow_sse if(-1 != fd){ // duplicate fd if(-1 == (fd2 = dup(fd)) || -1 == fstat(fd2, &st) || 0 != lseek(fd2, 0, SEEK_SET) || NULL == (file = fdopen(fd2, "rb"))){ - FGPRINT("S3fsCurl::PutRequest : Could not duplicate file discriptor(errno=%d)\n", errno); - SYSLOGERR("Could not duplicate file discriptor(errno=%d)", errno); + DPRN("Could not duplicate file discriptor(errno=%d)", errno); return -errno; } }else{ // This case is creating zero byte obejct.(calling by create_file_object()) - FGPRINT(" S3fsCurl::PutRequest : create zero byte file object.\n"); + DPRNNN("create zero byte file object."); } if(!CreateCurlHandle(true)){ @@ -1651,8 +1621,7 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd, bool ow_sse curl_easy_setopt(hCurl, CURLOPT_INFILESIZE, 0); // Content-Length: 0 } - FGPRINT(" uploading... [path=%s][fd=%d][size=%zd]\n", tpath, fd, (-1 != fd ? st.st_size : 0)); - SYSLOGDBG("upload path=%s", tpath); + DPRNNN("uploading... [path=%s][fd=%d][size=%zd]", tpath, fd, (-1 != fd ? st.st_size : 0)); int result = RequestPerform(); delete bodydata; @@ -1666,7 +1635,7 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd, bool ow_sse int S3fsCurl::PreGetObjectRequest(const char* tpath, int fd, off_t start, ssize_t size) { - FGPRINT(" S3fsCurl::PreGetRequest [tpath=%s][start=%zd][size=%zd]\n", SAFESTRPTR(tpath), start, size); + FPRNNN("[tpath=%s][start=%zd][size=%zd]", SAFESTRPTR(tpath), start, size); if(!tpath || -1 == fd || 0 > start || 0 >= size){ return -1; @@ -1722,7 +1691,7 @@ int S3fsCurl::GetObjectRequest(const char* tpath, int fd, off_t start, ssize_t s { int result; - FGPRINT(" S3fsCurl::GetRequest [tpath=%s][start=%zd][size=%zd]\n", SAFESTRPTR(tpath), start, size); + FPRNNN("[tpath=%s][start=%zd][size=%zd]", SAFESTRPTR(tpath), start, size); if(!tpath){ return -1; @@ -1731,8 +1700,7 @@ int S3fsCurl::GetObjectRequest(const char* tpath, int fd, off_t start, ssize_t s return result; } - FGPRINT(" downloading... [path=%s][fd=%d]\n", tpath, fd); - SYSLOGDBG("LOCAL FD"); + DPRNNN("downloading... [path=%s][fd=%d]", tpath, fd); result = RequestPerform(); partdata.clear(); @@ -1742,7 +1710,7 @@ int S3fsCurl::GetObjectRequest(const char* tpath, int fd, off_t start, ssize_t s int S3fsCurl::CheckBucket(void) { - FGPRINT(" S3fsCurl::CheckBucket\n"); + FPRNNN("check a bucket."); if(!CreateCurlHandle(true)){ return -1; @@ -1783,7 +1751,7 @@ int S3fsCurl::CheckBucket(void) int S3fsCurl::ListBucketRequest(const char* tpath, const char* query) { - FGPRINT(" S3fsCurl::ListBucketRequest [tpath=%s]\n", SAFESTRPTR(tpath)); + FPRNNN("[tpath=%s]", SAFESTRPTR(tpath)); if(!tpath){ return -1; @@ -1836,7 +1804,7 @@ int S3fsCurl::ListBucketRequest(const char* tpath, const char* query) // int S3fsCurl::PreMultipartPostRequest(const char* tpath, headers_t& meta, string& upload_id, bool ow_sse_flg) { - FGPRINT(" S3fsCurl::PreMultipartPostRequest [tpath=%s]\n", SAFESTRPTR(tpath)); + FPRNNN("[tpath=%s]", SAFESTRPTR(tpath)); if(!tpath){ return -1; @@ -1921,7 +1889,7 @@ int S3fsCurl::PreMultipartPostRequest(const char* tpath, headers_t& meta, string int S3fsCurl::CompleteMultipartPostRequest(const char* tpath, string& upload_id, etaglist_t& parts) { - FGPRINT(" S3fsCurl::CompleteMultipartPostRequest [tpath=%s][parts=%zd]\n", SAFESTRPTR(tpath), parts.size()); + FPRNNN("[tpath=%s][parts=%zd]", SAFESTRPTR(tpath), parts.size()); if(!tpath){ return -1; @@ -1932,7 +1900,7 @@ int S3fsCurl::CompleteMultipartPostRequest(const char* tpath, string& upload_id, postContent += "\n"; for(int cnt = 0; cnt < (int)parts.size(); cnt++){ if(0 == parts[cnt].length()){ - FGPRINT("S3fsCurl::CompleteMultipartPostRequest : %d file part is not finished uploading.\n", cnt + 1); + DPRN("%d file part is not finished uploading.", cnt + 1); return -1; } postContent += "\n"; @@ -1994,7 +1962,7 @@ int S3fsCurl::CompleteMultipartPostRequest(const char* tpath, string& upload_id, int S3fsCurl::MultipartListRequest(string& body) { - FGPRINT(" S3fsCurl::MultipartListRequest\n"); + FPRNNN("list request(multipart)"); if(!CreateCurlHandle(true)){ return -1; @@ -2057,8 +2025,7 @@ int S3fsCurl::MultipartListRequest(string& body) int S3fsCurl::UploadMultipartPostSetup(const char* tpath, int part_num, string& upload_id) { - FGPRINT(" S3fsCurl::UploadMultipartPostSetup[tpath=%s][start=%zd][size=%zd][part=%d]\n", - SAFESTRPTR(tpath), partdata.startpos, partdata.size, part_num); + FPRNNN("[tpath=%s][start=%zd][size=%zd][part=%d]", SAFESTRPTR(tpath), partdata.startpos, partdata.size, part_num); if(-1 == partdata.fd || -1 == partdata.startpos || -1 == partdata.size){ return -1; @@ -2067,8 +2034,7 @@ int S3fsCurl::UploadMultipartPostSetup(const char* tpath, int part_num, string& // make md5 and file pointer partdata.etag = md5sum(partdata.fd, partdata.startpos, partdata.size); if(partdata.etag.empty()){ - FGPRINT("S3fsCurl::UploadMultipartPostSetup: Could not make md5 for file(part %d)\n", part_num); - SYSLOGERR("Could not make md5 for file(part %d)", part_num); + DPRN("Could not make md5 for file(part %d)", part_num); return -1; } @@ -2122,8 +2088,7 @@ int S3fsCurl::UploadMultipartPostRequest(const char* tpath, int part_num, string { int result; - FGPRINT(" S3fsCurl::UploadMultipartPostRequest[tpath=%s][start=%zd][size=%zd][part=%d]\n", - SAFESTRPTR(tpath), partdata.startpos, partdata.size, part_num); + FPRNNN("[tpath=%s][start=%zd][size=%zd][part=%d]", SAFESTRPTR(tpath), partdata.startpos, partdata.size, part_num); // setup if(0 != (result = S3fsCurl::UploadMultipartPostSetup(tpath, part_num, upload_id))){ @@ -2150,7 +2115,7 @@ int S3fsCurl::UploadMultipartPostRequest(const char* tpath, int part_num, string int S3fsCurl::CopyMultipartPostRequest(const char* from, const char* to, int part_num, string& upload_id, headers_t& meta, bool ow_sse_flg) { - FGPRINT(" S3fsCurl::CopyMultipartPostRequest [from=%s][to=%s][part=%d]\n", SAFESTRPTR(from), SAFESTRPTR(to), part_num); + FPRNNN("[from=%s][to=%s][part=%d]", SAFESTRPTR(from), SAFESTRPTR(to), part_num); if(!from || !to){ return -1; @@ -2220,8 +2185,7 @@ int S3fsCurl::CopyMultipartPostRequest(const char* from, const char* to, int par curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); // request - FGPRINT(" copying... [from=%s][to=%s][part=%d]\n", from, to, part_num); - SYSLOGDBG("copy path from=%s, to=%s, part=%d", from, to, part_num); + DPRNNN("copying... [from=%s][to=%s][part=%d]", from, to, part_num); int result = RequestPerform(); if(0 == result){ @@ -2248,7 +2212,7 @@ int S3fsCurl::MultipartHeadRequest(const char* tpath, off_t size, headers_t& met etaglist_t list; stringstream strrange; - FGPRINT(" S3fsCurl::MultipartHeadRequest [tpath=%s]\n", SAFESTRPTR(tpath)); + FPRNNN("[tpath=%s]", SAFESTRPTR(tpath)); if(0 != (result = PreMultipartPostRequest(tpath, meta, upload_id, ow_sse_flg))){ return result; @@ -2287,27 +2251,25 @@ int S3fsCurl::MultipartUploadRequest(const char* tpath, headers_t& meta, int fd, off_t chunk; unsigned char* buf; - FGPRINT(" S3fsCurl::MultipartUploadRequest [tpath=%s][fd=%d]\n", SAFESTRPTR(tpath), fd); + FPRNNN("[tpath=%s][fd=%d]", SAFESTRPTR(tpath), fd); // duplicate fd if(-1 == (fd2 = dup(fd)) || 0 != lseek(fd2, 0, SEEK_SET) || NULL == (file = fdopen(fd2, "rb"))){ - FGPRINT("S3fsCurl::MultipartUploadRequest : Cloud not duplicate file discriptor(errno=%d)\n", errno); - SYSLOGERR("Cloud not duplicate file discriptor(errno=%d)", errno); + DPRN("Cloud not duplicate file discriptor(errno=%d)", errno); if(-1 != fd2){ close(fd2); } return -errno; } if(-1 == fstat(fd2, &st)){ - FGPRINT("S3fsCurl::MultipartUploadRequest: Invalid file discriptor(errno=%d)\n", errno); - SYSLOGERR("Invalid file discriptor(errno=%d)", errno); + DPRN("Invalid file discriptor(errno=%d)", errno); fclose(file); return -errno; } // make Tempolary buf(maximum size + 4) if(NULL == (buf = (unsigned char*)malloc(sizeof(unsigned char) * (MULTIPART_SIZE + 4)))){ - SYSLOGCRIT("Could not allocate memory for buffer\n"); + DPRNCRIT("Could not allocate memory for buffer"); fclose(file); S3FS_FUSE_EXIT(); return -ENOMEM; @@ -2332,8 +2294,7 @@ int S3fsCurl::MultipartUploadRequest(const char* tpath, headers_t& meta, int fd, // upload part if(0 != (result = UploadMultipartPostRequest(tpath, (list.size() + 1), upload_id))){ - FGPRINT("S3fsCurl::MultipartUploadRequest: failed uploading part(%d)\n", result); - SYSLOGERR("failed uploading part(%d)", result); + DPRN("failed uploading part(%d)", result); free(buf); fclose(file); return result; @@ -2359,7 +2320,7 @@ int S3fsCurl::MultipartRenameRequest(const char* from, const char* to, headers_t etaglist_t list; stringstream strrange; - FGPRINT(" S3fsCurl::MultipartRenameRequest [from=%s][to=%s]\n", SAFESTRPTR(from), SAFESTRPTR(to)); + FPRNNN("[from=%s][to=%s]", SAFESTRPTR(from), SAFESTRPTR(to)); string srcresource; string srcurl; @@ -2490,8 +2451,7 @@ int S3fsMultiCurl::MultiPerform(void) } while(curlm_code == CURLM_CALL_MULTI_PERFORM); if(curlm_code != CURLM_OK) { - FGPRINT("S3fsMultiCurl::MultiPerform: curl_multi_perform code: %d msg: %s\n", curlm_code, curl_multi_strerror(curlm_code)); - SYSLOGERR("curl_multi_perform code: %d msg: %s", curlm_code, curl_multi_strerror(curlm_code)); + DPRNNN("curl_multi_perform code: %d msg: %s", curlm_code, curl_multi_strerror(curlm_code)); } // Set timer when still running @@ -2505,8 +2465,7 @@ int S3fsMultiCurl::MultiPerform(void) FD_ZERO(&e_fd); if(CURLM_OK != (curlm_code = curl_multi_timeout(hMulti, &milliseconds))){ - FGPRINT("S3fsMultiCurl::MultiPerform: curl_multi_timeout code: %d msg: %s\n", curlm_code, curl_multi_strerror(curlm_code)); - SYSLOGERR("curl_multi_timeout code: %d msg: %s", curlm_code, curl_multi_strerror(curlm_code)); + DPRNNN("curl_multi_timeout code: %d msg: %s", curlm_code, curl_multi_strerror(curlm_code)); } if(milliseconds < 0){ milliseconds = 50; @@ -2518,13 +2477,11 @@ int S3fsMultiCurl::MultiPerform(void) timeout.tv_usec = 1000 * milliseconds % 1000000; if(CURLM_OK != (curlm_code = curl_multi_fdset(hMulti, &r_fd, &w_fd, &e_fd, &max_fd))){ - FGPRINT("S3fsMultiCurl::MultiPerform: curl_multi_fdset code: %d msg: %s\n", curlm_code, curl_multi_strerror(curlm_code)); - SYSLOGERR("curl_multi_fdset code: %d msg: %s", curlm_code, curl_multi_strerror(curlm_code)); + DPRN("curl_multi_fdset code: %d msg: %s", curlm_code, curl_multi_strerror(curlm_code)); return -EIO; } if(-1 == select(max_fd + 1, &r_fd, &w_fd, &e_fd, &timeout)){ - FGPRINT("S3fsMultiCurl::MultiPerform: failed select - errno(%d)\n", errno); - SYSLOGERR("failed select - errno(%d)", errno); + DPRN("failed select - errno(%d)", errno); return -errno; } } @@ -2544,8 +2501,7 @@ int S3fsMultiCurl::MultiRead(void) while(NULL != (msg = curl_multi_info_read(hMulti, &remaining_messages))){ if(CURLMSG_DONE != msg->msg){ - FGPRINT("S3fsMultiCurl::MultiRead: curl_multi_info_read code: %d\n", msg->msg); - SYSLOGERR("curl_multi_info_read code: %d", msg->msg); + DPRN("curl_multi_info_read code: %d", msg->msg); return -EIO; } hCurl = msg->easy_handle; @@ -2557,17 +2513,15 @@ int S3fsMultiCurl::MultiRead(void) if(s3fscurl->GetResponseCode(responseCode) && 400 > responseCode){ // add into stat cache if(SuccessCallback && !SuccessCallback(s3fscurl)){ - FGPRINT("S3fsMultiCurl::MultiRead: error from callback function(%s).\n", s3fscurl->base_path.c_str()); + DPRNNN("S3fsMultiCurl::MultiRead: error from callback function(%s).", s3fscurl->base_path.c_str()); } }else{ // This case is directory object("dir", "non dir object", "_$folder$", etc) - //FGPRINT("S3fsMultiCurl::MultiRead: failed a request(%s)\n", s3fscurl->base_path.c_str()); + DPRNINFO("S3fsMultiCurl::MultiRead: failed a request(%s)", s3fscurl->base_path.c_str()); } }else{ - FGPRINT("S3fsMultiCurl::MultiRead: failed to read(remaining: %i code: %d msg: %s), so retry this.\n", - remaining_messages, msg->data.result, curl_easy_strerror(msg->data.result)); - SYSLOGDBGERR("failed to read(remaining: %i code: %d msg: %s), so retry this.", + DPRNNN("failed to read(remaining: %i code: %d msg: %s), so retry this.", remaining_messages, msg->data.result, curl_easy_strerror(msg->data.result)); // For retry @@ -2594,7 +2548,7 @@ int S3fsMultiCurl::Request(void) int result; CURLMcode curlm_code; - FGPRINT(" S3fsMultiCurl::Request[count=%ld]\n", cMap_all.size()); + FPRNNN("[count=%ld]", cMap_all.size()); if(hMulti){ Clear(); @@ -2620,8 +2574,7 @@ int S3fsMultiCurl::Request(void) S3fsCurl* s3fscurl = (*iter).second; if(CURLM_OK != (curlm_code = curl_multi_add_handle(hMulti, hCurl))){ - FGPRINT("S3fsMultiCurl::Request: curl_multi_add_handle code: %d msg: %s\n", curlm_code, curl_multi_strerror(curlm_code)); - SYSLOGERR("curl_multi_add_handle code: %d msg: %s", curlm_code, curl_multi_strerror(curlm_code)); + DPRN("curl_multi_add_handle code: %d msg: %s", curlm_code, curl_multi_strerror(curlm_code)); Clear(); return -EIO; } @@ -2703,7 +2656,7 @@ unsigned char* md5hexsum(int fd, off_t start, off_t size) break; }else if(-1 == bytes){ // error - FGPRINT("md5hexsum: : file read error(%d)\n", errno); + DPRNNN("file read error(%d)", errno); free(result); return NULL; } diff --git a/src/fdcache.cpp b/src/fdcache.cpp index 417836f..ccf915a 100644 --- a/src/fdcache.cpp +++ b/src/fdcache.cpp @@ -83,13 +83,11 @@ bool CacheFileStat::DeleteCacheFileStat(const char* path) // stat path string sfile_path; if(!CacheFileStat::MakeCacheFileStatPath(path, sfile_path, false)){ - //FGPRINT("CacheFileStat::DeleteCacheFileStat: failed to create cache stat file path(%s)\n", path.c_str()); - //SYSLOGERR("failed to create cache stat file path(%s)", path.c_str()); + DPRNINFO("failed to create cache stat file path(%s)", path); return false; } if(0 != unlink(sfile_path.c_str())){ - //FGPRINT("CacheFileStat::DeleteCacheFileStat: failed to delete file(%s): errno=%d\n", path, errno); - //SYSLOGERR("failed to delete file(%s): errno=%d", path, errno); + DPRNINFO("failed to delete file(%s): errno=%d", path, errno); return false; } return true; @@ -140,34 +138,30 @@ bool CacheFileStat::Open(void) // stat path string sfile_path; if(!CacheFileStat::MakeCacheFileStatPath(path.c_str(), sfile_path, true)){ - FGPRINT("CacheFileStat::Open: failed to create cache stat file path(%s)\n", path.c_str()); - SYSLOGERR("failed to create cache stat file path(%s)", path.c_str()); + DPRN("failed to create cache stat file path(%s)", path.c_str()); return false; } // open if(-1 == (fd = open(sfile_path.c_str(), O_CREAT|O_RDWR, 0600))){ - FGPRINT2("CacheFileStat::Open: failed to open cache stat file(%s) - errno(%d)\n", path.c_str(), errno); - //SYSLOGERR("failed to open cache stat file path(%s) - errno(%d)", path.c_str(), errno); + DPRNINFO("failed to open cache stat file path(%s) - errno(%d)", path.c_str(), errno); return false; } // lock if(-1 == flock(fd, LOCK_EX)){ - FGPRINT("CacheFileStat::Open: failed to lock cache stat file(%s) - errno(%d)\n", path.c_str(), errno); - SYSLOGERR("failed to lock cache stat file(%s) - errno(%d)", path.c_str(), errno); + DPRN("failed to lock cache stat file(%s) - errno(%d)", path.c_str(), errno); close(fd); fd = -1; return false; } // seek top if(0 != lseek(fd, 0, SEEK_SET)){ - FGPRINT("CacheFileStat::Open: failed to lseek cache stat file(%s) - errno(%d)\n", path.c_str(), errno); - SYSLOGERR("failed to lseek cache stat file(%s) - errno(%d)", path.c_str(), errno); + DPRN("failed to lseek cache stat file(%s) - errno(%d)", path.c_str(), errno); flock(fd, LOCK_UN); close(fd); fd = -1; return false; } - FGPRINT2(" CacheFileStat::Open: file locked(%s - %s)\n", path.c_str(), sfile_path.c_str()); + DPRNINFO("file locked(%s - %s)", path.c_str(), sfile_path.c_str()); return true; } @@ -180,15 +174,13 @@ bool CacheFileStat::Release(void) } // unlock if(-1 == flock(fd, LOCK_UN)){ - FGPRINT("CacheFileStat::Open: failed to unlock cache stat file(%s) - errno(%d)\n", path.c_str(), errno); - SYSLOGERR("failed to unlock cache stat file(%s) - errno(%d)", path.c_str(), errno); + DPRN("failed to unlock cache stat file(%s) - errno(%d)", path.c_str(), errno); return false; } - FGPRINT2(" CacheFileStat::Open: file unlocked(%s)\n", path.c_str()); + DPRNINFO("file unlocked(%s)", path.c_str()); if(-1 == close(fd)){ - FGPRINT("CacheFileStat::Open: failed to close cache stat file(%s) - errno(%d)\n", path.c_str(), errno); - SYSLOGERR("failed to close cache stat file(%s) - errno(%d)", path.c_str(), errno); + DPRN("failed to close cache stat file(%s) - errno(%d)", path.c_str(), errno); return false; } fd = -1; @@ -391,8 +383,7 @@ bool PageList::Serialize(CacheFileStat& file, bool is_output) string strall = ssall.str(); if(0 >= pwrite(file.GetFd(), strall.c_str(), strall.length(), 0)){ - FGPRINT("PageList::Serialize: failed to write stats(%d)\n", errno); - SYSLOGERR("failed to write stats(%d)", errno); + DPRN("failed to write stats(%d)", errno); return false; } @@ -403,8 +394,7 @@ bool PageList::Serialize(CacheFileStat& file, bool is_output) struct stat st; memset(&st, 0, sizeof(struct stat)); if(-1 == fstat(file.GetFd(), &st)){ - FGPRINT("PageList::Serialize: fstat is failed. errno(%d)\n", errno); - SYSLOGERR("fstat is failed. errno(%d)", errno); + DPRN("fstat is failed. errno(%d)", errno); return false; } if(0 >= st.st_size){ @@ -414,15 +404,13 @@ bool PageList::Serialize(CacheFileStat& file, bool is_output) } char* ptmp; if(NULL == (ptmp = (char*)calloc(st.st_size + 1, sizeof(char)))){ - FGPRINT("PageList::Serialize: could not allocate memory.\n"); - SYSLOGERR("could not allocate memory."); + DPRNCRIT("could not allocate memory."); S3FS_FUSE_EXIT(); return false; } // read from file if(0 >= pread(file.GetFd(), ptmp, st.st_size, 0)){ - FGPRINT("PageList::Serialize: failed to read stats(%d)\n", errno); - SYSLOGERR("failed to read stats(%d)", errno); + DPRN("failed to read stats(%d)", errno); free(ptmp); return false; } @@ -435,8 +423,7 @@ bool PageList::Serialize(CacheFileStat& file, bool is_output) // load(size) if(!getline(ssall, oneline, '\n')){ - FGPRINT("PageList::Serialize: failed to parse stats.\n"); - SYSLOGERR("failed to parse stats."); + DPRN("failed to parse stats."); return false; } size_t total = static_cast(atoi(oneline.c_str())); @@ -468,16 +455,14 @@ bool PageList::Serialize(CacheFileStat& file, bool is_output) SetInit(offset, size, is_init); } if(is_err){ - FGPRINT("PageList::Serialize: failed to parse stats.\n"); - SYSLOGERR("failed to parse stats."); + DPRN("failed to parse stats."); Clear(); return false; } // check size if(total != Size()){ - FGPRINT("PageList::Serialize: different size(%zd - %zd).\n", total, Size()); - SYSLOGERR("different size(%zd - %zd).", total, Size()); + DPRN("different size(%zd - %zd).", total, Size()); Clear(); return false; } @@ -489,11 +474,11 @@ void PageList::Dump(void) { int cnt = 0; - FGPRINT2(" FdEntity::Dump = {\n"); + DPRNINFO("pages = {"); for(fdpage_list_t::iterator iter = pages.begin(); iter != pages.end(); iter++, cnt++){ - FGPRINT2(" [%08d] -> {%014zd - %014zd : %s}\n", cnt, (*iter)->offset, (*iter)->bytes, (*iter)->init ? "true" : "false"); + DPRNINFO(" [%08d] -> {%014zd - %014zd : %s}", cnt, (*iter)->offset, (*iter)->bytes, (*iter)->init ? "true" : "false"); } - FGPRINT2(" }\n"); + DPRNINFO("}"); } //------------------------------------------------ @@ -506,8 +491,7 @@ FdEntity::FdEntity(const char* tpath, const char* cpath) pthread_mutex_init(&fdent_lock, NULL); is_lock_init = true; }catch(exception& e){ - FGPRINT("FdEntity::FdEntity: failed to init mutex\n"); - SYSLOGERR("failed to init mutex"); + DPRNCRIT("failed to init mutex"); } } @@ -519,8 +503,7 @@ FdEntity::~FdEntity() try{ pthread_mutex_destroy(&fdent_lock); }catch(exception& e){ - FGPRINT("FdEntity::~FdEntity: failed to destroy mutex\n"); - SYSLOGERR("failed to destroy mutex"); + DPRNCRIT("failed to destroy mutex"); } is_lock_init = false; } @@ -534,8 +517,7 @@ void FdEntity::Clear(void) { CacheFileStat cfstat(path.c_str()); if(!pagelist.Serialize(cfstat, true)){ - FGPRINT("FdEntity::Clear: failed to save cache stat file(%s).\n", path.c_str()); - SYSLOGERR("failed to save cache stat file(%s).", path.c_str()); + DPRN("failed to save cache stat file(%s).", path.c_str()); } } fclose(file); @@ -551,7 +533,7 @@ void FdEntity::Clear(void) void FdEntity::Close(void) { - FGPRINT2(" FdEntity::Close[path=%s][fd=%d][refcnt=%d]\n", path.c_str(), fd, (-1 != fd ? refcnt - 1 : refcnt)); + FPRNINFO("[path=%s][fd=%d][refcnt=%d]", path.c_str(), fd, (-1 != fd ? refcnt - 1 : refcnt)); if(-1 != fd){ AutoLock auto_lock(&fdent_lock); @@ -563,8 +545,7 @@ void FdEntity::Close(void) { CacheFileStat cfstat(path.c_str()); if(!pagelist.Serialize(cfstat, true)){ - FGPRINT("FdEntity::Close: failed to save cache stat file(%s).\n", path.c_str()); - SYSLOGERR("failed to save cache stat file(%s).", path.c_str()); + DPRN("failed to save cache stat file(%s).", path.c_str()); } } fclose(file); @@ -576,7 +557,7 @@ void FdEntity::Close(void) int FdEntity::Dup(void) { - FGPRINT2(" FdEntity::Dup[path=%s][fd=%d][refcnt=%d]\n", path.c_str(), fd, (-1 != fd ? refcnt + 1 : refcnt)); + FPRNINFO("[path=%s][fd=%d][refcnt=%d]", path.c_str(), fd, (-1 != fd ? refcnt + 1 : refcnt)); if(-1 != fd){ AutoLock auto_lock(&fdent_lock); @@ -592,7 +573,7 @@ int FdEntity::Open(ssize_t size, time_t time) bool is_truncate = false; // need to truncate bool init_value = false; // value for pagelist - FGPRINT2(" FdEntity::Open[path=%s][fd=%d][size=%zd][time=%zd]\n", path.c_str(), fd, size, time); + FPRNINFO("[path=%s][fd=%d][size=%zd][time=%zd]", path.c_str(), fd, size, time); if(-1 != fd){ // already opened, needs to increment refcnt. @@ -613,8 +594,7 @@ int FdEntity::Open(ssize_t size, time_t time) struct stat st; memset(&st, 0, sizeof(struct stat)); if(-1 == fstat(fd, &st)){ - FGPRINT("FdEntity::Open: fstat is failed. errno(%d)\n", errno); - SYSLOGERR("fstat is failed. errno(%d)", errno); + DPRN("fstat is failed. errno(%d)", errno); fclose(file); file = NULL; fd = -1; @@ -634,8 +614,7 @@ int FdEntity::Open(ssize_t size, time_t time) }else{ // file does not exist -> create & open if(-1 == (fd = open(cachepath.c_str(), O_CREAT|O_RDWR|O_TRUNC, 0600))){ - FGPRINT("FdEntity::Open: failed to open file(%s). errno(%d)\n", cachepath.c_str(), errno); - SYSLOGERR("failed to open file(%s). errno(%d)", cachepath.c_str(), errno); + DPRN("failed to open file(%s). errno(%d)", cachepath.c_str(), errno); return (0 == errno ? -EIO : -errno); } if(-1 == size){ @@ -647,8 +626,7 @@ int FdEntity::Open(ssize_t size, time_t time) } // make file pointer(for being same tmpfile) if(NULL == (file = fdopen(fd, "wb"))){ - FGPRINT("FdEntity::Open: failed to get fileno(%s). errno(%d)\n", cachepath.c_str(), errno); - SYSLOGERR("failed to get fileno(%s). errno(%d)", cachepath.c_str(), errno); + DPRN("failed to get fileno(%s). errno(%d)", cachepath.c_str(), errno); close(fd); fd = -1; return (0 == errno ? -EIO : -errno); @@ -657,8 +635,7 @@ int FdEntity::Open(ssize_t size, time_t time) }else{ // open temporary file if(NULL == (file = tmpfile()) || -1 ==(fd = fileno(file))){ - FGPRINT("FdEntity::Open: failed to open tmp file. err(%d)\n", errno); - SYSLOGERR("failed to open tmp file. err(%d)", errno); + DPRN("failed to open tmp file. err(%d)", errno); if(file){ fclose(file); file = NULL; @@ -676,8 +653,7 @@ int FdEntity::Open(ssize_t size, time_t time) // truncate if(is_truncate){ if(0 != ftruncate(fd, size) || 0 != fsync(fd)){ - FGPRINT("FdEntity::Open: ftruncate(%s) or fsync returned err(%d)\n", cachepath.c_str(), errno); - SYSLOGERR("ftruncate(%s) or fsync returned err(%d)", cachepath.c_str(), errno); + DPRN("ftruncate(%s) or fsync returned err(%d)", cachepath.c_str(), errno); fclose(file); file = NULL; fd = -1; @@ -688,8 +664,7 @@ int FdEntity::Open(ssize_t size, time_t time) // set mtime if(-1 != time){ if(0 != SetMtime(time)){ - FGPRINT("FdEntity::Open: failed to set mtime. errno(%d)\n", errno); - SYSLOGERR("failed to set mtime. errno(%d)", errno); + DPRN("failed to set mtime. errno(%d)", errno); fclose(file); file = NULL; fd = -1; @@ -712,7 +687,7 @@ int FdEntity::Open(ssize_t size, time_t time) int FdEntity::SetMtime(time_t time) { - FGPRINT2(" FdEntity::SetMtime[path=%s][fd=%d][time=%zd]\n", path.c_str(), fd, time); + FPRNINFO("[path=%s][fd=%d][time=%zd]", path.c_str(), fd, time); if(-1 == time){ return 0; @@ -726,8 +701,7 @@ int FdEntity::SetMtime(time_t time) tv[1].tv_sec = tv[0].tv_sec; tv[1].tv_usec= 0L; if(-1 == futimes(fd, tv)){ - FGPRINT("FdEntity::Set: futimes failed. errno(%d)\n", errno); - SYSLOGERR("futimes failed. errno(%d)", errno); + DPRN("futimes failed. errno(%d)", errno); return -errno; } }else if(0 < cachepath.size()){ @@ -736,8 +710,7 @@ int FdEntity::SetMtime(time_t time) n_mtime.modtime = time; n_mtime.actime = time; if(-1 == utime(cachepath.c_str(), &n_mtime)){ - //FGPRINT("FdEntity::Set: utime failed. errno(%d)\n", errno); - //SYSLOGERR("utime failed. errno(%d)", errno); + DPRNINFO("utime failed. errno(%d)", errno); return -errno; } } @@ -775,8 +748,7 @@ bool FdEntity::GetStats(struct stat& st) memset(&st, 0, sizeof(struct stat)); if(-1 == fstat(fd, &st)){ - FGPRINT("FdEntity::GetStats: fstat failed. errno(%d)\n", errno); - SYSLOGERR("fstat failed. errno(%d)", errno); + DPRN("fstat failed. errno(%d)", errno); return false; } return true; @@ -784,7 +756,7 @@ bool FdEntity::GetStats(struct stat& st) bool FdEntity::SetAllStatus(bool is_enable) { - FGPRINT2(" FdEntity::SetAllStatus[path=%s][fd=%d][%s]\n", path.c_str(), fd, is_enable ? "enable" : "disable"); + FPRNINFO("[path=%s][fd=%d][%s]", path.c_str(), fd, is_enable ? "enable" : "disable"); if(-1 == fd){ return false; @@ -795,8 +767,7 @@ bool FdEntity::SetAllStatus(bool is_enable) struct stat st; memset(&st, 0, sizeof(struct stat)); if(-1 == fstat(fd, &st)){ - FGPRINT("FdEntity::SetAllEnable: fstat is failed. errno(%d)\n", errno); - SYSLOGERR("fstat is failed. errno(%d)", errno); + DPRN("fstat is failed. errno(%d)", errno); return false; } // Reinit @@ -809,7 +780,7 @@ int FdEntity::Load(off_t start, ssize_t size) { int result = 0; - FGPRINT2(" FdEntity::Load[path=%s][fd=%d][offset=%zd][size=%zd]\n", path.c_str(), fd, start, size); + FPRNINFO("[path=%s][fd=%d][offset=%zd][size=%zd]", path.c_str(), fd, start, size); if(-1 == fd){ return -EBADF; @@ -856,7 +827,7 @@ bool FdEntity::LoadFull(size_t* size, bool force_load) { int result; - FGPRINT2(" FdEntity::LoadFull[path=%s][fd=%d]\n", path.c_str(), fd); + FPRNINFO("[path=%s][fd=%d]", path.c_str(), fd); if(-1 == fd){ if(0 != Open()){ @@ -870,8 +841,7 @@ bool FdEntity::LoadFull(size_t* size, bool force_load) // TODO: possibly do background for delay loading // if(0 != (result = Load(0, pagelist.Size()))){ - FGPRINT("FdEntity::FullDownload: could not download, result(%d)\n", result); - SYSLOGERR("could not download, result(%d)", result); + DPRN("could not download, result(%d)", result); return false; } if(is_modify){ @@ -888,7 +858,7 @@ int FdEntity::RowFlush(const char* tpath, headers_t& meta, bool ow_sse_flg, bool { int result; - FGPRINT2(" FdEntity::RowFlush[tpath=%s][path=%s][fd=%d]\n", SAFESTRPTR(tpath), path.c_str(), fd); + FPRNINFO("[tpath=%s][path=%s][fd=%d]", SAFESTRPTR(tpath), path.c_str(), fd); if(-1 == fd){ return -EBADF; @@ -921,8 +891,7 @@ int FdEntity::RowFlush(const char* tpath, headers_t& meta, bool ow_sse_flg, bool // seek to head of file. if(0 != lseek(fd, 0, SEEK_SET)){ - FGPRINT("FdEntity::RowFlush: lseek error(%d)\n", errno); - SYSLOGERR("lseek error(%d)\n", errno); + DPRN("lseek error(%d)", errno); return -errno; } @@ -943,8 +912,7 @@ int FdEntity::RowFlush(const char* tpath, headers_t& meta, bool ow_sse_flg, bool // seek to head of file. if(0 == result && 0 != lseek(fd, 0, SEEK_SET)){ - FGPRINT("FdEntity::RowFlush: lseek error(%d)\n", errno); - SYSLOGERR("lseek error(%d)\n", errno); + DPRN("lseek error(%d)", errno); return -errno; } @@ -959,7 +927,7 @@ ssize_t FdEntity::Read(char* bytes, off_t start, size_t size, bool force_load) int result; ssize_t rsize; - FGPRINT2(" FdEntity::Read[path=%s][fd=%d][offset=%zd][size=%zd]\n", path.c_str(), fd, start, size); + FPRNINFO("[path=%s][fd=%d][offset=%zd][size=%zd]", path.c_str(), fd, start, size); if(-1 == fd){ return -EBADF; @@ -970,8 +938,7 @@ ssize_t FdEntity::Read(char* bytes, off_t start, size_t size, bool force_load) } // Loading if(0 != (result = Load(start, size))){ - FGPRINT("FdEntity::Read: could not download. start(%zd), size(%zd), errno(%d)\n", start, size, result); - SYSLOGERR("could not download. start(%zd), size(%zd), errno(%d)", start, size, result); + DPRN("could not download. start(%zd), size(%zd), errno(%d)", start, size, result); return -EIO; } // Reading @@ -979,8 +946,7 @@ ssize_t FdEntity::Read(char* bytes, off_t start, size_t size, bool force_load) AutoLock auto_lock(&fdent_lock); if(-1 == (rsize = pread(fd, bytes, size, start))){ - FGPRINT("FdEntity::Read: pread failed. errno(%d)\n", errno); - SYSLOGERR("pread failed. errno(%d)", errno); + DPRN("pread failed. errno(%d)", errno); return -errno; } } @@ -992,7 +958,7 @@ ssize_t FdEntity::Write(const char* bytes, off_t start, size_t size) int result; ssize_t wsize; - FGPRINT2(" FdEntity::Write[path=%s][fd=%d][offset=%zd][size=%zd]\n", path.c_str(), fd, start, size); + FPRNINFO("[path=%s][fd=%d][offset=%zd][size=%zd]", path.c_str(), fd, start, size); if(-1 == fd){ return -EBADF; @@ -1000,8 +966,7 @@ ssize_t FdEntity::Write(const char* bytes, off_t start, size_t size) // Load unitialized area which starts from 0 to (start + size) before writing. if(0 != (result = Load(0, start))){ - FGPRINT("FdEntity::Write: failed to load uninitialized area before writing(errno=%d)\n", result); - SYSLOGERR("failed to load uninitialized area before writing(errno=%d)", result); + DPRN("failed to load uninitialized area before writing(errno=%d)", result); return static_cast(result); } @@ -1010,8 +975,7 @@ ssize_t FdEntity::Write(const char* bytes, off_t start, size_t size) AutoLock auto_lock(&fdent_lock); if(-1 == (wsize = pwrite(fd, bytes, size, start))){ - FGPRINT("FdEntity::Write: pwrite failed. errno(%d)\n", errno); - SYSLOGERR("pwrite failed. errno(%d)", errno); + DPRN("pwrite failed. errno(%d)", errno); return -errno; } if(!is_modify){ @@ -1071,7 +1035,7 @@ bool FdManager::DeleteCacheDirectory(void) int FdManager::DeleteCacheFile(const char* path) { - FGPRINT2(" FdManager::DeleteCacheFile[path=%s]\n", SAFESTRPTR(path)); + FPRNINFO("[path=%s]", SAFESTRPTR(path)); if(!path){ return -EIO; @@ -1085,13 +1049,11 @@ int FdManager::DeleteCacheFile(const char* path) } int result = 0; if(0 != unlink(cache_path.c_str())){ - //FGPRINT("FdManager::DeleteCacheFile: failed to delete file(%s): errno=%d\n", path, errno); - //SYSLOGERR("failed to delete file(%s): errno=%d", path, errno); + DPRNINFO("failed to delete file(%s): errno=%d", path, errno); result = -errno; } if(!CacheFileStat::DeleteCacheFileStat(path)){ - //FGPRINT("FdManager::DeleteCacheFile: failed to delete stat file(%s): errno=%d\n", path, errno); - //SYSLOGERR("failed to delete stat file(%s): errno=%d", path, errno); + DPRNINFO("failed to delete stat file(%s): errno=%d", path, errno); if(0 != errno){ result = -errno; }else{ @@ -1130,8 +1092,7 @@ FdManager::FdManager() FdManager::is_lock_init = true; }catch(exception& e){ FdManager::is_lock_init = false; - FGPRINT("FdManager::FdManager: failed to init mutex\n"); - SYSLOGERR("failed to init mutex"); + DPRNCRIT("failed to init mutex"); } }else{ assert(false); @@ -1151,8 +1112,7 @@ FdManager::~FdManager() try{ pthread_mutex_destroy(&FdManager::fd_manager_lock); }catch(exception& e){ - FGPRINT("FdManager::FdManager: failed to init mutex\n"); - SYSLOGERR("failed to init mutex"); + DPRNCRIT("failed to init mutex"); } FdManager::is_lock_init = false; } @@ -1163,7 +1123,7 @@ FdManager::~FdManager() FdEntity* FdManager::GetFdEntity(const char* path) { - FGPRINT2(" FdManager::GetFdEntity[path=%s]\n", SAFESTRPTR(path)); + FPRNINFO("[path=%s]", SAFESTRPTR(path)); if(!path || '\0' == path[0]){ return NULL; @@ -1181,7 +1141,7 @@ FdEntity* FdManager::Open(const char* path, ssize_t size, time_t time, bool forc { FdEntity* ent; - FGPRINT2(" FdManager::Open[path=%s][size=%zd][time=%zd]\n", SAFESTRPTR(path), size, time); + FPRNINFO("[path=%s][size=%zd][time=%zd]", SAFESTRPTR(path), size, time); if(!path || '\0' == path[0]){ return NULL; @@ -1198,8 +1158,7 @@ FdEntity* FdManager::Open(const char* path, ssize_t size, time_t time, bool forc // not found string cache_path = ""; if(!force_tmpfile && !FdManager::MakeCachePath(path, cache_path, true)){ - FGPRINT("FdManager::GetFd: failed to make cache path for object(%s).\n", path); - SYSLOGERR("failed to make cache path for object(%s).", path); + DPRN("failed to make cache path for object(%s).", path); return NULL; } // make new obj @@ -1219,7 +1178,7 @@ FdEntity* FdManager::Open(const char* path, ssize_t size, time_t time, bool forc bool FdManager::Close(FdEntity* ent) { - FGPRINT2(" FdManager::Close[ent->file=%s][ent->fd=%d]\n", ent ? ent->GetPath() : "", ent ? ent->GetFd() : -1); + FPRNINFO("[ent->file=%s][ent->fd=%d]", ent ? ent->GetPath() : "", ent ? ent->GetFd() : -1); AutoLock auto_lock(&FdManager::fd_manager_lock); diff --git a/src/s3fs.cpp b/src/s3fs.cpp index f40d7d4..c227a8e 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -305,7 +305,7 @@ static int get_object_attribute(const char* path, struct stat* pstbuf, headers_t bool forcedir = false; string::size_type Pos; -//FGPRINT(" get_object_attribute[path=%s]\n", path); + FPRNINFO("[path=%s]", path); if(!path || '\0' == path[0]){ return -ENOENT; @@ -412,20 +412,20 @@ static int get_object_attribute(const char* path, struct stat* pstbuf, headers_t if(0 != StatCache::getStatCacheData()->GetCacheSize()){ // add into stat cache if(!StatCache::getStatCacheData()->AddStat(strpath, (*pheader), forcedir)){ - FGPRINT(" get_object_attribute: failed adding stat cache [path=%s]\n", strpath.c_str()); + DPRN("failed adding stat cache [path=%s]", strpath.c_str()); return -ENOENT; } if(!StatCache::getStatCacheData()->GetStat(strpath, pstat, pheader, overcheck, pisforce)){ // There is not in cache.(why?) -> retry to convert. if(!convert_header_to_stat(strpath.c_str(), (*pheader), pstat, forcedir)){ - FGPRINT(" get_object_attribute: failed convert headers to stat[path=%s]\n", strpath.c_str()); + DPRN("failed convert headers to stat[path=%s]", strpath.c_str()); return -ENOENT; } } }else{ // cache size is Zero -> only convert. if(!convert_header_to_stat(strpath.c_str(), (*pheader), pstat, forcedir)){ - FGPRINT(" get_object_attribute: failed convert headers to stat[path=%s]\n", strpath.c_str()); + DPRN("failed convert headers to stat[path=%s]", strpath.c_str()); return -ENOENT; } } @@ -449,7 +449,7 @@ static int check_object_access(const char* path, int mask, struct stat* pstbuf) struct stat* pst = (pstbuf ? pstbuf : &st); struct fuse_context* pcxt; -//FGPRINT(" check_object_access[path=%s]\n", path); + FPRNINFO("[path=%s]", path); if(NULL == (pcxt = fuse_get_context())){ return -EIO; @@ -521,7 +521,7 @@ static int check_object_owner(const char* path, struct stat* pstbuf) struct stat* pst = (pstbuf ? pstbuf : &st); struct fuse_context* pcxt; -//FGPRINT(" check_object_owner[path=%s]\n", path); + FPRNINFO("[path=%s]", path); if(NULL == (pcxt = fuse_get_context())){ return -EIO; @@ -553,7 +553,7 @@ static int check_parent_object_access(const char* path, int mask) string parent; int result; -//FGPRINT(" check_parent_object_access[path=%s]\n", path); + FPRNINFO("[path=%s]", path); if(0 == strcmp(path, "/") || 0 == strcmp(path, ".")){ // path is mount point. @@ -590,7 +590,7 @@ static FdEntity* get_local_fent(const char* path, bool is_load) struct stat stobj; FdEntity* ent; - FGPRINT(" get_local_fent[path=%s]\n", path); + FPRNNN("[path=%s]", path); if(0 != get_object_attribute(path, &stobj)){ return NULL; @@ -601,14 +601,12 @@ static FdEntity* get_local_fent(const char* path, bool is_load) bool force_tmpfile = S_ISREG(stobj.st_mode) ? false : true; if(NULL == (ent = FdManager::get()->Open(path, stobj.st_size, mtime, force_tmpfile, true))){ - FGPRINT(" get_local_fent: Coult not open file. errno(%d)\n", errno); - SYSLOGERR("Coult not open file. errno(%d)", errno); + DPRN("Coult not open file. errno(%d)", errno); return NULL; } // load if(is_load && !ent->LoadFull()){ - FGPRINT(" get_local_fent: Coult not load file. errno(%d)\n", errno); - SYSLOGERR("Coult not load file. errno(%d)", errno); + DPRN("Coult not load file. errno(%d)", errno); FdManager::get()->Close(ent); return NULL; } @@ -627,7 +625,7 @@ static int put_headers(const char* path, headers_t& meta, bool ow_sse_flg) S3fsCurl s3fscurl; struct stat buf; - FGPRINT(" put_headers[path=%s]\n", path); + FPRNNN("[path=%s]", path); // files larger than 5GB must be modified via the multipart interface // *** If there is not target object(a case of move command), @@ -666,7 +664,7 @@ static int s3fs_getattr(const char* path, struct stat* stbuf) { int result; - FGPRINT("s3fs_getattr[path=%s]\n", path); + FPRN("[path=%s]", path); // check parent directory attribute. if(0 != (result = check_parent_object_access(path, X_OK))){ @@ -698,15 +696,13 @@ static int s3fs_readlink(const char* path, char* buf, size_t size) // Open FdEntity* ent; if(NULL == (ent = get_local_fent(path))){ - FGPRINT("s3fs_readlink: could not get fent(file=%s)\n", path); - SYSLOGERR("could not get fent(file=%s)", path); + DPRN("could not get fent(file=%s)", path); return -EIO; } // Get size size_t readsize; if(!ent->GetSize(readsize)){ - FGPRINT("s3fs_readlink: could not get file size(file=%s)\n", path); - SYSLOGERR("could not get file size(file=%s)", path); + DPRN("could not get file size(file=%s)", path); FdManager::get()->Close(ent); return -EIO; } @@ -716,8 +712,7 @@ static int s3fs_readlink(const char* path, char* buf, size_t size) // Read ssize_t ressize; if(0 > (ressize = ent->Read(buf, 0, readsize))){ - FGPRINT("s3fs_readlink: could not read file(file=%s, errno=%zd)\n", path, ressize); - SYSLOGERR("could not read file(file=%s, errno=%zd)", path, ressize); + DPRN("could not read file(file=%s, errno=%zd)", path, ressize); FdManager::get()->Close(ent); return static_cast(ressize); } @@ -731,7 +726,7 @@ static int s3fs_readlink(const char* path, char* buf, size_t size) // common function for creation of a plain object static int create_file_object(const char* path, mode_t mode, uid_t uid, gid_t gid) { - FGPRINT(" create_file_object[path=%s][mode=%d]\n", path, mode); + FPRNNN("[path=%s][mode=%d]", path, mode); headers_t meta; meta["Content-Type"] = S3fsCurl::LookupMimeType(string(path)); @@ -750,15 +745,14 @@ static int s3fs_mknod(const char *path, mode_t mode, dev_t rdev) headers_t meta; struct fuse_context* pcxt; - FGPRINT("s3fs_mknod[path=%s][mode=0%o][dev=%lu]\n", path, mode, rdev); + FPRN("[path=%s][mode=0%o][dev=%lu]", path, mode, rdev); if(NULL == (pcxt = fuse_get_context())){ return -EIO; } if(0 != (result = create_file_object(path, mode, pcxt->uid, pcxt->gid))){ - FGPRINT("s3fs_mknod: could not create object for special file(result=%d)\n", result); - SYSLOGERR("could not create object for special file(result=%d)", result); + DPRN("could not create object for special file(result=%d)", result); return result; } StatCache::getStatCacheData()->DelStat(path); @@ -772,7 +766,7 @@ static int s3fs_create(const char* path, mode_t mode, struct fuse_file_info* fi) headers_t meta; struct fuse_context* pcxt; - FGPRINT("s3fs_create[path=%s][mode=%d][flags=%d]\n", path, mode, fi->flags); + FPRN("[path=%s][mode=%d][flags=%d]", path, mode, fi->flags); if(NULL == (pcxt = fuse_get_context())){ return -EIO; @@ -807,7 +801,7 @@ static int s3fs_create(const char* path, mode_t mode, struct fuse_file_info* fi) static int create_directory_object(const char* path, mode_t mode, time_t time, uid_t uid, gid_t gid) { - FGPRINT(" create_directory_object[path=%s][mode=%d][time=%lu][uid=%d][gid=%d]\n", path, mode, time, uid, gid); + FPRNN("[path=%s][mode=%d][time=%lu][uid=%d][gid=%d]", path, mode, time, uid, gid); if(!path || '\0' == path[0]){ return -1; @@ -833,7 +827,7 @@ static int s3fs_mkdir(const char* path, mode_t mode) int result; struct fuse_context* pcxt; - FGPRINT("s3fs_mkdir[path=%s][mode=%d]\n", path, mode); + FPRN("[path=%s][mode=%d]", path, mode); if(NULL == (pcxt = fuse_get_context())){ return -EIO; @@ -859,7 +853,7 @@ static int s3fs_unlink(const char* path) { int result; - FGPRINT("s3fs_unlink[path=%s]\n", path); + FPRN("[path=%s]", path); if(0 != (result = check_parent_object_access(path, W_OK | X_OK))){ return result; @@ -878,7 +872,7 @@ static int directory_empty(const char* path) S3ObjList head; if((result = list_bucket(path, head, "/")) != 0){ - FGPRINT(" directory_empty - list_bucket returns error.\n"); + DPRNNN("list_bucket returns error."); return result; } if(!head.IsEmpty()){ @@ -893,7 +887,7 @@ static int s3fs_rmdir(const char* path) string strpath; struct stat stbuf; - FGPRINT("s3fs_rmdir [path=%s]\n", path); + FPRN("[path=%s]", path); if(0 != (result = check_parent_object_access(path, W_OK | X_OK))){ return result; @@ -946,7 +940,7 @@ static int s3fs_symlink(const char* from, const char* to) int result; struct fuse_context* pcxt; - FGPRINT("s3fs_symlink[from=%s][to=%s]\n", from, to); + FPRN("[from=%s][to=%s]", from, to); if(NULL == (pcxt = fuse_get_context())){ return -EIO; @@ -971,22 +965,19 @@ static int s3fs_symlink(const char* from, const char* to) // open tmpfile FdEntity* ent; if(NULL == (ent = FdManager::get()->Open(to, 0, -1, true, true))){ - FGPRINT("s3fs_symlink: could not open tmpfile(errno=%d)\n", errno); - SYSLOGERR("could not open tmpfile(errno=%d)", errno); + DPRN("could not open tmpfile(errno=%d)", errno); return -errno; } // write ssize_t from_size = strlen(from); if(from_size != ent->Write(from, 0, from_size)){ - FGPRINT("s3fs_symlink: could not write tmpfile(errno=%d)\n", errno); - SYSLOGERR("could not write tmpfile(errno=%d)", errno); + DPRN("could not write tmpfile(errno=%d)", errno); FdManager::get()->Close(ent); return -errno; } // upload if(0 != (result = ent->Flush(headers, true, true))){ - FGPRINT("s3fs_symlink: could not upload tmpfile(result=%d)\n", result); - SYSLOGERR("could not upload tmpfile(result=%d)", result); + DPRN("could not upload tmpfile(result=%d)", result); } FdManager::get()->Close(ent); @@ -1001,8 +992,7 @@ static int rename_object(const char* from, const char* to) string s3_realpath; headers_t meta; - FGPRINT("rename_object [from=%s] [to=%s]\n", from , to); - SYSLOGDBG("rename_object [from=%s] [to=%s]", from, to); + FPRNN("[from=%s][to=%s]", from , to); if(0 != (result = check_parent_object_access(to, W_OK | X_OK))){ // not permmit writing "to" object parent dir. @@ -1035,8 +1025,7 @@ static int rename_object_nocopy(const char* from, const char* to) int result; headers_t meta; - FGPRINT("rename_object_nocopy [from=%s] [to=%s]\n", from , to); - SYSLOGDBG("rename_object_nocopy [from=%s] [to=%s]", from, to); + FPRNN("[from=%s][to=%s]", from , to); if(0 != (result = check_parent_object_access(to, W_OK | X_OK))){ // not permmit writing "to" object parent dir. @@ -1058,15 +1047,13 @@ static int rename_object_nocopy(const char* from, const char* to) // open & load FdEntity* ent; if(NULL == (ent = get_local_fent(from, true))){ - FGPRINT(" rename_object_nocopy: could not open and read file(%s)\n", from); - SYSLOGERR("could not open and read file(%s)", from); + DPRN("could not open and read file(%s)", from); return -EIO; } // upload if(0 != (result = ent->RowFlush(to, meta, false, true))){ - FGPRINT(" rename_object_nocopy: could not upload file(%s): result=%d\n", to, result); - SYSLOGERR("could not upload file(%s): result=%d", to, result); + DPRN("could not upload file(%s): result=%d", to, result); FdManager::get()->Close(ent); return result; } @@ -1088,8 +1075,7 @@ static int rename_large_object(const char* from, const char* to) struct stat buf; headers_t meta; - FGPRINT("rename_large_object [from=%s] [to=%s]\n", from , to); - SYSLOGDBG("rename_large_object [from=%s] [to=%s]", from, to); + FPRNN("[from=%s][to=%s]", from , to); if(0 != (result = check_parent_object_access(to, W_OK | X_OK))){ // not permmit writing "to" object parent dir. @@ -1118,8 +1104,7 @@ static int clone_directory_object(const char* from, const char* to) int result = -1; struct stat stbuf; - FGPRINT("clone_directory_object [from=%s] [to=%s]\n", from, to); - SYSLOGDBG("clone_directory_object [from=%s] [to=%s]", from, to); + FPRNN("[from=%s][to=%s]", from, to); // get target's attributes if(0 != (result = get_object_attribute(from, &stbuf))){ @@ -1149,8 +1134,7 @@ static int rename_directory(const char* from, const char* to) int result; bool is_dir; - FGPRINT("rename_directory[from=%s][to=%s]\n", from, to); - SYSLOGDBG("rename_directory [from=%s] [to=%s]", from, to); + FPRNN("[from=%s][to=%s]", from, to); // // Initiate and Add base directory into MVNODE struct. @@ -1176,7 +1160,7 @@ static int rename_directory(const char* from, const char* to) // No delimiter is specified, the result(head) is all object keys. // (CommonPrefixes is empty, but all object is listed in Key.) if(0 != (result = list_bucket(basepath.c_str(), head, NULL))){ - FGPRINT(" rename_directory list_bucket returns error.\n"); + DPRNNN("list_bucket returns error."); return result; } head.GetNameList(headlist); // get name without "/". @@ -1192,13 +1176,13 @@ static int rename_directory(const char* from, const char* to) // Check subdirectory. StatCache::getStatCacheData()->HasStat(from_name, etag.c_str()); // Check ETag if(0 != get_object_attribute(from_name.c_str(), &stbuf, NULL)){ - FGPRINT(" rename_directory - failed to get %s object attribute.\n", from_name.c_str()); + DPRNNN("failed to get %s object attribute.", from_name.c_str()); continue; } if(S_ISDIR(stbuf.st_mode)){ is_dir = true; if(0 != chk_dir_object_type(from_name.c_str(), newpath, from_name, nowcache, NULL, &DirType) || DIRTYPE_UNKNOWN == DirType){ - FGPRINT(" rename_directory - failed to get %s%s object directory type.\n", basepath.c_str(), (*liter).c_str()); + DPRNNN("failed to get %s%s object directory type.", basepath.c_str(), (*liter).c_str()); continue; } if(DIRTYPE_NOOBJ != DirType){ @@ -1225,8 +1209,7 @@ static int rename_directory(const char* from, const char* to) for(mn_cur = mn_head; mn_cur; mn_cur = mn_cur->next){ if(mn_cur->is_dir && mn_cur->old_path && '\0' != mn_cur->old_path[0]){ if(0 != (result = clone_directory_object(mn_cur->old_path, mn_cur->new_path))){ - FGPRINT(" rename_directory - failed(%d) to rename %s directory object to %s.\n", result, mn_cur->old_path, mn_cur->new_path); - SYSLOGERR("clone_directory_object returned an error(%d)", result); + DPRN("clone_directory_object returned an error(%d)", result); free_mvnodes(mn_head); return -EIO; } @@ -1243,8 +1226,7 @@ static int rename_directory(const char* from, const char* to) result = rename_object_nocopy(mn_cur->old_path, mn_cur->new_path); } if(0 != result){ - FGPRINT(" rename_directory - failed(%d) to rename %s object to %s.\n", result, mn_cur->old_path, mn_cur->new_path); - SYSLOGERR("rename_object returned an error(%d)", result); + DPRN("rename_object returned an error(%d)", result); free_mvnodes(mn_head); return -EIO; } @@ -1256,8 +1238,7 @@ static int rename_directory(const char* from, const char* to) if(mn_cur->is_dir && mn_cur->old_path && '\0' != mn_cur->old_path[0]){ if(!(mn_cur->is_normdir)){ if(0 != (result = s3fs_rmdir(mn_cur->old_path))){ - FGPRINT(" rename_directory - failed(%d) to remove %s directory object.\n", result, mn_cur->old_path); - SYSLOGERR("s3fs_rmdir returned an error(%d)", result); + DPRN("s3fs_rmdir returned an error(%d)", result); free_mvnodes(mn_head); return -EIO; } @@ -1277,8 +1258,7 @@ static int s3fs_rename(const char* from, const char* to) struct stat buf; int result; - FGPRINT("s3fs_rename [from=%s] [to=%s]\n", from, to); - SYSLOGDBG("s3fs_rename [from=%s] [to=%s]", from, to); + FPRN("[from=%s][to=%s]", from, to); if(0 != (result = check_parent_object_access(to, W_OK | X_OK))){ // not permmit writing "to" object parent dir. @@ -1309,7 +1289,7 @@ static int s3fs_rename(const char* from, const char* to) static int s3fs_link(const char* from, const char* to) { - FGPRINT("s3fs_link[from=%s][to=%s]\n", from, to); + FPRN("[from=%s][to=%s]", from, to); return -EPERM; } @@ -1323,7 +1303,7 @@ static int s3fs_chmod(const char* path, mode_t mode) struct stat stbuf; int nDirType = DIRTYPE_UNKNOWN; - FGPRINT("s3fs_chmod [path=%s] [mode=%d]\n", path, mode); + FPRN("[path=%s][mode=%d]", path, mode); if(0 != (result = check_parent_object_access(path, X_OK))){ return result; @@ -1385,7 +1365,7 @@ static int s3fs_chmod_nocopy(const char* path, mode_t mode) struct stat stbuf; int nDirType = DIRTYPE_UNKNOWN; - FGPRINT("s3fs_chmod_nocopy [path=%s] [mode=%d]\n", path, mode); + FPRNN("[path=%s][mode=%d]", path, mode); if(0 != (result = check_parent_object_access(path, X_OK))){ return result; @@ -1432,15 +1412,13 @@ static int s3fs_chmod_nocopy(const char* path, mode_t mode) // open & load FdEntity* ent; if(NULL == (ent = get_local_fent(strpath.c_str(), true))){ - FGPRINT(" s3fs_chmod_nocopy: could not open and read file(%s)\n", strpath.c_str()); - SYSLOGERR("could not open and read file(%s)", strpath.c_str()); + DPRN("could not open and read file(%s)", strpath.c_str()); return -EIO; } // upload if(0 != (result = ent->Flush(meta, false, true))){ - FGPRINT(" s3fs_chmod_nocopy: could not upload file(%s): result=%d\n", strpath.c_str(), result); - SYSLOGERR("could not upload file(%s): result=%d", strpath.c_str(), result); + DPRN("could not upload file(%s): result=%d", strpath.c_str(), result); FdManager::get()->Close(ent); return result; } @@ -1461,7 +1439,7 @@ static int s3fs_chown(const char* path, uid_t uid, gid_t gid) struct stat stbuf; int nDirType = DIRTYPE_UNKNOWN; - FGPRINT("s3fs_chown [path=%s] [uid=%d] [gid=%d]\n", path, uid, gid); + FPRN("[path=%s][uid=%d][gid=%d]", path, uid, gid); if(0 != (result = check_parent_object_access(path, X_OK))){ return result; @@ -1538,7 +1516,7 @@ static int s3fs_chown_nocopy(const char* path, uid_t uid, gid_t gid) struct stat stbuf; int nDirType = DIRTYPE_UNKNOWN; - FGPRINT("s3fs_chown_nocopy [path=%s] [uid=%d] [gid=%d]\n", path, uid, gid); + FPRNN("[path=%s][uid=%d][gid=%d]", path, uid, gid); if(0 != (result = check_parent_object_access(path, X_OK))){ return result; @@ -1595,15 +1573,13 @@ static int s3fs_chown_nocopy(const char* path, uid_t uid, gid_t gid) // open & load FdEntity* ent; if(NULL == (ent = get_local_fent(strpath.c_str(), true))){ - FGPRINT(" s3fs_chown_nocopy: could not open and read file(%s)\n", strpath.c_str()); - SYSLOGERR("could not open and read file(%s)", strpath.c_str()); + DPRN("could not open and read file(%s)", strpath.c_str()); return -EIO; } // upload if(0 != (result = ent->Flush(meta, false, true))){ - FGPRINT(" s3fs_chown_nocopy: could not upload file(%s): result=%d\n", strpath.c_str(), result); - SYSLOGERR("could not upload file(%s): result=%d", strpath.c_str(), result); + DPRN("could not upload file(%s): result=%d", strpath.c_str(), result); FdManager::get()->Close(ent); return result; } @@ -1624,7 +1600,7 @@ static int s3fs_utimens(const char* path, const struct timespec ts[2]) struct stat stbuf; int nDirType = DIRTYPE_UNKNOWN; - FGPRINT("s3fs_utimens[path=%s][mtime=%zd]\n", path, ts[1].tv_sec); + FPRN("[path=%s][mtime=%zd]", path, ts[1].tv_sec); if(0 != (result = check_parent_object_access(path, X_OK))){ return result; @@ -1685,7 +1661,7 @@ static int s3fs_utimens_nocopy(const char* path, const struct timespec ts[2]) struct stat stbuf; int nDirType = DIRTYPE_UNKNOWN; - FGPRINT("s3fs_utimens_nocopy [path=%s][mtime=%s]\n", path, str(ts[1].tv_sec).c_str()); + FPRNN("[path=%s][mtime=%s]", path, str(ts[1].tv_sec).c_str()); if(0 != (result = check_parent_object_access(path, X_OK))){ return result; @@ -1732,23 +1708,20 @@ static int s3fs_utimens_nocopy(const char* path, const struct timespec ts[2]) // open & load FdEntity* ent; if(NULL == (ent = get_local_fent(strpath.c_str(), true))){ - FGPRINT(" s3fs_utimens_nocopy: could not open and read file(%s)\n", strpath.c_str()); - SYSLOGERR("could not open and read file(%s)", strpath.c_str()); + DPRN("could not open and read file(%s)", strpath.c_str()); return -EIO; } // set mtime if(0 != (result = ent->SetMtime(ts[1].tv_sec))){ - FGPRINT(" s3fs_utimens_nocopy: could not set mtime to file(%s): result=%d\n", strpath.c_str(), result); - SYSLOGERR("could not set mtime to file(%s): result=%d", strpath.c_str(), result); + DPRN("could not set mtime to file(%s): result=%d", strpath.c_str(), result); FdManager::get()->Close(ent); return result; } // upload if(0 != (result = ent->Flush(meta, false, true))){ - FGPRINT(" s3fs_utimens_nocopy: could not upload file(%s): result=%d\n", strpath.c_str(), result); - SYSLOGERR("could not upload file(%s): result=%d", strpath.c_str(), result); + DPRN("could not upload file(%s): result=%d", strpath.c_str(), result); FdManager::get()->Close(ent); return result; } @@ -1765,7 +1738,7 @@ static int s3fs_truncate(const char* path, off_t size) headers_t meta; FdEntity* ent = NULL; - FGPRINT("s3fs_truncate[path=%s][size=%zd]\n", path, size); + FPRN("[path=%s][size=%zd]", path, size); if(0 != (result = check_parent_object_access(path, X_OK))){ return result; @@ -1778,13 +1751,11 @@ static int s3fs_truncate(const char* path, off_t size) if(0 == (result = get_object_attribute(path, NULL, &meta))){ // Exists -> Get file(with size) if(NULL == (ent = FdManager::get()->Open(path, size, -1, false, true))){ - FGPRINT(" s3fs_truncate: could not open file(%s): errno=%d\n", path, errno); - SYSLOGERR("could not open file(%s): errno=%d", path, errno); + DPRN("could not open file(%s): errno=%d", path, errno); return -EIO; } if(!ent->Load(0, size)){ - FGPRINT(" s3fs_truncate: could not download file(%s): errno=%d\n", path, errno); - SYSLOGERR("could not download file(%s): errno=%d", path, errno); + DPRN("could not download file(%s): errno=%d", path, errno); FdManager::get()->Close(ent); return -EIO; } @@ -1792,16 +1763,14 @@ static int s3fs_truncate(const char* path, off_t size) }else{ // Not found -> Make tmpfile(with size) if(NULL == (ent = FdManager::get()->Open(path, size, -1, true, true))){ - FGPRINT(" s3fs_truncate: could not open file(%s): errno=%d\n", path, errno); - SYSLOGERR("could not open file(%s): errno=%d", path, errno); + DPRN("could not open file(%s): errno=%d", path, errno); return -EIO; } } // upload if(0 != (result = ent->Flush(meta, false, true))){ - FGPRINT(" s3fs_chmod_nocopy: could not upload file(%s): result=%d\n", path, result); - SYSLOGERR("could not upload file(%s): result=%d", path, result); + DPRN("could not upload file(%s): result=%d", path, result); FdManager::get()->Close(ent); return result; } @@ -1818,7 +1787,7 @@ static int s3fs_open(const char* path, struct fuse_file_info* fi) headers_t meta; struct stat st; - FGPRINT("s3fs_open[path=%s][flags=%d]\n", path, fi->flags); + FPRN("[path=%s][flags=%d]", path, fi->flags); int mask = (O_RDONLY != (fi->flags & O_ACCMODE) ? W_OK : R_OK); if(0 != (result = check_parent_object_access(path, X_OK))){ @@ -1854,31 +1823,27 @@ static int s3fs_read(const char* path, char* buf, size_t size, off_t offset, str { ssize_t res; - // Commented - This message is output too much - FGPRINT2("s3fs_read[path=%s][size=%zd][offset=%zd][fd=%zd]\n", path, size, offset, fi->fh); + FPRNINFO("[path=%s][size=%zd][offset=%zd][fd=%zd]", path, size, offset, fi->fh); FdEntity* ent; if(NULL == (ent = FdManager::get()->ExistOpen(path))){ - FGPRINT(" s3fs_read: could not find opened fd(%s)\n", path); - SYSLOGERR("could not find opened fd(%s)", path); + DPRN("could not find opened fd(%s)", path); return -EIO; } if(ent->GetFd() != static_cast(fi->fh)){ - FGPRINT(" s3fs_read: Warning - different fd(%d - %zd)\n", ent->GetFd(), fi->fh); - SYSLOGERR("Warning - different fd(%d - %zd)", ent->GetFd(), fi->fh); + DPRNNN("Warning - different fd(%d - %zd)", ent->GetFd(), fi->fh); } // check real file size size_t realsize = 0; if(!ent->GetSize(realsize) || 0 >= realsize){ - //FGPRINT(" s3fs_read: file size is 0, so break to read.\n"); + DPRNINFO("file size is 0, so break to read."); FdManager::get()->Close(ent); return 0; } if(0 > (res = ent->Read(buf, offset, size, false))){ - FGPRINT(" s3fs_read: failed to read file(%s). result=%zd\n", path, res); - SYSLOGERR("failed to read file(%s). result=%zd", path, res); + DPRN("failed to read file(%s). result=%zd", path, res); } FdManager::get()->Close(ent); @@ -1889,22 +1854,18 @@ static int s3fs_write(const char* path, const char* buf, size_t size, off_t offs { ssize_t res; - // Commented - This message is output too much - FGPRINT2("s3fs_write[path=%s][size=%zd][offset=%zd][fd=%zd]\n", path, size, offset, fi->fh); + FPRNINFO("[path=%s][size=%zd][offset=%zd][fd=%zd]", path, size, offset, fi->fh); FdEntity* ent; if(NULL == (ent = FdManager::get()->ExistOpen(path))){ - FGPRINT(" s3fs_write: could not find opened fd(%s)\n", path); - SYSLOGERR("could not find opened fd(%s)", path); + DPRN("could not find opened fd(%s)", path); return -EIO; } if(ent->GetFd() != static_cast(fi->fh)){ - FGPRINT(" s3fs_write: Warning - different fd(%d - %zd)\n", ent->GetFd(), fi->fh); - SYSLOGERR("Warning - different fd(%d - %zd)", ent->GetFd(), fi->fh); + DPRNNN("Warning - different fd(%d - %zd)", ent->GetFd(), fi->fh); } if(0 > (res = ent->Write(buf, offset, size))){ - FGPRINT(" s3fs_write: failed to write file(%s). result=%zd\n", path, res); - SYSLOGERR("failed to write file(%s). result=%zd", path, res); + DPRN("failed to write file(%s). result=%zd", path, res); } FdManager::get()->Close(ent); @@ -1926,7 +1887,7 @@ static int s3fs_flush(const char* path, struct fuse_file_info* fi) { int result; - FGPRINT("s3fs_flush[path=%s][fd=%zd]\n", path, fi->fh); + FPRN("[path=%s][fd=%zd]", path, fi->fh); int mask = (O_RDONLY != (fi->flags & O_ACCMODE) ? W_OK : R_OK); if(0 != (result = check_parent_object_access(path, X_OK))){ @@ -1964,25 +1925,22 @@ static int s3fs_flush(const char* path, struct fuse_file_info* fi) static int s3fs_release(const char* path, struct fuse_file_info* fi) { - FGPRINT("s3fs_release[path=%s][fd=%ld]\n", path, fi->fh); + FPRN("[path=%s][fd=%ld]", path, fi->fh); FdEntity* ent; if(NULL == (ent = FdManager::get()->GetFdEntity(path))){ - FGPRINT(" s3fs_release: could not find fd(file=%s)\n", path); - SYSLOGERR("could not find fd(file=%s)", path); + DPRN("could not find fd(file=%s)", path); return -EIO; } if(ent->GetFd() != static_cast(fi->fh)){ - FGPRINT(" s3fs_release: Warning - different fd(%d - %zd)\n", ent->GetFd(), fi->fh); - SYSLOGERR("Warning - different fd(%d - %zd)", ent->GetFd(), fi->fh); + DPRNNN("Warning - different fd(%d - %zd)", ent->GetFd(), fi->fh); } FdManager::get()->Close(ent); // check - for debug if(debug){ if(NULL != (ent = FdManager::get()->GetFdEntity(path))){ - FGPRINT(" s3fs_release: Warning - file(%s),fd(%d) is still opened.\n", path, ent->GetFd()); - SYSLOGERR("Warning - file(%s),fd(%d) is still opened.", path, ent->GetFd()); + DPRNNN("Warning - file(%s),fd(%d) is still opened.", path, ent->GetFd()); } } @@ -1997,7 +1955,7 @@ static int s3fs_opendir(const char* path, struct fuse_file_info* fi) int result; int mask = (O_RDONLY != (fi->flags & O_ACCMODE) ? W_OK : R_OK) | X_OK; - FGPRINT("s3fs_opendir [path=%s][flags=%d]\n", path, fi->flags); + FPRN("[path=%s][flags=%d]", path, fi->flags); if(0 == (result = check_object_access(path, mask, NULL))){ result = check_parent_object_access(path, mask); @@ -2012,7 +1970,7 @@ static bool multi_head_callback(S3fsCurl* s3fscurl) } string saved_path = s3fscurl->GetSpacialSavedPath(); if(!StatCache::getStatCacheData()->AddStat(saved_path, *(s3fscurl->GetResponseHeaders()))){ - FGPRINT(" multi_head_callback: failed adding stat cache [path=%s]\n", saved_path.c_str()); + DPRN("failed adding stat cache [path=%s]", saved_path.c_str()); return false; } return true; @@ -2029,8 +1987,7 @@ static S3fsCurl* multi_head_retry_callback(S3fsCurl* s3fscurl) string saved_path = s3fscurl->GetSpacialSavedPath(); if(!newcurl->PreHeadRequest(path, base_path, saved_path)){ - FGPRINT(" multi_head_retry_callback: Could not duplicate curl object(%s).\n", saved_path.c_str()); - SYSLOGERR("Could not duplicate curl object(%s).", saved_path.c_str()); + DPRN("Could not duplicate curl object(%s).", saved_path.c_str()); delete newcurl; return NULL; } @@ -2043,7 +2000,7 @@ static int readdir_multi_head(const char* path, S3ObjList& head) s3obj_list_t headlist; int result; - FGPRINT(" readdir_multi_head[path=%s][list=%ld]\n", path, headlist.size()); + FPRNN("[path=%s][list=%ld]", path, headlist.size()); // Make base path list. head.GetNameList(headlist, true, false); // get name with "/". @@ -2068,15 +2025,13 @@ static int readdir_multi_head(const char* path, S3ObjList& head) S3fsCurl* s3fscurl = new S3fsCurl(); if(!s3fscurl->PreHeadRequest(disppath, (*iter), disppath)){ // target path = cache key path.(ex "dir/") - FGPRINT(" readdir_multi_head: Could not make curl object for head request(%s).\n", disppath.c_str()); - SYSLOGERR("Could not make curl object for head request(%s).", disppath.c_str()); + DPRNNN("Could not make curl object for head request(%s).", disppath.c_str()); delete s3fscurl; continue; } if(!curlmulti.SetS3fsCurlObject(s3fscurl)){ - FGPRINT(" readdir_multi_head: Could not set curl object into multi curl(%s).\n", disppath.c_str()); - SYSLOGERR("Could not make curl object into multi curl(%s).", disppath.c_str()); + DPRNNN("Could not make curl object into multi curl(%s).", disppath.c_str()); delete s3fscurl; continue; } @@ -2085,8 +2040,7 @@ static int readdir_multi_head(const char* path, S3ObjList& head) // Multi request if(0 != (result = curlmulti.Request())){ - FGPRINT(" readdir_multi_head: error occuered in multi request(errno=%d).\n", result); - SYSLOGERR("error occuered in multi request(errno=%d).", result); + DPRN("error occuered in multi request(errno=%d).", result); break; } @@ -2102,7 +2056,7 @@ static int s3fs_readdir(const char* path, void* buf, fuse_fill_dir_t filler, off s3obj_list_t headlist; int result; - FGPRINT("s3fs_readdir[path=%s]\n", path); + FPRN("[path=%s]", path); if(0 != (result = check_object_access(path, X_OK, NULL))){ return result; @@ -2110,7 +2064,7 @@ static int s3fs_readdir(const char* path, void* buf, fuse_fill_dir_t filler, off // get a list of all the objects if((result = list_bucket(path, head, "/")) != 0){ - FGPRINT(" s3fs_readdir list_bucket returns error(%d).\n", result); + DPRN("list_bucket returns error(%d).", result); return result; } @@ -2134,7 +2088,7 @@ static int s3fs_readdir(const char* path, void* buf, fuse_fill_dir_t filler, off strpath += "/"; } if(0 != (result = readdir_multi_head(strpath.c_str(), head))){ - FGPRINT(" s3fs_readdir readdir_multi_head returns error(%d).\n", result); + DPRN("readdir_multi_head returns error(%d).", result); } return result; } @@ -2149,7 +2103,7 @@ static int list_bucket(const char* path, S3ObjList& head, const char* delimiter) S3fsCurl s3fscurl; BodyData* body; - FGPRINT("list_bucket [path=%s]\n", path); + FPRNN("[path=%s]", path); if(delimiter && 0 < strlen(delimiter)){ query += "delimiter="; @@ -2175,13 +2129,13 @@ static int list_bucket(const char* path, S3ObjList& head, const char* delimiter) } // request if(0 != (result = s3fscurl.ListBucketRequest(path, each_query.c_str()))){ - FGPRINT(" list_bucket S3fsCurl::ListBucketRequest returns with error.\n"); + DPRN("ListBucketRequest returns with error."); return result; } body = s3fscurl.GetBodyData(); if(0 != append_objects_from_xml(path, body->str(), head)){ - FGPRINT(" list_bucket append_objects_from_xml returns with error.\n"); + DPRN("append_objects_from_xml returns with error."); return -1; } truncated = is_truncated(body->str()); @@ -2219,7 +2173,7 @@ static int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathC char* name = get_object_name(doc, key_nodes->nodeTab[0]->xmlChildrenNode, path); if(!name){ - FGPRINT(" append_objects_from_xml_ex name is something wrong. but continue.\n"); + DPRNNN("append_objects_from_xml_ex name is something wrong. but continue."); }else if((const char*)name != c_strErrorObjectName){ bool is_dir = isCPrefix ? true : false; @@ -2241,7 +2195,7 @@ static int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathC } } if(!head.insert(name, (0 < stretag.length() ? stretag.c_str() : NULL), is_dir)){ - FGPRINT(" append_objects_from_xml_ex insert_object returns with error.\n"); + DPRN("insert_object returns with error."); xmlXPathFreeObject(key); xmlXPathFreeObject(contents_xp); free(name); @@ -2249,7 +2203,7 @@ static int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathC } free(name); }else{ - //FGPRINT("append_objects_from_xml_ex name is file or subdir in dir. but continue.\n"); + DPRNINFO("append_objects_from_xml_ex name is file or subdir in dir. but continue."); } xmlXPathFreeObject(key); } @@ -2297,7 +2251,7 @@ static int append_objects_from_xml(const char* path, const char* xml, S3ObjList& doc = xmlReadMemory(xml, strlen(xml), "", NULL, 0); if(doc == NULL){ - FGPRINT(" append_objects_from_xml xmlReadMemory returns with error.\n"); + DPRN("xmlReadMemory returns with error."); return -1; } ctx = xmlXPathNewContext(doc); @@ -2319,7 +2273,7 @@ static int append_objects_from_xml(const char* path, const char* xml, S3ObjList& if(-1 == append_objects_from_xml_ex(prefix.c_str(), doc, ctx, ex_contents.c_str(), ex_key.c_str(), ex_etag.c_str(), 0, head) || -1 == append_objects_from_xml_ex(prefix.c_str(), doc, ctx, ex_cprefix.c_str(), ex_prefix.c_str(), NULL, 1, head) ) { - FGPRINT(" append_objects_from_xml append_objects_from_xml_ex returns with error.\n"); + DPRN("append_objects_from_xml_ex returns with error."); xmlXPathFreeContext(ctx); xmlFreeDoc(doc); return -1; @@ -2390,7 +2344,7 @@ static char* get_object_name(xmlDocPtr doc, xmlNodePtr node, const char* path) // Get full path xmlChar* fullpath = xmlNodeListGetString(doc, node, 1); if(!fullpath){ - FGPRINT(" get_object_name could not get object full path name..\n"); + DPRN("could not get object full path name.."); return NULL; } // basepath(path) is as same as fullpath. @@ -2455,7 +2409,7 @@ static int remote_mountpath_exists(const char* path) { struct stat stbuf; - FGPRINT("remote_mountpath_exists [path=%s]\n", path); + FPRNN("[path=%s]", path); // getattr will prefix the path with the remote mountpoint if(0 != get_object_attribute("/", &stbuf, NULL)){ @@ -2493,8 +2447,8 @@ static unsigned long id_function(void) static void* s3fs_init(struct fuse_conn_info* conn) { - SYSLOGINFO("init $Rev$"); - FGPRINT("s3fs_init\n"); + FPRN("init"); + LOWSYSLOGPRINT(LOG_ERR, "init $Rev$"); // openssl mutex_buf = static_cast(malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t))); @@ -2510,8 +2464,7 @@ static void* s3fs_init(struct fuse_conn_info* conn) } // cache if(is_remove_cache && !FdManager::DeleteCacheDirectory()){ - //FGPRINT("s3fs_init: Could not inilialize cache directory.\n"); - //SYSLOGDBG("Could not inilialize cache directory."); + DPRNINFO("Could not inilialize cache directory."); } return 0; @@ -2519,8 +2472,7 @@ static void* s3fs_init(struct fuse_conn_info* conn) static void s3fs_destroy(void*) { - SYSLOGDBG("destroy"); - FGPRINT("s3fs_destroy\n"); + DPRN("destroy"); // openssl CRYPTO_set_id_callback(NULL); @@ -2533,14 +2485,13 @@ static void s3fs_destroy(void*) // cache if(is_remove_cache && !FdManager::DeleteCacheDirectory()){ - //FGPRINT("s3fs_destroy: Could not remove cache directory.\n"); - //SYSLOGDBG("Could not remove cache directory."); + DPRNINFO("Could not remove cache directory."); } } static int s3fs_access(const char* path, int mask) { - FGPRINT("s3fs_access[path=%s][mask=%s%s%s%s]\n", path, + FPRN("[path=%s][mask=%s%s%s%s]", path, ((mask & R_OK) == R_OK) ? "R_OK " : "", ((mask & W_OK) == W_OK) ? "W_OK " : "", ((mask & X_OK) == X_OK) ? "X_OK " : "", @@ -2551,7 +2502,7 @@ static int s3fs_access(const char* path, int mask) static int s3fs_check_service(void) { - FGPRINT("s3fs_check_service\n"); + FPRN("check services."); S3fsCurl s3fscurl; if(0 != s3fscurl.CheckBucket()){ @@ -2573,7 +2524,6 @@ static int s3fs_check_service(void) return EXIT_SUCCESS; } if(responseCode != 200 && responseCode != 301){ - SYSLOGDBG("responseCode: %ld\n", responseCode); fprintf(stderr, "%s: unable to connect\n", program_name.c_str()); return EXIT_FAILURE; } diff --git a/src/s3fs_util.cpp b/src/s3fs_util.cpp index e766576..80a60d1 100644 --- a/src/s3fs_util.cpp +++ b/src/s3fs_util.cpp @@ -458,8 +458,7 @@ string get_username(uid_t uid) { struct passwd* ppw; if(NULL == (ppw = getpwuid(uid)) || NULL == ppw->pw_name){ - FGPRINT(" could not get username(errno=%d).\n", (int)errno); - SYSLOGDBG("could not get username(errno=%d).\n", (int)errno); + DPRNNN("could not get username(errno=%d).", (int)errno); return string(""); } return string(ppw->pw_name); @@ -477,21 +476,18 @@ int is_uid_inculde_group(uid_t uid, gid_t gid) // make buffer if(0 == maxlen){ if(0 > (maxlen = (size_t)sysconf(_SC_GETGR_R_SIZE_MAX))){ - FGPRINT(" could not get max name length.\n"); - SYSLOGDBG("could not get max name length.\n"); + DPRNNN("could not get max name length."); maxlen = 0; return -ERANGE; } } if(NULL == (pbuf = (char*)malloc(sizeof(char) * maxlen))){ - FGPRINT(" failed to allocate memory.\n"); - SYSLOGERR("failed to allocate memory.\n"); + DPRNCRIT("failed to allocate memory."); return -ENOMEM; } // get group infomation if(0 != (result = getgrgid_r(gid, &ginfo, pbuf, maxlen, &pginfo))){ - FGPRINT(" could not get group infomation.\n"); - SYSLOGDBG("could not get group infomation.\n"); + DPRNNN("could not get group infomation."); free(pbuf); return -result; } @@ -553,7 +549,7 @@ bool delete_files_in_dir(const char* dir, bool is_remove_own) struct dirent* dent; if(NULL == (dp = opendir(dir))){ - //FGPRINT("delete_files_in_dir: could not open dir(%s) - errno(%d)\n", dir, errno); + DPRNINFO("could not open dir(%s) - errno(%d)", dir, errno); return false; } @@ -566,20 +562,20 @@ bool delete_files_in_dir(const char* dir, bool is_remove_own) fullpath += dent->d_name; struct stat st; if(0 != lstat(fullpath.c_str(), &st)){ - FGPRINT("delete_files_in_dir: could not get stats of file(%s) - errno(%d)\n", fullpath.c_str(), errno); + DPRN("could not get stats of file(%s) - errno(%d)", fullpath.c_str(), errno); closedir(dp); return false; } if(S_ISDIR(st.st_mode)){ // dir -> Reentrant if(!delete_files_in_dir(fullpath.c_str(), true)){ - //FGPRINT("delete_files_in_dir: could not remove sub dir(%s) - errno(%d)\n", fullpath.c_str(), errno); + DPRNINFO("could not remove sub dir(%s) - errno(%d)", fullpath.c_str(), errno); closedir(dp); return false; } }else{ if(0 != unlink(fullpath.c_str())){ - FGPRINT("delete_files_in_dir: could not remove file(%s) - errno(%d)\n", fullpath.c_str(), errno); + DPRN("could not remove file(%s) - errno(%d)", fullpath.c_str(), errno); closedir(dp); return false; } @@ -588,7 +584,7 @@ bool delete_files_in_dir(const char* dir, bool is_remove_own) closedir(dp); if(is_remove_own && 0 != rmdir(dir)){ - FGPRINT("delete_files_in_dir: could not remove dir(%s) - errno(%d)\n", dir, errno); + DPRN("could not remove dir(%s) - errno(%d)", dir, errno); return false; } return true; diff --git a/src/string_util.cpp b/src/string_util.cpp index 1bff204..a3f5eb4 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -17,6 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include #include #include @@ -125,7 +126,7 @@ bool get_keyword_value(string& target, const char* keyword, string& value) string prepare_url(const char* url) { - SYSLOGDBG("URL is %s", url); + DPRNNN("URL is %s", url); string uri; string host; @@ -145,7 +146,7 @@ string prepare_url(const char* url) url_str = uri + host + path; - SYSLOGDBG("URL changed is %s", url_str.c_str()); + DPRNNN("URL changed is %s", url_str.c_str()); return str(url_str); }