diff --git a/src/cmd/wrcmd.c b/src/cmd/wrcmd.c index 0a74b04db170ad1efb314a91d0bd7000cb5c68b5..cecbe36aa4cb07c865d4a18d51998e544ddabd22 100644 --- a/src/cmd/wrcmd.c +++ b/src/cmd/wrcmd.c @@ -1448,43 +1448,6 @@ status_t wr_load_wr_ctrl_group_from_file( return CM_SUCCESS; } -status_t wr_load_vg_item_and_pool_from_file(const char *file_name, const char *vg_name, wr_vg_info_item_t *vg_item) -{ - int32 file_fd = wr_open_memory_file(file_name); - if (file_fd == -1) { - LOG_DEBUG_ERR("Failed to open memory file %s", file_name); - return CM_ERROR; - } - int64 size = cm_file_size(file_fd); - if (size == -1) { - cm_close_file(file_fd); - LOG_DEBUG_ERR("Failed to read file size %s", file_name); - return CM_ERROR; - } - int64 length = -1; - status_t status; - bool32 result = (bool32)(cm_seek_file(file_fd, 0, SEEK_SET) != -1); - WR_RETURN_IF_FALSE2(result, LOG_DEBUG_ERR("Failed to seek file %s", file_name)); - do { - status = wr_load_wr_ctrl_group_from_file(file_fd, &length, vg_name, vg_item); - if (status != CM_SUCCESS) { - if (length == -1) { - break; - } - result = (bool32)(cm_seek_file(file_fd, length, SEEK_SET) != -1); - WR_RETURN_IF_FALSE2(result, LOG_DEBUG_ERR("Failed to seek file %s", file_name)); - } - - status = wr_load_buffer_cache_group_from_file(file_fd, &length, vg_name, vg_item); - WR_BREAK_IF_ERROR(status); - } while (CM_FALSE); - cm_close_file(file_fd); - if (status != CM_SUCCESS) { - LOG_DEBUG_ERR("Failed to load vg item %s", vg_name); - } - return status; -} - static wr_args_t cmd_rename_args[] = { {'o', "old_name", CM_TRUE, CM_TRUE, wr_cmd_check_device_path, cmd_check_convert_path, cmd_clean_check_convert, 0, NULL, NULL, 0}, diff --git a/src/common/persist/wr_alloc_unit.c b/src/common/persist/wr_alloc_unit.c index 881433566c3e8c235fda427a74d654bf0cb8ae84..174052d8fb72b2edded6f8c5cbd480859415837a 100644 --- a/src/common/persist/wr_alloc_unit.c +++ b/src/common/persist/wr_alloc_unit.c @@ -53,32 +53,11 @@ bool32 wr_can_alloc_from_recycle(const gft_node_t *root_node, bool32 is_before) return CM_FALSE; } -status_t wr_alloc_au_core(wr_session_t *session, wr_ctrl_t *wr_ctrl, wr_vg_info_item_t *vg_item, auid_t *auid) -{ - return CM_SUCCESS; -} - -bool32 wr_alloc_au_batch(wr_session_t *session, wr_vg_info_item_t *vg_item, auid_t *auid, uint32 count) -{ - return CM_TRUE; -} - status_t wr_alloc_au(wr_session_t *session, wr_vg_info_item_t *vg_item, auid_t *auid) { return CM_SUCCESS; } -status_t wr_get_core_version(wr_vg_info_item_t *item, uint64 *version) -{ - return CM_SUCCESS; -} - -// shoud lock in caller -status_t wr_load_core_ctrl(wr_vg_info_item_t *item, wr_core_ctrl_t *core) -{ - return CM_SUCCESS; -} - void wr_update_core_ctrl( wr_session_t *session, wr_vg_info_item_t *item, wr_core_ctrl_t *core, uint32 volume_id, bool32 is_only_root) { diff --git a/src/common/persist/wr_alloc_unit.h b/src/common/persist/wr_alloc_unit.h index 73d32fe92871aabae5fff767d31400e0de1ee1b4..264d148c9ba19ca0f39af22382c1a58e9645715f 100644 --- a/src/common/persist/wr_alloc_unit.h +++ b/src/common/persist/wr_alloc_unit.h @@ -73,10 +73,7 @@ typedef struct st_wr_au_root_t { bool32 wr_can_alloc_from_recycle(const gft_node_t *root_node, bool32 is_before); void wr_init_au_root(wr_ctrl_t *wr_ctrl); status_t wr_alloc_au(wr_session_t *session, wr_vg_info_item_t *vg_item, auid_t *auid); -bool32 wr_alloc_au_batch(wr_session_t *session, wr_vg_info_item_t *vg_item, auid_t *auid, uint32 count); -status_t wr_get_core_version(wr_vg_info_item_t *item, uint64 *version); -status_t wr_load_core_ctrl(wr_vg_info_item_t *item, wr_core_ctrl_t *core); void wr_update_core_ctrl( wr_session_t *session, wr_vg_info_item_t *item, wr_core_ctrl_t *core, uint32 volume_id, bool32 is_only_root); status_t wr_get_au_head(wr_vg_info_item_t *item, auid_t auid, wr_au_head_t *au_head); diff --git a/src/common/persist/wr_defs_print.c b/src/common/persist/wr_defs_print.c index cc7c9ffd3b64446f7f099bebdc80b5d2077a2a2c..1f4a9c10eacd88b777eced2597b433a0cf309088 100644 --- a/src/common/persist/wr_defs_print.c +++ b/src/common/persist/wr_defs_print.c @@ -40,17 +40,7 @@ void printf_auid(const auid_t *first) void printf_wr_fs_block_list(wr_fs_block_list_t *free) { - (void)printf(" count = %llu\n", free->count); - - auid_t *first = &free->first; - (void)printf(" first = {\n"); - printf_auid(first); - (void)printf(" }\n"); - - auid_t *last = &free->last; - (void)printf(" last = {\n"); - printf_auid(last); - (void)printf(" }\n"); + return; } void printf_wr_fs_aux_root(wr_fs_aux_root_t *root) @@ -65,12 +55,7 @@ void printf_wr_fs_aux_root(wr_fs_aux_root_t *root) void printf_wr_fs_block_root(wr_fs_block_root_t *root) { - (void)printf(" version = %llu\n", root->version); - - wr_fs_block_list_t *free = &root->free; - (void)printf(" free = {\n"); - printf_wr_fs_block_list(free); - (void)printf(" }\n"); + return; } void printf_wr_volume_attr(const wr_volume_attr_t *volume_attrs) @@ -108,35 +93,7 @@ void printf_wr_au_root(wr_au_root_t *au_root) void wr_printf_core_ctrl_base(wr_core_ctrl_t *core_ctrl) { - (void)printf("core_ctrl = {\n"); - (void)printf(" checksum = %u\n", core_ctrl->checksum); - (void)printf(" reserve = %u\n", core_ctrl->reserve); - (void)printf(" version = %llu\n", core_ctrl->version); - (void)printf(" au_size = %u\n", core_ctrl->au_size); - (void)printf(" volume_count = %u\n", core_ctrl->volume_count); - (void)printf(" fs_block_root = {\n"); - - wr_fs_block_root_t *root = (wr_fs_block_root_t *)(core_ctrl->fs_block_root); - printf_wr_fs_block_root(root); - (void)printf(" }\n"); - (void)printf(" au_root = {\n"); - - wr_au_root_t *au_root = (wr_au_root_t *)(core_ctrl->au_root); - printf_wr_au_root(au_root); - (void)printf(" }\n"); - - wr_volume_attr_t *volume_attrs = core_ctrl->volume_attrs; - for (uint32 i = 0; i < WR_MAX_VOLUMES; ++i) { - if (i == 0 || volume_attrs->id != 0) { - (void)printf(" volume_attrs[%u] = {\n", i); - printf_wr_volume_attr(volume_attrs); - (void)printf(" }\n"); - } - volume_attrs++; - continue; - } - - (void)printf("}\n"); + return; } void printf_gft_list(gft_list_t *items) diff --git a/src/common/persist/wr_diskgroup.c b/src/common/persist/wr_diskgroup.c index 5477e21655f0d5df167a55953f724e7ed4adda7b..e8e4c86af744dbcf9345c457406866f9c2c4c736 100644 --- a/src/common/persist/wr_diskgroup.c +++ b/src/common/persist/wr_diskgroup.c @@ -133,41 +133,12 @@ void regist_get_instance_status_proc(wr_get_instance_status_proc_t proc) { get_instance_status_proc = proc; } -void wr_checksum_vg_ctrl(wr_vg_info_item_t *vg_item); void vg_destroy_env(wr_vg_info_item_t *vg_item) { cm_oamap_destroy(&vg_item->au_map); } -status_t wr_read_vg_config_file(const char *file_name, char *buf, uint32 *buf_len, bool32 read_only) -{ - int32 file_fd; - status_t status; - uint32 mode = (read_only) ? (O_RDONLY | O_BINARY) : (O_CREAT | O_RDWR | O_BINARY); - - if (!cm_file_exist(file_name)) { - WR_THROW_ERROR(ERR_WR_FILE_NOT_EXIST, file_name, "config"); - return CM_ERROR; - } - - WR_RETURN_IF_ERROR(cm_open_file(file_name, mode, &file_fd)); - - int64 size = cm_file_size(file_fd); - bool32 result = (bool32)(size != -1); - WR_RETURN_IF_FALSE3(result, cm_close_file(file_fd), WR_THROW_ERROR(ERR_SEEK_FILE, 0, SEEK_END, errno)); - - result = (bool32)(size <= (int64)(*buf_len)); - WR_RETURN_IF_FALSE3(result, cm_close_file(file_fd), WR_THROW_ERROR(ERR_WR_CONFIG_FILE_OVERSIZED, file_name)); - - result = (bool32)(cm_seek_file(file_fd, 0, SEEK_SET) == 0); - WR_RETURN_IF_FALSE3(result, cm_close_file(file_fd), WR_THROW_ERROR(ERR_SEEK_FILE, 0, SEEK_SET, errno)); - - status = cm_read_file(file_fd, buf, (int32)size, (int32 *)buf_len); - cm_close_file(file_fd); - return status; -} - void wr_free_vg_info() { LOG_RUN_INF("free g_vgs_info."); @@ -245,88 +216,8 @@ status_t wr_check_dup_vg(wr_vg_info_t *config, uint32 vg_no, bool32 *result) return CM_SUCCESS; } -// NOTE:called after load vg ctrl and recovery. -void wr_checksum_vg_ctrl(wr_vg_info_item_t *vg_item) -{ - LOG_RUN_INF("Begin to checksum vg:%s ctrl.", vg_item->vg_name); - char *buf = vg_item->wr_ctrl->vg_data; - uint32 checksum = wr_get_checksum(buf, WR_VG_DATA_SIZE); - uint32 old_checksum = vg_item->wr_ctrl->vg_info.checksum; - wr_check_checksum(checksum, old_checksum); - - buf = vg_item->wr_ctrl->root; - checksum = wr_get_checksum(buf, WR_BLOCK_SIZE); - wr_common_block_t *block = (wr_common_block_t *)buf; - old_checksum = block->checksum; - wr_check_checksum(checksum, old_checksum); - LOG_RUN_INF("Succeed to checksum vg:%s ctrl.", vg_item->vg_name); -} - -// NOTE:only called initializing.no check redo and recovery. -status_t wr_load_vg_ctrl(wr_vg_info_item_t *vg_item, bool32 is_lock) -{ - CM_ASSERT(vg_item != NULL); - bool32 remote = CM_FALSE; - wr_config_t *inst_cfg = wr_get_inst_cfg(); - - if (vg_item->vg_name[0] == '\0' || vg_item->entry_path[0] == '\0') { - LOG_RUN_ERR("Failed to load vg ctrl, input parameter is invalid."); - return CM_ERROR; - } - LOG_RUN_INF("Begin to load vg %s ctrl.", vg_item->vg_name); - status_t status; - if (is_lock) { - if (wr_lock_vg_storage_r(vg_item, vg_item->entry_path, inst_cfg) != CM_SUCCESS) { - LOG_RUN_ERR("Failed to lock vg:%s.", vg_item->entry_path); - return CM_ERROR; - } - } - status = wr_load_vg_ctrl_part(vg_item, 0, vg_item->wr_ctrl, (int32)sizeof(wr_ctrl_t), &remote); - if (status != CM_SUCCESS) { - if (is_lock) { - (void)wr_unlock_vg_storage(vg_item, vg_item->entry_path, inst_cfg); - } - LOG_RUN_ERR("Failed to read volume %s.", vg_item->entry_path); - return status; - } - if (is_lock) { - if (wr_unlock_vg_storage(vg_item, vg_item->entry_path, inst_cfg) != CM_SUCCESS) { - return CM_ERROR; - } - } - if (!WR_VG_IS_VALID(vg_item->wr_ctrl)) { - WR_THROW_ERROR(ERR_WR_VG_CHECK_NOT_INIT); - LOG_RUN_ERR("Invalid vg %s ctrl", vg_item->vg_name); - return CM_ERROR; - } - - date_t date = cm_timeval2date(vg_item->wr_ctrl->vg_info.create_time); - time_t time = cm_date2time(date); - char create_time[512]; - status = cm_time2str(time, "YYYY-MM-DD HH24:mi:ss", create_time, sizeof(create_time)); - LOG_RUN_INF("The vg:%s info, create time:%s.", vg_item->vg_name, create_time); - - return status; -} - status_t wr_load_vg_ctrl_part(wr_vg_info_item_t *vg_item, int64 offset, void *buf, int32 size, bool32 *remote) { - CM_ASSERT(vg_item != NULL); - CM_ASSERT(buf != NULL); - // todo close volume? - if (vg_item->volume_handle[0].handle == WR_INVALID_HANDLE) { - if (wr_open_volume(vg_item->entry_path, NULL, WR_INSTANCE_OPEN_FLAG, &vg_item->volume_handle[0]) != - CM_SUCCESS) { - LOG_RUN_ERR("Failed to open volume %s.", vg_item->entry_path); - return CM_ERROR; - } - } - LOG_DEBUG_INF( - "Begin to read volume %s when load vg ctrl part, offset:%lld,size:%d.", vg_item->entry_path, offset, size); - if (wr_read_volume_inst(vg_item, &vg_item->volume_handle[0], offset, buf, size, remote) != CM_SUCCESS) { - LOG_RUN_ERR("Failed to read volume %s,offset:%lld,size:%d.", vg_item->entry_path, offset, size); - return CM_ERROR; - } return CM_SUCCESS; } @@ -336,28 +227,11 @@ void wr_lock_vg_mem_x(wr_vg_info_item_t *vg_item) wr_latch_x(&vg_item->disk_latch); } -void wr_lock_vg_mem_x2ix(wr_vg_info_item_t *vg_item) -{ - latch_statis_t *stat = NULL; - wr_latch_x2ix(&vg_item->disk_latch, WR_DEFAULT_SESSIONID, stat); -} - -void wr_lock_vg_mem_ix2x(wr_vg_info_item_t *vg_item) -{ - latch_statis_t *stat = NULL; - wr_latch_ix2x(&vg_item->disk_latch, WR_DEFAULT_SESSIONID, stat); -} - void wr_lock_vg_mem_s(wr_vg_info_item_t *vg_item) { wr_latch_s(&vg_item->disk_latch); } -void wr_lock_vg_mem_degrade(wr_vg_info_item_t *vg_item) -{ - wr_latch_degrade(&vg_item->disk_latch, WR_DEFAULT_SESSIONID, NULL); -} - void wr_lock_vg_mem_s_force(wr_vg_info_item_t *vg_item) { wr_latch_s2(&vg_item->disk_latch, WR_DEFAULT_SESSIONID, CM_TRUE, NULL); @@ -858,21 +732,7 @@ status_t wr_write_ctrl_to_disk(wr_vg_info_item_t *vg_item, int64 offset, void *b status_t wr_update_core_ctrl_disk(wr_vg_info_item_t *vg_item) { - status_t status; - vg_item->wr_ctrl->core.version++; - vg_item->wr_ctrl->core.checksum = wr_get_checksum(&vg_item->wr_ctrl->core, WR_CORE_CTRL_SIZE); - LOG_DEBUG_INF( - "[REDO]Try to update vg core:%s, version:%llu to disk.", vg_item->vg_name, vg_item->wr_ctrl->core.version); - int64 offset = (int64)WR_CTRL_CORE_OFFSET; - status = wr_write_ctrl_to_disk(vg_item, offset, &vg_item->wr_ctrl->core, WR_CORE_CTRL_SIZE); - if (status == CM_SUCCESS) { - // write to backup area - status = wr_write_ctrl_to_disk( - vg_item, (int64)WR_CTRL_BAK_CORE_OFFSET, &vg_item->wr_ctrl->core, WR_CORE_CTRL_SIZE); - LOG_DEBUG_INF( - "[REDO]End to update vg core:%s, version:%llu to disk.", vg_item->vg_name, vg_item->wr_ctrl->core.version); - } - return status; + return CM_SUCCESS; } status_t wr_update_volume_ctrl(wr_vg_info_item_t *vg_item) @@ -1002,89 +862,9 @@ status_t wr_cmp_volume_head(wr_vg_info_item_t *vg_item, const char *volume_name, status_t wr_add_volume_vg_ctrl( wr_ctrl_t *vg_ctrl, uint32 id, uint64 vol_size, const char *volume_name, volume_slot_e volume_flag) { - errno_t errcode = strcpy_s(vg_ctrl->volume.defs[id].name, WR_MAX_VOLUME_PATH_LEN, volume_name); - WR_SECUREC_SS_RETURN_IF_ERROR(errcode, CM_ERROR); - vg_ctrl->volume.defs[id].flag = volume_flag; - vg_ctrl->volume.defs[id].id = id; - vg_ctrl->core.volume_attrs[id].id = id; - vg_ctrl->core.volume_attrs[id].hwm = CM_CALC_ALIGN(WR_VOLUME_HEAD_SIZE, wr_get_vg_au_size(vg_ctrl)); - vg_ctrl->core.volume_attrs[id].size = vol_size; - if (vol_size <= vg_ctrl->core.volume_attrs[id].hwm) { - WR_THROW_ERROR(ERR_WR_VOLUME_ADD, volume_name, "volume size is too small"); - return CM_ERROR; - } - vg_ctrl->core.volume_attrs[id].free = vol_size - vg_ctrl->core.volume_attrs[id].hwm; - LOG_RUN_INF("Add volume refresh core, old core version:%llu, volume version:%llu, volume def version:%llu.", - vg_ctrl->core.version, vg_ctrl->volume.version, vg_ctrl->volume.defs[id].version); - vg_ctrl->volume.defs[id].version++; - vg_ctrl->core.volume_count++; - vg_ctrl->core.version++; - vg_ctrl->volume.version++; - return CM_SUCCESS; -} - -static status_t wr_add_volume_impl_generate_redo( - wr_session_t *session, wr_vg_info_item_t *vg_item, const char *volume_name, uint32 id) -{ - wr_redo_volhead_t redo; - wr_volume_header_t *vol_head = (wr_volume_header_t *)redo.head; - - CM_RETURN_IFERR(wr_cmp_volume_head(vg_item, volume_name, id)); - CM_RETURN_IFERR(wr_gen_volume_head(vol_head, vg_item, volume_name, id)); - - int32 ret = snprintf_s(redo.name, WR_MAX_NAME_LEN, strlen(volume_name), "%s", volume_name); - bool32 result = (bool32)(ret != -1); - WR_RETURN_IF_FALSE2(result, WR_THROW_ERROR(ERR_SYSTEM_CALL, ret)); - wr_put_log(session, vg_item, WR_RT_UPDATE_VOLHEAD, &redo, sizeof(redo)); - return CM_SUCCESS; -} - -static status_t wr_add_volume_record_log(wr_session_t *session, wr_vg_info_item_t *vg_item, uint32 id) -{ - wr_ctrl_t *vg_ctrl = vg_item->wr_ctrl; - wr_redo_volop_t volop_redo; - volop_redo.volume_count = vg_ctrl->core.volume_count; - volop_redo.core_version = vg_ctrl->core.version; - volop_redo.volume_version = vg_ctrl->volume.version; - volop_redo.is_add = WR_TRUE; - - LOG_RUN_INF("Refresh core, old version:%llu, disk version:%llu.", vg_ctrl->core.version - 1, vg_ctrl->core.version); - - errno_t errcode = - memcpy_sp(volop_redo.attr, WR_DISK_UNIT_SIZE, &vg_ctrl->core.volume_attrs[id], sizeof(wr_volume_attr_t)); - WR_SECUREC_RETURN_IF_ERROR(errcode, CM_ERROR); - errcode = memcpy_sp(volop_redo.def, WR_DISK_UNIT_SIZE, &vg_ctrl->volume.defs[id], sizeof(wr_volume_def_t)); - WR_SECUREC_RETURN_IF_ERROR(errcode, CM_ERROR); - wr_put_log(session, vg_item, WR_RT_ADD_OR_REMOVE_VOLUME, &volop_redo, sizeof(volop_redo)); return CM_SUCCESS; } -static status_t wr_add_volume_impl( - wr_session_t *session, wr_vg_info_item_t *vg_item, const char *volume_name, volume_slot_e volume_flag) -{ - uint32 id = wr_find_free_volume_id(vg_item); - bool32 result = (bool32)(id < WR_MAX_VOLUMES); - WR_RETURN_IF_FALSE2( - result, LOG_DEBUG_ERR("[VOL][ADV] Failed to add volume, exceed max volumes %d.", WR_MAX_VOLUMES)); - - CM_RETURN_IFERR(wr_open_volume(volume_name, NULL, WR_INSTANCE_OPEN_FLAG, &vg_item->volume_handle[id])); - status_t status = wr_add_volume_impl_generate_redo(session, vg_item, volume_name, id); - uint64 vol_size = wr_get_volume_size(&vg_item->volume_handle[id]); - wr_close_volume(&vg_item->volume_handle[id]); - if (status != CM_SUCCESS) { - return status; - } - - result = (bool32)(vol_size != WR_INVALID_64); - WR_RETURN_IF_FALSE2( - result, LOG_DEBUG_ERR("[VOL][ADV] Failed to get volume size when add volume:%s.", volume_name)); - status = wr_add_volume_vg_ctrl(vg_item->wr_ctrl, id, vol_size, volume_name, volume_flag); - if (status != CM_SUCCESS) { - return status; - } - return wr_add_volume_record_log(session, vg_item, id); -} - uint32_t wr_find_volume(wr_vg_info_item_t *vg_item, const char *volume_name) { for (uint32_t i = 0; i < WR_MAX_VOLUMES; i++) { @@ -1101,32 +881,6 @@ uint32_t wr_find_volume(wr_vg_info_item_t *vg_item, const char *volume_name) return CM_INVALID_ID32; } -status_t wr_add_volume_core( - wr_session_t *session, wr_vg_info_item_t *vg_item, const char *volume_name, wr_config_t *inst_cfg) -{ - if (wr_refresh_vginfo(vg_item) != CM_SUCCESS) { - LOG_DEBUG_ERR("[VOL][ADV] %s refresh vginfo failed.", "wr_add_volume"); - return CM_ERROR; - } - if (wr_find_volume(vg_item, volume_name) != CM_INVALID_ID32) { - WR_THROW_ERROR(ERR_WR_VOLUME_EXISTED, volume_name, vg_item->vg_name); - return CM_ERROR; - } - if (wr_add_volume_impl(session, vg_item, volume_name, VOLUME_PREPARE) != CM_SUCCESS) { - return CM_ERROR; - } - - if (wr_process_redo_log(session, vg_item) != CM_SUCCESS) { - wr_unlock_vg_mem_and_shm(session, vg_item); - (void)wr_unlock_vg_storage(vg_item, vg_item->entry_path, inst_cfg); - LOG_RUN_ERR("[WR] ABORT INFO: redo log process failed, errcode:%d, OS errno:%d, OS errmsg:%s.", - cm_get_error_code(), errno, strerror(errno)); - cm_fync_logfile(); - wr_exit(1); - } - return CM_SUCCESS; -} - status_t wr_refresh_meta_info(wr_session_t *session) { return CM_SUCCESS; @@ -1139,58 +893,6 @@ uint64 wr_get_vg_latch_shm_offset(wr_vg_info_item_t *vg_item) return offset; } -// shoud lock in caller -status_t wr_load_volume_ctrl(wr_vg_info_item_t *vg_item, wr_volume_ctrl_t *volume_ctrl) -{ - return CM_SUCCESS; -} - -status_t wr_check_refresh_core(wr_vg_info_item_t *vg_item) -{ - if (!WR_STANDBY_CLUSTER && wr_is_readwrite()) { - WR_ASSERT_LOG(wr_need_exec_local(), "only masterid %u can be readwrite.", wr_get_master_id()); - return CM_SUCCESS; - } -#ifndef WIN32 - char buf[WR_DISK_UNIT_SIZE] __attribute__((__aligned__(WR_DISK_UNIT_SIZE))); -#else - char buf[WR_DISK_UNIT_SIZE]; -#endif - bool32 remote = CM_FALSE; - uint64 core_version = vg_item->wr_ctrl->core.version; - wr_fs_block_root_t *fs_root = (wr_fs_block_root_t *)vg_item->wr_ctrl->core.fs_block_root; - uint64 fs_version = fs_root->version; - wr_fs_aux_root_t *fs_aux_root = (wr_fs_aux_root_t *)vg_item->wr_ctrl->core.fs_aux_root; - uint64 fs_aux_version = fs_aux_root->version; - - status_t status = wr_load_vg_ctrl_part(vg_item, (int64)WR_CTRL_CORE_OFFSET, buf, WR_DISK_UNIT_SIZE, &remote); - if (status != CM_SUCCESS) { - LOG_DEBUG_ERR("Failed to load vg core version %s.", vg_item->entry_path); - return status; - } - - wr_core_ctrl_t *new_core = (wr_core_ctrl_t *)buf; - if (wr_compare_version(new_core->version, core_version)) { - LOG_RUN_INF("Refresh core, old version:%llu, disk version:%llu.", core_version, new_core->version); - status = wr_load_vg_ctrl_part( - vg_item, (int64)WR_CTRL_CORE_OFFSET, &vg_item->wr_ctrl->core, (int32)WR_CORE_CTRL_SIZE, &remote); - if (status != CM_SUCCESS) { - LOG_DEBUG_ERR("Failed to load vg core %s.", vg_item->entry_path); - return status; - } - } else { - fs_root = (wr_fs_block_root_t *)new_core->fs_block_root; - fs_aux_root = (wr_fs_aux_root_t *)new_core->fs_aux_root; - if (wr_compare_version(fs_root->version, fs_version) || - wr_compare_version(fs_aux_root->version, fs_aux_version)) { - LOG_RUN_INF("Refresh core head, old version:%llu, disk version:%llu.", fs_version, fs_root->version); - errno_t errcode = memcpy_s(&vg_item->wr_ctrl->core, WR_DISK_UNIT_SIZE, buf, WR_DISK_UNIT_SIZE); - securec_check_ret(errcode); - } - } - return CM_SUCCESS; -} - // NOTE:use in server. status_t wr_check_volume(wr_vg_info_item_t *vg_item, uint32 volumeid) { diff --git a/src/common/persist/wr_diskgroup.h b/src/common/persist/wr_diskgroup.h index ab978e785546a3d3028b465cfc4a82b3401e1541..2cdd05e9596e5b4c1e66fe02eeacd0bad9e35de6 100644 --- a/src/common/persist/wr_diskgroup.h +++ b/src/common/persist/wr_diskgroup.h @@ -85,17 +85,12 @@ void wr_free_vg_info(); wr_vg_info_item_t *wr_find_vg_item(const char *vg_name); wr_vg_info_item_t *wr_find_vg_item_by_id(uint32 vg_id); -status_t wr_load_vg_ctrl(wr_vg_info_item_t *vg_item, bool32 is_lock); status_t wr_load_vg_ctrl_part(wr_vg_info_item_t *vg_item, int64 offset, void *buf, int32 size, bool32 *remote); -status_t wr_check_refresh_core(wr_vg_info_item_t *vg_item); void wr_lock_vg_mem_x(wr_vg_info_item_t *vg_item); -void wr_lock_vg_mem_x2ix(wr_vg_info_item_t *vg_item); -void wr_lock_vg_mem_ix2x(wr_vg_info_item_t *vg_item); void wr_lock_vg_mem_s(wr_vg_info_item_t *vg_item); void wr_lock_vg_mem_s_force(wr_vg_info_item_t *vg_item); -void wr_lock_vg_mem_degrade(wr_vg_info_item_t *vg_item); void wr_unlock_vg_mem(wr_vg_info_item_t *vg_item); status_t wr_file_lock_vg_w(wr_config_t *inst_cfg); @@ -108,14 +103,12 @@ status_t wr_unlock_vg_raid(wr_vg_info_item_t *vg_item, const char *entry_path, i status_t wr_unlock_vg_share_disk(wr_vg_info_item_t *vg_item, const char *entry_path, int64 inst_id); status_t wr_unlock_vg(int32 wr_mode, wr_vg_info_item_t *vg_item, const char *entry_path, int64 inst_id); status_t wr_lock_vg_storage_r(wr_vg_info_item_t *vg_item, const char *entry_path, wr_config_t *inst_cfg); -status_t wr_lock_vg_storage_w(wr_vg_info_item_t *vg_item, const char *entry_path, wr_config_t *inst_cfg); status_t wr_unlock_vg_storage(wr_vg_info_item_t *vg_item, const char *entry_path, wr_config_t *inst_cfg); status_t wr_lock_vg_storage_core(wr_vg_info_item_t *vg_item, const char *entry_path, wr_config_t *inst_cfg); status_t wr_unlock_vg_storage_core(wr_vg_info_item_t *vg_item, const char *entry_path, wr_config_t *inst_cfg); status_t wr_add_volume(wr_session_t *session, const char *vg_name, const char *volume_name); status_t wr_remove_volume(wr_session_t *session, const char *vg_name, const char *volume_name); status_t wr_refresh_meta_info(wr_session_t *session); -status_t wr_load_volume_ctrl(wr_vg_info_item_t *vg_item, wr_volume_ctrl_t *volume_ctrl); status_t wr_write_ctrl_to_disk(wr_vg_info_item_t *vg_item, int64 offset, void *buf, uint32 size); status_t wr_update_core_ctrl_disk(wr_vg_info_item_t *vg_item); diff --git a/src/common/persist/wr_redo.c b/src/common/persist/wr_redo.c index 653bf7638a3ef5ea083a2556de7a87133c59ba66..1739044f0627d96555cbd489c384277a5d353056 100644 --- a/src/common/persist/wr_redo.c +++ b/src/common/persist/wr_redo.c @@ -180,148 +180,6 @@ status_t wr_flush_log(wr_vg_info_item_t *vg_item, char *log_buf) return status; } -static status_t rp_redo_update_volhead(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ -#ifndef WIN32 - char align_buf[WR_DISK_UNIT_SIZE] __attribute__((__aligned__(WR_DISK_UNIT_SIZE))); -#else - char align_buf[WR_DISK_UNIT_SIZE]; -#endif - wr_redo_volhead_t *redo = (wr_redo_volhead_t *)entry->data; - if (entry->size == 0) { - WR_RETURN_IFERR2(CM_ERROR, WR_THROW_ERROR(ERR_WR_REDO_ILL, "invalid entry log size 0.")); - } - int32 errcode = memcpy_sp(align_buf, WR_DISK_UNIT_SIZE, redo->head, WR_DISK_UNIT_SIZE); - securec_check_ret(errcode); - wr_volume_t volume; - if (wr_open_volume(redo->name, NULL, WR_INSTANCE_OPEN_FLAG, &volume) != CM_SUCCESS) { - return CM_ERROR; - } - status_t status = wr_write_volume(&volume, 0, align_buf, (int32)WR_ALIGN_SIZE); - wr_close_volume(&volume); - return status; -} - -static status_t rp_redo_add_or_remove_volume( - wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - errno_t errcode = 0; - wr_redo_volop_t *redo = (wr_redo_volop_t *)entry->data; - if (entry->size == 0) { - WR_RETURN_IFERR2(CM_ERROR, WR_THROW_ERROR(ERR_WR_REDO_ILL, "invalid entry log size 0.")); - } - wr_volume_attr_t *attr = (wr_volume_attr_t *)redo->attr; - uint32 id = attr->id; - - if (vg_item->status == WR_VG_STATUS_RECOVERY) { - if (wr_refresh_vginfo(vg_item) != CM_SUCCESS) { - WR_RETURN_IFERR2( - CM_ERROR, LOG_DEBUG_ERR("[REDO][REPLAY][ADD_OR_REMOVE_VOLUME] %s", "refresh vginfo failed.")); - } - - // in recovery - if (redo->is_add) { - CM_ASSERT((vg_item->wr_ctrl->core.volume_count + 1 == redo->volume_count) || - (vg_item->wr_ctrl->core.volume_count == redo->volume_count)); - } else { - CM_ASSERT((vg_item->wr_ctrl->core.volume_count - 1 == redo->volume_count) || - (vg_item->wr_ctrl->core.volume_count == redo->volume_count)); - } - - errcode = memcpy_s(&vg_item->wr_ctrl->core.volume_attrs[id], sizeof(wr_volume_attr_t), redo->attr, - sizeof(wr_volume_attr_t)); - securec_check_ret(errcode); - errcode = memcpy_s( - &vg_item->wr_ctrl->volume.defs[id], sizeof(wr_volume_def_t), redo->def, sizeof(wr_volume_def_t)); - securec_check_ret(errcode); - - LOG_RUN_INF("[REDO][REPLAY][ADD_OR_REMOVE_VOLUME] recovery add volume core\n" - "[before]core version:%llu, volume version:%llu, volume count:%u.\n" - "[after]core version:%llu, volume version:%llu, volume count:%u.", - vg_item->wr_ctrl->core.version, vg_item->wr_ctrl->volume.version, vg_item->wr_ctrl->core.volume_count, - redo->core_version, redo->volume_version, redo->volume_count); - - vg_item->wr_ctrl->core.version = redo->core_version; - vg_item->wr_ctrl->core.volume_count = redo->volume_count; - vg_item->wr_ctrl->volume.version = redo->volume_version; - } - status_t status = wr_update_volume_id_info(vg_item, id); - WR_RETURN_IFERR2(status, - LOG_DEBUG_ERR("[REDO][REPLAY][ADD_OR_REMOVE_VOLUME] Failed to update core ctrl and volume to disk, vg:%s.", - vg_item->vg_name)); - WR_LOG_DEBUG_OP("[REDO][REPLAY][ADD_OR_REMOVE_VOLUME] Succeed to replay add or remove volume:%u.", id); - return CM_SUCCESS; -} - -static status_t rb_redo_update_volhead(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - // no need to update volume head. - return CM_SUCCESS; -} - -static void print_redo_update_volhead(wr_redo_entry_t *entry) -{ - wr_redo_volhead_t *redo = (wr_redo_volhead_t *)entry->data; - (void)printf(" redo_volhead = {\n"); - (void)printf(" head = %s\n", redo->head); - (void)printf(" name = %s\n", redo->name); - (void)printf(" }\n"); -} -static status_t rb_redo_add_or_remove_volume( - wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - bool32 remote = CM_FALSE; - wr_redo_volop_t *redo = (wr_redo_volop_t *)entry->data; - WR_LOG_DEBUG_OP( - "[REDO][ROLLBACK][ADD_OR_REMOVE_VOL] rollback %s volume operate", (redo->is_add) ? "add" : "remove"); - return wr_load_vg_ctrl_part(vg_item, (int64)WR_CTRL_CORE_OFFSET, vg_item->wr_ctrl->core_data, - (int32)(WR_CORE_CTRL_SIZE + WR_VOLUME_CTRL_SIZE), &remote); -} - -static void print_redo_add_or_remove_volume(wr_redo_entry_t *entry) -{ - wr_redo_volop_t *data = (wr_redo_volop_t *)entry->data; - (void)printf(" redo_volop = {\n"); - (void)printf(" attr = %s\n", data->attr); - (void)printf(" def = %s\n", data->def); - (void)printf(" is_add = %u\n", data->is_add); - (void)printf(" volume_count = %u\n", data->volume_count); - (void)printf(" core_version = %llu\n", data->core_version); - (void)printf(" volume_version = %llu\n", data->volume_version); - (void)printf(" }\n"); -} - -static status_t rp_update_core_ctrl(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - errno_t errcode = 0; - wr_core_ctrl_t *data = (wr_core_ctrl_t *)entry->data; - if (entry->size != 0 && vg_item->status == WR_VG_STATUS_RECOVERY) { - errcode = - memcpy_s(vg_item->wr_ctrl->core_data, WR_CORE_CTRL_SIZE, data, entry->size - sizeof(wr_redo_entry_t)); - securec_check_ret(errcode); - } - LOG_DEBUG_INF("[REDO] replay to update core ctrl, hwm:%llu.", vg_item->wr_ctrl->core.volume_attrs[0].hwm); - status_t status = wr_update_core_ctrl_disk(vg_item); - WR_RETURN_IFERR2(status, LOG_DEBUG_ERR("[REDO] Failed to update core ctrl to disk, vg:%s.", vg_item->vg_name)); - WR_LOG_DEBUG_OP("[REDO] Succeed to replay update core ctrl:%s.", vg_item->vg_name); - return CM_SUCCESS; -} - -static status_t rb_update_core_ctrl(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - bool32 remote = CM_FALSE; - WR_LOG_DEBUG_OP( - "[REDO][ROLLBACK] rollback update core ctrl, hwm:%llu.", vg_item->wr_ctrl->core.volume_attrs[0].hwm); - return wr_load_vg_ctrl_part( - vg_item, (int64)WR_CTRL_CORE_OFFSET, vg_item->wr_ctrl->core_data, (int32)WR_CORE_CTRL_SIZE, &remote); -} - -static void print_redo_update_core_ctrl(wr_redo_entry_t *entry) -{ - wr_core_ctrl_t *data = (wr_core_ctrl_t *)entry->data; - wr_printf_core_ctrl_base(data); -} - void rp_init_block_addr_history(wr_block_addr_his_t *addr_his) { CM_ASSERT(addr_his != NULL); @@ -348,434 +206,22 @@ bool32 rp_check_block_addr(const wr_block_addr_his_t *addr_his, const void *bloc } return CM_FALSE; } -static status_t rp_redo_alloc_ft_node_core(wr_session_t *session, wr_vg_info_item_t *vg_item, - wr_redo_alloc_ft_node_t *data, wr_root_ft_block_t *ft_block, bool32 check_version) -{ - bool32 cmp; - status_t status; - gft_node_t *node; - wr_ft_block_t *cur_block; - wr_block_addr_his_t addr_his; - rp_init_block_addr_history(&addr_his); - rp_insert_block_addr_history(&addr_his, ft_block); - for (uint32 i = 0; i < WR_REDO_ALLOC_FT_NODE_NUM; i++) { - cmp = wr_cmp_auid(data->node[i].id, CM_INVALID_ID64); - if (cmp) { - continue; - } - node = wr_get_ft_node_by_ftid(session, vg_item, data->node[i].id, check_version, CM_FALSE); - if (node == NULL) { - WR_RETURN_IFERR2(CM_ERROR, WR_THROW_ERROR(ERR_WR_FNODE_CHECK, "invalid ft node.")); - } - cur_block = wr_get_ft_by_node(node); - if (vg_item->status == WR_VG_STATUS_RECOVERY) { - *node = data->node[i]; - if (i == WR_REDO_ALLOC_FT_NODE_SELF_INDEX) { - cur_block->common.flags = WR_BLOCK_FLAG_USED; - } - } - - LOG_DEBUG_INF("[REDO] replay alloc file table node, name:%s.", node->name); - - cur_block = wr_get_ft_by_node(node); - if (rp_check_block_addr(&addr_his, cur_block) && vg_item->status != WR_VG_STATUS_RECOVERY) { - continue; // already update the block to disk - } - status = wr_update_ft_block_disk(vg_item, cur_block, data->node[i].id); - WR_RETURN_IF_ERROR(status); - rp_insert_block_addr_history(&addr_his, cur_block); - } - return CM_SUCCESS; -} - -static status_t rp_redo_alloc_ft_node(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - CM_ASSERT(vg_item != NULL); - CM_ASSERT(entry != NULL); - status_t status; - wr_redo_alloc_ft_node_t *data = (wr_redo_alloc_ft_node_t *)entry->data; - wr_root_ft_block_t *ft_block = WR_GET_ROOT_BLOCK(vg_item->wr_ctrl); - gft_root_t *gft = &ft_block->ft_root; - bool32 check_version = CM_FALSE; - - if (entry->size == 0) { - WR_RETURN_IFERR2(CM_ERROR, WR_THROW_ERROR(ERR_WR_REDO_ILL, "invalid entry log size 0.")); - } - if (vg_item->status == WR_VG_STATUS_RECOVERY) { - status = wr_refresh_root_ft(vg_item, CM_TRUE, CM_FALSE); - if (status != CM_SUCCESS) { - LOG_DEBUG_ERR("[REDO] Failed to refresh file table root, vg:%s.", vg_item->vg_name); - return status; - } - - *gft = data->ft_root; - check_version = CM_TRUE; - LOG_DEBUG_INF("[REDO] replay alloc file table node when recovery."); - } - - status = wr_update_ft_root(vg_item); - WR_RETURN_IFERR2(status, WR_THROW_ERROR(ERR_WR_REDO_ILL, "Failed to update file table root.")); - WR_RETURN_IF_ERROR(rp_redo_alloc_ft_node_core(session, vg_item, data, ft_block, check_version)); - LOG_DEBUG_INF("[REDO] Succeed to replay alloc ft node, vg name:%s.", vg_item->vg_name); - return CM_SUCCESS; -} - -static status_t rb_rollback_ft_block( - wr_session_t *session, wr_vg_info_item_t *vg_item, gft_node_t *node, uint32 node_num) -{ - CM_ASSERT(vg_item != NULL); - CM_ASSERT(node != NULL); - status_t status; - bool32 check_version = CM_FALSE; - bool32 remote = CM_FALSE; - - status = wr_load_vg_ctrl_part( - vg_item, (int64)WR_CTRL_ROOT_OFFSET, vg_item->wr_ctrl->root, (int32)WR_BLOCK_SIZE, &remote); - if (status != CM_SUCCESS) { - return status; - } - - gft_node_t *cur_node; - wr_ft_block_t *cur_block = NULL; - bool32 cmp; - int64 offset = 0; - for (uint32 i = 0; i < node_num; i++) { - cmp = wr_cmp_auid(node[i].id, CM_INVALID_ID64); - if (cmp) { - continue; - } - cur_node = wr_get_ft_node_by_ftid(session, vg_item, node[i].id, check_version, CM_FALSE); - if (!cur_node) { - WR_RETURN_IFERR2(CM_ERROR, WR_THROW_ERROR(ERR_WR_FNODE_CHECK, "invalid ft node.")); - } - - cur_block = wr_get_ft_by_node(cur_node); - offset = wr_get_ft_block_offset(vg_item, node[i].id); - status = - wr_get_block_from_disk(vg_item, node[i].id, (char *)cur_block, offset, (int32)WR_BLOCK_SIZE, CM_TRUE); - if (status != CM_SUCCESS) { - return status; - } - } - return CM_SUCCESS; -} - -static status_t rb_redo_alloc_ft_node(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - CM_ASSERT(vg_item != NULL); - CM_ASSERT(entry != NULL); - wr_redo_alloc_ft_node_t *data = (wr_redo_alloc_ft_node_t *)entry->data; - - if (entry->size == 0) { - WR_RETURN_IFERR2(CM_ERROR, WR_THROW_ERROR(ERR_WR_REDO_ILL, "invalid entry log size 0.")); - } - - return rb_rollback_ft_block(session, vg_item, data->node, WR_REDO_ALLOC_FT_NODE_NUM); -} - -static void print_redo_alloc_ft_node(wr_redo_entry_t *entry) -{ - wr_redo_alloc_ft_node_t *data = (wr_redo_alloc_ft_node_t *)entry->data; - (void)printf(" alloc_ft_node = {\n"); - (void)printf(" ft_root = {\n"); - printf_gft_root(&data->ft_root); - (void)printf(" }\n"); - for (uint32 i = 0; i < WR_REDO_ALLOC_FT_NODE_NUM; i++) { - if (wr_cmp_auid(data->node[i].id, CM_INVALID_ID64)) { - continue; - } - (void)printf(" gft_node[%u] = {\n", i); - printf_gft_node(&data->node[i], " "); - (void)printf(" }\n"); - } - (void)printf(" }\n"); -} - -static status_t wr_update_ft_info(wr_vg_info_item_t *vg_item, wr_ft_block_t *block, wr_redo_format_ft_t *data) -{ - status_t status = wr_update_ft_block_disk(vg_item, block, data->old_last_block); - if (status != CM_SUCCESS) { - LOG_DEBUG_ERR( - "[REDO] Failed to update file table block to disk, %s.", wr_display_metaid(data->old_last_block)); - return status; - } - status = wr_update_ft_root(vg_item); - WR_RETURN_IFERR2(status, LOG_DEBUG_ERR("[REDO] Failed to update file table root, vg:%s.", vg_item->vg_name)); - return CM_SUCCESS; -} - -static status_t rp_redo_format_ft_node(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - CM_ASSERT(vg_item != NULL && entry != NULL); - - status_t status; - wr_redo_format_ft_t *data = (wr_redo_format_ft_t *)entry->data; - wr_ft_block_t *block = NULL; - if (vg_item->status == WR_VG_STATUS_RECOVERY) { - status = wr_refresh_root_ft(vg_item, CM_TRUE, CM_FALSE); - WR_RETURN_IFERR2(status, LOG_DEBUG_ERR("[REDO] Failed to refresh file table root, vg:%s.", vg_item->vg_name)); - // note:first load - block = (wr_ft_block_t *)wr_get_ft_block_by_ftid(session, vg_item, data->old_last_block); - if (block == NULL) { - WR_RETURN_IFERR2(CM_ERROR, LOG_DEBUG_ERR("[REDO]Failed to get last file table block, blockid: %s.", - wr_display_metaid(data->old_last_block))); - } - wr_root_ft_block_t *root_block = WR_GET_ROOT_BLOCK(vg_item->wr_ctrl); - root_block->ft_root.free_list = data->old_free_list; - root_block->ft_root.last = data->old_last_block; - status = wr_format_ft_node(session, vg_item, data->auid); - WR_RETURN_IFERR2( - status, LOG_DEBUG_ERR("[REDO] Failed to format file table node, %s.", wr_display_metaid(data->auid))); - } - // when recover, has load old last block. - if (vg_item->status != WR_VG_STATUS_RECOVERY) { // just find the block, it has already in memory. - block = (wr_ft_block_t *)wr_get_ft_block_by_ftid(session, vg_item, data->old_last_block); - if (block == NULL) { - WR_RETURN_IFERR2(CM_ERROR, LOG_DEBUG_ERR("[REDO]Failed to get last file table block, blockid: %s.", - wr_display_metaid(data->old_last_block))); - } - } - CM_RETURN_IFERR(wr_update_ft_info(vg_item, block, data)); - wr_block_id_t first = data->auid; - ga_obj_id_t obj_id; - status = wr_find_block_objid_in_shm(session, vg_item, first, WR_BLOCK_TYPE_FT, &obj_id); - WR_RETURN_IFERR2(status, LOG_DEBUG_ERR("[REDO] Failed to find block: %s.", wr_display_metaid(first))); - status = wr_update_au_disk(vg_item, data->auid, GA_8K_POOL, obj_id.obj_id, data->count, WR_BLOCK_SIZE); - WR_RETURN_IFERR2(status, LOG_DEBUG_ERR("[REDO] Failed to update au to disk, %s.", wr_display_metaid(data->auid))); - WR_LOG_DEBUG_OP("[REDO] Succeed to replay formate ft node: %s , obj_id:%u, count:%u.", - wr_display_metaid(data->auid), data->obj_id, data->count); - LOG_DEBUG_INF("[REDO] old_last_block: %s", wr_display_metaid(data->old_last_block)); - return CM_SUCCESS; -} - -static status_t rb_redo_format_ft_node(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - // format file table node only when new au, if fail, just free the memory, no need to rollback. - return CM_SUCCESS; -} - -static void print_redo_format_ft_node(wr_redo_entry_t *entry) -{ - wr_redo_format_ft_t *data = (wr_redo_format_ft_t *)entry->data; - (void)printf(" format_ft = {\n"); - (void)printf(" auid = {\n"); - printf_auid(&data->auid); - (void)printf(" }\n"); - (void)printf(" obj_id = %u\n", data->obj_id); - (void)printf(" count = %u\n", data->count); - (void)printf(" old_last_block = {\n"); - printf_auid(&data->old_last_block); - (void)printf(" }\n"); - (void)printf(" old_free_list = {\n"); - printf_gft_list(&data->old_free_list); - (void)printf(" }\n"); - (void)printf(" obj_id = %u\n", data->obj_id); - (void)printf(" }\n"); -} - -static status_t rp_redo_free_fs_block(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - CM_ASSERT(vg_item != NULL); - CM_ASSERT(entry != NULL); - - status_t status; - wr_redo_free_fs_block_t *data = (wr_redo_free_fs_block_t *)entry->data; - - wr_fs_block_t *block; - wr_fs_block_t *log_block = (wr_fs_block_t *)data->head; - if (vg_item->status == WR_VG_STATUS_RECOVERY) { - ga_obj_id_t obj_id; - block = (wr_fs_block_t *)wr_find_block_in_shm( - session, vg_item, log_block->head.common.id, WR_BLOCK_TYPE_FS, CM_TRUE, &obj_id, CM_FALSE); - if (block == NULL) { - WR_RETURN_IFERR2(CM_ERROR, WR_THROW_ERROR(ERR_WR_FNODE_CHECK, "invalid block")); - } - block->head.next = log_block->head.next; - block->head.index = WR_FS_INDEX_INIT; - block->head.common.flags = WR_BLOCK_FLAG_FREE; - wr_set_auid(&block->head.ftid, WR_BLOCK_ID_INIT); - status = wr_update_fs_bitmap_block_disk(vg_item, block, WR_DISK_UNIT_SIZE, CM_FALSE); - WR_RETURN_IF_ERROR(status); - wr_unregister_buffer_cache(session, vg_item, log_block->head.common.id); - ga_free_object(obj_id.pool_id, obj_id.obj_id); - return CM_SUCCESS; - } - - status = wr_update_fs_bitmap_block_disk(vg_item, log_block, WR_DISK_UNIT_SIZE, CM_TRUE); - WR_RETURN_IFERR2(status, - LOG_DEBUG_ERR("[REDO] Failed to update fs bitmap block: %s.", wr_display_metaid(log_block->head.common.id))); - LOG_DEBUG_INF("[REDO] Succeed to replay free fs block: %s, vg name:%s.", - wr_display_metaid(log_block->head.common.id), vg_item->vg_name); - return CM_SUCCESS; -} status_t rb_redo_free_fs_block(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) { - CM_ASSERT(vg_item != NULL); - CM_ASSERT(entry != NULL); - - wr_redo_free_fs_block_t *data = (wr_redo_free_fs_block_t *)entry->data; - wr_fs_block_t *log_block = (wr_fs_block_t *)data->head; - - return wr_load_fs_block_by_blockid(session, vg_item, log_block->head.common.id, (int32)WR_FILE_SPACE_BLOCK_SIZE); -} -static void print_redo_free_fs_block(wr_redo_entry_t *entry) -{ - wr_redo_free_fs_block_t *data = (wr_redo_free_fs_block_t *)entry->data; - (void)printf(" free_fs_block = {\n"); - (void)printf(" head = %s\n", data->head); - (void)printf(" }\n"); -} -static status_t rp_redo_alloc_fs_block(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - CM_ASSERT(vg_item != NULL); - CM_ASSERT(entry != NULL); - - status_t status; - wr_redo_alloc_fs_block_t *data = (wr_redo_alloc_fs_block_t *)entry->data; - wr_fs_block_root_t *root = WR_GET_FS_BLOCK_ROOT(vg_item->wr_ctrl); - wr_fs_block_t *block = NULL; - - if (vg_item->status == WR_VG_STATUS_RECOVERY) { - status = wr_check_refresh_core(vg_item); - WR_RETURN_IFERR2(status, LOG_DEBUG_ERR("[REDO] Failed to refresh vg core:%s.", vg_item->vg_name)); - block = (wr_fs_block_t *)wr_find_block_in_shm( - session, vg_item, data->id, WR_BLOCK_TYPE_FS, CM_TRUE, NULL, CM_FALSE); - if (block == NULL) { - WR_RETURN_IFERR2(CM_ERROR, WR_THROW_ERROR(ERR_WR_FNODE_CHECK, "invalid block")); - } - - wr_init_fs_block_head(block); - block->head.ftid = data->ftid; - block->head.index = data->index; - block->head.common.flags = WR_BLOCK_FLAG_USED; - *root = data->root; - } - status = wr_update_core_ctrl_disk(vg_item); - WR_RETURN_IFERR2(status, LOG_DEBUG_ERR("[REDO] Failed to update vg core:%s to disk.", vg_item->vg_name)); - - if (block == NULL) { - block = (wr_fs_block_t *)wr_find_block_in_shm( - session, vg_item, data->id, WR_BLOCK_TYPE_FS, CM_FALSE, NULL, CM_FALSE); - } - - if (block == NULL) { - WR_RETURN_IFERR2(CM_ERROR, WR_THROW_ERROR(ERR_WR_FNODE_CHECK, "invalid block")); - } - - status = wr_update_fs_bitmap_block_disk(vg_item, block, WR_FILE_SPACE_BLOCK_SIZE, CM_FALSE); - WR_RETURN_IFERR2( - status, LOG_DEBUG_ERR("[REDO] Failed to update fs bitmap block: %s.", wr_display_metaid(data->id))); - LOG_DEBUG_INF( - "[REDO] Succeed to replay alloc fs block: %s, vg name:%s.", wr_display_metaid(data->id), vg_item->vg_name); return CM_SUCCESS; } -static status_t rb_redo_alloc_fs_block(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - CM_ASSERT(vg_item != NULL); - CM_ASSERT(entry != NULL); - - status_t status; - bool32 remote = CM_FALSE; - wr_redo_alloc_fs_block_t *data = (wr_redo_alloc_fs_block_t *)entry->data; - - ga_obj_id_t obj_id; - wr_fs_block_t *block = (wr_fs_block_t *)wr_find_block_in_shm( - session, vg_item, data->id, WR_BLOCK_TYPE_FS, CM_FALSE, &obj_id, CM_FALSE); - CM_ASSERT(block != NULL); - wr_unregister_buffer_cache(session, vg_item, block->head.common.id); - ga_free_object(obj_id.pool_id, obj_id.obj_id); - status = wr_load_vg_ctrl_part( - vg_item, (int64)WR_CTRL_CORE_OFFSET, vg_item->wr_ctrl->core_data, WR_DISK_UNIT_SIZE, &remote); - CM_ASSERT(status == CM_SUCCESS); - return status; -} - -static void print_redo_alloc_fs_block(wr_redo_entry_t *entry) -{ - wr_redo_alloc_fs_block_t *data = (wr_redo_alloc_fs_block_t *)entry->data; - (void)printf(" alloc_fs_block = {\n"); - (void)printf(" id = {\n"); - printf_auid(&data->id); - (void)printf(" }\n"); - (void)printf(" ftid = {\n"); - printf_auid(&data->ftid); - (void)printf(" }\n"); - (void)printf(" root = {\n"); - printf_wr_fs_block_root(&data->root); - (void)printf(" }\n"); - (void)printf(" index = %hu\n", data->index); - (void)printf(" }\n"); -} status_t rp_redo_init_fs_block(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) { - CM_ASSERT(vg_item != NULL); - CM_ASSERT(entry != NULL); - - status_t status; - wr_redo_init_fs_block_t *data = (wr_redo_init_fs_block_t *)entry->data; - - wr_fs_block_t *block = NULL; - - if (vg_item->status == WR_VG_STATUS_RECOVERY) { - block = (wr_fs_block_t *)wr_find_block_in_shm( - session, vg_item, data->id, WR_BLOCK_TYPE_FS, CM_TRUE, NULL, CM_FALSE); - if (block == NULL) { - WR_RETURN_IFERR2(CM_ERROR, WR_THROW_ERROR(ERR_WR_FNODE_CHECK, "invalid block")); - } - block->bitmap[data->index] = data->second_id; - block->head.used_num = data->used_num; - } - - if (block == NULL) { - block = (wr_fs_block_t *)wr_find_block_in_shm( - session, vg_item, data->id, WR_BLOCK_TYPE_FS, CM_FALSE, NULL, CM_FALSE); - if (block == NULL) { - WR_RETURN_IFERR2(CM_ERROR, WR_THROW_ERROR(ERR_WR_FNODE_CHECK, "invalid block")); - } - } - - status = wr_update_fs_bitmap_block_disk(vg_item, block, WR_FILE_SPACE_BLOCK_SIZE, CM_FALSE); - WR_RETURN_IFERR2( - status, LOG_DEBUG_ERR("[REDO] Failed to update fs bitmap block: %s to disk.", wr_display_metaid(data->id))); - LOG_DEBUG_INF( - "[REDO] Succeed to replay init fs block: %s, vg name:%s.", wr_display_metaid(data->id), vg_item->vg_name); return CM_SUCCESS; } status_t rb_redo_init_fs_block(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) { - CM_ASSERT(vg_item != NULL); - CM_ASSERT(entry != NULL); - - wr_redo_init_fs_block_t *data = (wr_redo_init_fs_block_t *)entry->data; - - wr_fs_block_t *block = (wr_fs_block_t *)wr_find_block_in_shm( - session, vg_item, data->id, WR_BLOCK_TYPE_FS, CM_FALSE, NULL, CM_FALSE); - if (block == NULL) { - WR_RETURN_IFERR2(CM_ERROR, WR_THROW_ERROR(ERR_WR_FNODE_CHECK, "invalid block")); - } - - wr_set_blockid(&block->bitmap[data->index], CM_INVALID_ID64); - block->head.used_num = 0; - return CM_SUCCESS; } -static void print_redo_init_fs_block(wr_redo_entry_t *entry) -{ - wr_redo_init_fs_block_t *data = (wr_redo_init_fs_block_t *)entry->data; - (void)printf(" init_fs_block = {\n"); - (void)printf(" id = {\n"); - printf_auid(&data->id); - (void)printf(" }\n"); - (void)printf(" second_id = {\n"); - printf_auid(&data->second_id); - (void)printf(" }\n"); - (void)printf(" index = %hu\n", data->index); - (void)printf(" used_num = %hu\n", data->used_num); - (void)printf(" }\n"); -} + status_t rp_redo_rename_file(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) { CM_ASSERT(vg_item != NULL); @@ -846,149 +292,25 @@ status_t rb_redo_rename_file(wr_session_t *session, wr_vg_info_item_t *vg_item, WR_SECUREC_SS_RETURN_IF_ERROR(ret, CM_ERROR); return CM_SUCCESS; } -static void print_redo_rename_file(wr_redo_entry_t *entry) -{ - wr_redo_rename_t *data = (wr_redo_rename_t *)entry->data; - (void)printf(" set_file_size = {\n"); - (void)printf(" node = {\n"); - printf_gft_node(&data->node, " "); - (void)printf(" }\n"); - (void)printf(" name = %s\n", data->name); - (void)printf(" old_name = %s\n", data->old_name); - (void)printf(" }\n"); -} + status_t rp_redo_set_fs_block(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) { - CM_ASSERT(vg_item != NULL); - CM_ASSERT(entry != NULL); - - status_t status; - wr_redo_set_fs_block_t *data = (wr_redo_set_fs_block_t *)entry->data; - - bool32 check_version = CM_FALSE; - if (vg_item->status == WR_VG_STATUS_RECOVERY) { - check_version = CM_TRUE; - } - - wr_fs_block_t *block = (wr_fs_block_t *)wr_find_block_in_shm( - session, vg_item, data->id, WR_BLOCK_TYPE_FS, check_version, NULL, CM_FALSE); - if (block == NULL) { - WR_RETURN_IFERR2(CM_ERROR, WR_THROW_ERROR(ERR_WR_FNODE_CHECK, "invalid block")); - } - - if (vg_item->status == WR_VG_STATUS_RECOVERY) { - block->bitmap[data->index] = data->value; - block->head.used_num = data->used_num; - } - - status = wr_update_fs_bitmap_block_disk(vg_item, block, WR_FILE_SPACE_BLOCK_SIZE, CM_FALSE); - WR_RETURN_IFERR2(status, LOG_DEBUG_ERR("Failed to update fs block: %s to disk.", wr_display_metaid(data->id))); - - LOG_DEBUG_INF("[REDO] Succeed to replay set fs block: %s, used_num:%hu, vg name:%s.", wr_display_metaid(data->id), - block->head.used_num, vg_item->vg_name); return CM_SUCCESS; } status_t rb_redo_set_fs_block(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - CM_ASSERT(vg_item != NULL); - CM_ASSERT(entry != NULL); - - wr_redo_set_fs_block_t *data = (wr_redo_set_fs_block_t *)entry->data; - - wr_fs_block_t *block; - bool32 check_version = CM_FALSE; - - block = (wr_fs_block_t *)wr_find_block_in_shm( - session, vg_item, data->id, WR_BLOCK_TYPE_FS, check_version, NULL, CM_FALSE); - if (block == NULL) { - WR_RETURN_IFERR2(CM_ERROR, WR_THROW_ERROR(ERR_WR_FNODE_CHECK, "invalid block")); - } - - block->bitmap[data->index] = data->old_value; - block->head.used_num = data->old_used_num; - - return CM_SUCCESS; -} - -static void print_redo_set_fs_block(wr_redo_entry_t *entry) -{ - wr_redo_set_fs_block_t *data = (wr_redo_set_fs_block_t *)entry->data; - (void)printf(" set_fs_block = {\n"); - (void)printf(" id = {\n"); - printf_auid(&data->id); - (void)printf(" }\n"); - (void)printf(" value = {\n"); - printf_auid(&data->value); - (void)printf(" }\n"); - (void)printf(" old_value = {\n"); - printf_auid(&data->old_value); - (void)printf(" }\n"); - (void)printf(" index = %hu\n", data->index); - (void)printf(" used_num = %hu\n", data->used_num); - (void)printf(" old_used_num = %hu\n", data->old_used_num); - (void)printf(" }\n"); -} - -static status_t rp_redo_free_ft_node_core(wr_session_t *session, wr_vg_info_item_t *vg_item, - wr_root_ft_block_t *ft_block, wr_redo_free_ft_node_t *data, bool32 check_version) { return CM_SUCCESS; } status_t rp_redo_free_ft_node(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) { - CM_ASSERT(vg_item != NULL); - CM_ASSERT(entry != NULL); - - wr_redo_free_ft_node_t *data = (wr_redo_free_ft_node_t *)entry->data; - wr_root_ft_block_t *ft_block = WR_GET_ROOT_BLOCK(vg_item->wr_ctrl); - gft_root_t *gft = &ft_block->ft_root; - bool32 check_version = CM_FALSE; - - if (entry->size == 0) { - WR_RETURN_IFERR2(CM_ERROR, WR_THROW_ERROR(ERR_WR_REDO_ILL, "invalid entry log size 0.")); - } - if (vg_item->status == WR_VG_STATUS_RECOVERY) { - CM_RETURN_IFERR_EX(wr_refresh_root_ft(vg_item, CM_TRUE, CM_FALSE), - LOG_DEBUG_ERR("[REDO] Failed to refresh file table root, vg:%s.", vg_item->vg_name)); - - *gft = data->ft_root; - check_version = CM_TRUE; - } - return rp_redo_free_ft_node_core(session, vg_item, ft_block, data, check_version); + return CM_SUCCESS; } status_t rb_redo_free_ft_node(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) { - CM_ASSERT(vg_item != NULL); - CM_ASSERT(entry != NULL); - - wr_redo_free_ft_node_t *data = (wr_redo_free_ft_node_t *)entry->data; - - if (entry->size == 0) { - WR_RETURN_IFERR2(CM_ERROR, WR_THROW_ERROR(ERR_WR_REDO_ILL, "invalid entry log size 0.")); - } - - return rb_rollback_ft_block(session, vg_item, data->node, WR_REDO_FREE_FT_NODE_NUM); -} - -static void print_redo_free_ft_node(wr_redo_entry_t *entry) -{ - wr_redo_free_ft_node_t *data = (wr_redo_free_ft_node_t *)entry->data; - (void)printf(" free_ft_node = {\n"); - (void)printf(" ft_root = {\n"); - printf_gft_root(&data->ft_root); - (void)printf(" }\n"); - for (uint32 i = 0; i < WR_REDO_FREE_FT_NODE_NUM; i++) { - if (wr_cmp_auid(data->node[i].id, CM_INVALID_ID64)) { - continue; - } - (void)printf(" gft_node[%u] = {\n", i); - printf_gft_node(&data->node[i], " "); - (void)printf(" }\n"); - } - (void)printf(" }\n"); + return CM_SUCCESS; } status_t rp_redo_recycle_ft_node(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) @@ -1001,55 +323,11 @@ status_t rb_redo_recycle_ft_node(wr_session_t *session, wr_vg_info_item_t *vg_it return CM_SUCCESS; } -static void print_redo_recycle_ft_node(wr_redo_entry_t *entry) -{ - wr_redo_recycle_ft_node_t *data = (wr_redo_recycle_ft_node_t *)entry->data; - (void)printf(" recycle_ft_node = {\n"); - for (uint32 i = 0; i < WR_REDO_RECYCLE_FT_NODE_NUM; i++) { - if (wr_cmp_auid(data->node[i].id, CM_INVALID_ID64)) { - continue; - } - (void)printf(" gft_node[%u] = {\n", i); - printf_gft_node(&data->node[i], " "); - (void)printf(" }\n"); - } - (void)printf(" }\n"); -} - status_t rp_redo_set_file_size(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) { return CM_SUCCESS; } -static status_t rb_redo_get_ft_node( - wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry, ftid_t ftid, gft_node_t **node) -{ - return CM_SUCCESS; -} - -status_t rb_redo_set_file_size(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - CM_ASSERT(vg_item != NULL); - CM_ASSERT(entry != NULL); - wr_redo_set_file_size_t *data = (wr_redo_set_file_size_t *)entry->data; - gft_node_t *node; - WR_RETURN_IF_ERROR(rb_redo_get_ft_node(session, vg_item, entry, data->ftid, &node)); - node->size = data->oldsize; - return CM_SUCCESS; -} - -static void print_redo_set_file_size(wr_redo_entry_t *entry) -{ - wr_redo_set_file_size_t *data = (wr_redo_set_file_size_t *)entry->data; - (void)printf(" set_file_size = {\n"); - (void)printf(" ftid = {\n"); - printf_auid(&data->ftid); - (void)printf(" }\n"); - (void)printf(" size = %llu\n", data->size); - (void)printf(" oldsize = %llu\n", data->oldsize); - (void)printf(" }\n"); -} - status_t rp_redo_format_fs_block(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) { return CM_SUCCESS; @@ -1083,149 +361,11 @@ status_t rb_redo_format_fs_block(wr_session_t *session, wr_vg_info_item_t *vg_it return CM_SUCCESS; } -static void print_redo_format_fs_block(wr_redo_entry_t *entry) -{ - wr_redo_format_fs_t *data = (wr_redo_format_fs_t *)entry->data; - (void)printf(" format_fs = {\n"); - (void)printf(" auid = {\n"); - printf_auid(&data->auid); - (void)printf(" }\n"); - (void)printf(" obj_id = %u\n", data->obj_id); - (void)printf(" count = %u\n", data->count); - (void)printf(" old_free_list = {\n"); - printf_wr_fs_block_list(&data->old_free_list); - (void)printf(" }\n"); - (void)printf(" }\n"); -} - -static status_t rp_redo_set_node_flag(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - return CM_SUCCESS; -} - -static status_t rb_redo_set_node_flag(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - return CM_SUCCESS; -} - -static void print_redo_set_node_flag(wr_redo_entry_t *entry) -{ - wr_redo_set_file_flag_t *data = (wr_redo_set_file_flag_t *)entry->data; - (void)printf(" set_file_flag = {\n"); - (void)printf(" id = {\n"); - printf_auid(&data->ftid); - (void)printf(" }\n"); - (void)printf(" flags = %u\n", data->flags); - (void)printf(" old_flags = %u\n", data->old_flags); - (void)printf(" }\n"); -} - -status_t rp_redo_set_fs_block_batch(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - return CM_SUCCESS; -} - -status_t rb_redo_set_fs_block_batch(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - return CM_SUCCESS; -} - -status_t rp_redo_set_fs_aux_block_batch_in_recovery(wr_session_t *session, wr_vg_info_item_t *vg_item, - wr_redo_entry_t *entry, wr_fs_block_t *second_block, gft_node_t *node) -{ - return CM_SUCCESS; -} - -status_t rp_redo_set_fs_aux_block_batch_inner(wr_session_t *session, wr_vg_info_item_t *vg_item, - wr_redo_entry_t *entry, wr_fs_block_t *second_block, gft_node_t *node) -{ - return CM_SUCCESS; -} - -status_t rp_redo_set_fs_aux_block_batch(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - return CM_SUCCESS; -} - -status_t rb_redo_set_fs_aux_block_batch(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - return CM_SUCCESS; -} - -status_t rp_redo_truncate_fs_block_batch(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - return CM_SUCCESS; -} - -status_t rb_redo_truncate_fs_block_batch(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_entry_t *entry) -{ - return CM_SUCCESS; -} - -static wr_redo_handler_t g_wr_handlers[] = { - {WR_RT_UPDATE_CORE_CTRL, rp_update_core_ctrl, rb_update_core_ctrl, print_redo_update_core_ctrl}, - {WR_RT_ADD_OR_REMOVE_VOLUME, rp_redo_add_or_remove_volume, rb_redo_add_or_remove_volume, - print_redo_add_or_remove_volume}, - {WR_RT_UPDATE_VOLHEAD, rp_redo_update_volhead, rb_redo_update_volhead, print_redo_update_volhead}, - // ft_au initializes multiple ft_blocks and mounts them to gft->free_list - {WR_RT_FORMAT_AU_FILE_TABLE, rp_redo_format_ft_node, rb_redo_format_ft_node, print_redo_format_ft_node}, - // mount a gft_node to a directory - {WR_RT_ALLOC_FILE_TABLE_NODE, rp_redo_alloc_ft_node, rb_redo_alloc_ft_node, print_redo_alloc_ft_node}, - // recycle gft_node to gft->free_list - {WR_RT_FREE_FILE_TABLE_NODE, rp_redo_free_ft_node, rb_redo_free_ft_node, print_redo_free_ft_node}, - // recycle gft_node to wr_ctrl->core.au_root->free_root - {WR_RT_RECYCLE_FILE_TABLE_NODE, rp_redo_recycle_ft_node, rb_redo_recycle_ft_node, print_redo_recycle_ft_node}, - {WR_RT_SET_FILE_SIZE, rp_redo_set_file_size, rb_redo_set_file_size, print_redo_set_file_size}, - {WR_RT_RENAME_FILE, rp_redo_rename_file, rb_redo_rename_file, print_redo_rename_file}, - - // bitmap_au is initialized to multiple fs_blocks and mounted to wr_ctrl->core.fs_block_root - {WR_RT_FORMAT_AU_FILE_SPACE, rp_redo_format_fs_block, rb_redo_format_fs_block, print_redo_format_fs_block}, - // allocate an idle fs_block from the wr_ctrl->core.fs_block_root - {WR_RT_ALLOC_FS_BLOCK, rp_redo_alloc_fs_block, rb_redo_alloc_fs_block, print_redo_alloc_fs_block}, - // recycle fs_block to wr_ctrl->core.fs_block_root->free - {WR_RT_FREE_FS_BLOCK, rp_redo_free_fs_block, rb_redo_free_fs_block, print_redo_free_fs_block}, - // initialize fs_block on gft_node - {WR_RT_INIT_FILE_FS_BLOCK, rp_redo_init_fs_block, rb_redo_init_fs_block, print_redo_init_fs_block}, - // adds or removes a managed object of fs_block - {WR_RT_SET_FILE_FS_BLOCK, rp_redo_set_fs_block, rb_redo_set_fs_block, print_redo_set_fs_block}, - {WR_RT_SET_NODE_FLAG, rp_redo_set_node_flag, rb_redo_set_node_flag, print_redo_set_node_flag}, -}; - -void wr_print_redo_entry(wr_redo_entry_t *entry) -{ - (void)printf(" redo entry type = %u\n", entry->type); - (void)printf(" redo entry size = %u\n", entry->size); - wr_redo_handler_t *handler = &g_wr_handlers[entry->type]; - handler->print(entry); -} - -// apply log to update meta -status_t wr_apply_log(wr_session_t *session, wr_vg_info_item_t *vg_item, char *log_buf) -{ - - return CM_SUCCESS; -} - -status_t wr_update_redo_info(wr_vg_info_item_t *vg_item, char *log_buf) -{ - return CM_SUCCESS; -} - -status_t wr_process_redo_log_inner(wr_session_t *session, wr_vg_info_item_t *vg_item) -{ - return CM_SUCCESS; -} - status_t wr_process_redo_log(wr_session_t *session, wr_vg_info_item_t *vg_item) { return CM_SUCCESS; } -status_t wr_rollback_log(wr_session_t *session, wr_vg_info_item_t *vg_item, char *log_buf) -{ - return CM_SUCCESS; -} - void wr_rollback_mem_update(wr_session_t *session, wr_vg_info_item_t *vg_item) { return; diff --git a/src/common/persist/wr_redo.h b/src/common/persist/wr_redo.h index b1faa0e6f8769231f54624d74fcf189435baec13..a5a6bab3629e70a130fe6898d5c6f6e5dcbf3cf1 100644 --- a/src/common/persist/wr_redo.h +++ b/src/common/persist/wr_redo.h @@ -289,14 +289,11 @@ bool32 rp_check_block_addr(const wr_block_addr_his_t *addr_his, const void *bloc status_t wr_write_redolog_to_disk(wr_vg_info_item_t *item, uint32 volume_id, int64 offset, char *buf, uint32 size); void wr_put_log(wr_session_t *session, wr_vg_info_item_t *vg_item, wr_redo_type_t type, void *data, uint32 size); status_t wr_flush_log(wr_vg_info_item_t *vg_item, char *log_buf); -status_t wr_apply_log(wr_session_t *session, wr_vg_info_item_t *vg_item, char *log_buf); status_t wr_process_redo_log(wr_session_t *session, wr_vg_info_item_t *vg_item); status_t wr_reset_log_slot_head(uint32 vg_id, char *log_buf); void wr_rollback_mem_update(wr_session_t *session, wr_vg_info_item_t *vg_item); void rb_redo_clean_resource( wr_session_t *session, wr_vg_info_item_t *item, auid_t auid, ga_pool_id_e pool_id, uint32 first, uint32 count); -status_t wr_update_redo_info(wr_vg_info_item_t *vg_item, char *log_buf); -void wr_print_redo_entry(wr_redo_entry_t *entry); #ifdef __cplusplus } diff --git a/src/common/wr_args_parse.c b/src/common/wr_args_parse.c index 49eceee2d8adf3ac5e82572f62ad860538877878..02723deeb1d50e2285b3c19bbcf4d96418043996 100644 --- a/src/common/wr_args_parse.c +++ b/src/common/wr_args_parse.c @@ -319,17 +319,6 @@ status_t set_config_info(char *home, wr_config_t *inst_cfg) return CM_SUCCESS; } -status_t wr_get_vg_item(wr_vg_info_item_t **vg_item, const char *vg_name) -{ - wr_vg_info_item_t *tmp_vg_item = wr_find_vg_item(vg_name); - if (tmp_vg_item == NULL) { - LOG_DEBUG_ERR("vg_name %s is not exist.\n", vg_name); - return CM_ERROR; - } - *vg_item = tmp_vg_item; - return CM_SUCCESS; -} - config_item_t g_wr_admin_parameters[] = { // name (30B) isdefault readonly defaultvalue value runtime_value description range datatype // comment diff --git a/src/common/wr_args_parse.h b/src/common/wr_args_parse.h index d18731cc18f747bd06c6d60b147fd68dc45d3a90..c15f0aeeb612980e89e011d2b1eb9c12b5ef9607 100644 --- a/src/common/wr_args_parse.h +++ b/src/common/wr_args_parse.h @@ -91,7 +91,6 @@ status_t cmd_check_convert_wr_home(const char *input_args, void **convert_result status_t cmd_realpath_home(const char *input_args, char **convert_result, int *convert_size); void cmd_clean_check_convert(char *convert_result, int convert_size); status_t set_config_info(char *home, wr_config_t *inst_cfg); -status_t wr_get_vg_item(wr_vg_info_item_t **vg_item, const char *vg_name); status_t wr_check_meta_type(const char *type); status_t wr_check_meta_id(const char *intput); status_t cmd_parse_check(wr_args_t *cmd_args_set, int set_size); diff --git a/src/common/wr_file.c b/src/common/wr_file.c index f5468e318e3eb299a9033bec182e1882c5509aa8..1ce18279f02591a237f2ce90d60cedfca89522d6 100644 --- a/src/common/wr_file.c +++ b/src/common/wr_file.c @@ -247,36 +247,12 @@ status_t wr_find_vg_by_dir(const char *dir_path, char *name, wr_vg_info_item_t * return CM_SUCCESS; } -void wr_lock_vg_mem_s_and_shm_x(wr_session_t *session, wr_vg_info_item_t *vg_item) -{ - wr_lock_vg_mem_s(vg_item); - wr_enter_shm_x(session, vg_item); -} - void wr_lock_vg_mem_and_shm_x(wr_session_t *session, wr_vg_info_item_t *vg_item) { wr_lock_vg_mem_x(vg_item); wr_enter_shm_x(session, vg_item); } -void wr_lock_vg_mem_and_shm_x2ix(wr_session_t *session, wr_vg_info_item_t *vg_item) -{ - wr_lock_shm_meta_x2ix(session, vg_item->vg_latch); - wr_lock_vg_mem_x2ix(vg_item); -} - -void wr_lock_vg_mem_and_shm_ix2x(wr_session_t *session, wr_vg_info_item_t *vg_item) -{ - wr_lock_vg_mem_ix2x(vg_item); - wr_lock_shm_meta_ix2x(session, vg_item->vg_latch); -} - -void wr_lock_vg_mem_and_shm_degrade(wr_session_t *session, wr_vg_info_item_t *vg_item) -{ - wr_lock_vg_mem_degrade(vg_item); - wr_lock_shm_meta_degrade(session, vg_item->vg_latch); -} - void wr_lock_vg_mem_and_shm_s(wr_session_t *session, wr_vg_info_item_t *vg_item) { wr_lock_vg_mem_s(vg_item); @@ -295,22 +271,6 @@ void wr_unlock_vg_mem_and_shm(wr_session_t *session, wr_vg_info_item_t *vg_item) wr_unlock_vg_mem(vg_item); } -void wr_lock_vg_mem_and_shm_ex_s(wr_session_t *session, char *vg_name) -{ - wr_vg_info_item_t *vg_item = wr_find_vg_item(vg_name); - if (vg_item != NULL) { - wr_lock_vg_mem_and_shm_s_force(session, vg_item); - } -} - -void wr_unlock_vg_mem_and_shm_ex(wr_session_t *session, char *vg_name) -{ - wr_vg_info_item_t *vg_item = wr_find_vg_item(vg_name); - if (vg_item != NULL) { - wr_unlock_vg_mem_and_shm(session, vg_item); - } -} - static status_t wr_exist_item_core( wr_session_t *session, const char *dir_path, bool32 *result, gft_item_type_t *output_type) { @@ -333,31 +293,6 @@ void wr_close_dir(wr_session_t *session, char *vg_name, uint64 ftid) return; } -int64 wr_get_fs_block_offset(wr_vg_info_item_t *vg_item, wr_block_id_t blockid) -{ - return wr_get_block_offset(vg_item, WR_FILE_SPACE_BLOCK_SIZE, blockid.block, blockid.au); -} - -void wr_init_fs_block_head(wr_fs_block_t *fs_block) -{ - CM_ASSERT(fs_block != NULL); - wr_set_blockid(&fs_block->head.next, CM_INVALID_ID64); - fs_block->head.used_num = 0; - wr_set_blockid(&fs_block->bitmap[0], CM_INVALID_ID64); -} - -status_t wr_alloc_fs_block_inter(wr_session_t *session, wr_vg_info_item_t *vg_item, bool32 check_version, - char **block, wr_alloc_fs_block_info_t *info) -{ - return CM_SUCCESS; -} - -status_t wr_alloc_fs_block( - wr_session_t *session, wr_vg_info_item_t *vg_item, char **block, wr_alloc_fs_block_info_t *info) -{ - return CM_SUCCESS; -} - status_t wr_exist_item(wr_session_t *session, const char *item, bool32 *result, gft_item_type_t *output_type) { CM_ASSERT(item != NULL); @@ -387,99 +322,6 @@ status_t wr_exist_item(wr_session_t *session, const char *item, bool32 *result, return status; } -static void wr_get_dir_path(char *dir_path, uint32 buf_size, const char *full_path) -{ - char *p = NULL; - size_t path_len = strlen(full_path); - errno_t ret = strncpy_s(dir_path, buf_size, full_path, path_len); - if (ret != EOK) { - WR_THROW_ERROR(ERR_SYSTEM_CALL, (ret)); - return; - } - p = strrchr(dir_path, '/'); - if (p == NULL) { - return; - } - *p = '\0'; -} - -static uint32_t wr_get_last_delimiter(const char *path, char delimiter) -{ - uint32_t len = (uint32_t)strlen(path); - for (uint32_t i = len - 1; i > 0; i--) { - if (path[i] == delimiter) { - return i; - } - } - return len; -} - -static status_t wr_check_node_delete(gft_node_t *node) -{ - if ((node->flags & WR_FT_NODE_FLAG_DEL) == 0) { - return CM_SUCCESS; - } - WR_THROW_ERROR(ERR_WR_FILE_NOT_EXIST, node->name, "wr"); - LOG_DEBUG_ERR("The file node:%s is deleted", node->name); - return CM_ERROR; -} - -gft_node_t *wr_get_gft_node_by_path( - wr_session_t *session, wr_vg_info_item_t *vg_item, const char *path, wr_vg_info_item_t **dir_vg_item) -{ - gft_node_t *parent_node = NULL; - gft_node_t *node = NULL; - status_t status = CM_ERROR; - char name[WR_MAX_NAME_LEN]; - char dir_path[WR_FILE_PATH_MAX_LENGTH]; - do { - WR_BREAK_IF_ERROR(wr_check_file(vg_item)); - wr_get_dir_path(dir_path, WR_FILE_PATH_MAX_LENGTH, path); - *dir_vg_item = vg_item; - wr_check_dir_output_t output_info = {&parent_node, dir_vg_item, NULL, CM_FALSE}; - status = wr_check_dir(session, dir_path, GFT_PATH, &output_info, CM_TRUE); - WR_BREAK_IF_ERROR(status); - uint32_t pos = wr_get_last_delimiter(path, '/'); - status = wr_get_name_from_path(path, &pos, name); - WR_BREAK_IF_ERROR(status); - if (name[0] == 0) { - LOG_DEBUG_INF("get root node ftid"); - return parent_node; - } - node = wr_find_ft_node(session, *dir_vg_item, parent_node, name, CM_TRUE); - if (node == NULL) { - status = CM_ERROR; - WR_BREAK_IFERR3( - status, WR_THROW_ERROR(ERR_WR_FILE_NOT_EXIST, name, path), LOG_DEBUG_ERR("path:%s not exist", path)); - } - WR_BREAK_IF_ERROR(wr_check_node_delete(node)); - LOG_DEBUG_INF("Success to get ft_node:%s by path:%s", wr_display_metaid(node->id), path); - status = CM_SUCCESS; - } while (0); - if (status == CM_SUCCESS) { - return node; - } - return NULL; -} - -status_t wr_get_ftid_by_path(wr_session_t *session, const char *path, ftid_t *ftid, wr_vg_info_item_t **dir_vg_item) -{ - CM_ASSERT(path != NULL); - wr_vg_info_item_t *vg_item = NULL; - char name[WR_MAX_NAME_LEN]; - CM_RETURN_IFERR(wr_find_vg_by_dir(path, name, &vg_item)); - wr_lock_vg_mem_and_shm_s(session, vg_item); - status_t status = CM_ERROR; - gft_node_t *node = wr_get_gft_node_by_path(session, vg_item, path, dir_vg_item); - if (node != NULL) { - *ftid = node->id; - LOG_DEBUG_INF("Success to get ftid:%s by path:%s", wr_display_metaid(*ftid), path); - status = CM_SUCCESS; - } - wr_unlock_vg_mem_and_shm(session, vg_item); - return status; -} - status_t wr_check_file(wr_vg_info_item_t *vg_item) { status_t status = wr_check_refresh_ft(vg_item); @@ -599,79 +441,6 @@ status_t wr_check_rm_file( return CM_SUCCESS; } -static void wr_init_ft_node( - wr_ft_block_t *ft_block, gft_node_t *first_node, gft_root_t *gft, uint32_t block_id, auid_t auid) -{ - gft_node_t *node; - for (uint32 i = 0; i < ft_block->node_num; i++) { - node = &first_node[i]; - if (i != 0) { - node->prev = auid; - node->prev.block = block_id; - node->prev.item = (uint16)i - 1; - } - node->id = auid; - node->id.block = block_id; - node->id.item = i; - wr_set_auid(&node->parent, WR_BLOCK_ID_INIT); - - if (i == ft_block->node_num - 1) { - gft->free_list.last = auid; - gft->free_list.last.block = block_id; - gft->free_list.last.item = i; - wr_set_auid(&node->next, WR_INVALID_64); - } else { - node->next = auid; - node->next.block = block_id; - node->next.item = (uint16)i + 1; - } - } -} - -status_t wr_init_ft_block( - wr_session_t *session, wr_vg_info_item_t *vg_item, char *block, uint32_t block_id, auid_t auid) -{ - char *root = vg_item->wr_ctrl->root; - gft_root_t *gft = &((wr_root_ft_block_t *)(root))->ft_root; - - wr_ft_block_t *ft_block = (wr_ft_block_t *)block; - ft_block->node_num = (WR_BLOCK_SIZE - sizeof(wr_ft_block_t)) / sizeof(gft_node_t); - ft_block->common.id = auid; - ft_block->common.id.block = block_id; - ft_block->common.type = WR_BLOCK_TYPE_FT; - ft_block->common.flags = WR_BLOCK_FLAG_FREE; - - gft_node_t *first_node = (gft_node_t *)(block + sizeof(wr_ft_block_t)); - gft_node_t *node; - gft_node_t *last_node = NULL; - if (ft_block->node_num > 0) { - node = &first_node[0]; - node->prev = gft->free_list.last; - bool32 cmp = wr_cmp_auid(gft->free_list.last, WR_INVALID_64); - if (!cmp) { - last_node = wr_get_ft_node_by_ftid(session, vg_item, gft->free_list.last, CM_FALSE, CM_FALSE); - if (last_node == NULL) { - LOG_DEBUG_ERR( - "[FT][FORMAT] Failed to get file table node:%s.", wr_display_metaid(gft->free_list.last)); - return CM_ERROR; - } - - last_node->next = auid; - last_node->next.block = block_id; - last_node->next.item = 0; - } - } - wr_init_ft_node(ft_block, first_node, gft, block_id, auid); - gft->free_list.count = gft->free_list.count + ft_block->node_num; - if (wr_cmp_auid(gft->free_list.first, WR_INVALID_64)) { - gft->free_list.first = auid; - gft->free_list.first.block = block_id; - gft->free_list.first.item = 0; - } - WR_LOG_DEBUG_OP("[FT][FORMAT] wr_init_ft_block blockid:%s.", wr_display_metaid(ft_block->common.id)); - return CM_SUCCESS; -} - void wr_init_bitmap_block(wr_ctrl_t *wr_ctrl, char *block, uint32_t block_id, auid_t auid) { wr_fs_block_root_t *block_root = WR_GET_FS_BLOCK_ROOT(wr_ctrl); @@ -734,94 +503,8 @@ status_t wr_update_au_disk( return CM_SUCCESS; } -status_t wr_format_ft_node_core( - wr_session_t *session, wr_vg_info_item_t *vg_item, ga_queue_t queue, auid_t auid, gft_root_t *gft) -{ - status_t status = CM_SUCCESS; - uint32 rollback_count = 0; - uint32 block_num = (uint32)WR_GET_FT_BLOCK_NUM_IN_AU(vg_item->wr_ctrl); - uint32 obj_id = queue.first; - ga_obj_id_t ga_obj_id = {.pool_id = GA_8K_POOL, .obj_id = 0}; - gft_list_t bk_list = gft->free_list; - wr_ft_block_t *block = (wr_ft_block_t *)wr_get_ft_block_by_ftid(session, vg_item, gft->last); - CM_ASSERT(block != NULL); - block->next = auid; - for (uint32 i = 0; i < block_num; i++) { - block = (wr_ft_block_t *)wr_buffer_get_meta_addr(GA_8K_POOL, obj_id); - errno_t err = memset_sp((char *)block, WR_BLOCK_SIZE, 0, WR_BLOCK_SIZE); - cm_panic(err == EOK); - block->common.id = auid; - block->common.id.block = i; - if (i != block_num - 1) { - block->next = auid; - block->next.block = i + 1; - } else { - wr_set_blockid(&block->next, CM_INVALID_ID64); - } - gft->last = block->common.id; - - ga_obj_id.obj_id = obj_id; - do { - status = wr_register_buffer_cache( - session, vg_item, block->common.id, ga_obj_id, (char *)block, WR_BLOCK_TYPE_FT); - if (status != CM_SUCCESS) { - rollback_count = i; - WR_BREAK_IFERR2(status, - LOG_DEBUG_ERR("[FT][FORMAT] Failed to register block:%s.", wr_display_metaid(block->common.id))); - } - - status = wr_init_ft_block(session, vg_item, (char *)block, i, auid); - if (status != CM_SUCCESS) { - rollback_count = i + 1; - WR_BREAK_IFERR2(status, - LOG_DEBUG_ERR("[FT][FORMAT] Failed to initialize block:%s.", wr_display_metaid(block->common.id))); - } - } while (0); - if (status != CM_SUCCESS) { - for (uint32 j = 0; j < rollback_count; ++j) { - wr_block_id_t block_id = auid; - block_id.block = j; - wr_unregister_buffer_cache(session, vg_item, block_id); - } - ga_free_object_list(GA_8K_POOL, &queue); - gft->free_list = bk_list; // rollback free_list - LOG_DEBUG_ERR("[FT][FORMAT] Rollback the format ft node when fail, i:%u.", i); - return status; - } - - obj_id = ga_next_object(GA_8K_POOL, obj_id); - } - return CM_SUCCESS; -} - status_t wr_format_ft_node(wr_session_t *session, wr_vg_info_item_t *vg_item, auid_t auid) { - CM_ASSERT(vg_item != NULL); - wr_ctrl_t *wr_ctrl = vg_item->wr_ctrl; - char *root = wr_ctrl->root; - wr_root_ft_block_t *ft_block = (wr_root_ft_block_t *)(root); - gft_root_t *gft = &ft_block->ft_root; - status_t status = CM_SUCCESS; - - gft_list_t bk_list = gft->free_list; - uint32 block_num = (uint32)WR_GET_FT_BLOCK_NUM_IN_AU(wr_ctrl); - ga_queue_t queue; - status = ga_alloc_object_list(GA_8K_POOL, block_num, &queue); - WR_RETURN_IFERR2(status, LOG_DEBUG_ERR("[FT][FORMAT] Failed to alloc object list, block_num:%u.", block_num)); - - wr_block_id_t old_last = gft->last; - status = wr_format_ft_node_core(session, vg_item, queue, auid, gft); - if (status != CM_SUCCESS) { - return status; - } - - wr_redo_format_ft_t redo; - redo.auid = auid; - redo.obj_id = queue.first; - redo.count = block_num; - redo.old_last_block = old_last; - redo.old_free_list = bk_list; - wr_put_log(session, vg_item, WR_RT_FORMAT_AU_FILE_TABLE, &redo, sizeof(wr_redo_format_ft_t)); return CM_SUCCESS; } @@ -866,487 +549,6 @@ status_t wr_format_bitmap_node(wr_session_t *session, wr_vg_info_item_t *vg_item return CM_SUCCESS; } -static void format_ft_block_when_create_vg( - wr_vg_info_item_t *vg_item, gft_list_t *plist, wr_ft_block_t *block, uint32 index, auid_t auid) -{ - uint32 blk_count = (uint32)WR_GET_FT_BLOCK_NUM_IN_AU(vg_item->wr_ctrl); - uint32 item_count = (WR_BLOCK_SIZE - sizeof(wr_ft_block_t)) / sizeof(gft_node_t); - gft_node_t *node = NULL; - - block->common.type = WR_BLOCK_TYPE_FT; - block->common.flags = WR_BLOCK_FLAG_FREE; - block->node_num = item_count; - - for (uint32 j = 0; j < item_count; j++) { - node = (gft_node_t *)((char *)block + sizeof(wr_ft_block_t) + sizeof(gft_node_t) * j); - node->id = auid; - node->id.block = index; - node->id.item = j; - wr_set_auid(&node->parent, WR_BLOCK_ID_INIT); - - // set the prev ftid_t - if (j == 0) { - if (index == 0) { - *(uint64 *)(&node->prev) = WR_INVALID_64; - } else { - // the prev ft block - node->prev = auid; - node->prev.block = index - 1; - node->prev.item = item_count - 1; - } - } else { - // the same ft block - node->prev = auid; - node->prev.block = index; - node->prev.item = j - 1; - } - - // set the next ftid_t - if (j == item_count - 1) { - if (index == blk_count - 1) { - *(uint64 *)(&node->next) = WR_INVALID_64; - } else { - // the next ft block - node->next = auid; - node->next.block = index + 1; - node->next.item = 0; - } - } else { - // the same ft block - node->next = auid; - node->next.block = index; - node->next.item = j + 1; - } - - // add to gft node free list - if (*(uint64 *)(&plist->first) == WR_INVALID_64) { - plist->first = node->id; - } - plist->last = node->id; - plist->count++; - } -} - -/* - * NOTE: this function is used only in creating vg. - * you can't use block memory cache and must flush block to disk manually. - */ -static status_t format_ft_au_when_create_vg(wr_vg_info_item_t *vg_item, auid_t auid) -{ - LOG_DEBUG_INF("[FT][FORMAT] Begin to format ft au when create vg."); - status_t status; - wr_ctrl_t *wr_ctrl = vg_item->wr_ctrl; - uint64 au_size = wr_get_vg_au_size(wr_ctrl); - char *au_buf = (char *)cm_malloc_align(WR_DISK_UNIT_SIZE, (uint32)au_size); - if (au_buf == NULL) { - WR_RETURN_IFERR2(CM_ERROR, LOG_DEBUG_ERR("[FT][FORMAT] Failed to alloc %d memory", (int32)au_size)); - } - int64 offset; - wr_ft_block_t *block = NULL; - errno_t err = memset_sp(au_buf, au_size, 0, au_size); - if (err != EOK) { - free(au_buf); - LOG_DEBUG_ERR("[FT][FORMAT] Failed to memset:%d", err); - return CM_ERROR; - } - - uint32 blk_count = (uint32)WR_GET_FT_BLOCK_NUM_IN_AU(wr_ctrl); - - gft_list_t new_list; - new_list.count = 0; - *(uint64 *)&new_list.first = WR_INVALID_64; - *(uint64 *)&new_list.last = WR_INVALID_64; - - for (uint32 i = 0; i < blk_count; i++) { - block = (wr_ft_block_t *)(au_buf + (i * WR_BLOCK_SIZE)); - block->common.id = auid; - block->common.id.block = i; - - // set ft block next - if (i == blk_count - 1) { - *(uint64 *)(&block->next) = WR_INVALID_64; - } else { - block->next = auid; - block->next.block = i + 1; - } - format_ft_block_when_create_vg(vg_item, &new_list, block, i, auid); - block->common.version++; - block->common.checksum = wr_get_checksum(block, WR_BLOCK_SIZE); - } - - wr_root_ft_block_t *root_ft = WR_GET_ROOT_BLOCK(wr_ctrl); - gft_root_t *root_gft = &root_ft->ft_root; - root_ft->ft_block.next = ((wr_ft_block_t *)au_buf)->common.id; // first block - root_gft->last = ((wr_ft_block_t *)(au_buf + au_size - WR_BLOCK_SIZE))->common.id; // last block - - // link the gft_node and free_list - root_gft->free_list = new_list; - // flush ft block to disk manually - block = (wr_ft_block_t *)(au_buf); - offset = wr_get_ft_block_offset(vg_item, block->common.id); - status = wr_check_write_volume(vg_item, block->common.id.volume, offset, au_buf, (uint32)au_size); - if (status != CM_SUCCESS) { - LOG_DEBUG_ERR("[FT][FORMAT] Failed to check write volume."); - free(au_buf); - return status; - } - status = wr_update_ft_root(vg_item); - free(au_buf); - return status; -} - -status_t wr_alloc_ft_au(wr_session_t *session, wr_vg_info_item_t *vg_item, ftid_t *id) -{ - CM_ASSERT(vg_item != NULL); - CM_ASSERT(id != NULL); - status_t status; - - status = wr_alloc_au(session, vg_item, id); - WR_RETURN_IFERR2( - status, LOG_DEBUG_ERR("[FT][ALLOC] Failed allocate au for file table from vg:%s.", vg_item->vg_name)); - - wr_au_root_t *au_root = WR_GET_AU_ROOT(vg_item->wr_ctrl); - if (au_root->free_root == WR_INVALID_64) { - /* when we are creating vg, .recycle directory hasn't been initialized yet! */ - status = format_ft_au_when_create_vg(vg_item, *(auid_t *)id); - } else { - CM_ASSERT(session != NULL); - status = wr_format_ft_node(session, vg_item, *id); - } - - WR_RETURN_IFERR2(status, - LOG_DEBUG_ERR("[FT][ALLOC] Failed format ft au:%s from vg:%s.", wr_display_metaid(*id), vg_item->vg_name)); - LOG_DEBUG_INF("[FT][ALLOC] Succeed to allocate ft au:%s from vg:%s.", wr_display_metaid(*id), vg_item->vg_name); - return status; -} - -static void wr_init_alloc_ft_node(gft_root_t *gft, gft_node_t *node, uint32 flags, gft_node_t *parent_node) -{ - node->create_time = cm_current_time(); - node->update_time = node->create_time; - (void)cm_atomic_set(&node->size, 0); - node->written_size = 0; - node->min_inited_size = 0; - node->prev = parent_node->items.last; - node->fid = gft->fid++; - node->flags = flags; -#ifdef WR_DEFAULT_FILE_FLAG_INNER_INITED - if (node->type == GFT_FILE) { - node->flags |= WR_FT_NODE_FLAG_INNER_INITED; - } -#endif - node->parent = parent_node->id; - wr_set_auid(&node->next, CM_INVALID_ID64); - - wr_block_ctrl_t *block_ctrl = wr_get_block_ctrl_by_node(node); - if (node->type == GFT_FILE && block_ctrl != NULL) { - wr_init_wr_fs_block_cache_info(&block_ctrl->fs_block_cache_info); - } -} - -void wr_set_ft_node(wr_session_t *session, wr_vg_info_item_t *vg_item, gft_node_t *parent_node, gft_node_t *node, - gft_root_t *gft, gft_node_t *prev_node) -{ - wr_redo_alloc_ft_node_t redo_node; - redo_node.node[WR_REDO_ALLOC_FT_NODE_SELF_INDEX] = *node; - if (prev_node != NULL) { - redo_node.node[WR_REDO_ALLOC_FT_NODE_PREV_INDEX] = *prev_node; - } else { - wr_set_auid(&redo_node.node[WR_REDO_ALLOC_FT_NODE_PREV_INDEX].id, WR_INVALID_64); - } - redo_node.node[WR_REDO_ALLOC_FT_NODE_PARENT_INDEX] = *parent_node; - - redo_node.ft_root = *gft; - wr_put_log(session, vg_item, WR_RT_ALLOC_FILE_TABLE_NODE, &redo_node, sizeof(wr_redo_alloc_ft_node_t)); - char *prev_name; - if (prev_node) { - prev_name = prev_node->name; - } else { - prev_name = "NULL"; - } - WR_LOG_DEBUG_OP("[FT] Alloc ft node, type:%u, name:%s, prev name:%s, %s, free count:%u.", node->type, node->name, - prev_name, wr_display_metaid(node->id), gft->free_list.count); -} - -void wr_ft_node_link_list(wr_session_t *session, wr_vg_info_item_t *vg_item, gft_node_t *parent_node, ftid_t id, - gft_node_t *node, gft_root_t *gft) -{ - gft_node_t *prev_node = NULL; - bool32 cmp = wr_cmp_auid(parent_node->items.last, CM_INVALID_ID64); - if (!cmp) { - /* - * when current thread modify prev_node's next pointer, - * another thread may be modify prev_node's size by extend space - * so here we need file lock to avoid concurrency scenario. - */ - prev_node = wr_get_ft_node_by_ftid(session, vg_item, parent_node->items.last, CM_TRUE, CM_FALSE); - if (prev_node != NULL) { - prev_node->next = id; - } - } - - parent_node->items.count++; - parent_node->items.last = id; - cmp = wr_cmp_auid(parent_node->items.first, CM_INVALID_ID64); - if (cmp) { - parent_node->items.first = id; - } - - wr_set_ft_node(session, vg_item, parent_node, node, gft, prev_node); -} - -/* - * NOTE: this function is called only in creating vg. - * because there is no block buffer for use, you can't call wr_find_block_in_mem - * or ga_alloc_object_list, redo log etc. You must flush buffer to disk manually. - */ -status_t wr_alloc_ft_node_when_create_vg( - wr_vg_info_item_t *vg_item, gft_node_t *parent_node, const char *name, gft_item_type_t type, uint32 flags) -{ - CM_ASSERT(vg_item != NULL); - CM_ASSERT(parent_node != NULL); - CM_ASSERT(name != NULL); - /* parent_node must be the root directory */ - CM_ASSERT(parent_node->id.au == 0 && parent_node->id.block == 0 && parent_node->id.item == 0); - - status_t status; - ftid_t id; - wr_ctrl_t *wr_ctrl = vg_item->wr_ctrl; - char *root = wr_ctrl->root; - wr_root_ft_block_t *ft_block = (wr_root_ft_block_t *)(root); - gft_root_t *gft = &ft_block->ft_root; - if (gft->free_list.count == 0) { - status = wr_alloc_ft_au(NULL, vg_item, &id); - if (status != CM_SUCCESS) { - LOG_RUN_ERR("[FT][ALLOC] Failed to allocate au when allocating file table node."); - return status; - } - LOG_RUN_INF("[FT][ALLOC] Succeed to allocate au:%s when allocating file table node.", wr_display_metaid(id)); - } - - id = gft->free_list.first; - char *buf = (char *)cm_malloc_align(WR_DISK_UNIT_SIZE, WR_BLOCK_SIZE); - if (buf == NULL) { - LOG_RUN_ERR("[FT][ALLOC] Failed to allocate buf."); - return CM_ERROR; - } - - /* read ft block from disk, because there's no cache in hands */ - wr_block_id_t block_id = id; - block_id.item = 0; - int64 offset = wr_get_block_offset(vg_item, WR_BLOCK_SIZE, block_id.block, block_id.au); - if (wr_get_block_from_disk(vg_item, block_id, buf, offset, WR_BLOCK_SIZE, CM_TRUE) != CM_SUCCESS) { - WR_FREE_POINT(buf); - LOG_RUN_ERR("[FT][ALLOC] Failed to load ft block %s.", wr_display_metaid(block_id)); - return CM_ERROR; - } - gft_node_t *node = (gft_node_t *)(buf + sizeof(wr_ft_block_t) + sizeof(gft_node_t) * id.item); - gft->free_list.first = node->next; - bool32 cmp = wr_cmp_auid(gft->free_list.first, CM_INVALID_ID64); - if (cmp) { - gft->free_list.last = gft->free_list.first; - } - gft->free_list.count--; - node->type = type; - node->parent = parent_node->id; - if (type == GFT_PATH) { - node->items.count = 0; - wr_set_auid(&node->items.first, CM_INVALID_ID64); - wr_set_auid(&node->items.last, CM_INVALID_ID64); - } else { - /* file or link */ - wr_set_blockid(&node->entry, CM_INVALID_ID64); - } - if (strcpy_s(node->name, sizeof(node->name), name) != EOK) { - cm_panic(0); - } - wr_init_alloc_ft_node(gft, node, flags, parent_node); - parent_node->items.first = node->id; - parent_node->items.last = node->id; - parent_node->items.count = 1; - ((wr_ft_block_t *)buf)->common.flags = WR_BLOCK_FLAG_USED; - do { - /* flush ft block to disk manually */ - status = wr_update_ft_block_disk(vg_item, (wr_ft_block_t *)buf, id); - WR_BREAK_IF_ERROR(status); - status = wr_update_ft_root(vg_item); // parent_node must be root directory like `+data` - } while (0); - if (status == CM_SUCCESS) { - LOG_RUN_INF("Succeed to create recycle file, node id is %s.", wr_display_metaid(node->id)); - } - WR_FREE_POINT(buf); - return status; -} - -status_t wr_alloc_ft_au_when_no_free( - wr_session_t *session, wr_vg_info_item_t *vg_item, gft_root_t *gft, bool32 *check_version) -{ - if (gft->free_list.count == 0) { - LOG_DEBUG_INF("[FT][ALLOC] There is no free au, begin to allocate au in vg:%s", vg_item->vg_name); - ftid_t id; - status_t status = wr_alloc_ft_au(session, vg_item, &id); - WR_RETURN_IFERR2(status, LOG_DEBUG_ERR("[FT][ALLOC] Failed to allocate au when allocating file table node.")); - *check_version = CM_FALSE; - WR_LOG_DEBUG_OP( - "[FT][ALLOC] Succeed to allocate au:%s when allocating file table node, ", wr_display_metaid(id)); - } - return CM_SUCCESS; -} - -static void wr_get_prev_and_next_node(wr_session_t *session, wr_vg_info_item_t *vg_item, gft_node_t *parent_node, - gft_node_t *node, gft_block_info_t *prev_info, gft_block_info_t *next_info) -{ - node->update_time = cm_current_time(); - if (*(uint64 *)(&parent_node->items.first) == *(uint64 *)(&node->id)) { - parent_node->items.first = node->next; - bool32 cmp = wr_cmp_blockid(parent_node->items.first, CM_INVALID_ID64); - if (cmp) { - CM_ASSERT(parent_node->items.count == 1); - parent_node->items.last = parent_node->items.first; - } else { - next_info->ft_node = wr_get_ft_node_by_ftid(session, vg_item, parent_node->items.first, CM_TRUE, CM_FALSE); - CM_ASSERT(next_info->ft_node != NULL); - wr_set_blockid(&next_info->ft_node->prev, CM_INVALID_ID64); - } - } else if (*(uint64 *)(&parent_node->items.last) == *(uint64 *)(&node->id)) { - parent_node->items.last = node->prev; - prev_info->ft_node = wr_get_ft_node_by_ftid(session, vg_item, parent_node->items.last, CM_TRUE, CM_FALSE); - CM_ASSERT(prev_info->ft_node != NULL); - wr_set_blockid(&prev_info->ft_node->next, CM_INVALID_ID64); - } else { - prev_info->ft_node = wr_get_ft_node_by_ftid(session, vg_item, node->prev, CM_TRUE, CM_FALSE); - CM_ASSERT(prev_info->ft_node != NULL); - prev_info->ft_node->next = node->next; - next_info->ft_node = wr_get_ft_node_by_ftid(session, vg_item, node->next, CM_TRUE, CM_FALSE); - CM_ASSERT(next_info->ft_node != NULL); - next_info->ft_node->prev = node->prev; - } - parent_node->items.count--; -} - -void wr_free_ft_node_inner( - wr_session_t *session, wr_vg_info_item_t *vg_item, gft_node_t *parent_node, gft_node_t *node, bool32 real_del) -{ - CM_ASSERT(vg_item != NULL); - CM_ASSERT(parent_node != NULL); - CM_ASSERT(node != NULL); - gft_block_info_t prev_info = {0}; - gft_block_info_t next_info = {0}; - node->update_time = cm_current_time(); - wr_get_prev_and_next_node(session, vg_item, parent_node, node, &prev_info, &next_info); - - wr_ctrl_t *wr_ctrl = vg_item->wr_ctrl; - char *root = wr_ctrl->root; - wr_root_ft_block_t *ft_block = (wr_root_ft_block_t *)(root); - gft_root_t *gft = &ft_block->ft_root; - if (real_del) { - wr_ft_block_t *block = wr_get_ft_by_node(node); - block->common.flags = WR_BLOCK_FLAG_FREE; - node->next = gft->free_list.first; - wr_set_blockid(&node->parent, WR_BLOCK_ID_INIT); - wr_set_blockid(&node->prev, WR_INVALID_64); - wr_set_blockid(&node->entry, WR_INVALID_64); - gft->free_list.first = node->id; - gft->free_list.count++; - } - - wr_redo_free_ft_node_t redo_node; - redo_node.node[WR_REDO_FREE_FT_NODE_PARENT_INDEX] = *parent_node; - if (prev_info.ft_node != NULL) { - redo_node.node[WR_REDO_FREE_FT_NODE_PREV_INDEX] = *prev_info.ft_node; - WR_LOG_DEBUG_OP("Free ft node, prev_node name:%s, prev_node id:%s.", prev_info.ft_node->name, - wr_display_metaid(prev_info.ft_node->id)); - } else { - wr_set_auid(&redo_node.node[WR_REDO_FREE_FT_NODE_PREV_INDEX].id, CM_INVALID_ID64); - } - if (next_info.ft_node != NULL) { - redo_node.node[WR_REDO_FREE_FT_NODE_NEXT_INDEX] = *next_info.ft_node; - WR_LOG_DEBUG_OP("Free ft node, next_node name:%s, next_node id:%s.", next_info.ft_node->name, - wr_display_metaid(next_info.ft_node->id)); - } else { - wr_set_auid(&redo_node.node[WR_REDO_FREE_FT_NODE_NEXT_INDEX].id, CM_INVALID_ID64); - } - redo_node.node[WR_REDO_FREE_FT_NODE_SELF_INDEX] = *node; - redo_node.ft_root = *gft; - wr_put_log(session, vg_item, WR_RT_FREE_FILE_TABLE_NODE, &redo_node, sizeof(wr_redo_free_ft_node_t)); - WR_LOG_DEBUG_OP("[FT][FREE] Free ft node, name:%s, %s, free count:%u, real delete:%u", node->name, - wr_display_metaid(node->id), gft->free_list.count, real_del); -} - -// remove ftn from parent -void wr_free_ft_node( - wr_session_t *session, wr_vg_info_item_t *vg_item, gft_node_t *parent_node, gft_node_t *node, bool32 real_del) -{ - CM_ASSERT(vg_item != NULL); - CM_ASSERT(parent_node != NULL); - CM_ASSERT(node != NULL); - wr_free_ft_node_inner(session, vg_item, parent_node, node, real_del); -} - -gft_node_t *wr_find_ft_node_core( - wr_session_t *session, wr_vg_info_item_t *vg_item, gft_node_t *parent_node, const char *name, bool32 skip_del) -{ - bool32 check_version = wr_is_server(); - ftid_t id = parent_node->items.first; - - for (uint32 i = 0; i < parent_node->items.count; i++) { - if (wr_cmp_blockid(id, CM_INVALID_ID64)) { - // may be find uncommitted node when standby - LOG_DEBUG_ERR("Get invalid id in parent name:%s, %s, count:%u, when find node name:%s, index:%u.", - parent_node->name, wr_display_metaid(parent_node->id), parent_node->items.count, name, i); - return NULL; - } - gft_node_t *node = wr_get_ft_node_by_ftid(session, vg_item, id, check_version, CM_FALSE); - if (node == NULL) { - LOG_DEBUG_ERR( - "Can not get node:%s, File name %s type:%u.", wr_display_metaid(id), name, parent_node->type); - return NULL; - } - if (skip_del && (node->flags & WR_FT_NODE_FLAG_DEL)) { - id = node->next; - LOG_DEBUG_INF("Skip del the node, next node:%s", wr_display_metaid(id)); - continue; - } - if (strcmp(node->name, name) == 0) { - return node; - } - - id = node->next; - } - return NULL; -} - -gft_node_t *wr_find_ft_node( - wr_session_t *session, wr_vg_info_item_t *vg_item, gft_node_t *parent_node, const char *name, bool8 skip_del) -{ - CM_ASSERT(name != NULL); - ftid_t id; - if (parent_node == NULL) { - memset_s(&id, sizeof(id), 0, sizeof(id)); - return wr_get_ft_node_by_ftid(session, vg_item, id, wr_is_server(), CM_FALSE); - } - - if (parent_node->type != GFT_PATH) { - LOG_DEBUG_ERR("File name %s, its parent's type:%u is invalid.", name, parent_node->type); - return NULL; - } - - if (parent_node->items.count == 0) { - LOG_DEBUG_INF("File name %s, its parent's sub item count:%u.", name, parent_node->items.count); - return NULL; - } - timeval_t begin_tv; - wr_begin_stat(&begin_tv); - gft_node_t *node = wr_find_ft_node_core(session, vg_item, parent_node, name, skip_del); - wr_session_end_stat(session, &begin_tv, WR_FIND_FT_ON_SERVER); - if (node != NULL) { - return node; - } - - LOG_DEBUG_INF("File name %s, its parent's sub item count:%u.", name, parent_node->items.count); - return NULL; -} - status_t wr_refresh_root_ft_inner(wr_vg_info_item_t *vg_item) { bool32 remote = CM_TRUE; @@ -1396,138 +598,9 @@ status_t wr_refresh_root_ft(wr_vg_info_item_t *vg_item, bool32 check_version, bo gft_node_t *wr_get_ft_node_by_ftid( wr_session_t *session, wr_vg_info_item_t *vg_item, ftid_t id, bool32 check_version, bool32 active_refresh) { - wr_ctrl_t *wr_ctrl = vg_item->wr_ctrl; - if (is_ft_root_block(id)) { - char *root = wr_ctrl->root; - wr_root_ft_block_t *ft_block = (wr_root_ft_block_t *)(root); - if (wr_refresh_root_ft(vg_item, check_version, active_refresh) != CM_SUCCESS) { - return NULL; - } - - if (id.item < ft_block->ft_block.node_num) { - return (gft_node_t *)((root + sizeof(wr_root_ft_block_t)) + id.item * sizeof(gft_node_t)); - } - } else { - wr_block_id_t block_id = id; - block_id.item = 0; - wr_ft_block_t *ft_block = (wr_ft_block_t *)wr_find_block_in_shm( - session, vg_item, block_id, WR_BLOCK_TYPE_FT, check_version, NULL, active_refresh); - if (ft_block == NULL) { - LOG_DEBUG_ERR("Failed to find block:%s in mem.", wr_display_metaid(block_id)); - return NULL; - } - - if (ft_block->node_num <= id.item) { - LOG_DEBUG_ERR("The block is wrong, node_num:%u, item:%u.", ft_block->node_num, (uint32)id.item); - return NULL; - } - - gft_node_t *node = (gft_node_t *)(((char *)ft_block + sizeof(wr_ft_block_t)) + id.item * sizeof(gft_node_t)); - if (!wr_is_server() || wr_is_ft_block_valid(node, ft_block)) { - return node; - } - - LOG_DEBUG_INF("block:%llu fid:%llu, file ver:%llu is not same as node:%llu, fid:%llu, file ver:%llu", - WR_ID_TO_U64(block_id), wr_get_ft_block_fid(ft_block), wr_get_ft_block_file_ver(ft_block), - WR_ID_TO_U64(node->id), node->fid, node->file_ver); - wr_set_ft_block_file_ver(node, ft_block); - LOG_DEBUG_INF("block:%llu fid:%llu, file ver:%llu setted with node:%llu, fid:%llu, file ver:%llu", - WR_ID_TO_U64(block_id), wr_get_ft_block_fid(ft_block), wr_get_ft_block_file_ver(ft_block), - WR_ID_TO_U64(node->id), node->fid, node->file_ver); - return node; - } - return NULL; -} - -gft_node_t *wr_get_ft_node_by_ftid_no_refresh(wr_session_t *session, wr_vg_info_item_t *vg_item, ftid_t id) -{ - wr_ctrl_t *wr_ctrl = vg_item->wr_ctrl; - if (is_ft_root_block(id)) { - char *root = wr_ctrl->root; - wr_root_ft_block_t *ft_block = (wr_root_ft_block_t *)(root); - if (id.item < ft_block->ft_block.node_num) { - return (gft_node_t *)((root + sizeof(wr_root_ft_block_t)) + id.item * sizeof(gft_node_t)); - } - } else { - wr_block_id_t block_id = id; - block_id.item = 0; - wr_ft_block_t *block = (wr_ft_block_t *)wr_find_block_in_shm_no_refresh(session, vg_item, block_id, NULL); - if (block == NULL) { - LOG_DEBUG_ERR("Failed to find block:%s in mem.", wr_display_metaid(block_id)); - return NULL; - } - - if (block->node_num <= id.item) { - LOG_DEBUG_ERR("The block is wrong, node_num:%u, item:%u.", block->node_num, (uint32)id.item); - return NULL; - } - - return (gft_node_t *)(((char *)block + sizeof(wr_ft_block_t)) + id.item * sizeof(gft_node_t)); - } - return NULL; -} - -gft_node_t *wr_get_ft_node_by_ftid_from_disk_and_refresh_shm( - wr_session_t *session, wr_vg_info_item_t *vg_item, ftid_t id) -{ - wr_ctrl_t *wr_ctrl = vg_item->wr_ctrl; - if (is_ft_root_block(id)) { - char *root = wr_ctrl->root; - wr_root_ft_block_t *ft_block = (wr_root_ft_block_t *)(root); - if (wr_refresh_root_ft_inner(vg_item) != CM_SUCCESS) { - return NULL; - } - if (id.item < ft_block->ft_block.node_num) { - return (gft_node_t *)((root + sizeof(wr_root_ft_block_t)) + id.item * sizeof(gft_node_t)); - } - } else { - wr_block_id_t block_id = id; - block_id.item = 0; - wr_ft_block_t *ft_block = (wr_ft_block_t *)wr_find_block_from_disk_and_refresh_shm( - session, vg_item, block_id, WR_BLOCK_TYPE_FT, NULL); - if (ft_block == NULL) { - LOG_DEBUG_ERR("Failed to find block:%s from disk and refresh shm.", wr_display_metaid(block_id)); - return NULL; - } - if (ft_block->node_num <= id.item) { - LOG_DEBUG_ERR("Wrong block, node_num:%u, item:%u.", ft_block->node_num, (uint32)id.item); - return NULL; - } - gft_node_t *node = (gft_node_t *)(((char *)ft_block + sizeof(wr_ft_block_t)) + id.item * sizeof(gft_node_t)); - if (!wr_is_server() || wr_is_ft_block_valid(node, ft_block)) { - return node; - } - LOG_DEBUG_INF("block:%llu, fid:%llu, file ver:%llu is not same as node:%llu, fid:%llu, file ver:%llu", - WR_ID_TO_U64(block_id), wr_get_ft_block_fid(ft_block), wr_get_ft_block_file_ver(ft_block), - WR_ID_TO_U64(node->id), node->fid, node->file_ver); - wr_set_ft_block_file_ver(node, ft_block); - LOG_DEBUG_INF("block:%llu, fid:%llu, file ver:%llu setted with node:%llu, fid:%llu, file ver:%llu", - WR_ID_TO_U64(block_id), wr_get_ft_block_fid(ft_block), wr_get_ft_block_file_ver(ft_block), - WR_ID_TO_U64(node->id), node->fid, node->file_ver); - return node; - } return NULL; } -char *wr_get_ft_block_by_ftid(wr_session_t *session, wr_vg_info_item_t *vg_item, ftid_t id) -{ - wr_ctrl_t *wr_ctrl = vg_item->wr_ctrl; - if (is_ft_root_block(id)) { - char *root = wr_ctrl->root; - // NOTE:when recover just return root, must not be load from disk.Because format ft node is logic recovery, - // its gft info only use redo log info. - if (vg_item->status == WR_VG_STATUS_RECOVERY) { - return root; - } - - if (wr_refresh_root_ft(vg_item, CM_TRUE, CM_FALSE) != CM_SUCCESS) { - return NULL; - } - return root; - } - return wr_find_block_in_shm(session, vg_item, id, WR_BLOCK_TYPE_FT, CM_TRUE, NULL, CM_FALSE); -} - static void wr_init_ft_root_core(char *root, wr_root_ft_block_t *ft_block, gft_root_t *gft) { wr_set_blockid(&ft_block->ft_block.next, WR_INVALID_64); @@ -1634,51 +707,6 @@ status_t wr_update_ft_root(wr_vg_info_item_t *vg_item) return status; } -status_t wr_check_refresh_fs_block( - wr_vg_info_item_t *vg_item, wr_block_id_t blockid, char *block, bool32 *is_changed) -{ - if (!WR_STANDBY_CLUSTER && wr_is_readwrite()) { - WR_ASSERT_LOG(wr_need_exec_local(), "only masterid %u can be readwrite.", wr_get_master_id()); - return CM_SUCCESS; - } - status_t status = wr_check_refresh_core(vg_item); - WR_RETURN_IFERR2(status, LOG_DEBUG_ERR("Failed to check and refresh core, %s.", vg_item->entry_path)); - - return wr_check_block_version(vg_item, blockid, WR_BLOCK_TYPE_FS, block, is_changed, CM_FALSE); -} - -// refresh file table -status_t wr_refresh_ft(wr_session_t *session, wr_vg_info_item_t *vg_item) -{ - if (!WR_STANDBY_CLUSTER && wr_is_readwrite()) { - WR_ASSERT_LOG(wr_need_exec_local(), "only masterid %u can be readwrite.", wr_get_master_id()); - return CM_SUCCESS; - } - bool32 remote = CM_FALSE; - status_t status = wr_load_vg_ctrl_part( - vg_item, (int64)WR_CTRL_ROOT_OFFSET, vg_item->wr_ctrl->root, (int32)WR_BLOCK_SIZE, &remote); - WR_RETURN_IFERR2(status, LOG_DEBUG_ERR("Failed to load vg core part %s.", vg_item->entry_path)); - - uint64 count = 0; - char *root = vg_item->wr_ctrl->root; - wr_root_ft_block_t *ft_block = (wr_root_ft_block_t *)(root); - wr_block_id_t block_id = ft_block->ft_block.next; - bool32 cmp = wr_cmp_blockid(block_id, CM_INVALID_ID64); - while (!cmp) { - ft_block = (wr_root_ft_block_t *)wr_get_ft_block_by_ftid(session, vg_item, block_id); - if (ft_block) { - block_id = ft_block->ft_block.next; - cmp = wr_cmp_blockid(block_id, CM_INVALID_ID64); - } else { - WR_RETURN_IFERR2( - CM_ERROR, LOG_DEBUG_ERR("Failed to get file table block when refresh ft %s.", vg_item->entry_path)); - } - count++; - } - WR_LOG_DEBUG_OP("Succeed to refresh ft %s, count:%llu.", vg_item->entry_path, count); - return CM_SUCCESS; -} - status_t wr_get_root_version(wr_vg_info_item_t *vg_item, uint64 *version) { CM_ASSERT(vg_item != NULL); @@ -1726,44 +754,6 @@ status_t wr_check_refresh_ft(wr_vg_info_item_t *vg_item) status_t wr_update_ft_block_disk(wr_vg_info_item_t *vg_item, wr_ft_block_t *block, ftid_t id) { - uint32 volume_id = (uint32)id.volume; - int64 offset = wr_get_ft_block_offset(vg_item, id); - - block->common.version++; - block->common.checksum = wr_get_checksum(block, WR_BLOCK_SIZE); - CM_ASSERT(vg_item->volume_handle[volume_id].handle != WR_INVALID_HANDLE); - return wr_check_write_volume(vg_item, volume_id, offset, block, WR_BLOCK_SIZE); -} - -int64 wr_get_ft_block_offset(wr_vg_info_item_t *vg_item, ftid_t id) -{ - if ((id.au) == 0) { - return (int64)WR_CTRL_ROOT_OFFSET; - } - return wr_get_block_offset(vg_item, WR_BLOCK_SIZE, id.block, id.au); -} - -status_t wr_update_fs_bitmap_block_disk( - wr_vg_info_item_t *item, wr_fs_block_t *block, uint32 size, bool32 had_checksum) -{ - CM_ASSERT(item != NULL); - CM_ASSERT(block != NULL); - uint32 volume_id = (uint32)block->head.common.id.volume; - int64 offset = wr_get_fs_block_offset(item, block->head.common.id); - - if (!had_checksum) { - block->head.common.version++; - block->head.common.checksum = wr_get_checksum(block, WR_FILE_SPACE_BLOCK_SIZE); - } - - WR_LOG_DEBUG_OP("[FS] update_fs_bitmap_block_disk checksum:%u, fsid:%s, version:%llu, size:%u.", - block->head.common.checksum, wr_display_metaid(block->head.common.id), block->head.common.version, size); - - CM_ASSERT(item->volume_handle[volume_id].handle != WR_INVALID_HANDLE); - status_t status = wr_check_write_volume(item, volume_id, offset, block, size); - if (status != CM_SUCCESS) { - return status; - } return CM_SUCCESS; } @@ -1773,76 +763,6 @@ static status_t wr_get_block_entry(wr_session_t *session, wr_vg_info_item_t *vg_ return CM_SUCCESS; } -status_t wr_get_fs_block_info_by_offset( - int64 offset, uint64 au_size, uint32 *block_count, uint32 *block_au_count, uint32 *au_offset) -{ - WR_ASSERT_LOG(au_size != 0, "The au size cannot be zero."); - - // two level bitmap, ~2k block ids per entry FSB - uint64 au_count = WR_FILE_SPACE_BLOCK_BITMAP_COUNT; // 2043 2nd FSBs - uint64 block_len = au_count * au_size; // [4G, 128G] per 2nd-level FSB, with AU range [2MB, 64MB] - int64 temp = (offset / (int64)block_len); - if (temp > (int64)au_count) { // Total [8T, 256T] per file, to be verified - LOG_DEBUG_ERR( - "Invalid offset, offset:%lld, real block count:%lld, max block count:%llu.", offset, temp, au_count); - return CM_ERROR; - } - *block_count = (uint32)(temp); // index of secondary FSB(id) in entry FSB's bitmap - int64 block_offset = offset % (int64)block_len; // offset within FSB - *block_au_count = (uint32)(block_offset / (int64)au_size); // index of AU within FSB - if (au_offset != NULL) { - *au_offset = (uint32)(block_offset % (int64)au_size); // offset within AU - } - - return CM_SUCCESS; -} -status_t wr_alloc_fs_aux_batch_prepare(wr_session_t *session, wr_vg_info_item_t *vg_item, uint32 batch_count) -{ - return CM_SUCCESS; -} - -status_t wr_extend_fs_aux_batch_inner(wr_session_t *session, wr_vg_info_item_t *vg_item, auid_t batch_first, - gft_node_t *node, uint32 block_au_count, uint32 batch_count, wr_fs_block_t *second_block, - uint64 old_aux_root_free_count) -{ - return CM_SUCCESS; -} - -status_t wr_extend_fs_aux_batch(wr_session_t *session, wr_vg_info_item_t *vg_item, auid_t batch_first, - gft_node_t *node, uint32 block_au_count, uint32 batch_count, wr_fs_block_t *second_block) -{ - return CM_SUCCESS; -} - -status_t wr_extend_fs_aux(wr_session_t *session, wr_vg_info_item_t *vg_item, gft_node_t *node, - wr_block_id_t second_fs_block_id, wr_alloc_fs_block_info_t *info, auid_t *data_auid) -{ - return CM_SUCCESS; -} - -status_t wr_extend_fs_batch(wr_session_t *session, wr_vg_info_item_t *vg_item, auid_t batch_first, - uint32 block_au_count, uint32 batch_count, wr_fs_block_t *second_block) -{ - return CM_SUCCESS; -} - -status_t wr_extend_batch_inner(wr_session_t *session, wr_vg_info_item_t *vg_item, gft_node_t *node, uint64 align_beg, - uint64 align_end, bool32 *finish) -{ - return CM_SUCCESS; -} - -status_t wr_extend_batch( - wr_session_t *session, wr_vg_info_item_t *vg_item, gft_node_t *node, wr_node_data_t *node_data, bool32 *finish) -{ - return CM_SUCCESS; -} - -status_t wr_extend_inner(wr_session_t *session, wr_node_data_t *node_data) -{ - return CM_SUCCESS; -} - status_t wr_extend_from_offset( wr_session_t *session, wr_vg_info_item_t *vg_item, gft_node_t *node, wr_node_data_t *node_data) { @@ -2127,37 +1047,6 @@ status_t wr_refresh_file(wr_session_t *session, uint64 fid, ftid_t ftid, char *v return CM_SUCCESS; } -void wr_init_root_fs_block(wr_ctrl_t *wr_ctrl) -{ - CM_ASSERT(wr_ctrl != NULL); - wr_fs_block_root_t *block_root = WR_GET_FS_BLOCK_ROOT(wr_ctrl); - block_root->version = 0; - block_root->free.count = 0; - wr_set_auid(&block_root->free.first, CM_INVALID_ID64); - wr_set_auid(&block_root->free.last, CM_INVALID_ID64); -} - -status_t wr_refresh_volume(wr_session_t *session, const char *name_str, uint32 vgid, uint32 volumeid) -{ - return CM_SUCCESS; -} - -status_t wr_refresh_vginfo(wr_vg_info_item_t *vg_item) -{ - return CM_SUCCESS; -} - -status_t wr_load_fs_block_by_blockid( - wr_session_t *session, wr_vg_info_item_t *vg_item, wr_block_id_t blockid, int32 size) -{ - char *block = wr_find_block_in_shm(session, vg_item, blockid, WR_BLOCK_TYPE_FS, CM_FALSE, NULL, CM_FALSE); - CM_ASSERT(block != NULL); - int64 offset = wr_get_fs_block_offset(vg_item, blockid); - status_t status = wr_get_block_from_disk(vg_item, blockid, block, offset, size, CM_TRUE); - WR_RETURN_IFERR2(status, LOG_DEBUG_ERR("Failed to get block %s.", vg_item->entry_path)); - - return CM_SUCCESS; -} status_t wr_check_rename_path(wr_session_t *session, const char *src_path, const char *dst_path, text_t *dst_name) { text_t src_dir; @@ -2196,11 +1085,6 @@ status_t wr_check_open_file_remote(wr_session_t *session, const char *vg_name, u return CM_SUCCESS; } -status_t wr_refresh_ft_block(wr_session_t *session, char *vg_name, uint32 vgid, wr_block_id_t blockid) -{ - return CM_SUCCESS; -} - status_t wr_update_file_written_size( wr_session_t *session, uint32 vg_id, int64 offset, int64 size, wr_block_id_t ftid, uint64 fid) { @@ -2397,11 +1281,6 @@ status_t wr_try_write_zero_one_au( return CM_SUCCESS; } -status_t wr_calculate_vg_usage(wr_session_t *session, wr_vg_info_item_t *vg_item, uint32 *usage) -{ - return CM_SUCCESS; -} - void wr_alarm_check_vg_usage(wr_session_t *session) { return; diff --git a/src/common/wr_file.h b/src/common/wr_file.h index a84e8ddb174f9df3e5f4aa41e1aa04e62193cece..48ad3143c7717a4f4725d9c9735d798849e133e0 100644 --- a/src/common/wr_file.h +++ b/src/common/wr_file.h @@ -51,57 +51,30 @@ status_t wr_open_dir(wr_session_t *session, const char *dir_path, bool32 is_refr void wr_close_dir(wr_session_t *session, char *vg_name, uint64 ftid); status_t wr_find_vg_by_dir(const char *dir_path, char *name, wr_vg_info_item_t **vg_item); -void wr_lock_vg_mem_s_and_shm_x(wr_session_t *session, wr_vg_info_item_t *vg_item); void wr_lock_vg_mem_and_shm_x(wr_session_t *session, wr_vg_info_item_t *vg_item); -void wr_lock_vg_mem_and_shm_x2ix(wr_session_t *session, wr_vg_info_item_t *vg_item); -void wr_lock_vg_mem_and_shm_ix2x(wr_session_t *session, wr_vg_info_item_t *vg_item); void wr_lock_vg_mem_and_shm_s(wr_session_t *session, wr_vg_info_item_t *vg_item); void wr_lock_vg_mem_and_shm_s_force(wr_session_t *session, wr_vg_info_item_t *vg_item); void wr_unlock_vg_mem_and_shm(wr_session_t *session, wr_vg_info_item_t *vg_item); -void wr_lock_vg_mem_and_shm_ex_s(wr_session_t *session, char *vg_name); -void wr_unlock_vg_mem_and_shm_ex(wr_session_t *session, char *vg_name); status_t wr_create_file(wr_session_t *session, const char *parent, const char *name, int32_t flag); status_t wr_exist_item(wr_session_t *session, const char *item, bool32 *result, gft_item_type_t *output_type); status_t wr_open_file(wr_session_t *session, const char *file, int32_t flag, wr_find_node_t *find_info); status_t wr_close_file(wr_session_t *session, wr_vg_info_item_t *vg_item, uint64 ftid); -status_t wr_extend_inner(wr_session_t *session, wr_node_data_t *node_data); status_t wr_extend(wr_session_t *session, wr_node_data_t *node_data); status_t wr_do_fallocate(wr_session_t *session, wr_node_data_t *node_data); status_t wr_truncate(wr_session_t *session, uint64 fid, ftid_t ftid, int64 length, char *vg_name); status_t wr_refresh_file(wr_session_t *session, uint64 fid, ftid_t ftid, char *vg_name, int64 offset); -status_t wr_refresh_volume(wr_session_t *session, const char *name_str, uint32 vgid, uint32 volumeid); -status_t wr_refresh_ft_block(wr_session_t *session, char *vg_name, uint32 vgid, wr_block_id_t blockid); status_t wr_update_file_written_size( wr_session_t *session, uint32 vg_id, int64 offset, int64 size, wr_block_id_t ftid, uint64 fid); -status_t wr_get_ftid_by_path(wr_session_t *session, const char *path, ftid_t *ftid, wr_vg_info_item_t **dir_vg_item); -gft_node_t *wr_get_gft_node_by_path( - wr_session_t *session, wr_vg_info_item_t *vg_item, const char *path, wr_vg_info_item_t **dir_vg_item); -// for wr internal call -status_t wr_alloc_ft_au_when_no_free( - wr_session_t *session, wr_vg_info_item_t *vg_item, gft_root_t *gft, bool32 *check_version); void wr_check_ft_node_free(gft_node_t *node); -status_t wr_alloc_ft_node_when_create_vg( - wr_vg_info_item_t *vg_item, gft_node_t *parent_node, const char *name, gft_item_type_t type, uint32 flags); status_t wr_format_ft_node(wr_session_t *session, wr_vg_info_item_t *vg_item, auid_t auid); -void wr_free_ft_node_inner( - wr_session_t *session, wr_vg_info_item_t *vg_item, gft_node_t *parent_node, gft_node_t *node, bool32 real_del); -void wr_free_ft_node( - wr_session_t *session, wr_vg_info_item_t *vg_item, gft_node_t *parent_node, gft_node_t *node, bool32 real_del); gft_node_t *wr_get_next_node(wr_session_t *session, wr_vg_info_item_t *vg_item, gft_node_t *node); bool32 wr_is_last_tree_node(gft_node_t *node); void wr_delay_clean_all_vg(wr_session_t *session); -gft_node_t *wr_find_ft_node( - wr_session_t *session, wr_vg_info_item_t *vg_item, gft_node_t *parent_node, const char *name, bool8 skip_del); gft_node_t *wr_get_ft_node_by_ftid( wr_session_t *session, wr_vg_info_item_t *vg_item, ftid_t id, bool32 check_version, bool32 active_refresh); -gft_node_t *wr_get_ft_node_by_ftid_from_disk_and_refresh_shm( - wr_session_t *session, wr_vg_info_item_t *vg_item, ftid_t id); -gft_node_t *wr_get_ft_node_by_ftid_no_refresh(wr_session_t *session, wr_vg_info_item_t *vg_item, ftid_t id); status_t wr_update_ft_block_disk(wr_vg_info_item_t *vg_item, wr_ft_block_t *block, ftid_t id); -int64 wr_get_ft_block_offset(wr_vg_info_item_t *vg_item, ftid_t id); -char *wr_get_ft_block_by_ftid(wr_session_t *session, wr_vg_info_item_t *vg_item, ftid_t id); status_t wr_refresh_root_ft(wr_vg_info_item_t *vg_item, bool32 check_version, bool32 active_refresh); status_t wr_update_au_disk( @@ -109,9 +82,7 @@ status_t wr_update_au_disk( // for tool or instance void wr_init_ft_root(wr_ctrl_t *wr_ctrl, gft_node_t **out_node); status_t wr_update_ft_root(wr_vg_info_item_t *vg_item); -status_t wr_refresh_ft(wr_session_t *session, wr_vg_info_item_t *vg_item); status_t wr_check_refresh_ft(wr_vg_info_item_t *vg_item); -status_t wr_alloc_ft_au(wr_session_t *session, wr_vg_info_item_t *vg_item, ftid_t *id); typedef struct st_wr_alloc_fs_block_info { bool8 is_extend; @@ -119,20 +90,8 @@ typedef struct st_wr_alloc_fs_block_info { uint16_t index; gft_node_t *node; } wr_alloc_fs_block_info_t; -status_t wr_alloc_fs_block( - wr_session_t *session, wr_vg_info_item_t *vg_item, char **block, wr_alloc_fs_block_info_t *info); void wr_free_fs_block_addr(wr_session_t *session, wr_vg_info_item_t *vg_item, char *block, ga_obj_id_t obj_id); -int64 wr_get_fs_block_offset(wr_vg_info_item_t *vg_item, wr_block_id_t blockid); -status_t wr_update_fs_bitmap_block_disk( - wr_vg_info_item_t *item, wr_fs_block_t *block, uint32 size, bool32 had_checksum); status_t wr_format_bitmap_node(wr_session_t *session, wr_vg_info_item_t *vg_item, auid_t auid); -status_t wr_check_refresh_fs_block( - wr_vg_info_item_t *vg_item, wr_block_id_t blockid, char *block, bool32 *is_changed); -void wr_init_root_fs_block(wr_ctrl_t *wr_ctrl); -status_t wr_load_fs_block_by_blockid( - wr_session_t *session, wr_vg_info_item_t *vg_item, wr_block_id_t blockid, int32 size); - -void wr_init_fs_block_head(wr_fs_block_t *fs_block); status_t wr_check_rename_path(wr_session_t *session, const char *src_path, const char *dst_path, text_t *dst_name); status_t wr_get_name_from_path(const char *path, uint32_t *beg_pos, char *name); @@ -148,11 +107,7 @@ status_t wr_check_volume_path(const char *path); status_t wr_check_device_path(const char *path); status_t wr_check_path_both(const char *path); -status_t wr_refresh_vginfo(wr_vg_info_item_t *vg_item); - /* AU is usually NOT serial/continuous within a single file, judged from R/W file behaviors */ -status_t wr_get_fs_block_info_by_offset( - int64 offset, uint64 au_size, uint32 *block_count, uint32 *block_au_count, uint32 *au_offset); status_t wr_check_open_file_remote(wr_session_t *session, const char *vg_name, uint64 ftid, bool32 *is_open); status_t wr_check_file(wr_vg_info_item_t *vg_item); @@ -174,32 +129,9 @@ static inline bool32 wr_is_fs_meta_valid(gft_node_t *node) return !(node->flags & WR_FT_NODE_FLAG_INVALID_FS_META); } -static inline bool32 wr_is_fs_block_valid(gft_node_t *node, wr_fs_block_t *fs_block) -{ - wr_block_ctrl_t *block_ctrl = WR_GET_BLOCK_CTRL_FROM_META(fs_block); - return ((node->fid == block_ctrl->fid) && (node->file_ver == block_ctrl->file_ver) && - (block_ctrl->ftid == WR_ID_TO_U64(node->id))); -} - static inline void wr_set_fs_block_file_ver(gft_node_t *node, wr_fs_block_t *fs_block) { - wr_block_ctrl_t *block_ctrl = WR_GET_BLOCK_CTRL_FROM_META(fs_block); - block_ctrl->fid = node->fid; - block_ctrl->ftid = WR_ID_TO_U64(node->id); - block_ctrl->file_ver = node->file_ver; - block_ctrl->node = (char *)node; -} - -static inline uint64 wr_get_fs_block_fid(wr_fs_block_t *fs_block) -{ - wr_block_ctrl_t *block_ctrl = WR_GET_BLOCK_CTRL_FROM_META(fs_block); - return block_ctrl->fid; -} - -static inline uint64 wr_get_fs_block_file_ver(wr_fs_block_t *fs_block) -{ - wr_block_ctrl_t *block_ctrl = WR_GET_BLOCK_CTRL_FROM_META(fs_block); - return block_ctrl->file_ver; + return; } static inline int64 wr_get_fsb_offset(uint32 au_size, const wr_block_id_t *id) @@ -242,34 +174,6 @@ static inline gft_node_t *wr_get_node_by_block_ctrl(wr_block_ctrl_t *block, uint return (gft_node_t *)((((char *)ft_block) + sizeof(wr_ft_block_t)) + item * sizeof(gft_node_t)); } -static inline bool32 wr_is_ft_block_valid(gft_node_t *node, wr_ft_block_t *ft_block) -{ - wr_block_ctrl_t *block_ctrl = WR_GET_BLOCK_CTRL_FROM_META(ft_block); - return ((block_ctrl->node != NULL) && (node->fid == block_ctrl->fid) && (node->file_ver == block_ctrl->file_ver) && - (block_ctrl->ftid == WR_ID_TO_U64(node->id))); -} - -static inline void wr_set_ft_block_file_ver(gft_node_t *node, wr_ft_block_t *ft_block) -{ - wr_block_ctrl_t *block_ctrl = WR_GET_BLOCK_CTRL_FROM_META(ft_block); - block_ctrl->fid = node->fid; - block_ctrl->ftid = WR_ID_TO_U64(node->id); - block_ctrl->file_ver = node->file_ver; - block_ctrl->node = (char *)node; -} - -static inline uint64 wr_get_ft_block_fid(wr_ft_block_t *ft_block) -{ - wr_block_ctrl_t *block_ctrl = WR_GET_BLOCK_CTRL_FROM_META(ft_block); - return block_ctrl->fid; -} - -static inline uint64 wr_get_ft_block_file_ver(wr_ft_block_t *ft_block) -{ - wr_block_ctrl_t *block_ctrl = WR_GET_BLOCK_CTRL_FROM_META(ft_block); - return block_ctrl->file_ver; -} - static inline bool32 wr_is_block_ctrl_valid(wr_block_ctrl_t *block_ctrl) { gft_node_t *node = NULL; diff --git a/src/common/wr_meta_buf.c b/src/common/wr_meta_buf.c index 8e4b153388b371ecbbd25607ea7107405ca2ae02..078e61cb9a24e9a2b831578e757a3179fd9d95f3 100644 --- a/src/common/wr_meta_buf.c +++ b/src/common/wr_meta_buf.c @@ -1032,12 +1032,7 @@ static uint32 wr_try_find_recycle_meta_by_bucket(wr_session_t *session, wr_vg_in static void wr_meta_init_owner_fs_block_cache(wr_block_ctrl_t *owner_block_ctrl) { - owner_block_ctrl->fs_block_cache_info.entry_block_addr = NULL; - owner_block_ctrl->fs_block_cache_info.entry_block_id = 0; - owner_block_ctrl->fs_block_cache_info.fs_block_addr = NULL; - owner_block_ctrl->fs_block_cache_info.fs_block_id = 0; - owner_block_ctrl->fs_block_cache_info.fs_aux_addr = NULL; - owner_block_ctrl->fs_block_cache_info.fs_aux_block_id = 0; + return; } static bool32 wr_try_clean_cache_meta(wr_session_t *session, wr_block_ctrl_t *block_ctrl) diff --git a/src/common_api/wr_api_impl.c b/src/common_api/wr_api_impl.c index 63ec7b495bf02200309699f1c48d605330a5530a..395f0a1295df2f4b6cd84d8c5f6e86629bd91214 100644 --- a/src/common_api/wr_api_impl.c +++ b/src/common_api/wr_api_impl.c @@ -62,8 +62,6 @@ status_t wr_kick_host_sync(wr_conn_t *conn, int64 kick_hostid) } status_t wr_apply_refresh_volume(wr_conn_t *conn, wr_file_context_t *context, auid_t auid); -status_t wr_refresh_volume_handle(wr_conn_t *conn, wr_file_context_t *context, auid_t auid); -status_t wr_reopen_volume_handle(wr_conn_t *conn, wr_file_context_t *context, auid_t auid); status_t wr_apply_extending_file(wr_conn_t *conn, int32 handle, int64 size, int64 offset) { @@ -159,16 +157,6 @@ static status_t wr_check_refresh_file_by_offset( return CM_SUCCESS; } -status_t wr_refresh_volume_handle(wr_conn_t *conn, wr_file_context_t *context, auid_t auid) -{ - return CM_SUCCESS; -} - -status_t wr_reopen_volume_handle(wr_conn_t *conn, wr_file_context_t *context, auid_t auid) -{ - return CM_SUCCESS; -} - status_t wr_lock_vg_s(wr_vg_info_item_t *vg_item, wr_session_t *session) { wr_latch_offset_t latch_offset; @@ -957,11 +945,6 @@ int64 wr_seek_file_impl(wr_conn_t *conn, int handle, int64 offset, int origin) return new_offset; } -static status_t wr_check_ready_fs_block(files_rw_ctx_t *rw_ctx, wr_fs_pos_desc_t *fs_pos) -{ - return CM_SUCCESS; -} - status_t wr_read_write_file_core(wr_rw_param_t *param, void *buf, int32 size, int32 *read_size) { status_t status = CM_SUCCESS; @@ -1459,64 +1442,6 @@ status_t wr_fstat_impl(wr_conn_t *conn, int handle, wr_stat_info_t item) return ret; } -status_t wr_aio_check_need_updt_fs_aux(wr_rw_param_t *param, int32 size, bool32 *need_update) -{ - wr_conn_t *conn = param->conn; - wr_file_context_t *context = param->context; - long long offset = param->offset; - - *need_update = CM_FALSE; - if (context->node->min_inited_size >= (uint64)(offset + size)) { - return CM_SUCCESS; - } - - uint64 au_size = wr_get_vg_au_size(context->vg_item->wr_ctrl); - - wr_fs_pos_desc_t fs_pos = {0}; - files_rw_ctx_t rw_ctx; - rw_ctx.conn = conn; - rw_ctx.env = param->wr_env; - rw_ctx.file_ctx = context; - rw_ctx.handle = param->handle; - rw_ctx.read = CM_TRUE; // should NOT apply extend for aio post - - int64 top_size = (context->node->size > (param->offset + size)) ? (offset + size) : context->node->size; - int64 left_size = size; - int64 cur_size = 0; - - do { - int64 align_size = (int64)CM_CALC_ALIGN((uint64)(offset + 1), au_size); - if (offset + left_size > align_size) { - cur_size = align_size - offset; - } else { - cur_size = left_size; - } - - rw_ctx.offset = offset; - rw_ctx.size = (int32)cur_size; - - status_t status = wr_check_ready_fs_block(&rw_ctx, &fs_pos); - WR_RETURN_IF_ERROR(status); - if (!fs_pos.is_valid) { - LOG_RUN_ERR("Fail to find fs block for file:%s, fid:%llu, fti:%llu, cur offset:%llu, size:%lld," - "written_size:%llu, file size:%llu.", - context->node->name, context->node->fid, WR_ID_TO_U64(context->node->id), offset, cur_size, - context->node->written_size, (uint64)context->node->size); - return CM_ERROR; - } - - offset += cur_size; - left_size -= cur_size; - } while (offset < top_size); - - return CM_SUCCESS; -} - -status_t wr_aio_post_pwrite_file_impl(wr_conn_t *conn, int handle, long long offset, int size) -{ - return CM_SUCCESS; -} - static status_t wr_get_phy_size_prepare(wr_conn_t *conn, wr_file_context_t *context, long long *size) { *size = 0; diff --git a/src/common_api/wr_api_impl.h b/src/common_api/wr_api_impl.h index a86d0d52018d53bc75303f34ee6e8c41b17358d7..adb2309d0b91c655f06f9dd097bae43c2f2b669f 100644 --- a/src/common_api/wr_api_impl.h +++ b/src/common_api/wr_api_impl.h @@ -227,7 +227,6 @@ status_t wr_setcfg_impl(wr_conn_t *conn, const char *name, const char *value, co status_t wr_getcfg_impl(wr_conn_t *conn, const char *name, char *out_str, size_t str_len); status_t wr_stop_server_impl(wr_conn_t *conn); void wr_get_api_volume_error(void); -status_t wr_aio_post_pwrite_file_impl(wr_conn_t *conn, int handle, long long offset, int size); status_t wr_get_phy_size_impl(wr_conn_t *conn, int handle, long long *size); status_t wr_msg_interact(wr_conn_t *conn, uint8 cmd, void *send_info, void *ack); status_t wr_fallocate_impl(wr_conn_t *conn, int handle, int mode, long long int offset, long long int length); diff --git a/src/service/wr_instance.c b/src/service/wr_instance.c index 82946b5e810e27990c2fd365c87381eb00bdd6e6..e4ffc63de2746a4746439d62091b6f39f46686a0 100644 --- a/src/service/wr_instance.c +++ b/src/service/wr_instance.c @@ -819,88 +819,6 @@ bool32 wr_check_join_cluster() return CM_TRUE; } -static bool32 wr_find_unreg_volume(wr_session_t *session, char **dev, uint8 *vg_idx, uint8 *volume_id) -{ - for (uint32 i = 0; i < g_vgs_info->group_num; i++) { - for (uint32 j = 0; j < WR_MAX_VOLUMES; j++) { - if (g_vgs_info->volume_group[i].wr_ctrl->volume.defs[j].flag != VOLUME_PREPARE) { - continue; - } - wr_lock_vg_mem_and_shm_s(session, &g_vgs_info->volume_group[i]); - if (g_vgs_info->volume_group[i].wr_ctrl->volume.defs[j].flag != VOLUME_PREPARE) { - wr_unlock_vg_mem_and_shm(session, &g_vgs_info->volume_group[i]); - continue; - } - *dev = g_vgs_info->volume_group[i].wr_ctrl->volume.defs[j].name; - *vg_idx = (uint8)i; - *volume_id = (uint8)j; - wr_unlock_vg_mem_and_shm(session, &g_vgs_info->volume_group[i]); - return CM_TRUE; - } - } - return CM_FALSE; -} - -static bool32 wr_is_register(iof_reg_in_t *reg_info, int64 host_id) -{ - for (int32 i = 0; i < reg_info->key_count; i++) { - if (reg_info->reg_keys[i] == host_id + 1) { - return CM_TRUE; - } - } - return CM_FALSE; -} - -void wr_check_unreg_volume(wr_session_t *session) -{ - uint8 vg_idx, volume_id; - iof_reg_in_t reg_info; - (void)memset_s(®_info, sizeof(reg_info), 0, sizeof(reg_info)); - - bool32 is_unreg = wr_find_unreg_volume(session, ®_info.dev, &vg_idx, &volume_id); - if (!is_unreg) { - return; - } - status_t ret = cm_iof_inql(®_info); - if (ret != CM_SUCCESS) { - return; - } - bool32 remote = CM_FALSE; - wr_vg_info_item_t *vg_item = &g_vgs_info->volume_group[0]; - if (wr_lock_vg_storage_r(vg_item, vg_item->entry_path, g_inst_cfg) != CM_SUCCESS) { - return; - } - wr_lock_vg_mem_and_shm_s(session, vg_item); - ret = wr_load_vg_ctrl_part(vg_item, (int64)(WR_VOLUME_HEAD_SIZE - WR_DISK_UNIT_SIZE), - &vg_item->wr_ctrl->global_ctrl, WR_DISK_UNIT_SIZE, &remote); - wr_unlock_vg_mem_and_shm(session, vg_item); - (void)wr_unlock_vg_storage(vg_item, vg_item->entry_path, g_inst_cfg); - if (ret != CM_SUCCESS) { - return; - } - - bool32 is_reg = CM_FALSE; - for (uint8 i = 0; i < WR_MAX_INSTANCES; i++) { - is_reg = cm_bitmap64_exist(&vg_item->wr_ctrl->global_ctrl.cluster_node_info, i); - if (is_reg && !wr_is_register(®_info, i)) { - return; - } - } - - vg_item = &g_vgs_info->volume_group[vg_idx]; - wr_lock_vg_mem_and_shm_x(session, vg_item); - if (vg_item->wr_ctrl->volume.defs[volume_id].flag == VOLUME_FREE) { - wr_unlock_vg_mem_and_shm(session, vg_item); - return; - } - vg_item->wr_ctrl->volume.defs[volume_id].flag = VOLUME_OCCUPY; - ret = wr_update_volume_ctrl(vg_item); - wr_unlock_vg_mem_and_shm(session, vg_item); - if (ret != CM_SUCCESS) { - return; - } -} - void wr_meta_syn_proc(thread_t *thread) { cm_set_thread_name("meta_syn"); diff --git a/src/service/wr_instance.h b/src/service/wr_instance.h index 80085671f3870c3f57eae0e5ec3bd8ff5d2e1cf6..beedfdd506ce8058a7545abb265c442ecfac9f33 100644 --- a/src/service/wr_instance.h +++ b/src/service/wr_instance.h @@ -111,7 +111,6 @@ status_t wr_start_lsnr(wr_instance_t *inst); void wr_uninit_cm(wr_instance_t *inst); void wr_check_peer_inst(wr_instance_t *inst, uint64 inst_id); void wr_free_log_ctrl(); -status_t wr_alloc_vg_item_redo_log_buf(wr_vg_info_item_t *vg_item); void wr_check_peer_by_inst(wr_instance_t *inst, uint64 inst_id); uint64 wr_get_inst_work_status(void); void wr_set_inst_work_status(uint64 cur_inst_map); @@ -122,7 +121,6 @@ void wr_get_cm_lock_and_recover(thread_t *thread); void wr_delay_clean_proc(thread_t *thread); void wr_hashmap_dynamic_extend_and_redistribute_proc(thread_t *thread); bool32 wr_check_join_cluster(); -void wr_check_unreg_volume(wr_session_t *session); void wr_meta_syn_proc(thread_t *thread); void wr_recycle_meta_proc(thread_t *thread); void wr_alarm_check_proc(thread_t *thread); diff --git a/src/service/wr_srv_proc.c b/src/service/wr_srv_proc.c index 2d5d12c3b658d77ea9383aa000edcba029821cdd..55514cff773c8335f0e4588ab3a23614c7a9738f 100644 --- a/src/service/wr_srv_proc.c +++ b/src/service/wr_srv_proc.c @@ -373,23 +373,6 @@ status_t wr_create_file(wr_session_t *session, const char *parent, const char *n return wr_filesystem_touch(path); } -void wr_clean_open_files_in_vg(wr_session_t *session, wr_vg_info_item_t *vg_item, uint64 pid) -{ - wr_open_file_info_t *open_file = NULL; - wr_latch_x2(&vg_item->open_file_latch, session->id); - bilist_node_t *curr_node = cm_bilist_head(&vg_item->open_file_list); - bilist_node_t *next_node = NULL; - while (curr_node != NULL) { - next_node = curr_node->next; - open_file = BILIST_NODE_OF(wr_open_file_info_t, curr_node, link); - if (open_file->pid == pid) { - wr_free_open_file_node(curr_node, &vg_item->open_file_list); - } - curr_node = next_node; - } - wr_unlatch(&vg_item->open_file_latch); -} - #ifdef __cplusplus } #endif diff --git a/src/service/wr_srv_proc.h b/src/service/wr_srv_proc.h index 5d19aa2d52287bad7255099b15295e315fc32493..4defd928765565eef30ad4cf9a576cfe0e6d7c8f 100644 --- a/src/service/wr_srv_proc.h +++ b/src/service/wr_srv_proc.h @@ -39,7 +39,6 @@ status_t wr_remove_dir(wr_session_t *session, const char *dir, bool32 recursive) status_t wr_remove_file(wr_session_t *session, const char *file); status_t wr_remove_link(wr_session_t *session, const char *file); status_t wr_remove_dir_file_by_node(wr_session_t *session, wr_vg_info_item_t *vg_item, gft_node_t *node); -void wr_clean_open_files_in_vg(wr_session_t *session, wr_vg_info_item_t *vg_item, uint64 pid); #ifdef __cplusplus } #endif