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, int rw, 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, int rw) in area_io() argument
289 chunk = area_location(ps, ps->current_area); in area_io()
291 r = chunk_io(ps, ps->area, chunk, rw, 0); in area_io()
298 static void zero_memory_area(struct pstore *ps) in zero_memory_area() argument
300 memset(ps->area, 0, ps->store->chunk_size << SECTOR_SHIFT); in zero_memory_area()
303 static int zero_disk_area(struct pstore *ps, chunk_t area) in zero_disk_area() argument
305 return chunk_io(ps, ps->zero_area, area_location(ps, area), WRITE, 0); in zero_disk_area()
308 static int read_header(struct pstore *ps, int *new_snapshot) in read_header() argument
320 if (!ps->store->chunk_size) { in read_header()
321 ps->store->chunk_size = max(DM_CHUNK_SIZE_DEFAULT_SECTORS, in read_header()
322 bdev_logical_block_size(dm_snap_cow(ps->store->snap)-> in read_header()
324 ps->store->chunk_mask = ps->store->chunk_size - 1; in read_header()
325 ps->store->chunk_shift = __ffs(ps->store->chunk_size); in read_header()
329 ps->io_client = dm_io_client_create(); in read_header()
330 if (IS_ERR(ps->io_client)) in read_header()
331 return PTR_ERR(ps->io_client); in read_header()
333 r = alloc_area(ps); in read_header()
337 r = chunk_io(ps, ps->header_area, 0, READ, 1); in read_header()
341 dh = ps->header_area; in read_header()
355 ps->valid = le32_to_cpu(dh->valid); in read_header()
356 ps->version = le32_to_cpu(dh->version); in read_header()
359 if (ps->store->chunk_size == chunk_size) in read_header()
365 chunk_size, ps->store->chunk_size); in read_header()
368 free_area(ps); in read_header()
370 r = dm_exception_store_set_chunk_size(ps->store, chunk_size, in read_header()
378 r = alloc_area(ps); in read_header()
382 free_area(ps); in read_header()
386 static int write_header(struct pstore *ps) in write_header() argument
390 memset(ps->header_area, 0, ps->store->chunk_size << SECTOR_SHIFT); in write_header()
392 dh = ps->header_area; in write_header()
394 dh->valid = cpu_to_le32(ps->valid); in write_header()
395 dh->version = cpu_to_le32(ps->version); in write_header()
396 dh->chunk_size = cpu_to_le32(ps->store->chunk_size); in write_header()
398 return chunk_io(ps, ps->header_area, 0, WRITE, 1); in write_header()
404 static struct disk_exception *get_exception(struct pstore *ps, void *ps_area, in get_exception() argument
407 BUG_ON(index >= ps->exceptions_per_area); in get_exception()
412 static void read_exception(struct pstore *ps, void *ps_area, in read_exception() argument
415 struct disk_exception *de = get_exception(ps, ps_area, index); in read_exception()
422 static void write_exception(struct pstore *ps, in write_exception() argument
425 struct disk_exception *de = get_exception(ps, ps->area, index); in write_exception()
432 static void clear_exception(struct pstore *ps, uint32_t index) in clear_exception() argument
434 struct disk_exception *de = get_exception(ps, ps->area, index); in clear_exception()
446 static int insert_exceptions(struct pstore *ps, void *ps_area, in insert_exceptions() argument
459 for (i = 0; i < ps->exceptions_per_area; i++) { in insert_exceptions()
460 read_exception(ps, ps_area, i, &e); in insert_exceptions()
469 ps->current_committed = i; in insert_exceptions()
477 if (ps->next_free <= e.new_chunk) in insert_exceptions()
478 ps->next_free = e.new_chunk + 1; in insert_exceptions()
491 static int read_exceptions(struct pstore *ps, in read_exceptions() argument
500 client = dm_bufio_client_create(dm_snap_cow(ps->store->snap)->bdev, in read_exceptions()
501 ps->store->chunk_size << SECTOR_SHIFT, in read_exceptions()
516 for (ps->current_area = 0; full; ps->current_area++) { in read_exceptions()
521 if (unlikely(prefetch_area < ps->current_area)) in read_exceptions()
522 prefetch_area = ps->current_area; in read_exceptions()
525 chunk_t pf_chunk = area_location(ps, prefetch_area); in read_exceptions()
532 } while (prefetch_area <= ps->current_area + DM_PREFETCH_CHUNKS); in read_exceptions()
534 chunk = area_location(ps, ps->current_area); in read_exceptions()
542 r = insert_exceptions(ps, area, callback, callback_context, in read_exceptions()
546 memcpy(ps->area, area, ps->store->chunk_size << SECTOR_SHIFT); in read_exceptions()
556 ps->current_area--; in read_exceptions()
558 skip_metadata(ps); in read_exceptions()
578 struct pstore *ps = get_info(store); in persistent_usage() local
580 *sectors_allocated = ps->next_free * store->chunk_size; in persistent_usage()
588 *metadata_sectors = (ps->current_area + 1 + NUM_SNAPSHOT_HDR_CHUNKS) * in persistent_usage()
594 struct pstore *ps = get_info(store); in persistent_dtr() local
596 destroy_workqueue(ps->metadata_wq); in persistent_dtr()
599 if (ps->io_client) in persistent_dtr()
600 dm_io_client_destroy(ps->io_client); in persistent_dtr()
601 free_area(ps); in persistent_dtr()
604 vfree(ps->callbacks); in persistent_dtr()
606 kfree(ps); in persistent_dtr()
615 struct pstore *ps = get_info(store); in persistent_read_metadata() local
620 r = read_header(ps, &new_snapshot); in persistent_read_metadata()
627 ps->exceptions_per_area = (ps->store->chunk_size << SECTOR_SHIFT) / in persistent_read_metadata()
629 ps->callbacks = dm_vcalloc(ps->exceptions_per_area, in persistent_read_metadata()
630 sizeof(*ps->callbacks)); in persistent_read_metadata()
631 if (!ps->callbacks) in persistent_read_metadata()
638 r = write_header(ps); in persistent_read_metadata()
644 ps->current_area = 0; in persistent_read_metadata()
645 zero_memory_area(ps); in persistent_read_metadata()
646 r = zero_disk_area(ps, 0); in persistent_read_metadata()
654 if (ps->version != SNAPSHOT_DISK_VERSION) { in persistent_read_metadata()
656 ps->version); in persistent_read_metadata()
663 if (!ps->valid) in persistent_read_metadata()
669 r = read_exceptions(ps, callback, callback_context); in persistent_read_metadata()
677 struct pstore *ps = get_info(store); in persistent_prepare_exception() local
681 if (size < ((ps->next_free + 1) * store->chunk_size)) in persistent_prepare_exception()
684 e->new_chunk = ps->next_free; in persistent_prepare_exception()
690 ps->next_free++; in persistent_prepare_exception()
691 skip_metadata(ps); in persistent_prepare_exception()
693 atomic_inc(&ps->pending_count); in persistent_prepare_exception()
703 struct pstore *ps = get_info(store); in persistent_commit_exception() local
708 ps->valid = 0; in persistent_commit_exception()
712 write_exception(ps, ps->current_committed++, &ce); in persistent_commit_exception()
720 cb = ps->callbacks + ps->callback_count++; in persistent_commit_exception()
728 if (!atomic_dec_and_test(&ps->pending_count) && in persistent_commit_exception()
729 (ps->current_committed != ps->exceptions_per_area)) in persistent_commit_exception()
735 if ((ps->current_committed == ps->exceptions_per_area) && in persistent_commit_exception()
736 zero_disk_area(ps, ps->current_area + 1)) in persistent_commit_exception()
737 ps->valid = 0; in persistent_commit_exception()
742 if (ps->valid && area_io(ps, WRITE_FLUSH_FUA)) in persistent_commit_exception()
743 ps->valid = 0; in persistent_commit_exception()
748 if (ps->current_committed == ps->exceptions_per_area) { in persistent_commit_exception()
749 ps->current_committed = 0; in persistent_commit_exception()
750 ps->current_area++; in persistent_commit_exception()
751 zero_memory_area(ps); in persistent_commit_exception()
754 for (i = 0; i < ps->callback_count; i++) { in persistent_commit_exception()
755 cb = ps->callbacks + i; in persistent_commit_exception()
756 cb->callback(cb->context, ps->valid); in persistent_commit_exception()
759 ps->callback_count = 0; in persistent_commit_exception()
766 struct pstore *ps = get_info(store); in persistent_prepare_merge() local
774 if (!ps->current_committed) { in persistent_prepare_merge()
778 if (!ps->current_area) in persistent_prepare_merge()
781 ps->current_area--; in persistent_prepare_merge()
782 r = area_io(ps, READ); in persistent_prepare_merge()
785 ps->current_committed = ps->exceptions_per_area; in persistent_prepare_merge()
788 read_exception(ps, ps->area, ps->current_committed - 1, &ce); in persistent_prepare_merge()
796 for (nr_consecutive = 1; nr_consecutive < ps->current_committed; in persistent_prepare_merge()
798 read_exception(ps, ps->area, in persistent_prepare_merge()
799 ps->current_committed - 1 - nr_consecutive, &ce); in persistent_prepare_merge()
812 struct pstore *ps = get_info(store); in persistent_commit_merge() local
814 BUG_ON(nr_merged > ps->current_committed); in persistent_commit_merge()
817 clear_exception(ps, ps->current_committed - 1 - i); in persistent_commit_merge()
819 r = area_io(ps, WRITE_FLUSH_FUA); in persistent_commit_merge()
823 ps->current_committed -= nr_merged; in persistent_commit_merge()
835 ps->next_free = area_location(ps, ps->current_area) + in persistent_commit_merge()
836 ps->current_committed + 1; in persistent_commit_merge()
843 struct pstore *ps = get_info(store); in persistent_drop_snapshot() local
845 ps->valid = 0; in persistent_drop_snapshot()
846 if (write_header(ps)) in persistent_drop_snapshot()
852 struct pstore *ps; in persistent_ctr() local
856 ps = kzalloc(sizeof(*ps), GFP_KERNEL); in persistent_ctr()
857 if (!ps) in persistent_ctr()
860 ps->store = store; in persistent_ctr()
861 ps->valid = 1; in persistent_ctr()
862 ps->version = SNAPSHOT_DISK_VERSION; in persistent_ctr()
863 ps->area = NULL; in persistent_ctr()
864 ps->zero_area = NULL; in persistent_ctr()
865 ps->header_area = NULL; in persistent_ctr()
866 ps->next_free = NUM_SNAPSHOT_HDR_CHUNKS + 1; /* header and 1st area */ in persistent_ctr()
867 ps->current_committed = 0; in persistent_ctr()
869 ps->callback_count = 0; in persistent_ctr()
870 atomic_set(&ps->pending_count, 0); in persistent_ctr()
871 ps->callbacks = NULL; in persistent_ctr()
873 ps->metadata_wq = alloc_workqueue("ksnaphd", WQ_MEM_RECLAIM, 0); in persistent_ctr()
874 if (!ps->metadata_wq) { in persistent_ctr()
891 store->context = ps; in persistent_ctr()
896 destroy_workqueue(ps->metadata_wq); in persistent_ctr()
898 kfree(ps); in persistent_ctr()