int32_t ofs_read_block_fixup(container_handle_t *ct, block_head_t *blk, uint64_t vbn, uint32_t blk_id, uint32_t alloc_size) { int32_t ret = 0; if ((ct == NULL) || (blk == NULL)) { LOG_ERROR("Invalid parameter. ct(%p) blk(%p)\n", ct, blk); return -BLOCK_ERR_PARAMETER; } ret = ofs_read_block(ct, blk, alloc_size, 0, vbn); if (ret < 0) { LOG_ERROR("Read data failed. ct(%p) blk(%p) blk_id(%x) alloc_size(%d) vbn(%lld) ret(%d)", ct, blk, blk_id, alloc_size, vbn, ret); return ret; } ret = verify_block(blk, blk_id, alloc_size); if (ret < 0) { LOG_ERROR("Verify object failed. ct(%p) blk(%p) blk_id(%x) alloc_size(%d) vbn(%lld) ret(%d)", ct, blk, blk_id, alloc_size, vbn, ret); return ret; } return fixup_block(blk); }
void FMTest1Thread(TAny* a) { SFMTest1Info& info = *(SFMTest1Info*)a; NThread* pC = NKern::CurrentThread(); TUint32 seed[2] = {(TUint32)pC, 0}; TBool wait = (pC->iPriority > info.iPriorityThreshold); TBool thread0 = (pC==info.iThreads[0]); TInt n = 0; while (!info.iStop) { if (thread0) NKern::ThreadSetPriority(pC, 11); NKern::FMWait(&info.iMutex); TBool ok = verify_block((TUint32*)info.iBlock, info.iBlockSize); TEST_RESULT(ok, "Block corrupt"); ++info.iBlock[0]; setup_block((TUint32*)info.iBlock, info.iBlockSize); ++n; NKern::FMSignal(&info.iMutex); if (wait) { TUint32 x = random(seed) & 1; NKern::Sleep(x+1); } } TEST_PRINT2("Thread %T ran %d times", pC, n); }
int op_testpattern(const char *file, bool op_write) { int fd = -1; mode_t mode = O_LARGEFILE; unsigned long long pos, len, i, op_blocks; double op_elapsed; struct timeval start_time; mode |= op_write ? O_RDWR : O_RDONLY; fd = open(file, mode); if (fd == -1) { fprintf(stderr, "Unable to open %s, errno %d\n", file, errno); return 1; } if (!check_file_size(fd)) { close(fd); return 1; } gettimeofday(&start_time, NULL); for(i = 0; i < max_blocks; i++) { pos = i * block_size; if (lseek(fd, pos, SEEK_SET) == (off_t)-1) { fprintf(stderr, "Unable to seek to offset %llx\n", pos); close(fd); return 1; } if (op_write) { update_block(); len = atomicio(vwrite, fd, block_buf, block_size); if (len < block_size) { fprintf(stderr, "Write block %llx failed\n", i); close(fd); return 1; } } else { len = atomicio(read, fd, block_buf, block_size); if (len < block_size) { fprintf(stderr, "Read block %llx failed\n", i); close(fd); return 1; } verify_block(); } op_blocks = i + 1; op_elapsed = get_op_elapsed(&start_time); if (max_time > 0 && op_elapsed >= max_time) break; } printf("%llu %llu %f %llu\n", max_blocks, op_blocks, op_elapsed, sect_errors); close(fd); return 0; }
block_head_t *get_last_correct_block(uint8_t *buf, uint32_t blk_id, uint32_t alloc_size, uint32_t cnt) { uint32_t i = 0; uint32_t prev_i = 0; uint16_t prev_seq_no = 0; int32_t ret = 0; block_head_t *blk = NULL; ASSERT(buf != NULL); ASSERT(alloc_size != 0); for (i = 0; i < cnt; i++) { blk = (block_head_t *)(buf + alloc_size * i); if (blk->blk_id == 0) { // not written yet break; } if ((i != 0) && ((prev_seq_no + 1) != blk->seq_no)) { // current and next data is not the newest break; } prev_seq_no = blk->seq_no; prev_i = i; } for (i = 0; i < cnt; i++) { blk = (block_head_t *)(buf + alloc_size * prev_i); if (blk->blk_id == 0) { // not written yet break; } ret = verify_block(blk, blk_id, alloc_size); if (ret < 0) { LOG_ERROR("Verify object failed. buf(%p) blk(%p) blk_id(%x) alloc_size(%d) ret(%d)\n", buf, blk, blk_id, alloc_size, ret); } else { ret = fixup_block(blk); if (ret >= 0) { return blk; } LOG_ERROR("Fixup object failed. blk(%p) ret(%d)\n", blk, ret); } if (prev_i == 0) { prev_i = cnt; } prev_i--; } LOG_ERROR("No valid object. buf(%p) blk(%p) blk_id(%x) alloc_size(%d)", buf, blk, blk_id, alloc_size); return NULL; }
bool verify_block( const uint16_t id, const std::array<uint16_t, N>& data ) { return verify_block(id, data.data(), data.size()); }