Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | drbd_actlog.c |
| 3 | |
| 4 | This file is part of DRBD by Philipp Reisner and Lars Ellenberg. |
| 5 | |
| 6 | Copyright (C) 2003-2008, LINBIT Information Technologies GmbH. |
| 7 | Copyright (C) 2003-2008, Philipp Reisner <philipp.reisner@linbit.com>. |
| 8 | Copyright (C) 2003-2008, Lars Ellenberg <lars.ellenberg@linbit.com>. |
| 9 | |
| 10 | drbd is free software; you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation; either version 2, or (at your option) |
| 13 | any later version. |
| 14 | |
| 15 | drbd is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with drbd; see the file COPYING. If not, write to |
| 22 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | |
| 24 | */ |
| 25 | |
| 26 | #include <linux/slab.h> |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 27 | #include <linux/crc32c.h> |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 28 | #include <linux/drbd.h> |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 29 | #include <linux/drbd_limits.h> |
| 30 | #include <linux/dynamic_debug.h> |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 31 | #include "drbd_int.h" |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 32 | #include "drbd_wrappers.h" |
| 33 | |
Lars Ellenberg | 85f103d | 2011-03-31 12:06:48 +0200 | [diff] [blame] | 34 | |
| 35 | enum al_transaction_types { |
| 36 | AL_TR_UPDATE = 0, |
| 37 | AL_TR_INITIALIZED = 0xffff |
| 38 | }; |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 39 | /* all fields on disc in big endian */ |
| 40 | struct __packed al_transaction_on_disk { |
| 41 | /* don't we all like magic */ |
| 42 | __be32 magic; |
| 43 | |
| 44 | /* to identify the most recent transaction block |
| 45 | * in the on disk ring buffer */ |
| 46 | __be32 tr_number; |
| 47 | |
| 48 | /* checksum on the full 4k block, with this field set to 0. */ |
| 49 | __be32 crc32c; |
| 50 | |
| 51 | /* type of transaction, special transaction types like: |
Lars Ellenberg | 85f103d | 2011-03-31 12:06:48 +0200 | [diff] [blame] | 52 | * purge-all, set-all-idle, set-all-active, ... to-be-defined |
| 53 | * see also enum al_transaction_types */ |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 54 | __be16 transaction_type; |
| 55 | |
| 56 | /* we currently allow only a few thousand extents, |
| 57 | * so 16bit will be enough for the slot number. */ |
| 58 | |
| 59 | /* how many updates in this transaction */ |
| 60 | __be16 n_updates; |
| 61 | |
| 62 | /* maximum slot number, "al-extents" in drbd.conf speak. |
| 63 | * Having this in each transaction should make reconfiguration |
| 64 | * of that parameter easier. */ |
| 65 | __be16 context_size; |
| 66 | |
| 67 | /* slot number the context starts with */ |
| 68 | __be16 context_start_slot_nr; |
| 69 | |
| 70 | /* Some reserved bytes. Expected usage is a 64bit counter of |
| 71 | * sectors-written since device creation, and other data generation tag |
| 72 | * supporting usage */ |
| 73 | __be32 __reserved[4]; |
| 74 | |
| 75 | /* --- 36 byte used --- */ |
| 76 | |
| 77 | /* Reserve space for up to AL_UPDATES_PER_TRANSACTION changes |
| 78 | * in one transaction, then use the remaining byte in the 4k block for |
| 79 | * context information. "Flexible" number of updates per transaction |
| 80 | * does not help, as we have to account for the case when all update |
| 81 | * slots are used anyways, so it would only complicate code without |
| 82 | * additional benefit. |
| 83 | */ |
| 84 | __be16 update_slot_nr[AL_UPDATES_PER_TRANSACTION]; |
| 85 | |
| 86 | /* but the extent number is 32bit, which at an extent size of 4 MiB |
| 87 | * allows to cover device sizes of up to 2**54 Byte (16 PiB) */ |
| 88 | __be32 update_extent_nr[AL_UPDATES_PER_TRANSACTION]; |
| 89 | |
| 90 | /* --- 420 bytes used (36 + 64*6) --- */ |
| 91 | |
| 92 | /* 4096 - 420 = 3676 = 919 * 4 */ |
| 93 | __be32 context[AL_CONTEXT_PER_TRANSACTION]; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | struct update_odbm_work { |
| 97 | struct drbd_work w; |
| 98 | unsigned int enr; |
| 99 | }; |
| 100 | |
| 101 | struct update_al_work { |
| 102 | struct drbd_work w; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 103 | struct completion event; |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 104 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | struct drbd_atodb_wait { |
| 108 | atomic_t count; |
| 109 | struct completion io_done; |
| 110 | struct drbd_conf *mdev; |
| 111 | int error; |
| 112 | }; |
| 113 | |
| 114 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 115 | static int w_al_write_transaction(struct drbd_work *, int); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 116 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 117 | static int _drbd_md_sync_page_io(struct drbd_conf *mdev, |
| 118 | struct drbd_backing_dev *bdev, |
| 119 | struct page *page, sector_t sector, |
| 120 | int rw, int size) |
| 121 | { |
| 122 | struct bio *bio; |
| 123 | struct drbd_md_io md_io; |
Andreas Gruenbacher | ac29f40 | 2010-12-13 02:20:47 +0100 | [diff] [blame] | 124 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 125 | |
| 126 | md_io.mdev = mdev; |
| 127 | init_completion(&md_io.event); |
| 128 | md_io.error = 0; |
| 129 | |
Philipp Reisner | a8a4e51 | 2010-08-25 10:21:04 +0200 | [diff] [blame] | 130 | if ((rw & WRITE) && !test_bit(MD_NO_FUA, &mdev->flags)) |
Lars Ellenberg | 86e1e98 | 2011-06-28 13:22:48 +0200 | [diff] [blame] | 131 | rw |= REQ_FUA | REQ_FLUSH; |
Jens Axboe | 721a960 | 2011-03-09 11:56:30 +0100 | [diff] [blame] | 132 | rw |= REQ_SYNC; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 133 | |
Lars Ellenberg | da4a75d | 2011-02-23 17:02:01 +0100 | [diff] [blame] | 134 | bio = bio_alloc_drbd(GFP_NOIO); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 135 | bio->bi_bdev = bdev->md_bdev; |
| 136 | bio->bi_sector = sector; |
Andreas Gruenbacher | ac29f40 | 2010-12-13 02:20:47 +0100 | [diff] [blame] | 137 | err = -EIO; |
| 138 | if (bio_add_page(bio, page, size, 0) != size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 139 | goto out; |
| 140 | bio->bi_private = &md_io; |
| 141 | bio->bi_end_io = drbd_md_io_complete; |
| 142 | bio->bi_rw = rw; |
| 143 | |
Andreas Gruenbacher | 0cf9d27 | 2010-12-07 10:43:29 +0100 | [diff] [blame] | 144 | if (drbd_insert_fault(mdev, (rw & WRITE) ? DRBD_FAULT_MD_WR : DRBD_FAULT_MD_RD)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 145 | bio_endio(bio, -EIO); |
| 146 | else |
| 147 | submit_bio(rw, bio); |
| 148 | wait_for_completion(&md_io.event); |
Andreas Gruenbacher | ac29f40 | 2010-12-13 02:20:47 +0100 | [diff] [blame] | 149 | if (bio_flagged(bio, BIO_UPTODATE)) |
| 150 | err = md_io.error; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 151 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 152 | out: |
| 153 | bio_put(bio); |
Andreas Gruenbacher | ac29f40 | 2010-12-13 02:20:47 +0100 | [diff] [blame] | 154 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | int drbd_md_sync_page_io(struct drbd_conf *mdev, struct drbd_backing_dev *bdev, |
| 158 | sector_t sector, int rw) |
| 159 | { |
Andreas Gruenbacher | 3fbf4d2 | 2010-12-13 02:25:41 +0100 | [diff] [blame] | 160 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 161 | struct page *iop = mdev->md_io_page; |
| 162 | |
| 163 | D_ASSERT(mutex_is_locked(&mdev->md_io_mutex)); |
| 164 | |
| 165 | BUG_ON(!bdev->md_bdev); |
| 166 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 167 | dev_dbg(DEV, "meta_data io: %s [%d]:%s(,%llus,%s)\n", |
| 168 | current->comm, current->pid, __func__, |
| 169 | (unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 170 | |
| 171 | if (sector < drbd_md_first_sector(bdev) || |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 172 | sector + 7 > drbd_md_last_sector(bdev)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 173 | dev_alert(DEV, "%s [%d]:%s(,%llus,%s) out of range md access!\n", |
| 174 | current->comm, current->pid, __func__, |
| 175 | (unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ"); |
| 176 | |
Andreas Gruenbacher | 3fbf4d2 | 2010-12-13 02:25:41 +0100 | [diff] [blame] | 177 | err = _drbd_md_sync_page_io(mdev, bdev, iop, sector, rw, MD_BLOCK_SIZE); |
| 178 | if (err) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 179 | dev_err(DEV, "drbd_md_sync_page_io(,%llus,%s) failed!\n", |
| 180 | (unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 181 | } |
Andreas Gruenbacher | 3fbf4d2 | 2010-12-13 02:25:41 +0100 | [diff] [blame] | 182 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | static struct lc_element *_al_get(struct drbd_conf *mdev, unsigned int enr) |
| 186 | { |
| 187 | struct lc_element *al_ext; |
| 188 | struct lc_element *tmp; |
Philipp Reisner | f91ab62 | 2010-11-09 13:59:41 +0100 | [diff] [blame] | 189 | int wake; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 190 | |
| 191 | spin_lock_irq(&mdev->al_lock); |
| 192 | tmp = lc_find(mdev->resync, enr/AL_EXT_PER_BM_SECT); |
| 193 | if (unlikely(tmp != NULL)) { |
| 194 | struct bm_extent *bm_ext = lc_entry(tmp, struct bm_extent, lce); |
| 195 | if (test_bit(BME_NO_WRITES, &bm_ext->flags)) { |
Philipp Reisner | f91ab62 | 2010-11-09 13:59:41 +0100 | [diff] [blame] | 196 | wake = !test_and_set_bit(BME_PRIORITY, &bm_ext->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 197 | spin_unlock_irq(&mdev->al_lock); |
Philipp Reisner | f91ab62 | 2010-11-09 13:59:41 +0100 | [diff] [blame] | 198 | if (wake) |
| 199 | wake_up(&mdev->al_wait); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 200 | return NULL; |
| 201 | } |
| 202 | } |
Lars Ellenberg | 46a15bc | 2011-02-21 13:21:01 +0100 | [diff] [blame] | 203 | al_ext = lc_get(mdev->act_log, enr); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 204 | spin_unlock_irq(&mdev->al_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 205 | return al_ext; |
| 206 | } |
| 207 | |
Lars Ellenberg | 181286a | 2011-03-31 15:18:56 +0200 | [diff] [blame] | 208 | void drbd_al_begin_io(struct drbd_conf *mdev, struct drbd_interval *i) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 209 | { |
Lars Ellenberg | 7726547 | 2011-03-31 16:00:51 +0200 | [diff] [blame] | 210 | /* for bios crossing activity log extent boundaries, |
| 211 | * we may need to activate two extents in one go */ |
Lars Ellenberg | e15766e | 2011-04-01 10:38:30 +0200 | [diff] [blame^] | 212 | unsigned first = i->sector >> (AL_EXTENT_SHIFT-9); |
| 213 | unsigned last = (i->sector + (i->size >> 9) - 1) >> (AL_EXTENT_SHIFT-9); |
| 214 | unsigned enr; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 215 | |
| 216 | D_ASSERT(atomic_read(&mdev->local_cnt) > 0); |
| 217 | |
Lars Ellenberg | e15766e | 2011-04-01 10:38:30 +0200 | [diff] [blame^] | 218 | for (enr = first; enr <= last; enr++) |
| 219 | wait_event(mdev->al_wait, _al_get(mdev, enr) != NULL); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 220 | |
Lars Ellenberg | e15766e | 2011-04-01 10:38:30 +0200 | [diff] [blame^] | 221 | if (mdev->act_log->pending_changes) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 222 | /* drbd_al_write_transaction(mdev,al_ext,enr); |
| 223 | * recurses into generic_make_request(), which |
| 224 | * disallows recursion, bios being serialized on the |
| 225 | * current->bio_tail list now. |
| 226 | * we have to delegate updates to the activity log |
| 227 | * to the worker thread. */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 228 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 229 | /* Serialize multiple transactions. |
| 230 | * This uses test_and_set_bit, memory barrier is implicit. |
| 231 | * Optimization potential: |
| 232 | * first check for transaction number > old transaction number, |
| 233 | * so not all waiters have to lock/unlock. */ |
| 234 | wait_event(mdev->al_wait, lc_try_lock_for_transaction(mdev->act_log)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 235 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 236 | /* Double check: it may have been committed by someone else, |
| 237 | * while we have been waiting for the lock. */ |
Lars Ellenberg | e15766e | 2011-04-01 10:38:30 +0200 | [diff] [blame^] | 238 | if (mdev->act_log->pending_changes) { |
| 239 | struct update_al_work al_work; |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 240 | init_completion(&al_work.event); |
| 241 | al_work.w.cb = w_al_write_transaction; |
| 242 | al_work.w.mdev = mdev; |
| 243 | drbd_queue_work_front(&mdev->tconn->data.work, &al_work.w); |
| 244 | wait_for_completion(&al_work.event); |
| 245 | |
| 246 | mdev->al_writ_cnt++; |
| 247 | |
| 248 | spin_lock_irq(&mdev->al_lock); |
| 249 | /* FIXME |
| 250 | if (al_work.err) |
| 251 | we need an "lc_cancel" here; |
| 252 | */ |
| 253 | lc_committed(mdev->act_log); |
| 254 | spin_unlock_irq(&mdev->al_lock); |
| 255 | } |
| 256 | lc_unlock(mdev->act_log); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 257 | wake_up(&mdev->al_wait); |
| 258 | } |
| 259 | } |
| 260 | |
Lars Ellenberg | 181286a | 2011-03-31 15:18:56 +0200 | [diff] [blame] | 261 | void drbd_al_complete_io(struct drbd_conf *mdev, struct drbd_interval *i) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 262 | { |
Lars Ellenberg | e15766e | 2011-04-01 10:38:30 +0200 | [diff] [blame^] | 263 | /* for bios crossing activity log extent boundaries, |
| 264 | * we may need to activate two extents in one go */ |
| 265 | unsigned first = i->sector >> (AL_EXTENT_SHIFT-9); |
| 266 | unsigned last = (i->sector + (i->size >> 9) - 1) >> (AL_EXTENT_SHIFT-9); |
| 267 | unsigned enr; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 268 | struct lc_element *extent; |
| 269 | unsigned long flags; |
Lars Ellenberg | e15766e | 2011-04-01 10:38:30 +0200 | [diff] [blame^] | 270 | bool wake = false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 271 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 272 | spin_lock_irqsave(&mdev->al_lock, flags); |
| 273 | |
Lars Ellenberg | e15766e | 2011-04-01 10:38:30 +0200 | [diff] [blame^] | 274 | for (enr = first; enr <= last; enr++) { |
| 275 | extent = lc_find(mdev->act_log, enr); |
| 276 | if (!extent) { |
| 277 | dev_err(DEV, "al_complete_io() called on inactive extent %u\n", enr); |
| 278 | continue; |
| 279 | } |
| 280 | if (lc_put(mdev->act_log, extent) == 0) |
| 281 | wake = true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 282 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 283 | spin_unlock_irqrestore(&mdev->al_lock, flags); |
Lars Ellenberg | e15766e | 2011-04-01 10:38:30 +0200 | [diff] [blame^] | 284 | wake_up(&mdev->al_wait); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Lars Ellenberg | 19f843a | 2010-12-15 08:59:11 +0100 | [diff] [blame] | 287 | #if (PAGE_SHIFT + 3) < (AL_EXTENT_SHIFT - BM_BLOCK_SHIFT) |
| 288 | /* Currently BM_BLOCK_SHIFT, BM_EXT_SHIFT and AL_EXTENT_SHIFT |
| 289 | * are still coupled, or assume too much about their relation. |
| 290 | * Code below will not work if this is violated. |
| 291 | * Will be cleaned up with some followup patch. |
| 292 | */ |
| 293 | # error FIXME |
| 294 | #endif |
| 295 | |
| 296 | static unsigned int al_extent_to_bm_page(unsigned int al_enr) |
| 297 | { |
| 298 | return al_enr >> |
| 299 | /* bit to page */ |
| 300 | ((PAGE_SHIFT + 3) - |
| 301 | /* al extent number to bit */ |
| 302 | (AL_EXTENT_SHIFT - BM_BLOCK_SHIFT)); |
| 303 | } |
| 304 | |
| 305 | static unsigned int rs_extent_to_bm_page(unsigned int rs_enr) |
| 306 | { |
| 307 | return rs_enr >> |
| 308 | /* bit to page */ |
| 309 | ((PAGE_SHIFT + 3) - |
| 310 | /* al extent number to bit */ |
| 311 | (BM_EXT_SHIFT - BM_BLOCK_SHIFT)); |
| 312 | } |
| 313 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 314 | static int |
Philipp Reisner | 00d5694 | 2011-02-09 18:09:48 +0100 | [diff] [blame] | 315 | w_al_write_transaction(struct drbd_work *w, int unused) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 316 | { |
| 317 | struct update_al_work *aw = container_of(w, struct update_al_work, w); |
Philipp Reisner | 00d5694 | 2011-02-09 18:09:48 +0100 | [diff] [blame] | 318 | struct drbd_conf *mdev = w->mdev; |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 319 | struct al_transaction_on_disk *buffer; |
| 320 | struct lc_element *e; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 321 | sector_t sector; |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 322 | int i, mx; |
| 323 | unsigned extent_nr; |
| 324 | unsigned crc = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 325 | |
| 326 | if (!get_ldev(mdev)) { |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 327 | dev_err(DEV, "disk is %s, cannot start al transaction\n", |
| 328 | drbd_disk_str(mdev->state.disk)); |
| 329 | aw->err = -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 330 | complete(&((struct update_al_work *)w)->event); |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 331 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 332 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 333 | |
Lars Ellenberg | 6719fb0 | 2010-10-18 23:04:07 +0200 | [diff] [blame] | 334 | /* The bitmap write may have failed, causing a state change. */ |
| 335 | if (mdev->state.disk < D_INCONSISTENT) { |
| 336 | dev_err(DEV, |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 337 | "disk is %s, cannot write al transaction\n", |
| 338 | drbd_disk_str(mdev->state.disk)); |
| 339 | aw->err = -EIO; |
Lars Ellenberg | 6719fb0 | 2010-10-18 23:04:07 +0200 | [diff] [blame] | 340 | complete(&((struct update_al_work *)w)->event); |
| 341 | put_ldev(mdev); |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 342 | return 0; |
Lars Ellenberg | 6719fb0 | 2010-10-18 23:04:07 +0200 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | mutex_lock(&mdev->md_io_mutex); /* protects md_io_buffer, al_tr_cycle, ... */ |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 346 | buffer = page_address(mdev->md_io_page); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 347 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 348 | memset(buffer, 0, sizeof(*buffer)); |
| 349 | buffer->magic = cpu_to_be32(DRBD_AL_MAGIC); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 350 | buffer->tr_number = cpu_to_be32(mdev->al_tr_number); |
| 351 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 352 | i = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 353 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 354 | /* Even though no one can start to change this list |
| 355 | * once we set the LC_LOCKED -- from drbd_al_begin_io(), |
| 356 | * lc_try_lock_for_transaction() --, someone may still |
| 357 | * be in the process of changing it. */ |
| 358 | spin_lock_irq(&mdev->al_lock); |
| 359 | list_for_each_entry(e, &mdev->act_log->to_be_changed, list) { |
| 360 | if (i == AL_UPDATES_PER_TRANSACTION) { |
| 361 | i++; |
| 362 | break; |
| 363 | } |
| 364 | buffer->update_slot_nr[i] = cpu_to_be16(e->lc_index); |
| 365 | buffer->update_extent_nr[i] = cpu_to_be32(e->lc_new_number); |
| 366 | if (e->lc_number != LC_FREE) |
| 367 | drbd_bm_mark_for_writeout(mdev, |
| 368 | al_extent_to_bm_page(e->lc_number)); |
| 369 | i++; |
| 370 | } |
| 371 | spin_unlock_irq(&mdev->al_lock); |
| 372 | BUG_ON(i > AL_UPDATES_PER_TRANSACTION); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 373 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 374 | buffer->n_updates = cpu_to_be16(i); |
| 375 | for ( ; i < AL_UPDATES_PER_TRANSACTION; i++) { |
| 376 | buffer->update_slot_nr[i] = cpu_to_be16(-1); |
| 377 | buffer->update_extent_nr[i] = cpu_to_be32(LC_FREE); |
| 378 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 379 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 380 | buffer->context_size = cpu_to_be16(mdev->act_log->nr_elements); |
| 381 | buffer->context_start_slot_nr = cpu_to_be16(mdev->al_tr_cycle); |
| 382 | |
| 383 | mx = min_t(int, AL_CONTEXT_PER_TRANSACTION, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 384 | mdev->act_log->nr_elements - mdev->al_tr_cycle); |
| 385 | for (i = 0; i < mx; i++) { |
| 386 | unsigned idx = mdev->al_tr_cycle + i; |
| 387 | extent_nr = lc_element_by_index(mdev->act_log, idx)->lc_number; |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 388 | buffer->context[i] = cpu_to_be32(extent_nr); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 389 | } |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 390 | for (; i < AL_CONTEXT_PER_TRANSACTION; i++) |
| 391 | buffer->context[i] = cpu_to_be32(LC_FREE); |
| 392 | |
| 393 | mdev->al_tr_cycle += AL_CONTEXT_PER_TRANSACTION; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 394 | if (mdev->al_tr_cycle >= mdev->act_log->nr_elements) |
| 395 | mdev->al_tr_cycle = 0; |
| 396 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 397 | sector = mdev->ldev->md.md_offset |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 398 | + mdev->ldev->md.al_offset |
| 399 | + mdev->al_tr_pos * (MD_BLOCK_SIZE>>9); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 400 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 401 | crc = crc32c(0, buffer, 4096); |
| 402 | buffer->crc32c = cpu_to_be32(crc); |
| 403 | |
| 404 | if (drbd_bm_write_hinted(mdev)) |
| 405 | aw->err = -EIO; |
| 406 | /* drbd_chk_io_error done already */ |
Andreas Gruenbacher | 3fbf4d2 | 2010-12-13 02:25:41 +0100 | [diff] [blame] | 407 | else if (drbd_md_sync_page_io(mdev, mdev->ldev, sector, WRITE)) { |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 408 | aw->err = -EIO; |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 409 | drbd_chk_io_error(mdev, 1, true); |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 410 | } else { |
| 411 | /* advance ringbuffer position and transaction counter */ |
| 412 | mdev->al_tr_pos = (mdev->al_tr_pos + 1) % (MD_AL_SECTORS*512/MD_BLOCK_SIZE); |
| 413 | mdev->al_tr_number++; |
| 414 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 415 | |
| 416 | mutex_unlock(&mdev->md_io_mutex); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 417 | complete(&((struct update_al_work *)w)->event); |
| 418 | put_ldev(mdev); |
| 419 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 420 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 423 | /* FIXME |
| 424 | * reading of the activity log, |
| 425 | * and potentially dirtying of the affected bitmap regions, |
| 426 | * should be done from userland only. |
| 427 | * DRBD would simply always attach with an empty activity log, |
| 428 | * and refuse to attach to something that looks like a crashed primary. |
| 429 | */ |
| 430 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 431 | /** |
| 432 | * drbd_al_read_tr() - Read a single transaction from the on disk activity log |
| 433 | * @mdev: DRBD device. |
| 434 | * @bdev: Block device to read form. |
| 435 | * @b: pointer to an al_transaction. |
| 436 | * @index: On disk slot of the transaction to read. |
| 437 | * |
| 438 | * Returns -1 on IO error, 0 on checksum error and 1 upon success. |
| 439 | */ |
| 440 | static int drbd_al_read_tr(struct drbd_conf *mdev, |
| 441 | struct drbd_backing_dev *bdev, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 442 | int index) |
| 443 | { |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 444 | struct al_transaction_on_disk *b = page_address(mdev->md_io_page); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 445 | sector_t sector; |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 446 | u32 crc; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 447 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 448 | sector = bdev->md.md_offset |
| 449 | + bdev->md.al_offset |
| 450 | + index * (MD_BLOCK_SIZE>>9); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 451 | |
| 452 | /* Dont process error normally, |
| 453 | * as this is done before disk is attached! */ |
Andreas Gruenbacher | 3fbf4d2 | 2010-12-13 02:25:41 +0100 | [diff] [blame] | 454 | if (drbd_md_sync_page_io(mdev, bdev, sector, READ)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 455 | return -1; |
| 456 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 457 | if (!expect(b->magic == cpu_to_be32(DRBD_AL_MAGIC))) |
| 458 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 459 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 460 | if (!expect(be16_to_cpu(b->n_updates) <= AL_UPDATES_PER_TRANSACTION)) |
| 461 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 462 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 463 | if (!expect(be16_to_cpu(b->context_size) <= DRBD_AL_EXTENTS_MAX)) |
| 464 | return 0; |
| 465 | |
| 466 | if (!expect(be16_to_cpu(b->context_start_slot_nr) < DRBD_AL_EXTENTS_MAX)) |
| 467 | return 0; |
| 468 | |
| 469 | crc = be32_to_cpu(b->crc32c); |
| 470 | b->crc32c = 0; |
| 471 | if (!expect(crc == crc32c(0, b, 4096))) |
| 472 | return 0; |
| 473 | |
| 474 | return 1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | /** |
| 478 | * drbd_al_read_log() - Restores the activity log from its on disk representation. |
| 479 | * @mdev: DRBD device. |
| 480 | * @bdev: Block device to read form. |
| 481 | * |
| 482 | * Returns 1 on success, returns 0 when reading the log failed due to IO errors. |
| 483 | */ |
| 484 | int drbd_al_read_log(struct drbd_conf *mdev, struct drbd_backing_dev *bdev) |
| 485 | { |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 486 | struct al_transaction_on_disk *b; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 487 | int i; |
| 488 | int rv; |
| 489 | int mx; |
| 490 | int active_extents = 0; |
| 491 | int transactions = 0; |
| 492 | int found_valid = 0; |
Lars Ellenberg | 85f103d | 2011-03-31 12:06:48 +0200 | [diff] [blame] | 493 | int found_initialized = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 494 | int from = 0; |
| 495 | int to = 0; |
| 496 | u32 from_tnr = 0; |
| 497 | u32 to_tnr = 0; |
| 498 | u32 cnr; |
| 499 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 500 | /* Note that this is expected to be called with a newly created, |
| 501 | * clean and all unused activity log of the "expected size". |
| 502 | */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 503 | |
| 504 | /* lock out all other meta data io for now, |
| 505 | * and make sure the page is mapped. |
| 506 | */ |
| 507 | mutex_lock(&mdev->md_io_mutex); |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 508 | b = page_address(mdev->md_io_page); |
| 509 | |
| 510 | /* Always use the full ringbuffer space for now. |
| 511 | * possible optimization: read in all of it, |
| 512 | * then scan the in-memory pages. */ |
| 513 | |
| 514 | mx = (MD_AL_SECTORS*512/MD_BLOCK_SIZE); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 515 | |
| 516 | /* Find the valid transaction in the log */ |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 517 | for (i = 0; i < mx; i++) { |
| 518 | rv = drbd_al_read_tr(mdev, bdev, i); |
| 519 | /* invalid data in that block */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 520 | if (rv == 0) |
| 521 | continue; |
Lars Ellenberg | 85f103d | 2011-03-31 12:06:48 +0200 | [diff] [blame] | 522 | if (be16_to_cpu(b->transaction_type) == AL_TR_INITIALIZED) { |
| 523 | ++found_initialized; |
| 524 | continue; |
| 525 | } |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 526 | |
| 527 | /* IO error */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 528 | if (rv == -1) { |
| 529 | mutex_unlock(&mdev->md_io_mutex); |
| 530 | return 0; |
| 531 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 532 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 533 | cnr = be32_to_cpu(b->tr_number); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 534 | if (++found_valid == 1) { |
| 535 | from = i; |
| 536 | to = i; |
| 537 | from_tnr = cnr; |
| 538 | to_tnr = cnr; |
| 539 | continue; |
| 540 | } |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 541 | |
| 542 | D_ASSERT(cnr != to_tnr); |
| 543 | D_ASSERT(cnr != from_tnr); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 544 | if ((int)cnr - (int)from_tnr < 0) { |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 545 | D_ASSERT(from_tnr - cnr + i - from == mx); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 546 | from = i; |
| 547 | from_tnr = cnr; |
| 548 | } |
| 549 | if ((int)cnr - (int)to_tnr > 0) { |
| 550 | D_ASSERT(cnr - to_tnr == i - to); |
| 551 | to = i; |
| 552 | to_tnr = cnr; |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | if (!found_valid) { |
Lars Ellenberg | 85f103d | 2011-03-31 12:06:48 +0200 | [diff] [blame] | 557 | if (found_initialized != mx) |
| 558 | dev_warn(DEV, "No usable activity log found.\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 559 | mutex_unlock(&mdev->md_io_mutex); |
| 560 | return 1; |
| 561 | } |
| 562 | |
| 563 | /* Read the valid transactions. |
| 564 | * dev_info(DEV, "Reading from %d to %d.\n",from,to); */ |
| 565 | i = from; |
| 566 | while (1) { |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 567 | struct lc_element *e; |
| 568 | unsigned j, n, slot, extent_nr; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 569 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 570 | rv = drbd_al_read_tr(mdev, bdev, i); |
Andreas Gruenbacher | 841ce24 | 2010-12-15 19:31:20 +0100 | [diff] [blame] | 571 | if (!expect(rv != 0)) |
| 572 | goto cancel; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 573 | if (rv == -1) { |
| 574 | mutex_unlock(&mdev->md_io_mutex); |
| 575 | return 0; |
| 576 | } |
| 577 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 578 | /* deal with different transaction types. |
| 579 | * not yet implemented */ |
| 580 | if (!expect(b->transaction_type == 0)) |
| 581 | goto cancel; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 582 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 583 | /* on the fly re-create/resize activity log? |
| 584 | * will be a special transaction type flag. */ |
| 585 | if (!expect(be16_to_cpu(b->context_size) == mdev->act_log->nr_elements)) |
| 586 | goto cancel; |
| 587 | if (!expect(be16_to_cpu(b->context_start_slot_nr) < mdev->act_log->nr_elements)) |
| 588 | goto cancel; |
| 589 | |
| 590 | /* We are the only user of the activity log right now, |
| 591 | * don't actually need to take that lock. */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 592 | spin_lock_irq(&mdev->al_lock); |
| 593 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 594 | /* first, apply the context, ... */ |
| 595 | for (j = 0, slot = be16_to_cpu(b->context_start_slot_nr); |
| 596 | j < AL_CONTEXT_PER_TRANSACTION && |
| 597 | slot < mdev->act_log->nr_elements; j++, slot++) { |
| 598 | extent_nr = be32_to_cpu(b->context[j]); |
| 599 | e = lc_element_by_index(mdev->act_log, slot); |
| 600 | if (e->lc_number != extent_nr) { |
| 601 | if (extent_nr != LC_FREE) |
| 602 | active_extents++; |
| 603 | else |
| 604 | active_extents--; |
| 605 | } |
| 606 | lc_set(mdev->act_log, extent_nr, slot); |
| 607 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 608 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 609 | /* ... then apply the updates, |
| 610 | * which override the context information. |
| 611 | * drbd_al_read_tr already did the rangecheck |
| 612 | * on n <= AL_UPDATES_PER_TRANSACTION */ |
| 613 | n = be16_to_cpu(b->n_updates); |
| 614 | for (j = 0; j < n; j++) { |
| 615 | slot = be16_to_cpu(b->update_slot_nr[j]); |
| 616 | extent_nr = be32_to_cpu(b->update_extent_nr[j]); |
| 617 | if (!expect(slot < mdev->act_log->nr_elements)) |
| 618 | break; |
| 619 | e = lc_element_by_index(mdev->act_log, slot); |
| 620 | if (e->lc_number != extent_nr) { |
| 621 | if (extent_nr != LC_FREE) |
| 622 | active_extents++; |
| 623 | else |
| 624 | active_extents--; |
| 625 | } |
| 626 | lc_set(mdev->act_log, extent_nr, slot); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 627 | } |
| 628 | spin_unlock_irq(&mdev->al_lock); |
| 629 | |
| 630 | transactions++; |
| 631 | |
| 632 | cancel: |
| 633 | if (i == to) |
| 634 | break; |
| 635 | i++; |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 636 | if (i >= mx) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 637 | i = 0; |
| 638 | } |
| 639 | |
| 640 | mdev->al_tr_number = to_tnr+1; |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 641 | mdev->al_tr_pos = (to + 1) % (MD_AL_SECTORS*512/MD_BLOCK_SIZE); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 642 | |
| 643 | /* ok, we are done with it */ |
| 644 | mutex_unlock(&mdev->md_io_mutex); |
| 645 | |
| 646 | dev_info(DEV, "Found %d transactions (%d active extents) in activity log.\n", |
| 647 | transactions, active_extents); |
| 648 | |
| 649 | return 1; |
| 650 | } |
| 651 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 652 | /** |
Lars Ellenberg | 867f574 | 2011-02-21 13:20:53 +0100 | [diff] [blame] | 653 | * drbd_al_apply_to_bm() - Sets the bitmap to dirty(1) where covered by active AL extents |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 654 | * @mdev: DRBD device. |
| 655 | */ |
| 656 | void drbd_al_apply_to_bm(struct drbd_conf *mdev) |
| 657 | { |
| 658 | unsigned int enr; |
| 659 | unsigned long add = 0; |
| 660 | char ppb[10]; |
Lars Ellenberg | 6719fb0 | 2010-10-18 23:04:07 +0200 | [diff] [blame] | 661 | int i, tmp; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 662 | |
| 663 | wait_event(mdev->al_wait, lc_try_lock(mdev->act_log)); |
| 664 | |
| 665 | for (i = 0; i < mdev->act_log->nr_elements; i++) { |
| 666 | enr = lc_element_by_index(mdev->act_log, i)->lc_number; |
| 667 | if (enr == LC_FREE) |
| 668 | continue; |
Lars Ellenberg | 6719fb0 | 2010-10-18 23:04:07 +0200 | [diff] [blame] | 669 | tmp = drbd_bm_ALe_set_all(mdev, enr); |
| 670 | dynamic_dev_dbg(DEV, "AL: set %d bits in extent %u\n", tmp, enr); |
| 671 | add += tmp; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | lc_unlock(mdev->act_log); |
| 675 | wake_up(&mdev->al_wait); |
| 676 | |
| 677 | dev_info(DEV, "Marked additional %s as out-of-sync based on AL.\n", |
| 678 | ppsize(ppb, Bit2KB(add))); |
| 679 | } |
| 680 | |
| 681 | static int _try_lc_del(struct drbd_conf *mdev, struct lc_element *al_ext) |
| 682 | { |
| 683 | int rv; |
| 684 | |
| 685 | spin_lock_irq(&mdev->al_lock); |
| 686 | rv = (al_ext->refcnt == 0); |
| 687 | if (likely(rv)) |
| 688 | lc_del(mdev->act_log, al_ext); |
| 689 | spin_unlock_irq(&mdev->al_lock); |
| 690 | |
| 691 | return rv; |
| 692 | } |
| 693 | |
| 694 | /** |
| 695 | * drbd_al_shrink() - Removes all active extents form the activity log |
| 696 | * @mdev: DRBD device. |
| 697 | * |
| 698 | * Removes all active extents form the activity log, waiting until |
| 699 | * the reference count of each entry dropped to 0 first, of course. |
| 700 | * |
| 701 | * You need to lock mdev->act_log with lc_try_lock() / lc_unlock() |
| 702 | */ |
| 703 | void drbd_al_shrink(struct drbd_conf *mdev) |
| 704 | { |
| 705 | struct lc_element *al_ext; |
| 706 | int i; |
| 707 | |
Lars Ellenberg | 46a15bc | 2011-02-21 13:21:01 +0100 | [diff] [blame] | 708 | D_ASSERT(test_bit(__LC_LOCKED, &mdev->act_log->flags)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 709 | |
| 710 | for (i = 0; i < mdev->act_log->nr_elements; i++) { |
| 711 | al_ext = lc_element_by_index(mdev->act_log, i); |
| 712 | if (al_ext->lc_number == LC_FREE) |
| 713 | continue; |
| 714 | wait_event(mdev->al_wait, _try_lc_del(mdev, al_ext)); |
| 715 | } |
| 716 | |
| 717 | wake_up(&mdev->al_wait); |
| 718 | } |
| 719 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 720 | static int w_update_odbm(struct drbd_work *w, int unused) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 721 | { |
| 722 | struct update_odbm_work *udw = container_of(w, struct update_odbm_work, w); |
Philipp Reisner | 00d5694 | 2011-02-09 18:09:48 +0100 | [diff] [blame] | 723 | struct drbd_conf *mdev = w->mdev; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 724 | struct sib_info sib = { .sib_reason = SIB_SYNC_PROGRESS, }; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 725 | |
| 726 | if (!get_ldev(mdev)) { |
| 727 | if (__ratelimit(&drbd_ratelimit_state)) |
| 728 | dev_warn(DEV, "Can not update on disk bitmap, local IO disabled.\n"); |
| 729 | kfree(udw); |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 730 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Lars Ellenberg | 19f843a | 2010-12-15 08:59:11 +0100 | [diff] [blame] | 733 | drbd_bm_write_page(mdev, rs_extent_to_bm_page(udw->enr)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 734 | put_ldev(mdev); |
| 735 | |
| 736 | kfree(udw); |
| 737 | |
| 738 | if (drbd_bm_total_weight(mdev) <= mdev->rs_failed) { |
| 739 | switch (mdev->state.conn) { |
| 740 | case C_SYNC_SOURCE: case C_SYNC_TARGET: |
| 741 | case C_PAUSED_SYNC_S: case C_PAUSED_SYNC_T: |
| 742 | drbd_resync_finished(mdev); |
| 743 | default: |
| 744 | /* nothing to do */ |
| 745 | break; |
| 746 | } |
| 747 | } |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 748 | drbd_bcast_event(mdev, &sib); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 749 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 750 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | |
| 754 | /* ATTENTION. The AL's extents are 4MB each, while the extents in the |
| 755 | * resync LRU-cache are 16MB each. |
| 756 | * The caller of this function has to hold an get_ldev() reference. |
| 757 | * |
| 758 | * TODO will be obsoleted once we have a caching lru of the on disk bitmap |
| 759 | */ |
| 760 | static void drbd_try_clear_on_disk_bm(struct drbd_conf *mdev, sector_t sector, |
| 761 | int count, int success) |
| 762 | { |
| 763 | struct lc_element *e; |
| 764 | struct update_odbm_work *udw; |
| 765 | |
| 766 | unsigned int enr; |
| 767 | |
| 768 | D_ASSERT(atomic_read(&mdev->local_cnt)); |
| 769 | |
| 770 | /* I simply assume that a sector/size pair never crosses |
| 771 | * a 16 MB extent border. (Currently this is true...) */ |
| 772 | enr = BM_SECT_TO_EXT(sector); |
| 773 | |
| 774 | e = lc_get(mdev->resync, enr); |
| 775 | if (e) { |
| 776 | struct bm_extent *ext = lc_entry(e, struct bm_extent, lce); |
| 777 | if (ext->lce.lc_number == enr) { |
| 778 | if (success) |
| 779 | ext->rs_left -= count; |
| 780 | else |
| 781 | ext->rs_failed += count; |
| 782 | if (ext->rs_left < ext->rs_failed) { |
| 783 | dev_err(DEV, "BAD! sector=%llus enr=%u rs_left=%d " |
| 784 | "rs_failed=%d count=%d\n", |
| 785 | (unsigned long long)sector, |
| 786 | ext->lce.lc_number, ext->rs_left, |
| 787 | ext->rs_failed, count); |
| 788 | dump_stack(); |
| 789 | |
| 790 | lc_put(mdev->resync, &ext->lce); |
Philipp Reisner | 38fa998 | 2011-03-15 18:24:49 +0100 | [diff] [blame] | 791 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 792 | return; |
| 793 | } |
| 794 | } else { |
| 795 | /* Normally this element should be in the cache, |
| 796 | * since drbd_rs_begin_io() pulled it already in. |
| 797 | * |
| 798 | * But maybe an application write finished, and we set |
| 799 | * something outside the resync lru_cache in sync. |
| 800 | */ |
| 801 | int rs_left = drbd_bm_e_weight(mdev, enr); |
| 802 | if (ext->flags != 0) { |
| 803 | dev_warn(DEV, "changing resync lce: %d[%u;%02lx]" |
| 804 | " -> %d[%u;00]\n", |
| 805 | ext->lce.lc_number, ext->rs_left, |
| 806 | ext->flags, enr, rs_left); |
| 807 | ext->flags = 0; |
| 808 | } |
| 809 | if (ext->rs_failed) { |
| 810 | dev_warn(DEV, "Kicking resync_lru element enr=%u " |
| 811 | "out with rs_failed=%d\n", |
| 812 | ext->lce.lc_number, ext->rs_failed); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 813 | } |
| 814 | ext->rs_left = rs_left; |
| 815 | ext->rs_failed = success ? 0 : count; |
Lars Ellenberg | 46a15bc | 2011-02-21 13:21:01 +0100 | [diff] [blame] | 816 | /* we don't keep a persistent log of the resync lru, |
| 817 | * we can commit any change right away. */ |
| 818 | lc_committed(mdev->resync); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 819 | } |
| 820 | lc_put(mdev->resync, &ext->lce); |
| 821 | /* no race, we are within the al_lock! */ |
| 822 | |
| 823 | if (ext->rs_left == ext->rs_failed) { |
| 824 | ext->rs_failed = 0; |
| 825 | |
| 826 | udw = kmalloc(sizeof(*udw), GFP_ATOMIC); |
| 827 | if (udw) { |
| 828 | udw->enr = ext->lce.lc_number; |
| 829 | udw->w.cb = w_update_odbm; |
Philipp Reisner | a21e929 | 2011-02-08 15:08:49 +0100 | [diff] [blame] | 830 | udw->w.mdev = mdev; |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 831 | drbd_queue_work_front(&mdev->tconn->data.work, &udw->w); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 832 | } else { |
| 833 | dev_warn(DEV, "Could not kmalloc an udw\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 834 | } |
| 835 | } |
| 836 | } else { |
| 837 | dev_err(DEV, "lc_get() failed! locked=%d/%d flags=%lu\n", |
| 838 | mdev->resync_locked, |
| 839 | mdev->resync->nr_elements, |
| 840 | mdev->resync->flags); |
| 841 | } |
| 842 | } |
| 843 | |
Lars Ellenberg | c6ea14d | 2010-11-05 09:23:37 +0100 | [diff] [blame] | 844 | void drbd_advance_rs_marks(struct drbd_conf *mdev, unsigned long still_to_go) |
| 845 | { |
| 846 | unsigned long now = jiffies; |
| 847 | unsigned long last = mdev->rs_mark_time[mdev->rs_last_mark]; |
| 848 | int next = (mdev->rs_last_mark + 1) % DRBD_SYNC_MARKS; |
| 849 | if (time_after_eq(now, last + DRBD_SYNC_MARK_STEP)) { |
| 850 | if (mdev->rs_mark_left[mdev->rs_last_mark] != still_to_go && |
| 851 | mdev->state.conn != C_PAUSED_SYNC_T && |
| 852 | mdev->state.conn != C_PAUSED_SYNC_S) { |
| 853 | mdev->rs_mark_time[next] = now; |
| 854 | mdev->rs_mark_left[next] = still_to_go; |
| 855 | mdev->rs_last_mark = next; |
| 856 | } |
| 857 | } |
| 858 | } |
| 859 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 860 | /* clear the bit corresponding to the piece of storage in question: |
| 861 | * size byte of data starting from sector. Only clear a bits of the affected |
| 862 | * one ore more _aligned_ BM_BLOCK_SIZE blocks. |
| 863 | * |
| 864 | * called by worker on C_SYNC_TARGET and receiver on SyncSource. |
| 865 | * |
| 866 | */ |
| 867 | void __drbd_set_in_sync(struct drbd_conf *mdev, sector_t sector, int size, |
| 868 | const char *file, const unsigned int line) |
| 869 | { |
| 870 | /* Is called from worker and receiver context _only_ */ |
| 871 | unsigned long sbnr, ebnr, lbnr; |
| 872 | unsigned long count = 0; |
| 873 | sector_t esector, nr_sectors; |
| 874 | int wake_up = 0; |
| 875 | unsigned long flags; |
| 876 | |
Andreas Gruenbacher | c670a39 | 2011-02-21 12:41:39 +0100 | [diff] [blame] | 877 | if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 878 | dev_err(DEV, "drbd_set_in_sync: sector=%llus size=%d nonsense!\n", |
| 879 | (unsigned long long)sector, size); |
| 880 | return; |
| 881 | } |
| 882 | nr_sectors = drbd_get_capacity(mdev->this_bdev); |
| 883 | esector = sector + (size >> 9) - 1; |
| 884 | |
Andreas Gruenbacher | 841ce24 | 2010-12-15 19:31:20 +0100 | [diff] [blame] | 885 | if (!expect(sector < nr_sectors)) |
| 886 | return; |
| 887 | if (!expect(esector < nr_sectors)) |
| 888 | esector = nr_sectors - 1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 889 | |
| 890 | lbnr = BM_SECT_TO_BIT(nr_sectors-1); |
| 891 | |
| 892 | /* we clear it (in sync). |
| 893 | * round up start sector, round down end sector. we make sure we only |
| 894 | * clear full, aligned, BM_BLOCK_SIZE (4K) blocks */ |
| 895 | if (unlikely(esector < BM_SECT_PER_BIT-1)) |
| 896 | return; |
| 897 | if (unlikely(esector == (nr_sectors-1))) |
| 898 | ebnr = lbnr; |
| 899 | else |
| 900 | ebnr = BM_SECT_TO_BIT(esector - (BM_SECT_PER_BIT-1)); |
| 901 | sbnr = BM_SECT_TO_BIT(sector + BM_SECT_PER_BIT-1); |
| 902 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 903 | if (sbnr > ebnr) |
| 904 | return; |
| 905 | |
| 906 | /* |
| 907 | * ok, (capacity & 7) != 0 sometimes, but who cares... |
| 908 | * we count rs_{total,left} in bits, not sectors. |
| 909 | */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 910 | count = drbd_bm_clear_bits(mdev, sbnr, ebnr); |
Lars Ellenberg | 1d7734a | 2010-08-11 21:21:50 +0200 | [diff] [blame] | 911 | if (count && get_ldev(mdev)) { |
Lars Ellenberg | c6ea14d | 2010-11-05 09:23:37 +0100 | [diff] [blame] | 912 | drbd_advance_rs_marks(mdev, drbd_bm_total_weight(mdev)); |
Lars Ellenberg | 1d7734a | 2010-08-11 21:21:50 +0200 | [diff] [blame] | 913 | spin_lock_irqsave(&mdev->al_lock, flags); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 914 | drbd_try_clear_on_disk_bm(mdev, sector, count, true); |
Lars Ellenberg | 1d7734a | 2010-08-11 21:21:50 +0200 | [diff] [blame] | 915 | spin_unlock_irqrestore(&mdev->al_lock, flags); |
| 916 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 917 | /* just wake_up unconditional now, various lc_chaged(), |
| 918 | * lc_put() in drbd_try_clear_on_disk_bm(). */ |
| 919 | wake_up = 1; |
Lars Ellenberg | 1d7734a | 2010-08-11 21:21:50 +0200 | [diff] [blame] | 920 | put_ldev(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 921 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 922 | if (wake_up) |
| 923 | wake_up(&mdev->al_wait); |
| 924 | } |
| 925 | |
| 926 | /* |
| 927 | * this is intended to set one request worth of data out of sync. |
| 928 | * affects at least 1 bit, |
Lars Ellenberg | 1816a2b | 2010-11-11 15:19:07 +0100 | [diff] [blame] | 929 | * and at most 1+DRBD_MAX_BIO_SIZE/BM_BLOCK_SIZE bits. |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 930 | * |
| 931 | * called by tl_clear and drbd_send_dblock (==drbd_make_request). |
| 932 | * so this can be _any_ process. |
| 933 | */ |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 934 | int __drbd_set_out_of_sync(struct drbd_conf *mdev, sector_t sector, int size, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 935 | const char *file, const unsigned int line) |
| 936 | { |
| 937 | unsigned long sbnr, ebnr, lbnr, flags; |
| 938 | sector_t esector, nr_sectors; |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 939 | unsigned int enr, count = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 940 | struct lc_element *e; |
| 941 | |
Andreas Gruenbacher | c670a39 | 2011-02-21 12:41:39 +0100 | [diff] [blame] | 942 | if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 943 | dev_err(DEV, "sector: %llus, size: %d\n", |
| 944 | (unsigned long long)sector, size); |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 945 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | if (!get_ldev(mdev)) |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 949 | return 0; /* no disk, no metadata, no bitmap to set bits in */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 950 | |
| 951 | nr_sectors = drbd_get_capacity(mdev->this_bdev); |
| 952 | esector = sector + (size >> 9) - 1; |
| 953 | |
Andreas Gruenbacher | 841ce24 | 2010-12-15 19:31:20 +0100 | [diff] [blame] | 954 | if (!expect(sector < nr_sectors)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 955 | goto out; |
Andreas Gruenbacher | 841ce24 | 2010-12-15 19:31:20 +0100 | [diff] [blame] | 956 | if (!expect(esector < nr_sectors)) |
| 957 | esector = nr_sectors - 1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 958 | |
| 959 | lbnr = BM_SECT_TO_BIT(nr_sectors-1); |
| 960 | |
| 961 | /* we set it out of sync, |
| 962 | * we do not need to round anything here */ |
| 963 | sbnr = BM_SECT_TO_BIT(sector); |
| 964 | ebnr = BM_SECT_TO_BIT(esector); |
| 965 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 966 | /* ok, (capacity & 7) != 0 sometimes, but who cares... |
| 967 | * we count rs_{total,left} in bits, not sectors. */ |
| 968 | spin_lock_irqsave(&mdev->al_lock, flags); |
| 969 | count = drbd_bm_set_bits(mdev, sbnr, ebnr); |
| 970 | |
| 971 | enr = BM_SECT_TO_EXT(sector); |
| 972 | e = lc_find(mdev->resync, enr); |
| 973 | if (e) |
| 974 | lc_entry(e, struct bm_extent, lce)->rs_left += count; |
| 975 | spin_unlock_irqrestore(&mdev->al_lock, flags); |
| 976 | |
| 977 | out: |
| 978 | put_ldev(mdev); |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 979 | |
| 980 | return count; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | static |
| 984 | struct bm_extent *_bme_get(struct drbd_conf *mdev, unsigned int enr) |
| 985 | { |
| 986 | struct lc_element *e; |
| 987 | struct bm_extent *bm_ext; |
| 988 | int wakeup = 0; |
| 989 | unsigned long rs_flags; |
| 990 | |
| 991 | spin_lock_irq(&mdev->al_lock); |
| 992 | if (mdev->resync_locked > mdev->resync->nr_elements/2) { |
| 993 | spin_unlock_irq(&mdev->al_lock); |
| 994 | return NULL; |
| 995 | } |
| 996 | e = lc_get(mdev->resync, enr); |
| 997 | bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL; |
| 998 | if (bm_ext) { |
| 999 | if (bm_ext->lce.lc_number != enr) { |
| 1000 | bm_ext->rs_left = drbd_bm_e_weight(mdev, enr); |
| 1001 | bm_ext->rs_failed = 0; |
Lars Ellenberg | 46a15bc | 2011-02-21 13:21:01 +0100 | [diff] [blame] | 1002 | lc_committed(mdev->resync); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1003 | wakeup = 1; |
| 1004 | } |
| 1005 | if (bm_ext->lce.refcnt == 1) |
| 1006 | mdev->resync_locked++; |
| 1007 | set_bit(BME_NO_WRITES, &bm_ext->flags); |
| 1008 | } |
| 1009 | rs_flags = mdev->resync->flags; |
| 1010 | spin_unlock_irq(&mdev->al_lock); |
| 1011 | if (wakeup) |
| 1012 | wake_up(&mdev->al_wait); |
| 1013 | |
| 1014 | if (!bm_ext) { |
| 1015 | if (rs_flags & LC_STARVING) |
| 1016 | dev_warn(DEV, "Have to wait for element" |
| 1017 | " (resync LRU too small?)\n"); |
Lars Ellenberg | 46a15bc | 2011-02-21 13:21:01 +0100 | [diff] [blame] | 1018 | BUG_ON(rs_flags & LC_LOCKED); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | return bm_ext; |
| 1022 | } |
| 1023 | |
| 1024 | static int _is_in_al(struct drbd_conf *mdev, unsigned int enr) |
| 1025 | { |
Lars Ellenberg | 46a15bc | 2011-02-21 13:21:01 +0100 | [diff] [blame] | 1026 | int rv; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1027 | |
| 1028 | spin_lock_irq(&mdev->al_lock); |
Lars Ellenberg | 46a15bc | 2011-02-21 13:21:01 +0100 | [diff] [blame] | 1029 | rv = lc_is_used(mdev->act_log, enr); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1030 | spin_unlock_irq(&mdev->al_lock); |
| 1031 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1032 | return rv; |
| 1033 | } |
| 1034 | |
| 1035 | /** |
| 1036 | * drbd_rs_begin_io() - Gets an extent in the resync LRU cache and sets it to BME_LOCKED |
| 1037 | * @mdev: DRBD device. |
| 1038 | * @sector: The sector number. |
| 1039 | * |
Lars Ellenberg | 80a40e4 | 2010-08-11 23:28:00 +0200 | [diff] [blame] | 1040 | * This functions sleeps on al_wait. Returns 0 on success, -EINTR if interrupted. |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1041 | */ |
| 1042 | int drbd_rs_begin_io(struct drbd_conf *mdev, sector_t sector) |
| 1043 | { |
| 1044 | unsigned int enr = BM_SECT_TO_EXT(sector); |
| 1045 | struct bm_extent *bm_ext; |
| 1046 | int i, sig; |
Philipp Reisner | f91ab62 | 2010-11-09 13:59:41 +0100 | [diff] [blame] | 1047 | int sa = 200; /* Step aside 200 times, then grab the extent and let app-IO wait. |
| 1048 | 200 times -> 20 seconds. */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1049 | |
Philipp Reisner | f91ab62 | 2010-11-09 13:59:41 +0100 | [diff] [blame] | 1050 | retry: |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1051 | sig = wait_event_interruptible(mdev->al_wait, |
| 1052 | (bm_ext = _bme_get(mdev, enr))); |
| 1053 | if (sig) |
Lars Ellenberg | 80a40e4 | 2010-08-11 23:28:00 +0200 | [diff] [blame] | 1054 | return -EINTR; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1055 | |
| 1056 | if (test_bit(BME_LOCKED, &bm_ext->flags)) |
Lars Ellenberg | 80a40e4 | 2010-08-11 23:28:00 +0200 | [diff] [blame] | 1057 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1058 | |
| 1059 | for (i = 0; i < AL_EXT_PER_BM_SECT; i++) { |
| 1060 | sig = wait_event_interruptible(mdev->al_wait, |
Philipp Reisner | f91ab62 | 2010-11-09 13:59:41 +0100 | [diff] [blame] | 1061 | !_is_in_al(mdev, enr * AL_EXT_PER_BM_SECT + i) || |
Philipp Reisner | c507f46 | 2010-11-22 15:49:17 +0100 | [diff] [blame] | 1062 | test_bit(BME_PRIORITY, &bm_ext->flags)); |
Philipp Reisner | f91ab62 | 2010-11-09 13:59:41 +0100 | [diff] [blame] | 1063 | |
| 1064 | if (sig || (test_bit(BME_PRIORITY, &bm_ext->flags) && sa)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1065 | spin_lock_irq(&mdev->al_lock); |
| 1066 | if (lc_put(mdev->resync, &bm_ext->lce) == 0) { |
Philipp Reisner | f91ab62 | 2010-11-09 13:59:41 +0100 | [diff] [blame] | 1067 | bm_ext->flags = 0; /* clears BME_NO_WRITES and eventually BME_PRIORITY */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1068 | mdev->resync_locked--; |
| 1069 | wake_up(&mdev->al_wait); |
| 1070 | } |
| 1071 | spin_unlock_irq(&mdev->al_lock); |
Philipp Reisner | f91ab62 | 2010-11-09 13:59:41 +0100 | [diff] [blame] | 1072 | if (sig) |
| 1073 | return -EINTR; |
| 1074 | if (schedule_timeout_interruptible(HZ/10)) |
| 1075 | return -EINTR; |
Philipp Reisner | c507f46 | 2010-11-22 15:49:17 +0100 | [diff] [blame] | 1076 | if (sa && --sa == 0) |
| 1077 | dev_warn(DEV,"drbd_rs_begin_io() stepped aside for 20sec." |
| 1078 | "Resync stalled?\n"); |
Philipp Reisner | f91ab62 | 2010-11-09 13:59:41 +0100 | [diff] [blame] | 1079 | goto retry; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1080 | } |
| 1081 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1082 | set_bit(BME_LOCKED, &bm_ext->flags); |
Lars Ellenberg | 80a40e4 | 2010-08-11 23:28:00 +0200 | [diff] [blame] | 1083 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | /** |
| 1087 | * drbd_try_rs_begin_io() - Gets an extent in the resync LRU cache, does not sleep |
| 1088 | * @mdev: DRBD device. |
| 1089 | * @sector: The sector number. |
| 1090 | * |
| 1091 | * Gets an extent in the resync LRU cache, sets it to BME_NO_WRITES, then |
| 1092 | * tries to set it to BME_LOCKED. Returns 0 upon success, and -EAGAIN |
| 1093 | * if there is still application IO going on in this area. |
| 1094 | */ |
| 1095 | int drbd_try_rs_begin_io(struct drbd_conf *mdev, sector_t sector) |
| 1096 | { |
| 1097 | unsigned int enr = BM_SECT_TO_EXT(sector); |
| 1098 | const unsigned int al_enr = enr*AL_EXT_PER_BM_SECT; |
| 1099 | struct lc_element *e; |
| 1100 | struct bm_extent *bm_ext; |
| 1101 | int i; |
| 1102 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1103 | spin_lock_irq(&mdev->al_lock); |
| 1104 | if (mdev->resync_wenr != LC_FREE && mdev->resync_wenr != enr) { |
| 1105 | /* in case you have very heavy scattered io, it may |
| 1106 | * stall the syncer undefined if we give up the ref count |
| 1107 | * when we try again and requeue. |
| 1108 | * |
| 1109 | * if we don't give up the refcount, but the next time |
| 1110 | * we are scheduled this extent has been "synced" by new |
| 1111 | * application writes, we'd miss the lc_put on the |
| 1112 | * extent we keep the refcount on. |
| 1113 | * so we remembered which extent we had to try again, and |
| 1114 | * if the next requested one is something else, we do |
| 1115 | * the lc_put here... |
| 1116 | * we also have to wake_up |
| 1117 | */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1118 | e = lc_find(mdev->resync, mdev->resync_wenr); |
| 1119 | bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL; |
| 1120 | if (bm_ext) { |
| 1121 | D_ASSERT(!test_bit(BME_LOCKED, &bm_ext->flags)); |
| 1122 | D_ASSERT(test_bit(BME_NO_WRITES, &bm_ext->flags)); |
| 1123 | clear_bit(BME_NO_WRITES, &bm_ext->flags); |
| 1124 | mdev->resync_wenr = LC_FREE; |
| 1125 | if (lc_put(mdev->resync, &bm_ext->lce) == 0) |
| 1126 | mdev->resync_locked--; |
| 1127 | wake_up(&mdev->al_wait); |
| 1128 | } else { |
| 1129 | dev_alert(DEV, "LOGIC BUG\n"); |
| 1130 | } |
| 1131 | } |
| 1132 | /* TRY. */ |
| 1133 | e = lc_try_get(mdev->resync, enr); |
| 1134 | bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL; |
| 1135 | if (bm_ext) { |
| 1136 | if (test_bit(BME_LOCKED, &bm_ext->flags)) |
| 1137 | goto proceed; |
| 1138 | if (!test_and_set_bit(BME_NO_WRITES, &bm_ext->flags)) { |
| 1139 | mdev->resync_locked++; |
| 1140 | } else { |
| 1141 | /* we did set the BME_NO_WRITES, |
| 1142 | * but then could not set BME_LOCKED, |
| 1143 | * so we tried again. |
| 1144 | * drop the extra reference. */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1145 | bm_ext->lce.refcnt--; |
| 1146 | D_ASSERT(bm_ext->lce.refcnt > 0); |
| 1147 | } |
| 1148 | goto check_al; |
| 1149 | } else { |
| 1150 | /* do we rather want to try later? */ |
Jens Axboe | 6a0afdf | 2009-10-01 09:04:14 +0200 | [diff] [blame] | 1151 | if (mdev->resync_locked > mdev->resync->nr_elements-3) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1152 | goto try_again; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1153 | /* Do or do not. There is no try. -- Yoda */ |
| 1154 | e = lc_get(mdev->resync, enr); |
| 1155 | bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL; |
| 1156 | if (!bm_ext) { |
| 1157 | const unsigned long rs_flags = mdev->resync->flags; |
| 1158 | if (rs_flags & LC_STARVING) |
| 1159 | dev_warn(DEV, "Have to wait for element" |
| 1160 | " (resync LRU too small?)\n"); |
Lars Ellenberg | 46a15bc | 2011-02-21 13:21:01 +0100 | [diff] [blame] | 1161 | BUG_ON(rs_flags & LC_LOCKED); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1162 | goto try_again; |
| 1163 | } |
| 1164 | if (bm_ext->lce.lc_number != enr) { |
| 1165 | bm_ext->rs_left = drbd_bm_e_weight(mdev, enr); |
| 1166 | bm_ext->rs_failed = 0; |
Lars Ellenberg | 46a15bc | 2011-02-21 13:21:01 +0100 | [diff] [blame] | 1167 | lc_committed(mdev->resync); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1168 | wake_up(&mdev->al_wait); |
| 1169 | D_ASSERT(test_bit(BME_LOCKED, &bm_ext->flags) == 0); |
| 1170 | } |
| 1171 | set_bit(BME_NO_WRITES, &bm_ext->flags); |
| 1172 | D_ASSERT(bm_ext->lce.refcnt == 1); |
| 1173 | mdev->resync_locked++; |
| 1174 | goto check_al; |
| 1175 | } |
| 1176 | check_al: |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1177 | for (i = 0; i < AL_EXT_PER_BM_SECT; i++) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1178 | if (lc_is_used(mdev->act_log, al_enr+i)) |
| 1179 | goto try_again; |
| 1180 | } |
| 1181 | set_bit(BME_LOCKED, &bm_ext->flags); |
| 1182 | proceed: |
| 1183 | mdev->resync_wenr = LC_FREE; |
| 1184 | spin_unlock_irq(&mdev->al_lock); |
| 1185 | return 0; |
| 1186 | |
| 1187 | try_again: |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1188 | if (bm_ext) |
| 1189 | mdev->resync_wenr = enr; |
| 1190 | spin_unlock_irq(&mdev->al_lock); |
| 1191 | return -EAGAIN; |
| 1192 | } |
| 1193 | |
| 1194 | void drbd_rs_complete_io(struct drbd_conf *mdev, sector_t sector) |
| 1195 | { |
| 1196 | unsigned int enr = BM_SECT_TO_EXT(sector); |
| 1197 | struct lc_element *e; |
| 1198 | struct bm_extent *bm_ext; |
| 1199 | unsigned long flags; |
| 1200 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1201 | spin_lock_irqsave(&mdev->al_lock, flags); |
| 1202 | e = lc_find(mdev->resync, enr); |
| 1203 | bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL; |
| 1204 | if (!bm_ext) { |
| 1205 | spin_unlock_irqrestore(&mdev->al_lock, flags); |
| 1206 | if (__ratelimit(&drbd_ratelimit_state)) |
| 1207 | dev_err(DEV, "drbd_rs_complete_io() called, but extent not found\n"); |
| 1208 | return; |
| 1209 | } |
| 1210 | |
| 1211 | if (bm_ext->lce.refcnt == 0) { |
| 1212 | spin_unlock_irqrestore(&mdev->al_lock, flags); |
| 1213 | dev_err(DEV, "drbd_rs_complete_io(,%llu [=%u]) called, " |
| 1214 | "but refcnt is 0!?\n", |
| 1215 | (unsigned long long)sector, enr); |
| 1216 | return; |
| 1217 | } |
| 1218 | |
| 1219 | if (lc_put(mdev->resync, &bm_ext->lce) == 0) { |
Philipp Reisner | e3555d8 | 2010-11-07 15:56:29 +0100 | [diff] [blame] | 1220 | bm_ext->flags = 0; /* clear BME_LOCKED, BME_NO_WRITES and BME_PRIORITY */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1221 | mdev->resync_locked--; |
| 1222 | wake_up(&mdev->al_wait); |
| 1223 | } |
| 1224 | |
| 1225 | spin_unlock_irqrestore(&mdev->al_lock, flags); |
| 1226 | } |
| 1227 | |
| 1228 | /** |
| 1229 | * drbd_rs_cancel_all() - Removes all extents from the resync LRU (even BME_LOCKED) |
| 1230 | * @mdev: DRBD device. |
| 1231 | */ |
| 1232 | void drbd_rs_cancel_all(struct drbd_conf *mdev) |
| 1233 | { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1234 | spin_lock_irq(&mdev->al_lock); |
| 1235 | |
| 1236 | if (get_ldev_if_state(mdev, D_FAILED)) { /* Makes sure ->resync is there. */ |
| 1237 | lc_reset(mdev->resync); |
| 1238 | put_ldev(mdev); |
| 1239 | } |
| 1240 | mdev->resync_locked = 0; |
| 1241 | mdev->resync_wenr = LC_FREE; |
| 1242 | spin_unlock_irq(&mdev->al_lock); |
| 1243 | wake_up(&mdev->al_wait); |
| 1244 | } |
| 1245 | |
| 1246 | /** |
| 1247 | * drbd_rs_del_all() - Gracefully remove all extents from the resync LRU |
| 1248 | * @mdev: DRBD device. |
| 1249 | * |
| 1250 | * Returns 0 upon success, -EAGAIN if at least one reference count was |
| 1251 | * not zero. |
| 1252 | */ |
| 1253 | int drbd_rs_del_all(struct drbd_conf *mdev) |
| 1254 | { |
| 1255 | struct lc_element *e; |
| 1256 | struct bm_extent *bm_ext; |
| 1257 | int i; |
| 1258 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1259 | spin_lock_irq(&mdev->al_lock); |
| 1260 | |
| 1261 | if (get_ldev_if_state(mdev, D_FAILED)) { |
| 1262 | /* ok, ->resync is there. */ |
| 1263 | for (i = 0; i < mdev->resync->nr_elements; i++) { |
| 1264 | e = lc_element_by_index(mdev->resync, i); |
Philipp Reisner | b2b163d | 2010-04-02 08:40:33 +0200 | [diff] [blame] | 1265 | bm_ext = lc_entry(e, struct bm_extent, lce); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1266 | if (bm_ext->lce.lc_number == LC_FREE) |
| 1267 | continue; |
| 1268 | if (bm_ext->lce.lc_number == mdev->resync_wenr) { |
| 1269 | dev_info(DEV, "dropping %u in drbd_rs_del_all, apparently" |
| 1270 | " got 'synced' by application io\n", |
| 1271 | mdev->resync_wenr); |
| 1272 | D_ASSERT(!test_bit(BME_LOCKED, &bm_ext->flags)); |
| 1273 | D_ASSERT(test_bit(BME_NO_WRITES, &bm_ext->flags)); |
| 1274 | clear_bit(BME_NO_WRITES, &bm_ext->flags); |
| 1275 | mdev->resync_wenr = LC_FREE; |
| 1276 | lc_put(mdev->resync, &bm_ext->lce); |
| 1277 | } |
| 1278 | if (bm_ext->lce.refcnt != 0) { |
| 1279 | dev_info(DEV, "Retrying drbd_rs_del_all() later. " |
| 1280 | "refcnt=%d\n", bm_ext->lce.refcnt); |
| 1281 | put_ldev(mdev); |
| 1282 | spin_unlock_irq(&mdev->al_lock); |
| 1283 | return -EAGAIN; |
| 1284 | } |
| 1285 | D_ASSERT(!test_bit(BME_LOCKED, &bm_ext->flags)); |
| 1286 | D_ASSERT(!test_bit(BME_NO_WRITES, &bm_ext->flags)); |
| 1287 | lc_del(mdev->resync, &bm_ext->lce); |
| 1288 | } |
| 1289 | D_ASSERT(mdev->resync->used == 0); |
| 1290 | put_ldev(mdev); |
| 1291 | } |
| 1292 | spin_unlock_irq(&mdev->al_lock); |
| 1293 | |
| 1294 | return 0; |
| 1295 | } |
| 1296 | |
| 1297 | /** |
| 1298 | * drbd_rs_failed_io() - Record information on a failure to resync the specified blocks |
| 1299 | * @mdev: DRBD device. |
| 1300 | * @sector: The sector number. |
| 1301 | * @size: Size of failed IO operation, in byte. |
| 1302 | */ |
| 1303 | void drbd_rs_failed_io(struct drbd_conf *mdev, sector_t sector, int size) |
| 1304 | { |
| 1305 | /* Is called from worker and receiver context _only_ */ |
| 1306 | unsigned long sbnr, ebnr, lbnr; |
| 1307 | unsigned long count; |
| 1308 | sector_t esector, nr_sectors; |
| 1309 | int wake_up = 0; |
| 1310 | |
Andreas Gruenbacher | c670a39 | 2011-02-21 12:41:39 +0100 | [diff] [blame] | 1311 | if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1312 | dev_err(DEV, "drbd_rs_failed_io: sector=%llus size=%d nonsense!\n", |
| 1313 | (unsigned long long)sector, size); |
| 1314 | return; |
| 1315 | } |
| 1316 | nr_sectors = drbd_get_capacity(mdev->this_bdev); |
| 1317 | esector = sector + (size >> 9) - 1; |
| 1318 | |
Andreas Gruenbacher | 841ce24 | 2010-12-15 19:31:20 +0100 | [diff] [blame] | 1319 | if (!expect(sector < nr_sectors)) |
| 1320 | return; |
| 1321 | if (!expect(esector < nr_sectors)) |
| 1322 | esector = nr_sectors - 1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1323 | |
| 1324 | lbnr = BM_SECT_TO_BIT(nr_sectors-1); |
| 1325 | |
| 1326 | /* |
| 1327 | * round up start sector, round down end sector. we make sure we only |
| 1328 | * handle full, aligned, BM_BLOCK_SIZE (4K) blocks */ |
| 1329 | if (unlikely(esector < BM_SECT_PER_BIT-1)) |
| 1330 | return; |
| 1331 | if (unlikely(esector == (nr_sectors-1))) |
| 1332 | ebnr = lbnr; |
| 1333 | else |
| 1334 | ebnr = BM_SECT_TO_BIT(esector - (BM_SECT_PER_BIT-1)); |
| 1335 | sbnr = BM_SECT_TO_BIT(sector + BM_SECT_PER_BIT-1); |
| 1336 | |
| 1337 | if (sbnr > ebnr) |
| 1338 | return; |
| 1339 | |
| 1340 | /* |
| 1341 | * ok, (capacity & 7) != 0 sometimes, but who cares... |
| 1342 | * we count rs_{total,left} in bits, not sectors. |
| 1343 | */ |
| 1344 | spin_lock_irq(&mdev->al_lock); |
| 1345 | count = drbd_bm_count_bits(mdev, sbnr, ebnr); |
| 1346 | if (count) { |
| 1347 | mdev->rs_failed += count; |
| 1348 | |
| 1349 | if (get_ldev(mdev)) { |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 1350 | drbd_try_clear_on_disk_bm(mdev, sector, count, false); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1351 | put_ldev(mdev); |
| 1352 | } |
| 1353 | |
| 1354 | /* just wake_up unconditional now, various lc_chaged(), |
| 1355 | * lc_put() in drbd_try_clear_on_disk_bm(). */ |
| 1356 | wake_up = 1; |
| 1357 | } |
| 1358 | spin_unlock_irq(&mdev->al_lock); |
| 1359 | if (wake_up) |
| 1360 | wake_up(&mdev->al_wait); |
| 1361 | } |