Lines Matching refs:mp

49 static inline int metapage_locked(struct metapage *mp)  in metapage_locked()  argument
51 return test_bit(META_locked, &mp->flag); in metapage_locked()
54 static inline int trylock_metapage(struct metapage *mp) in trylock_metapage() argument
56 return test_and_set_bit(META_locked, &mp->flag); in trylock_metapage()
59 static inline void unlock_metapage(struct metapage *mp) in unlock_metapage() argument
61 clear_bit(META_locked, &mp->flag); in unlock_metapage()
62 wake_up(&mp->wait); in unlock_metapage()
65 static void __lock_metapage(struct metapage *mp) in __lock_metapage() argument
71 add_wait_queue_exclusive(&mp->wait, &wait); in __lock_metapage()
74 if (metapage_locked(mp)) { in __lock_metapage()
79 } while (trylock_metapage(mp)); in __lock_metapage()
81 remove_wait_queue(&mp->wait, &wait); in __lock_metapage()
85 static inline void lock_metapage(struct metapage *mp) in lock_metapage() argument
87 if (trylock_metapage(mp)) in lock_metapage()
88 __lock_metapage(mp); in lock_metapage()
104 struct metapage *mp = (struct metapage *)foo; in init_once() local
108 mp->lid = 0; in init_once()
109 mp->lsn = 0; in init_once()
110 mp->flag = 0; in init_once()
111 mp->data = NULL; in init_once()
112 mp->clsn = 0; in init_once()
113 mp->log = NULL; in init_once()
114 set_bit(META_free, &mp->flag); in init_once()
115 init_waitqueue_head(&mp->wait); in init_once()
150 static void __free_metapage(struct metapage *mp) in __free_metapage() argument
152 mp->flag = 0; in __free_metapage()
153 set_bit(META_free, &mp->flag); in __free_metapage()
156 reserved_metapages[num_reserved++] = mp; in __free_metapage()
158 kmem_cache_free(metapage_cache, mp); in __free_metapage()
161 static inline void free_metapage(struct metapage * mp) in free_metapage() argument
164 __free_metapage(mp); in free_metapage()
170 struct metapage *mp; in metapage_init() local
186 mp = kmem_cache_alloc(metapage_cache, GFP_NOFS); in metapage_init()
187 if (mp) in metapage_init()
188 reserved_metapages[num_reserved++] = mp; in metapage_init()
243 static void add_to_hash(struct metapage * mp, struct metapage ** hash_ptr) in add_to_hash() argument
246 (*hash_ptr)->hash_prev = mp; in add_to_hash()
248 mp->hash_prev = NULL; in add_to_hash()
249 mp->hash_next = *hash_ptr; in add_to_hash()
250 *hash_ptr = mp; in add_to_hash()
253 static void remove_from_hash(struct metapage * mp, struct metapage ** hash_ptr) in remove_from_hash() argument
255 if (mp->hash_prev) in remove_from_hash()
256 mp->hash_prev->hash_next = mp->hash_next; in remove_from_hash()
258 assert(*hash_ptr == mp); in remove_from_hash()
259 *hash_ptr = mp->hash_next; in remove_from_hash()
262 if (mp->hash_next) in remove_from_hash()
263 mp->hash_next->hash_prev = mp->hash_prev; in remove_from_hash()
276 struct metapage *mp; in __get_metapage() local
298 mp = search_hash(hash_ptr, mapping, lblock); in __get_metapage()
299 if (mp) { in __get_metapage()
301 if (test_bit(META_stale, &mp->flag)) { in __get_metapage()
306 mp->count++; in __get_metapage()
307 lock_metapage(mp); in __get_metapage()
309 if (test_bit(META_discard, &mp->flag)) { in __get_metapage()
314 release_metapage(mp); in __get_metapage()
317 clear_bit(META_discard, &mp->flag); in __get_metapage()
319 jfs_info("__get_metapage: found 0x%p, in hash", mp); in __get_metapage()
320 if (mp->logical_size != size) { in __get_metapage()
323 release_metapage(mp); in __get_metapage()
351 mp = alloc_metapage(&dropped_lock, no_wait); in __get_metapage()
352 if (!mp) { in __get_metapage()
363 __free_metapage(mp); in __get_metapage()
364 mp = mp2; in __get_metapage()
368 mp->flag = 0; in __get_metapage()
369 lock_metapage(mp); in __get_metapage()
371 set_bit(META_absolute, &mp->flag); in __get_metapage()
372 mp->xflag = COMMIT_PAGE; in __get_metapage()
373 mp->count = 1; in __get_metapage()
374 atomic_set(&mp->nohomeok,0); in __get_metapage()
375 mp->mapping = mapping; in __get_metapage()
376 mp->index = lblock; in __get_metapage()
377 mp->page = 0; in __get_metapage()
378 mp->logical_size = size; in __get_metapage()
379 add_to_hash(mp, hash_ptr); in __get_metapage()
384 mp->page = grab_cache_page(mapping, page_index); in __get_metapage()
385 if (!mp->page) { in __get_metapage()
390 UnlockPage(mp->page); in __get_metapage()
394 mp->page = read_cache_page(mapping, lblock, in __get_metapage()
396 if (IS_ERR(mp->page)) { in __get_metapage()
402 mp->data = kmap(mp->page) + page_offset; in __get_metapage()
406 memset(mp->data, 0, PSIZE); in __get_metapage()
408 jfs_info("__get_metapage: returning = 0x%p", mp); in __get_metapage()
409 return mp; in __get_metapage()
413 remove_from_hash(mp, hash_ptr); in __get_metapage()
414 __free_metapage(mp); in __get_metapage()
419 void hold_metapage(struct metapage * mp, int force) in hold_metapage() argument
423 mp->count++; in hold_metapage()
426 ASSERT (!(test_bit(META_forced, &mp->flag))); in hold_metapage()
427 if (trylock_metapage(mp)) in hold_metapage()
428 set_bit(META_forced, &mp->flag); in hold_metapage()
430 lock_metapage(mp); in hold_metapage()
435 static void __write_metapage(struct metapage * mp) in __write_metapage() argument
437 int l2bsize = mp->mapping->host->i_blkbits; in __write_metapage()
443 jfs_info("__write_metapage: mp = 0x%p", mp); in __write_metapage()
445 if (test_bit(META_discard, &mp->flag)) { in __write_metapage()
449 clear_bit(META_dirty, &mp->flag); in __write_metapage()
453 page_index = mp->page->index; in __write_metapage()
455 (mp->index - (page_index << l2BlocksPerPage)) << l2bsize; in __write_metapage()
457 lock_page(mp->page); in __write_metapage()
458 rc = mp->mapping->a_ops->prepare_write(NULL, mp->page, page_offset, in __write_metapage()
460 mp->logical_size); in __write_metapage()
463 ClearPageUptodate(mp->page); in __write_metapage()
464 UnlockPage(mp->page); in __write_metapage()
465 kunmap(mp->page); in __write_metapage()
466 clear_bit(META_dirty, &mp->flag); in __write_metapage()
469 rc = mp->mapping->a_ops->commit_write(NULL, mp->page, page_offset, in __write_metapage()
471 mp->logical_size); in __write_metapage()
476 UnlockPage(mp->page); in __write_metapage()
477 clear_bit(META_dirty, &mp->flag); in __write_metapage()
482 static inline void sync_metapage(struct metapage *mp) in sync_metapage() argument
484 struct page *page = mp->page; in sync_metapage()
499 void release_metapage(struct metapage * mp) in release_metapage() argument
503 jfs_info("release_metapage: mp = 0x%p, flag = 0x%lx", mp, mp->flag); in release_metapage()
506 if (test_bit(META_forced, &mp->flag)) { in release_metapage()
507 clear_bit(META_forced, &mp->flag); in release_metapage()
508 mp->count--; in release_metapage()
513 assert(mp->count); in release_metapage()
514 if (--mp->count || atomic_read(&mp->nohomeok)) { in release_metapage()
515 unlock_metapage(mp); in release_metapage()
520 if (mp->page) { in release_metapage()
521 set_bit(META_stale, &mp->flag); in release_metapage()
523 kunmap(mp->page); in release_metapage()
524 mp->data = 0; in release_metapage()
525 if (test_bit(META_dirty, &mp->flag)) in release_metapage()
526 __write_metapage(mp); in release_metapage()
527 if (test_bit(META_sync, &mp->flag)) { in release_metapage()
528 sync_metapage(mp); in release_metapage()
529 clear_bit(META_sync, &mp->flag); in release_metapage()
532 if (test_bit(META_discard, &mp->flag)) { in release_metapage()
533 lock_page(mp->page); in release_metapage()
534 block_flushpage(mp->page, 0); in release_metapage()
535 UnlockPage(mp->page); in release_metapage()
538 page_cache_release(mp->page); in release_metapage()
539 mp->page = NULL; in release_metapage()
544 if (mp->lsn) { in release_metapage()
548 log = mp->log; in release_metapage()
550 mp->log = 0; in release_metapage()
551 mp->lsn = 0; in release_metapage()
552 mp->clsn = 0; in release_metapage()
554 list_del(&mp->synclist); in release_metapage()
557 remove_from_hash(mp, meta_hash(mp->mapping, mp->index)); in release_metapage()
560 free_metapage(mp); in release_metapage()
570 struct metapage *mp; in __invalidate_metapages() local
582 mp = search_hash(hash_ptr, mapping, lblock); in __invalidate_metapages()
583 if (mp) { in __invalidate_metapages()
584 if (test_bit(META_stale, &mp->flag)) { in __invalidate_metapages()
590 set_bit(META_discard, &mp->flag); in __invalidate_metapages()