Lines Matching refs:ps
166 static int alloc_area(struct pstore *ps) in alloc_area() argument
171 len = ps->store->chunk_size << SECTOR_SHIFT; in alloc_area()
177 ps->area = vmalloc(len); in alloc_area()
178 if (!ps->area) in alloc_area()
181 ps->zero_area = vzalloc(len); in alloc_area()
182 if (!ps->zero_area) in alloc_area()
185 ps->header_area = vmalloc(len); in alloc_area()
186 if (!ps->header_area) in alloc_area()
192 vfree(ps->zero_area); in alloc_area()
195 vfree(ps->area); in alloc_area()
201 static void free_area(struct pstore *ps) in free_area() argument
203 vfree(ps->area); in free_area()
204 ps->area = NULL; in free_area()
205 vfree(ps->zero_area); in free_area()
206 ps->zero_area = NULL; in free_area()
207 vfree(ps->header_area); in free_area()
208 ps->header_area = NULL; in free_area()
228 static int chunk_io(struct pstore *ps, void *area, chunk_t chunk, int rw, in chunk_io() argument
232 .bdev = dm_snap_cow(ps->store->snap)->bdev, in chunk_io()
233 .sector = ps->store->chunk_size * chunk, in chunk_io()
234 .count = ps->store->chunk_size, in chunk_io()
240 .client = ps->io_client, in chunk_io()
256 queue_work(ps->metadata_wq, &req.work); in chunk_io()
257 flush_workqueue(ps->metadata_wq); in chunk_io()
266 static chunk_t area_location(struct pstore *ps, chunk_t area) in area_location() argument
268 return NUM_SNAPSHOT_HDR_CHUNKS + ((ps->exceptions_per_area + 1) * area); in area_location()
271 static void skip_metadata(struct pstore *ps) in skip_metadata() argument
273 uint32_t stride = ps->exceptions_per_area + 1; in skip_metadata()
274 chunk_t next_free = ps->next_free; in skip_metadata()
276 ps->next_free++; in skip_metadata()
283 static int area_io(struct pstore *ps, int rw) in area_io() argument
288 chunk = area_location(ps, ps->current_area); in area_io()
290 r = chunk_io(ps, ps->area, chunk, rw, 0); in area_io()
297 static void zero_memory_area(struct pstore *ps) in zero_memory_area() argument
299 memset(ps->area, 0, ps->store->chunk_size << SECTOR_SHIFT); in zero_memory_area()
302 static int zero_disk_area(struct pstore *ps, chunk_t area) in zero_disk_area() argument
304 return chunk_io(ps, ps->zero_area, area_location(ps, area), WRITE, 0); in zero_disk_area()
307 static int read_header(struct pstore *ps, int *new_snapshot) in read_header() argument
319 if (!ps->store->chunk_size) { in read_header()
320 ps->store->chunk_size = max(DM_CHUNK_SIZE_DEFAULT_SECTORS, in read_header()
321 bdev_logical_block_size(dm_snap_cow(ps->store->snap)-> in read_header()
323 ps->store->chunk_mask = ps->store->chunk_size - 1; in read_header()
324 ps->store->chunk_shift = ffs(ps->store->chunk_size) - 1; in read_header()
328 ps->io_client = dm_io_client_create(); in read_header()
329 if (IS_ERR(ps->io_client)) in read_header()
330 return PTR_ERR(ps->io_client); in read_header()
332 r = alloc_area(ps); in read_header()
336 r = chunk_io(ps, ps->header_area, 0, READ, 1); in read_header()
340 dh = ps->header_area; in read_header()
354 ps->valid = le32_to_cpu(dh->valid); in read_header()
355 ps->version = le32_to_cpu(dh->version); in read_header()
358 if (ps->store->chunk_size == chunk_size) in read_header()
364 chunk_size, ps->store->chunk_size); in read_header()
367 free_area(ps); in read_header()
369 r = dm_exception_store_set_chunk_size(ps->store, chunk_size, in read_header()
377 r = alloc_area(ps); in read_header()
381 free_area(ps); in read_header()
385 static int write_header(struct pstore *ps) in write_header() argument
389 memset(ps->header_area, 0, ps->store->chunk_size << SECTOR_SHIFT); in write_header()
391 dh = ps->header_area; in write_header()
393 dh->valid = cpu_to_le32(ps->valid); in write_header()
394 dh->version = cpu_to_le32(ps->version); in write_header()
395 dh->chunk_size = cpu_to_le32(ps->store->chunk_size); in write_header()
397 return chunk_io(ps, ps->header_area, 0, WRITE, 1); in write_header()
403 static struct disk_exception *get_exception(struct pstore *ps, void *ps_area, in get_exception() argument
406 BUG_ON(index >= ps->exceptions_per_area); in get_exception()
411 static void read_exception(struct pstore *ps, void *ps_area, in read_exception() argument
414 struct disk_exception *de = get_exception(ps, ps_area, index); in read_exception()
421 static void write_exception(struct pstore *ps, in write_exception() argument
424 struct disk_exception *de = get_exception(ps, ps->area, index); in write_exception()
431 static void clear_exception(struct pstore *ps, uint32_t index) in clear_exception() argument
433 struct disk_exception *de = get_exception(ps, ps->area, index); in clear_exception()
445 static int insert_exceptions(struct pstore *ps, void *ps_area, in insert_exceptions() argument
458 for (i = 0; i < ps->exceptions_per_area; i++) { in insert_exceptions()
459 read_exception(ps, ps_area, i, &e); in insert_exceptions()
468 ps->current_committed = i; in insert_exceptions()
476 if (ps->next_free <= e.new_chunk) in insert_exceptions()
477 ps->next_free = e.new_chunk + 1; in insert_exceptions()
490 static int read_exceptions(struct pstore *ps, in read_exceptions() argument
499 client = dm_bufio_client_create(dm_snap_cow(ps->store->snap)->bdev, in read_exceptions()
500 ps->store->chunk_size << SECTOR_SHIFT, in read_exceptions()
515 for (ps->current_area = 0; full; ps->current_area++) { in read_exceptions()
520 if (unlikely(prefetch_area < ps->current_area)) in read_exceptions()
521 prefetch_area = ps->current_area; in read_exceptions()
524 chunk_t pf_chunk = area_location(ps, prefetch_area); in read_exceptions()
531 } while (prefetch_area <= ps->current_area + DM_PREFETCH_CHUNKS); in read_exceptions()
533 chunk = area_location(ps, ps->current_area); in read_exceptions()
541 r = insert_exceptions(ps, area, callback, callback_context, in read_exceptions()
545 memcpy(ps->area, area, ps->store->chunk_size << SECTOR_SHIFT); in read_exceptions()
555 ps->current_area--; in read_exceptions()
557 skip_metadata(ps); in read_exceptions()
577 struct pstore *ps = get_info(store); in persistent_usage() local
579 *sectors_allocated = ps->next_free * store->chunk_size; in persistent_usage()
587 *metadata_sectors = (ps->current_area + 1 + NUM_SNAPSHOT_HDR_CHUNKS) * in persistent_usage()
593 struct pstore *ps = get_info(store); in persistent_dtr() local
595 destroy_workqueue(ps->metadata_wq); in persistent_dtr()
598 if (ps->io_client) in persistent_dtr()
599 dm_io_client_destroy(ps->io_client); in persistent_dtr()
600 free_area(ps); in persistent_dtr()
603 vfree(ps->callbacks); in persistent_dtr()
605 kfree(ps); in persistent_dtr()
614 struct pstore *ps = get_info(store); in persistent_read_metadata() local
619 r = read_header(ps, &new_snapshot); in persistent_read_metadata()
626 ps->exceptions_per_area = (ps->store->chunk_size << SECTOR_SHIFT) / in persistent_read_metadata()
628 ps->callbacks = dm_vcalloc(ps->exceptions_per_area, in persistent_read_metadata()
629 sizeof(*ps->callbacks)); in persistent_read_metadata()
630 if (!ps->callbacks) in persistent_read_metadata()
637 r = write_header(ps); in persistent_read_metadata()
643 ps->current_area = 0; in persistent_read_metadata()
644 zero_memory_area(ps); in persistent_read_metadata()
645 r = zero_disk_area(ps, 0); in persistent_read_metadata()
653 if (ps->version != SNAPSHOT_DISK_VERSION) { in persistent_read_metadata()
655 ps->version); in persistent_read_metadata()
662 if (!ps->valid) in persistent_read_metadata()
668 r = read_exceptions(ps, callback, callback_context); in persistent_read_metadata()
676 struct pstore *ps = get_info(store); in persistent_prepare_exception() local
680 if (size < ((ps->next_free + 1) * store->chunk_size)) in persistent_prepare_exception()
683 e->new_chunk = ps->next_free; in persistent_prepare_exception()
689 ps->next_free++; in persistent_prepare_exception()
690 skip_metadata(ps); in persistent_prepare_exception()
692 atomic_inc(&ps->pending_count); in persistent_prepare_exception()
702 struct pstore *ps = get_info(store); in persistent_commit_exception() local
707 ps->valid = 0; in persistent_commit_exception()
711 write_exception(ps, ps->current_committed++, &ce); in persistent_commit_exception()
719 cb = ps->callbacks + ps->callback_count++; in persistent_commit_exception()
727 if (!atomic_dec_and_test(&ps->pending_count) && in persistent_commit_exception()
728 (ps->current_committed != ps->exceptions_per_area)) in persistent_commit_exception()
734 if ((ps->current_committed == ps->exceptions_per_area) && in persistent_commit_exception()
735 zero_disk_area(ps, ps->current_area + 1)) in persistent_commit_exception()
736 ps->valid = 0; in persistent_commit_exception()
741 if (ps->valid && area_io(ps, WRITE_FLUSH_FUA)) in persistent_commit_exception()
742 ps->valid = 0; in persistent_commit_exception()
747 if (ps->current_committed == ps->exceptions_per_area) { in persistent_commit_exception()
748 ps->current_committed = 0; in persistent_commit_exception()
749 ps->current_area++; in persistent_commit_exception()
750 zero_memory_area(ps); in persistent_commit_exception()
753 for (i = 0; i < ps->callback_count; i++) { in persistent_commit_exception()
754 cb = ps->callbacks + i; in persistent_commit_exception()
755 cb->callback(cb->context, ps->valid); in persistent_commit_exception()
758 ps->callback_count = 0; in persistent_commit_exception()
765 struct pstore *ps = get_info(store); in persistent_prepare_merge() local
773 if (!ps->current_committed) { in persistent_prepare_merge()
777 if (!ps->current_area) in persistent_prepare_merge()
780 ps->current_area--; in persistent_prepare_merge()
781 r = area_io(ps, READ); in persistent_prepare_merge()
784 ps->current_committed = ps->exceptions_per_area; in persistent_prepare_merge()
787 read_exception(ps, ps->area, ps->current_committed - 1, &ce); in persistent_prepare_merge()
795 for (nr_consecutive = 1; nr_consecutive < ps->current_committed; in persistent_prepare_merge()
797 read_exception(ps, ps->area, in persistent_prepare_merge()
798 ps->current_committed - 1 - nr_consecutive, &ce); in persistent_prepare_merge()
811 struct pstore *ps = get_info(store); in persistent_commit_merge() local
813 BUG_ON(nr_merged > ps->current_committed); in persistent_commit_merge()
816 clear_exception(ps, ps->current_committed - 1 - i); in persistent_commit_merge()
818 r = area_io(ps, WRITE_FLUSH_FUA); in persistent_commit_merge()
822 ps->current_committed -= nr_merged; in persistent_commit_merge()
834 ps->next_free = area_location(ps, ps->current_area) + in persistent_commit_merge()
835 ps->current_committed + 1; in persistent_commit_merge()
842 struct pstore *ps = get_info(store); in persistent_drop_snapshot() local
844 ps->valid = 0; in persistent_drop_snapshot()
845 if (write_header(ps)) in persistent_drop_snapshot()
852 struct pstore *ps; in persistent_ctr() local
855 ps = kzalloc(sizeof(*ps), GFP_KERNEL); in persistent_ctr()
856 if (!ps) in persistent_ctr()
859 ps->store = store; in persistent_ctr()
860 ps->valid = 1; in persistent_ctr()
861 ps->version = SNAPSHOT_DISK_VERSION; in persistent_ctr()
862 ps->area = NULL; in persistent_ctr()
863 ps->zero_area = NULL; in persistent_ctr()
864 ps->header_area = NULL; in persistent_ctr()
865 ps->next_free = NUM_SNAPSHOT_HDR_CHUNKS + 1; /* header and 1st area */ in persistent_ctr()
866 ps->current_committed = 0; in persistent_ctr()
868 ps->callback_count = 0; in persistent_ctr()
869 atomic_set(&ps->pending_count, 0); in persistent_ctr()
870 ps->callbacks = NULL; in persistent_ctr()
872 ps->metadata_wq = alloc_workqueue("ksnaphd", WQ_MEM_RECLAIM, 0); in persistent_ctr()
873 if (!ps->metadata_wq) { in persistent_ctr()
874 kfree(ps); in persistent_ctr()
879 store->context = ps; in persistent_ctr()