2021-05-23 16:28:50 +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_FDINFO_H_
|
|
|
|
#define S3FS_FDCACHE_FDINFO_H_
|
|
|
|
|
2023-07-27 00:12:28 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2021-11-02 12:16:48 +00:00
|
|
|
#include "psemaphore.h"
|
|
|
|
#include "metaheader.h"
|
2022-01-14 15:02:49 +00:00
|
|
|
#include "autolock.h"
|
2022-07-30 03:06:47 +00:00
|
|
|
#include "types.h"
|
2021-11-02 12:16:48 +00:00
|
|
|
|
2022-07-18 16:03:38 +00:00
|
|
|
class FdEntity;
|
2022-07-30 03:06:47 +00:00
|
|
|
class UntreatedParts;
|
2022-07-18 16:03:38 +00:00
|
|
|
|
2021-11-02 12:16:48 +00:00
|
|
|
//------------------------------------------------
|
|
|
|
// Structure of parameters to pass to thread
|
|
|
|
//------------------------------------------------
|
|
|
|
class PseudoFdInfo;
|
|
|
|
|
|
|
|
struct pseudofdinfo_thparam
|
|
|
|
{
|
|
|
|
PseudoFdInfo* ppseudofdinfo;
|
|
|
|
std::string path;
|
|
|
|
std::string upload_id;
|
|
|
|
int upload_fd;
|
|
|
|
off_t start;
|
|
|
|
off_t size;
|
|
|
|
bool is_copy;
|
|
|
|
int part_num;
|
|
|
|
etagpair* petag;
|
|
|
|
|
2023-07-27 12:56:58 +00:00
|
|
|
pseudofdinfo_thparam() : ppseudofdinfo(nullptr), path(""), upload_id(""), upload_fd(-1), start(0), size(0), is_copy(false), part_num(-1), petag(nullptr) {}
|
2021-11-02 12:16:48 +00:00
|
|
|
};
|
2021-07-11 12:38:36 +00:00
|
|
|
|
2021-05-23 16:28:50 +00:00
|
|
|
//------------------------------------------------
|
|
|
|
// Class PseudoFdInfo
|
|
|
|
//------------------------------------------------
|
|
|
|
class PseudoFdInfo
|
|
|
|
{
|
|
|
|
private:
|
2021-11-02 12:16:48 +00:00
|
|
|
static int max_threads;
|
|
|
|
static int opt_max_threads; // for option value
|
2021-07-11 12:38:36 +00:00
|
|
|
|
2021-11-02 12:16:48 +00:00
|
|
|
int pseudo_fd;
|
|
|
|
int physical_fd;
|
|
|
|
int flags; // flags at open
|
|
|
|
std::string upload_id;
|
|
|
|
int upload_fd; // duplicated fd for uploading
|
|
|
|
filepart_list_t upload_list;
|
2022-07-18 16:03:38 +00:00
|
|
|
petagpool etag_entities; // list of etag string and part number entities(to maintain the etag entity even if MPPART_INFO is destroyed)
|
2021-11-02 12:16:48 +00:00
|
|
|
bool is_lock_init;
|
2023-01-04 11:23:39 +00:00
|
|
|
mutable pthread_mutex_t upload_list_lock; // protects upload_id and upload_list
|
2021-11-02 12:16:48 +00:00
|
|
|
Semaphore uploaded_sem; // use a semaphore to trigger an upload completion like event flag
|
2023-09-25 15:15:05 +00:00
|
|
|
int instruct_count; // number of instructions for processing by threads
|
|
|
|
int completed_count; // number of completed processes by thread
|
2021-11-02 12:16:48 +00:00
|
|
|
int last_result; // the result of thread processing
|
2021-05-23 16:28:50 +00:00
|
|
|
|
|
|
|
private:
|
2021-11-02 12:16:48 +00:00
|
|
|
static void* MultipartUploadThreadWorker(void* arg);
|
|
|
|
|
2021-05-23 16:28:50 +00:00
|
|
|
bool Clear();
|
2022-08-07 10:22:35 +00:00
|
|
|
void CloseUploadFd();
|
2022-01-14 15:02:49 +00:00
|
|
|
bool OpenUploadFd(AutoLock::Type type = AutoLock::NONE);
|
2022-08-07 10:22:35 +00:00
|
|
|
bool ResetUploadInfo(AutoLock::Type type);
|
|
|
|
bool RowInitialUploadInfo(const std::string& id, bool is_cancel_mp, AutoLock::Type type);
|
2022-07-29 17:27:49 +00:00
|
|
|
bool CompleteInstruction(int result, AutoLock::Type type = AutoLock::NONE);
|
|
|
|
bool ParallelMultipartUpload(const char* path, const mp_part_list_t& mplist, bool is_copy, AutoLock::Type type = AutoLock::NONE);
|
2022-01-14 15:02:49 +00:00
|
|
|
bool InsertUploadPart(off_t start, off_t size, int part_num, bool is_copy, etagpair** ppetag, AutoLock::Type type = AutoLock::NONE);
|
2022-08-07 10:22:35 +00:00
|
|
|
bool CancelAllThreads();
|
2024-01-24 15:46:45 +00:00
|
|
|
bool ExtractUploadPartsFromUntreatedArea(const off_t& untreated_start, const off_t& untreated_size, mp_part_list_t& to_upload_list, filepart_list_t& cancel_upload_list, off_t max_mp_size);
|
2021-05-23 16:28:50 +00:00
|
|
|
|
|
|
|
public:
|
2022-09-24 06:45:13 +00:00
|
|
|
explicit PseudoFdInfo(int fd = -1, int open_flags = 0);
|
2021-05-23 16:28:50 +00:00
|
|
|
~PseudoFdInfo();
|
2023-09-06 14:52:10 +00:00
|
|
|
PseudoFdInfo(const PseudoFdInfo&) = delete;
|
|
|
|
PseudoFdInfo(PseudoFdInfo&&) = delete;
|
|
|
|
PseudoFdInfo& operator=(const PseudoFdInfo&) = delete;
|
|
|
|
PseudoFdInfo& operator=(PseudoFdInfo&&) = delete;
|
2021-05-23 16:28:50 +00:00
|
|
|
|
|
|
|
int GetPhysicalFd() const { return physical_fd; }
|
|
|
|
int GetPseudoFd() const { return pseudo_fd; }
|
|
|
|
int GetFlags() const { return flags; }
|
|
|
|
bool Writable() const;
|
|
|
|
bool Readable() const;
|
|
|
|
|
|
|
|
bool Set(int fd, int open_flags);
|
2022-08-07 10:22:35 +00:00
|
|
|
bool ClearUploadInfo(bool is_cancel_mp = false);
|
|
|
|
bool InitialUploadInfo(const std::string& id){ return RowInitialUploadInfo(id, true, AutoLock::NONE); }
|
2021-05-23 16:55:25 +00:00
|
|
|
|
|
|
|
bool IsUploading() const { return !upload_id.empty(); }
|
|
|
|
bool GetUploadId(std::string& id) const;
|
2023-01-04 11:23:39 +00:00
|
|
|
bool GetEtaglist(etaglist_t& list) const;
|
2021-05-23 16:55:25 +00:00
|
|
|
|
2023-07-27 12:56:58 +00:00
|
|
|
bool AppendUploadPart(off_t start, off_t size, bool is_copy = false, etagpair** ppetag = nullptr);
|
2021-05-23 16:55:25 +00:00
|
|
|
|
2023-10-07 04:26:44 +00:00
|
|
|
bool ParallelMultipartUploadAll(const char* path, const mp_part_list_t& to_upload_list, const mp_part_list_t& copy_list, int& result);
|
2022-07-18 16:03:38 +00:00
|
|
|
|
2023-10-15 04:01:14 +00:00
|
|
|
int WaitAllThreadsExit();
|
2022-07-18 16:03:38 +00:00
|
|
|
ssize_t UploadBoundaryLastUntreatedArea(const char* path, headers_t& meta, FdEntity* pfdent);
|
2023-10-15 04:01:14 +00:00
|
|
|
bool ExtractUploadPartsFromAllArea(UntreatedParts& untreated_list, mp_part_list_t& to_upload_list, mp_part_list_t& to_copy_list, mp_part_list_t& to_download_list, filepart_list_t& cancel_upload_list, bool& wait_upload_complete, off_t max_mp_size, off_t file_size, bool use_copy);
|
2021-05-23 16:28:50 +00:00
|
|
|
};
|
|
|
|
|
2023-07-27 00:12:28 +00:00
|
|
|
typedef std::map<int, std::unique_ptr<PseudoFdInfo>> fdinfo_map_t;
|
2021-05-23 16:28:50 +00:00
|
|
|
|
|
|
|
#endif // S3FS_FDCACHE_FDINFO_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
|
|
|
|
*/
|