Skip to content

Commit 26a9148

Browse files
author
yongqingliu
committed
add user_agent_suffix option and support specify tmpdir
1 parent b922ee8 commit 26a9148

File tree

7 files changed

+63
-4
lines changed

7 files changed

+63
-4
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.20)
24+
AC_INIT(cosfs, 1.0.21)
2525
AC_CONFIG_HEADER([config.h])
2626

2727
AC_CANONICAL_SYSTEM

src/curl.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ mimes_t S3fsCurl::mimeTypes;
309309
int S3fsCurl::max_parallel_cnt = 10; // default
310310
off_t S3fsCurl::multipart_size = MULTIPART_SIZE; // default
311311
bool S3fsCurl::is_sigv4 = true; // default
312-
const string S3fsCurl::skUserAgent = "tencentyun-cosfs-v5-" + string(VERSION);
312+
string S3fsCurl::skUserAgent = "tencentyun-cosfs-v5-" + string(VERSION);
313313

314314
//-------------------------------------------------------------------
315315
// Class methods for S3fsCurl
@@ -1413,6 +1413,12 @@ bool S3fsCurl::SetRAMCredentials(const char* response)
14131413
return true;
14141414
}
14151415

1416+
bool S3fsCurl::SetUserAgentSuffix(const std::string& suffix) {
1417+
skUserAgent = "tencentyun-cosfs-v5-";
1418+
skUserAgent += suffix + "-" + VERSION;
1419+
return true;
1420+
}
1421+
14161422
bool S3fsCurl::CheckRAMCredentialUpdate(void)
14171423
{
14181424
if(0 == S3fsCurl::CAM_role.size()){

src/curl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class S3fsCurl
237237
static int max_parallel_cnt;
238238
static off_t multipart_size;
239239
static bool is_sigv4;
240-
static const std::string skUserAgent;
240+
static std::string skUserAgent;
241241

242242
// variables
243243
CURL* hCurl;
@@ -320,6 +320,7 @@ class S3fsCurl
320320
static int ParallelMultipartUploadRequest(const char* tpath, headers_t& meta, int fd);
321321
static int ParallelGetObjectRequest(const char* tpath, int fd, off_t start, ssize_t size);
322322
static bool CheckRAMCredentialUpdate(void);
323+
static bool SetUserAgentSuffix(const std::string& suffix);
323324

324325
// class methods(valiables)
325326
static std::string LookupMimeType(std::string name);

src/fdcache.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ int FdEntity::Open(headers_t* pmeta, ssize_t size, time_t time)
780780
// not using cache
781781

782782
// open temporary file
783-
if(NULL == (pfile = tmpfile()) || -1 ==(fd = fileno(pfile))){
783+
if(NULL == (pfile = FdManager::MakeTempFile()) || -1 ==(fd = fileno(pfile))){
784784
S3FS_PRN_ERR("failed to open tmp file. err(%d)", errno);
785785
if(pfile){
786786
fclose(pfile);
@@ -1713,6 +1713,7 @@ pthread_mutex_t FdManager::fd_manager_lock;
17131713
bool FdManager::is_lock_init(false);
17141714
string FdManager::cache_dir("");
17151715
size_t FdManager::free_disk_space = 0;
1716+
std::string FdManager::tmp_dir = "";
17161717

17171718
//------------------------------------------------
17181719
// FdManager class methods
@@ -1859,6 +1860,28 @@ fsblkcnt_t FdManager::GetFreeDiskSpace(const char* path)
18591860
return (vfsbuf.f_bavail * vfsbuf.f_bsize);
18601861
}
18611862

1863+
FILE* FdManager::MakeTempFile() {
1864+
if (tmp_dir.empty()) {
1865+
return tmpfile();
1866+
}
1867+
int fd;
1868+
char cfn[PATH_MAX];
1869+
std::string fn = tmp_dir + "/cosfstmp.XXXXXX";
1870+
strncpy(cfn, fn.c_str(), sizeof(cfn) - 1);
1871+
cfn[sizeof(cfn) - 1] = '\0';
1872+
1873+
fd = mkstemp(cfn);
1874+
if (-1 == fd) {
1875+
S3FS_PRN_ERR("failed to create tmp file. errno(%d)", errno);
1876+
return NULL;
1877+
}
1878+
if (-1 == unlink(cfn)) {
1879+
S3FS_PRN_ERR("failed to delete tmp file. errno(%d)", errno);
1880+
return NULL;
1881+
}
1882+
return fdopen(fd, "rb+");
1883+
}
1884+
18621885
bool FdManager::IsSafeDiskSpace(const char* path, size_t size)
18631886
{
18641887
fsblkcnt_t fsize = FdManager::GetFreeDiskSpace(path);
@@ -2061,6 +2084,16 @@ bool FdManager::Close(FdEntity* ent)
20612084
return false;
20622085
}
20632086

2087+
bool FdManager::SetTmpDir(const char *dir)
2088+
{
2089+
if(!dir || '\0' == dir[0]){
2090+
tmp_dir = "/tmp";
2091+
}else{
2092+
tmp_dir = dir;
2093+
}
2094+
return true;
2095+
}
2096+
20642097
bool FdManager::ChangeEntityToTempPath(FdEntity* ent, const char* path)
20652098
{
20662099
AutoLock auto_lock(&FdManager::fd_manager_lock);

src/fdcache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class FdManager
196196
static size_t free_disk_space; // limit free disk space
197197

198198
fdent_map_t fent;
199+
static std::string tmp_dir;
199200

200201
private:
201202
static fsblkcnt_t GetFreeDiskSpace(const char* path);
@@ -227,6 +228,8 @@ class FdManager
227228
void Rename(const std::string &from, const std::string &to);
228229
bool Close(FdEntity* ent);
229230
bool ChangeEntityToTempPath(FdEntity* ent, const char* path);
231+
static bool SetTmpDir(const char* dir);
232+
static FILE* MakeTempFile();
230233
};
231234

232235
#endif // FD_CACHE_H_

src/s3fs.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4583,6 +4583,15 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
45834583
noxattr = true;
45844584
return 0;
45854585
}
4586+
if(0 == STR2NCMP(arg, "user_agent_suffix=")){
4587+
std::string user_agent_suffix = string(strchr(arg, '=') + sizeof(char));
4588+
S3fsCurl::SetUserAgentSuffix(user_agent_suffix);
4589+
return 0;
4590+
}
4591+
if(0 == STR2NCMP(arg, "tmpdir=")){
4592+
FdManager::SetTmpDir(strchr(arg, '=') + sizeof(char));
4593+
return 0;
4594+
}
45864595
// old format for storage_class
45874596
if(0 == strcmp(arg, "use_rrs") || 0 == STR2NCMP(arg, "use_rrs=")){
45884597
off_t rrs = 1;
@@ -4911,6 +4920,7 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
49114920
is_specified_endpoint = true;
49124921
return 0;
49134922
}
4923+
49144924
if(0 == strcmp(arg, "use_path_request_style")){
49154925
pathrequeststyle = true;
49164926
return 0;

src/s3fs_util.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,12 @@ void show_help (void)
929929
" del_cache (delete local file cache)\n"
930930
" - delete local file cache when cosfs starts and exits.\n"
931931
"\n"
932+
" tmpdir (default=\"/tmp\")\n"
933+
" - local folder for temporary files.\n"
934+
"\n"
935+
" user_agent_suffix (http request user agent suffix)\n"
936+
" - specify http request user agent.\n"
937+
"\n"
932938
" storage_class (default=\"standard\")\n"
933939
" - store object with specified storage class. Possible values:\n"
934940
" standard, standard_ia, and reduced_redundancy.\n"

0 commit comments

Comments
 (0)