Next Previous Contents

8.10 Desription of important GConv functions

Function convert()

Source in file: gc.c

int convert(size_t impnum, struct partition *imported, size_t expnum, struct partition *exported, size_t spcnum, struct space *free_space, int badblock_check, PROGRESS_PARAM, ERR_PARAM)

Converts partitions from beginning state (imported partitions) to destination state (exported partitions).

The convert() is divided into a few other functions, some less important of them are also in the same file and are named gc_* functions or GC_* macros.

Function move_files()

Source in file: movefiles.c

int move_files(size_t n, struct partition *imported, size_t m, struct partition *exported, PROGRESS_PARAM, ERR_PARAM)

Moves all files from imported filesystems to exported filesystems, in current version all files from i-th imported filesystem are moved to i-th exported filesystem. We plan selecting destination exported partition for files in future versions because joining and splitting operations require this.

Note: function align_files() is simpler than this, browses directory structure of each imported filesystem and for each file browses all blocks. For each extent calls fc_align() (in destination exported partition), function returns subextent (or empty extent) which can stay its location.

Support for hardlinks and their duplicating is initialized (hardlink_init() and dupl_init()). Checks if passed parameters are correct. Sums blocks of all imported partitions (for computing progress). And follows main loop, actions are realized for all partitions which must be rebuilt (not solved by fc_superblock()).

The main loop consists of following, used call-sequece of filesystem calls corresponds with description in filesystem API documentation.

Function entrydata_iterate()

Source in file: movedata.c

int entrydata_iterate(struct partition *imported, struct entry_info *imp_entry, struct partition *exported, struct entry_info *exp_entry, int (*proc)(struct block_list *list_glob, struct block_list *list_exp, struct partition *exported, struct entry_info *exp_entry, ERR_PARAM), ERR_PARAM)

Its task is to pass all (extents of) blocks of entry in imported partition to given function to do something with these blocks in exported partition, e.g. decide about destination location of this entry and link source and destination numbers of blocks for later permutating of blocks.

Function consists of double loop, gets blocks from source entry imp_entry, these blocks are relative to to start of imported partition. Blocks are renumbered to be relative to start of the virtual device (it contains everything) by extents_globalize(). Blocks are passed to given function (from argument) exp_entry which can consider exported partition and exp_entry. Function move_blocklist() converts blocks to be relative to start of exported partition or marks that are outside (used constant INVALID_BLOCK as first block). Such list can be fragmented, function join_blocklist() joins all neighbouring extents which can be joined (satisfying logical order). The most important action is call passed proc function with these lists to do something like linking, aligning etc.

The last action is to free used resources by fc_getdone() for imp_entry and exp_entry.

Note: exception for exp_entry == NULL is used in aligning proc_align().

Function proc_movedata()

Source in file: movedata.c

int proc_movedata(struct block_list *list_glob, struct block_list *list_exp, struct partition *exported, struct entry_info *exp_entry, ERR_PARAM)

Note: functions proc_align() and proc_duplicate() are very similar to this and don't need detailed description.

Consists of single loop which iterates through all passed blocks and does following actions:

Functions bread() and bwrite()

Source in file: brw.c

block_t bread(struct partition *part, const struct extent *blocks, void *buf, ERR_PARAM)

block_t bwrite(struct partition *part, const struct extent *blocks, const void *buf, ERR_PARAM)

Part of API, unify interface for logical access to partitions. Therefore these are usable for both imported and exported partitions. Even in special accelerated functions.

Functions linnew_read() and linnew_write()

Source in file: map_rw.c

int linnew_read(const struct extent *ext, void *buf, ERR_PARAM)

int linnew_write(const struct extent *ext, const void *buf, ERR_PARAM)

Provide read and write operation with the virtual device in its destination state. Functions are intended namely for accessing to exported partitions and are used in bread() and bwrite().

Functions consist of loop, which is repeated until action is done. Rest of given extent is converted from destination to current addressing of the virtual device in each iteration, used new2real(). Rests differ for read and write. Read is very simple use of exported cache expcache_read(). Note: block which wasn't already written contains zeroes. Write is very similar to read, it uses also exported cache expcache_write() and blocks are allocated during the first write by alloc_realblock() and also these must be linked with current destination, e.g. for filesystem metadata.

Function crazy_algorithm()

Source in file: crazy.c

int crazy_algorithm(PROGRESS_PARAM, ERR_PARAM)

The function does modification of all partition which are consireder for conversion. The functionality is very simple, works in single for-cycle for all blocks. In i-th iteration of the for-cycle function get_next_swapop() returns number of another block and these two blocks may be swapped or second one may be copied on first one (depends on returned moveonly flag). If such action is required (means that second one differs with INVALID_BLOCK) then function crazy_swap() is used to do it. The crazy_swap() is buffered and such buffering makes this simple idea very fast.

Note: simplicity is very important to be possible to implement journaling in feature versions, and to be sure that this critical code is without bugs.


Next Previous Contents