26 #include <linux/slab.h>
85 static bool md_io_allowed(
struct drbd_conf *mdev)
94 long dt = bdev->
dc.disk_timeout *
HZ / 10;
100 dev_err(
DEV,
"meta-data IO operation timed out\n");
103 static int _drbd_md_sync_page_io(
struct drbd_conf *mdev,
111 mdev->
md_io.done = 0;
124 bio->bi_private = &mdev->
md_io;
129 dev_err(
DEV,
"ASSERT FAILED: get_ldev_if_state() == 1 in _drbd_md_sync_page_io()\n");
141 ok = bio_flagged(bio, BIO_UPTODATE) && mdev->
md_io.error == 0;
151 int logical_block_size,
mask, ok;
159 logical_block_size = bdev_logical_block_size(bdev->
md_bdev);
160 if (logical_block_size == 0)
166 D_ASSERT(mask == 1 || mask == 3 || mask == 7);
168 offset = sector &
mask;
169 sector = sector & ~mask;
178 ok = _drbd_md_sync_page_io(mdev, bdev, iop, sector,
179 READ, logical_block_size);
183 "READ [logical_block_size!=512]) failed!\n",
184 (
unsigned long long)sector);
192 if (sector < drbd_md_first_sector(bdev) ||
193 sector > drbd_md_last_sector(bdev))
194 dev_alert(
DEV,
"%s [%d]:%s(,%llus,%s) out of range md access!\n",
196 (
unsigned long long)sector, (rw & WRITE) ?
"WRITE" :
"READ");
198 ok = _drbd_md_sync_page_io(mdev, bdev, iop, sector, rw, logical_block_size);
200 dev_err(
DEV,
"drbd_md_sync_page_io(,%llus,%s) failed!\n",
201 (
unsigned long long)sector, (rw & WRITE) ?
"WRITE" :
"READ");
219 unsigned long al_flags = 0;
228 spin_unlock_irq(&mdev->
al_lock);
235 al_flags = mdev->
act_log->flags;
236 spin_unlock_irq(&mdev->
al_lock);
267 init_completion(&al_work.
event);
272 drbd_queue_work_front(&mdev->
data.work, &al_work.
w);
279 spin_unlock_irq(&mdev->
al_lock);
295 spin_unlock_irqrestore(&mdev->
al_lock, flags);
296 dev_err(
DEV,
"al_complete_io() called on inactive extent %u\n", enr);
303 spin_unlock_irqrestore(&mdev->
al_lock, flags);
306 #if (PAGE_SHIFT + 3) < (AL_EXTENT_SHIFT - BM_BLOCK_SHIFT)
315 static unsigned int al_extent_to_bm_page(
unsigned int al_enr)
324 static unsigned int rs_extent_to_bm_page(
unsigned int rs_enr)
338 const unsigned int new_enr = aw->
enr;
339 const unsigned int evicted = aw->
old_enr;
343 unsigned int extent_nr;
348 "disk is %s, cannot start al transaction (-%d +%d)\n",
365 "disk is %s, cannot write al transaction (-%d +%d)\n",
374 dev_err(
DEV,
"disk failed while waiting for md_io buffer\n");
392 for (i = 0; i <
mx; i++) {
397 xor_sum ^= extent_nr;
410 sector = mdev->ldev->md.md_offset
411 + mdev->ldev->md.al_offset + mdev->
al_tr_pos;
440 static int drbd_al_read_tr(
struct drbd_conf *mdev,
449 sector = bdev->
md.md_offset + bdev->
md.al_offset +
index;
478 int active_extents = 0;
479 int transactions = 0;
497 for (i = 0; i <=
mx; i++) {
498 rv = drbd_al_read_tr(mdev, bdev, buffer, i);
507 if (++found_valid == 1) {
514 if ((
int)cnr - (
int)from_tnr < 0) {
515 D_ASSERT(from_tnr - cnr + i - from == mx+1);
519 if ((
int)cnr - (
int)to_tnr > 0) {
537 unsigned int extent_nr;
540 rv = drbd_al_read_tr(mdev, bdev, buffer, i);
555 for (j = AL_EXTENTS_PT; j >= 0; j--) {
565 spin_unlock_irq(&mdev->
al_lock);
586 dev_info(
DEV,
"Found %d transactions (%d active extents) in activity log.\n",
587 transactions, active_extents);
599 unsigned long add = 0;
605 for (i = 0; i < mdev->
act_log->nr_elements; i++) {
617 dev_info(
DEV,
"Marked additional %s as out-of-sync based on AL.\n",
626 rv = (al_ext->
refcnt == 0);
629 spin_unlock_irq(&mdev->
al_lock);
650 for (i = 0; i < mdev->
act_log->nr_elements; i++) {
666 dev_warn(
DEV,
"Can not update on disk bitmap, local IO disabled.\n");
699 int count,
int success)
715 if (ext->
lce.lc_number == enr) {
721 dev_warn(
DEV,
"BAD! sector=%llus enr=%u rs_left=%d "
722 "rs_failed=%d count=%d cstate=%s\n",
723 (
unsigned long long)sector,
744 if (ext->
flags != 0) {
748 ext->
flags, enr, rs_left);
753 "out with rs_failed=%d\n",
768 udw->
enr = ext->
lce.lc_number;
769 udw->
w.cb = w_update_odbm;
770 drbd_queue_work_front(&mdev->
data.work, &udw->
w);
776 dev_err(
DEV,
"lc_get() failed! locked=%d/%d flags=%lu\n",
778 mdev->
resync->nr_elements,
807 const char *
file,
const unsigned int line)
810 unsigned long sbnr, ebnr, lbnr;
811 unsigned long count = 0;
817 dev_err(
DEV,
"drbd_set_in_sync: sector=%llus size=%d nonsense!\n",
818 (
unsigned long long)sector, size);
821 nr_sectors = drbd_get_capacity(mdev->
this_bdev);
822 esector = sector + (size >> 9) - 1;
824 ERR_IF(sector >= nr_sectors)
return;
825 ERR_IF(esector >= nr_sectors) esector = (nr_sectors-1);
834 if (
unlikely(esector == (nr_sectors-1)))
851 drbd_try_clear_on_disk_bm(mdev, sector, count,
true);
852 spin_unlock_irqrestore(&mdev->
al_lock, flags);
872 const char *
file,
const unsigned int line)
874 unsigned long sbnr, ebnr, lbnr,
flags;
876 unsigned int enr, count = 0;
885 (
unsigned long long)sector, size);
892 nr_sectors = drbd_get_capacity(mdev->
this_bdev);
893 esector = sector + (size >> 9) - 1;
895 ERR_IF(sector >= nr_sectors)
897 ERR_IF(esector >= nr_sectors)
898 esector = (nr_sectors-1);
916 spin_unlock_irqrestore(&mdev->
al_lock, flags);
930 unsigned long rs_flags;
934 spin_unlock_irq(&mdev->
al_lock);
940 if (bm_ext->
lce.lc_number != enr) {
946 if (bm_ext->
lce.refcnt == 1)
950 rs_flags = mdev->
resync->flags;
951 spin_unlock_irq(&mdev->
al_lock);
958 " (resync LRU too small?)\n");
965 static int _is_in_al(
struct drbd_conf *mdev,
unsigned int enr)
980 spin_unlock_irq(&mdev->
al_lock);
1007 (bm_ext = _bme_get(mdev, enr)));
1016 !_is_in_al(mdev, enr * AL_EXT_PER_BM_SECT + i) ||
1020 spin_lock_irq(&mdev->
al_lock);
1026 spin_unlock_irq(&mdev->
al_lock);
1031 if (sa && --sa == 0)
1032 dev_warn(
DEV,
"drbd_rs_begin_io() stepped aside for 20sec."
1033 "Resync stalled?\n");
1058 spin_lock_irq(&mdev->
al_lock);
1084 dev_alert(
DEV,
"LOGIC BUG\n");
1100 bm_ext->
lce.refcnt--;
1112 const unsigned long rs_flags = mdev->
resync->flags;
1115 " (resync LRU too small?)\n");
1119 if (bm_ext->
lce.lc_number != enr) {
1135 if (lc_is_used(mdev->
act_log, al_enr+i))
1141 spin_unlock_irq(&mdev->
al_lock);
1147 spin_unlock_irq(&mdev->
al_lock);
1156 unsigned long flags;
1162 spin_unlock_irqrestore(&mdev->
al_lock, flags);
1164 dev_err(
DEV,
"drbd_rs_complete_io() called, but extent not found\n");
1168 if (bm_ext->
lce.refcnt == 0) {
1169 spin_unlock_irqrestore(&mdev->
al_lock, flags);
1170 dev_err(
DEV,
"drbd_rs_complete_io(,%llu [=%u]) called, "
1171 "but refcnt is 0!?\n",
1172 (
unsigned long long)sector, enr);
1182 spin_unlock_irqrestore(&mdev->
al_lock, flags);
1191 spin_lock_irq(&mdev->
al_lock);
1199 spin_unlock_irq(&mdev->
al_lock);
1216 spin_lock_irq(&mdev->
al_lock);
1220 for (i = 0; i < mdev->
resync->nr_elements; i++) {
1226 dev_info(
DEV,
"dropping %u in drbd_rs_del_all, apparently"
1227 " got 'synced' by application io\n",
1235 if (bm_ext->
lce.refcnt != 0) {
1236 dev_info(
DEV,
"Retrying drbd_rs_del_all() later. "
1237 "refcnt=%d\n", bm_ext->
lce.refcnt);
1239 spin_unlock_irq(&mdev->
al_lock);
1249 spin_unlock_irq(&mdev->
al_lock);
1264 unsigned long sbnr, ebnr, lbnr;
1265 unsigned long count;
1270 dev_err(
DEV,
"drbd_rs_failed_io: sector=%llus size=%d nonsense!\n",
1271 (
unsigned long long)sector, size);
1274 nr_sectors = drbd_get_capacity(mdev->
this_bdev);
1275 esector = sector + (size >> 9) - 1;
1277 ERR_IF(sector >= nr_sectors)
return;
1278 ERR_IF(esector >= nr_sectors) esector = (nr_sectors-1);
1287 if (
unlikely(esector == (nr_sectors-1)))
1300 spin_lock_irq(&mdev->
al_lock);
1306 drbd_try_clear_on_disk_bm(mdev, sector, count,
false);
1314 spin_unlock_irq(&mdev->
al_lock);