Lines Matching full: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, int op, 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()
242 .client = ps->io_client, in chunk_io()
258 queue_work(ps->metadata_wq, &req.work); in chunk_io()
259 flush_workqueue(ps->metadata_wq); in chunk_io()
268 static chunk_t area_location(struct pstore *ps, chunk_t area) in area_location() argument
270 return NUM_SNAPSHOT_HDR_CHUNKS + ((ps->exceptions_per_area + 1) * area); in area_location()
273 static void skip_metadata(struct pstore *ps) in skip_metadata() argument
275 uint32_t stride = ps->exceptions_per_area + 1; in skip_metadata()
276 chunk_t next_free = ps->next_free; in skip_metadata()
278 ps->next_free++; in skip_metadata()
285 static int area_io(struct pstore *ps, int op, int op_flags) in area_io() argument
287 chunk_t chunk = area_location(ps, ps->current_area); in area_io()
289 return chunk_io(ps, ps->area, chunk, op, op_flags, 0); in area_io()
292 static void zero_memory_area(struct pstore *ps) in zero_memory_area() argument
294 memset(ps->area, 0, ps->store->chunk_size << SECTOR_SHIFT); in zero_memory_area()
297 static int zero_disk_area(struct pstore *ps, chunk_t area) in zero_disk_area() argument
299 return chunk_io(ps, ps->zero_area, area_location(ps, area), in zero_disk_area()
303 static int read_header(struct pstore *ps, int *new_snapshot) in read_header() argument
315 if (!ps->store->chunk_size) { in read_header()
316 ps->store->chunk_size = max(DM_CHUNK_SIZE_DEFAULT_SECTORS, in read_header()
317 bdev_logical_block_size(dm_snap_cow(ps->store->snap)-> in read_header()
319 ps->store->chunk_mask = ps->store->chunk_size - 1; in read_header()
320 ps->store->chunk_shift = __ffs(ps->store->chunk_size); in read_header()
324 ps->io_client = dm_io_client_create(); in read_header()
325 if (IS_ERR(ps->io_client)) in read_header()
326 return PTR_ERR(ps->io_client); in read_header()
328 r = alloc_area(ps); in read_header()
332 r = chunk_io(ps, ps->header_area, 0, REQ_OP_READ, 0, 1); in read_header()
336 dh = ps->header_area; in read_header()
350 ps->valid = le32_to_cpu(dh->valid); in read_header()
351 ps->version = le32_to_cpu(dh->version); in read_header()
354 if (ps->store->chunk_size == chunk_size) in read_header()
360 chunk_size, ps->store->chunk_size); in read_header()
363 free_area(ps); in read_header()
365 r = dm_exception_store_set_chunk_size(ps->store, chunk_size, in read_header()
373 r = alloc_area(ps); in read_header()
377 free_area(ps); in read_header()
381 static int write_header(struct pstore *ps) in write_header() argument
385 memset(ps->header_area, 0, ps->store->chunk_size << SECTOR_SHIFT); in write_header()
387 dh = ps->header_area; in write_header()
389 dh->valid = cpu_to_le32(ps->valid); in write_header()
390 dh->version = cpu_to_le32(ps->version); in write_header()
391 dh->chunk_size = cpu_to_le32(ps->store->chunk_size); in write_header()
393 return chunk_io(ps, ps->header_area, 0, REQ_OP_WRITE, 0, 1); in write_header()
399 static struct disk_exception *get_exception(struct pstore *ps, void *ps_area, in get_exception() argument
402 BUG_ON(index >= ps->exceptions_per_area); in get_exception()
407 static void read_exception(struct pstore *ps, void *ps_area, in read_exception() argument
410 struct disk_exception *de = get_exception(ps, ps_area, index); in read_exception()
417 static void write_exception(struct pstore *ps, in write_exception() argument
420 struct disk_exception *de = get_exception(ps, ps->area, index); in write_exception()
427 static void clear_exception(struct pstore *ps, uint32_t index) in clear_exception() argument
429 struct disk_exception *de = get_exception(ps, ps->area, index); in clear_exception()
441 static int insert_exceptions(struct pstore *ps, void *ps_area, in insert_exceptions() argument
454 for (i = 0; i < ps->exceptions_per_area; i++) { in insert_exceptions()
455 read_exception(ps, ps_area, i, &e); in insert_exceptions()
464 ps->current_committed = i; in insert_exceptions()
472 if (ps->next_free <= e.new_chunk) in insert_exceptions()
473 ps->next_free = e.new_chunk + 1; in insert_exceptions()
486 static int read_exceptions(struct pstore *ps, in read_exceptions() argument
495 client = dm_bufio_client_create(dm_snap_cow(ps->store->snap)->bdev, in read_exceptions()
496 ps->store->chunk_size << SECTOR_SHIFT, in read_exceptions()
511 for (ps->current_area = 0; full; ps->current_area++) { in read_exceptions()
516 if (unlikely(prefetch_area < ps->current_area)) in read_exceptions()
517 prefetch_area = ps->current_area; in read_exceptions()
520 chunk_t pf_chunk = area_location(ps, prefetch_area); in read_exceptions()
527 } while (prefetch_area <= ps->current_area + DM_PREFETCH_CHUNKS); in read_exceptions()
529 chunk = area_location(ps, ps->current_area); in read_exceptions()
537 r = insert_exceptions(ps, area, callback, callback_context, in read_exceptions()
541 memcpy(ps->area, area, ps->store->chunk_size << SECTOR_SHIFT); in read_exceptions()
551 ps->current_area--; in read_exceptions()
553 skip_metadata(ps); in read_exceptions()
573 struct pstore *ps = get_info(store); in persistent_usage() local
575 *sectors_allocated = ps->next_free * store->chunk_size; in persistent_usage()
580 * Then there are (ps->current_area + 1) metadata chunks, each one in persistent_usage()
581 * separated from the next by ps->exceptions_per_area data chunks. in persistent_usage()
583 *metadata_sectors = (ps->current_area + 1 + NUM_SNAPSHOT_HDR_CHUNKS) * in persistent_usage()
589 struct pstore *ps = get_info(store); in persistent_dtr() local
591 destroy_workqueue(ps->metadata_wq); in persistent_dtr()
594 if (ps->io_client) in persistent_dtr()
595 dm_io_client_destroy(ps->io_client); in persistent_dtr()
596 free_area(ps); in persistent_dtr()
599 vfree(ps->callbacks); in persistent_dtr()
601 kfree(ps); in persistent_dtr()
610 struct pstore *ps = get_info(store); in persistent_read_metadata() local
615 r = read_header(ps, &new_snapshot); in persistent_read_metadata()
622 ps->exceptions_per_area = (ps->store->chunk_size << SECTOR_SHIFT) / in persistent_read_metadata()
624 ps->callbacks = dm_vcalloc(ps->exceptions_per_area, in persistent_read_metadata()
625 sizeof(*ps->callbacks)); in persistent_read_metadata()
626 if (!ps->callbacks) in persistent_read_metadata()
633 r = write_header(ps); in persistent_read_metadata()
639 ps->current_area = 0; in persistent_read_metadata()
640 zero_memory_area(ps); in persistent_read_metadata()
641 r = zero_disk_area(ps, 0); in persistent_read_metadata()
649 if (ps->version != SNAPSHOT_DISK_VERSION) { in persistent_read_metadata()
651 ps->version); in persistent_read_metadata()
658 if (!ps->valid) in persistent_read_metadata()
664 r = read_exceptions(ps, callback, callback_context); in persistent_read_metadata()
672 struct pstore *ps = get_info(store); in persistent_prepare_exception() local
676 if (size < ((ps->next_free + 1) * store->chunk_size)) in persistent_prepare_exception()
679 e->new_chunk = ps->next_free; in persistent_prepare_exception()
685 ps->next_free++; in persistent_prepare_exception()
686 skip_metadata(ps); in persistent_prepare_exception()
688 atomic_inc(&ps->pending_count); in persistent_prepare_exception()
698 struct pstore *ps = get_info(store); in persistent_commit_exception() local
703 ps->valid = 0; in persistent_commit_exception()
707 write_exception(ps, ps->current_committed++, &ce); in persistent_commit_exception()
715 cb = ps->callbacks + ps->callback_count++; in persistent_commit_exception()
723 if (!atomic_dec_and_test(&ps->pending_count) && in persistent_commit_exception()
724 (ps->current_committed != ps->exceptions_per_area)) in persistent_commit_exception()
730 if ((ps->current_committed == ps->exceptions_per_area) && in persistent_commit_exception()
731 zero_disk_area(ps, ps->current_area + 1)) in persistent_commit_exception()
732 ps->valid = 0; in persistent_commit_exception()
737 if (ps->valid && area_io(ps, REQ_OP_WRITE, in persistent_commit_exception()
739 ps->valid = 0; in persistent_commit_exception()
744 if (ps->current_committed == ps->exceptions_per_area) { in persistent_commit_exception()
745 ps->current_committed = 0; in persistent_commit_exception()
746 ps->current_area++; in persistent_commit_exception()
747 zero_memory_area(ps); in persistent_commit_exception()
750 for (i = 0; i < ps->callback_count; i++) { in persistent_commit_exception()
751 cb = ps->callbacks + i; in persistent_commit_exception()
752 cb->callback(cb->context, ps->valid); in persistent_commit_exception()
755 ps->callback_count = 0; in persistent_commit_exception()
762 struct pstore *ps = get_info(store); in persistent_prepare_merge() local
770 if (!ps->current_committed) { in persistent_prepare_merge()
774 if (!ps->current_area) in persistent_prepare_merge()
777 ps->current_area--; in persistent_prepare_merge()
778 r = area_io(ps, REQ_OP_READ, 0); in persistent_prepare_merge()
781 ps->current_committed = ps->exceptions_per_area; in persistent_prepare_merge()
784 read_exception(ps, ps->area, ps->current_committed - 1, &ce); in persistent_prepare_merge()
792 for (nr_consecutive = 1; nr_consecutive < ps->current_committed; in persistent_prepare_merge()
794 read_exception(ps, ps->area, in persistent_prepare_merge()
795 ps->current_committed - 1 - nr_consecutive, &ce); in persistent_prepare_merge()
808 struct pstore *ps = get_info(store); in persistent_commit_merge() local
810 BUG_ON(nr_merged > ps->current_committed); in persistent_commit_merge()
813 clear_exception(ps, ps->current_committed - 1 - i); in persistent_commit_merge()
815 r = area_io(ps, REQ_OP_WRITE, REQ_PREFLUSH | REQ_FUA); in persistent_commit_merge()
819 ps->current_committed -= nr_merged; in persistent_commit_merge()
822 * At this stage, only persistent_usage() uses ps->next_free, so in persistent_commit_merge()
823 * we make no attempt to keep ps->next_free strictly accurate in persistent_commit_merge()
828 * ps->current_area does not get reduced by prepare_merge() until in persistent_commit_merge()
831 ps->next_free = area_location(ps, ps->current_area) + in persistent_commit_merge()
832 ps->current_committed + 1; in persistent_commit_merge()
839 struct pstore *ps = get_info(store); in persistent_drop_snapshot() local
841 ps->valid = 0; in persistent_drop_snapshot()
842 if (write_header(ps)) in persistent_drop_snapshot()
848 struct pstore *ps; in persistent_ctr() local
852 ps = kzalloc(sizeof(*ps), GFP_KERNEL); in persistent_ctr()
853 if (!ps) in persistent_ctr()
856 ps->store = store; in persistent_ctr()
857 ps->valid = 1; in persistent_ctr()
858 ps->version = SNAPSHOT_DISK_VERSION; in persistent_ctr()
859 ps->area = NULL; in persistent_ctr()
860 ps->zero_area = NULL; in persistent_ctr()
861 ps->header_area = NULL; in persistent_ctr()
862 ps->next_free = NUM_SNAPSHOT_HDR_CHUNKS + 1; /* header and 1st area */ in persistent_ctr()
863 ps->current_committed = 0; in persistent_ctr()
865 ps->callback_count = 0; in persistent_ctr()
866 atomic_set(&ps->pending_count, 0); in persistent_ctr()
867 ps->callbacks = NULL; in persistent_ctr()
869 ps->metadata_wq = alloc_workqueue("ksnaphd", WQ_MEM_RECLAIM, 0); in persistent_ctr()
870 if (!ps->metadata_wq) { in persistent_ctr()
887 store->context = ps; in persistent_ctr()
892 destroy_workqueue(ps->metadata_wq); in persistent_ctr()
894 kfree(ps); in persistent_ctr()