2020-08-22 12:40:53 +00:00
|
|
|
/*
|
|
|
|
* s3fs - FUSE-based file system backed by Amazon S3
|
|
|
|
*
|
|
|
|
* Copyright(C) 2007 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef S3FS_FDCACHE_ENTITY_H_
|
|
|
|
#define S3FS_FDCACHE_ENTITY_H_
|
|
|
|
|
2021-05-28 15:11:55 +00:00
|
|
|
#include "autolock.h"
|
2020-08-22 12:40:53 +00:00
|
|
|
#include "fdcache_page.h"
|
2021-05-23 16:28:50 +00:00
|
|
|
#include "fdcache_fdinfo.h"
|
2020-08-22 12:40:53 +00:00
|
|
|
#include "metaheader.h"
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
// class FdEntity
|
|
|
|
//------------------------------------------------
|
|
|
|
class FdEntity
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
static bool mixmultipart; // whether multipart uploading can use copy api.
|
|
|
|
|
|
|
|
pthread_mutex_t fdent_lock;
|
|
|
|
bool is_lock_init;
|
|
|
|
std::string path; // object path
|
2021-05-23 16:28:50 +00:00
|
|
|
int physical_fd; // physical file(cache or temporary file) descriptor
|
|
|
|
fdinfo_map_t pseudo_fd_map; // pseudo file descriptor information map
|
2020-08-22 12:40:53 +00:00
|
|
|
FILE* pfile; // file pointer(tmp file or cache file)
|
|
|
|
ino_t inode; // inode number for cache file
|
|
|
|
headers_t orgmeta; // original headers at opening
|
|
|
|
off_t size_orgmeta; // original file size in original headers
|
|
|
|
|
|
|
|
pthread_mutex_t fdent_data_lock;// protects the following members
|
|
|
|
PageList pagelist;
|
|
|
|
std::string cachepath; // local cache file path
|
|
|
|
// (if this is empty, does not load/save pagelist.)
|
|
|
|
std::string mirrorpath; // mirror file path to local cache file path
|
2021-06-29 23:20:44 +00:00
|
|
|
bool is_meta_pending;
|
2021-04-18 04:11:12 +00:00
|
|
|
struct timespec holding_mtime; // if mtime is updated while the file is open, it is set time_t value
|
2020-08-22 12:40:53 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static int FillFile(int fd, unsigned char byte, off_t size, off_t start);
|
|
|
|
static ino_t GetInode(int fd);
|
|
|
|
|
2020-09-20 22:02:06 +00:00
|
|
|
void Clear();
|
|
|
|
ino_t GetInode();
|
|
|
|
int OpenMirrorFile();
|
2021-05-23 16:55:25 +00:00
|
|
|
int NoCacheLoadAndPost(PseudoFdInfo* pseudo_obj, off_t start = 0, off_t size = 0); // size=0 means loading to end
|
|
|
|
PseudoFdInfo* CheckPseudoFdFlags(int fd, bool writable, bool lock_already_held = false);
|
|
|
|
bool IsUploading(bool lock_already_held = false);
|
2020-08-22 12:40:53 +00:00
|
|
|
bool SetAllStatus(bool is_loaded); // [NOTE] not locking
|
2020-09-20 22:02:06 +00:00
|
|
|
bool SetAllStatusUnloaded() { return SetAllStatus(false); }
|
2021-05-23 16:55:25 +00:00
|
|
|
int NoCachePreMultipartPost(PseudoFdInfo* pseudo_obj);
|
|
|
|
int NoCacheMultipartPost(PseudoFdInfo* pseudo_obj, int tgfd, off_t start, off_t size);
|
|
|
|
int NoCacheCompleteMultipartPost(PseudoFdInfo* pseudo_obj);
|
2021-07-04 02:28:46 +00:00
|
|
|
int RowFlushNoMultipart(PseudoFdInfo* pseudo_obj, const char* tpath);
|
|
|
|
int RowFlushMultipart(PseudoFdInfo* pseudo_obj, const char* tpath);
|
|
|
|
int RowFlushMixMultipart(PseudoFdInfo* pseudo_obj, const char* tpath);
|
|
|
|
ssize_t WriteNoMultipart(PseudoFdInfo* pseudo_obj, const char* bytes, off_t start, size_t size);
|
|
|
|
ssize_t WriteMultipart(PseudoFdInfo* pseudo_obj, const char* bytes, off_t start, size_t size);
|
|
|
|
ssize_t WriteMixMultipart(PseudoFdInfo* pseudo_obj, const char* bytes, off_t start, size_t size);
|
2020-09-20 22:02:06 +00:00
|
|
|
int UploadPendingMeta();
|
2020-08-22 12:40:53 +00:00
|
|
|
|
|
|
|
public:
|
2020-10-13 13:30:42 +00:00
|
|
|
static bool GetNoMixMultipart() { return mixmultipart; }
|
2020-09-20 22:02:06 +00:00
|
|
|
static bool SetNoMixMultipart();
|
2020-08-22 12:40:53 +00:00
|
|
|
|
|
|
|
explicit FdEntity(const char* tpath = NULL, const char* cpath = NULL);
|
|
|
|
~FdEntity();
|
|
|
|
|
2021-05-23 16:28:50 +00:00
|
|
|
void Close(int fd);
|
|
|
|
bool IsOpen() const { return (-1 != physical_fd); }
|
|
|
|
bool FindPseudoFd(int fd, bool lock_already_held = false);
|
2021-10-07 13:19:36 +00:00
|
|
|
int Open(const headers_t* pmeta, off_t size, time_t time, int flags, AutoLock::Type type);
|
2021-05-23 16:28:50 +00:00
|
|
|
bool LoadAll(int fd, headers_t* pmeta = NULL, off_t* size = NULL, bool force_load = false);
|
|
|
|
int Dup(int fd, bool lock_already_held = false);
|
|
|
|
int OpenPseudoFd(int flags = O_RDONLY, bool lock_already_held = false);
|
|
|
|
int GetOpenCount(bool lock_already_held = false);
|
2020-09-20 22:02:06 +00:00
|
|
|
const char* GetPath() const { return path.c_str(); }
|
2020-08-22 12:40:53 +00:00
|
|
|
bool RenamePath(const std::string& newpath, std::string& fentmapkey);
|
2021-05-23 16:28:50 +00:00
|
|
|
int GetPhysicalFd() const { return physical_fd; }
|
2020-09-20 22:02:06 +00:00
|
|
|
bool IsModified() const;
|
2020-08-22 12:40:53 +00:00
|
|
|
bool MergeOrgMeta(headers_t& updatemeta);
|
|
|
|
|
|
|
|
bool GetStats(struct stat& st, bool lock_already_held = false);
|
2021-04-18 04:11:12 +00:00
|
|
|
int SetCtime(struct timespec time, bool lock_already_held = false);
|
|
|
|
int SetAtime(struct timespec time, bool lock_already_held = false);
|
|
|
|
int SetMCtime(struct timespec mtime, struct timespec ctime, bool lock_already_held = false);
|
2020-09-20 22:02:06 +00:00
|
|
|
bool UpdateCtime();
|
2020-10-03 02:14:23 +00:00
|
|
|
bool UpdateAtime();
|
|
|
|
bool UpdateMtime(bool clear_holding_mtime = false);
|
|
|
|
bool UpdateMCtime();
|
2021-04-18 04:11:12 +00:00
|
|
|
bool SetHoldingMtime(struct timespec mtime, bool lock_already_held = false);
|
2020-10-03 02:14:23 +00:00
|
|
|
bool ClearHoldingMtime(bool lock_already_held = false);
|
2020-08-22 12:40:53 +00:00
|
|
|
bool GetSize(off_t& size);
|
|
|
|
bool GetXattr(std::string& xattr);
|
|
|
|
bool SetXattr(const std::string& xattr);
|
|
|
|
bool SetMode(mode_t mode);
|
|
|
|
bool SetUId(uid_t uid);
|
|
|
|
bool SetGId(gid_t gid);
|
|
|
|
bool SetContentType(const char* path);
|
|
|
|
|
2021-06-27 06:15:48 +00:00
|
|
|
int Load(off_t start, off_t size, AutoLock::Type type, bool is_modified_flag = false); // size=0 means loading to end
|
2020-08-22 12:40:53 +00:00
|
|
|
|
2021-05-28 15:11:55 +00:00
|
|
|
off_t BytesModified();
|
2021-05-23 16:28:50 +00:00
|
|
|
int RowFlush(int fd, const char* tpath, bool force_sync = false);
|
|
|
|
int Flush(int fd, bool force_sync = false) { return RowFlush(fd, NULL, force_sync); }
|
2020-08-22 12:40:53 +00:00
|
|
|
|
2021-05-23 16:28:50 +00:00
|
|
|
ssize_t Read(int fd, char* bytes, off_t start, size_t size, bool force_load = false);
|
|
|
|
ssize_t Write(int fd, const char* bytes, off_t start, size_t size);
|
2020-08-22 12:40:53 +00:00
|
|
|
|
|
|
|
bool ReserveDiskSpace(off_t size);
|
2020-11-03 06:42:03 +00:00
|
|
|
bool PunchHole(off_t start = 0, size_t size = 0);
|
2021-04-30 10:56:33 +00:00
|
|
|
|
2021-10-16 15:51:36 +00:00
|
|
|
void MarkDirtyNewFile();
|
2020-08-22 12:40:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::map<std::string, class FdEntity*> fdent_map_t; // key=path, value=FdEntity*
|
|
|
|
|
|
|
|
#endif // S3FS_FDCACHE_ENTITY_H_
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
* vim600: expandtab sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: expandtab sw=4 ts=4
|
|
|
|
*/
|