Lines Matching refs:ps
167 static int alloc_area(struct pstore *ps) in alloc_area() argument
172 len = ps->store->chunk_size << SECTOR_SHIFT; in alloc_area()
178 ps->area = vmalloc(len); in alloc_area()
179 if (!ps->area) in alloc_area()
182 ps->zero_area = vzalloc(len); in alloc_area()
183 if (!ps->zero_area) in alloc_area()
186 ps->header_area = vmalloc(len); in alloc_area()
187 if (!ps->header_area) in alloc_area()
193 vfree(ps->zero_area); in alloc_area()
196 vfree(ps->area); in alloc_area()
202 static void free_area(struct pstore *ps) in free_area() argument
204 vfree(ps->area); in free_area()
205 ps->area = NULL; in free_area()
206 vfree(ps->zero_area); in free_area()
207 ps->zero_area = NULL; in free_area()
208 vfree(ps->header_area); in free_area()
209 ps->header_area = NULL; in free_area()
229 static int chunk_io(struct pstore *ps, void *area, chunk_t chunk, blk_opf_t opf, in chunk_io() argument
233 .bdev = dm_snap_cow(ps->store->snap)->bdev, in chunk_io()
234 .sector = ps->store->chunk_size * chunk, in chunk_io()
235 .count = ps->store->chunk_size, in chunk_io()
241 .client = ps->io_client, in chunk_io()
257 queue_work(ps->metadata_wq, &req.work); in chunk_io()
258 flush_workqueue(ps->metadata_wq); in chunk_io()
267 static chunk_t area_location(struct pstore *ps, chunk_t area) in area_location() argument
269 return NUM_SNAPSHOT_HDR_CHUNKS + ((ps->exceptions_per_area + 1) * area); in area_location()
272 static void skip_metadata(struct pstore *ps) in skip_metadata() argument
274 uint32_t stride = ps->exceptions_per_area + 1; in skip_metadata()
275 chunk_t next_free = ps->next_free; in skip_metadata()
277 ps->next_free++; in skip_metadata()
284 static int area_io(struct pstore *ps, blk_opf_t opf) in area_io() argument
286 chunk_t chunk = area_location(ps, ps->current_area); in area_io()
288 return chunk_io(ps, ps->area, chunk, opf, 0); in area_io()
291 static void zero_memory_area(struct pstore *ps) in zero_memory_area() argument
293 memset(ps->area, 0, ps->store->chunk_size << SECTOR_SHIFT); in zero_memory_area()
296 static int zero_disk_area(struct pstore *ps, chunk_t area) in zero_disk_area() argument
298 return chunk_io(ps, ps->zero_area, area_location(ps, area), in zero_disk_area()
302 static int read_header(struct pstore *ps, int *new_snapshot) in read_header() argument
314 if (!ps->store->chunk_size) { in read_header()
315 ps->store->chunk_size = max(DM_CHUNK_SIZE_DEFAULT_SECTORS, in read_header()
316 bdev_logical_block_size(dm_snap_cow(ps->store->snap)-> in read_header()
318 ps->store->chunk_mask = ps->store->chunk_size - 1; in read_header()
319 ps->store->chunk_shift = __ffs(ps->store->chunk_size); in read_header()
323 ps->io_client = dm_io_client_create(); in read_header()
324 if (IS_ERR(ps->io_client)) in read_header()
325 return PTR_ERR(ps->io_client); in read_header()
327 r = alloc_area(ps); in read_header()
331 r = chunk_io(ps, ps->header_area, 0, REQ_OP_READ, 1); in read_header()
335 dh = ps->header_area; in read_header()
349 ps->valid = le32_to_cpu(dh->valid); in read_header()
350 ps->version = le32_to_cpu(dh->version); in read_header()
353 if (ps->store->chunk_size == chunk_size) in read_header()
359 chunk_size, ps->store->chunk_size); in read_header()
362 free_area(ps); in read_header()
364 r = dm_exception_store_set_chunk_size(ps->store, chunk_size, in read_header()
372 r = alloc_area(ps); in read_header()
376 free_area(ps); in read_header()
380 static int write_header(struct pstore *ps) in write_header() argument
384 memset(ps->header_area, 0, ps->store->chunk_size << SECTOR_SHIFT); in write_header()
386 dh = ps->header_area; in write_header()
388 dh->valid = cpu_to_le32(ps->valid); in write_header()
389 dh->version = cpu_to_le32(ps->version); in write_header()
390 dh->chunk_size = cpu_to_le32(ps->store->chunk_size); in write_header()
392 return chunk_io(ps, ps->header_area, 0, REQ_OP_WRITE, 1); in write_header()
398 static struct disk_exception *get_exception(struct pstore *ps, void *ps_area, in get_exception() argument
401 BUG_ON(index >= ps->exceptions_per_area); in get_exception()
406 static void read_exception(struct pstore *ps, void *ps_area, in read_exception() argument
409 struct disk_exception *de = get_exception(ps, ps_area, index); in read_exception()
416 static void write_exception(struct pstore *ps, in write_exception() argument
419 struct disk_exception *de = get_exception(ps, ps->area, index); in write_exception()
426 static void clear_exception(struct pstore *ps, uint32_t index) in clear_exception() argument
428 struct disk_exception *de = get_exception(ps, ps->area, index); in clear_exception()
440 static int insert_exceptions(struct pstore *ps, void *ps_area, in insert_exceptions() argument
453 for (i = 0; i < ps->exceptions_per_area; i++) { in insert_exceptions()
454 read_exception(ps, ps_area, i, &e); in insert_exceptions()
463 ps->current_committed = i; in insert_exceptions()
471 if (ps->next_free <= e.new_chunk) in insert_exceptions()
472 ps->next_free = e.new_chunk + 1; in insert_exceptions()
485 static int read_exceptions(struct pstore *ps, in read_exceptions() argument
494 client = dm_bufio_client_create(dm_snap_cow(ps->store->snap)->bdev, in read_exceptions()
495 ps->store->chunk_size << SECTOR_SHIFT, in read_exceptions()
510 for (ps->current_area = 0; full; ps->current_area++) { in read_exceptions()
515 if (unlikely(prefetch_area < ps->current_area)) in read_exceptions()
516 prefetch_area = ps->current_area; in read_exceptions()
519 chunk_t pf_chunk = area_location(ps, prefetch_area); in read_exceptions()
526 } while (prefetch_area <= ps->current_area + DM_PREFETCH_CHUNKS); in read_exceptions()
528 chunk = area_location(ps, ps->current_area); in read_exceptions()
536 r = insert_exceptions(ps, area, callback, callback_context, in read_exceptions()
540 memcpy(ps->area, area, ps->store->chunk_size << SECTOR_SHIFT); in read_exceptions()
550 ps->current_area--; in read_exceptions()
552 skip_metadata(ps); in read_exceptions()
572 struct pstore *ps = get_info(store); in persistent_usage() local
574 *sectors_allocated = ps->next_free * store->chunk_size; in persistent_usage()
582 *metadata_sectors = (ps->current_area + 1 + NUM_SNAPSHOT_HDR_CHUNKS) * in persistent_usage()
588 struct pstore *ps = get_info(store); in persistent_dtr() local
590 destroy_workqueue(ps->metadata_wq); in persistent_dtr()
593 if (ps->io_client) in persistent_dtr()
594 dm_io_client_destroy(ps->io_client); in persistent_dtr()
595 free_area(ps); in persistent_dtr()
598 kvfree(ps->callbacks); in persistent_dtr()
600 kfree(ps); in persistent_dtr()
609 struct pstore *ps = get_info(store); in persistent_read_metadata() local
614 r = read_header(ps, &new_snapshot); in persistent_read_metadata()
621 ps->exceptions_per_area = (ps->store->chunk_size << SECTOR_SHIFT) / in persistent_read_metadata()
623 ps->callbacks = kvcalloc(ps->exceptions_per_area, in persistent_read_metadata()
624 sizeof(*ps->callbacks), GFP_KERNEL); in persistent_read_metadata()
625 if (!ps->callbacks) in persistent_read_metadata()
632 r = write_header(ps); in persistent_read_metadata()
638 ps->current_area = 0; in persistent_read_metadata()
639 zero_memory_area(ps); in persistent_read_metadata()
640 r = zero_disk_area(ps, 0); in persistent_read_metadata()
648 if (ps->version != SNAPSHOT_DISK_VERSION) { in persistent_read_metadata()
650 ps->version); in persistent_read_metadata()
657 if (!ps->valid) in persistent_read_metadata()
663 r = read_exceptions(ps, callback, callback_context); in persistent_read_metadata()
671 struct pstore *ps = get_info(store); in persistent_prepare_exception() local
675 if (size < ((ps->next_free + 1) * store->chunk_size)) in persistent_prepare_exception()
678 e->new_chunk = ps->next_free; in persistent_prepare_exception()
684 ps->next_free++; in persistent_prepare_exception()
685 skip_metadata(ps); in persistent_prepare_exception()
687 atomic_inc(&ps->pending_count); in persistent_prepare_exception()
697 struct pstore *ps = get_info(store); in persistent_commit_exception() local
702 ps->valid = 0; in persistent_commit_exception()
706 write_exception(ps, ps->current_committed++, &ce); in persistent_commit_exception()
714 cb = ps->callbacks + ps->callback_count++; in persistent_commit_exception()
722 if (!atomic_dec_and_test(&ps->pending_count) && in persistent_commit_exception()
723 (ps->current_committed != ps->exceptions_per_area)) in persistent_commit_exception()
729 if ((ps->current_committed == ps->exceptions_per_area) && in persistent_commit_exception()
730 zero_disk_area(ps, ps->current_area + 1)) in persistent_commit_exception()
731 ps->valid = 0; in persistent_commit_exception()
736 if (ps->valid && area_io(ps, REQ_OP_WRITE | REQ_PREFLUSH | REQ_FUA | in persistent_commit_exception()
738 ps->valid = 0; in persistent_commit_exception()
743 if (ps->current_committed == ps->exceptions_per_area) { in persistent_commit_exception()
744 ps->current_committed = 0; in persistent_commit_exception()
745 ps->current_area++; in persistent_commit_exception()
746 zero_memory_area(ps); in persistent_commit_exception()
749 for (i = 0; i < ps->callback_count; i++) { in persistent_commit_exception()
750 cb = ps->callbacks + i; in persistent_commit_exception()
751 cb->callback(cb->context, ps->valid); in persistent_commit_exception()
754 ps->callback_count = 0; in persistent_commit_exception()
761 struct pstore *ps = get_info(store); in persistent_prepare_merge() local
769 if (!ps->current_committed) { in persistent_prepare_merge()
773 if (!ps->current_area) in persistent_prepare_merge()
776 ps->current_area--; in persistent_prepare_merge()
777 r = area_io(ps, REQ_OP_READ); in persistent_prepare_merge()
780 ps->current_committed = ps->exceptions_per_area; in persistent_prepare_merge()
783 read_exception(ps, ps->area, ps->current_committed - 1, &ce); in persistent_prepare_merge()
791 for (nr_consecutive = 1; nr_consecutive < ps->current_committed; in persistent_prepare_merge()
793 read_exception(ps, ps->area, in persistent_prepare_merge()
794 ps->current_committed - 1 - nr_consecutive, &ce); in persistent_prepare_merge()
807 struct pstore *ps = get_info(store); in persistent_commit_merge() local
809 BUG_ON(nr_merged > ps->current_committed); in persistent_commit_merge()
812 clear_exception(ps, ps->current_committed - 1 - i); in persistent_commit_merge()
814 r = area_io(ps, REQ_OP_WRITE | REQ_PREFLUSH | REQ_FUA); in persistent_commit_merge()
818 ps->current_committed -= nr_merged; in persistent_commit_merge()
830 ps->next_free = area_location(ps, ps->current_area) + in persistent_commit_merge()
831 ps->current_committed + 1; in persistent_commit_merge()
838 struct pstore *ps = get_info(store); in persistent_drop_snapshot() local
840 ps->valid = 0; in persistent_drop_snapshot()
841 if (write_header(ps)) in persistent_drop_snapshot()
847 struct pstore *ps; in persistent_ctr() local
851 ps = kzalloc(sizeof(*ps), GFP_KERNEL); in persistent_ctr()
852 if (!ps) in persistent_ctr()
855 ps->store = store; in persistent_ctr()
856 ps->valid = 1; in persistent_ctr()
857 ps->version = SNAPSHOT_DISK_VERSION; in persistent_ctr()
858 ps->area = NULL; in persistent_ctr()
859 ps->zero_area = NULL; in persistent_ctr()
860 ps->header_area = NULL; in persistent_ctr()
861 ps->next_free = NUM_SNAPSHOT_HDR_CHUNKS + 1; /* header and 1st area */ in persistent_ctr()
862 ps->current_committed = 0; in persistent_ctr()
864 ps->callback_count = 0; in persistent_ctr()
865 atomic_set(&ps->pending_count, 0); in persistent_ctr()
866 ps->callbacks = NULL; in persistent_ctr()
868 ps->metadata_wq = alloc_workqueue("ksnaphd", WQ_MEM_RECLAIM, 0); in persistent_ctr()
869 if (!ps->metadata_wq) { in persistent_ctr()
886 store->context = ps; in persistent_ctr()
891 destroy_workqueue(ps->metadata_wq); in persistent_ctr()
893 kfree(ps); in persistent_ctr()