2011-02-25 17:35:12 +00:00
|
|
|
/*
|
|
|
|
* s3fs - FUSE-based file system backed by Amazon S3
|
|
|
|
*
|
2017-05-07 11:24:17 +00:00
|
|
|
* Copyright(C) 2007 Randy Rizun <rrizun@gmail.com>
|
2011-02-25 17:35:12 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2022-07-30 03:06:47 +00:00
|
|
|
#include <algorithm>
|
2022-01-24 23:36:27 +00:00
|
|
|
#include <cerrno>
|
2020-08-22 12:40:53 +00:00
|
|
|
#include <cstdlib>
|
2022-07-30 03:06:47 +00:00
|
|
|
#include <vector>
|
2020-08-22 12:40:53 +00:00
|
|
|
|
2013-09-14 21:50:39 +00:00
|
|
|
#include "s3fs.h"
|
2022-07-30 03:06:47 +00:00
|
|
|
#include "s3fs_logger.h"
|
2022-01-29 02:35:37 +00:00
|
|
|
#include "s3fs_util.h"
|
2020-08-22 12:40:53 +00:00
|
|
|
#include "cache.h"
|
|
|
|
#include "autolock.h"
|
2015-01-28 17:13:11 +00:00
|
|
|
#include "string_util.h"
|
2011-02-25 17:35:12 +00:00
|
|
|
|
2016-02-06 09:09:17 +00:00
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Utility
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
inline void SetStatCacheTime(struct timespec& ts)
|
|
|
|
{
|
2022-01-24 23:36:27 +00:00
|
|
|
if(-1 == clock_gettime(static_cast<clockid_t>(CLOCK_MONOTONIC_COARSE), &ts)){
|
|
|
|
S3FS_PRN_CRIT("clock_gettime failed: %d", errno);
|
|
|
|
abort();
|
2020-08-22 12:40:53 +00:00
|
|
|
}
|
2016-02-06 09:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void InitStatCacheTime(struct timespec& ts)
|
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
ts.tv_sec = 0;
|
|
|
|
ts.tv_nsec = 0;
|
2016-02-06 09:09:17 +00:00
|
|
|
}
|
|
|
|
|
2019-09-23 10:49:49 +00:00
|
|
|
inline int CompareStatCacheTime(const struct timespec& ts1, const struct timespec& ts2)
|
2016-02-06 09:09:17 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
// return -1: ts1 < ts2
|
|
|
|
// 0: ts1 == ts2
|
|
|
|
// 1: ts1 > ts2
|
|
|
|
if(ts1.tv_sec < ts2.tv_sec){
|
|
|
|
return -1;
|
|
|
|
}else if(ts1.tv_sec > ts2.tv_sec){
|
|
|
|
return 1;
|
|
|
|
}else{
|
|
|
|
if(ts1.tv_nsec < ts2.tv_nsec){
|
|
|
|
return -1;
|
|
|
|
}else if(ts1.tv_nsec > ts2.tv_nsec){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2016-02-06 09:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool IsExpireStatCacheTime(const struct timespec& ts, const time_t& expire)
|
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
struct timespec nowts;
|
|
|
|
SetStatCacheTime(nowts);
|
2021-05-07 18:24:36 +00:00
|
|
|
nowts.tv_sec -= expire;
|
|
|
|
|
|
|
|
return (0 < CompareStatCacheTime(nowts, ts));
|
2016-02-06 09:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-11-26 13:42:44 +00:00
|
|
|
// For stats cache out
|
2016-02-06 09:09:17 +00:00
|
|
|
//
|
|
|
|
typedef std::vector<stat_cache_t::iterator> statiterlist_t;
|
|
|
|
|
|
|
|
struct sort_statiterlist{
|
2020-08-22 12:40:53 +00:00
|
|
|
// ascending order
|
|
|
|
bool operator()(const stat_cache_t::iterator& src1, const stat_cache_t::iterator& src2) const
|
|
|
|
{
|
2023-08-20 03:10:47 +00:00
|
|
|
int result = CompareStatCacheTime(src1->second.cache_date, src2->second.cache_date);
|
2020-08-22 12:40:53 +00:00
|
|
|
if(0 == result){
|
2023-08-20 03:10:47 +00:00
|
|
|
if(src1->second.hit_count < src2->second.hit_count){
|
2020-08-22 12:40:53 +00:00
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (result < 0);
|
|
|
|
}
|
2016-02-06 09:09:17 +00:00
|
|
|
};
|
|
|
|
|
2019-11-26 13:42:44 +00:00
|
|
|
//
|
|
|
|
// For symbolic link cache out
|
|
|
|
//
|
|
|
|
typedef std::vector<symlink_cache_t::iterator> symlinkiterlist_t;
|
|
|
|
|
|
|
|
struct sort_symlinkiterlist{
|
2020-08-22 12:40:53 +00:00
|
|
|
// ascending order
|
|
|
|
bool operator()(const symlink_cache_t::iterator& src1, const symlink_cache_t::iterator& src2) const
|
|
|
|
{
|
2023-08-20 03:10:47 +00:00
|
|
|
int result = CompareStatCacheTime(src1->second.cache_date, src2->second.cache_date); // use the same as Stats
|
2020-08-22 12:40:53 +00:00
|
|
|
if(0 == result){
|
2023-08-20 03:10:47 +00:00
|
|
|
if(src1->second.hit_count < src2->second.hit_count){
|
2020-08-22 12:40:53 +00:00
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (result < 0);
|
|
|
|
}
|
2019-11-26 13:42:44 +00:00
|
|
|
};
|
|
|
|
|
2013-03-30 13:37:14 +00:00
|
|
|
//-------------------------------------------------------------------
|
2013-04-06 17:39:22 +00:00
|
|
|
// Static
|
2013-03-30 13:37:14 +00:00
|
|
|
//-------------------------------------------------------------------
|
2013-09-14 21:50:39 +00:00
|
|
|
StatCache StatCache::singleton;
|
2013-04-06 17:39:22 +00:00
|
|
|
pthread_mutex_t StatCache::stat_cache_lock;
|
2013-03-30 13:37:14 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
2013-04-06 17:39:22 +00:00
|
|
|
// Constructor/Destructor
|
2013-03-30 13:37:14 +00:00
|
|
|
//-------------------------------------------------------------------
|
2022-03-12 07:57:31 +00:00
|
|
|
StatCache::StatCache() : IsExpireTime(true), IsExpireIntervalType(false), ExpireTime(15 * 60), CacheSize(100000), IsCacheNoObject(true)
|
2013-04-06 17:39:22 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
if(this == StatCache::getStatCacheData()){
|
|
|
|
stat_cache.clear();
|
|
|
|
pthread_mutexattr_t attr;
|
|
|
|
pthread_mutexattr_init(&attr);
|
2019-07-08 01:59:46 +00:00
|
|
|
#if S3FS_PTHREAD_ERRORCHECK
|
2020-08-22 12:40:53 +00:00
|
|
|
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
|
2019-07-08 01:59:46 +00:00
|
|
|
#endif
|
2021-01-24 22:56:10 +00:00
|
|
|
int result;
|
|
|
|
if(0 != (result = pthread_mutex_init(&StatCache::stat_cache_lock, &attr))){
|
|
|
|
S3FS_PRN_CRIT("failed to init stat_cache_lock: %d", result);
|
2020-08-22 12:40:53 +00:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
abort();
|
|
|
|
}
|
2013-04-06 17:39:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StatCache::~StatCache()
|
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
if(this == StatCache::getStatCacheData()){
|
|
|
|
Clear();
|
2021-01-24 22:56:10 +00:00
|
|
|
int result = pthread_mutex_destroy(&StatCache::stat_cache_lock);
|
|
|
|
if(result != 0){
|
|
|
|
S3FS_PRN_CRIT("failed to destroy stat_cache_lock: %d", result);
|
2020-08-22 12:40:53 +00:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
abort();
|
|
|
|
}
|
2013-04-06 17:39:22 +00:00
|
|
|
}
|
2013-03-30 13:37:14 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
2013-04-06 17:39:22 +00:00
|
|
|
// Methods
|
2013-03-30 13:37:14 +00:00
|
|
|
//-------------------------------------------------------------------
|
2019-01-23 23:44:50 +00:00
|
|
|
unsigned long StatCache::GetCacheSize() const
|
2013-04-06 17:39:22 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
return CacheSize;
|
2013-04-06 17:39:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long StatCache::SetCacheSize(unsigned long size)
|
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
unsigned long old = CacheSize;
|
|
|
|
CacheSize = size;
|
|
|
|
return old;
|
2013-04-06 17:39:22 +00:00
|
|
|
}
|
|
|
|
|
2019-01-23 23:44:50 +00:00
|
|
|
time_t StatCache::GetExpireTime() const
|
2013-04-06 17:39:22 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
return (IsExpireTime ? ExpireTime : (-1));
|
2013-04-06 17:39:22 +00:00
|
|
|
}
|
|
|
|
|
2017-03-19 15:19:04 +00:00
|
|
|
time_t StatCache::SetExpireTime(time_t expire, bool is_interval)
|
2013-03-30 13:37:14 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
time_t old = ExpireTime;
|
|
|
|
ExpireTime = expire;
|
|
|
|
IsExpireTime = true;
|
|
|
|
IsExpireIntervalType = is_interval;
|
|
|
|
return old;
|
2013-03-30 13:37:14 +00:00
|
|
|
}
|
|
|
|
|
2019-01-23 23:44:50 +00:00
|
|
|
time_t StatCache::UnsetExpireTime()
|
2013-03-30 13:37:14 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
time_t old = IsExpireTime ? ExpireTime : (-1);
|
|
|
|
ExpireTime = 0;
|
|
|
|
IsExpireTime = false;
|
|
|
|
IsExpireIntervalType = false;
|
|
|
|
return old;
|
2013-03-30 13:37:14 +00:00
|
|
|
}
|
2011-02-25 17:35:12 +00:00
|
|
|
|
2013-05-08 07:51:22 +00:00
|
|
|
bool StatCache::SetCacheNoObject(bool flag)
|
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
bool old = IsCacheNoObject;
|
|
|
|
IsCacheNoObject = flag;
|
|
|
|
return old;
|
2013-05-08 07:51:22 +00:00
|
|
|
}
|
|
|
|
|
2019-01-23 23:44:50 +00:00
|
|
|
void StatCache::Clear()
|
2013-09-14 21:50:39 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
AutoLock lock(&StatCache::stat_cache_lock);
|
2013-09-14 21:50:39 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
stat_cache.clear();
|
|
|
|
S3FS_MALLOCTRIM(0);
|
2013-09-14 21:50:39 +00:00
|
|
|
}
|
|
|
|
|
2020-09-11 09:37:24 +00:00
|
|
|
bool StatCache::GetStat(const std::string& key, struct stat* pst, headers_t* meta, bool overcheck, const char* petag, bool* pisforce)
|
2013-03-30 13:37:14 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
bool is_delete_cache = false;
|
2020-09-11 09:37:24 +00:00
|
|
|
std::string strpath = key;
|
2020-08-22 12:40:53 +00:00
|
|
|
|
|
|
|
AutoLock lock(&StatCache::stat_cache_lock);
|
|
|
|
|
|
|
|
stat_cache_t::iterator iter = stat_cache.end();
|
2021-06-13 04:26:38 +00:00
|
|
|
if(overcheck && '/' != *strpath.rbegin()){
|
2020-08-22 12:40:53 +00:00
|
|
|
strpath += "/";
|
|
|
|
iter = stat_cache.find(strpath);
|
|
|
|
}
|
|
|
|
if(iter == stat_cache.end()){
|
|
|
|
strpath = key;
|
|
|
|
iter = stat_cache.find(strpath);
|
|
|
|
}
|
|
|
|
|
2023-08-20 03:10:47 +00:00
|
|
|
if(iter != stat_cache.end()){
|
|
|
|
stat_cache_entry* ent = &iter->second;
|
2021-05-07 18:24:36 +00:00
|
|
|
if(0 < ent->notruncate || !IsExpireTime || !IsExpireStatCacheTime(ent->cache_date, ExpireTime)){
|
2020-08-22 12:40:53 +00:00
|
|
|
if(ent->noobjcache){
|
|
|
|
if(!IsCacheNoObject){
|
|
|
|
// need to delete this cache.
|
2022-07-30 06:33:37 +00:00
|
|
|
DelStat(strpath, AutoLock::ALREADY_LOCKED);
|
2020-08-22 12:40:53 +00:00
|
|
|
}else{
|
|
|
|
// noobjcache = true means no object.
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// hit without checking etag
|
2020-09-11 09:37:24 +00:00
|
|
|
std::string stretag;
|
2020-08-22 12:40:53 +00:00
|
|
|
if(petag){
|
|
|
|
// find & check ETag
|
|
|
|
for(headers_t::iterator hiter = ent->meta.begin(); hiter != ent->meta.end(); ++hiter){
|
2020-09-11 09:37:24 +00:00
|
|
|
std::string tag = lower(hiter->first);
|
2020-08-22 12:40:53 +00:00
|
|
|
if(tag == "etag"){
|
|
|
|
stretag = hiter->second;
|
2023-08-15 12:22:36 +00:00
|
|
|
if('\0' != petag[0] && petag != stretag){
|
2020-08-22 12:40:53 +00:00
|
|
|
is_delete_cache = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(is_delete_cache){
|
|
|
|
// not hit by different ETag
|
|
|
|
S3FS_PRN_DBG("stat cache not hit by ETag[path=%s][time=%lld.%09ld][hit count=%lu][ETag(%s)!=(%s)]",
|
|
|
|
strpath.c_str(), static_cast<long long>(ent->cache_date.tv_sec), ent->cache_date.tv_nsec, ent->hit_count, petag ? petag : "null", stretag.c_str());
|
|
|
|
}else{
|
|
|
|
// hit
|
|
|
|
S3FS_PRN_DBG("stat cache hit [path=%s][time=%lld.%09ld][hit count=%lu]",
|
|
|
|
strpath.c_str(), static_cast<long long>(ent->cache_date.tv_sec), ent->cache_date.tv_nsec, ent->hit_count);
|
|
|
|
|
2023-07-27 12:56:58 +00:00
|
|
|
if(pst!= nullptr){
|
2020-08-22 12:40:53 +00:00
|
|
|
*pst= ent->stbuf;
|
|
|
|
}
|
2023-07-27 12:56:58 +00:00
|
|
|
if(meta != nullptr){
|
2020-08-22 12:40:53 +00:00
|
|
|
*meta = ent->meta;
|
|
|
|
}
|
2023-07-27 12:56:58 +00:00
|
|
|
if(pisforce != nullptr){
|
2020-08-22 12:40:53 +00:00
|
|
|
(*pisforce) = ent->isforce;
|
|
|
|
}
|
|
|
|
ent->hit_count++;
|
|
|
|
|
|
|
|
if(IsExpireIntervalType){
|
|
|
|
SetStatCacheTime(ent->cache_date);
|
|
|
|
}
|
|
|
|
return true;
|
2016-03-13 09:29:06 +00:00
|
|
|
}
|
2017-03-19 15:19:04 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
}else{
|
|
|
|
// timeout
|
|
|
|
is_delete_cache = true;
|
2017-03-19 15:19:04 +00:00
|
|
|
}
|
Summary of Changes(1.62 -> 1.63)
1) Lifetime for the stats cache
Added the new option "stat_cache_expire".
This option which is specified by seconds means the lifetime for each stats cache entry.
If this option is not specified, the stats cache is kept in s3fs process until the stats cache grown to maximum size. (default)
If this option is specified, the stats cache entry is out from the memory when the entry expires time.
2) Enable file permission
s3fs before 1.62 did not consider the file access permission.
s3fs after this version can consider it.
For access permission, the s3fs_getattr() function was divided into sub function which can check the file access permission.
It is like access() function.
And the function calling the s3fs_getattr() calls this new sub function instead of s3fs_getattr().
Last the s3fs_opendir() function which is called by FUSE was added for checking directory access permission when listing the files in directory.
3) UID/GUID
When a file or a directory was created, the s3fs could not set the UID/GID as the user who executed a command.
(Almost the UID/GID are root, because the s3fs run by root.)
After this version, the s3fs set correct UID/GID as the user who executes the commond.
4) About the mtime
If the object does not have "x-amz-meta-mtime" meta, the s3fs uses the "Last-Modified" header instead of it.
But the s3fs had a bug in this code, and this version fixed this bug.
When user modified the file, the s3fs did not update the mtime of the file.
This version fixed this bug.
In the get_local_fd() function, the local file's mtime was changed only when s3fs run with "use_cache" option.
This version always updates the mtime whether the local cache file is used or not.
And s3fs_flush ( ) function set the mtime of local cache file from S3 object mtime, but it was wrong .
This version is that the s3fs_flush ( ) changes the mtime of S3 object from the local cache file or the tmpfile .
The s3fs cuts some requests, because the s3fs can always check mtime whether the s3fs uses or does not use the local cache file.
5) A case of no "x-amz-meta-mode"
If the object did not have "x-amz-meta-mtime" mete, the s3fs recognized the file as not regular file.
After this version, the s3fs recognizes the file as regular file.
6) "." and ".." directory
The s3fs_readdir() did not return "X" and "XX" directory name.
After this version, the s3fs is changed that it returns "X" and "XX".
Example, the result of "ls" lists "X" and "XX" directory.
7) Fixed a bug
The insert_object() had a bug, and it is fixed.
git-svn-id: http://s3fs.googlecode.com/svn/trunk@390 df820570-a93a-0410-bd06-b72b767a4274
2013-02-24 08:58:54 +00:00
|
|
|
}
|
2011-02-25 17:35:12 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
if(is_delete_cache){
|
2022-07-30 06:33:37 +00:00
|
|
|
DelStat(strpath, AutoLock::ALREADY_LOCKED);
|
2020-08-22 12:40:53 +00:00
|
|
|
}
|
|
|
|
return false;
|
2011-02-25 17:35:12 +00:00
|
|
|
}
|
|
|
|
|
2020-09-11 09:37:24 +00:00
|
|
|
bool StatCache::IsNoObjectCache(const std::string& key, bool overcheck)
|
2013-05-08 07:51:22 +00:00
|
|
|
{
|
2020-09-11 09:37:24 +00:00
|
|
|
bool is_delete_cache = false;
|
|
|
|
std::string strpath = key;
|
2013-05-08 07:51:22 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
if(!IsCacheNoObject){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoLock lock(&StatCache::stat_cache_lock);
|
|
|
|
|
|
|
|
stat_cache_t::iterator iter = stat_cache.end();
|
2021-06-13 04:26:38 +00:00
|
|
|
if(overcheck && '/' != *strpath.rbegin()){
|
2020-08-22 12:40:53 +00:00
|
|
|
strpath += "/";
|
|
|
|
iter = stat_cache.find(strpath);
|
|
|
|
}
|
|
|
|
if(iter == stat_cache.end()){
|
|
|
|
strpath = key;
|
|
|
|
iter = stat_cache.find(strpath);
|
2013-05-08 07:51:22 +00:00
|
|
|
}
|
|
|
|
|
2023-08-20 03:10:47 +00:00
|
|
|
if(iter != stat_cache.end()) {
|
|
|
|
const stat_cache_entry* ent = &iter->second;
|
|
|
|
if(0 < ent->notruncate || !IsExpireTime || !IsExpireStatCacheTime(iter->second.cache_date, ExpireTime)){
|
|
|
|
if(iter->second.noobjcache){
|
2020-08-22 12:40:53 +00:00
|
|
|
// noobjcache = true means no object.
|
2023-08-20 03:10:47 +00:00
|
|
|
SetStatCacheTime((*iter).second.cache_date);
|
2020-08-22 12:40:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
// timeout
|
|
|
|
is_delete_cache = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_delete_cache){
|
2022-07-30 06:33:37 +00:00
|
|
|
DelStat(strpath, AutoLock::ALREADY_LOCKED);
|
2020-08-22 12:40:53 +00:00
|
|
|
}
|
|
|
|
return false;
|
2013-05-08 07:51:22 +00:00
|
|
|
}
|
|
|
|
|
2023-01-04 11:23:39 +00:00
|
|
|
bool StatCache::AddStat(const std::string& key, const headers_t& meta, bool forcedir, bool no_truncate)
|
2013-03-30 13:37:14 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
if(!no_truncate && CacheSize< 1){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
S3FS_PRN_INFO3("add stat cache entry[path=%s]", key.c_str());
|
|
|
|
|
|
|
|
bool found;
|
|
|
|
bool do_truncate;
|
|
|
|
{
|
|
|
|
AutoLock lock(&StatCache::stat_cache_lock);
|
|
|
|
found = stat_cache.end() != stat_cache.find(key);
|
|
|
|
do_truncate = stat_cache.size() > CacheSize;
|
|
|
|
}
|
2013-04-06 17:39:22 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
if(found){
|
|
|
|
DelStat(key.c_str());
|
|
|
|
}else{
|
|
|
|
if(do_truncate){
|
2023-07-25 13:41:00 +00:00
|
|
|
// cppcheck-suppress unmatchedSuppression
|
|
|
|
// cppcheck-suppress knownConditionTrueFalse
|
2020-08-22 12:40:53 +00:00
|
|
|
if(!TruncateCache()){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// make new
|
2023-08-20 03:10:47 +00:00
|
|
|
stat_cache_entry ent;
|
|
|
|
if(!convert_header_to_stat(key.c_str(), meta, &ent.stbuf, forcedir)){
|
2013-09-14 21:50:39 +00:00
|
|
|
return false;
|
2013-04-06 17:39:22 +00:00
|
|
|
}
|
2023-08-20 03:10:47 +00:00
|
|
|
ent.hit_count = 0;
|
|
|
|
ent.isforce = forcedir;
|
|
|
|
ent.noobjcache = false;
|
|
|
|
ent.notruncate = (no_truncate ? 1L : 0L);
|
|
|
|
ent.meta.clear();
|
|
|
|
SetStatCacheTime(ent.cache_date); // Set time.
|
2020-08-22 12:40:53 +00:00
|
|
|
//copy only some keys
|
2023-01-04 11:23:39 +00:00
|
|
|
for(headers_t::const_iterator iter = meta.begin(); iter != meta.end(); ++iter){
|
2020-09-11 09:37:24 +00:00
|
|
|
std::string tag = lower(iter->first);
|
|
|
|
std::string value = iter->second;
|
2020-08-22 12:40:53 +00:00
|
|
|
if(tag == "content-type"){
|
2023-08-20 03:10:47 +00:00
|
|
|
ent.meta[iter->first] = value;
|
2020-08-22 12:40:53 +00:00
|
|
|
}else if(tag == "content-length"){
|
2023-08-20 03:10:47 +00:00
|
|
|
ent.meta[iter->first] = value;
|
2020-08-22 12:40:53 +00:00
|
|
|
}else if(tag == "etag"){
|
2023-08-20 03:10:47 +00:00
|
|
|
ent.meta[iter->first] = value;
|
2020-08-22 12:40:53 +00:00
|
|
|
}else if(tag == "last-modified"){
|
2023-08-20 03:10:47 +00:00
|
|
|
ent.meta[iter->first] = value;
|
2020-09-26 05:09:20 +00:00
|
|
|
}else if(is_prefix(tag.c_str(), "x-amz")){
|
2023-08-20 03:10:47 +00:00
|
|
|
ent.meta[tag] = value; // key is lower case for "x-amz"
|
2020-08-22 12:40:53 +00:00
|
|
|
}
|
|
|
|
}
|
2011-02-25 17:35:12 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
// add
|
|
|
|
AutoLock lock(&StatCache::stat_cache_lock);
|
|
|
|
|
2023-08-13 15:03:10 +00:00
|
|
|
std::pair<stat_cache_t::iterator, bool> pair = stat_cache.emplace(key, std::move(ent));
|
2019-11-26 13:42:44 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
// check symbolic link cache
|
2023-08-20 03:10:47 +00:00
|
|
|
if(!S_ISLNK(pair.first->second.stbuf.st_mode)){
|
2020-08-22 12:40:53 +00:00
|
|
|
if(symlink_cache.end() != symlink_cache.find(key)){
|
|
|
|
// if symbolic link cache has key, thus remove it.
|
2022-07-30 06:33:37 +00:00
|
|
|
DelSymlink(key.c_str(), AutoLock::ALREADY_LOCKED);
|
2020-08-22 12:40:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2011-02-25 17:35:12 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 18:24:36 +00:00
|
|
|
// [NOTE]
|
|
|
|
// Updates only meta data if cached data exists.
|
|
|
|
// And when these are updated, it also updates the cache time.
|
|
|
|
//
|
2022-05-29 09:52:10 +00:00
|
|
|
// Since the file mode may change while the file is open, it is
|
|
|
|
// updated as well.
|
|
|
|
//
|
2021-05-07 18:24:36 +00:00
|
|
|
bool StatCache::UpdateMetaStats(const std::string& key, headers_t& meta)
|
|
|
|
{
|
|
|
|
if(CacheSize < 1){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
S3FS_PRN_INFO3("update stat cache entry[path=%s]", key.c_str());
|
|
|
|
|
|
|
|
AutoLock lock(&StatCache::stat_cache_lock);
|
|
|
|
stat_cache_t::iterator iter = stat_cache.find(key);
|
2023-08-20 03:10:47 +00:00
|
|
|
if(stat_cache.end() == iter){
|
2021-05-07 18:24:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
2023-08-20 03:10:47 +00:00
|
|
|
stat_cache_entry* ent = &iter->second;
|
2021-05-07 18:24:36 +00:00
|
|
|
|
|
|
|
// update only meta keys
|
|
|
|
for(headers_t::iterator metaiter = meta.begin(); metaiter != meta.end(); ++metaiter){
|
|
|
|
std::string tag = lower(metaiter->first);
|
|
|
|
std::string value = metaiter->second;
|
|
|
|
if(tag == "content-type"){
|
|
|
|
ent->meta[metaiter->first] = value;
|
|
|
|
}else if(tag == "content-length"){
|
|
|
|
ent->meta[metaiter->first] = value;
|
|
|
|
}else if(tag == "etag"){
|
|
|
|
ent->meta[metaiter->first] = value;
|
|
|
|
}else if(tag == "last-modified"){
|
|
|
|
ent->meta[metaiter->first] = value;
|
|
|
|
}else if(is_prefix(tag.c_str(), "x-amz")){
|
|
|
|
ent->meta[tag] = value; // key is lower case for "x-amz"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update time.
|
|
|
|
SetStatCacheTime(ent->cache_date);
|
|
|
|
|
2022-05-29 09:52:10 +00:00
|
|
|
// Update only mode
|
2023-03-11 07:45:56 +00:00
|
|
|
ent->stbuf.st_mode = get_mode(meta, key);
|
2022-05-29 09:52:10 +00:00
|
|
|
|
2021-05-07 18:24:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-11 09:37:24 +00:00
|
|
|
bool StatCache::AddNoObjectCache(const std::string& key)
|
2013-05-08 07:51:22 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
if(!IsCacheNoObject){
|
|
|
|
return true; // pretend successful
|
|
|
|
}
|
|
|
|
if(CacheSize < 1){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
S3FS_PRN_INFO3("add no object cache entry[path=%s]", key.c_str());
|
|
|
|
|
|
|
|
bool found;
|
|
|
|
bool do_truncate;
|
|
|
|
{
|
|
|
|
AutoLock lock(&StatCache::stat_cache_lock);
|
|
|
|
found = stat_cache.end() != stat_cache.find(key);
|
|
|
|
do_truncate = stat_cache.size() > CacheSize;
|
|
|
|
}
|
2013-05-08 07:51:22 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
if(found){
|
|
|
|
DelStat(key.c_str());
|
|
|
|
}else{
|
|
|
|
if(do_truncate){
|
2023-07-25 13:41:00 +00:00
|
|
|
// cppcheck-suppress unmatchedSuppression
|
|
|
|
// cppcheck-suppress knownConditionTrueFalse
|
2020-08-22 12:40:53 +00:00
|
|
|
if(!TruncateCache()){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// make new
|
2023-08-20 03:10:47 +00:00
|
|
|
stat_cache_entry ent;
|
|
|
|
memset(&ent.stbuf, 0, sizeof(struct stat));
|
|
|
|
ent.hit_count = 0;
|
|
|
|
ent.isforce = false;
|
|
|
|
ent.noobjcache = true;
|
|
|
|
ent.notruncate = 0L;
|
|
|
|
ent.meta.clear();
|
|
|
|
SetStatCacheTime(ent.cache_date); // Set time.
|
2020-08-22 12:40:53 +00:00
|
|
|
|
|
|
|
// add
|
2019-01-25 22:40:36 +00:00
|
|
|
AutoLock lock(&StatCache::stat_cache_lock);
|
2020-08-22 12:40:53 +00:00
|
|
|
|
2023-08-13 15:03:10 +00:00
|
|
|
stat_cache.emplace(key, std::move(ent));
|
2020-08-22 12:40:53 +00:00
|
|
|
|
|
|
|
// check symbolic link cache
|
|
|
|
if(symlink_cache.end() != symlink_cache.find(key)){
|
|
|
|
// if symbolic link cache has key, thus remove it.
|
2022-07-30 06:33:37 +00:00
|
|
|
DelSymlink(key.c_str(), AutoLock::ALREADY_LOCKED);
|
2020-08-22 12:40:53 +00:00
|
|
|
}
|
|
|
|
return true;
|
2013-05-08 07:51:22 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 01:25:09 +00:00
|
|
|
void StatCache::ChangeNoTruncateFlag(const std::string& key, bool no_truncate)
|
2016-03-13 05:43:28 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
AutoLock lock(&StatCache::stat_cache_lock);
|
|
|
|
stat_cache_t::iterator iter = stat_cache.find(key);
|
|
|
|
|
|
|
|
if(stat_cache.end() != iter){
|
2023-08-20 03:10:47 +00:00
|
|
|
stat_cache_entry* ent = &iter->second;
|
2023-08-20 10:00:20 +00:00
|
|
|
if(no_truncate){
|
|
|
|
++(ent->notruncate);
|
|
|
|
}else{
|
|
|
|
if(0L < ent->notruncate){
|
|
|
|
--(ent->notruncate);
|
2020-08-22 12:40:53 +00:00
|
|
|
}
|
2016-03-13 05:43:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-23 23:44:50 +00:00
|
|
|
bool StatCache::TruncateCache()
|
2013-03-30 13:37:14 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
AutoLock lock(&StatCache::stat_cache_lock);
|
|
|
|
|
|
|
|
if(stat_cache.empty()){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 1) erase over expire time
|
|
|
|
if(IsExpireTime){
|
|
|
|
for(stat_cache_t::iterator iter = stat_cache.begin(); iter != stat_cache.end(); ){
|
2023-08-20 10:00:20 +00:00
|
|
|
const stat_cache_entry* entry = &iter->second;
|
|
|
|
if(0L == entry->notruncate && IsExpireStatCacheTime(entry->cache_date, ExpireTime)){
|
2023-07-27 14:34:43 +00:00
|
|
|
iter = stat_cache.erase(iter);
|
2020-08-22 12:40:53 +00:00
|
|
|
}else{
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2) check stat cache count
|
|
|
|
if(stat_cache.size() < CacheSize){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3) erase from the old cache in order
|
|
|
|
size_t erase_count= stat_cache.size() - CacheSize + 1;
|
|
|
|
statiterlist_t erase_iters;
|
|
|
|
for(stat_cache_t::iterator iter = stat_cache.begin(); iter != stat_cache.end() && 0 < erase_count; ++iter){
|
|
|
|
// check no truncate
|
2023-08-20 03:10:47 +00:00
|
|
|
const stat_cache_entry* ent = &iter->second;
|
2023-08-20 10:00:20 +00:00
|
|
|
if(0L < ent->notruncate){
|
2020-08-22 12:40:53 +00:00
|
|
|
// skip for no truncate entry and keep extra counts for this entity.
|
|
|
|
if(0 < erase_count){
|
|
|
|
--erase_count; // decrement
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
// iter is not have notruncate flag
|
|
|
|
erase_iters.push_back(iter);
|
|
|
|
}
|
|
|
|
if(erase_count < erase_iters.size()){
|
2022-07-30 03:06:47 +00:00
|
|
|
std::sort(erase_iters.begin(), erase_iters.end(), sort_statiterlist());
|
2020-08-22 12:40:53 +00:00
|
|
|
while(erase_count < erase_iters.size()){
|
|
|
|
erase_iters.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(statiterlist_t::iterator iiter = erase_iters.begin(); iiter != erase_iters.end(); ++iiter){
|
|
|
|
stat_cache_t::iterator siter = *iiter;
|
|
|
|
|
|
|
|
S3FS_PRN_DBG("truncate stat cache[path=%s]", siter->first.c_str());
|
|
|
|
stat_cache.erase(siter);
|
|
|
|
}
|
|
|
|
S3FS_MALLOCTRIM(0);
|
2019-01-25 22:40:36 +00:00
|
|
|
|
2016-02-06 09:09:17 +00:00
|
|
|
return true;
|
2013-04-06 17:39:22 +00:00
|
|
|
}
|
|
|
|
|
2022-07-30 06:33:37 +00:00
|
|
|
bool StatCache::DelStat(const char* key, AutoLock::Type locktype)
|
2013-04-06 17:39:22 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
if(!key){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
S3FS_PRN_INFO3("delete stat cache entry[path=%s]", key);
|
2013-04-06 17:39:22 +00:00
|
|
|
|
2022-07-30 06:33:37 +00:00
|
|
|
AutoLock lock(&StatCache::stat_cache_lock, locktype);
|
2013-09-14 21:50:39 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
stat_cache_t::iterator iter;
|
2023-08-17 13:12:28 +00:00
|
|
|
if(stat_cache.end() != (iter = stat_cache.find(key))){
|
2020-08-22 12:40:53 +00:00
|
|
|
stat_cache.erase(iter);
|
2013-04-06 17:39:22 +00:00
|
|
|
}
|
2020-08-22 12:40:53 +00:00
|
|
|
if(0 < strlen(key) && 0 != strcmp(key, "/")){
|
2020-09-11 09:37:24 +00:00
|
|
|
std::string strpath = key;
|
2021-06-13 04:26:38 +00:00
|
|
|
if('/' == *strpath.rbegin()){
|
2020-08-22 12:40:53 +00:00
|
|
|
// If there is "path" cache, delete it.
|
2021-01-25 09:02:32 +00:00
|
|
|
strpath.erase(strpath.length() - 1);
|
2020-08-22 12:40:53 +00:00
|
|
|
}else{
|
|
|
|
// If there is "path/" cache, delete it.
|
|
|
|
strpath += "/";
|
|
|
|
}
|
|
|
|
if(stat_cache.end() != (iter = stat_cache.find(strpath))){
|
|
|
|
stat_cache.erase(iter);
|
|
|
|
}
|
2013-03-30 14:03:06 +00:00
|
|
|
}
|
2020-08-22 12:40:53 +00:00
|
|
|
S3FS_MALLOCTRIM(0);
|
2013-09-14 21:50:39 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
return true;
|
2011-02-25 17:35:12 +00:00
|
|
|
}
|
|
|
|
|
2020-09-11 09:37:24 +00:00
|
|
|
bool StatCache::GetSymlink(const std::string& key, std::string& value)
|
2019-11-26 13:42:44 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
bool is_delete_cache = false;
|
2020-09-11 09:37:24 +00:00
|
|
|
const std::string& strpath = key;
|
2019-11-26 13:42:44 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
AutoLock lock(&StatCache::stat_cache_lock);
|
2019-11-26 13:42:44 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
symlink_cache_t::iterator iter = symlink_cache.find(strpath);
|
2023-08-20 03:10:47 +00:00
|
|
|
if(iter != symlink_cache.end()){
|
|
|
|
symlink_cache_entry* ent = &iter->second;
|
2020-08-22 12:40:53 +00:00
|
|
|
if(!IsExpireTime || !IsExpireStatCacheTime(ent->cache_date, ExpireTime)){ // use the same as Stats
|
|
|
|
// found
|
|
|
|
S3FS_PRN_DBG("symbolic link cache hit [path=%s][time=%lld.%09ld][hit count=%lu]",
|
|
|
|
strpath.c_str(), static_cast<long long>(ent->cache_date.tv_sec), ent->cache_date.tv_nsec, ent->hit_count);
|
2019-11-26 13:42:44 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
value = ent->link;
|
2019-11-26 13:42:44 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
ent->hit_count++;
|
|
|
|
if(IsExpireIntervalType){
|
|
|
|
SetStatCacheTime(ent->cache_date);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
// timeout
|
|
|
|
is_delete_cache = true;
|
2019-11-26 13:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
if(is_delete_cache){
|
2022-07-30 06:33:37 +00:00
|
|
|
DelSymlink(strpath.c_str(), AutoLock::ALREADY_LOCKED);
|
2020-08-22 12:40:53 +00:00
|
|
|
}
|
|
|
|
return false;
|
2019-11-26 13:42:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-11 09:37:24 +00:00
|
|
|
bool StatCache::AddSymlink(const std::string& key, const std::string& value)
|
2019-11-26 13:42:44 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
if(CacheSize< 1){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
S3FS_PRN_INFO3("add symbolic link cache entry[path=%s, value=%s]", key.c_str(), value.c_str());
|
|
|
|
|
|
|
|
bool found;
|
|
|
|
bool do_truncate;
|
|
|
|
{
|
|
|
|
AutoLock lock(&StatCache::stat_cache_lock);
|
|
|
|
found = symlink_cache.end() != symlink_cache.find(key);
|
|
|
|
do_truncate = symlink_cache.size() > CacheSize;
|
|
|
|
}
|
2019-11-26 13:42:44 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
if(found){
|
|
|
|
DelSymlink(key.c_str());
|
|
|
|
}else{
|
|
|
|
if(do_truncate){
|
2023-07-25 13:41:00 +00:00
|
|
|
// cppcheck-suppress unmatchedSuppression
|
|
|
|
// cppcheck-suppress knownConditionTrueFalse
|
2020-08-22 12:40:53 +00:00
|
|
|
if(!TruncateSymlink()){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-11-26 13:42:44 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
// make new
|
2023-08-20 03:10:47 +00:00
|
|
|
symlink_cache_entry ent;
|
|
|
|
ent.link = value;
|
|
|
|
ent.hit_count = 0;
|
|
|
|
SetStatCacheTime(ent.cache_date); // Set time(use the same as Stats).
|
2019-11-26 13:42:44 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
// add
|
|
|
|
AutoLock lock(&StatCache::stat_cache_lock);
|
2019-11-26 13:42:44 +00:00
|
|
|
|
2023-08-13 15:03:10 +00:00
|
|
|
symlink_cache.emplace(key, std::move(ent));
|
2019-11-26 13:42:44 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
return true;
|
2019-11-26 13:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool StatCache::TruncateSymlink()
|
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
AutoLock lock(&StatCache::stat_cache_lock);
|
|
|
|
|
|
|
|
if(symlink_cache.empty()){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 1) erase over expire time
|
|
|
|
if(IsExpireTime){
|
|
|
|
for(symlink_cache_t::iterator iter = symlink_cache.begin(); iter != symlink_cache.end(); ){
|
2023-08-20 03:10:47 +00:00
|
|
|
const symlink_cache_entry* entry = &iter->second;
|
|
|
|
if(IsExpireStatCacheTime(entry->cache_date, ExpireTime)){ // use the same as Stats
|
2023-07-27 14:34:43 +00:00
|
|
|
iter = symlink_cache.erase(iter);
|
2020-08-22 12:40:53 +00:00
|
|
|
}else{
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2) check stat cache count
|
|
|
|
if(symlink_cache.size() < CacheSize){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3) erase from the old cache in order
|
|
|
|
size_t erase_count= symlink_cache.size() - CacheSize + 1;
|
|
|
|
symlinkiterlist_t erase_iters;
|
|
|
|
for(symlink_cache_t::iterator iter = symlink_cache.begin(); iter != symlink_cache.end(); ++iter){
|
|
|
|
erase_iters.push_back(iter);
|
|
|
|
sort(erase_iters.begin(), erase_iters.end(), sort_symlinkiterlist());
|
|
|
|
if(erase_count < erase_iters.size()){
|
|
|
|
erase_iters.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(symlinkiterlist_t::iterator iiter = erase_iters.begin(); iiter != erase_iters.end(); ++iiter){
|
|
|
|
symlink_cache_t::iterator siter = *iiter;
|
|
|
|
|
|
|
|
S3FS_PRN_DBG("truncate symbolic link cache[path=%s]", siter->first.c_str());
|
|
|
|
symlink_cache.erase(siter);
|
|
|
|
}
|
|
|
|
S3FS_MALLOCTRIM(0);
|
2019-11-26 13:42:44 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-07-30 06:33:37 +00:00
|
|
|
bool StatCache::DelSymlink(const char* key, AutoLock::Type locktype)
|
2019-11-26 13:42:44 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
if(!key){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
S3FS_PRN_INFO3("delete symbolic link cache entry[path=%s]", key);
|
2019-11-26 13:42:44 +00:00
|
|
|
|
2022-07-30 06:33:37 +00:00
|
|
|
AutoLock lock(&StatCache::stat_cache_lock, locktype);
|
2019-11-26 13:42:44 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
symlink_cache_t::iterator iter;
|
2023-08-17 13:12:28 +00:00
|
|
|
if(symlink_cache.end() != (iter = symlink_cache.find(key))){
|
2020-08-22 12:40:53 +00:00
|
|
|
symlink_cache.erase(iter);
|
|
|
|
}
|
|
|
|
S3FS_MALLOCTRIM(0);
|
2019-11-26 13:42:44 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
return true;
|
2019-11-26 13:42:44 +00:00
|
|
|
}
|
|
|
|
|
2013-04-06 17:39:22 +00:00
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Functions
|
|
|
|
//-------------------------------------------------------------------
|
2020-08-20 14:46:11 +00:00
|
|
|
bool convert_header_to_stat(const char* path, const headers_t& meta, struct stat* pst, bool forcedir)
|
2013-04-06 17:39:22 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
if(!path || !pst){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
memset(pst, 0, sizeof(struct stat));
|
2011-02-25 17:35:12 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
pst->st_nlink = 1; // see fuse FAQ
|
2013-04-06 17:39:22 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
// mode
|
|
|
|
pst->st_mode = get_mode(meta, path, true, forcedir);
|
2013-04-06 17:39:22 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
// blocks
|
|
|
|
if(S_ISREG(pst->st_mode)){
|
|
|
|
pst->st_blocks = get_blocks(pst->st_size);
|
|
|
|
}
|
|
|
|
pst->st_blksize = 4096;
|
2013-04-06 17:39:22 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
// mtime
|
2021-04-18 04:11:12 +00:00
|
|
|
struct timespec mtime = get_mtime(meta);
|
2020-10-03 02:14:23 +00:00
|
|
|
if(pst->st_mtime < 0){
|
|
|
|
pst->st_mtime = 0L;
|
2021-04-18 04:11:12 +00:00
|
|
|
}else{
|
2022-01-29 01:59:06 +00:00
|
|
|
if(mtime.tv_sec < 0){
|
|
|
|
mtime.tv_sec = 0;
|
|
|
|
mtime.tv_nsec = 0;
|
|
|
|
}
|
2023-07-30 13:53:17 +00:00
|
|
|
set_timespec_to_stat(*pst, stat_time_type::MTIME, mtime);
|
2020-10-03 02:14:23 +00:00
|
|
|
}
|
2011-02-25 17:35:12 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
// ctime
|
2021-04-18 04:11:12 +00:00
|
|
|
struct timespec ctime = get_ctime(meta);
|
2020-10-03 02:14:23 +00:00
|
|
|
if(pst->st_ctime < 0){
|
|
|
|
pst->st_ctime = 0L;
|
2021-04-18 04:11:12 +00:00
|
|
|
}else{
|
2022-01-29 01:59:06 +00:00
|
|
|
if(ctime.tv_sec < 0){
|
|
|
|
ctime.tv_sec = 0;
|
|
|
|
ctime.tv_nsec = 0;
|
|
|
|
}
|
2023-07-30 13:53:17 +00:00
|
|
|
set_timespec_to_stat(*pst, stat_time_type::CTIME, ctime);
|
2020-10-03 02:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// atime
|
2021-04-18 04:11:12 +00:00
|
|
|
struct timespec atime = get_atime(meta);
|
2020-10-03 02:14:23 +00:00
|
|
|
if(pst->st_atime < 0){
|
|
|
|
pst->st_atime = 0L;
|
2021-04-18 04:11:12 +00:00
|
|
|
}else{
|
2022-01-29 01:59:06 +00:00
|
|
|
if(atime.tv_sec < 0){
|
|
|
|
atime.tv_sec = 0;
|
|
|
|
atime.tv_nsec = 0;
|
|
|
|
}
|
2023-07-30 13:53:17 +00:00
|
|
|
set_timespec_to_stat(*pst, stat_time_type::ATIME, atime);
|
2020-10-03 02:14:23 +00:00
|
|
|
}
|
2019-01-07 01:51:42 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
// size
|
|
|
|
pst->st_size = get_size(meta);
|
2013-04-06 17:39:22 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
// uid/gid
|
|
|
|
pst->st_uid = get_uid(meta);
|
|
|
|
pst->st_gid = get_gid(meta);
|
2011-02-25 17:35:12 +00:00
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
return true;
|
2011-02-25 17:35:12 +00:00
|
|
|
}
|
2013-03-30 13:37:14 +00:00
|
|
|
|
2014-09-07 15:08:27 +00:00
|
|
|
/*
|
|
|
|
* Local variables:
|
2020-08-22 12:40:53 +00:00
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
2014-09-07 15:08:27 +00:00
|
|
|
* End:
|
2020-08-22 12:40:53 +00:00
|
|
|
* vim600: expandtab sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: expandtab sw=4 ts=4
|
2014-09-07 15:08:27 +00:00
|
|
|
*/
|