Lines Matching +full:ext +full:- +full:32 +full:k
1 // SPDX-License-Identifier: GPL-2.0-only
8 * Copyright (C) 1998,2001-2005 Pavel Machek <pavel@ucw.cz>
10 * Copyright (C) 2010-2012 Bojan Smojver <bojan@rexursive.com>
61 #define MAP_PAGE_ENTRIES (PAGE_SIZE / sizeof(sector_t) - 1)
68 return nr_free_pages() - nr_free_highpages(); in low_free_pages()
92 * a file-alike way
100 unsigned int k; member
106 char reserved[PAGE_SIZE - 20 - sizeof(sector_t) - sizeof(int) -
134 struct swsusp_extent *ext; in swsusp_extents_insert() local
138 ext = rb_entry(*new, struct swsusp_extent, node); in swsusp_extents_insert()
140 if (swap_offset < ext->start) { in swsusp_extents_insert()
142 if (swap_offset == ext->start - 1) { in swsusp_extents_insert()
143 ext->start--; in swsusp_extents_insert()
146 new = &((*new)->rb_left); in swsusp_extents_insert()
147 } else if (swap_offset > ext->end) { in swsusp_extents_insert()
149 if (swap_offset == ext->end + 1) { in swsusp_extents_insert()
150 ext->end++; in swsusp_extents_insert()
153 new = &((*new)->rb_right); in swsusp_extents_insert()
156 return -EINVAL; in swsusp_extents_insert()
160 ext = kzalloc(sizeof(struct swsusp_extent), GFP_KERNEL); in swsusp_extents_insert()
161 if (!ext) in swsusp_extents_insert()
162 return -ENOMEM; in swsusp_extents_insert()
164 ext->start = swap_offset; in swsusp_extents_insert()
165 ext->end = swap_offset; in swsusp_extents_insert()
166 rb_link_node(&ext->node, parent, new); in swsusp_extents_insert()
167 rb_insert_color(&ext->node, &swsusp_extents); in swsusp_extents_insert()
172 * alloc_swapdev_block - allocate a swap page and register that it has
191 * free_all_swap_pages - free swap pages allocated for saving image data.
201 struct swsusp_extent *ext; in free_all_swap_pages() local
204 ext = rb_entry(node, struct swsusp_extent, node); in free_all_swap_pages()
206 for (offset = ext->start; offset <= ext->end; offset++) in free_all_swap_pages()
209 kfree(ext); in free_all_swap_pages()
234 atomic_set(&hb->count, 0); in hib_init_batch()
235 init_waitqueue_head(&hb->wait); in hib_init_batch()
236 hb->error = BLK_STS_OK; in hib_init_batch()
237 blk_start_plug(&hb->plug); in hib_init_batch()
242 blk_finish_plug(&hb->plug); in hib_finish_batch()
247 struct hib_bio_batch *hb = bio->bi_private; in hib_end_io()
250 if (bio->bi_status) { in hib_end_io()
251 pr_alert("Read-error on swap-device (%u:%u:%Lu)\n", in hib_end_io()
253 (unsigned long long)bio->bi_iter.bi_sector); in hib_end_io()
262 if (bio->bi_status && !hb->error) in hib_end_io()
263 hb->error = bio->bi_status; in hib_end_io()
264 if (atomic_dec_and_test(&hb->count)) in hib_end_io()
265 wake_up(&hb->wait); in hib_end_io()
278 bio->bi_iter.bi_sector = page_off * (PAGE_SIZE >> 9); in hib_submit_io()
284 (unsigned long long)bio->bi_iter.bi_sector); in hib_submit_io()
286 return -EFAULT; in hib_submit_io()
290 bio->bi_end_io = hib_end_io; in hib_submit_io()
291 bio->bi_private = hb; in hib_submit_io()
292 atomic_inc(&hb->count); in hib_submit_io()
308 wait_event(hb->wait, atomic_read(&hb->count) == 0); in hib_wait_io()
309 return blk_status_to_errno(hb->error); in hib_wait_io()
322 if (!memcmp("SWAP-SPACE",swsusp_header->sig, 10) || in mark_swapfiles()
323 !memcmp("SWAPSPACE2",swsusp_header->sig, 10)) { in mark_swapfiles()
324 memcpy(swsusp_header->orig_sig,swsusp_header->sig, 10); in mark_swapfiles()
325 memcpy(swsusp_header->sig, HIBERNATE_SIG, 10); in mark_swapfiles()
326 swsusp_header->image = handle->first_sector; in mark_swapfiles()
327 swsusp_header->flags = flags; in mark_swapfiles()
329 swsusp_header->crc32 = handle->crc32; in mark_swapfiles()
334 error = -ENODEV; in mark_swapfiles()
340 * swsusp_swap_check - check if the resume device is a swap device
370 * write_page - Write one page to given swap location.
382 return -ENOSPC; in write_page()
412 if (handle->cur) in release_swap_writer()
413 free_page((unsigned long)handle->cur); in release_swap_writer()
414 handle->cur = NULL; in release_swap_writer()
423 if (ret != -ENOSPC) in get_swap_writer()
424 pr_err("Cannot find swap device, try swapon -a\n"); in get_swap_writer()
427 handle->cur = (struct swap_map_page *)get_zeroed_page(GFP_KERNEL); in get_swap_writer()
428 if (!handle->cur) { in get_swap_writer()
429 ret = -ENOMEM; in get_swap_writer()
432 handle->cur_swap = alloc_swapdev_block(root_swap); in get_swap_writer()
433 if (!handle->cur_swap) { in get_swap_writer()
434 ret = -ENOSPC; in get_swap_writer()
437 handle->k = 0; in get_swap_writer()
438 handle->reqd_free_pages = reqd_free_pages(); in get_swap_writer()
439 handle->first_sector = handle->cur_swap; in get_swap_writer()
454 if (!handle->cur) in swap_write_page()
455 return -EINVAL; in swap_write_page()
460 handle->cur->entries[handle->k++] = offset; in swap_write_page()
461 if (handle->k >= MAP_PAGE_ENTRIES) { in swap_write_page()
464 return -ENOSPC; in swap_write_page()
465 handle->cur->next_swap = offset; in swap_write_page()
466 error = write_page(handle->cur, handle->cur_swap, hb); in swap_write_page()
469 clear_page(handle->cur); in swap_write_page()
470 handle->cur_swap = offset; in swap_write_page()
471 handle->k = 0; in swap_write_page()
473 if (hb && low_free_pages() <= handle->reqd_free_pages) { in swap_write_page()
481 handle->reqd_free_pages = reqd_free_pages(); in swap_write_page()
490 if (handle->cur && handle->cur_swap) in flush_swap_writer()
491 return write_page(handle->cur, handle->cur_swap, NULL); in flush_swap_writer()
493 return -EINVAL; in flush_swap_writer()
518 #define LZO_UNC_PAGES 32
535 * save_image - save the suspend image data
606 wait_event(d->go, atomic_read(&d->ready) || in crc32_threadfn()
609 d->thr = NULL; in crc32_threadfn()
610 atomic_set(&d->stop, 1); in crc32_threadfn()
611 wake_up(&d->done); in crc32_threadfn()
614 atomic_set(&d->ready, 0); in crc32_threadfn()
616 for (i = 0; i < d->run_threads; i++) in crc32_threadfn()
617 *d->crc32 = crc32_le(*d->crc32, in crc32_threadfn()
618 d->unc[i], *d->unc_len[i]); in crc32_threadfn()
619 atomic_set(&d->stop, 1); in crc32_threadfn()
620 wake_up(&d->done); in crc32_threadfn()
649 wait_event(d->go, atomic_read(&d->ready) || in lzo_compress_threadfn()
652 d->thr = NULL; in lzo_compress_threadfn()
653 d->ret = -1; in lzo_compress_threadfn()
654 atomic_set(&d->stop, 1); in lzo_compress_threadfn()
655 wake_up(&d->done); in lzo_compress_threadfn()
658 atomic_set(&d->ready, 0); in lzo_compress_threadfn()
660 d->ret = lzo1x_1_compress(d->unc, d->unc_len, in lzo_compress_threadfn()
661 d->cmp + LZO_HEADER, &d->cmp_len, in lzo_compress_threadfn()
662 d->wrk); in lzo_compress_threadfn()
663 atomic_set(&d->stop, 1); in lzo_compress_threadfn()
664 wake_up(&d->done); in lzo_compress_threadfn()
670 * save_image_lzo - Save the suspend image data compressed with LZO.
698 nr_threads = num_online_cpus() - 1; in save_image_lzo()
704 ret = -ENOMEM; in save_image_lzo()
711 ret = -ENOMEM; in save_image_lzo()
720 ret = -ENOMEM; in save_image_lzo()
738 ret = -ENOMEM; in save_image_lzo()
746 init_waitqueue_head(&crc->go); in save_image_lzo()
747 init_waitqueue_head(&crc->done); in save_image_lzo()
749 handle->crc32 = 0; in save_image_lzo()
750 crc->crc32 = &handle->crc32; in save_image_lzo()
752 crc->unc[thr] = data[thr].unc; in save_image_lzo()
753 crc->unc_len[thr] = &data[thr].unc_len; in save_image_lzo()
756 crc->thr = kthread_run(crc32_threadfn, crc, "image_crc32"); in save_image_lzo()
757 if (IS_ERR(crc->thr)) { in save_image_lzo()
758 crc->thr = NULL; in save_image_lzo()
760 ret = -ENOMEM; in save_image_lzo()
768 handle->reqd_free_pages = reqd_free_pages(); in save_image_lzo()
808 crc->run_threads = thr; in save_image_lzo()
809 atomic_set(&crc->ready, 1); in save_image_lzo()
810 wake_up(&crc->go); in save_image_lzo()
828 ret = -1; in save_image_lzo()
838 * OK - we saved the length of the compressed data, so in save_image_lzo()
853 wait_event(crc->done, atomic_read(&crc->stop)); in save_image_lzo()
854 atomic_set(&crc->stop, 0); in save_image_lzo()
868 if (crc->thr) in save_image_lzo()
869 kthread_stop(crc->thr); in save_image_lzo()
884 * enough_swap - Make sure we have enough swap to save the image.
902 * swsusp_write - Write entire image and metadata.
928 error = -ENOSPC; in swsusp_write()
936 error = -EFAULT; in swsusp_write()
944 save_image(&handle, &snapshot, pages - 1) : in swsusp_write()
945 save_image_lzo(&handle, &snapshot, pages - 1); in swsusp_write()
954 * in a file-alike way
961 while (handle->maps) { in release_swap_reader()
962 if (handle->maps->map) in release_swap_reader()
963 free_page((unsigned long)handle->maps->map); in release_swap_reader()
964 tmp = handle->maps; in release_swap_reader()
965 handle->maps = handle->maps->next; in release_swap_reader()
968 handle->cur = NULL; in release_swap_reader()
978 *flags_p = swsusp_header->flags; in get_swap_reader()
980 if (!swsusp_header->image) /* how can this happen? */ in get_swap_reader()
981 return -EINVAL; in get_swap_reader()
983 handle->cur = NULL; in get_swap_reader()
984 last = handle->maps = NULL; in get_swap_reader()
985 offset = swsusp_header->image; in get_swap_reader()
987 tmp = kzalloc(sizeof(*handle->maps), GFP_KERNEL); in get_swap_reader()
990 return -ENOMEM; in get_swap_reader()
992 if (!handle->maps) in get_swap_reader()
993 handle->maps = tmp; in get_swap_reader()
995 last->next = tmp; in get_swap_reader()
998 tmp->map = (struct swap_map_page *) in get_swap_reader()
1000 if (!tmp->map) { in get_swap_reader()
1002 return -ENOMEM; in get_swap_reader()
1005 error = hib_submit_io(REQ_OP_READ, 0, offset, tmp->map, NULL); in get_swap_reader()
1010 offset = tmp->map->next_swap; in get_swap_reader()
1012 handle->k = 0; in get_swap_reader()
1013 handle->cur = handle->maps->map; in get_swap_reader()
1024 if (!handle->cur) in swap_read_page()
1025 return -EINVAL; in swap_read_page()
1026 offset = handle->cur->entries[handle->k]; in swap_read_page()
1028 return -EFAULT; in swap_read_page()
1032 if (++handle->k >= MAP_PAGE_ENTRIES) { in swap_read_page()
1033 handle->k = 0; in swap_read_page()
1034 free_page((unsigned long)handle->maps->map); in swap_read_page()
1035 tmp = handle->maps; in swap_read_page()
1036 handle->maps = handle->maps->next; in swap_read_page()
1038 if (!handle->maps) in swap_read_page()
1041 handle->cur = handle->maps->map; in swap_read_page()
1054 * load_image - load the image using the swap map handle
1087 if (snapshot->sync_read) in load_image()
1105 ret = -ENODATA; in load_image()
1135 wait_event(d->go, atomic_read(&d->ready) || in lzo_decompress_threadfn()
1138 d->thr = NULL; in lzo_decompress_threadfn()
1139 d->ret = -1; in lzo_decompress_threadfn()
1140 atomic_set(&d->stop, 1); in lzo_decompress_threadfn()
1141 wake_up(&d->done); in lzo_decompress_threadfn()
1144 atomic_set(&d->ready, 0); in lzo_decompress_threadfn()
1146 d->unc_len = LZO_UNC_SIZE; in lzo_decompress_threadfn()
1147 d->ret = lzo1x_decompress_safe(d->cmp + LZO_HEADER, d->cmp_len, in lzo_decompress_threadfn()
1148 d->unc, &d->unc_len); in lzo_decompress_threadfn()
1150 flush_icache_range((unsigned long)d->unc, in lzo_decompress_threadfn()
1151 (unsigned long)d->unc + d->unc_len); in lzo_decompress_threadfn()
1153 atomic_set(&d->stop, 1); in lzo_decompress_threadfn()
1154 wake_up(&d->done); in lzo_decompress_threadfn()
1160 * load_image_lzo - Load compressed image data and decompress them with LZO.
1191 nr_threads = num_online_cpus() - 1; in load_image_lzo()
1197 ret = -ENOMEM; in load_image_lzo()
1204 ret = -ENOMEM; in load_image_lzo()
1213 ret = -ENOMEM; in load_image_lzo()
1233 ret = -ENOMEM; in load_image_lzo()
1241 init_waitqueue_head(&crc->go); in load_image_lzo()
1242 init_waitqueue_head(&crc->done); in load_image_lzo()
1244 handle->crc32 = 0; in load_image_lzo()
1245 crc->crc32 = &handle->crc32; in load_image_lzo()
1247 crc->unc[thr] = data[thr].unc; in load_image_lzo()
1248 crc->unc_len[thr] = &data[thr].unc_len; in load_image_lzo()
1251 crc->thr = kthread_run(crc32_threadfn, crc, "image_crc32"); in load_image_lzo()
1252 if (IS_ERR(crc->thr)) { in load_image_lzo()
1253 crc->thr = NULL; in load_image_lzo()
1255 ret = -ENOMEM; in load_image_lzo()
1267 read_pages = (low_free_pages() - snapshot_get_image_size()) / 2; in load_image_lzo()
1280 ret = -ENOMEM; in load_image_lzo()
1310 if (handle->cur && in load_image_lzo()
1311 handle->cur->entries[handle->k]) { in load_image_lzo()
1322 want -= i; in load_image_lzo()
1340 if (crc->run_threads) { in load_image_lzo()
1341 wait_event(crc->done, atomic_read(&crc->stop)); in load_image_lzo()
1342 atomic_set(&crc->stop, 0); in load_image_lzo()
1343 crc->run_threads = 0; in load_image_lzo()
1352 ret = -1; in load_image_lzo()
1360 ret = -1; in load_image_lzo()
1371 have--; in load_image_lzo()
1408 data[thr].unc_len & (PAGE_SIZE - 1))) { in load_image_lzo()
1410 ret = -1; in load_image_lzo()
1426 crc->run_threads = thr + 1; in load_image_lzo()
1427 atomic_set(&crc->ready, 1); in load_image_lzo()
1428 wake_up(&crc->go); in load_image_lzo()
1434 crc->run_threads = thr; in load_image_lzo()
1435 atomic_set(&crc->ready, 1); in load_image_lzo()
1436 wake_up(&crc->go); in load_image_lzo()
1440 if (crc->run_threads) { in load_image_lzo()
1441 wait_event(crc->done, atomic_read(&crc->stop)); in load_image_lzo()
1442 atomic_set(&crc->stop, 0); in load_image_lzo()
1449 ret = -ENODATA; in load_image_lzo()
1451 if (swsusp_header->flags & SF_CRC32_MODE) { in load_image_lzo()
1452 if(handle->crc32 != swsusp_header->crc32) { in load_image_lzo()
1454 ret = -ENODATA; in load_image_lzo()
1465 if (crc->thr) in load_image_lzo()
1466 kthread_stop(crc->thr); in load_image_lzo()
1481 * swsusp_read - read the hibernation image.
1496 return error < 0 ? error : -EFAULT; in swsusp_read()
1505 load_image(&handle, &snapshot, header->pages - 1) : in swsusp_read()
1506 load_image_lzo(&handle, &snapshot, header->pages - 1); in swsusp_read()
1518 * swsusp_check - Check for swsusp signature in the resume device
1536 if (!memcmp(HIBERNATE_SIG, swsusp_header->sig, 10)) { in swsusp_check()
1537 memcpy(swsusp_header->sig, swsusp_header->orig_sig, 10); in swsusp_check()
1543 error = -EINVAL; in swsusp_check()
1562 * swsusp_close - close swap device.
1576 * swsusp_unmark - Unmark swsusp signature in the resume device
1586 if (!memcmp(HIBERNATE_SIG,swsusp_header->sig, 10)) { in swsusp_unmark()
1587 memcpy(swsusp_header->sig,swsusp_header->orig_sig, 10); in swsusp_unmark()
1593 error = -ENODEV; in swsusp_unmark()