Lines Matching full:data
2 * undo_io.c --- This is the undo io manager that copies the old data that
3 * copies the old data being overwritten into a tdb database
75 * A key block, which contains undo_keys to map the following data blocks.
76 * Data blocks
92 __le64 key_offset; /* where do the key/data block chunks start? */
188 static errcode_t write_undo_indexes(struct undo_private_data *data, int flush) in write_undo_indexes() argument
196 /* Spit out a key block, if there's any data */ in write_undo_indexes()
197 if (data->keys_in_block) { in write_undo_indexes()
198 data->keyb->magic = ext2fs_cpu_to_le32(KEYBLOCK_MAGIC); in write_undo_indexes()
199 data->keyb->crc = 0; in write_undo_indexes()
200 data->keyb->crc = ext2fs_cpu_to_le32( in write_undo_indexes()
202 (unsigned char *)data->keyb, in write_undo_indexes()
203 data->tdb_data_size)); in write_undo_indexes()
204 dbg_printf("Writing keyblock to blk %llu\n", data->key_blk_num); in write_undo_indexes()
205 retval = io_channel_write_blk64(data->undo_file, in write_undo_indexes()
206 data->key_blk_num, in write_undo_indexes()
207 1, data->keyb); in write_undo_indexes()
211 if (data->keys_in_block == KEYS_PER_BLOCK(data)) { in write_undo_indexes()
212 memset(data->keyb, 0, data->tdb_data_size); in write_undo_indexes()
213 data->keys_in_block = 0; in write_undo_indexes()
214 data->key_blk_num = data->undo_blk_num; in write_undo_indexes()
215 data->undo_blk_num++; in write_undo_indexes()
220 channel = data->real; in write_undo_indexes()
231 memcpy(data->hdr.magic, E2UNDO_MAGIC, sizeof(data->hdr.magic)); in write_undo_indexes()
232 data->hdr.num_keys = ext2fs_cpu_to_le64(data->num_keys); in write_undo_indexes()
233 data->hdr.super_offset = ext2fs_cpu_to_le64(data->super_blk_num); in write_undo_indexes()
234 data->hdr.key_offset = ext2fs_cpu_to_le64(data->first_key_blk); in write_undo_indexes()
235 data->hdr.fs_block_size = ext2fs_cpu_to_le32(block_size); in write_undo_indexes()
236 data->hdr.sb_crc = ext2fs_cpu_to_le32(sb_crc); in write_undo_indexes()
237 data->hdr.fs_offset = ext2fs_cpu_to_le64(data->offset); in write_undo_indexes()
238 if (data->offset) in write_undo_indexes()
239 e2undo_set_feature_fs_offset(&data->hdr); in write_undo_indexes()
241 e2undo_clear_feature_fs_offset(&data->hdr); in write_undo_indexes()
242 hdr_crc = ext2fs_crc32c_le(~0, (unsigned char *)&data->hdr, in write_undo_indexes()
243 sizeof(data->hdr) - in write_undo_indexes()
244 sizeof(data->hdr.header_crc)); in write_undo_indexes()
245 data->hdr.header_crc = ext2fs_cpu_to_le32(hdr_crc); in write_undo_indexes()
246 retval = io_channel_write_blk64(data->undo_file, 0, in write_undo_indexes()
247 -(int)sizeof(data->hdr), in write_undo_indexes()
248 &data->hdr); in write_undo_indexes()
256 dbg_printf("Writing superblock to block %llu\n", data->super_blk_num); in write_undo_indexes()
257 retval = io_channel_write_blk64(data->undo_file, data->super_blk_num, in write_undo_indexes()
263 retval = io_channel_flush(data->undo_file); in write_undo_indexes()
269 static errcode_t undo_setup_tdb(struct undo_private_data *data) in undo_setup_tdb() argument
274 if (data->tdb_written == 1) in undo_setup_tdb()
277 data->tdb_written = 1; in undo_setup_tdb()
280 memset(&data->fake_fs, 0, sizeof(data->fake_fs)); in undo_setup_tdb()
281 data->fake_fs.blocksize = data->tdb_data_size; in undo_setup_tdb()
282 retval = ext2fs_alloc_generic_bmap(&data->fake_fs, in undo_setup_tdb()
286 "undo block map", &data->written_block_map); in undo_setup_tdb()
291 retval = ext2fs_get_mem(data->tdb_data_size, &data->keyb); in undo_setup_tdb()
294 data->key_blk_num = data->first_key_blk; in undo_setup_tdb()
297 dbg_printf("Undo block size %llu\n", data->tdb_data_size); in undo_setup_tdb()
298 dbg_printf("Keys per block %llu\n", KEYS_PER_BLOCK(data)); in undo_setup_tdb()
299 data->hdr.block_size = ext2fs_cpu_to_le32(data->tdb_data_size); in undo_setup_tdb()
300 io_channel_set_blksize(data->undo_file, data->tdb_data_size); in undo_setup_tdb()
304 retval = io_channel_read_blk64(data->undo_file, i, 1, in undo_setup_tdb()
305 data->keyb); in undo_setup_tdb()
307 memset(data->keyb, 0, data->tdb_data_size); in undo_setup_tdb()
308 retval = io_channel_write_blk64(data->undo_file, i, 1, in undo_setup_tdb()
309 data->keyb); in undo_setup_tdb()
312 retval = io_channel_flush(data->undo_file); in undo_setup_tdb()
316 memset(data->keyb, 0, data->tdb_data_size); in undo_setup_tdb()
328 struct undo_private_data *data; in undo_write_tdb() local
335 data = (struct undo_private_data *) channel->private_data; in undo_write_tdb()
337 if (data->undo_file == NULL) { in undo_write_tdb()
353 retval = undo_setup_tdb(data); in undo_write_tdb()
357 * Data is stored in tdb database as blocks of tdb_data_size size in undo_write_tdb()
362 offset = (block * channel->block_size) + data->offset ; in undo_write_tdb()
363 block_num = offset / data->tdb_data_size; in undo_write_tdb()
364 end_block = (offset + size - 1) / data->tdb_data_size; in undo_write_tdb()
372 if (ext2fs_test_block_bitmap2(data->written_block_map, in undo_write_tdb()
378 ext2fs_mark_block_bitmap2(data->written_block_map, block_num); in undo_write_tdb()
387 offset = block_num * data->tdb_data_size + in undo_write_tdb()
388 (data->offset % data->tdb_data_size); in undo_write_tdb()
389 backing_blk_num = (offset - data->offset) / channel->block_size; in undo_write_tdb()
391 retval = ext2fs_get_mem(data->tdb_data_size, &read_ptr); in undo_write_tdb()
396 memset(read_ptr, 0, data->tdb_data_size); in undo_write_tdb()
398 if ((data->tdb_data_size % channel->block_size) == 0) in undo_write_tdb()
399 sz = data->tdb_data_size / channel->block_size; in undo_write_tdb()
401 sz = -data->tdb_data_size; in undo_write_tdb()
402 retval = io_channel_read_blk64(data->real, backing_blk_num, in undo_write_tdb()
415 data_size = data->tdb_data_size; in undo_write_tdb()
423 data_size, backing_blk_num, block, data->tdb_data_size); in undo_write_tdb()
424 if ((data_size % data->undo_file->block_size) == 0) in undo_write_tdb()
425 sz = data_size / data->undo_file->block_size; in undo_write_tdb()
429 if (data->keys_in_block) { in undo_write_tdb()
430 key = data->keyb->keys + data->keys_in_block - 1; in undo_write_tdb()
440 E2UNDO_MAX_EXTENT_BLOCKS * data->tdb_data_size > in undo_write_tdb()
447 data->num_keys++; in undo_write_tdb()
448 key = data->keyb->keys + data->keys_in_block; in undo_write_tdb()
449 data->keys_in_block++; in undo_write_tdb()
457 data->undo_blk_num, in undo_write_tdb()
458 sz, data->num_keys - 1); in undo_write_tdb()
459 retval = io_channel_write_blk64(data->undo_file, in undo_write_tdb()
460 data->undo_blk_num, sz, read_ptr); in undo_write_tdb()
465 data->undo_blk_num++; in undo_write_tdb()
469 retval = write_undo_indexes(data, 0); in undo_write_tdb()
483 void *data ATTR((unused)), in undo_io_read_error()
546 struct undo_private_data *data) in try_reopen_undo_file() argument
565 retval = io_channel_read_blk64(data->undo_file, 0, -(int)sizeof(hdr), in try_reopen_undo_file()
586 io_channel_set_blksize(data->undo_file, blocksize); in try_reopen_undo_file()
596 if (check_filesystem(&hdr, data->undo_file, blocksize, super_block, in try_reopen_undo_file()
597 data->real) != 0) { in try_reopen_undo_file()
603 data->tdb_data_size = blocksize; in try_reopen_undo_file()
604 retval = undo_setup_tdb(data); in try_reopen_undo_file()
607 data->num_keys = num_keys; in try_reopen_undo_file()
608 data->super_blk_num = super_block; in try_reopen_undo_file()
609 data->first_key_blk = ext2fs_le64_to_cpu(hdr.key_offset); in try_reopen_undo_file()
612 keys_per_block = KEYS_PER_BLOCK(data); in try_reopen_undo_file()
613 lblk = data->first_key_blk; in try_reopen_undo_file()
620 data->key_blk_num = lblk; in try_reopen_undo_file()
621 retval = io_channel_read_blk64(data->undo_file, in try_reopen_undo_file()
622 lblk, 1, data->keyb); in try_reopen_undo_file()
627 if (ext2fs_le32_to_cpu(data->keyb->magic) != KEYBLOCK_MAGIC) { in try_reopen_undo_file()
631 crc = data->keyb->crc; in try_reopen_undo_file()
632 data->keyb->crc = 0; in try_reopen_undo_file()
633 key_crc = ext2fs_crc32c_le(~0, (unsigned char *)data->keyb, in try_reopen_undo_file()
642 max_j = data->num_keys - i; in try_reopen_undo_file()
645 for (j = 0, dkey = data->keyb->keys; in try_reopen_undo_file()
652 ext2fs_mark_block_bitmap_range2(data->written_block_map, in try_reopen_undo_file()
656 data->undo_blk_num = lblk; in try_reopen_undo_file()
657 data->keys_in_block = j + 1; in try_reopen_undo_file()
661 data->key_blk_num, data->undo_blk_num, data->num_keys, in try_reopen_undo_file()
662 data->keys_in_block); in try_reopen_undo_file()
664 data->hdr.state = hdr.state & ~E2UNDO_STATE_FINISHED; in try_reopen_undo_file()
665 data->hdr.f_compat = hdr.f_compat; in try_reopen_undo_file()
666 data->hdr.f_incompat = hdr.f_incompat; in try_reopen_undo_file()
667 data->hdr.f_rocompat = hdr.f_rocompat; in try_reopen_undo_file()
671 data->key_blk_num = data->undo_blk_num = 0; in try_reopen_undo_file()
672 data->keys_in_block = 0; in try_reopen_undo_file()
673 ext2fs_free_mem(&data->keyb); in try_reopen_undo_file()
674 ext2fs_free_generic_bitmap(data->written_block_map); in try_reopen_undo_file()
675 data->tdb_written = 0; in try_reopen_undo_file()
685 struct undo_private_data *data = p; in undo_atexit() local
688 err = write_undo_indexes(data, 1); in undo_atexit()
689 io_channel_close(data->undo_file); in undo_atexit()
691 com_err(data->tdb_file, err, "while force-closing undo file"); in undo_atexit()
697 struct undo_private_data *data = NULL; in undo_open() local
708 retval = ext2fs_get_mem(sizeof(struct undo_private_data), &data); in undo_open()
718 io->private_data = data; in undo_open()
724 memset(data, 0, sizeof(struct undo_private_data)); in undo_open()
725 data->magic = EXT2_ET_MAGIC_UNIX_IO_CHANNEL; in undo_open()
726 data->super_blk_num = 1; in undo_open()
727 data->first_key_blk = 2; in undo_open()
728 data->undo_blk_num = 3; in undo_open()
732 &data->real); in undo_open()
736 data->tdb_file = strdup(tdb_file); in undo_open()
737 if (data->tdb_file == NULL) in undo_open()
739 undo_fd = ext2fs_open_file(data->tdb_file, O_RDWR | O_CREAT, in undo_open()
744 retval = undo_io_backing_manager->open(data->tdb_file, in undo_open()
746 &data->undo_file); in undo_open()
750 data->real = NULL; in undo_open()
751 data->undo_file = NULL; in undo_open()
754 if (data->real) in undo_open()
756 (data->real->flags & CHANNEL_FLAGS_DISCARD_ZEROES); in undo_open()
762 if (data->real) in undo_open()
763 undo_err_handler_init(data->real); in undo_open()
765 if (data->undo_file) { in undo_open()
766 retval = try_reopen_undo_file(undo_fd, data); in undo_open()
770 retval = ext2fs_add_exit_fn(undo_atexit, data); in undo_open()
780 ext2fs_remove_exit_fn(undo_atexit, data); in undo_open()
783 if (data && data->undo_file) in undo_open()
784 io_channel_close(data->undo_file); in undo_open()
785 if (data && data->tdb_file) in undo_open()
786 free(data->tdb_file); in undo_open()
787 if (data && data->real) in undo_open()
788 io_channel_close(data->real); in undo_open()
789 if (data) in undo_open()
790 ext2fs_free_mem(&data); in undo_open()
798 struct undo_private_data *data; in undo_close() local
802 data = (struct undo_private_data *) channel->private_data; in undo_close()
803 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); in undo_close()
809 data->hdr.state = ext2fs_cpu_to_le32(E2UNDO_STATE_FINISHED); in undo_close()
810 err = write_undo_indexes(data, 1); in undo_close()
811 ext2fs_remove_exit_fn(undo_atexit, data); in undo_close()
812 if (data->real) in undo_close()
813 retval = io_channel_close(data->real); in undo_close()
814 if (data->tdb_file) in undo_close()
815 free(data->tdb_file); in undo_close()
816 if (data->undo_file) in undo_close()
817 io_channel_close(data->undo_file); in undo_close()
818 ext2fs_free_mem(&data->keyb); in undo_close()
819 if (data->written_block_map) in undo_close()
820 ext2fs_free_generic_bitmap(data->written_block_map); in undo_close()
833 struct undo_private_data *data; in undo_set_blksize() local
837 data = (struct undo_private_data *) channel->private_data; in undo_set_blksize()
838 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); in undo_set_blksize()
843 if (data->real) in undo_set_blksize()
844 retval = io_channel_set_blksize(data->real, blksize); in undo_set_blksize()
848 if (!data->tdb_data_size || !data->tdb_written) in undo_set_blksize()
849 data->tdb_data_size = blksize; in undo_set_blksize()
858 struct undo_private_data *data; in undo_read_blk64() local
861 data = (struct undo_private_data *) channel->private_data; in undo_read_blk64()
862 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); in undo_read_blk64()
864 if (data->real) in undo_read_blk64()
865 retval = io_channel_read_blk64(data->real, block, count, buf); in undo_read_blk64()
879 struct undo_private_data *data; in undo_write_blk64() local
883 data = (struct undo_private_data *) channel->private_data; in undo_write_blk64()
884 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); in undo_write_blk64()
891 if (data->real) in undo_write_blk64()
892 retval = io_channel_write_blk64(data->real, block, count, buf); in undo_write_blk64()
906 struct undo_private_data *data; in undo_write_byte() local
912 data = (struct undo_private_data *) channel->private_data; in undo_write_byte()
913 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); in undo_write_byte()
915 location = offset + data->offset; in undo_write_byte()
928 if (data->real && data->real->manager->write_byte) in undo_write_byte()
929 retval = io_channel_write_byte(data->real, offset, size, buf); in undo_write_byte()
937 struct undo_private_data *data; in undo_discard() local
942 data = (struct undo_private_data *) channel->private_data; in undo_discard()
943 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); in undo_discard()
955 if (data->real) in undo_discard()
956 retval = io_channel_discard(data->real, block, count); in undo_discard()
964 struct undo_private_data *data; in undo_zeroout() local
969 data = (struct undo_private_data *) channel->private_data; in undo_zeroout()
970 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); in undo_zeroout()
982 if (data->real) in undo_zeroout()
983 retval = io_channel_zeroout(data->real, block, count); in undo_zeroout()
992 struct undo_private_data *data; in undo_cache_readahead() local
996 data = (struct undo_private_data *) channel->private_data; in undo_cache_readahead()
997 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); in undo_cache_readahead()
999 if (data->real) in undo_cache_readahead()
1000 retval = io_channel_cache_readahead(data->real, block, count); in undo_cache_readahead()
1006 * Flush data buffers to disk.
1011 struct undo_private_data *data; in undo_flush() local
1014 data = (struct undo_private_data *) channel->private_data; in undo_flush()
1015 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); in undo_flush()
1017 if (data->real) in undo_flush()
1018 retval = io_channel_flush(data->real); in undo_flush()
1027 struct undo_private_data *data; in undo_set_option() local
1032 data = (struct undo_private_data *) channel->private_data; in undo_set_option()
1033 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); in undo_set_option()
1044 if (!data->tdb_data_size || !data->tdb_written) { in undo_set_option()
1045 data->tdb_written = -1; in undo_set_option()
1046 data->tdb_data_size = tmp; in undo_set_option()
1054 if (data->real && data->real->manager->set_option) { in undo_set_option()
1055 retval = data->real->manager->set_option(data->real, in undo_set_option()
1065 data->offset = tmp; in undo_set_option()
1073 struct undo_private_data *data; in undo_get_stats() local
1076 data = (struct undo_private_data *) channel->private_data; in undo_get_stats()
1077 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); in undo_get_stats()
1079 if (data->real) in undo_get_stats()
1080 retval = (data->real->manager->get_stats)(data->real, stats); in undo_get_stats()