// TODO Copyright #ifndef _S3_MGR_H_ #define _S3_MGR_H_ #include #include #include #include #include #include "uuid/uuid.h" #include "smagent/sma_interface.h" #define MAX_VOLID_SIZE 256 #define MAX_SNAPID_SIZE sizeof(uint64_t) #define UUID_SIZE (sizeof(uuid_t)) #define S3_PRINT(fmt, ...) \ do { \ fprintf(stdout, "%s():%d: " fmt, \ __func__, __LINE__, \ ##__VA_ARGS__); \ fflush(stdout); \ } while(0) #define S3_ERR_PRINT(fmt, ...) \ do { \ fprintf(stderr, "%s():%d: " fmt, \ __func__, __LINE__, \ ##__VA_ARGS__); \ fflush(stderr); \ } while(0) #ifdef DEBUG #define S3_DEBUG_PRINT(fmt, ...) \ do { \ fprintf(stdout, "%s():%d: " fmt, \ __func__, __LINE__, \ ##__VA_ARGS__); \ fflush(stdout); \ } while(0) #else /* DEBUG */ #define S3_DEBUG_PRINT(fmt, ...) #endif /* DEBUG */ class S3Mgr { private: // singleton Btrfs Mgr instance static S3Mgr *instance_; // s3 mount path static std::string s3_mount_path_; // make default constructors private S3Mgr(std::string s3_mount_path); S3Mgr(S3Mgr const&); S3Mgr& operator=(S3Mgr const&); // data subvolume path std::string base_vol_path_; // metadata subvolume path std::string mtdt_vol_path_; // snapshot dir path std::string snap_vol_path_; // VOL dir name std::string vol_dir_; // SNAP dir name std::string snap_dir_; // TAG dir name std::string tag_dir_; // opaque file name std::string opaque_fn_; // routine to create a dir, if it doesnt exist SmaStatus create_dir(const char *path); // get the mtdt_vol path for a given vol_id std::string get_mtdt_vol_path(void *vol_id); // get the snap vol path std::string get_snapvol_path(void *vol_id); // get the file size uint32_t get_file_size(std::string file_path); // write to file SmaStatus write_to_file(std::string dir_path, std::string file_name, char *buffer, uint32_t len); // populate snap_info from snap_names SmaStatus populate_snap_list(SmaSnapListInfo *snap_list, std::vector snap_names, std::vector snap_ids, std::string subvol_snap_root); public: // get the base subvolume path std::string get_base_path(); static void set_s3_mount_path(char *mount_path) { s3_mount_path_ = mount_path; } static S3Mgr *instance() { if (!instance_) { assert(s3_mount_path_.length()); instance_ = new S3Mgr(s3_mount_path_); } return instance_; } static void free_instance() { if (instance_) { delete instance_; instance_ = NULL; } } ~S3Mgr() {} // get absolute path for a given vol_id std::string get_full_path(void *vol_id); // check if the volume dir exists or not bool is_dir_present(std::string dir_path); // check if the volume is read_write or dp bool is_rw_volume(std::string vol_path); // store vol_id to uuid mapping SmaStatus store_uuid(void *vol_id, uuid_t *ep_uuid); // fetch uuid for a given vol_id SmaStatus get_uuid(void *vol_id, uuid_t *ep_uuid); // store vol_info record SmaStatus store_vol_info(void *vol_id, uint32_t type_no, SmaOpaqueVolumeInfo *vol_info); // delete vol_info record SmaStatus remove_vol_info(void *vol_id, uint32_t type_no, SmaOpaqueVolumeInfo *vol_info); // read vol_info record SmaStatus read_vol_info(void *vol_id, uint32_t type_no, SmaOpaqueVolumeInfo *vol_info); // create snapshot for given subvolume SmaStatus create_snapshot(void *vol_id, SmaSnapInfo *snap_info); // delete snapshot for given subvolume and snap id SmaStatus delete_snapshot(void *vol_id, void *snap_id); #if 0 // store snapshot create specific data SmaStatus store_snap_create_info(void *vol_id, SmaSnapInfo *snap_info); #endif // SNAP ops // store snap_info record SmaStatus store_snap_info(void *vol_id, uint32_t type_no, SmaOpaqueSnapInfo *snap_info); // delete snap_info record SmaStatus remove_snap_info(void *vol_id, uint32_t type_no, SmaOpaqueSnapInfo *snap_info); // read snap_info dir to get list of snap_ids int read_snap_info_dir(void *vol_id, uint32_t type_no, std::vector &snap_id_vec); // read each snap_info record int read_snap_info_entry(void *vol_id, uint32_t type_no, SmaOpaqueSnapInfo *snap_info); // TAGS ops // store tag_info record int store_tag_info(void *vol_id, uint32_t type_no, void *snap_id, SmaOpaqueTagInfo *tag_info); // delete tag_info record int remove_tag_info(void *vol_id, uint32_t type_no, void *snap_id, SmaOpaqueTagInfo *tag_info); // read tag_info dir to get list of tag files int read_tag_info_dir(void *vol_id, uint32_t type_no, void *snap_id, std::vector &key_fname_vec); // read each tag_info record int read_tag_info_entry(void *vol_id, uint32_t type_no, void *snap_id, char *file_name, SmaOpaqueTagInfo *snap_info); // get snapshot list SmaStatus get_snap_list(void *vol_id, SmaSnapListInfo *snap_list); // get snapshot subvolume id uint64_t get_snapvol_id(void *vol_id, std::string snapvol_name); // get the snapshot subvolume name for a given vol_id, snap_id std::string get_snapvol_name(void *vol_id, void *snap_id); }; // class S3Mgr #endif // _S3_MGR_H_