Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ int S3fsCurl::max_parallel_cnt = 10; // default
off_t S3fsCurl::multipart_size = MULTIPART_SIZE; // default
bool S3fsCurl::is_sigv4 = true; // default
string S3fsCurl::skUserAgent = "tencentyun-cosfs-v5-" + string(VERSION);
bool S3fsCurl::is_client_info_in_delete = false; // default

//-------------------------------------------------------------------
// Class methods for S3fsCurl
Expand Down Expand Up @@ -2135,7 +2136,7 @@ bool S3fsCurl::GetUploadId(string& upload_id)
return result;
}

int S3fsCurl::DeleteRequest(const char* tpath)
int S3fsCurl::DeleteRequest(const char* tpath, int pid)
{
S3FS_PRN_INFO3("[tpath=%s]", SAFESTRPTR(tpath));

Expand Down Expand Up @@ -2163,6 +2164,13 @@ int S3fsCurl::DeleteRequest(const char* tpath)
string Signature = CalcSignature("DELETE", "", "", date, resource, "");
requestHeaders = curl_slist_sort_insert(requestHeaders, "Authorization", Signature.c_str());
}
if(S3fsCurl::IsClientInfoInDelete()){
ostringstream pidstr;
pidstr << pid;
string clientinfo = S3fsCurl::GetClientInfo(pidstr.str());
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-delete-client-pid", pidstr.str().c_str());
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-delete-client-cgroup", clientinfo.c_str());
}

curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str());
curl_easy_setopt(hCurl, CURLOPT_CUSTOMREQUEST, "DELETE");
Expand Down Expand Up @@ -3384,6 +3392,29 @@ int S3fsCurl::MultipartRenameRequest(const char* from, const char* to, headers_t
return 0;
}

std::string S3fsCurl::GetClientInfo(std::string pid)
{
if (pid == "-1") {
return "can not get pid";
}
std::string path = "/proc/" + pid + "/cgroup";
std::ifstream ifs(path.c_str());
if (!ifs) {
S3FS_PRN_ERR("failed to open %s", path.c_str());
return "failed to open " + path;
}
std::string line;
while (std::getline(ifs, line)) {
if (line.find("cpu,cpuacct") != std::string::npos) {
return line;
}
if (line.find("cpuacct,cpu") != std::string::npos) {
return line;
}
}
return "not found cpu,cpuacct";
}

//-------------------------------------------------------------------
// Class S3fsMultiCurl
//-------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion src/curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ class S3fsCurl
static off_t multipart_size;
static bool is_sigv4;
static std::string skUserAgent;
static bool is_client_info_in_delete;

// variables
CURL* hCurl;
Expand Down Expand Up @@ -370,6 +371,9 @@ class S3fsCurl
static off_t GetMultipartSize(void) { return S3fsCurl::multipart_size; }
static bool SetSignatureV4(bool isset) { bool bresult = S3fsCurl::is_sigv4; S3fsCurl::is_sigv4 = isset; return bresult; }
static bool IsSignatureV4(void) { return S3fsCurl::is_sigv4; }
static void SetClientInfoInDelete(bool is_set) { S3fsCurl::is_client_info_in_delete = is_set; }
static bool IsClientInfoInDelete(void) { return S3fsCurl::is_client_info_in_delete; }
static std::string GetClientInfo(std::string pid);

