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
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
dnl Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT(cosfs, 1.0.21)
AC_INIT(cosfs, 1.0.22)
AC_CONFIG_HEADER([config.h])

AC_CANONICAL_SYSTEM
Expand Down
7 changes: 4 additions & 3 deletions src/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "s3fs.h"
#include "s3fs_util.h"
#include "s3fs_auth.h"
#include "fdcache.h"

using namespace std;

Expand All @@ -69,13 +70,13 @@ static bool make_md5_from_string(const char* pstr, string& md5)
return false;
}
FILE* fp;
if(NULL == (fp = tmpfile())){
S3FS_PRN_ERR("Could not make tmpfile.");
if(NULL == (fp = FdManager::MakeTempFile())){
S3FS_PRN_ERR("failed to open temporary file by errno(%d)", errno);
return false;
}
size_t length = strlen(pstr);
if(length != fwrite(pstr, sizeof(char), length, fp)){
S3FS_PRN_ERR("Failed to write tmpfile.");
S3FS_PRN_ERR("failed to write temporary file by errno(%d)", errno);
fclose(fp);
return false;
}
Expand Down
44 changes: 29 additions & 15 deletions src/fdcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@ using namespace std;
//------------------------------------------------
#define MAX_MULTIPART_CNT 10000 // OSS multipart max count

//
// For cache directory top path
//
#if defined(P_tmpdir)
#define TMPFILE_DIR_0PATH P_tmpdir
#else
#define TMPFILE_DIR_0PATH "/tmp"
#endif

size_t FdEntity::max_prefetch_bytes = 100 * 1024 * 1024;

//------------------------------------------------
Expand Down Expand Up @@ -1229,8 +1220,8 @@ int FdEntity::NoCacheLoadAndPost(off_t start, size_t size)
// open temporary file
FILE* ptmpfp;
int tmpfd;
if(NULL == (ptmpfp = tmpfile()) || -1 ==(tmpfd = fileno(ptmpfp))){
S3FS_PRN_ERR("failed to open tmp file. err(%d)", errno);
if(NULL == (ptmpfp = FdManager::MakeTempFile()) || -1 ==(tmpfd = fileno(ptmpfp))){
S3FS_PRN_ERR("failed to open temporary file by errno(%d)", errno);
if(ptmpfp){
fclose(ptmpfp);
}
Expand Down Expand Up @@ -1836,7 +1827,7 @@ pthread_mutex_t FdManager::fd_manager_lock;
bool FdManager::is_lock_init(false);
string FdManager::cache_dir("");
size_t FdManager::free_disk_space = 0;
std::string FdManager::tmp_dir = "";
std::string FdManager::tmp_dir = "/tmp";

//------------------------------------------------
// FdManager class methods
Expand Down Expand Up @@ -1969,7 +1960,7 @@ fsblkcnt_t FdManager::GetFreeDiskSpace(const char* path)
if(0 < FdManager::cache_dir.size()){
ctoppath = FdManager::cache_dir + "/";
}else{
ctoppath = TMPFILE_DIR_0PATH "/";
ctoppath = tmp_dir + "/";
}
if(path && '\0' != *path){
ctoppath += path;
Expand All @@ -1983,8 +1974,31 @@ fsblkcnt_t FdManager::GetFreeDiskSpace(const char* path)
return (vfsbuf.f_bavail * vfsbuf.f_bsize);
}

bool FdManager::IsDir(const std::string* dir)
{
// check the directory
struct stat st;
if(0 != stat(dir->c_str(), &st)){
S3FS_PRN_ERR("could not stat() directory %s by errno(%d).", dir->c_str(), errno);
return false;
}
if(!S_ISDIR(st.st_mode)){
S3FS_PRN_ERR("the directory %s is not a directory.", dir->c_str());
return false;
}
return true;
}

bool FdManager::CheckTmpDirExist()
{
if(FdManager::tmp_dir.empty()){
return true;
}
return IsDir(&tmp_dir);
}

FILE* FdManager::MakeTempFile() {
if (tmp_dir.empty()) {
if (tmp_dir.empty() || tmp_dir == "/tmp") {
return tmpfile();
}
int fd;
Expand Down Expand Up @@ -2237,7 +2251,7 @@ bool FdManager::SetTmpDir(const char *dir)
tmp_dir = "/tmp";
}else{
tmp_dir = dir;
}
}
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions src/fdcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class FdManager

private:
static fsblkcnt_t GetFreeDiskSpace(const char* path);
static bool IsDir(const std::string* dir);

public:
FdManager();
Expand Down Expand Up @@ -230,6 +231,7 @@ class FdManager
bool Close(FdEntity* ent);
bool ChangeEntityToTempPath(FdEntity* ent, const char* path);
static bool SetTmpDir(const char* dir);
static bool CheckTmpDirExist();
static FILE* MakeTempFile();
};

Expand Down
16 changes: 12 additions & 4 deletions src/s3fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4625,6 +4625,10 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
S3fsCurl::SetRetries(static_cast<int>(s3fs_strtoofft(strchr(arg, '=') + sizeof(char))));
return 0;
}
if(0 == STR2NCMP(arg, "tmpdir=")){
FdManager::SetTmpDir(strchr(arg, '=') + sizeof(char));
return 0;
}
if(0 == STR2NCMP(arg, "use_cache=")){
FdManager::SetCacheDir(strchr(arg, '=') + sizeof(char));
return 0;
Expand Down Expand Up @@ -4661,10 +4665,6 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
S3fsCurl::SetUserAgentSuffix(user_agent_suffix);
return 0;
}
if(0 == STR2NCMP(arg, "tmpdir=")){
FdManager::SetTmpDir(strchr(arg, '=') + sizeof(char));
return 0;
}
// old format for storage_class
if(0 == strcmp(arg, "use_rrs") || 0 == STR2NCMP(arg, "use_rrs=")){
off_t rrs = 1;
Expand Down Expand Up @@ -5212,6 +5212,14 @@ int main(int argc, char* argv[])
// like checking for appropriate lengths and characters
}

// check tmp dir permission
if(!FdManager::CheckTmpDirExist()){
S3FS_PRN_EXIT("temporary directory doesn't exists.");
S3fsCurl::DestroyS3fsCurl();
s3fs_destroy_global_ssl();
exit(EXIT_FAILURE);
}

// check cache dir permission
if(!FdManager::CheckCacheTopDir() || !CacheFileStat::CheckCacheFileStatTopDir()){
S3FS_PRN_EXIT("could not allow cache directory permission, check permission of cache directories.");
Expand Down