Lines Matching +full:xlen +full:- +full:1
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) International Business Machines Corp., 2000-2005
4 * Portions Copyright (C) Christoph Hellwig, 2001-2002
33 #define metapage_locked(mp) test_bit(META_locked, &(mp)->flag)
34 #define trylock_metapage(mp) test_and_set_bit_lock(META_locked, &(mp)->flag)
38 clear_bit_unlock(META_locked, &mp->flag); in unlock_metapage()
39 wake_up(&mp->wait); in unlock_metapage()
46 add_wait_queue_exclusive(&mp->wait, &wait); in __lock_metapage()
50 folio_unlock(mp->folio); in __lock_metapage()
52 folio_lock(mp->folio); in __lock_metapage()
56 remove_wait_queue(&mp->wait, &wait); in __lock_metapage()
60 * Must have mp->folio locked
74 #if MPS_PER_PAGE > 1
85 struct meta_anchor *anchor = folio->private; in folio_to_mp()
89 return anchor->mp[offset >> L2PSIZE]; in folio_to_mp()
98 a = folio->private; in insert_metapage()
102 return -ENOMEM; in insert_metapage()
104 kmap(&folio->page); in insert_metapage()
108 l2mp_blocks = L2PSIZE - folio->mapping->host->i_blkbits; in insert_metapage()
109 index = (mp->index >> l2mp_blocks) & (MPS_PER_PAGE - 1); in insert_metapage()
110 a->mp_count++; in insert_metapage()
111 a->mp[index] = mp; in insert_metapage()
119 struct meta_anchor *a = folio->private; in remove_metapage()
120 int l2mp_blocks = L2PSIZE - folio->mapping->host->i_blkbits; in remove_metapage()
123 index = (mp->index >> l2mp_blocks) & (MPS_PER_PAGE - 1); in remove_metapage()
125 BUG_ON(a->mp[index] != mp); in remove_metapage()
127 a->mp[index] = NULL; in remove_metapage()
128 if (--a->mp_count == 0) { in remove_metapage()
131 kunmap(&folio->page); in remove_metapage()
137 struct meta_anchor *anchor = folio->private; in inc_io()
139 atomic_inc(&anchor->io_count); in inc_io()
145 struct meta_anchor *anchor = folio->private; in dec_io()
147 if (anchor->status == BLK_STS_OK) in dec_io()
148 anchor->status = status; in dec_io()
150 if (atomic_dec_and_test(&anchor->io_count)) in dec_io()
151 handler(folio, anchor->status); in dec_io()
157 return folio->private; in folio_to_mp()
164 kmap(&folio->page); in insert_metapage()
172 kunmap(&folio->page); in remove_metapage()
185 mp->lid = 0; in alloc_metapage()
186 mp->lsn = 0; in alloc_metapage()
187 mp->data = NULL; in alloc_metapage()
188 mp->clsn = 0; in alloc_metapage()
189 mp->log = NULL; in alloc_metapage()
190 init_waitqueue_head(&mp->wait); in alloc_metapage()
208 return -ENOMEM; in metapage_init()
215 return -ENOMEM; in metapage_init()
229 if (mp->count || mp->nohomeok || test_bit(META_dirty, &mp->flag) || in drop_metapage()
230 test_bit(META_io, &mp->flag)) in drop_metapage()
247 sector_t file_blocks = (inode->i_size + inode->i_sb->s_blocksize - 1) >> in metapage_get_blocks()
248 inode->i_blkbits; in metapage_get_blocks()
253 *len = file_blocks - lblock; in metapage_get_blocks()
255 if (inode->i_ino) { in metapage_get_blocks()
277 struct folio *folio = bio->bi_private; in metapage_read_end_io()
279 dec_io(folio, bio->bi_status, last_read_complete); in metapage_read_end_io()
285 struct jfs_log *log = mp->log; in remove_from_logsync()
295 if (mp->lsn) { in remove_from_logsync()
296 mp->log = NULL; in remove_from_logsync()
297 mp->lsn = 0; in remove_from_logsync()
298 mp->clsn = 0; in remove_from_logsync()
299 log->count--; in remove_from_logsync()
300 list_del(&mp->synclist); in remove_from_logsync()
313 mapping_set_error(folio->mapping, err); in last_write_complete()
318 if (mp && test_bit(META_io, &mp->flag)) { in last_write_complete()
319 if (mp->lsn) in last_write_complete()
321 clear_bit(META_io, &mp->flag); in last_write_complete()
333 struct folio *folio = bio->bi_private; in metapage_write_end_io()
335 BUG_ON(!folio->private); in metapage_write_end_io()
337 dec_io(folio, bio->bi_status, last_write_complete); in metapage_write_end_io()
346 struct inode *inode = folio->mapping->host; in metapage_write_folio()
347 int blocks_per_mp = JFS_SBI(inode->i_sb)->nbperpage; in metapage_write_folio()
349 int xlen; in metapage_write_folio() local
362 page_start = folio_pos(folio) >> inode->i_blkbits; in metapage_write_folio()
370 if (!mp || !test_bit(META_dirty, &mp->flag)) in metapage_write_folio()
373 if (mp->nohomeok && !test_bit(META_forcewrite, &mp->flag)) { in metapage_write_folio()
374 redirty = 1; in metapage_write_folio()
379 if (mp->log && !(mp->log->cflag & logGC_PAGEOUT)) in metapage_write_folio()
380 jfs_flush_journal(mp->log, 0); in metapage_write_folio()
384 clear_bit(META_dirty, &mp->flag); in metapage_write_folio()
385 set_bit(META_io, &mp->flag); in metapage_write_folio()
386 block_offset = offset >> inode->i_blkbits; in metapage_write_folio()
389 if (xlen && lblock == next_block) { in metapage_write_folio()
391 len = min(xlen, blocks_per_mp); in metapage_write_folio()
392 xlen -= len; in metapage_write_folio()
393 bio_bytes += len << inode->i_blkbits; in metapage_write_folio()
403 if (!bio->bi_iter.bi_size) in metapage_write_folio()
410 xlen = (folio_size(folio) - offset) >> inode->i_blkbits; in metapage_write_folio()
411 pblock = metapage_get_blocks(inode, lblock, &xlen); in metapage_write_folio()
421 len = min(xlen, (int)JFS_SBI(inode->i_sb)->nbperpage); in metapage_write_folio()
423 bio = bio_alloc(inode->i_sb->s_bdev, 1, REQ_OP_WRITE, GFP_NOFS); in metapage_write_folio()
424 bio->bi_iter.bi_sector = pblock << (inode->i_blkbits - 9); in metapage_write_folio()
425 bio->bi_end_io = metapage_write_end_io; in metapage_write_folio()
426 bio->bi_private = folio; in metapage_write_folio()
430 bio_bytes = len << inode->i_blkbits; in metapage_write_folio()
432 xlen -= len; in metapage_write_folio()
437 if (!bio->bi_iter.bi_size) in metapage_write_folio()
462 while (bad_blocks--) in metapage_write_folio()
464 return -EIO; in metapage_write_folio()
482 struct inode *inode = folio->mapping->host; in metapage_read_folio()
488 int xlen; in metapage_read_folio() local
493 page_start = folio_pos(folio) >> inode->i_blkbits; in metapage_read_folio()
497 xlen = blocks_per_page - block_offset; in metapage_read_folio()
499 &xlen); in metapage_read_folio()
501 if (!folio->private) in metapage_read_folio()
507 bio = bio_alloc(inode->i_sb->s_bdev, 1, REQ_OP_READ, in metapage_read_folio()
509 bio->bi_iter.bi_sector = in metapage_read_folio()
510 pblock << (inode->i_blkbits - 9); in metapage_read_folio()
511 bio->bi_end_io = metapage_read_end_io; in metapage_read_folio()
512 bio->bi_private = folio; in metapage_read_folio()
513 len = xlen << inode->i_blkbits; in metapage_read_folio()
514 offset = block_offset << inode->i_blkbits; in metapage_read_folio()
516 block_offset += xlen; in metapage_read_folio()
541 if (mp->count || mp->nohomeok || in metapage_release_folio()
542 test_bit(META_dirty, &mp->flag)) { in metapage_release_folio()
543 jfs_info("count = %ld, nohomeok = %d", mp->count, in metapage_release_folio()
544 mp->nohomeok); in metapage_release_folio()
548 if (mp->lsn) in metapage_release_folio()
588 inode->i_ino, lblock, absolute); in __get_metapage()
590 l2bsize = inode->i_blkbits; in __get_metapage()
591 l2BlocksPerPage = PAGE_SHIFT - l2bsize; in __get_metapage()
593 page_offset = (lblock - (page_index << l2BlocksPerPage)) << l2bsize; in __get_metapage()
601 mapping = JFS_SBI(inode->i_sb)->direct_inode->i_mapping; in __get_metapage()
608 if ((lblock << inode->i_blkbits) >= inode->i_size) in __get_metapage()
610 mapping = inode->i_mapping; in __get_metapage()
631 if (mp->logical_size != size) { in __get_metapage()
632 jfs_error(inode->i_sb, in __get_metapage()
633 "get_mp->logical_size != size\n"); in __get_metapage()
635 mp->logical_size, size); in __get_metapage()
639 mp->count++; in __get_metapage()
641 if (test_bit(META_discard, &mp->flag)) { in __get_metapage()
643 jfs_error(inode->i_sb, in __get_metapage()
648 clear_bit(META_discard, &mp->flag); in __get_metapage()
655 mp->folio = folio; in __get_metapage()
656 mp->sb = inode->i_sb; in __get_metapage()
657 mp->flag = 0; in __get_metapage()
658 mp->xflag = COMMIT_PAGE; in __get_metapage()
659 mp->count = 1; in __get_metapage()
660 mp->nohomeok = 0; in __get_metapage()
661 mp->logical_size = size; in __get_metapage()
662 mp->data = folio_address(folio) + page_offset; in __get_metapage()
663 mp->index = lblock; in __get_metapage()
673 memset(mp->data, 0, PSIZE); in __get_metapage()
677 jfs_info("__get_metapage: returning = 0x%p data = 0x%p", mp, mp->data); in __get_metapage()
688 folio_get(mp->folio); in grab_metapage()
689 folio_lock(mp->folio); in grab_metapage()
690 mp->count++; in grab_metapage()
692 folio_unlock(mp->folio); in grab_metapage()
697 struct address_space *mapping = folio->mapping; in metapage_write_one()
725 struct folio *folio = mp->folio; in force_metapage()
727 set_bit(META_forcewrite, &mp->flag); in force_metapage()
728 clear_bit(META_sync, &mp->flag); in force_metapage()
733 jfs_error(mp->sb, "metapage_write_one() failed\n"); in force_metapage()
734 clear_bit(META_forcewrite, &mp->flag); in force_metapage()
740 folio_lock(mp->folio); in hold_metapage()
745 if (mp->count || mp->nohomeok) { in put_metapage()
747 folio_unlock(mp->folio); in put_metapage()
750 folio_get(mp->folio); in put_metapage()
751 mp->count++; in put_metapage()
753 folio_unlock(mp->folio); in put_metapage()
759 struct folio *folio = mp->folio; in release_metapage()
760 jfs_info("release_metapage: mp = 0x%p, flag = 0x%lx", mp, mp->flag); in release_metapage()
765 assert(mp->count); in release_metapage()
766 if (--mp->count || mp->nohomeok) { in release_metapage()
772 if (test_bit(META_dirty, &mp->flag)) { in release_metapage()
774 if (test_bit(META_sync, &mp->flag)) { in release_metapage()
775 clear_bit(META_sync, &mp->flag); in release_metapage()
777 jfs_error(mp->sb, "metapage_write_one() failed\n"); in release_metapage()
780 } else if (mp->lsn) /* discard_metapage doesn't remove it */ in release_metapage()
793 int l2BlocksPerPage = PAGE_SHIFT - ip->i_blkbits; in __invalidate_metapages()
794 int BlocksPerPage = 1 << l2BlocksPerPage; in __invalidate_metapages()
797 JFS_SBI(ip->i_sb)->direct_inode->i_mapping; in __invalidate_metapages()
805 for (lblock = addr & ~(BlocksPerPage - 1); lblock < addr + len; in __invalidate_metapages()
815 if (mp->index < addr) in __invalidate_metapages()
817 if (mp->index >= addr + len) in __invalidate_metapages()
820 clear_bit(META_dirty, &mp->flag); in __invalidate_metapages()
821 set_bit(META_discard, &mp->flag); in __invalidate_metapages()
822 if (mp->lsn) in __invalidate_metapages()