// methods
bool CreateCurlHandle(bool force = false);
Expand All @@ -378,7 +382,7 @@ class S3fsCurl
bool AddSseRequestHead(sse_type_t ssetype, std::string& ssevalue, bool is_only_c, bool is_copy);
bool GetResponseCode(long& responseCode);
int RequestPerform(void);
int DeleteRequest(const char* tpath);
int DeleteRequest(const char* tpath, int pid);
bool PreHeadRequest(const char* tpath, const char* bpath = NULL, const char* savedpath = NULL, int ssekey_pos = -1);
bool PreHeadRequest(std::string& tpath, std::string& bpath, std::string& savedpath, int ssekey_pos = -1) {
return PreHeadRequest(tpath.c_str(), bpath.c_str(), savedpath.c_str(), ssekey_pos);
Expand Down
53 changes: 41 additions & 12 deletions src/s3fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1025,16 +1025,18 @@ static int s3fs_unlink(const char* path)

S3FS_PRN_INFO("[path=%s]", path);

int pid = -1;
struct fuse_context* pcxt;
if(NULL != (pcxt = fuse_get_context())){
pid = pcxt->pid;
S3FS_PRN_INFO("%s, uid=[%d], gid=[%d], pid=[%d]", __FUNCTION__, pcxt->uid, pcxt->gid, pcxt->pid);
}

if(0 != (result = check_parent_object_access(path, W_OK | X_OK))){
return result;
}
S3fsCurl s3fscurl;
result = s3fscurl.DeleteRequest(path);
result = s3fscurl.DeleteRequest(path, pid);
FdManager::DeleteCacheFile(path);
StatCache::getStatCacheData()->DelStat(path);
S3FS_MALLOCTRIM(0);
Expand Down Expand Up @@ -1065,8 +1067,10 @@ static int s3fs_rmdir(const char* path)

S3FS_PRN_INFO("[path=%s]", path);

int pid = -1;
struct fuse_context* pcxt;
if(NULL != (pcxt = fuse_get_context())){
pid = pcxt->pid;
S3FS_PRN_INFO("%s, uid=[%d], gid=[%d], pid=[%d]", __FUNCTION__, pcxt->uid, pcxt->gid, pcxt->pid);
}

Expand All @@ -1084,7 +1088,7 @@ static int s3fs_rmdir(const char* path)
strpath += "/";
}
S3fsCurl s3fscurl;
result = s3fscurl.DeleteRequest(strpath.c_str());
result = s3fscurl.DeleteRequest(strpath.c_str(), pid);
s3fscurl.DestroyCurlHandle();
StatCache::getStatCacheData()->DelStat(strpath.c_str());

