2011-02-25 17:35:12 +00:00
|
|
|
/*
|
|
|
|
* s3fs - FUSE-based file system backed by Amazon S3
|
|
|
|
*
|
|
|
|
* Copyright 2007-2008 Randy Rizun <rrizun@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2011-09-26 15:20:14 +00:00
|
|
|
#include <stdio.h>
|
2011-02-25 17:35:12 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2016-02-07 07:40:55 +00:00
|
|
|
#ifndef HAVE_CLOCK_GETTIME
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
2011-02-25 17:35:12 +00:00
|
|
|
#include <unistd.h>
|
2013-08-19 06:29:24 +00:00
|
|
|
#include <stdint.h>
|
2011-02-25 17:35:12 +00:00
|
|
|
#include <pthread.h>
|
2013-03-30 14:03:06 +00:00
|
|
|
#include <string.h>
|
2013-04-06 17:39:22 +00:00
|
|
|
#include <assert.h>
|
2013-08-10 15:29:39 +00:00
|
|
|
#include <syslog.h>
|
2011-02-25 17:35:12 +00:00
|
|
|
#include <string>
|
|
|
|
#include <map>
|
2016-02-06 09:09:17 +00:00
|
|
|
#include <vector>
|
2013-04-06 17:39:22 +00:00
|
|
|
#include <algorithm>
|
2013-04-20 19:17:28 +00:00
|
|
|
#include <list>
|
2011-02-25 17:35:12 +00:00
|
|
|
|
|
|
|
#include "cache.h"
|
2013-09-14 21:50:39 +00:00
|
|
|
#include "s3fs.h"
|
2013-04-06 17:39:22 +00:00
|
|
|
#include "s3fs_util.h"
|
2015-01-28 17:13:11 +00:00
|
|
|
#include "string_util.h"
|
2011-02-25 17:35:12 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2016-02-06 09:09:17 +00:00
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Utility
|
|
|
|
//-------------------------------------------------------------------
|
2016-02-07 08:27:02 +00:00
|
|
|
#ifndef CLOCK_REALTIME
|
|
|
|
#define CLOCK_REALTIME 0
|
|
|
|
#endif
|
2016-02-07 08:10:23 +00:00
|
|
|
#ifndef CLOCK_MONOTONIC
|
|
|
|
#define CLOCK_MONOTONIC CLOCK_REALTIME
|
|
|
|
#endif
|
|
|
|
#ifndef CLOCK_MONOTONIC_COARSE
|
|
|
|
#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
|
2016-02-07 07:40:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_CLOCK_GETTIME
|
|
|
|
static int clock_gettime(int clk_id, struct timespec* ts)
|
|
|
|
{
|
|
|
|
struct timeval now;
|
|
|
|
if(0 != gettimeofday(&now, NULL)){
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ts->tv_sec = now.tv_sec;
|
|
|
|
ts->tv_nsec = now.tv_usec * 1000;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-06 09:09:17 +00:00
|
|
|
inline void SetStatCacheTime(struct timespec& ts)
|
|
|
|
{
|
|
|
|
if(-1 == clock_gettime(CLOCK_MONOTONIC_COARSE, &ts)){
|
|
|
|
ts.tv_sec = time(NULL);
|
|
|
|
ts.tv_nsec = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void InitStatCacheTime(struct timespec& ts)
|
|
|
|
{
|
|
|
|
ts.tv_sec = 0;
|
|
|
|
ts.tv_nsec = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int CompareStatCacheTime(struct timespec& ts1, struct timespec& ts2)
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool IsExpireStatCacheTime(const struct timespec& ts, const time_t& expire)
|
|
|
|
{
|
|
|
|
return ((ts.tv_sec + expire) < time(NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// For cache out
|
|
|
|
//
|
|
|
|
typedef std::vector<stat_cache_t::iterator> statiterlist_t;
|
|
|
|
|
|
|
|
struct sort_statiterlist{
|
|
|
|
// ascending order
|
|
|
|
bool operator()(const stat_cache_t::iterator& src1, const stat_cache_t::iterator& src2) const
|
|
|
|
{
|
|
|
|
int result = CompareStatCacheTime(src1->second->cache_date, src2->second->cache_date);
|
|
|
|
if(0 == result){
|
|
|
|
if(src1->second->hit_count < src2->second->hit_count){
|
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (result < 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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
|
|
|
//-------------------------------------------------------------------
|
2013-09-14 21:50:39 +00:00
|
|
|
StatCache::StatCache() : IsExpireTime(false), ExpireTime(0), CacheSize(1000), IsCacheNoObject(false)
|
2013-04-06 17:39:22 +00:00
|
|
|
{
|
|
|
|
if(this == StatCache::getStatCacheData()){
|
2013-09-14 21:50:39 +00:00
|
|
|
stat_cache.clear();
|
2013-04-06 17:39:22 +00:00
|
|
|
pthread_mutex_init(&(StatCache::stat_cache_lock), NULL);
|
|
|
|
}else{
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StatCache::~StatCache()
|
|
|
|
{
|
|
|
|
if(this == StatCache::getStatCacheData()){
|
2013-09-14 21:50:39 +00:00
|
|
|
Clear();
|
2013-04-06 17:39:22 +00:00
|
|
|
pthread_mutex_destroy(&(StatCache::stat_cache_lock));
|
|
|
|
}else{
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
//-------------------------------------------------------------------
|
2013-04-06 17:39:22 +00:00
|
|
|
unsigned long StatCache::GetCacheSize(void) const
|
|
|
|
{
|
|
|
|
return CacheSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long StatCache::SetCacheSize(unsigned long size)
|
|
|
|
{
|
|
|
|
unsigned long old = CacheSize;
|
|
|
|
CacheSize = size;
|
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
|
|
|
time_t StatCache::GetExpireTime(void) const
|
|
|
|
{
|
|
|
|
return (IsExpireTime ? ExpireTime : (-1));
|
|
|
|
}
|
|
|
|
|
|
|
|
time_t StatCache::SetExpireTime(time_t expire)
|
2013-03-30 13:37:14 +00:00
|
|
|
{
|
2013-04-06 17:39:22 +00:00
|
|
|
time_t old = ExpireTime;
|
|
|
|
ExpireTime = expire;
|
|
|
|
IsExpireTime = true;
|
|
|
|
return old;
|
2013-03-30 13:37:14 +00:00
|
|
|
}
|
|
|
|
|
2013-04-06 17:39:22 +00:00
|
|
|
time_t StatCache::UnsetExpireTime(void)
|
2013-03-30 13:37:14 +00:00
|
|
|
{
|
2013-04-06 17:39:22 +00:00
|
|
|
time_t old = IsExpireTime ? ExpireTime : (-1);
|
|
|
|
ExpireTime = 0;
|
|
|
|
IsExpireTime = 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)
|
|
|
|
{
|
|
|
|
bool old = IsCacheNoObject;
|
|
|
|
IsCacheNoObject = flag;
|
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
2013-09-14 21:50:39 +00:00
|
|
|
void StatCache::Clear(void)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&StatCache::stat_cache_lock);
|
|
|
|
|
|
|
|
for(stat_cache_t::iterator iter = stat_cache.begin(); iter != stat_cache.end(); stat_cache.erase(iter++)){
|
|
|
|
if((*iter).second){
|
|
|
|
delete (*iter).second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
S3FS_MALLOCTRIM(0);
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&StatCache::stat_cache_lock);
|
|
|
|
}
|
|
|
|
|
2013-04-29 14:31:10 +00:00
|
|
|
bool StatCache::GetStat(string& key, struct stat* pst, headers_t* meta, bool overcheck, const char* petag, bool* pisforce)
|
2013-03-30 13:37:14 +00:00
|
|
|
{
|
2013-04-06 17:39:22 +00:00
|
|
|
bool is_delete_cache = false;
|
|
|
|
string strpath = key;
|
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
|
|
|
|
2013-04-06 17:39:22 +00:00
|
|
|
pthread_mutex_lock(&StatCache::stat_cache_lock);
|
Summary of Changes(1.63 -> 1.64)
* This new version was made for fixing big issue about directory object.
Please be careful and review new s3fs.
==========================
List of Changes
==========================
1) Fixed bugs
Fixed some memory leak and un-freed curl handle.
Fixed codes with a bug which is not found yet.
Fixed a bug that the s3fs could not update object's mtime when the s3fs had a opened file descriptor.
Please let us know a bug, when you find new bug of a memory leak.
2) Changed codes
Changed codes of s3fs_readdir() and list_bucket() etc.
Changed codes so that the get_realpath() function returned std::string.
Changed codes about exit() function. Because the exit() function is called from many fuse callback function directly, these function called fuse_exit() function and retuned with error.
Changed codes so that the case of the characters for the "x-amz-meta" response header is ignored.
3) Added a option
Added the norenameapi option for the storage compatible with S3 without copy API.
This option is subset of nocopyapi option.
Please read man page or call with --help option.
4) Object for directory
This is very big and important change.
The object of directory is changed "dir/" instead of "dir" for being compatible with other S3 client applications.
And this version understands the object of directory which is made by old version.
If the new s3fs changes the attributes or owner/group or mtime of the directory object, the s3fs automatically changes the object from old object name("dir") to new("dir/").
If you need to change old object name("dir") to new("dir/") manually, you can use shell script(mergedir.sh) in test directory.
* About the directory object name
AWS S3 allows the object name as both "dir" and "dir/".
The s3fs before this version understood only "dir" as directory object name, but old version did not understand the "dir/" object name.
The new version understands both of "dir" and "dir/" object name.
The s3fs user needs to be care for the special situation that I mentioned later.
The new version deletes old "dir" object and makes new "dir/" object, when the user operates the directory object for changing the permission or owner/group or mtime.
This operation does on background and automatically.
If you need to merge manually, you can use shell script which is mergedir.sh in test directory.
This script runs chmod/chown/touch commands after finding a directory.
Other S3 client application makes a directory object("dir/") without meta information which is needed to understand by the s3fs, this script can add meta information for a directory object.
If this script function is insufficient for you, you can read and modify the codes by yourself.
Please use the shell script carefully because of changing the object.
If you find a bug in this script, please let me know.
* Details
** The directory object made by old version
The directory object made by old version is not understood by other S3 client application.
New s3fs version was updated for keeping compatibility with other clients.
You can use the mergedir.sh in test directory for merging from old directory object("dir") to new("dir/").
The directory object name is changed from "dir" to "dir/" after the mergedir.sh is run, this changed "dir/" object is understood by other S3 clients.
This script runs chmod/chown/chgrp/touch/etc commands against the old directory object("dir"), then new s3fs merges that directory automatically.
If you need to change directory object from old to new manually, you can do it by running these commands which change the directory attributes(mode/owner/group/mtime).
** The directory object made by new version
The directory object name made by new version is "dir/".
Because the name includes "/", other S3 client applications understand it as the directory.
I tested new directory by s3cmd/tntDrive/DragonDisk/Gladinet as other S3 clients, the result was good compatibility.
You need to know that the compatibility has small problem by the difference in specifications between clients.
And you need to be careful about that the old s3fs can not understand the directory object which made by new s3fs.
You should change all s3fs which accesses same bucket.
** The directory object made by other S3 client application
Because the object is determined as a directory by the s3fs, the s3fs makes and uses special meta information which is "x-amz-meta-***" and "Content-Type" as HTTP header.
The s3fs sets and uses HTTP headers for the directory object, those headers are listed below.
Content-Type: application/x-directory
x-amz-meta-mode: <mode>
x-amz-meta-uid: <UID>
x-amz-meta-gid <GID>
x-amz-meta-mtime: <unix time of modified file>
Other S3 client application builds the directory object without attributes which is needed by the s3fs.
When the "ls" command is run on the s3fs-fuse file system which has directories/files made by other S3 clients, this result is shown below.
d--------- 1 root root 0 Feb 27 11:21 dir
---------- 1 root root 1024 Mar 14 02:15 file
Because the objects don't have meta information("x-amz-meta-mode"), it means mode=0000.
In this case, the directory object is shown only "d", because the s3fs determines the object as a directory when the object is the name with "/" or has "Content-type: application/x-directory" header.
(The s3fs sets "Content-Type: application/x-directory" to the directory object, but other S3 clients set "binary/octet-stream".)
In that result, nobody without root is allowed to operate the object.
The owner and group are "root"(UID=0) because the object doesn't have "x-amz-meta-uid/gid".
If the object doesn't have "x-amz-meta-mtime", the s3fs uses "Last-Modified" HTTP header.
Therefore the object's mtime is "Last-Modified" value.(This logic is same as old version)
It has been already explained, if you need to change the object attributes, you can do it by manually operation or mergedir.sh.
* Example of the compatibility with s3cmd etc
** Case A) Only "dir/file" object
One of case, there is only "dir/file" object without "dir/" object, that object is made by s3cmd or etc.
In this case, the response of REST API(list bucket) with "delimiter=/" parameter has "CommonPrefixes", and the "dir/" is listed in "CommonPrefixes/Prefix", but the "dir/" object is not real object.
The s3fs needs to determine this object as directory, however there is no real directory object("dir" or "dir/").
But both new s3fs and old one does NOT understand this "dir/" in "CommonPrefixes", because the s3fs fails to get meta information from "dir" or "dir/".
On this case, the result of "ls" command is shown below.
??????????? ? ? ? ? ? dir
This "dir" is not operated by anyone and any process, because the s3fs does not understand this object permission.
And "dir/file" object can not be shown and operated too.
Some other S3 clients(tntDrive/Gladinet/etc) can not understand this object as same as the s3fs.
If you need to operate "dir/file" object, you need to make the "dir/" object as a directory.
To make the "dir/" directory object, you need to do below.
Because there is already the "dir" object which is not real object, you can not make "dir/" directory.
(s3cmd does not make "dir/" object because the object name has "/".).
You should make another name directory(ex: "dir2/"), and move the "dir/file" objects to in new directory.
Last, you can rename the directory name from "dir2/" to "dir/".
** Case B) Both "dir" and "dir/file" object
This case is that there are "dir" and "dir/file" objects which were made by s3cmd/etc.
s3cmd and s3fs understand the "dir" object as normal(file) object because this object does not have meta information and a name with "/".
But the result of REST API(list bucket) has "dir/" name in "CommonPrefixes/Prefix".
The s3fs checks "dir/" and "dir" as a directory, but the "dir" object is not directory object.
(Because the new s3fs need to compatible old version, the s3fs checks a directory object in order of "dir/", "dir")
In this case, the result of "ls" command is shown below.
---------- 1 root root 0 Feb 27 02:48 dir
As a result, the "dir/file" can not be shown and operated because the "dir" object is a file.
If you determine the "dir" as a directory, you need to add mete information to the "dir" object by s3cmd.
** Case C) Both "dir" and "dir/" object
Last case is that there are "dir" and "dir/" objects which were made by other S3 clients.
(example: At first you upload a object "dir/" as a directory by new 3sfs, and you upload a object "dir" by s3cmd.)
New s3fs determines "dir/" as a directory, because the s3fs searches in oder of "dir/", "dir".
As a result, the "dir" object can not be shown and operated.
** Compatibility between S3 clients
Both new and old s3fs do not understand both "dir" and "dir/" at the same time, tntDrive and Galdinet are same as the s3fs.
If there are "dir/" and "dir" objects, the s3fs gives priority to "dir/".
But s3cmd and DragonDisk understand both objects.
git-svn-id: http://s3fs.googlecode.com/svn/trunk@392 df820570-a93a-0410-bd06-b72b767a4274
2013-03-23 14:04:07 +00:00
|
|
|
|
|
|
|
stat_cache_t::iterator iter = stat_cache.end();
|
2013-04-06 17:39:22 +00:00
|
|
|
if(overcheck && '/' != strpath[strpath.length() - 1]){
|
Summary of Changes(1.63 -> 1.64)
* This new version was made for fixing big issue about directory object.
Please be careful and review new s3fs.
==========================
List of Changes
==========================
1) Fixed bugs
Fixed some memory leak and un-freed curl handle.
Fixed codes with a bug which is not found yet.
Fixed a bug that the s3fs could not update object's mtime when the s3fs had a opened file descriptor.
Please let us know a bug, when you find new bug of a memory leak.
2) Changed codes
Changed codes of s3fs_readdir() and list_bucket() etc.
Changed codes so that the get_realpath() function returned std::string.
Changed codes about exit() function. Because the exit() function is called from many fuse callback function directly, these function called fuse_exit() function and retuned with error.
Changed codes so that the case of the characters for the "x-amz-meta" response header is ignored.
3) Added a option
Added the norenameapi option for the storage compatible with S3 without copy API.
This option is subset of nocopyapi option.
Please read man page or call with --help option.
4) Object for directory
This is very big and important change.
The object of directory is changed "dir/" instead of "dir" for being compatible with other S3 client applications.
And this version understands the object of directory which is made by old version.
If the new s3fs changes the attributes or owner/group or mtime of the directory object, the s3fs automatically changes the object from old object name("dir") to new("dir/").
If you need to change old object name("dir") to new("dir/") manually, you can use shell script(mergedir.sh) in test directory.
* About the directory object name
AWS S3 allows the object name as both "dir" and "dir/".
The s3fs before this version understood only "dir" as directory object name, but old version did not understand the "dir/" object name.
The new version understands both of "dir" and "dir/" object name.
The s3fs user needs to be care for the special situation that I mentioned later.
The new version deletes old "dir" object and makes new "dir/" object, when the user operates the directory object for changing the permission or owner/group or mtime.
This operation does on background and automatically.
If you need to merge manually, you can use shell script which is mergedir.sh in test directory.
This script runs chmod/chown/touch commands after finding a directory.
Other S3 client application makes a directory object("dir/") without meta information which is needed to understand by the s3fs, this script can add meta information for a directory object.
If this script function is insufficient for you, you can read and modify the codes by yourself.
Please use the shell script carefully because of changing the object.
If you find a bug in this script, please let me know.
* Details
** The directory object made by old version
The directory object made by old version is not understood by other S3 client application.
New s3fs version was updated for keeping compatibility with other clients.
You can use the mergedir.sh in test directory for merging from old directory object("dir") to new("dir/").
The directory object name is changed from "dir" to "dir/" after the mergedir.sh is run, this changed "dir/" object is understood by other S3 clients.
This script runs chmod/chown/chgrp/touch/etc commands against the old directory object("dir"), then new s3fs merges that directory automatically.
If you need to change directory object from old to new manually, you can do it by running these commands which change the directory attributes(mode/owner/group/mtime).
** The directory object made by new version
The directory object name made by new version is "dir/".
Because the name includes "/", other S3 client applications understand it as the directory.
I tested new directory by s3cmd/tntDrive/DragonDisk/Gladinet as other S3 clients, the result was good compatibility.
You need to know that the compatibility has small problem by the difference in specifications between clients.
And you need to be careful about that the old s3fs can not understand the directory object which made by new s3fs.
You should change all s3fs which accesses same bucket.
** The directory object made by other S3 client application
Because the object is determined as a directory by the s3fs, the s3fs makes and uses special meta information which is "x-amz-meta-***" and "Content-Type" as HTTP header.
The s3fs sets and uses HTTP headers for the directory object, those headers are listed below.
Content-Type: application/x-directory
x-amz-meta-mode: <mode>
x-amz-meta-uid: <UID>
x-amz-meta-gid <GID>
x-amz-meta-mtime: <unix time of modified file>
Other S3 client application builds the directory object without attributes which is needed by the s3fs.
When the "ls" command is run on the s3fs-fuse file system which has directories/files made by other S3 clients, this result is shown below.
d--------- 1 root root 0 Feb 27 11:21 dir
---------- 1 root root 1024 Mar 14 02:15 file
Because the objects don't have meta information("x-amz-meta-mode"), it means mode=0000.
In this case, the directory object is shown only "d", because the s3fs determines the object as a directory when the object is the name with "/" or has "Content-type: application/x-directory" header.
(The s3fs sets "Content-Type: application/x-directory" to the directory object, but other S3 clients set "binary/octet-stream".)
In that result, nobody without root is allowed to operate the object.
The owner and group are "root"(UID=0) because the object doesn't have "x-amz-meta-uid/gid".
If the object doesn't have "x-amz-meta-mtime", the s3fs uses "Last-Modified" HTTP header.
Therefore the object's mtime is "Last-Modified" value.(This logic is same as old version)
It has been already explained, if you need to change the object attributes, you can do it by manually operation or mergedir.sh.
* Example of the compatibility with s3cmd etc
** Case A) Only "dir/file" object
One of case, there is only "dir/file" object without "dir/" object, that object is made by s3cmd or etc.
In this case, the response of REST API(list bucket) with "delimiter=/" parameter has "CommonPrefixes", and the "dir/" is listed in "CommonPrefixes/Prefix", but the "dir/" object is not real object.
The s3fs needs to determine this object as directory, however there is no real directory object("dir" or "dir/").
But both new s3fs and old one does NOT understand this "dir/" in "CommonPrefixes", because the s3fs fails to get meta information from "dir" or "dir/".
On this case, the result of "ls" command is shown below.
??????????? ? ? ? ? ? dir
This "dir" is not operated by anyone and any process, because the s3fs does not understand this object permission.
And "dir/file" object can not be shown and operated too.
Some other S3 clients(tntDrive/Gladinet/etc) can not understand this object as same as the s3fs.
If you need to operate "dir/file" object, you need to make the "dir/" object as a directory.
To make the "dir/" directory object, you need to do below.
Because there is already the "dir" object which is not real object, you can not make "dir/" directory.
(s3cmd does not make "dir/" object because the object name has "/".).
You should make another name directory(ex: "dir2/"), and move the "dir/file" objects to in new directory.
Last, you can rename the directory name from "dir2/" to "dir/".
** Case B) Both "dir" and "dir/file" object
This case is that there are "dir" and "dir/file" objects which were made by s3cmd/etc.
s3cmd and s3fs understand the "dir" object as normal(file) object because this object does not have meta information and a name with "/".
But the result of REST API(list bucket) has "dir/" name in "CommonPrefixes/Prefix".
The s3fs checks "dir/" and "dir" as a directory, but the "dir" object is not directory object.
(Because the new s3fs need to compatible old version, the s3fs checks a directory object in order of "dir/", "dir")
In this case, the result of "ls" command is shown below.
---------- 1 root root 0 Feb 27 02:48 dir
As a result, the "dir/file" can not be shown and operated because the "dir" object is a file.
If you determine the "dir" as a directory, you need to add mete information to the "dir" object by s3cmd.
** Case C) Both "dir" and "dir/" object
Last case is that there are "dir" and "dir/" objects which were made by other S3 clients.
(example: At first you upload a object "dir/" as a directory by new 3sfs, and you upload a object "dir" by s3cmd.)
New s3fs determines "dir/" as a directory, because the s3fs searches in oder of "dir/", "dir".
As a result, the "dir" object can not be shown and operated.
** Compatibility between S3 clients
Both new and old s3fs do not understand both "dir" and "dir/" at the same time, tntDrive and Galdinet are same as the s3fs.
If there are "dir/" and "dir" objects, the s3fs gives priority to "dir/".
But s3cmd and DragonDisk understand both objects.
git-svn-id: http://s3fs.googlecode.com/svn/trunk@392 df820570-a93a-0410-bd06-b72b767a4274
2013-03-23 14:04:07 +00:00
|
|
|
strpath += "/";
|
|
|
|
iter = stat_cache.find(strpath.c_str());
|
|
|
|
}
|
|
|
|
if(iter == stat_cache.end()){
|
2013-04-06 17:39:22 +00:00
|
|
|
strpath = key;
|
Summary of Changes(1.63 -> 1.64)
* This new version was made for fixing big issue about directory object.
Please be careful and review new s3fs.
==========================
List of Changes
==========================
1) Fixed bugs
Fixed some memory leak and un-freed curl handle.
Fixed codes with a bug which is not found yet.
Fixed a bug that the s3fs could not update object's mtime when the s3fs had a opened file descriptor.
Please let us know a bug, when you find new bug of a memory leak.
2) Changed codes
Changed codes of s3fs_readdir() and list_bucket() etc.
Changed codes so that the get_realpath() function returned std::string.
Changed codes about exit() function. Because the exit() function is called from many fuse callback function directly, these function called fuse_exit() function and retuned with error.
Changed codes so that the case of the characters for the "x-amz-meta" response header is ignored.
3) Added a option
Added the norenameapi option for the storage compatible with S3 without copy API.
This option is subset of nocopyapi option.
Please read man page or call with --help option.
4) Object for directory
This is very big and important change.
The object of directory is changed "dir/" instead of "dir" for being compatible with other S3 client applications.
And this version understands the object of directory which is made by old version.
If the new s3fs changes the attributes or owner/group or mtime of the directory object, the s3fs automatically changes the object from old object name("dir") to new("dir/").
If you need to change old object name("dir") to new("dir/") manually, you can use shell script(mergedir.sh) in test directory.
* About the directory object name
AWS S3 allows the object name as both "dir" and "dir/".
The s3fs before this version understood only "dir" as directory object name, but old version did not understand the "dir/" object name.
The new version understands both of "dir" and "dir/" object name.
The s3fs user needs to be care for the special situation that I mentioned later.
The new version deletes old "dir" object and makes new "dir/" object, when the user operates the directory object for changing the permission or owner/group or mtime.
This operation does on background and automatically.
If you need to merge manually, you can use shell script which is mergedir.sh in test directory.
This script runs chmod/chown/touch commands after finding a directory.
Other S3 client application makes a directory object("dir/") without meta information which is needed to understand by the s3fs, this script can add meta information for a directory object.
If this script function is insufficient for you, you can read and modify the codes by yourself.
Please use the shell script carefully because of changing the object.
If you find a bug in this script, please let me know.
* Details
** The directory object made by old version
The directory object made by old version is not understood by other S3 client application.
New s3fs version was updated for keeping compatibility with other clients.
You can use the mergedir.sh in test directory for merging from old directory object("dir") to new("dir/").
The directory object name is changed from "dir" to "dir/" after the mergedir.sh is run, this changed "dir/" object is understood by other S3 clients.
This script runs chmod/chown/chgrp/touch/etc commands against the old directory object("dir"), then new s3fs merges that directory automatically.
If you need to change directory object from old to new manually, you can do it by running these commands which change the directory attributes(mode/owner/group/mtime).
** The directory object made by new version
The directory object name made by new version is "dir/".
Because the name includes "/", other S3 client applications understand it as the directory.
I tested new directory by s3cmd/tntDrive/DragonDisk/Gladinet as other S3 clients, the result was good compatibility.
You need to know that the compatibility has small problem by the difference in specifications between clients.
And you need to be careful about that the old s3fs can not understand the directory object which made by new s3fs.
You should change all s3fs which accesses same bucket.
** The directory object made by other S3 client application
Because the object is determined as a directory by the s3fs, the s3fs makes and uses special meta information which is "x-amz-meta-***" and "Content-Type" as HTTP header.
The s3fs sets and uses HTTP headers for the directory object, those headers are listed below.
Content-Type: application/x-directory
x-amz-meta-mode: <mode>
x-amz-meta-uid: <UID>
x-amz-meta-gid <GID>
x-amz-meta-mtime: <unix time of modified file>
Other S3 client application builds the directory object without attributes which is needed by the s3fs.
When the "ls" command is run on the s3fs-fuse file system which has directories/files made by other S3 clients, this result is shown below.
d--------- 1 root root 0 Feb 27 11:21 dir
---------- 1 root root 1024 Mar 14 02:15 file
Because the objects don't have meta information("x-amz-meta-mode"), it means mode=0000.
In this case, the directory object is shown only "d", because the s3fs determines the object as a directory when the object is the name with "/" or has "Content-type: application/x-directory" header.
(The s3fs sets "Content-Type: application/x-directory" to the directory object, but other S3 clients set "binary/octet-stream".)
In that result, nobody without root is allowed to operate the object.
The owner and group are "root"(UID=0) because the object doesn't have "x-amz-meta-uid/gid".
If the object doesn't have "x-amz-meta-mtime", the s3fs uses "Last-Modified" HTTP header.
Therefore the object's mtime is "Last-Modified" value.(This logic is same as old version)
It has been already explained, if you need to change the object attributes, you can do it by manually operation or mergedir.sh.
* Example of the compatibility with s3cmd etc
** Case A) Only "dir/file" object
One of case, there is only "dir/file" object without "dir/" object, that object is made by s3cmd or etc.
In this case, the response of REST API(list bucket) with "delimiter=/" parameter has "CommonPrefixes", and the "dir/" is listed in "CommonPrefixes/Prefix", but the "dir/" object is not real object.
The s3fs needs to determine this object as directory, however there is no real directory object("dir" or "dir/").
But both new s3fs and old one does NOT understand this "dir/" in "CommonPrefixes", because the s3fs fails to get meta information from "dir" or "dir/".
On this case, the result of "ls" command is shown below.
??????????? ? ? ? ? ? dir
This "dir" is not operated by anyone and any process, because the s3fs does not understand this object permission.
And "dir/file" object can not be shown and operated too.
Some other S3 clients(tntDrive/Gladinet/etc) can not understand this object as same as the s3fs.
If you need to operate "dir/file" object, you need to make the "dir/" object as a directory.
To make the "dir/" directory object, you need to do below.
Because there is already the "dir" object which is not real object, you can not make "dir/" directory.
(s3cmd does not make "dir/" object because the object name has "/".).
You should make another name directory(ex: "dir2/"), and move the "dir/file" objects to in new directory.
Last, you can rename the directory name from "dir2/" to "dir/".
** Case B) Both "dir" and "dir/file" object
This case is that there are "dir" and "dir/file" objects which were made by s3cmd/etc.
s3cmd and s3fs understand the "dir" object as normal(file) object because this object does not have meta information and a name with "/".
But the result of REST API(list bucket) has "dir/" name in "CommonPrefixes/Prefix".
The s3fs checks "dir/" and "dir" as a directory, but the "dir" object is not directory object.
(Because the new s3fs need to compatible old version, the s3fs checks a directory object in order of "dir/", "dir")
In this case, the result of "ls" command is shown below.
---------- 1 root root 0 Feb 27 02:48 dir
As a result, the "dir/file" can not be shown and operated because the "dir" object is a file.
If you determine the "dir" as a directory, you need to add mete information to the "dir" object by s3cmd.
** Case C) Both "dir" and "dir/" object
Last case is that there are "dir" and "dir/" objects which were made by other S3 clients.
(example: At first you upload a object "dir/" as a directory by new 3sfs, and you upload a object "dir" by s3cmd.)
New s3fs determines "dir/" as a directory, because the s3fs searches in oder of "dir/", "dir".
As a result, the "dir" object can not be shown and operated.
** Compatibility between S3 clients
Both new and old s3fs do not understand both "dir" and "dir/" at the same time, tntDrive and Galdinet are same as the s3fs.
If there are "dir/" and "dir" objects, the s3fs gives priority to "dir/".
But s3cmd and DragonDisk understand both objects.
git-svn-id: http://s3fs.googlecode.com/svn/trunk@392 df820570-a93a-0410-bd06-b72b767a4274
2013-03-23 14:04:07 +00:00
|
|
|
iter = stat_cache.find(strpath.c_str());
|
|
|
|
}
|
|
|
|
|
2013-09-14 21:50:39 +00:00
|
|
|
if(iter != stat_cache.end() && (*iter).second){
|
|
|
|
stat_cache_entry* ent = (*iter).second;
|
2016-02-06 09:09:17 +00:00
|
|
|
if(!IsExpireTime || !IsExpireStatCacheTime(ent->cache_date, ExpireTime)){
|
2013-09-14 21:50:39 +00:00
|
|
|
if(ent->noobjcache){
|
2013-05-08 07:51:22 +00:00
|
|
|
pthread_mutex_unlock(&StatCache::stat_cache_lock);
|
|
|
|
if(!IsCacheNoObject){
|
|
|
|
// need to delete this cache.
|
|
|
|
DelStat(strpath);
|
|
|
|
}else{
|
|
|
|
// noobjcache = true means no object.
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-06 17:39:22 +00:00
|
|
|
// hit without checking etag
|
|
|
|
if(petag){
|
2013-09-14 21:50:39 +00:00
|
|
|
string stretag = ent->meta["ETag"];
|
2013-04-06 17:39:22 +00:00
|
|
|
if('\0' != petag[0] && 0 != strcmp(petag, stretag.c_str())){
|
|
|
|
is_delete_cache = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(is_delete_cache){
|
|
|
|
// not hit by different ETag
|
2016-02-06 09:09:17 +00:00
|
|
|
S3FS_PRN_DBG("stat cache not hit by ETag[path=%s][time=%jd.%09ld][hit count=%lu][ETag(%s)!=(%s)]",
|
|
|
|
strpath.c_str(), (intmax_t)(ent->cache_date.tv_sec), ent->cache_date.tv_nsec, ent->hit_count, petag ? petag : "null", ent->meta["ETag"].c_str());
|
2013-04-06 17:39:22 +00:00
|
|
|
}else{
|
|
|
|
// hit
|
2016-02-06 09:09:17 +00:00
|
|
|
S3FS_PRN_DBG("stat cache hit [path=%s][time=%jd.%09ld][hit count=%lu]",
|
|
|
|
strpath.c_str(), (intmax_t)(ent->cache_date.tv_sec), ent->cache_date.tv_nsec, ent->hit_count);
|
2011-02-25 17:35:12 +00:00
|
|
|
|
2013-04-06 17:39:22 +00:00
|
|
|
if(pst!= NULL){
|
2013-09-14 21:50:39 +00:00
|
|
|
*pst= ent->stbuf;
|
2013-04-06 17:39:22 +00:00
|
|
|
}
|
|
|
|
if(meta != NULL){
|
2013-09-14 21:50:39 +00:00
|
|
|
*meta = ent->meta;
|
2013-04-06 17:39:22 +00:00
|
|
|
}
|
2013-04-29 14:31:10 +00:00
|
|
|
if(pisforce != NULL){
|
2013-09-14 21:50:39 +00:00
|
|
|
(*pisforce) = ent->isforce;
|
2013-04-29 14:31:10 +00:00
|
|
|
}
|
2013-09-14 21:50:39 +00:00
|
|
|
ent->hit_count++;
|
2016-02-06 09:09:17 +00:00
|
|
|
SetStatCacheTime(ent->cache_date);
|
2013-04-06 17:39:22 +00:00
|
|
|
pthread_mutex_unlock(&StatCache::stat_cache_lock);
|
|
|
|
return true;
|
2013-03-30 13:37:14 +00:00
|
|
|
}
|
2013-04-06 17:39:22 +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
|
|
|
}else{
|
|
|
|
// timeout
|
2013-04-06 17:39:22 +00:00
|
|
|
is_delete_cache = true;
|
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
|
|
|
}
|
2013-04-06 17:39:22 +00:00
|
|
|
pthread_mutex_unlock(&StatCache::stat_cache_lock);
|
2011-02-25 17:35:12 +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
|
|
|
if(is_delete_cache){
|
2013-04-06 17:39:22 +00:00
|
|
|
DelStat(strpath);
|
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
|
|
|
}
|
2013-04-06 17:39:22 +00:00
|
|
|
return false;
|
2011-02-25 17:35:12 +00:00
|
|
|
}
|
|
|
|
|
2013-05-08 07:51:22 +00:00
|
|
|
bool StatCache::IsNoObjectCache(string& key, bool overcheck)
|
|
|
|
{
|
|
|
|
bool is_delete_cache = false;
|
|
|
|
string strpath = key;
|
|
|
|
|
|
|
|
if(!IsCacheNoObject){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_lock(&StatCache::stat_cache_lock);
|
|
|
|
|
|
|
|
stat_cache_t::iterator iter = stat_cache.end();
|
|
|
|
if(overcheck && '/' != strpath[strpath.length() - 1]){
|
|
|
|
strpath += "/";
|
|
|
|
iter = stat_cache.find(strpath.c_str());
|
|
|
|
}
|
|
|
|
if(iter == stat_cache.end()){
|
|
|
|
strpath = key;
|
|
|
|
iter = stat_cache.find(strpath.c_str());
|
|
|
|
}
|
|
|
|
|
2013-09-14 21:50:39 +00:00
|
|
|
if(iter != stat_cache.end() && (*iter).second) {
|
2016-02-06 09:09:17 +00:00
|
|
|
if(!IsExpireTime || !IsExpireStatCacheTime((*iter).second->cache_date, ExpireTime)){
|
2013-09-14 21:50:39 +00:00
|
|
|
if((*iter).second->noobjcache){
|
2013-05-08 07:51:22 +00:00
|
|
|
// noobjcache = true means no object.
|
2016-02-06 09:09:17 +00:00
|
|
|
SetStatCacheTime((*iter).second->cache_date);
|
2013-05-08 07:51:22 +00:00
|
|
|
pthread_mutex_unlock(&StatCache::stat_cache_lock);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
// timeout
|
|
|
|
is_delete_cache = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&StatCache::stat_cache_lock);
|
|
|
|
|
|
|
|
if(is_delete_cache){
|
|
|
|
DelStat(strpath);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-13 05:43:28 +00:00
|
|
|
bool StatCache::AddStat(std::string& key, headers_t& meta, bool forcedir, bool no_truncate)
|
2013-03-30 13:37:14 +00:00
|
|
|
{
|
2016-03-13 05:43:28 +00:00
|
|
|
if(!no_truncate && CacheSize< 1){
|
2013-04-06 17:39:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-09-30 19:41:27 +00:00
|
|
|
S3FS_PRN_INFO3("add stat cache entry[path=%s]", key.c_str());
|
2013-04-06 17:39:22 +00:00
|
|
|
|
2015-08-14 22:45:19 +00:00
|
|
|
pthread_mutex_lock(&StatCache::stat_cache_lock);
|
|
|
|
|
|
|
|
bool found = stat_cache.end() != stat_cache.find(key);
|
|
|
|
bool do_truncate = stat_cache.size() > CacheSize;
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&StatCache::stat_cache_lock);
|
|
|
|
|
|
|
|
if(found){
|
2013-09-14 21:50:39 +00:00
|
|
|
DelStat(key.c_str());
|
|
|
|
}else{
|
2015-08-14 22:45:19 +00:00
|
|
|
if(do_truncate){
|
2013-09-14 21:50:39 +00:00
|
|
|
if(!TruncateCache()){
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-06 17:39:22 +00:00
|
|
|
}
|
|
|
|
}
|
2011-02-25 17:35:12 +00:00
|
|
|
|
2013-09-14 21:50:39 +00:00
|
|
|
// make new
|
|
|
|
stat_cache_entry* ent = new stat_cache_entry();
|
|
|
|
if(!convert_header_to_stat(key.c_str(), meta, &(ent->stbuf), forcedir)){
|
|
|
|
delete ent;
|
2013-04-06 17:39:22 +00:00
|
|
|
return false;
|
2013-03-30 13:37:14 +00:00
|
|
|
}
|
2013-09-14 21:50:39 +00:00
|
|
|
ent->hit_count = 0;
|
|
|
|
ent->isforce = forcedir;
|
|
|
|
ent->noobjcache = false;
|
2016-03-13 05:43:28 +00:00
|
|
|
ent->notruncate = (no_truncate ? 1L : 0L);
|
2013-09-14 21:50:39 +00:00
|
|
|
ent->meta.clear();
|
2016-02-06 09:09:17 +00:00
|
|
|
SetStatCacheTime(ent->cache_date); // Set time.
|
2013-04-06 17:39:22 +00:00
|
|
|
//copy only some keys
|
2013-09-14 21:50:39 +00:00
|
|
|
for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter){
|
2015-01-28 17:13:11 +00:00
|
|
|
string tag = lower(iter->first);
|
|
|
|
string value = iter->second;
|
|
|
|
if(tag == "content-type"){
|
|
|
|
ent->meta[iter->first] = value;
|
|
|
|
}else if(tag == "content-length"){
|
|
|
|
ent->meta[iter->first] = value;
|
|
|
|
}else if(tag == "etag"){
|
|
|
|
ent->meta[iter->first] = value;
|
|
|
|
}else if(tag == "last-modified"){
|
|
|
|
ent->meta[iter->first] = value;
|
2013-04-06 17:39:22 +00:00
|
|
|
}else if(tag.substr(0, 5) == "x-amz"){
|
2015-01-28 17:13:11 +00:00
|
|
|
ent->meta[tag] = value; // key is lower case for "x-amz"
|
2013-04-06 17:39:22 +00:00
|
|
|
}
|
2013-03-30 13:37:14 +00:00
|
|
|
}
|
2013-09-14 21:50:39 +00:00
|
|
|
// add
|
|
|
|
pthread_mutex_lock(&StatCache::stat_cache_lock);
|
|
|
|
stat_cache[key] = ent;
|
2013-04-06 17:39:22 +00:00
|
|
|
pthread_mutex_unlock(&StatCache::stat_cache_lock);
|
|
|
|
|
|
|
|
return true;
|
2011-02-25 17:35:12 +00:00
|
|
|
}
|
|
|
|
|
2013-05-08 07:51:22 +00:00
|
|
|
bool StatCache::AddNoObjectCache(string& key)
|
|
|
|
{
|
|
|
|
if(!IsCacheNoObject){
|
|
|
|
return true; // pretend successful
|
|
|
|
}
|
|
|
|
if(CacheSize < 1){
|
|
|
|
return true;
|
|
|
|
}
|
2015-09-30 19:41:27 +00:00
|
|
|
S3FS_PRN_INFO3("add no object cache entry[path=%s]", key.c_str());
|
2013-05-08 07:51:22 +00:00
|
|
|
|
2015-08-14 22:45:19 +00:00
|
|
|
pthread_mutex_lock(&StatCache::stat_cache_lock);
|
|
|
|
|
|
|
|
bool found = stat_cache.end() != stat_cache.find(key);
|
|
|
|
bool do_truncate = stat_cache.size() > CacheSize;
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&StatCache::stat_cache_lock);
|
|
|
|
|
|
|
|
if(found){
|
2013-09-14 21:50:39 +00:00
|
|
|
DelStat(key.c_str());
|
|
|
|
}else{
|
2015-08-14 22:45:19 +00:00
|
|
|
if(do_truncate){
|
2013-09-14 21:50:39 +00:00
|
|
|
if(!TruncateCache()){
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-08 07:51:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-14 21:50:39 +00:00
|
|
|
// make new
|
|
|
|
stat_cache_entry* ent = new stat_cache_entry();
|
|
|
|
memset(&(ent->stbuf), 0, sizeof(struct stat));
|
|
|
|
ent->hit_count = 0;
|
|
|
|
ent->isforce = false;
|
|
|
|
ent->noobjcache = true;
|
2016-03-13 05:43:28 +00:00
|
|
|
ent->notruncate = 0L;
|
2013-09-14 21:50:39 +00:00
|
|
|
ent->meta.clear();
|
2016-02-06 09:09:17 +00:00
|
|
|
SetStatCacheTime(ent->cache_date); // Set time.
|
2013-09-14 21:50:39 +00:00
|
|
|
// add
|
2013-05-08 07:51:22 +00:00
|
|
|
pthread_mutex_lock(&StatCache::stat_cache_lock);
|
2013-09-14 21:50:39 +00:00
|
|
|
stat_cache[key] = ent;
|
2013-05-08 07:51:22 +00:00
|
|
|
pthread_mutex_unlock(&StatCache::stat_cache_lock);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-13 05:43:28 +00:00
|
|
|
void StatCache::ChangeNoTruncateFlag(std::string key, bool no_truncate)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&StatCache::stat_cache_lock);
|
|
|
|
|
|
|
|
stat_cache_t::iterator iter = stat_cache.find(key);
|
|
|
|
|
|
|
|
if(stat_cache.end() != iter){
|
|
|
|
stat_cache_entry* ent = iter->second;
|
|
|
|
if(ent){
|
|
|
|
if(no_truncate){
|
|
|
|
++(ent->notruncate);
|
|
|
|
}else{
|
|
|
|
if(0L < ent->notruncate){
|
|
|
|
--(ent->notruncate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&StatCache::stat_cache_lock);
|
|
|
|
}
|
|
|
|
|
2013-04-06 17:39:22 +00:00
|
|
|
bool StatCache::TruncateCache(void)
|
2013-03-30 13:37:14 +00:00
|
|
|
{
|
2015-08-12 15:04:16 +00:00
|
|
|
if(stat_cache.empty()){
|
2013-09-14 21:50:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-02-25 17:35:12 +00:00
|
|
|
|
2016-02-06 09:09:17 +00:00
|
|
|
pthread_mutex_lock(&StatCache::stat_cache_lock);
|
2013-09-14 21:50:39 +00:00
|
|
|
|
2016-02-06 09:09:17 +00:00
|
|
|
// 1) erase over expire time
|
|
|
|
if(IsExpireTime){
|
|
|
|
for(stat_cache_t::iterator iter = stat_cache.begin(); iter != stat_cache.end(); ){
|
|
|
|
stat_cache_entry* entry = iter->second;
|
2016-03-13 05:43:28 +00:00
|
|
|
if(!entry || (0L < entry->notruncate && IsExpireStatCacheTime(entry->cache_date, ExpireTime))){
|
2016-02-06 09:09:17 +00:00
|
|
|
stat_cache.erase(iter++);
|
|
|
|
}else{
|
|
|
|
++iter;
|
2013-09-14 21:50:39 +00:00
|
|
|
}
|
2013-04-06 17:39:22 +00:00
|
|
|
}
|
2013-09-14 21:50:39 +00:00
|
|
|
}
|
2016-02-06 09:09:17 +00:00
|
|
|
|
|
|
|
// 2) check stat cache count
|
|
|
|
if(stat_cache.size() < CacheSize){
|
|
|
|
pthread_mutex_unlock(&StatCache::stat_cache_lock);
|
|
|
|
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(); ++iter){
|
2016-03-13 05:43:28 +00:00
|
|
|
// check no truncate
|
|
|
|
stat_cache_entry* ent = iter->second;
|
|
|
|
if(ent && 0L < ent->notruncate){
|
|
|
|
// skip for no truncate entry
|
|
|
|
if(0 < erase_count){
|
|
|
|
--erase_count; // decrement
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// iter is not have notruncate flag
|
2016-02-06 09:09:17 +00:00
|
|
|
erase_iters.push_back(iter);
|
|
|
|
sort(erase_iters.begin(), erase_iters.end(), sort_statiterlist());
|
|
|
|
if(erase_count < erase_iters.size()){
|
|
|
|
erase_iters.pop_back();
|
2013-04-06 17:39:22 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-06 09:09:17 +00:00
|
|
|
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);
|
2013-04-06 17:39:22 +00:00
|
|
|
|
2013-09-14 21:50:39 +00:00
|
|
|
pthread_mutex_unlock(&StatCache::stat_cache_lock);
|
2013-04-06 17:39:22 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StatCache::DelStat(const char* key)
|
|
|
|
{
|
|
|
|
if(!key){
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-30 19:41:27 +00:00
|
|
|
S3FS_PRN_INFO3("delete stat cache entry[path=%s]", key);
|
2013-04-06 17:39:22 +00:00
|
|
|
|
|
|
|
pthread_mutex_lock(&StatCache::stat_cache_lock);
|
2013-09-14 21:50:39 +00:00
|
|
|
|
|
|
|
stat_cache_t::iterator iter;
|
|
|
|
if(stat_cache.end() != (iter = stat_cache.find(string(key)))){
|
|
|
|
if((*iter).second){
|
|
|
|
delete (*iter).second;
|
|
|
|
}
|
2011-02-25 17:35:12 +00:00
|
|
|
stat_cache.erase(iter);
|
2013-03-30 13:37:14 +00:00
|
|
|
}
|
2013-04-06 17:39:22 +00:00
|
|
|
if(0 < strlen(key) && 0 != strcmp(key, "/")){
|
|
|
|
string strpath = key;
|
|
|
|
if('/' == strpath[strpath.length() - 1]){
|
|
|
|
// If there is "path" cache, delete it.
|
|
|
|
strpath = strpath.substr(0, strpath.length() - 1);
|
|
|
|
}else{
|
|
|
|
// If there is "path/" cache, delete it.
|
|
|
|
strpath += "/";
|
|
|
|
}
|
2013-09-14 21:50:39 +00:00
|
|
|
if(stat_cache.end() != (iter = stat_cache.find(strpath.c_str()))){
|
|
|
|
if((*iter).second){
|
|
|
|
delete (*iter).second;
|
|
|
|
}
|
2013-03-30 14:03:06 +00:00
|
|
|
stat_cache.erase(iter);
|
|
|
|
}
|
|
|
|
}
|
2013-09-14 21:50:39 +00:00
|
|
|
S3FS_MALLOCTRIM(0);
|
|
|
|
|
2013-04-06 17:39:22 +00:00
|
|
|
pthread_mutex_unlock(&StatCache::stat_cache_lock);
|
|
|
|
|
|
|
|
return true;
|
2011-02-25 17:35:12 +00:00
|
|
|
}
|
|
|
|
|
2013-04-06 17:39:22 +00:00
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Functions
|
|
|
|
//-------------------------------------------------------------------
|
2013-04-29 14:31:10 +00:00
|
|
|
bool convert_header_to_stat(const char* path, headers_t& meta, struct stat* pst, bool forcedir)
|
2013-04-06 17:39:22 +00:00
|
|
|
{
|
|
|
|
if(!path || !pst){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
memset(pst, 0, sizeof(struct stat));
|
2011-02-25 17:35:12 +00:00
|
|
|
|
2013-04-06 17:39:22 +00:00
|
|
|
pst->st_nlink = 1; // see fuse FAQ
|
|
|
|
|
|
|
|
// mode
|
2013-05-09 08:35:17 +00:00
|
|
|
pst->st_mode = get_mode(meta, path, true, forcedir);
|
2013-04-06 17:39:22 +00:00
|
|
|
|
|
|
|
// blocks
|
|
|
|
if(S_ISREG(pst->st_mode)){
|
|
|
|
pst->st_blocks = get_blocks(pst->st_size);
|
|
|
|
}
|
2014-01-16 16:04:41 +00:00
|
|
|
pst->st_blksize = 4096;
|
2013-04-06 17:39:22 +00:00
|
|
|
|
|
|
|
// mtime
|
2013-05-09 08:35:17 +00:00
|
|
|
pst->st_mtime = get_mtime(meta);
|
2011-02-25 17:35:12 +00:00
|
|
|
|
2013-04-06 17:39:22 +00:00
|
|
|
// size
|
2013-05-09 08:35:17 +00:00
|
|
|
pst->st_size = get_size(meta);
|
2013-04-06 17:39:22 +00:00
|
|
|
|
|
|
|
// uid/gid
|
2013-05-09 08:35:17 +00:00
|
|
|
pst->st_uid = get_uid(meta);
|
|
|
|
pst->st_gid = get_gid(meta);
|
2011-02-25 17:35:12 +00:00
|
|
|
|
2013-04-06 17:39:22 +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:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
* vim600: noet sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: noet sw=4 ts=4
|
|
|
|
*/
|