Lines Matching +full:disk +full:- +full:activity
1 // SPDX-License-Identifier: GPL-2.0-or-later
7 Copyright (C) 2003-2008, LINBIT Information Technologies GmbH.
8 Copyright (C) 2003-2008, Philipp Reisner <philipp.reisner@linbit.com>.
9 Copyright (C) 2003-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
31 * in the on disk ring buffer */
38 * purge-all, set-all-idle, set-all-active, ... to-be-defined
48 /* maximum slot number, "al-extents" in drbd.conf speak.
57 * sectors-written since device creation, and other data generation tag
61 /* --- 36 byte used --- */
76 /* --- 420 bytes used (36 + 64*6) --- */
78 /* 4096 - 420 = 3676 = 919 * 4 */
86 wait_event(device->misc_wait, in drbd_md_get_buffer()
87 (r = atomic_cmpxchg(&device->md_io.in_use, 0, 1)) == 0 || in drbd_md_get_buffer()
88 device->state.disk <= D_FAILED); in drbd_md_get_buffer()
93 device->md_io.current_use = intent; in drbd_md_get_buffer()
94 device->md_io.start_jif = jiffies; in drbd_md_get_buffer()
95 device->md_io.submit_jif = device->md_io.start_jif - 1; in drbd_md_get_buffer()
96 return page_address(device->md_io.page); in drbd_md_get_buffer()
101 if (atomic_dec_and_test(&device->md_io.in_use)) in drbd_md_put_buffer()
102 wake_up(&device->misc_wait); in drbd_md_put_buffer()
111 dt = rcu_dereference(bdev->disk_conf)->disk_timeout; in wait_until_done_or_force_detached()
117 dt = wait_event_timeout(device->misc_wait, in wait_until_done_or_force_detached()
118 *done || test_bit(FORCE_DETACH, &device->flags), dt); in wait_until_done_or_force_detached()
120 drbd_err(device, "meta-data IO operation timed out\n"); in wait_until_done_or_force_detached()
134 device->md_io.done = 0; in _drbd_md_sync_page_io()
135 device->md_io.error = -ENODEV; in _drbd_md_sync_page_io()
137 if ((op == REQ_OP_WRITE) && !test_bit(MD_NO_FUA, &device->flags)) in _drbd_md_sync_page_io()
142 bio_set_dev(bio, bdev->md_bdev); in _drbd_md_sync_page_io()
143 bio->bi_iter.bi_sector = sector; in _drbd_md_sync_page_io()
144 err = -EIO; in _drbd_md_sync_page_io()
145 if (bio_add_page(bio, device->md_io.page, size, 0) != size) in _drbd_md_sync_page_io()
147 bio->bi_private = device; in _drbd_md_sync_page_io()
148 bio->bi_end_io = drbd_md_endio; in _drbd_md_sync_page_io()
151 if (op != REQ_OP_WRITE && device->state.disk == D_DISKLESS && device->ldev == NULL) in _drbd_md_sync_page_io()
157 err = -ENODEV; in _drbd_md_sync_page_io()
162 atomic_inc(&device->md_io.in_use); /* drbd_md_put_buffer() is in the completion handler */ in _drbd_md_sync_page_io()
163 device->md_io.submit_jif = jiffies; in _drbd_md_sync_page_io()
168 wait_until_done_or_force_detached(device, bdev, &device->md_io.done); in _drbd_md_sync_page_io()
169 if (!bio->bi_status) in _drbd_md_sync_page_io()
170 err = device->md_io.error; in _drbd_md_sync_page_io()
181 D_ASSERT(device, atomic_read(&device->md_io.in_use) == 1); in drbd_md_sync_page_io()
183 BUG_ON(!bdev->md_bdev); in drbd_md_sync_page_io()
186 current->comm, current->pid, __func__, in drbd_md_sync_page_io()
193 current->comm, current->pid, __func__, in drbd_md_sync_page_io()
209 tmp = lc_find(device->resync, enr/AL_EXT_PER_BM_SECT); in find_active_resync_extent()
212 if (test_bit(BME_NO_WRITES, &bm_ext->flags)) in find_active_resync_extent()
224 spin_lock_irq(&device->al_lock); in _al_get()
227 wake = !test_and_set_bit(BME_PRIORITY, &bm_ext->flags); in _al_get()
228 spin_unlock_irq(&device->al_lock); in _al_get()
230 wake_up(&device->al_wait); in _al_get()
234 al_ext = lc_try_get(device->act_log, enr); in _al_get()
236 al_ext = lc_get(device->act_log, enr); in _al_get()
237 spin_unlock_irq(&device->al_lock); in _al_get()
243 /* for bios crossing activity log extent boundaries, in drbd_al_begin_io_fastpath()
245 unsigned first = i->sector >> (AL_EXTENT_SHIFT-9); in drbd_al_begin_io_fastpath()
246 unsigned last = i->size == 0 ? first : (i->sector + (i->size >> 9) - 1) >> (AL_EXTENT_SHIFT-9); in drbd_al_begin_io_fastpath()
249 D_ASSERT(device, atomic_read(&device->local_cnt) > 0); in drbd_al_begin_io_fastpath()
260 /* for bios crossing activity log extent boundaries, in drbd_al_begin_io_prepare()
262 unsigned first = i->sector >> (AL_EXTENT_SHIFT-9); in drbd_al_begin_io_prepare()
263 unsigned last = i->size == 0 ? first : (i->sector + (i->size >> 9) - 1) >> (AL_EXTENT_SHIFT-9); in drbd_al_begin_io_prepare()
268 D_ASSERT(device, atomic_read(&device->local_cnt) > 0); in drbd_al_begin_io_prepare()
272 wait_event(device->al_wait, in drbd_al_begin_io_prepare()
274 if (al_ext->lc_number != enr) in drbd_al_begin_io_prepare()
280 #if (PAGE_SHIFT + 3) < (AL_EXTENT_SHIFT - BM_BLOCK_SHIFT)
293 ((PAGE_SHIFT + 3) - in al_extent_to_bm_page()
295 (AL_EXTENT_SHIFT - BM_BLOCK_SHIFT)); in al_extent_to_bm_page()
300 const unsigned int stripes = device->ldev->md.al_stripes; in al_tr_number_to_on_disk_sector()
301 const unsigned int stripe_size_4kB = device->ldev->md.al_stripe_size_4k; in al_tr_number_to_on_disk_sector()
303 /* transaction number, modulo on-disk ring buffer wrap around */ in al_tr_number_to_on_disk_sector()
304 unsigned int t = device->al_tr_number % (device->ldev->md.al_size_4k); in al_tr_number_to_on_disk_sector()
306 /* ... to aligned 4k on disk block */ in al_tr_number_to_on_disk_sector()
309 /* ... to 512 byte sector in activity log */ in al_tr_number_to_on_disk_sector()
312 /* ... plus offset to the on disk position */ in al_tr_number_to_on_disk_sector()
313 return device->ldev->md.md_offset + device->ldev->md.al_offset + t; in al_tr_number_to_on_disk_sector()
326 buffer->magic = cpu_to_be32(DRBD_AL_MAGIC); in __al_write_transaction()
327 buffer->tr_number = cpu_to_be32(device->al_tr_number); in __al_write_transaction()
334 * once we set the LC_LOCKED -- from drbd_al_begin_io(), in __al_write_transaction()
335 * lc_try_lock_for_transaction() --, someone may still in __al_write_transaction()
337 spin_lock_irq(&device->al_lock); in __al_write_transaction()
338 list_for_each_entry(e, &device->act_log->to_be_changed, list) { in __al_write_transaction()
343 buffer->update_slot_nr[i] = cpu_to_be16(e->lc_index); in __al_write_transaction()
344 buffer->update_extent_nr[i] = cpu_to_be32(e->lc_new_number); in __al_write_transaction()
345 if (e->lc_number != LC_FREE) in __al_write_transaction()
347 al_extent_to_bm_page(e->lc_number)); in __al_write_transaction()
350 spin_unlock_irq(&device->al_lock); in __al_write_transaction()
353 buffer->n_updates = cpu_to_be16(i); in __al_write_transaction()
355 buffer->update_slot_nr[i] = cpu_to_be16(-1); in __al_write_transaction()
356 buffer->update_extent_nr[i] = cpu_to_be32(LC_FREE); in __al_write_transaction()
359 buffer->context_size = cpu_to_be16(device->act_log->nr_elements); in __al_write_transaction()
360 buffer->context_start_slot_nr = cpu_to_be16(device->al_tr_cycle); in __al_write_transaction()
363 device->act_log->nr_elements - device->al_tr_cycle); in __al_write_transaction()
365 unsigned idx = device->al_tr_cycle + i; in __al_write_transaction()
366 extent_nr = lc_element_by_index(device->act_log, idx)->lc_number; in __al_write_transaction()
367 buffer->context[i] = cpu_to_be32(extent_nr); in __al_write_transaction()
370 buffer->context[i] = cpu_to_be32(LC_FREE); in __al_write_transaction()
372 device->al_tr_cycle += AL_CONTEXT_PER_TRANSACTION; in __al_write_transaction()
373 if (device->al_tr_cycle >= device->act_log->nr_elements) in __al_write_transaction()
374 device->al_tr_cycle = 0; in __al_write_transaction()
379 buffer->crc32c = cpu_to_be32(crc); in __al_write_transaction()
382 err = -EIO; in __al_write_transaction()
386 write_al_updates = rcu_dereference(device->ldev->disk_conf)->al_updates; in __al_write_transaction()
389 if (drbd_md_sync_page_io(device, device->ldev, sector, WRITE)) { in __al_write_transaction()
390 err = -EIO; in __al_write_transaction()
393 device->al_tr_number++; in __al_write_transaction()
394 device->al_writ_cnt++; in __al_write_transaction()
408 drbd_err(device, "disk is %s, cannot start al transaction\n", in al_write_transaction()
409 drbd_disk_str(device->state.disk)); in al_write_transaction()
410 return -EIO; in al_write_transaction()
414 if (device->state.disk < D_INCONSISTENT) { in al_write_transaction()
416 "disk is %s, cannot write al transaction\n", in al_write_transaction()
417 drbd_disk_str(device->state.disk)); in al_write_transaction()
419 return -EIO; in al_write_transaction()
425 drbd_err(device, "disk failed while waiting for md_io buffer\n"); in al_write_transaction()
427 return -ENODEV; in al_write_transaction()
446 wait_event(device->al_wait, in drbd_al_begin_io_commit()
447 device->act_log->pending_changes == 0 || in drbd_al_begin_io_commit()
448 (locked = lc_try_lock_for_transaction(device->act_log))); in drbd_al_begin_io_commit()
453 if (device->act_log->pending_changes) { in drbd_al_begin_io_commit()
457 write_al_updates = rcu_dereference(device->ldev->disk_conf)->al_updates; in drbd_al_begin_io_commit()
462 spin_lock_irq(&device->al_lock); in drbd_al_begin_io_commit()
467 lc_committed(device->act_log); in drbd_al_begin_io_commit()
468 spin_unlock_irq(&device->al_lock); in drbd_al_begin_io_commit()
470 lc_unlock(device->act_log); in drbd_al_begin_io_commit()
471 wake_up(&device->al_wait); in drbd_al_begin_io_commit()
476 * @delegate: delegate activity log I/O to the worker thread
486 struct lru_cache *al = device->act_log; in drbd_al_begin_io_nonblock()
487 /* for bios crossing activity log extent boundaries, in drbd_al_begin_io_nonblock()
489 unsigned first = i->sector >> (AL_EXTENT_SHIFT-9); in drbd_al_begin_io_nonblock()
490 unsigned last = i->size == 0 ? first : (i->sector + (i->size >> 9) - 1) >> (AL_EXTENT_SHIFT-9); in drbd_al_begin_io_nonblock()
497 nr_al_extents = 1 + last - first; /* worst case: all touched extends are cold. */ in drbd_al_begin_io_nonblock()
498 available_update_slots = min(al->nr_elements - al->used, in drbd_al_begin_io_nonblock()
499 al->max_pending_changes - al->pending_changes); in drbd_al_begin_io_nonblock()
503 * and use that instead of the worst-case nr_al_extents */ in drbd_al_begin_io_nonblock()
505 /* Too many activity log extents are currently "hot". in drbd_al_begin_io_nonblock()
513 if (!al->pending_changes) in drbd_al_begin_io_nonblock()
514 __set_bit(__LC_STARVING, &device->act_log->flags); in drbd_al_begin_io_nonblock()
515 return -ENOBUFS; in drbd_al_begin_io_nonblock()
521 tmp = lc_find(device->resync, enr/AL_EXT_PER_BM_SECT); in drbd_al_begin_io_nonblock()
524 if (test_bit(BME_NO_WRITES, &bm_ext->flags)) { in drbd_al_begin_io_nonblock()
525 if (!test_and_set_bit(BME_PRIORITY, &bm_ext->flags)) in drbd_al_begin_io_nonblock()
526 return -EBUSY; in drbd_al_begin_io_nonblock()
527 return -EWOULDBLOCK; in drbd_al_begin_io_nonblock()
537 al_ext = lc_get_cumulative(device->act_log, enr); in drbd_al_begin_io_nonblock()
546 /* for bios crossing activity log extent boundaries, in drbd_al_complete_io()
548 unsigned first = i->sector >> (AL_EXTENT_SHIFT-9); in drbd_al_complete_io()
549 unsigned last = i->size == 0 ? first : (i->sector + (i->size >> 9) - 1) >> (AL_EXTENT_SHIFT-9); in drbd_al_complete_io()
555 spin_lock_irqsave(&device->al_lock, flags); in drbd_al_complete_io()
558 extent = lc_find(device->act_log, enr); in drbd_al_complete_io()
563 lc_put(device->act_log, extent); in drbd_al_complete_io()
565 spin_unlock_irqrestore(&device->al_lock, flags); in drbd_al_complete_io()
566 wake_up(&device->al_wait); in drbd_al_complete_io()
573 spin_lock_irq(&device->al_lock); in _try_lc_del()
574 rv = (al_ext->refcnt == 0); in _try_lc_del()
576 lc_del(device->act_log, al_ext); in _try_lc_del()
577 spin_unlock_irq(&device->al_lock); in _try_lc_del()
583 * drbd_al_shrink() - Removes all active extents form the activity log
586 * Removes all active extents form the activity log, waiting until
589 * You need to lock device->act_log with lc_try_lock() / lc_unlock()
596 D_ASSERT(device, test_bit(__LC_LOCKED, &device->act_log->flags)); in drbd_al_shrink()
598 for (i = 0; i < device->act_log->nr_elements; i++) { in drbd_al_shrink()
599 al_ext = lc_element_by_index(device->act_log, i); in drbd_al_shrink()
600 if (al_ext->lc_number == LC_FREE) in drbd_al_shrink()
602 wait_event(device->al_wait, _try_lc_del(device, al_ext)); in drbd_al_shrink()
605 wake_up(&device->al_wait); in drbd_al_shrink()
611 struct drbd_md *md = &device->ldev->md; in drbd_al_initialize()
612 int al_size_4k = md->al_stripes * md->al_stripe_size_4k; in drbd_al_initialize()
617 spin_lock_irq(&device->al_lock); in drbd_al_initialize()
618 lc_committed(device->act_log); in drbd_al_initialize()
619 spin_unlock_irq(&device->al_lock); in drbd_al_initialize()
623 * on-disk ring buffer. */ in drbd_al_initialize()
639 * resync LRU-cache are 16MB each.
642 * Adjusts the caching members ->rs_left (success) or ->rs_failed (!success),
649 * TODO will be obsoleted once we have a caching lru of the on disk bitmap
657 D_ASSERT(device, atomic_read(&device->local_cnt)); in update_rs_extent()
659 /* When setting out-of-sync bits, in update_rs_extent()
664 * already -- or we want to pull it in if necessary -- (lc_get), in update_rs_extent()
667 e = lc_find(device->resync, enr); in update_rs_extent()
669 e = lc_get(device->resync, enr); in update_rs_extent()
672 if (ext->lce.lc_number == enr) { in update_rs_extent()
674 ext->rs_left -= count; in update_rs_extent()
676 ext->rs_left += count; in update_rs_extent()
678 ext->rs_failed += count; in update_rs_extent()
679 if (ext->rs_left < ext->rs_failed) { in update_rs_extent()
682 ext->lce.lc_number, ext->rs_left, in update_rs_extent()
683 ext->rs_failed, count, in update_rs_extent()
684 drbd_conn_str(device->state.conn)); in update_rs_extent()
688 * the set bits to cache that value in ext->rs_left. in update_rs_extent()
692 ext->rs_left = drbd_bm_e_weight(device, enr); in update_rs_extent()
702 if (ext->flags != 0) { in update_rs_extent()
704 " -> %d[%u;00]\n", in update_rs_extent()
705 ext->lce.lc_number, ext->rs_left, in update_rs_extent()
706 ext->flags, enr, rs_left); in update_rs_extent()
707 ext->flags = 0; in update_rs_extent()
709 if (ext->rs_failed) { in update_rs_extent()
712 ext->lce.lc_number, ext->rs_failed); in update_rs_extent()
714 ext->rs_left = rs_left; in update_rs_extent()
715 ext->rs_failed = (mode == RECORD_RS_FAILED) ? count : 0; in update_rs_extent()
718 lc_committed(device->resync); in update_rs_extent()
721 lc_put(device->resync, &ext->lce); in update_rs_extent()
724 if (ext->rs_left <= ext->rs_failed) { in update_rs_extent()
725 ext->rs_failed = 0; in update_rs_extent()
731 device->resync_locked, in update_rs_extent()
732 device->resync->nr_elements, in update_rs_extent()
733 device->resync->flags); in update_rs_extent()
741 unsigned long last = device->rs_mark_time[device->rs_last_mark]; in drbd_advance_rs_marks()
742 int next = (device->rs_last_mark + 1) % DRBD_SYNC_MARKS; in drbd_advance_rs_marks()
744 if (device->rs_mark_left[device->rs_last_mark] != still_to_go && in drbd_advance_rs_marks()
745 device->state.conn != C_PAUSED_SYNC_T && in drbd_advance_rs_marks()
746 device->state.conn != C_PAUSED_SYNC_S) { in drbd_advance_rs_marks()
747 device->rs_mark_time[next] = now; in drbd_advance_rs_marks()
748 device->rs_mark_left[next] = still_to_go; in drbd_advance_rs_marks()
749 device->rs_last_mark = next; in drbd_advance_rs_marks()
754 /* It is called lazy update, so don't do write-out too often. */
757 return time_after(jiffies, device->rs_last_bcast + 2*HZ); in lazy_bitmap_update_due()
763 struct drbd_connection *connection = first_peer_device(device)->connection; in maybe_schedule_on_disk_bitmap_update()
764 if (connection->agreed_pro_version <= 95 || in maybe_schedule_on_disk_bitmap_update()
765 is_sync_target_state(device->state.conn)) in maybe_schedule_on_disk_bitmap_update()
766 set_bit(RS_DONE, &device->flags); in maybe_schedule_on_disk_bitmap_update()
770 * to avoid uuids-rotated-too-fast causing full resync in maybe_schedule_on_disk_bitmap_update()
784 * We keep a count of set bits per resync-extent in the ->rs_left in update_sync_bits()
811 spin_lock_irqsave(&device->al_lock, flags); in update_sync_bits()
813 spin_unlock_irqrestore(&device->al_lock, flags); in update_sync_bits()
821 bool rs_is_done = (still_to_go <= device->rs_failed); in update_sync_bits()
826 device->rs_failed += count; in update_sync_bits()
827 wake_up(&device->al_wait); in update_sync_bits()
866 return 0; /* no disk, no metadata, no bitmap to manipulate bits in */ in __drbd_change_sync()
868 nr_sectors = get_capacity(device->vdisk); in __drbd_change_sync()
869 esector = sector + (size >> 9) - 1; in __drbd_change_sync()
874 esector = nr_sectors - 1; in __drbd_change_sync()
876 lbnr = BM_SECT_TO_BIT(nr_sectors-1); in __drbd_change_sync()
881 if (unlikely(esector < BM_SECT_PER_BIT-1)) in __drbd_change_sync()
883 if (unlikely(esector == (nr_sectors-1))) in __drbd_change_sync()
886 ebnr = BM_SECT_TO_BIT(esector - (BM_SECT_PER_BIT-1)); in __drbd_change_sync()
887 sbnr = BM_SECT_TO_BIT(sector + BM_SECT_PER_BIT-1); in __drbd_change_sync()
909 spin_lock_irq(&device->al_lock); in _bme_get()
910 if (device->resync_locked > device->resync->nr_elements/2) { in _bme_get()
911 spin_unlock_irq(&device->al_lock); in _bme_get()
914 e = lc_get(device->resync, enr); in _bme_get()
917 if (bm_ext->lce.lc_number != enr) { in _bme_get()
918 bm_ext->rs_left = drbd_bm_e_weight(device, enr); in _bme_get()
919 bm_ext->rs_failed = 0; in _bme_get()
920 lc_committed(device->resync); in _bme_get()
923 if (bm_ext->lce.refcnt == 1) in _bme_get()
924 device->resync_locked++; in _bme_get()
925 set_bit(BME_NO_WRITES, &bm_ext->flags); in _bme_get()
927 rs_flags = device->resync->flags; in _bme_get()
928 spin_unlock_irq(&device->al_lock); in _bme_get()
930 wake_up(&device->al_wait); in _bme_get()
946 spin_lock_irq(&device->al_lock); in _is_in_al()
947 rv = lc_is_used(device->act_log, enr); in _is_in_al()
948 spin_unlock_irq(&device->al_lock); in _is_in_al()
954 * drbd_rs_begin_io() - Gets an extent in the resync LRU cache and sets it to BME_LOCKED
958 * This functions sleeps on al_wait. Returns 0 on success, -EINTR if interrupted.
968 sig = wait_event_interruptible(device->al_wait, in drbd_rs_begin_io()
971 return -EINTR; in drbd_rs_begin_io()
973 if (test_bit(BME_LOCKED, &bm_ext->flags)) in drbd_rs_begin_io()
976 /* step aside only while we are above c-min-rate; unless disabled. */ in drbd_rs_begin_io()
980 sig = wait_event_interruptible(device->al_wait, in drbd_rs_begin_io()
982 (sa && test_bit(BME_PRIORITY, &bm_ext->flags))); in drbd_rs_begin_io()
984 if (sig || (sa && test_bit(BME_PRIORITY, &bm_ext->flags))) { in drbd_rs_begin_io()
985 spin_lock_irq(&device->al_lock); in drbd_rs_begin_io()
986 if (lc_put(device->resync, &bm_ext->lce) == 0) { in drbd_rs_begin_io()
987 bm_ext->flags = 0; /* clears BME_NO_WRITES and eventually BME_PRIORITY */ in drbd_rs_begin_io()
988 device->resync_locked--; in drbd_rs_begin_io()
989 wake_up(&device->al_wait); in drbd_rs_begin_io()
991 spin_unlock_irq(&device->al_lock); in drbd_rs_begin_io()
993 return -EINTR; in drbd_rs_begin_io()
995 return -EINTR; in drbd_rs_begin_io()
999 set_bit(BME_LOCKED, &bm_ext->flags); in drbd_rs_begin_io()
1004 * drbd_try_rs_begin_io() - Gets an extent in the resync LRU cache, does not sleep
1009 * tries to set it to BME_LOCKED. Returns 0 upon success, and -EAGAIN
1021 /* If we need to throttle, a half-locked (only marked BME_NO_WRITES, in drbd_try_rs_begin_io()
1023 * need to throttle. There is at most one such half-locked extent, in drbd_try_rs_begin_io()
1026 if (throttle && device->resync_wenr != enr) in drbd_try_rs_begin_io()
1027 return -EAGAIN; in drbd_try_rs_begin_io()
1029 spin_lock_irq(&device->al_lock); in drbd_try_rs_begin_io()
1030 if (device->resync_wenr != LC_FREE && device->resync_wenr != enr) { in drbd_try_rs_begin_io()
1044 e = lc_find(device->resync, device->resync_wenr); in drbd_try_rs_begin_io()
1047 D_ASSERT(device, !test_bit(BME_LOCKED, &bm_ext->flags)); in drbd_try_rs_begin_io()
1048 D_ASSERT(device, test_bit(BME_NO_WRITES, &bm_ext->flags)); in drbd_try_rs_begin_io()
1049 clear_bit(BME_NO_WRITES, &bm_ext->flags); in drbd_try_rs_begin_io()
1050 device->resync_wenr = LC_FREE; in drbd_try_rs_begin_io()
1051 if (lc_put(device->resync, &bm_ext->lce) == 0) { in drbd_try_rs_begin_io()
1052 bm_ext->flags = 0; in drbd_try_rs_begin_io()
1053 device->resync_locked--; in drbd_try_rs_begin_io()
1055 wake_up(&device->al_wait); in drbd_try_rs_begin_io()
1061 e = lc_try_get(device->resync, enr); in drbd_try_rs_begin_io()
1064 if (test_bit(BME_LOCKED, &bm_ext->flags)) in drbd_try_rs_begin_io()
1066 if (!test_and_set_bit(BME_NO_WRITES, &bm_ext->flags)) { in drbd_try_rs_begin_io()
1067 device->resync_locked++; in drbd_try_rs_begin_io()
1073 bm_ext->lce.refcnt--; in drbd_try_rs_begin_io()
1074 D_ASSERT(device, bm_ext->lce.refcnt > 0); in drbd_try_rs_begin_io()
1079 if (device->resync_locked > device->resync->nr_elements-3) in drbd_try_rs_begin_io()
1081 /* Do or do not. There is no try. -- Yoda */ in drbd_try_rs_begin_io()
1082 e = lc_get(device->resync, enr); in drbd_try_rs_begin_io()
1085 const unsigned long rs_flags = device->resync->flags; in drbd_try_rs_begin_io()
1092 if (bm_ext->lce.lc_number != enr) { in drbd_try_rs_begin_io()
1093 bm_ext->rs_left = drbd_bm_e_weight(device, enr); in drbd_try_rs_begin_io()
1094 bm_ext->rs_failed = 0; in drbd_try_rs_begin_io()
1095 lc_committed(device->resync); in drbd_try_rs_begin_io()
1096 wake_up(&device->al_wait); in drbd_try_rs_begin_io()
1097 D_ASSERT(device, test_bit(BME_LOCKED, &bm_ext->flags) == 0); in drbd_try_rs_begin_io()
1099 set_bit(BME_NO_WRITES, &bm_ext->flags); in drbd_try_rs_begin_io()
1100 D_ASSERT(device, bm_ext->lce.refcnt == 1); in drbd_try_rs_begin_io()
1101 device->resync_locked++; in drbd_try_rs_begin_io()
1106 if (lc_is_used(device->act_log, al_enr+i)) in drbd_try_rs_begin_io()
1109 set_bit(BME_LOCKED, &bm_ext->flags); in drbd_try_rs_begin_io()
1111 device->resync_wenr = LC_FREE; in drbd_try_rs_begin_io()
1112 spin_unlock_irq(&device->al_lock); in drbd_try_rs_begin_io()
1118 D_ASSERT(device, !test_bit(BME_LOCKED, &bm_ext->flags)); in drbd_try_rs_begin_io()
1119 D_ASSERT(device, test_bit(BME_NO_WRITES, &bm_ext->flags)); in drbd_try_rs_begin_io()
1120 clear_bit(BME_NO_WRITES, &bm_ext->flags); in drbd_try_rs_begin_io()
1121 device->resync_wenr = LC_FREE; in drbd_try_rs_begin_io()
1122 if (lc_put(device->resync, &bm_ext->lce) == 0) { in drbd_try_rs_begin_io()
1123 bm_ext->flags = 0; in drbd_try_rs_begin_io()
1124 device->resync_locked--; in drbd_try_rs_begin_io()
1126 wake_up(&device->al_wait); in drbd_try_rs_begin_io()
1128 device->resync_wenr = enr; in drbd_try_rs_begin_io()
1130 spin_unlock_irq(&device->al_lock); in drbd_try_rs_begin_io()
1131 return -EAGAIN; in drbd_try_rs_begin_io()
1141 spin_lock_irqsave(&device->al_lock, flags); in drbd_rs_complete_io()
1142 e = lc_find(device->resync, enr); in drbd_rs_complete_io()
1145 spin_unlock_irqrestore(&device->al_lock, flags); in drbd_rs_complete_io()
1151 if (bm_ext->lce.refcnt == 0) { in drbd_rs_complete_io()
1152 spin_unlock_irqrestore(&device->al_lock, flags); in drbd_rs_complete_io()
1159 if (lc_put(device->resync, &bm_ext->lce) == 0) { in drbd_rs_complete_io()
1160 bm_ext->flags = 0; /* clear BME_LOCKED, BME_NO_WRITES and BME_PRIORITY */ in drbd_rs_complete_io()
1161 device->resync_locked--; in drbd_rs_complete_io()
1162 wake_up(&device->al_wait); in drbd_rs_complete_io()
1165 spin_unlock_irqrestore(&device->al_lock, flags); in drbd_rs_complete_io()
1169 * drbd_rs_cancel_all() - Removes all extents from the resync LRU (even BME_LOCKED)
1174 spin_lock_irq(&device->al_lock); in drbd_rs_cancel_all()
1176 if (get_ldev_if_state(device, D_FAILED)) { /* Makes sure ->resync is there. */ in drbd_rs_cancel_all()
1177 lc_reset(device->resync); in drbd_rs_cancel_all()
1180 device->resync_locked = 0; in drbd_rs_cancel_all()
1181 device->resync_wenr = LC_FREE; in drbd_rs_cancel_all()
1182 spin_unlock_irq(&device->al_lock); in drbd_rs_cancel_all()
1183 wake_up(&device->al_wait); in drbd_rs_cancel_all()
1187 * drbd_rs_del_all() - Gracefully remove all extents from the resync LRU
1190 * Returns 0 upon success, -EAGAIN if at least one reference count was
1199 spin_lock_irq(&device->al_lock); in drbd_rs_del_all()
1202 /* ok, ->resync is there. */ in drbd_rs_del_all()
1203 for (i = 0; i < device->resync->nr_elements; i++) { in drbd_rs_del_all()
1204 e = lc_element_by_index(device->resync, i); in drbd_rs_del_all()
1206 if (bm_ext->lce.lc_number == LC_FREE) in drbd_rs_del_all()
1208 if (bm_ext->lce.lc_number == device->resync_wenr) { in drbd_rs_del_all()
1211 device->resync_wenr); in drbd_rs_del_all()
1212 D_ASSERT(device, !test_bit(BME_LOCKED, &bm_ext->flags)); in drbd_rs_del_all()
1213 D_ASSERT(device, test_bit(BME_NO_WRITES, &bm_ext->flags)); in drbd_rs_del_all()
1214 clear_bit(BME_NO_WRITES, &bm_ext->flags); in drbd_rs_del_all()
1215 device->resync_wenr = LC_FREE; in drbd_rs_del_all()
1216 lc_put(device->resync, &bm_ext->lce); in drbd_rs_del_all()
1218 if (bm_ext->lce.refcnt != 0) { in drbd_rs_del_all()
1220 "refcnt=%d\n", bm_ext->lce.refcnt); in drbd_rs_del_all()
1222 spin_unlock_irq(&device->al_lock); in drbd_rs_del_all()
1223 return -EAGAIN; in drbd_rs_del_all()
1225 D_ASSERT(device, !test_bit(BME_LOCKED, &bm_ext->flags)); in drbd_rs_del_all()
1226 D_ASSERT(device, !test_bit(BME_NO_WRITES, &bm_ext->flags)); in drbd_rs_del_all()
1227 lc_del(device->resync, &bm_ext->lce); in drbd_rs_del_all()
1229 D_ASSERT(device, device->resync->used == 0); in drbd_rs_del_all()
1232 spin_unlock_irq(&device->al_lock); in drbd_rs_del_all()
1233 wake_up(&device->al_wait); in drbd_rs_del_all()