Skip to content

Commit 675e62d

Browse files
authored
Merge pull request #32 from liuyongqing/master
more tips and detailed log output
2 parents 13aebf7 + f0bf5d3 commit 675e62d

File tree

3 files changed

+76
-30
lines changed

3 files changed

+76
-30
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
dnl Process this file with autoconf to produce a configure script.
2222

2323
AC_PREREQ(2.59)
24-
AC_INIT(cosfs, 1.0.12)
24+
AC_INIT(cosfs, 1.0.13)
2525
AC_CONFIG_HEADER([config.h])
2626

2727
AC_CANONICAL_SYSTEM

src/common.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#define S3FS_COMMON_H_
2323

2424
#include <sys/stat.h>
25+
#include <unistd.h>
26+
#include <sys/syscall.h>
2527
#include "../config.h"
2628

2729
//
@@ -69,7 +71,7 @@ enum s3fs_log_level{
6971
if(foreground){ \
7072
fprintf(stdout, "%s%s:%s(%d): " fmt "%s\n", S3FS_LOG_LEVEL_STRING(level), __FILE__, __func__, __LINE__, __VA_ARGS__); \
7173
}else{ \
72-
syslog(S3FS_LOG_LEVEL_TO_SYSLOG(level), "%s:%s(%d): " fmt "%s", __FILE__, __func__, __LINE__, __VA_ARGS__); \
74+
syslog(S3FS_LOG_LEVEL_TO_SYSLOG(level), "[tid:%ld]%s:%s(%d): " fmt "%s", syscall(SYS_gettid), __FILE__, __func__, __LINE__, __VA_ARGS__); \
7375
} \
7476
}
7577

@@ -78,7 +80,7 @@ enum s3fs_log_level{
7880
if(foreground){ \
7981
fprintf(stdout, "%s%s%s:%s(%d): " fmt "%s\n", S3FS_LOG_LEVEL_STRING(level), S3FS_LOG_NEST(nest), __FILE__, __func__, __LINE__, __VA_ARGS__); \
8082
}else{ \
81-
syslog(S3FS_LOG_LEVEL_TO_SYSLOG(level), "%s" fmt "%s", S3FS_LOG_NEST(nest), __VA_ARGS__); \
83+
syslog(S3FS_LOG_LEVEL_TO_SYSLOG(level), "[tid:%ld]%s%s%s:%s(%d): " fmt "%s\n", syscall(SYS_gettid), S3FS_LOG_LEVEL_STRING(level), S3FS_LOG_NEST(nest), __FILE__, __func__, __LINE__, __VA_ARGS__); \
8284
} \
8385
}
8486

src/s3fs.cpp

Lines changed: 71 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3758,26 +3758,23 @@ static int s3fs_check_service(void)
37583758

37593759
// check errors(after retrying)
37603760
if(0 > res && responseCode != 200 && responseCode != 301){
3761+
BodyData* body = s3fscurl.GetBodyData();
37613762
if(responseCode == 400){
3762-
S3FS_PRN_EXIT("Client argument error.");
3763-
return EXIT_FAILURE;
3764-
}
3765-
if(responseCode == 403){
3766-
S3FS_PRN_EXIT("Forbidden visit bucket, check secretId, secretKey.");
3767-
return EXIT_FAILURE;
3763+
S3FS_PRN_EXIT("Client argument error, please check mount command\n\n%s", body ? body->str() : "");
3764+
} else if(responseCode == 403){
3765+
S3FS_PRN_EXIT("Forbidden visit bucket, please check secretId, secretKey and mount command\n\n%s", body ? body->str() : "");
3766+
} else if(responseCode == 404){
3767+
string bucket_name = bucket + "-" + appid;
3768+
S3FS_PRN_EXIT("Bucket %s not found, please check if the bucket exists and mount command\n\n%s", bucket_name.c_str(), body ? body->str() : "");
3769+
} else if(responseCode == CURLE_OPERATION_TIMEDOUT){
3770+
// unable to connect
3771+
S3FS_PRN_EXIT("Unable to connect host %s(timeout), please check network condition and mount command", host.c_str());
3772+
} else{
3773+
// other error code
3774+
S3FS_PRN_EXIT("Mount bucket failed, connect host is: %s, please check network condition and mount command\n\n%s", host.c_str(), body ? body->str() : "");
37683775
}
3769-
if(responseCode == 404){
3770-
S3FS_PRN_EXIT("Bucket not found, check bucket name and region whether correct.");
3771-
return EXIT_FAILURE;
3772-
}
3773-
// unable to connect
3774-
if(responseCode == CURLE_OPERATION_TIMEDOUT){
3775-
S3FS_PRN_EXIT("Unable to connect bucket and timeout, check network condition.");
3776-
return EXIT_FAILURE;
3777-
}
3778-
3779-
// another error
3780-
S3FS_PRN_EXIT("Unable to connect cos, check network condition.");
3776+
// a correct mount example
3777+
S3FS_PRN_EXIT("mount example: cosfs examplebucket-1250000000 /mnt/cosfs -ourl=http://cos.ap-guangzhou.myqcloud.com -odbglevel=dbg -oallow_other");
37813778
return EXIT_FAILURE;
37823779
}
37833780
}
@@ -4194,13 +4191,35 @@ static int set_moutpoint_attribute(struct stat& mpst)
41944191
}
41954192