Expand All @@ -1099,7 +1103,7 @@ static int s3fs_rmdir(const char* path)
if(0 == get_object_attribute(strpath.c_str(), &stbuf, NULL, false)){
if(S_ISDIR(stbuf.st_mode)){
// Found "dir" object.
result = s3fscurl.DeleteRequest(strpath.c_str());
result = s3fscurl.DeleteRequest(strpath.c_str(), pid);
s3fscurl.DestroyCurlHandle();
StatCache::getStatCacheData()->DelStat(strpath.c_str());
}
Expand All @@ -1111,7 +1115,7 @@ static int s3fs_rmdir(const char* path)
// This processing is necessary for other OSS clients compatibility.
if(is_special_name_folder_object(strpath.c_str())){
strpath += "_$folder$";
result = s3fscurl.DeleteRequest(strpath.c_str());
result = s3fscurl.DeleteRequest(strpath.c_str(), pid);
}
S3FS_MALLOCTRIM(0);

Expand Down Expand Up @@ -1566,8 +1570,10 @@ static int s3fs_chmod(const char* path, mode_t mode)

S3FS_PRN_INFO("[path=%s][mode=%04o]", path, mode);

int pid = -1;
struct fuse_context* pcxt;
if(NULL != (pcxt = fuse_get_context())){
pid = pcxt->pid;
S3FS_PRN_INFO("%s, uid=[%d], gid=[%d], pid=[%d]", __FUNCTION__, pcxt->uid, pcxt->gid, pcxt->pid);
}

Expand Down Expand Up @@ -1600,7 +1606,7 @@ static int s3fs_chmod(const char* path, mode_t mode)
// At first, remove directory old object
if(IS_RMTYPEDIR(nDirType)){
S3fsCurl s3fscurl;
if(0 != (result = s3fscurl.DeleteRequest(strpath.c_str()))){
if(0 != (result = s3fscurl.DeleteRequest(strpath.c_str(), pid))){
return result;
}
}
Expand Down Expand Up @@ -1665,8 +1671,10 @@ static int s3fs_chmod_nocopy(const char* path, mode_t mode)

S3FS_PRN_INFO1("[path=%s][mode=%04o]", path, mode);

int pid = -1;
struct fuse_context* pcxt;
if(NULL != (pcxt = fuse_get_context())){
pid = pcxt->pid;
S3FS_PRN_INFO("%s, uid=[%d], gid=[%d], pid=[%d]", __FUNCTION__, pcxt->uid, pcxt->gid, pcxt->pid);
}

Expand Down Expand Up @@ -1700,7 +1708,7 @@ static int s3fs_chmod_nocopy(const char* path, mode_t mode)
// At first, remove directory old object
if(IS_RMTYPEDIR(nDirType)){
S3fsCurl s3fscurl;
if(0 != (result = s3fscurl.DeleteRequest(strpath.c_str()))){
if(0 != (result = s3fscurl.DeleteRequest(strpath.c_str(), pid))){
return result;
}
}
Expand Down Expand Up @@ -1750,8 +1758,10 @@ static int s3fs_chown(const char* path, uid_t uid, gid_t gid)

S3FS_PRN_INFO("[path=%s][uid=%u][gid=%u]", path, (unsigned int)uid, (unsigned int)gid);

int pid = -1;
struct fuse_context* pcxt;
if(NULL != (pcxt = fuse_get_context())){
pid = pcxt->pid;
S3FS_PRN_INFO("%s, uid=[%d], gid=[%d], pid=[%d]", __FUNCTION__, pcxt->uid, pcxt->gid, pcxt->pid);
}

Expand Down Expand Up @@ -1799,7 +1809,7 @@ static int s3fs_chown(const char* path, uid_t uid, gid_t gid)
// At first, remove directory old object
if(IS_RMTYPEDIR(nDirType)){
S3fsCurl s3fscurl;
if(0 != (result = s3fscurl.DeleteRequest(strpath.c_str()))){
if(0 != (result = s3fscurl.DeleteRequest(strpath.c_str(), pid))){
return result;
}
}
Expand Down Expand Up @@ -1864,8 +1874,10 @@ static int s3fs_chown_nocopy(const char* path, uid_t uid, gid_t gid)
int nDirType = DIRTYPE_UNKNOWN;

S3FS_PRN_INFO1("[path=%s][uid=%u][gid=%u]", path, (unsigned int)uid, (unsigned int)gid);
int pid = -1;
struct fuse_context* pcxt;
if(NULL != (pcxt = fuse_get_context())){
pid = pcxt->pid;
S3FS_PRN_INFO("%s, uid=[%d], gid=[%d], pid=[%d]", __FUNCTION__, pcxt->uid, pcxt->gid, pcxt->pid);
}

Expand Down Expand Up @@ -1908,7 +1920,7 @@ static int s3fs_chown_nocopy(const char* path, uid_t uid, gid_t gid)
// At first, remove directory old object
if(IS_RMTYPEDIR(nDirType)){
S3fsCurl s3fscurl;
if(0 != (result = s3fscurl.DeleteRequest(strpath.c_str()))){
if(0 != (result = s3fscurl.DeleteRequest(strpath.c_str(), pid))){
return result;
}
}
Expand Down Expand Up @@ -1958,8 +1970,10 @@ static int s3fs_utimens(const char* path, const struct timespec ts[2])
int nDirType = DIRTYPE_UNKNOWN;

S3FS_PRN_INFO("[path=%s][mtime=%jd]", path, (intmax_t)(ts[1].tv_sec));
int pid = -1;
struct fuse_context* pcxt;
if(NULL != (pcxt = fuse_get_context())){
pid = pcxt->pid;
S3FS_PRN_INFO("%s, uid=[%d], gid=[%d], pid=[%d]", __FUNCTION__, pcxt->uid, pcxt->gid, pcxt->pid);
}

Expand Down Expand Up @@ -1994,7 +2008,7 @@ static int s3fs_utimens(const char* path, const struct timespec ts[2])
// At first, remove directory old object
if(IS_RMTYPEDIR(nDirType)){
S3fsCurl s3fscurl;
if(0 != (result = s3fscurl.DeleteRequest(strpath.c_str()))){
if(0 != (result = s3fscurl.DeleteRequest(strpath.c_str(), pid))){
return result;
}
}
Expand Down Expand Up @@ -2056,8 +2070,10 @@ static int s3fs_utimens_nocopy(const char* path, const struct timespec ts[2])
int nDirType = DIRTYPE_UNKNOWN;

S3FS_PRN_INFO1("[path=%s][mtime=%s]", path, str(ts[1].tv_sec).c_str());
int pid = -1;
struct fuse_context* pcxt;
if(NULL != (pcxt = fuse_get_context())){
pid = pcxt->pid;
S3FS_PRN_INFO("%s, uid=[%d], gid=[%d], pid=[%d]", __FUNCTION__, pcxt->uid, pcxt->gid, pcxt->pid);
}

Expand Down Expand Up @@ -2093,7 +2109,7 @@ static int s3fs_utimens_nocopy(const char* path, const struct timespec ts[2])
// At first, remove directory old object
if(IS_RMTYPEDIR(nDirType)){
S3fsCurl s3fscurl;
if(0 != (result = s3fscurl.DeleteRequest(strpath.c_str()))){
if(0 != (result = s3fscurl.DeleteRequest(strpath.c_str(), pid))){
return result;
}
}
Expand Down Expand Up @@ -3223,6 +3239,13 @@ static int s3fs_setxattr(const char* path, const char* name, const char* value,
}
#endif

int pid = -1;
struct fuse_context* pcxt;
if(NULL != (pcxt = fuse_get_context())){
pid = pcxt->pid;
S3FS_PRN_INFO("%s, uid=[%d], gid=[%d], pid=[%d]", __FUNCTION__, pcxt->uid, pcxt->gid, pcxt->pid);
}

int result;
string strpath;
string newpath;
Expand Down Expand Up @@ -3265,7 +3288,7 @@ static int s3fs_setxattr(const char* path, const char* name, const char* value,
// At first, remove directory old object
if(IS_RMTYPEDIR(nDirType)){
S3fsCurl s3fscurl;
if(0 != (result = s3fscurl.DeleteRequest(strpath.c_str()))){
if(0 != (result = s3fscurl.DeleteRequest(strpath.c_str(), pid))){
return result;
}
}
Expand Down Expand Up @@ -3497,8 +3520,10 @@ static int s3fs_listxattr(const char* path, char* list, size_t size)
static int s3fs_removexattr(const char* path, const char* name)
{
S3FS_PRN_INFO("[path=%s][name=%s]", path, name);
int pid = -1;
struct fuse_context* pcxt;
if(NULL != (pcxt = fuse_get_context())){
pid = pcxt->pid;
S3FS_PRN_INFO("%s, uid=[%d], gid=[%d], pid=[%d]", __FUNCTION__, pcxt->uid, pcxt->gid, pcxt->pid);
}

Expand Down Expand Up @@ -3575,7 +3600,7 @@ static int s3fs_removexattr(const char* path, const char* name)
// At first, remove directory old object
if(IS_RMTYPEDIR(nDirType)){
S3fsCurl s3fscurl;
if(0 != (result = s3fscurl.DeleteRequest(strpath.c_str()))){
if(0 != (result = s3fscurl.DeleteRequest(strpath.c_str(), pid))){
free_xattrs(xattrs);
return result;
}
Expand Down Expand Up @@ -4633,6 +4658,10 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
FdManager::SetCacheDir(strchr(arg, '=') + sizeof(char));
return 0;
}
if(0 == STR2NCMP(arg, "enable_clientinfo")){
S3fsCurl::SetClientInfoInDelete(true);
return 0;
}
if(0 == strcmp(arg, "del_cache")){
is_remove_cache = true;
return 0;
Expand Down