io.cc (fstransform-0.9.3-src) | : | io.cc (fstransform-0.9.4) | ||
---|---|---|---|---|
skipping to change at line 49 | skipping to change at line 49 | |||
FT_IO_NAMESPACE_BEGIN | FT_IO_NAMESPACE_BEGIN | |||
char const * const fr_io::label[] = { | char const * const fr_io::label[] = { | |||
"device", "loop-file", "zero-file", "secondary-storage", "primary-storag e", "storage", "free-space" | "device", "loop-file", "zero-file", "secondary-storage", "primary-storag e", "storage", "free-space" | |||
}; | }; | |||
char const * const fr_io::LABEL[] = { | char const * const fr_io::LABEL[] = { | |||
"DEVICE", "LOOP-FILE", "ZERO-FILE", "SECONDARY-STORAGE", "PRIMARY-STORAG E", "STORAGE", "FREE-SPACE" | "DEVICE", "LOOP-FILE", "ZERO-FILE", "SECONDARY-STORAGE", "PRIMARY-STORAG E", "STORAGE", "FREE-SPACE" | |||
}; | }; | |||
char const* const fr_io::extents_filename[FC_IO_EXTENTS_FILE_COUNT] = { | char const* const fr_io::extents_filename[FC_IO_EXTENTS_COUNT] = { | |||
"/loop_extents.txt", "/free_space_extents.txt" | "/loop_extents.txt", "/free_space_extents.txt", "/to_zero_extents.txt" | |||
}; | }; | |||
/** constructor */ | /** constructor */ | |||
fr_io::fr_io(fr_persist & persist) | fr_io::fr_io(fr_persist & persist) | |||
: this_primary_storage(), request_vec(), this_dev_length(0), this_eff_block_ | : this_primary_storage(), request_vec(), this_dev_length(0), this_loop_file_ | |||
size_log2(0), | length(0), this_eff_block_size_log2(0), | |||
this_dev_path(NULL), this_umount_cmd(NULL), this_job(persist.job()), this_ | this_dev_path(NULL), this_cmd_umount(NULL), this_job(persist.job()), this_ | |||
persist(persist), this_ui(NULL), | persist(persist), this_ui(NULL), | |||
request_dir(FC_INVALID2INVALID), this_delegate_ui(false) | request_dir(FC_INVALID2INVALID), this_delegate_ui(false) | |||
{ | { | |||
this_secondary_storage.clear(); | this_secondary_storage.clear(); | |||
} | } | |||
/** | /** | |||
* destructor. | * destructor. | |||
* sub-classes must override it to call close() if they override close() | * sub-classes must override it to call close() if they override close() | |||
*/ | */ | |||
fr_io::~fr_io() | fr_io::~fr_io() | |||
{ } | { } | |||
/** | /** | |||
* open this fr_io. | * open this fr_io. | |||
* sub-classes must override this method to perform appropriate initialization, | * sub-classes must override this method to perform appropriate initialization, | |||
* and the first thing sub-classes open() must do is to call fr_io::open(). | * and the first thing sub-classes open() must do is to call fr_io::open(). | |||
*/ | */ | |||
int fr_io::open(const fr_args & args) | int fr_io::open(const fr_args & args) | |||
{ | { | |||
this_umount_cmd = args.umount_cmd; | this_cmd_umount = args.cmd_umount; | |||
return 0; | return 0; | |||
} | } | |||
/** | /** | |||
* close this fr_io. | * close this fr_io. | |||
* sub-classes must override this method to perform appropriate cleanup | * sub-classes must override this method to perform appropriate cleanup | |||
*/ | */ | |||
void fr_io::close() | void fr_io::close() | |||
{ | { | |||
this_primary_storage.clear(); | this_primary_storage.clear(); | |||
this_secondary_storage.clear(); | this_secondary_storage.clear(); | |||
request_vec.clear(); | request_vec.clear(); | |||
request_dir = FC_INVALID2INVALID; | request_dir = FC_INVALID2INVALID; | |||
this_dev_length = this_eff_block_size_log2 = 0; | this_dev_length = this_eff_block_size_log2 = 0; | |||
this_dev_path = NULL; | this_dev_path = NULL; | |||
} | } | |||
/** compute and return log2() of effective block size and remember it */ | /** compute and return log2() of effective block size */ | |||
ft_uoff fr_io::effective_block_size_log2(ft_uoff block_size_bitmask) | ft_uoff fr_io::effective_block_size_log2(ft_uoff block_size_bitmask) | |||
{ | { | |||
ft_uoff block_size_log2 = 0; | ft_uoff block_size_log2 = 0; | |||
if (block_size_bitmask != 0) { | if (block_size_bitmask != 0) { | |||
while ((block_size_bitmask & 1) == 0) { | while ((block_size_bitmask & 1) == 0) { | |||
block_size_log2++; | block_size_log2++; | |||
block_size_bitmask >>= 1; | block_size_bitmask >>= 1; | |||
} | } | |||
} | } | |||
return this_eff_block_size_log2 = block_size_log2; | return block_size_log2; | |||
} | } | |||
/* return (-)EOVERFLOW if request from/to + length overflow specified maximum va lue */ | /* return (-)EOVERFLOW if request from/to + length overflow specified maximum va lue */ | |||
int fr_io::validate(const char * type_name, ft_uoff type_max, fr_dir dir, ft_uof f from, ft_uoff to, ft_uoff length) | int fr_io::validate(const char * type_name, ft_uoff type_max, fr_dir dir, ft_uof f from, ft_uoff to, ft_uoff length) | |||
{ | { | |||
to = ff_max2(from, to); | to = ff_max2(from, to); | |||
if (!ff_can_sum(to, length) || length > type_max || to > type_max - length) { | if (!ff_can_sum(to, length) || length > type_max || to > type_max - length) { | |||
return ff_log(FC_FATAL, EOVERFLOW, "internal error! %s to %s io.copy(dir | return ff_log(FC_FATAL, EOVERFLOW, "internal error! %s to %s io.copy(dir | |||
= %d, from_physical = %"FT_ULL", to_physical = %"FT_ULL", length = %"FT_ULL")" | = %d, from_physical = %" FT_ULL ", to_physical = %" FT_ULL ", length = %" FT_UL | |||
" overflows maximum allowed (%s)%"FT_ULL, | L ")" | |||
" overflows maximum allowed (%s)%" FT_ULL , | ||||
ff_is_from_dev(dir) ? label[FC_DEVICE] : label[FC_STORAGE] , | ff_is_from_dev(dir) ? label[FC_DEVICE] : label[FC_STORAGE] , | |||
ff_is_to_dev(dir) ? label[FC_DEVICE] : label[FC_STORAGE], | ff_is_to_dev(dir) ? label[FC_DEVICE] : label[FC_STORAGE], | |||
(int)dir, (ft_ull)from, (ft_ull)to, (ft_ull)length, type_n ame, (ft_ull)type_max); | (int)dir, (ft_ull)from, (ft_ull)to, (ft_ull)length, type_n ame, (ft_ull)type_max); | |||
} | } | |||
return 0; | return 0; | |||
} | } | |||
/** | /** | |||
* if replaying an existing job, calls ff_load_extents_file() to load saved exte nts files. | * if replaying an existing job, calls ff_load_extents_file() to load saved exte nts files. | |||
* otherwise calls the 3-argument version of read_extents() and, if it succeeds, | * otherwise calls the 4-argument version of read_extents() and, if it succeeds, | |||
* calls effective_block_size_log2() to compute and remember effective block siz e | * calls effective_block_size_log2() to compute and remember effective block siz e | |||
*/ | */ | |||
int fr_io::read_extents(fr_vector<ft_uoff> & loop_file_extents, | int fr_io::read_extents(fr_vector<ft_uoff> & loop_file_extents, | |||
fr_vector<ft_uoff> & free_space_extents) | fr_vector<ft_uoff> & free_space_extents, | |||
fr_vector<ft_uoff> & to_zero_extents) | ||||
{ | { | |||
ft_uoff block_size_bitmask = 0; | ft_uoff block_size_bitmask = 0; | |||
int err; | int err; | |||
if (is_replaying()) | if (is_replaying()) | |||
err = load_extents(loop_file_extents, free_space_extents, block_size_bitm ask); | err = load_extents(loop_file_extents, free_space_extents, to_zero_extents , block_size_bitmask); | |||
else | else | |||
err = read_extents(loop_file_extents, free_space_extents, block_size_bitm ask); | err = read_extents(loop_file_extents, free_space_extents, to_zero_extents , block_size_bitmask); | |||
if (err == 0) { | if (err == 0) { | |||
ft_uoff eff_block_size_log2 = effective_block_size_log2(block_size_bitma | this_eff_block_size_log2 = effective_block_size_log2(block_size_bitmask) | |||
sk); | ; | |||
ff_log(FC_INFO, 0, "%s effective block size = %"FT_ULL, label[FC_DEVICE] | ff_log(FC_INFO, 0, "%s effective block size = %" FT_ULL , label[FC_DEVIC | |||
, (ft_ull) 1 << eff_block_size_log2); | E], (ft_ull) 1 << this_eff_block_size_log2); | |||
} | } | |||
return err; | return err; | |||
} | } | |||
/** | /** | |||
* loads extents from file job.job_dir() + '/loop_extents.txt' and job.job_dir() | * loads extents from files 'loop_extents.txt', 'free_space_extents.txt' and 'to | |||
+ '/free_space_extents.txt' | _zero_extents.txt' | |||
* by calling the function ff_load_extents_file() | * inside folder job.job_dir() by calling the function ff_load_extents_file() | |||
* if successful, calls effective_block_size_log2() to compute and remember effe ctive block size | * if successful, calls effective_block_size_log2() to compute and remember effe ctive block size | |||
*/ | */ | |||
int fr_io::load_extents(fr_vector<ft_uoff> & loop_file_extents, | int fr_io::load_extents(fr_vector<ft_uoff> & loop_file_extents, | |||
fr_vector<ft_uoff> & free_space_exten | fr_vector<ft_uoff> & free_space_e | |||
ts, ft_uoff & ret_block_size_bitmask) | xtents, | |||
fr_vector<ft_uoff> & to_zero_extents, | ||||
ft_uoff & ret_block_size_bitmask) | ||||
{ | { | |||
fr_vector<ft_uoff> * ret_extents[] = { & loop_file_extents, & free_space_ extents, & to_zero_extents }; | ||||
ft_string path; | ft_string path; | |||
const ft_string & job_dir = this_job.job_dir(); | ||||
ft_uoff block_size_bitmask = 0; | ft_uoff block_size_bitmask = 0; | |||
const ft_string & job_dir = this_job.job_dir(); | ||||
FILE * f = NULL; | FILE * f = NULL; | |||
const char * path_cstr = NULL; | const char * path_cstr = NULL; | |||
int err = 0; | int err = 0; | |||
for (ft_size i = 0; err == 0 && i < FC_IO_EXTENTS_FILE_COUNT; i++) { | for (ft_size i = 0; err == 0 && i < FC_IO_EXTENTS_COUNT; i++) { | |||
path = job_dir; | path = job_dir; | |||
path += extents_filename[i]; | path += extents_filename[i]; | |||
path_cstr = path.c_str(); | path_cstr = path.c_str(); | |||
if ((f = fopen(path_cstr, "r")) == NULL) { | if ((f = fopen(path_cstr, "r")) == NULL) { | |||
err = ff_log(FC_ERROR, errno, "error opening persistence file '%s'", | if (i == FC_IO_EXTENTS_TO_ZERO) | |||
path_cstr); | ff_log(FC_WARN, errno, "this job is probably from version | |||
break; | 0.9.3, cannot open persistence file '%s'", path_cstr); | |||
else | ||||
err = ff_log(FC_ERROR, errno, "error opening persistence | ||||
file '%s'", path_cstr); | ||||
break; | ||||
} | } | |||
if ((err = ff_load_extents_file(f, (i == 0 ? loop_file_extents : free_sp ace_extents), block_size_bitmask)) != 0) | if ((err = ff_load_extents_file(f, * ret_extents[i], block_size_bitmask) ) != 0) | |||
err = ff_log(FC_ERROR, err, "error reading persistence file '%s'", p ath_cstr); | err = ff_log(FC_ERROR, err, "error reading persistence file '%s'", p ath_cstr); | |||
if (fclose(f) != 0) { | if (fclose(f) != 0) { | |||
ff_log(FC_WARN, errno, "warning: failed to close persistence file '% s'", path_cstr); | ff_log(FC_WARN, errno, "warning: failed to close persistence file '% s'", path_cstr); | |||
f = NULL; | f = NULL; | |||
} | } | |||
} | } | |||
if (err == 0) | if (err == 0) | |||
ret_block_size_bitmask = block_size_bitmask; | ret_block_size_bitmask = block_size_bitmask; | |||
return err; | return err; | |||
} | } | |||
/** | /** | |||
* saves extents to files job.job_dir() + '/loop_extents.txt' and job.job_dir() + '/free_space_extents.txt' | * saves extents to files job.job_dir() + '/loop_extents.txt' and job.job_dir() + '/free_space_extents.txt' | |||
* by calling the function ff_save_extents_file() | * by calling the function ff_save_extents_file() | |||
*/ | */ | |||
int fr_io::save_extents(const fr_vector<ft_uoff> & loop_file_extents, | int fr_io::save_extents(const fr_vector<ft_uoff> & loop_file_extents, | |||
const fr_vector<ft_uoff> & free_space_extents) const | const fr_vector<ft_uoff> & free_space_extents, | |||
const fr_vector<ft_uoff> & to_zero_extents) const | ||||
{ | { | |||
const fr_vector<ft_uoff> * extents[] = { & loop_file_extents, & free_spac e_extents, & to_zero_extents }; | ||||
ft_string path; | ft_string path; | |||
const ft_string & job_dir = this_job.job_dir(); | const ft_string & job_dir = this_job.job_dir(); | |||
FILE * f = NULL; | FILE * f = NULL; | |||
const char * path_cstr = NULL; | const char * path_cstr = NULL; | |||
int err = 0; | int err = 0; | |||
for (ft_size i = 0; err == 0 && i < FC_IO_EXTENTS_FILE_COUNT; i++) { | ||||
for (ft_size i = 0; err == 0 && i < FC_IO_EXTENTS_COUNT; i++) { | ||||
path = job_dir; | path = job_dir; | |||
path += extents_filename[i]; | path += extents_filename[i]; | |||
path_cstr = path.c_str(); | path_cstr = path.c_str(); | |||
if ((f = fopen(path_cstr, "w")) == NULL) { | if ((f = fopen(path_cstr, "w")) == NULL) { | |||
err = ff_log(FC_ERROR, errno, "error opening persistence file '%s'", path_cstr); | err = ff_log(FC_ERROR, errno, "error opening persistence file '%s'", path_cstr); | |||
break; | break; | |||
} | } | |||
if ((err = ff_save_extents_file(f, i == 0 ? loop_file_extents : free_spa ce_extents)) != 0) | if ((err = ff_save_extents_file(f, * extents[i])) != 0) | |||
err = ff_log(FC_ERROR, err, "error writing to persistence file '%s'" , path_cstr); | err = ff_log(FC_ERROR, err, "error writing to persistence file '%s'" , path_cstr); | |||
if (fclose(f) != 0) { | if (fclose(f) != 0) { | |||
ff_log(FC_WARN, errno, "error closing persistence file '%s'", path_c str); | ff_log(FC_WARN, errno, "error closing persistence file '%s'", path_c str); | |||
f = NULL; | f = NULL; | |||
} | } | |||
} | } | |||
return err; | return err; | |||
} | } | |||
skipping to change at line 305 | skipping to change at line 314 | |||
if (err == 0) | if (err == 0) | |||
err = flush_bytes(); | err = flush_bytes(); | |||
if (err == 0 && this_ui != 0 && !this_delegate_ui) | if (err == 0 && this_ui != 0 && !this_delegate_ui) | |||
this_ui->show_io_flush(); | this_ui->show_io_flush(); | |||
} | } | |||
return err; | return err; | |||
} | } | |||
/** called to remove storage from file system if execution is successful */ | /** called to remove storage from file system if execution is successful */ | |||
int fr_io::remove_storage_after_success() | int fr_io::remove_storage_after_success() | |||
{ } | { | |||
return 0; | ||||
} | ||||
FT_IO_NAMESPACE_END | FT_IO_NAMESPACE_END | |||
End of changes. 24 change blocks. | ||||
35 lines changed or deleted | 49 lines changed or added |