41964193
void SplitString(const std::string& str, char delim, std::vector<std::string>* vec) {
4197-
std::stringstream ss(str);
4198-
std::string item;
4199-
while(std::getline(ss, item, delim)) {
4200-
if(!item.empty()) {
4201-
vec->push_back(item);
4202-
}
4203-
}
4194+
std::stringstream ss(str);
4195+
std::string item;
4196+
while(std::getline(ss, item, delim)) {
4197+
if(!item.empty()) {
4198+
vec->push_back(item);
4199+
}
4200+
}
4201+
}
4202+
4203+
// parse version like 3.12.3
4204+
// return number like: <8 bits major number>|<8 bits minor number>|<8 bits patch number>
4205+
int get_version(string version_str) {
4206+
int major_version = 0;
4207+
int minor_version = 0;
4208+
int patch_version = 0;
4209+
std::vector<std::string> split_vec;
4210+
4211+
SplitString(version_str, '.', &split_vec);
4212+
if(1 <= split_vec.size()) {
4213+
major_version = static_cast<int>(s3fs_strtoofft(split_vec[0].c_str()));
4214+
}
4215+
if(2 <= split_vec.size()) {
4216+
minor_version = static_cast<int>(s3fs_strtoofft(split_vec[1].c_str()));
4217+
}
4218+
if(3 <= split_vec.size()) {
4219+
patch_version = static_cast<int>(s3fs_strtoofft(split_vec[2].c_str()));
4220+
}
4221+
4222+
return (major_version << 16) + (minor_version << 8) + patch_version;
42044223
}
42054224

42064225
// This is repeatedly called by the fuse option parser
@@ -4662,6 +4681,30 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
46624681
found = host.find_last_of('/');
46634682
length = host.length();
46644683
}
4684+
if((host.compare(0, 12, "https://cos.") != 0) && (host.compare(0, 11, "http://cos.") != 0)) {
4685+
fprintf(stdout, "Warn:option url has invalid format:%s, correct example:-ourl=http://cos.ap-guangzhou.myqcloud.com\n", host.c_str());
4686+
}
4687+
// if use https and libcurl version greater or equal to 3.12.3, should set environment NSS_STRICT_NOFORK=DISABLED
4688+
curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
4689+
char *env = getenv("NSS_STRICT_NOFORK");
4690+
bool use_nss = false;
4691+
int nss_version = 0;
4692+
if(data->ssl_version && 0 == STR2NCMP(data->ssl_version, "NSS/")) {
4693+
use_nss = true;
4694+
nss_version = get_version(data->ssl_version + 4);
4695+
S3FS_PRN_CRIT("NSS version is:%s, convert hex version:%x", data->ssl_version, nss_version);
4696+
}
4697+
4698+
if((host.compare(0, 8, "https://") == 0) && use_nss && (nss_version >= 0x030c03) && (NULL == env || STR2NCMP(env, "DISABLED"))) {
4699+
int res = setenv("NSS_STRICT_NOFORK", "DISABLED", 1);
4700+
if(0 != res) {
4701+
S3FS_PRN_EXIT("if you mount using the https protocal and the libcurl version is greater or equal to 3.12.3,"
4702+
"please set NSS_STRICT_NOFORK=DISABLED environment variable and mount again");
4703+
return -1;
4704+
} else {
4705+
S3FS_PRN_CRIT("set NSS_STRICT_NOFORK=DISABLED environment variable success");
4706+
}
4707+
}
46654708
return 0;
46664709
}
46674710
if (0 == STR2NCMP(arg, "default_permission=")) {
@@ -4845,7 +4888,7 @@ int main(int argc, char* argv[])
48454888
}
48464889

48474890
// The first plain argument is the bucket
4848-
if(bucket.size() == 0 || appid.empty()){
4891+
if(bucket.empty() || appid.empty()){
48494892
S3FS_PRN_EXIT("missing BUCKET argument or appid argument.");
48504893
show_usage();
48514894
exit(EXIT_FAILURE);
@@ -5000,7 +5043,8 @@ int main(int argc, char* argv[])
50005043

50015044
int result;
50025045
if (EXIT_SUCCESS != (result = s3fs_check_service())) {
5003-
S3FS_PRN_EXIT("More help information, please refer to cosfs documentation: https://cloud.tencent.com/document/product/436/6883");
5046+
S3FS_PRN_EXIT("On the CentOS system, cosfs logs are stored in /var/log/messages; On the Ubuntu system, cosfs logs are stored in /var/log/syslog");
5047+
S3FS_PRN_EXIT("More help information, please refer to cosfs --help|less or cosfs documentation: https://cloud.tencent.com/document/product/436/6883 for detail");
50045048
exit(result);
50055049
}
50065050

0 commit comments

Comments
 (0)