blob: 50b851e389e6f17fd959cb15a39cb077de58a308 [file] [log] [blame]
Philipp Reisnerb411b362009-09-25 16:07:19 -07001/*
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 Ellenberg7ad651b2011-02-21 13:21:03 +010027#include <linux/crc32c.h>
Philipp Reisnerb411b362009-09-25 16:07:19 -070028#include <linux/drbd.h>
Lars Ellenberg7ad651b2011-02-21 13:21:03 +010029#include <linux/drbd_limits.h>
30#include <linux/dynamic_debug.h>
Philipp Reisnerb411b362009-09-25 16:07:19 -070031#include "drbd_int.h"
Philipp Reisnerb411b362009-09-25 16:07:19 -070032#include "drbd_wrappers.h"
33
Lars Ellenberg85f103d2011-03-31 12:06:48 +020034
35enum al_transaction_types {
36 AL_TR_UPDATE = 0,
37 AL_TR_INITIALIZED = 0xffff
38};
Lars Ellenberg7ad651b2011-02-21 13:21:03 +010039/* all fields on disc in big endian */
40struct __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 Ellenberg85f103d2011-03-31 12:06:48 +020052 * purge-all, set-all-idle, set-all-active, ... to-be-defined
53 * see also enum al_transaction_types */
Lars Ellenberg7ad651b2011-02-21 13:21:03 +010054 __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 Reisnerb411b362009-09-25 16:07:19 -070094};
95
96struct update_odbm_work {
97 struct drbd_work w;
98 unsigned int enr;
99};
100
101struct update_al_work {
102 struct drbd_work w;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700103 struct completion event;
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100104 int err;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700105};
106
107struct drbd_atodb_wait {
108 atomic_t count;
109 struct completion io_done;
110 struct drbd_conf *mdev;
111 int error;
112};
113
114
Andreas Gruenbacher99920dc2011-03-16 15:31:39 +0100115static int w_al_write_transaction(struct drbd_work *, int);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700116
Philipp Reisnerb411b362009-09-25 16:07:19 -0700117static 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 Gruenbacherac29f402010-12-13 02:20:47 +0100124 int err;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700125
126 md_io.mdev = mdev;
127 init_completion(&md_io.event);
128 md_io.error = 0;
129
Philipp Reisnera8a4e512010-08-25 10:21:04 +0200130 if ((rw & WRITE) && !test_bit(MD_NO_FUA, &mdev->flags))
Lars Ellenberg86e1e982011-06-28 13:22:48 +0200131 rw |= REQ_FUA | REQ_FLUSH;
Jens Axboe721a9602011-03-09 11:56:30 +0100132 rw |= REQ_SYNC;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700133
Lars Ellenbergda4a75d2011-02-23 17:02:01 +0100134 bio = bio_alloc_drbd(GFP_NOIO);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700135 bio->bi_bdev = bdev->md_bdev;
136 bio->bi_sector = sector;
Andreas Gruenbacherac29f402010-12-13 02:20:47 +0100137 err = -EIO;
138 if (bio_add_page(bio, page, size, 0) != size)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700139 goto out;
140 bio->bi_private = &md_io;
141 bio->bi_end_io = drbd_md_io_complete;
142 bio->bi_rw = rw;
143
Andreas Gruenbacher0cf9d272010-12-07 10:43:29 +0100144 if (drbd_insert_fault(mdev, (rw & WRITE) ? DRBD_FAULT_MD_WR : DRBD_FAULT_MD_RD))
Philipp Reisnerb411b362009-09-25 16:07:19 -0700145 bio_endio(bio, -EIO);
146 else
147 submit_bio(rw, bio);
148 wait_for_completion(&md_io.event);
Andreas Gruenbacherac29f402010-12-13 02:20:47 +0100149 if (bio_flagged(bio, BIO_UPTODATE))
150 err = md_io.error;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700151
Philipp Reisnerb411b362009-09-25 16:07:19 -0700152 out:
153 bio_put(bio);
Andreas Gruenbacherac29f402010-12-13 02:20:47 +0100154 return err;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700155}
156
157int drbd_md_sync_page_io(struct drbd_conf *mdev, struct drbd_backing_dev *bdev,
158 sector_t sector, int rw)
159{
Andreas Gruenbacher3fbf4d22010-12-13 02:25:41 +0100160 int err;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700161 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 Ellenberg7ad651b2011-02-21 13:21:03 +0100167 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 Reisnerb411b362009-09-25 16:07:19 -0700170
171 if (sector < drbd_md_first_sector(bdev) ||
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100172 sector + 7 > drbd_md_last_sector(bdev))
Philipp Reisnerb411b362009-09-25 16:07:19 -0700173 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 Gruenbacher3fbf4d22010-12-13 02:25:41 +0100177 err = _drbd_md_sync_page_io(mdev, bdev, iop, sector, rw, MD_BLOCK_SIZE);
178 if (err) {
Philipp Reisnerb411b362009-09-25 16:07:19 -0700179 dev_err(DEV, "drbd_md_sync_page_io(,%llus,%s) failed!\n",
180 (unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ");
Philipp Reisnerb411b362009-09-25 16:07:19 -0700181 }
Andreas Gruenbacher3fbf4d22010-12-13 02:25:41 +0100182 return err;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700183}
184
185static 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 Reisnerf91ab622010-11-09 13:59:41 +0100189 int wake;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700190
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 Reisnerf91ab622010-11-09 13:59:41 +0100196 wake = !test_and_set_bit(BME_PRIORITY, &bm_ext->flags);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700197 spin_unlock_irq(&mdev->al_lock);
Philipp Reisnerf91ab622010-11-09 13:59:41 +0100198 if (wake)
199 wake_up(&mdev->al_wait);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700200 return NULL;
201 }
202 }
Lars Ellenberg46a15bc2011-02-21 13:21:01 +0100203 al_ext = lc_get(mdev->act_log, enr);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700204 spin_unlock_irq(&mdev->al_lock);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700205 return al_ext;
206}
207
Lars Ellenberg181286a2011-03-31 15:18:56 +0200208void drbd_al_begin_io(struct drbd_conf *mdev, struct drbd_interval *i)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700209{
Lars Ellenberg77265472011-03-31 16:00:51 +0200210 /* for bios crossing activity log extent boundaries,
211 * we may need to activate two extents in one go */
Lars Ellenberge15766e2011-04-01 10:38:30 +0200212 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 Reisnerb411b362009-09-25 16:07:19 -0700215
216 D_ASSERT(atomic_read(&mdev->local_cnt) > 0);
217
Lars Ellenberge15766e2011-04-01 10:38:30 +0200218 for (enr = first; enr <= last; enr++)
219 wait_event(mdev->al_wait, _al_get(mdev, enr) != NULL);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700220
Lars Ellenberge15766e2011-04-01 10:38:30 +0200221 if (mdev->act_log->pending_changes) {
Philipp Reisnerb411b362009-09-25 16:07:19 -0700222 /* 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 Reisnerb411b362009-09-25 16:07:19 -0700228
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100229 /* 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 Reisnerb411b362009-09-25 16:07:19 -0700235
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100236 /* Double check: it may have been committed by someone else,
237 * while we have been waiting for the lock. */
Lars Ellenberge15766e2011-04-01 10:38:30 +0200238 if (mdev->act_log->pending_changes) {
239 struct update_al_work al_work;
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100240 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 Reisnerb411b362009-09-25 16:07:19 -0700257 wake_up(&mdev->al_wait);
258 }
259}
260
Lars Ellenberg181286a2011-03-31 15:18:56 +0200261void drbd_al_complete_io(struct drbd_conf *mdev, struct drbd_interval *i)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700262{
Lars Ellenberge15766e2011-04-01 10:38:30 +0200263 /* 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 Reisnerb411b362009-09-25 16:07:19 -0700268 struct lc_element *extent;
269 unsigned long flags;
Lars Ellenberge15766e2011-04-01 10:38:30 +0200270 bool wake = false;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700271
Philipp Reisnerb411b362009-09-25 16:07:19 -0700272 spin_lock_irqsave(&mdev->al_lock, flags);
273
Lars Ellenberge15766e2011-04-01 10:38:30 +0200274 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 Reisnerb411b362009-09-25 16:07:19 -0700282 }
Philipp Reisnerb411b362009-09-25 16:07:19 -0700283 spin_unlock_irqrestore(&mdev->al_lock, flags);
Lars Ellenberge15766e2011-04-01 10:38:30 +0200284 wake_up(&mdev->al_wait);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700285}
286
Lars Ellenberg19f843a2010-12-15 08:59:11 +0100287#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
296static 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
305static 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 Gruenbacher99920dc2011-03-16 15:31:39 +0100314static int
Philipp Reisner00d56942011-02-09 18:09:48 +0100315w_al_write_transaction(struct drbd_work *w, int unused)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700316{
317 struct update_al_work *aw = container_of(w, struct update_al_work, w);
Philipp Reisner00d56942011-02-09 18:09:48 +0100318 struct drbd_conf *mdev = w->mdev;
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100319 struct al_transaction_on_disk *buffer;
320 struct lc_element *e;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700321 sector_t sector;
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100322 int i, mx;
323 unsigned extent_nr;
324 unsigned crc = 0;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700325
326 if (!get_ldev(mdev)) {
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100327 dev_err(DEV, "disk is %s, cannot start al transaction\n",
328 drbd_disk_str(mdev->state.disk));
329 aw->err = -EIO;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700330 complete(&((struct update_al_work *)w)->event);
Andreas Gruenbacher99920dc2011-03-16 15:31:39 +0100331 return 0;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700332 }
Philipp Reisnerb411b362009-09-25 16:07:19 -0700333
Lars Ellenberg6719fb02010-10-18 23:04:07 +0200334 /* The bitmap write may have failed, causing a state change. */
335 if (mdev->state.disk < D_INCONSISTENT) {
336 dev_err(DEV,
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100337 "disk is %s, cannot write al transaction\n",
338 drbd_disk_str(mdev->state.disk));
339 aw->err = -EIO;
Lars Ellenberg6719fb02010-10-18 23:04:07 +0200340 complete(&((struct update_al_work *)w)->event);
341 put_ldev(mdev);
Andreas Gruenbacher99920dc2011-03-16 15:31:39 +0100342 return 0;
Lars Ellenberg6719fb02010-10-18 23:04:07 +0200343 }
344
345 mutex_lock(&mdev->md_io_mutex); /* protects md_io_buffer, al_tr_cycle, ... */
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100346 buffer = page_address(mdev->md_io_page);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700347
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100348 memset(buffer, 0, sizeof(*buffer));
349 buffer->magic = cpu_to_be32(DRBD_AL_MAGIC);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700350 buffer->tr_number = cpu_to_be32(mdev->al_tr_number);
351
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100352 i = 0;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700353
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100354 /* 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 Reisnerb411b362009-09-25 16:07:19 -0700373
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100374 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 Reisnerb411b362009-09-25 16:07:19 -0700379
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100380 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 Reisnerb411b362009-09-25 16:07:19 -0700384 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 Ellenberg7ad651b2011-02-21 13:21:03 +0100388 buffer->context[i] = cpu_to_be32(extent_nr);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700389 }
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100390 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 Reisnerb411b362009-09-25 16:07:19 -0700394 if (mdev->al_tr_cycle >= mdev->act_log->nr_elements)
395 mdev->al_tr_cycle = 0;
396
Philipp Reisnerb411b362009-09-25 16:07:19 -0700397 sector = mdev->ldev->md.md_offset
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100398 + mdev->ldev->md.al_offset
399 + mdev->al_tr_pos * (MD_BLOCK_SIZE>>9);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700400
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100401 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 Gruenbacher3fbf4d22010-12-13 02:25:41 +0100407 else if (drbd_md_sync_page_io(mdev, mdev->ldev, sector, WRITE)) {
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100408 aw->err = -EIO;
Andreas Gruenbacher81e84652010-12-09 15:03:57 +0100409 drbd_chk_io_error(mdev, 1, true);
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100410 } 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 Reisnerb411b362009-09-25 16:07:19 -0700415
416 mutex_unlock(&mdev->md_io_mutex);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700417 complete(&((struct update_al_work *)w)->event);
418 put_ldev(mdev);
419
Andreas Gruenbacher99920dc2011-03-16 15:31:39 +0100420 return 0;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700421}
422
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100423/* 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 Reisnerb411b362009-09-25 16:07:19 -0700431/**
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 */
440static int drbd_al_read_tr(struct drbd_conf *mdev,
441 struct drbd_backing_dev *bdev,
Philipp Reisnerb411b362009-09-25 16:07:19 -0700442 int index)
443{
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100444 struct al_transaction_on_disk *b = page_address(mdev->md_io_page);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700445 sector_t sector;
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100446 u32 crc;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700447
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100448 sector = bdev->md.md_offset
449 + bdev->md.al_offset
450 + index * (MD_BLOCK_SIZE>>9);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700451
452 /* Dont process error normally,
453 * as this is done before disk is attached! */
Andreas Gruenbacher3fbf4d22010-12-13 02:25:41 +0100454 if (drbd_md_sync_page_io(mdev, bdev, sector, READ))
Philipp Reisnerb411b362009-09-25 16:07:19 -0700455 return -1;
456
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100457 if (!expect(b->magic == cpu_to_be32(DRBD_AL_MAGIC)))
458 return 0;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700459
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100460 if (!expect(be16_to_cpu(b->n_updates) <= AL_UPDATES_PER_TRANSACTION))
461 return 0;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700462
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100463 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 Reisnerb411b362009-09-25 16:07:19 -0700475}
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 */
484int drbd_al_read_log(struct drbd_conf *mdev, struct drbd_backing_dev *bdev)
485{
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100486 struct al_transaction_on_disk *b;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700487 int i;
488 int rv;
489 int mx;
490 int active_extents = 0;
491 int transactions = 0;
492 int found_valid = 0;
Lars Ellenberg85f103d2011-03-31 12:06:48 +0200493 int found_initialized = 0;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700494 int from = 0;
495 int to = 0;
496 u32 from_tnr = 0;
497 u32 to_tnr = 0;
498 u32 cnr;
499
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100500 /* 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 Reisnerb411b362009-09-25 16:07:19 -0700503
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 Ellenberg7ad651b2011-02-21 13:21:03 +0100508 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 Reisnerb411b362009-09-25 16:07:19 -0700515
516 /* Find the valid transaction in the log */
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100517 for (i = 0; i < mx; i++) {
518 rv = drbd_al_read_tr(mdev, bdev, i);
519 /* invalid data in that block */
Philipp Reisnerb411b362009-09-25 16:07:19 -0700520 if (rv == 0)
521 continue;
Lars Ellenberg85f103d2011-03-31 12:06:48 +0200522 if (be16_to_cpu(b->transaction_type) == AL_TR_INITIALIZED) {
523 ++found_initialized;
524 continue;
525 }
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100526
527 /* IO error */
Philipp Reisnerb411b362009-09-25 16:07:19 -0700528 if (rv == -1) {
529 mutex_unlock(&mdev->md_io_mutex);
530 return 0;
531 }
Philipp Reisnerb411b362009-09-25 16:07:19 -0700532
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100533 cnr = be32_to_cpu(b->tr_number);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700534 if (++found_valid == 1) {
535 from = i;
536 to = i;
537 from_tnr = cnr;
538 to_tnr = cnr;
539 continue;
540 }
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100541
542 D_ASSERT(cnr != to_tnr);
543 D_ASSERT(cnr != from_tnr);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700544 if ((int)cnr - (int)from_tnr < 0) {
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100545 D_ASSERT(from_tnr - cnr + i - from == mx);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700546 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 Ellenberg85f103d2011-03-31 12:06:48 +0200557 if (found_initialized != mx)
558 dev_warn(DEV, "No usable activity log found.\n");
Philipp Reisnerb411b362009-09-25 16:07:19 -0700559 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 Ellenberg7ad651b2011-02-21 13:21:03 +0100567 struct lc_element *e;
568 unsigned j, n, slot, extent_nr;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700569
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100570 rv = drbd_al_read_tr(mdev, bdev, i);
Andreas Gruenbacher841ce242010-12-15 19:31:20 +0100571 if (!expect(rv != 0))
572 goto cancel;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700573 if (rv == -1) {
574 mutex_unlock(&mdev->md_io_mutex);
575 return 0;
576 }
577
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100578 /* deal with different transaction types.
579 * not yet implemented */
580 if (!expect(b->transaction_type == 0))
581 goto cancel;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700582
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100583 /* 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 Reisnerb411b362009-09-25 16:07:19 -0700592 spin_lock_irq(&mdev->al_lock);
593
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100594 /* 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 Reisnerb411b362009-09-25 16:07:19 -0700608
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100609 /* ... 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 Reisnerb411b362009-09-25 16:07:19 -0700627 }
628 spin_unlock_irq(&mdev->al_lock);
629
630 transactions++;
631
632cancel:
633 if (i == to)
634 break;
635 i++;
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100636 if (i >= mx)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700637 i = 0;
638 }
639
640 mdev->al_tr_number = to_tnr+1;
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100641 mdev->al_tr_pos = (to + 1) % (MD_AL_SECTORS*512/MD_BLOCK_SIZE);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700642
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 Reisnerb411b362009-09-25 16:07:19 -0700652/**
Lars Ellenberg867f5742011-02-21 13:20:53 +0100653 * drbd_al_apply_to_bm() - Sets the bitmap to dirty(1) where covered by active AL extents
Philipp Reisnerb411b362009-09-25 16:07:19 -0700654 * @mdev: DRBD device.
655 */
656void drbd_al_apply_to_bm(struct drbd_conf *mdev)
657{
658 unsigned int enr;
659 unsigned long add = 0;
660 char ppb[10];
Lars Ellenberg6719fb02010-10-18 23:04:07 +0200661 int i, tmp;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700662
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 Ellenberg6719fb02010-10-18 23:04:07 +0200669 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 Reisnerb411b362009-09-25 16:07:19 -0700672 }
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
681static 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 */
703void drbd_al_shrink(struct drbd_conf *mdev)
704{
705 struct lc_element *al_ext;
706 int i;
707
Lars Ellenberg46a15bc2011-02-21 13:21:01 +0100708 D_ASSERT(test_bit(__LC_LOCKED, &mdev->act_log->flags));
Philipp Reisnerb411b362009-09-25 16:07:19 -0700709
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 Gruenbacher99920dc2011-03-16 15:31:39 +0100720static int w_update_odbm(struct drbd_work *w, int unused)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700721{
722 struct update_odbm_work *udw = container_of(w, struct update_odbm_work, w);
Philipp Reisner00d56942011-02-09 18:09:48 +0100723 struct drbd_conf *mdev = w->mdev;
Lars Ellenberg3b98c0c2011-03-07 12:49:34 +0100724 struct sib_info sib = { .sib_reason = SIB_SYNC_PROGRESS, };
Philipp Reisnerb411b362009-09-25 16:07:19 -0700725
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 Gruenbacher99920dc2011-03-16 15:31:39 +0100730 return 0;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700731 }
732
Lars Ellenberg19f843a2010-12-15 08:59:11 +0100733 drbd_bm_write_page(mdev, rs_extent_to_bm_page(udw->enr));
Philipp Reisnerb411b362009-09-25 16:07:19 -0700734 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 Ellenberg3b98c0c2011-03-07 12:49:34 +0100748 drbd_bcast_event(mdev, &sib);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700749
Andreas Gruenbacher99920dc2011-03-16 15:31:39 +0100750 return 0;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700751}
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 */
760static 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 Reisner38fa9982011-03-15 18:24:49 +0100791 conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700792 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 Reisnerb411b362009-09-25 16:07:19 -0700813 }
814 ext->rs_left = rs_left;
815 ext->rs_failed = success ? 0 : count;
Lars Ellenberg46a15bc2011-02-21 13:21:01 +0100816 /* 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 Reisnerb411b362009-09-25 16:07:19 -0700819 }
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 Reisnera21e9292011-02-08 15:08:49 +0100830 udw->w.mdev = mdev;
Philipp Reisnere42325a2011-01-19 13:55:45 +0100831 drbd_queue_work_front(&mdev->tconn->data.work, &udw->w);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700832 } else {
833 dev_warn(DEV, "Could not kmalloc an udw\n");
Philipp Reisnerb411b362009-09-25 16:07:19 -0700834 }
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 Ellenbergc6ea14d2010-11-05 09:23:37 +0100844void 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 Reisnerb411b362009-09-25 16:07:19 -0700860/* 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 */
867void __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 Gruenbacherc670a392011-02-21 12:41:39 +0100877 if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) {
Philipp Reisnerb411b362009-09-25 16:07:19 -0700878 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 Gruenbacher841ce242010-12-15 19:31:20 +0100885 if (!expect(sector < nr_sectors))
886 return;
887 if (!expect(esector < nr_sectors))
888 esector = nr_sectors - 1;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700889
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 Reisnerb411b362009-09-25 16:07:19 -0700903 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 Reisnerb411b362009-09-25 16:07:19 -0700910 count = drbd_bm_clear_bits(mdev, sbnr, ebnr);
Lars Ellenberg1d7734a2010-08-11 21:21:50 +0200911 if (count && get_ldev(mdev)) {
Lars Ellenbergc6ea14d2010-11-05 09:23:37 +0100912 drbd_advance_rs_marks(mdev, drbd_bm_total_weight(mdev));
Lars Ellenberg1d7734a2010-08-11 21:21:50 +0200913 spin_lock_irqsave(&mdev->al_lock, flags);
Andreas Gruenbacher81e84652010-12-09 15:03:57 +0100914 drbd_try_clear_on_disk_bm(mdev, sector, count, true);
Lars Ellenberg1d7734a2010-08-11 21:21:50 +0200915 spin_unlock_irqrestore(&mdev->al_lock, flags);
916
Philipp Reisnerb411b362009-09-25 16:07:19 -0700917 /* just wake_up unconditional now, various lc_chaged(),
918 * lc_put() in drbd_try_clear_on_disk_bm(). */
919 wake_up = 1;
Lars Ellenberg1d7734a2010-08-11 21:21:50 +0200920 put_ldev(mdev);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700921 }
Philipp Reisnerb411b362009-09-25 16:07:19 -0700922 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 Ellenberg1816a2b2010-11-11 15:19:07 +0100929 * and at most 1+DRBD_MAX_BIO_SIZE/BM_BLOCK_SIZE bits.
Philipp Reisnerb411b362009-09-25 16:07:19 -0700930 *
931 * called by tl_clear and drbd_send_dblock (==drbd_make_request).
932 * so this can be _any_ process.
933 */
Philipp Reisner73a01a12010-10-27 14:33:00 +0200934int __drbd_set_out_of_sync(struct drbd_conf *mdev, sector_t sector, int size,
Philipp Reisnerb411b362009-09-25 16:07:19 -0700935 const char *file, const unsigned int line)
936{
937 unsigned long sbnr, ebnr, lbnr, flags;
938 sector_t esector, nr_sectors;
Philipp Reisner73a01a12010-10-27 14:33:00 +0200939 unsigned int enr, count = 0;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700940 struct lc_element *e;
941
Andreas Gruenbacherc670a392011-02-21 12:41:39 +0100942 if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) {
Philipp Reisnerb411b362009-09-25 16:07:19 -0700943 dev_err(DEV, "sector: %llus, size: %d\n",
944 (unsigned long long)sector, size);
Philipp Reisner73a01a12010-10-27 14:33:00 +0200945 return 0;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700946 }
947
948 if (!get_ldev(mdev))
Philipp Reisner73a01a12010-10-27 14:33:00 +0200949 return 0; /* no disk, no metadata, no bitmap to set bits in */
Philipp Reisnerb411b362009-09-25 16:07:19 -0700950
951 nr_sectors = drbd_get_capacity(mdev->this_bdev);
952 esector = sector + (size >> 9) - 1;
953
Andreas Gruenbacher841ce242010-12-15 19:31:20 +0100954 if (!expect(sector < nr_sectors))
Philipp Reisnerb411b362009-09-25 16:07:19 -0700955 goto out;
Andreas Gruenbacher841ce242010-12-15 19:31:20 +0100956 if (!expect(esector < nr_sectors))
957 esector = nr_sectors - 1;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700958
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 Reisnerb411b362009-09-25 16:07:19 -0700966 /* 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
977out:
978 put_ldev(mdev);
Philipp Reisner73a01a12010-10-27 14:33:00 +0200979
980 return count;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700981}
982
983static
984struct 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 Ellenberg46a15bc2011-02-21 13:21:01 +01001002 lc_committed(mdev->resync);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001003 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 Ellenberg46a15bc2011-02-21 13:21:01 +01001018 BUG_ON(rs_flags & LC_LOCKED);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001019 }
1020
1021 return bm_ext;
1022}
1023
1024static int _is_in_al(struct drbd_conf *mdev, unsigned int enr)
1025{
Lars Ellenberg46a15bc2011-02-21 13:21:01 +01001026 int rv;
Philipp Reisnerb411b362009-09-25 16:07:19 -07001027
1028 spin_lock_irq(&mdev->al_lock);
Lars Ellenberg46a15bc2011-02-21 13:21:01 +01001029 rv = lc_is_used(mdev->act_log, enr);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001030 spin_unlock_irq(&mdev->al_lock);
1031
Philipp Reisnerb411b362009-09-25 16:07:19 -07001032 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 Ellenberg80a40e42010-08-11 23:28:00 +02001040 * This functions sleeps on al_wait. Returns 0 on success, -EINTR if interrupted.
Philipp Reisnerb411b362009-09-25 16:07:19 -07001041 */
1042int 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 Reisnerf91ab622010-11-09 13:59:41 +01001047 int sa = 200; /* Step aside 200 times, then grab the extent and let app-IO wait.
1048 200 times -> 20 seconds. */
Philipp Reisnerb411b362009-09-25 16:07:19 -07001049
Philipp Reisnerf91ab622010-11-09 13:59:41 +01001050retry:
Philipp Reisnerb411b362009-09-25 16:07:19 -07001051 sig = wait_event_interruptible(mdev->al_wait,
1052 (bm_ext = _bme_get(mdev, enr)));
1053 if (sig)
Lars Ellenberg80a40e42010-08-11 23:28:00 +02001054 return -EINTR;
Philipp Reisnerb411b362009-09-25 16:07:19 -07001055
1056 if (test_bit(BME_LOCKED, &bm_ext->flags))
Lars Ellenberg80a40e42010-08-11 23:28:00 +02001057 return 0;
Philipp Reisnerb411b362009-09-25 16:07:19 -07001058
1059 for (i = 0; i < AL_EXT_PER_BM_SECT; i++) {
1060 sig = wait_event_interruptible(mdev->al_wait,
Philipp Reisnerf91ab622010-11-09 13:59:41 +01001061 !_is_in_al(mdev, enr * AL_EXT_PER_BM_SECT + i) ||
Philipp Reisnerc507f462010-11-22 15:49:17 +01001062 test_bit(BME_PRIORITY, &bm_ext->flags));
Philipp Reisnerf91ab622010-11-09 13:59:41 +01001063
1064 if (sig || (test_bit(BME_PRIORITY, &bm_ext->flags) && sa)) {
Philipp Reisnerb411b362009-09-25 16:07:19 -07001065 spin_lock_irq(&mdev->al_lock);
1066 if (lc_put(mdev->resync, &bm_ext->lce) == 0) {
Philipp Reisnerf91ab622010-11-09 13:59:41 +01001067 bm_ext->flags = 0; /* clears BME_NO_WRITES and eventually BME_PRIORITY */
Philipp Reisnerb411b362009-09-25 16:07:19 -07001068 mdev->resync_locked--;
1069 wake_up(&mdev->al_wait);
1070 }
1071 spin_unlock_irq(&mdev->al_lock);
Philipp Reisnerf91ab622010-11-09 13:59:41 +01001072 if (sig)
1073 return -EINTR;
1074 if (schedule_timeout_interruptible(HZ/10))
1075 return -EINTR;
Philipp Reisnerc507f462010-11-22 15:49:17 +01001076 if (sa && --sa == 0)
1077 dev_warn(DEV,"drbd_rs_begin_io() stepped aside for 20sec."
1078 "Resync stalled?\n");
Philipp Reisnerf91ab622010-11-09 13:59:41 +01001079 goto retry;
Philipp Reisnerb411b362009-09-25 16:07:19 -07001080 }
1081 }
Philipp Reisnerb411b362009-09-25 16:07:19 -07001082 set_bit(BME_LOCKED, &bm_ext->flags);
Lars Ellenberg80a40e42010-08-11 23:28:00 +02001083 return 0;
Philipp Reisnerb411b362009-09-25 16:07:19 -07001084}
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 */
1095int 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 Reisnerb411b362009-09-25 16:07:19 -07001103 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 Reisnerb411b362009-09-25 16:07:19 -07001118 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 Reisnerb411b362009-09-25 16:07:19 -07001145 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 Axboe6a0afdf2009-10-01 09:04:14 +02001151 if (mdev->resync_locked > mdev->resync->nr_elements-3)
Philipp Reisnerb411b362009-09-25 16:07:19 -07001152 goto try_again;
Philipp Reisnerb411b362009-09-25 16:07:19 -07001153 /* 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 Ellenberg46a15bc2011-02-21 13:21:01 +01001161 BUG_ON(rs_flags & LC_LOCKED);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001162 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 Ellenberg46a15bc2011-02-21 13:21:01 +01001167 lc_committed(mdev->resync);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001168 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 }
1176check_al:
Philipp Reisnerb411b362009-09-25 16:07:19 -07001177 for (i = 0; i < AL_EXT_PER_BM_SECT; i++) {
Philipp Reisnerb411b362009-09-25 16:07:19 -07001178 if (lc_is_used(mdev->act_log, al_enr+i))
1179 goto try_again;
1180 }
1181 set_bit(BME_LOCKED, &bm_ext->flags);
1182proceed:
1183 mdev->resync_wenr = LC_FREE;
1184 spin_unlock_irq(&mdev->al_lock);
1185 return 0;
1186
1187try_again:
Philipp Reisnerb411b362009-09-25 16:07:19 -07001188 if (bm_ext)
1189 mdev->resync_wenr = enr;
1190 spin_unlock_irq(&mdev->al_lock);
1191 return -EAGAIN;
1192}
1193
1194void 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 Reisnerb411b362009-09-25 16:07:19 -07001201 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 Reisnere3555d82010-11-07 15:56:29 +01001220 bm_ext->flags = 0; /* clear BME_LOCKED, BME_NO_WRITES and BME_PRIORITY */
Philipp Reisnerb411b362009-09-25 16:07:19 -07001221 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 */
1232void drbd_rs_cancel_all(struct drbd_conf *mdev)
1233{
Philipp Reisnerb411b362009-09-25 16:07:19 -07001234 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 */
1253int 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 Reisnerb411b362009-09-25 16:07:19 -07001259 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 Reisnerb2b163d2010-04-02 08:40:33 +02001265 bm_ext = lc_entry(e, struct bm_extent, lce);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001266 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 */
1303void 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 Gruenbacherc670a392011-02-21 12:41:39 +01001311 if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) {
Philipp Reisnerb411b362009-09-25 16:07:19 -07001312 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 Gruenbacher841ce242010-12-15 19:31:20 +01001319 if (!expect(sector < nr_sectors))
1320 return;
1321 if (!expect(esector < nr_sectors))
1322 esector = nr_sectors - 1;
Philipp Reisnerb411b362009-09-25 16:07:19 -07001323
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 Gruenbacher81e84652010-12-09 15:03:57 +01001350 drbd_try_clear_on_disk_bm(mdev, sector, count, false);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001351 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}