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>
62 #define MAP_PAGE_ENTRIES (PAGE_SIZE / sizeof(sector_t) - 1)
69 return nr_free_pages() - nr_free_highpages(); in low_free_pages()
93 * a file-alike way
101 unsigned int k; member
107 char reserved[PAGE_SIZE - 20 - sizeof(sector_t) - sizeof(int) -
108 sizeof(u32) - sizeof(u32)];
136 struct swsusp_extent *ext; in swsusp_extents_insert() local
140 ext = rb_entry(*new, struct swsusp_extent, node); in swsusp_extents_insert()
142 if (swap_offset < ext->start) { in swsusp_extents_insert()
144 if (swap_offset == ext->start - 1) { in swsusp_extents_insert()
145 ext->start--; in swsusp_extents_insert()
148 new = &((*new)->rb_left); in swsusp_extents_insert()
149 } else if (swap_offset > ext->end) { in swsusp_extents_insert()
151 if (swap_offset == ext->end + 1) { in swsusp_extents_insert()
152 ext->end++; in swsusp_extents_insert()
155 new = &((*new)->rb_right); in swsusp_extents_insert()
158 return -EINVAL; in swsusp_extents_insert()
162 ext = kzalloc(sizeof(struct swsusp_extent), GFP_KERNEL); in swsusp_extents_insert()
163 if (!ext) in swsusp_extents_insert()
164 return -ENOMEM; in swsusp_extents_insert()
166 ext->start = swap_offset; in swsusp_extents_insert()
167 ext->end = swap_offset; in swsusp_extents_insert()
168 rb_link_node(&ext->node, parent, new); in swsusp_extents_insert()
169 rb_insert_color(&ext->node, &swsusp_extents); in swsusp_extents_insert()
174 * alloc_swapdev_block - allocate a swap page and register that it has
193 * free_all_swap_pages - free swap pages allocated for saving image data.
203 struct swsusp_extent *ext; in free_all_swap_pages() local
206 ext = rb_entry(node, struct swsusp_extent, node); in free_all_swap_pages()
208 for (offset = ext->start; offset <= ext->end; offset++) in free_all_swap_pages()
211 kfree(ext); in free_all_swap_pages()
236 atomic_set(&hb->count, 0); in hib_init_batch()
237 init_waitqueue_head(&hb->wait); in hib_init_batch()
238 hb->error = BLK_STS_OK; in hib_init_batch()
239 blk_start_plug(&hb->plug); in hib_init_batch()
244 blk_finish_plug(&hb->plug); in hib_finish_batch()
249 struct hib_bio_batch *hb = bio->bi_private; in hib_end_io()
252 if (bio->bi_status) { in hib_end_io()
253 pr_alert("Read-error on swap-device (%u:%u:%Lu)\n", in hib_end_io()
255 (unsigned long long)bio->bi_iter.bi_sector); in hib_end_io()
264 if (bio->bi_status && !hb->error) in hib_end_io()
265 hb->error = bio->bi_status; in hib_end_io()
266 if (atomic_dec_and_test(&hb->count)) in hib_end_io()
267 wake_up(&hb->wait); in hib_end_io()
280 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()
320 if (!memcmp("SWAP-SPACE",swsusp_header->sig, 10) || in mark_swapfiles()
321 !memcmp("SWAPSPACE2",swsusp_header->sig, 10)) { in mark_swapfiles()
322 memcpy(swsusp_header->orig_sig,swsusp_header->sig, 10); in mark_swapfiles()
323 memcpy(swsusp_header->sig, HIBERNATE_SIG, 10); in mark_swapfiles()
324 swsusp_header->image = handle->first_sector; in mark_swapfiles()
326 swsusp_header->hw_sig = swsusp_hardware_signature; in mark_swapfiles()
329 swsusp_header->flags = flags; in mark_swapfiles()
331 swsusp_header->crc32 = handle->crc32; in mark_swapfiles()
336 error = -ENODEV; in mark_swapfiles()
342 * swsusp_swap_check - check if the resume device is a swap device
372 * write_page - Write one page to given swap location.
384 return -ENOSPC; in write_page()
414 if (handle->cur) in release_swap_writer()
415 free_page((unsigned long)handle->cur); in release_swap_writer()
416 handle->cur = NULL; in release_swap_writer()
425 if (ret != -ENOSPC) in get_swap_writer()
426 pr_err("Cannot find swap device, try swapon -a\n"); in get_swap_writer()
429 handle->cur = (struct swap_map_page *)get_zeroed_page(GFP_KERNEL); in get_swap_writer()
430 if (!handle->cur) { in get_swap_writer()
431 ret = -ENOMEM; in get_swap_writer()
434 handle->cur_swap = alloc_swapdev_block(root_swap); in get_swap_writer()
435 if (!handle->cur_swap) { in get_swap_writer()
436 ret = -ENOSPC; in get_swap_writer()
439 handle->k = 0; in get_swap_writer()
440 handle->reqd_free_pages = reqd_free_pages(); in get_swap_writer()
441 handle->first_sector = handle->cur_swap; in get_swap_writer()
456 if (!handle->cur) in swap_write_page()
457 return -EINVAL; in swap_write_page()
462 handle->cur->entries[handle->k++] = offset; in swap_write_page()
463 if (handle->k >= MAP_PAGE_ENTRIES) { in swap_write_page()
466 return -ENOSPC; in swap_write_page()
467 handle->cur->next_swap = offset; in swap_write_page()
468 error = write_page(handle->cur, handle->cur_swap, hb); in swap_write_page()
471 clear_page(handle->cur); in swap_write_page()
472 handle->cur_swap = offset; in swap_write_page()
473 handle->k = 0; in swap_write_page()
475 if (hb && low_free_pages() <= handle->reqd_free_pages) { in swap_write_page()
483 handle->reqd_free_pages = reqd_free_pages(); in swap_write_page()
492 if (handle->cur && handle->cur_swap) in flush_swap_writer()
493 return write_page(handle->cur, handle->cur_swap, NULL); in flush_swap_writer()
495 return -EINVAL; in flush_swap_writer()
520 #define LZO_UNC_PAGES 32
537 * save_image - save the suspend image data
608 wait_event(d->go, atomic_read_acquire(&d->ready) || in crc32_threadfn()
611 d->thr = NULL; in crc32_threadfn()
612 atomic_set_release(&d->stop, 1); in crc32_threadfn()
613 wake_up(&d->done); in crc32_threadfn()
616 atomic_set(&d->ready, 0); in crc32_threadfn()
618 for (i = 0; i < d->run_threads; i++) in crc32_threadfn()
619 *d->crc32 = crc32_le(*d->crc32, in crc32_threadfn()
620 d->unc[i], *d->unc_len[i]); in crc32_threadfn()
621 atomic_set_release(&d->stop, 1); in crc32_threadfn()
622 wake_up(&d->done); in crc32_threadfn()
651 wait_event(d->go, atomic_read_acquire(&d->ready) || in lzo_compress_threadfn()
654 d->thr = NULL; in lzo_compress_threadfn()
655 d->ret = -1; in lzo_compress_threadfn()
656 atomic_set_release(&d->stop, 1); in lzo_compress_threadfn()
657 wake_up(&d->done); in lzo_compress_threadfn()
660 atomic_set(&d->ready, 0); in lzo_compress_threadfn()
662 d->ret = lzo1x_1_compress(d->unc, d->unc_len, in lzo_compress_threadfn()
663 d->cmp + LZO_HEADER, &d->cmp_len, in lzo_compress_threadfn()
664 d->wrk); in lzo_compress_threadfn()
665 atomic_set_release(&d->stop, 1); in lzo_compress_threadfn()
666 wake_up(&d->done); in lzo_compress_threadfn()
672 * save_image_lzo - Save the suspend image data compressed with LZO.
700 nr_threads = num_online_cpus() - 1; in save_image_lzo()
706 ret = -ENOMEM; in save_image_lzo()
713 ret = -ENOMEM; in save_image_lzo()
720 ret = -ENOMEM; in save_image_lzo()
737 ret = -ENOMEM; in save_image_lzo()
745 init_waitqueue_head(&crc->go); in save_image_lzo()
746 init_waitqueue_head(&crc->done); in save_image_lzo()
748 handle->crc32 = 0; in save_image_lzo()
749 crc->crc32 = &handle->crc32; in save_image_lzo()
751 crc->unc[thr] = data[thr].unc; in save_image_lzo()
752 crc->unc_len[thr] = &data[thr].unc_len; in save_image_lzo()
755 crc->thr = kthread_run(crc32_threadfn, crc, "image_crc32"); in save_image_lzo()
756 if (IS_ERR(crc->thr)) { in save_image_lzo()
757 crc->thr = NULL; in save_image_lzo()
759 ret = -ENOMEM; in save_image_lzo()
767 handle->reqd_free_pages = reqd_free_pages(); in save_image_lzo()
807 crc->run_threads = thr; in save_image_lzo()
808 atomic_set_release(&crc->ready, 1); in save_image_lzo()
809 wake_up(&crc->go); in save_image_lzo()
827 ret = -1; in save_image_lzo()
837 * OK - we saved the length of the compressed data, so in save_image_lzo()
852 wait_event(crc->done, atomic_read_acquire(&crc->stop)); in save_image_lzo()
853 atomic_set(&crc->stop, 0); in save_image_lzo()
867 if (crc->thr) in save_image_lzo()
868 kthread_stop(crc->thr); in save_image_lzo()
883 * enough_swap - Make sure we have enough swap to save the image.
901 * swsusp_write - Write entire image and metadata.
927 error = -ENOSPC; in swsusp_write()
935 error = -EFAULT; in swsusp_write()
943 save_image(&handle, &snapshot, pages - 1) : in swsusp_write()
944 save_image_lzo(&handle, &snapshot, pages - 1); in swsusp_write()
953 * in a file-like way.
960 while (handle->maps) { in release_swap_reader()
961 if (handle->maps->map) in release_swap_reader()
962 free_page((unsigned long)handle->maps->map); in release_swap_reader()
963 tmp = handle->maps; in release_swap_reader()
964 handle->maps = handle->maps->next; in release_swap_reader()
967 handle->cur = NULL; in release_swap_reader()
977 *flags_p = swsusp_header->flags; in get_swap_reader()
979 if (!swsusp_header->image) /* how can this happen? */ in get_swap_reader()
980 return -EINVAL; in get_swap_reader()
982 handle->cur = NULL; in get_swap_reader()
983 last = handle->maps = NULL; in get_swap_reader()
984 offset = swsusp_header->image; in get_swap_reader()
986 tmp = kzalloc(sizeof(*handle->maps), GFP_KERNEL); in get_swap_reader()
989 return -ENOMEM; in get_swap_reader()
991 if (!handle->maps) in get_swap_reader()
992 handle->maps = tmp; in get_swap_reader()
994 last->next = tmp; in get_swap_reader()
997 tmp->map = (struct swap_map_page *) in get_swap_reader()
999 if (!tmp->map) { in get_swap_reader()
1001 return -ENOMEM; in get_swap_reader()
1004 error = hib_submit_io(REQ_OP_READ, offset, tmp->map, NULL); in get_swap_reader()
1009 offset = tmp->map->next_swap; in get_swap_reader()
1011 handle->k = 0; in get_swap_reader()
1012 handle->cur = handle->maps->map; in get_swap_reader()
1023 if (!handle->cur) in swap_read_page()
1024 return -EINVAL; in swap_read_page()
1025 offset = handle->cur->entries[handle->k]; in swap_read_page()
1027 return -EFAULT; in swap_read_page()
1031 if (++handle->k >= MAP_PAGE_ENTRIES) { in swap_read_page()
1032 handle->k = 0; in swap_read_page()
1033 free_page((unsigned long)handle->maps->map); in swap_read_page()
1034 tmp = handle->maps; in swap_read_page()
1035 handle->maps = handle->maps->next; in swap_read_page()
1037 if (!handle->maps) in swap_read_page()
1040 handle->cur = handle->maps->map; in swap_read_page()
1053 * load_image - load the image using the swap map handle
1086 if (snapshot->sync_read) in load_image()
1104 ret = -ENODATA; in load_image()
1134 wait_event(d->go, atomic_read_acquire(&d->ready) || in lzo_decompress_threadfn()
1137 d->thr = NULL; in lzo_decompress_threadfn()
1138 d->ret = -1; in lzo_decompress_threadfn()
1139 atomic_set_release(&d->stop, 1); in lzo_decompress_threadfn()
1140 wake_up(&d->done); in lzo_decompress_threadfn()
1143 atomic_set(&d->ready, 0); in lzo_decompress_threadfn()
1145 d->unc_len = LZO_UNC_SIZE; in lzo_decompress_threadfn()
1146 d->ret = lzo1x_decompress_safe(d->cmp + LZO_HEADER, d->cmp_len, in lzo_decompress_threadfn()
1147 d->unc, &d->unc_len); in lzo_decompress_threadfn()
1149 flush_icache_range((unsigned long)d->unc, in lzo_decompress_threadfn()
1150 (unsigned long)d->unc + d->unc_len); in lzo_decompress_threadfn()
1152 atomic_set_release(&d->stop, 1); in lzo_decompress_threadfn()
1153 wake_up(&d->done); in lzo_decompress_threadfn()
1159 * load_image_lzo - Load compressed image data and decompress them with LZO.
1190 nr_threads = num_online_cpus() - 1; in load_image_lzo()
1196 ret = -ENOMEM; in load_image_lzo()
1203 ret = -ENOMEM; in load_image_lzo()
1210 ret = -ENOMEM; in load_image_lzo()
1229 ret = -ENOMEM; in load_image_lzo()
1237 init_waitqueue_head(&crc->go); in load_image_lzo()
1238 init_waitqueue_head(&crc->done); in load_image_lzo()
1240 handle->crc32 = 0; in load_image_lzo()
1241 crc->crc32 = &handle->crc32; in load_image_lzo()
1243 crc->unc[thr] = data[thr].unc; in load_image_lzo()
1244 crc->unc_len[thr] = &data[thr].unc_len; in load_image_lzo()
1247 crc->thr = kthread_run(crc32_threadfn, crc, "image_crc32"); in load_image_lzo()
1248 if (IS_ERR(crc->thr)) { in load_image_lzo()
1249 crc->thr = NULL; in load_image_lzo()
1251 ret = -ENOMEM; in load_image_lzo()
1263 read_pages = (low_free_pages() - snapshot_get_image_size()) / 2; in load_image_lzo()
1276 ret = -ENOMEM; in load_image_lzo()
1306 if (handle->cur && in load_image_lzo()
1307 handle->cur->entries[handle->k]) { in load_image_lzo()
1318 want -= i; in load_image_lzo()
1336 if (crc->run_threads) { in load_image_lzo()
1337 wait_event(crc->done, atomic_read_acquire(&crc->stop)); in load_image_lzo()
1338 atomic_set(&crc->stop, 0); in load_image_lzo()
1339 crc->run_threads = 0; in load_image_lzo()
1348 ret = -1; in load_image_lzo()
1356 ret = -1; in load_image_lzo()
1367 have--; in load_image_lzo()
1404 data[thr].unc_len & (PAGE_SIZE - 1))) { in load_image_lzo()
1406 ret = -1; in load_image_lzo()
1422 crc->run_threads = thr + 1; in load_image_lzo()
1423 atomic_set_release(&crc->ready, 1); in load_image_lzo()
1424 wake_up(&crc->go); in load_image_lzo()
1430 crc->run_threads = thr; in load_image_lzo()
1431 atomic_set_release(&crc->ready, 1); in load_image_lzo()
1432 wake_up(&crc->go); in load_image_lzo()
1436 if (crc->run_threads) { in load_image_lzo()
1437 wait_event(crc->done, atomic_read_acquire(&crc->stop)); in load_image_lzo()
1438 atomic_set(&crc->stop, 0); in load_image_lzo()
1445 ret = -ENODATA; in load_image_lzo()
1447 if (swsusp_header->flags & SF_CRC32_MODE) { in load_image_lzo()
1448 if(handle->crc32 != swsusp_header->crc32) { in load_image_lzo()
1450 ret = -ENODATA; in load_image_lzo()
1461 if (crc->thr) in load_image_lzo()
1462 kthread_stop(crc->thr); in load_image_lzo()
1477 * swsusp_read - read the hibernation image.
1492 return error < 0 ? error : -EFAULT; in swsusp_read()
1501 load_image(&handle, &snapshot, header->pages - 1) : in swsusp_read()
1502 load_image_lzo(&handle, &snapshot, header->pages - 1); in swsusp_read()
1516 * swsusp_check - Check for swsusp signature in the resume device
1535 if (!memcmp(HIBERNATE_SIG, swsusp_header->sig, 10)) { in swsusp_check()
1536 memcpy(swsusp_header->sig, swsusp_header->orig_sig, 10); in swsusp_check()
1542 error = -EINVAL; in swsusp_check()
1544 if (!error && swsusp_header->flags & SF_HW_SIG && in swsusp_check()
1545 swsusp_header->hw_sig != swsusp_hardware_signature) { in swsusp_check()
1547 swsusp_header->hw_sig, swsusp_hardware_signature); in swsusp_check()
1548 error = -EINVAL; in swsusp_check()
1567 * swsusp_close - close swap device.
1582 * swsusp_unmark - Unmark swsusp signature in the resume device
1592 if (!memcmp(HIBERNATE_SIG,swsusp_header->sig, 10)) { in swsusp_unmark()
1593 memcpy(swsusp_header->sig,swsusp_header->orig_sig, 10); in swsusp_unmark()
1599 error = -ENODEV; in swsusp_unmark()