2009-09-26 07:07:19 +08:00
|
|
|
/*
|
|
|
|
drbd_actlog.c
|
|
|
|
|
|
|
|
This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
|
|
|
|
|
|
|
|
Copyright (C) 2003-2008, LINBIT Information Technologies GmbH.
|
|
|
|
Copyright (C) 2003-2008, Philipp Reisner <philipp.reisner@linbit.com>.
|
|
|
|
Copyright (C) 2003-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
|
|
|
|
|
|
|
|
drbd is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
drbd is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with drbd; see the file COPYING. If not, write to
|
|
|
|
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/slab.h>
|
2011-02-21 20:21:03 +08:00
|
|
|
#include <linux/crc32c.h>
|
2009-09-26 07:07:19 +08:00
|
|
|
#include <linux/drbd.h>
|
2011-02-21 20:21:03 +08:00
|
|
|
#include <linux/drbd_limits.h>
|
|
|
|
#include <linux/dynamic_debug.h>
|
2009-09-26 07:07:19 +08:00
|
|
|
#include "drbd_int.h"
|
|
|
|
|
2011-03-31 18:06:48 +08:00
|
|
|
|
|
|
|
enum al_transaction_types {
|
|
|
|
AL_TR_UPDATE = 0,
|
|
|
|
AL_TR_INITIALIZED = 0xffff
|
|
|
|
};
|
2011-02-21 20:21:03 +08:00
|
|
|
/* all fields on disc in big endian */
|
|
|
|
struct __packed al_transaction_on_disk {
|
|
|
|
/* don't we all like magic */
|
|
|
|
__be32 magic;
|
|
|
|
|
|
|
|
/* to identify the most recent transaction block
|
|
|
|
* in the on disk ring buffer */
|
|
|
|
__be32 tr_number;
|
|
|
|
|
|
|
|
/* checksum on the full 4k block, with this field set to 0. */
|
|
|
|
__be32 crc32c;
|
|
|
|
|
|
|
|
/* type of transaction, special transaction types like:
|
2011-03-31 18:06:48 +08:00
|
|
|
* purge-all, set-all-idle, set-all-active, ... to-be-defined
|
|
|
|
* see also enum al_transaction_types */
|
2011-02-21 20:21:03 +08:00
|
|
|
__be16 transaction_type;
|
|
|
|
|
|
|
|
/* we currently allow only a few thousand extents,
|
|
|
|
* so 16bit will be enough for the slot number. */
|
|
|
|
|
|
|
|
/* how many updates in this transaction */
|
|
|
|
__be16 n_updates;
|
|
|
|
|
|
|
|
/* maximum slot number, "al-extents" in drbd.conf speak.
|
|
|
|
* Having this in each transaction should make reconfiguration
|
|
|
|
* of that parameter easier. */
|
|
|
|
__be16 context_size;
|
|
|
|
|
|
|
|
/* slot number the context starts with */
|
|
|
|
__be16 context_start_slot_nr;
|
|
|
|
|
|
|
|
/* Some reserved bytes. Expected usage is a 64bit counter of
|
|
|
|
* sectors-written since device creation, and other data generation tag
|
|
|
|
* supporting usage */
|
|
|
|
__be32 __reserved[4];
|
|
|
|
|
|
|
|
/* --- 36 byte used --- */
|
|
|
|
|
|
|
|
/* Reserve space for up to AL_UPDATES_PER_TRANSACTION changes
|
|
|
|
* in one transaction, then use the remaining byte in the 4k block for
|
|
|
|
* context information. "Flexible" number of updates per transaction
|
|
|
|
* does not help, as we have to account for the case when all update
|
|
|
|
* slots are used anyways, so it would only complicate code without
|
|
|
|
* additional benefit.
|
|
|
|
*/
|
|
|
|
__be16 update_slot_nr[AL_UPDATES_PER_TRANSACTION];
|
|
|
|
|
|
|
|
/* but the extent number is 32bit, which at an extent size of 4 MiB
|
|
|
|
* allows to cover device sizes of up to 2**54 Byte (16 PiB) */
|
|
|
|
__be32 update_extent_nr[AL_UPDATES_PER_TRANSACTION];
|
|
|
|
|
|
|
|
/* --- 420 bytes used (36 + 64*6) --- */
|
|
|
|
|
|
|
|
/* 4096 - 420 = 3676 = 919 * 4 */
|
|
|
|
__be32 context[AL_CONTEXT_PER_TRANSACTION];
|
2009-09-26 07:07:19 +08:00
|
|
|
};
|
|
|
|
|
2014-04-02 05:53:30 +08:00
|
|
|
void *drbd_md_get_buffer(struct drbd_device *device, const char *intent)
|
2011-07-05 21:38:59 +08:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
wait_event(device->misc_wait,
|
2014-04-02 05:53:30 +08:00
|
|
|
(r = atomic_cmpxchg(&device->md_io.in_use, 0, 1)) == 0 ||
|
2011-07-03 19:26:43 +08:00
|
|
|
device->state.disk <= D_FAILED);
|
2011-07-05 21:38:59 +08:00
|
|
|
|
2014-04-02 05:53:30 +08:00
|
|
|
if (r)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
device->md_io.current_use = intent;
|
|
|
|
device->md_io.start_jif = jiffies;
|
|
|
|
device->md_io.submit_jif = device->md_io.start_jif - 1;
|
|
|
|
return page_address(device->md_io.page);
|
2011-07-05 21:38:59 +08:00
|
|
|
}
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
void drbd_md_put_buffer(struct drbd_device *device)
|
2011-07-05 21:38:59 +08:00
|
|
|
{
|
2014-04-02 05:53:30 +08:00
|
|
|
if (atomic_dec_and_test(&device->md_io.in_use))
|
2011-07-03 19:26:43 +08:00
|
|
|
wake_up(&device->misc_wait);
|
2011-07-05 21:38:59 +08:00
|
|
|
}
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
void wait_until_done_or_force_detached(struct drbd_device *device, struct drbd_backing_dev *bdev,
|
2012-02-22 18:51:57 +08:00
|
|
|
unsigned int *done)
|
2011-07-05 21:38:59 +08:00
|
|
|
{
|
2012-02-22 18:51:57 +08:00
|
|
|
long dt;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
dt = rcu_dereference(bdev->disk_conf)->disk_timeout;
|
|
|
|
rcu_read_unlock();
|
|
|
|
dt = dt * HZ / 10;
|
|
|
|
if (dt == 0)
|
|
|
|
dt = MAX_SCHEDULE_TIMEOUT;
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
dt = wait_event_timeout(device->misc_wait,
|
|
|
|
*done || test_bit(FORCE_DETACH, &device->flags), dt);
|
2012-09-27 21:07:11 +08:00
|
|
|
if (dt == 0) {
|
2011-07-03 23:53:52 +08:00
|
|
|
drbd_err(device, "meta-data IO operation timed out\n");
|
2011-07-03 19:26:43 +08:00
|
|
|
drbd_chk_io_error(device, 1, DRBD_FORCE_DETACH);
|
2012-09-27 21:07:11 +08:00
|
|
|
}
|
2011-07-05 21:38:59 +08:00
|
|
|
}
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
static int _drbd_md_sync_page_io(struct drbd_device *device,
|
2009-09-26 07:07:19 +08:00
|
|
|
struct drbd_backing_dev *bdev,
|
2014-04-02 06:24:18 +08:00
|
|
|
sector_t sector, int rw)
|
2009-09-26 07:07:19 +08:00
|
|
|
{
|
|
|
|
struct bio *bio;
|
2014-04-02 06:24:18 +08:00
|
|
|
/* we do all our meta data IO in aligned 4k blocks. */
|
|
|
|
const int size = 4096;
|
2010-12-13 09:20:47 +08:00
|
|
|
int err;
|
2009-09-26 07:07:19 +08:00
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
device->md_io.done = 0;
|
|
|
|
device->md_io.error = -ENODEV;
|
2009-09-26 07:07:19 +08:00
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
if ((rw & WRITE) && !test_bit(MD_NO_FUA, &device->flags))
|
2011-06-28 19:22:48 +08:00
|
|
|
rw |= REQ_FUA | REQ_FLUSH;
|
2014-02-11 15:56:53 +08:00
|
|
|
rw |= REQ_SYNC | REQ_NOIDLE;
|
2009-09-26 07:07:19 +08:00
|
|
|
|
2011-02-24 00:02:01 +08:00
|
|
|
bio = bio_alloc_drbd(GFP_NOIO);
|
2009-09-26 07:07:19 +08:00
|
|
|
bio->bi_bdev = bdev->md_bdev;
|
2013-10-12 06:44:27 +08:00
|
|
|
bio->bi_iter.bi_sector = sector;
|
2010-12-13 09:20:47 +08:00
|
|
|
err = -EIO;
|
2014-04-02 06:24:18 +08:00
|
|
|
if (bio_add_page(bio, device->md_io.page, size, 0) != size)
|
2009-09-26 07:07:19 +08:00
|
|
|
goto out;
|
2014-04-02 05:53:30 +08:00
|
|
|
bio->bi_private = device;
|
2014-09-11 20:29:06 +08:00
|
|
|
bio->bi_end_io = drbd_md_endio;
|
2009-09-26 07:07:19 +08:00
|
|
|
bio->bi_rw = rw;
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
if (!(rw & WRITE) && device->state.disk == D_DISKLESS && device->ldev == NULL)
|
2013-03-20 01:16:47 +08:00
|
|
|
/* special case, drbd_md_read() during drbd_adm_attach(): no get_ldev */
|
|
|
|
;
|
2011-07-03 19:26:43 +08:00
|
|
|
else if (!get_ldev_if_state(device, D_ATTACHING)) {
|
2014-09-11 20:29:06 +08:00
|
|
|
/* Corresponding put_ldev in drbd_md_endio() */
|
2011-07-03 23:53:52 +08:00
|
|
|
drbd_err(device, "ASSERT FAILED: get_ldev_if_state() == 1 in _drbd_md_sync_page_io()\n");
|
2011-07-05 21:38:59 +08:00
|
|
|
err = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
bio_get(bio); /* one bio_put() is in the completion handler */
|
2014-04-02 05:53:30 +08:00
|
|
|
atomic_inc(&device->md_io.in_use); /* drbd_md_put_buffer() is in the completion handler */
|
|
|
|
device->md_io.submit_jif = jiffies;
|
2011-07-03 19:26:43 +08:00
|
|
|
if (drbd_insert_fault(device, (rw & WRITE) ? DRBD_FAULT_MD_WR : DRBD_FAULT_MD_RD))
|
2015-07-20 21:29:37 +08:00
|
|
|
bio_io_error(bio);
|
2009-09-26 07:07:19 +08:00
|
|
|
else
|
|
|
|
submit_bio(rw, bio);
|
2011-07-03 19:26:43 +08:00
|
|
|
wait_until_done_or_force_detached(device, bdev, &device->md_io.done);
|
2015-07-20 21:29:37 +08:00
|
|
|
if (!bio->bi_error)
|
2011-07-03 19:26:43 +08:00
|
|
|
err = device->md_io.error;
|
2009-09-26 07:07:19 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
bio_put(bio);
|
2010-12-13 09:20:47 +08:00
|
|
|
return err;
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
int drbd_md_sync_page_io(struct drbd_device *device, struct drbd_backing_dev *bdev,
|
2009-09-26 07:07:19 +08:00
|
|
|
sector_t sector, int rw)
|
|
|
|
{
|
2010-12-13 09:25:41 +08:00
|
|
|
int err;
|
2014-04-02 05:53:30 +08:00
|
|
|
D_ASSERT(device, atomic_read(&device->md_io.in_use) == 1);
|
2009-09-26 07:07:19 +08:00
|
|
|
|
|
|
|
BUG_ON(!bdev->md_bdev);
|
|
|
|
|
2014-04-29 00:43:28 +08:00
|
|
|
dynamic_drbd_dbg(device, "meta_data io: %s [%d]:%s(,%llus,%s) %pS\n",
|
2011-02-21 20:21:03 +08:00
|
|
|
current->comm, current->pid, __func__,
|
2013-03-20 01:16:47 +08:00
|
|
|
(unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ",
|
|
|
|
(void*)_RET_IP_ );
|
2009-09-26 07:07:19 +08:00
|
|
|
|
|
|
|
if (sector < drbd_md_first_sector(bdev) ||
|
2011-02-21 20:21:03 +08:00
|
|
|
sector + 7 > drbd_md_last_sector(bdev))
|
2011-07-03 23:53:52 +08:00
|
|
|
drbd_alert(device, "%s [%d]:%s(,%llus,%s) out of range md access!\n",
|
2009-09-26 07:07:19 +08:00
|
|
|
current->comm, current->pid, __func__,
|
|
|
|
(unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ");
|
|
|
|
|
2014-04-02 06:24:18 +08:00
|
|
|
err = _drbd_md_sync_page_io(device, bdev, sector, rw);
|
2010-12-13 09:25:41 +08:00
|
|
|
if (err) {
|
2011-07-03 23:53:52 +08:00
|
|
|
drbd_err(device, "drbd_md_sync_page_io(,%llus,%s) failed with error %d\n",
|
2011-08-19 19:47:31 +08:00
|
|
|
(unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ", err);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
2010-12-13 09:25:41 +08:00
|
|
|
return err;
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
static struct bm_extent *find_active_resync_extent(struct drbd_device *device, unsigned int enr)
|
2009-09-26 07:07:19 +08:00
|
|
|
{
|
|
|
|
struct lc_element *tmp;
|
2011-07-03 19:26:43 +08:00
|
|
|
tmp = lc_find(device->resync, enr/AL_EXT_PER_BM_SECT);
|
2009-09-26 07:07:19 +08:00
|
|
|
if (unlikely(tmp != NULL)) {
|
|
|
|
struct bm_extent *bm_ext = lc_entry(tmp, struct bm_extent, lce);
|
2013-03-20 01:16:53 +08:00
|
|
|
if (test_bit(BME_NO_WRITES, &bm_ext->flags))
|
|
|
|
return bm_ext;
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
2013-03-20 01:16:53 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
static struct lc_element *_al_get(struct drbd_device *device, unsigned int enr, bool nonblock)
|
2013-03-20 01:16:53 +08:00
|
|
|
{
|
|
|
|
struct lc_element *al_ext;
|
|
|
|
struct bm_extent *bm_ext;
|
|
|
|
int wake;
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_lock_irq(&device->al_lock);
|
|
|
|
bm_ext = find_active_resync_extent(device, enr);
|
2013-03-20 01:16:53 +08:00
|
|
|
if (bm_ext) {
|
|
|
|
wake = !test_and_set_bit(BME_PRIORITY, &bm_ext->flags);
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_unlock_irq(&device->al_lock);
|
2013-03-20 01:16:53 +08:00
|
|
|
if (wake)
|
2011-07-03 19:26:43 +08:00
|
|
|
wake_up(&device->al_wait);
|
2013-03-20 01:16:53 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (nonblock)
|
2011-07-03 19:26:43 +08:00
|
|
|
al_ext = lc_try_get(device->act_log, enr);
|
2013-03-20 01:16:53 +08:00
|
|
|
else
|
2011-07-03 19:26:43 +08:00
|
|
|
al_ext = lc_get(device->act_log, enr);
|
|
|
|
spin_unlock_irq(&device->al_lock);
|
2009-09-26 07:07:19 +08:00
|
|
|
return al_ext;
|
|
|
|
}
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
bool drbd_al_begin_io_fastpath(struct drbd_device *device, struct drbd_interval *i)
|
2009-09-26 07:07:19 +08:00
|
|
|
{
|
2011-03-31 22:00:51 +08:00
|
|
|
/* for bios crossing activity log extent boundaries,
|
|
|
|
* we may need to activate two extents in one go */
|
2011-04-01 16:38:30 +08:00
|
|
|
unsigned first = i->sector >> (AL_EXTENT_SHIFT-9);
|
2012-07-30 15:00:54 +08:00
|
|
|
unsigned last = i->size == 0 ? first : (i->sector + (i->size >> 9) - 1) >> (AL_EXTENT_SHIFT-9);
|
2011-05-03 22:49:20 +08:00
|
|
|
|
2011-06-27 22:23:33 +08:00
|
|
|
D_ASSERT(device, (unsigned)(last - first) <= 1);
|
|
|
|
D_ASSERT(device, atomic_read(&device->local_cnt) > 0);
|
2013-03-20 01:16:52 +08:00
|
|
|
|
|
|
|
/* FIXME figure out a fast path for bios crossing AL extent boundaries */
|
|
|
|
if (first != last)
|
|
|
|
return false;
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
return _al_get(device, first, true);
|
2013-03-20 01:16:52 +08:00
|
|
|
}
|
2013-03-20 01:16:48 +08:00
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
bool drbd_al_begin_io_prepare(struct drbd_device *device, struct drbd_interval *i)
|
2013-03-20 01:16:52 +08:00
|
|
|
{
|
|
|
|
/* for bios crossing activity log extent boundaries,
|
|
|
|
* we may need to activate two extents in one go */
|
|
|
|
unsigned first = i->sector >> (AL_EXTENT_SHIFT-9);
|
|
|
|
unsigned last = i->size == 0 ? first : (i->sector + (i->size >> 9) - 1) >> (AL_EXTENT_SHIFT-9);
|
|
|
|
unsigned enr;
|
|
|
|
bool need_transaction = false;
|
2009-09-26 07:07:19 +08:00
|
|
|
|
2011-06-27 22:23:33 +08:00
|
|
|
D_ASSERT(device, first <= last);
|
|
|
|
D_ASSERT(device, atomic_read(&device->local_cnt) > 0);
|
2009-09-26 07:07:19 +08:00
|
|
|
|
2013-03-20 01:16:49 +08:00
|
|
|
for (enr = first; enr <= last; enr++) {
|
|
|
|
struct lc_element *al_ext;
|
2011-07-03 19:26:43 +08:00
|
|
|
wait_event(device->al_wait,
|
|
|
|
(al_ext = _al_get(device, enr, false)) != NULL);
|
2013-03-20 01:16:49 +08:00
|
|
|
if (al_ext->lc_number != enr)
|
|
|
|
need_transaction = true;
|
|
|
|
}
|
2013-03-20 01:16:52 +08:00
|
|
|
return need_transaction;
|
|
|
|
}
|
|
|
|
|
2015-06-03 19:13:34 +08:00
|
|
|
#if (PAGE_SHIFT + 3) < (AL_EXTENT_SHIFT - BM_BLOCK_SHIFT)
|
|
|
|
/* Currently BM_BLOCK_SHIFT, BM_EXT_SHIFT and AL_EXTENT_SHIFT
|
|
|
|
* are still coupled, or assume too much about their relation.
|
|
|
|
* Code below will not work if this is violated.
|
|
|
|
* Will be cleaned up with some followup patch.
|
|
|
|
*/
|
|
|
|
# error FIXME
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static unsigned int al_extent_to_bm_page(unsigned int al_enr)
|
|
|
|
{
|
|
|
|
return al_enr >>
|
|
|
|
/* bit to page */
|
|
|
|
((PAGE_SHIFT + 3) -
|
|
|
|
/* al extent number to bit */
|
|
|
|
(AL_EXTENT_SHIFT - BM_BLOCK_SHIFT));
|
|
|
|
}
|
|
|
|
|
|
|
|
static sector_t al_tr_number_to_on_disk_sector(struct drbd_device *device)
|
|
|
|
{
|
|
|
|
const unsigned int stripes = device->ldev->md.al_stripes;
|
|
|
|
const unsigned int stripe_size_4kB = device->ldev->md.al_stripe_size_4k;
|
|
|
|
|
|
|
|
/* transaction number, modulo on-disk ring buffer wrap around */
|
|
|
|
unsigned int t = device->al_tr_number % (device->ldev->md.al_size_4k);
|
|
|
|
|
|
|
|
/* ... to aligned 4k on disk block */
|
|
|
|
t = ((t % stripes) * stripe_size_4kB) + t/stripes;
|
|
|
|
|
|
|
|
/* ... to 512 byte sector in activity log */
|
|
|
|
t *= 8;
|
|
|
|
|
|
|
|
/* ... plus offset to the on disk position */
|
|
|
|
return device->ldev->md.md_offset + device->ldev->md.al_offset + t;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __al_write_transaction(struct drbd_device *device, struct al_transaction_on_disk *buffer)
|
|
|
|
{
|
|
|
|
struct lc_element *e;
|
|
|
|
sector_t sector;
|
|
|
|
int i, mx;
|
|
|
|
unsigned extent_nr;
|
|
|
|
unsigned crc = 0;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
memset(buffer, 0, sizeof(*buffer));
|
|
|
|
buffer->magic = cpu_to_be32(DRBD_AL_MAGIC);
|
|
|
|
buffer->tr_number = cpu_to_be32(device->al_tr_number);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
/* Even though no one can start to change this list
|
|
|
|
* once we set the LC_LOCKED -- from drbd_al_begin_io(),
|
|
|
|
* lc_try_lock_for_transaction() --, someone may still
|
|
|
|
* be in the process of changing it. */
|
|
|
|
spin_lock_irq(&device->al_lock);
|
|
|
|
list_for_each_entry(e, &device->act_log->to_be_changed, list) {
|
|
|
|
if (i == AL_UPDATES_PER_TRANSACTION) {
|
|
|
|
i++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buffer->update_slot_nr[i] = cpu_to_be16(e->lc_index);
|
|
|
|
buffer->update_extent_nr[i] = cpu_to_be32(e->lc_new_number);
|
|
|
|
if (e->lc_number != LC_FREE)
|
|
|
|
drbd_bm_mark_for_writeout(device,
|
|
|
|
al_extent_to_bm_page(e->lc_number));
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
spin_unlock_irq(&device->al_lock);
|
|
|
|
BUG_ON(i > AL_UPDATES_PER_TRANSACTION);
|
|
|
|
|
|
|
|
buffer->n_updates = cpu_to_be16(i);
|
|
|
|
for ( ; i < AL_UPDATES_PER_TRANSACTION; i++) {
|
|
|
|
buffer->update_slot_nr[i] = cpu_to_be16(-1);
|
|
|
|
buffer->update_extent_nr[i] = cpu_to_be32(LC_FREE);
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer->context_size = cpu_to_be16(device->act_log->nr_elements);
|
|
|
|
buffer->context_start_slot_nr = cpu_to_be16(device->al_tr_cycle);
|
|
|
|
|
|
|
|
mx = min_t(int, AL_CONTEXT_PER_TRANSACTION,
|
|
|
|
device->act_log->nr_elements - device->al_tr_cycle);
|
|
|
|
for (i = 0; i < mx; i++) {
|
|
|
|
unsigned idx = device->al_tr_cycle + i;
|
|
|
|
extent_nr = lc_element_by_index(device->act_log, idx)->lc_number;
|
|
|
|
buffer->context[i] = cpu_to_be32(extent_nr);
|
|
|
|
}
|
|
|
|
for (; i < AL_CONTEXT_PER_TRANSACTION; i++)
|
|
|
|
buffer->context[i] = cpu_to_be32(LC_FREE);
|
|
|
|
|
|
|
|
device->al_tr_cycle += AL_CONTEXT_PER_TRANSACTION;
|
|
|
|
if (device->al_tr_cycle >= device->act_log->nr_elements)
|
|
|
|
device->al_tr_cycle = 0;
|
|
|
|
|
|
|
|
sector = al_tr_number_to_on_disk_sector(device);
|
|
|
|
|
|
|
|
crc = crc32c(0, buffer, 4096);
|
|
|
|
buffer->crc32c = cpu_to_be32(crc);
|
|
|
|
|
|
|
|
if (drbd_bm_write_hinted(device))
|
|
|
|
err = -EIO;
|
|
|
|
else {
|
|
|
|
bool write_al_updates;
|
|
|
|
rcu_read_lock();
|
|
|
|
write_al_updates = rcu_dereference(device->ldev->disk_conf)->al_updates;
|
|
|
|
rcu_read_unlock();
|
|
|
|
if (write_al_updates) {
|
|
|
|
if (drbd_md_sync_page_io(device, device->ldev, sector, WRITE)) {
|
|
|
|
err = -EIO;
|
|
|
|
drbd_chk_io_error(device, 1, DRBD_META_IO_ERROR);
|
|
|
|
} else {
|
|
|
|
device->al_tr_number++;
|
|
|
|
device->al_writ_cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int al_write_transaction(struct drbd_device *device)
|
|
|
|
{
|
|
|
|
struct al_transaction_on_disk *buffer;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (!get_ldev(device)) {
|
|
|
|
drbd_err(device, "disk is %s, cannot start al transaction\n",
|
|
|
|
drbd_disk_str(device->state.disk));
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The bitmap write may have failed, causing a state change. */
|
|
|
|
if (device->state.disk < D_INCONSISTENT) {
|
|
|
|
drbd_err(device,
|
|
|
|
"disk is %s, cannot write al transaction\n",
|
|
|
|
drbd_disk_str(device->state.disk));
|
|
|
|
put_ldev(device);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* protects md_io_buffer, al_tr_cycle, ... */
|
|
|
|
buffer = drbd_md_get_buffer(device, __func__);
|
|
|
|
if (!buffer) {
|
|
|
|
drbd_err(device, "disk failed while waiting for md_io buffer\n");
|
|
|
|
put_ldev(device);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = __al_write_transaction(device, buffer);
|
|
|
|
|
|
|
|
drbd_md_put_buffer(device);
|
|
|
|
put_ldev(device);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-03-20 01:16:52 +08:00
|
|
|
|
2014-02-11 18:15:36 +08:00
|
|
|
void drbd_al_begin_io_commit(struct drbd_device *device)
|
2013-03-20 01:16:52 +08:00
|
|
|
{
|
|
|
|
bool locked = false;
|
2013-03-20 01:16:49 +08:00
|
|
|
|
2011-05-03 22:49:20 +08:00
|
|
|
/* Serialize multiple transactions.
|
|
|
|
* This uses test_and_set_bit, memory barrier is implicit.
|
|
|
|
*/
|
2011-07-03 19:26:43 +08:00
|
|
|
wait_event(device->al_wait,
|
|
|
|
device->act_log->pending_changes == 0 ||
|
|
|
|
(locked = lc_try_lock_for_transaction(device->act_log)));
|
2011-05-03 22:49:20 +08:00
|
|
|
|
|
|
|
if (locked) {
|
2011-02-21 20:21:03 +08:00
|
|
|
/* Double check: it may have been committed by someone else,
|
|
|
|
* while we have been waiting for the lock. */
|
2011-07-03 19:26:43 +08:00
|
|
|
if (device->act_log->pending_changes) {
|
2012-02-21 04:53:28 +08:00
|
|
|
bool write_al_updates;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2011-07-03 19:26:43 +08:00
|
|
|
write_al_updates = rcu_dereference(device->ldev->disk_conf)->al_updates;
|
2012-02-21 04:53:28 +08:00
|
|
|
rcu_read_unlock();
|
|
|
|
|
2013-03-20 01:16:52 +08:00
|
|
|
if (write_al_updates)
|
2014-02-11 18:15:36 +08:00
|
|
|
al_write_transaction(device);
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_lock_irq(&device->al_lock);
|
2011-02-21 20:21:03 +08:00
|
|
|
/* FIXME
|
2011-07-15 23:19:02 +08:00
|
|
|
if (err)
|
2011-02-21 20:21:03 +08:00
|
|
|
we need an "lc_cancel" here;
|
|
|
|
*/
|
2011-07-03 19:26:43 +08:00
|
|
|
lc_committed(device->act_log);
|
|
|
|
spin_unlock_irq(&device->al_lock);
|
2011-02-21 20:21:03 +08:00
|
|
|
}
|
2011-07-03 19:26:43 +08:00
|
|
|
lc_unlock(device->act_log);
|
|
|
|
wake_up(&device->al_wait);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-20 01:16:52 +08:00
|
|
|
/*
|
|
|
|
* @delegate: delegate activity log I/O to the worker thread
|
|
|
|
*/
|
2014-02-11 18:15:36 +08:00
|
|
|
void drbd_al_begin_io(struct drbd_device *device, struct drbd_interval *i)
|
2013-03-20 01:16:52 +08:00
|
|
|
{
|
2011-07-03 19:26:43 +08:00
|
|
|
if (drbd_al_begin_io_prepare(device, i))
|
2014-02-11 18:15:36 +08:00
|
|
|
drbd_al_begin_io_commit(device);
|
2013-03-20 01:16:52 +08:00
|
|
|
}
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
int drbd_al_begin_io_nonblock(struct drbd_device *device, struct drbd_interval *i)
|
2013-03-20 01:16:56 +08:00
|
|
|
{
|
2011-07-03 19:26:43 +08:00
|
|
|
struct lru_cache *al = device->act_log;
|
2013-03-20 01:16:56 +08:00
|
|
|
/* for bios crossing activity log extent boundaries,
|
|
|
|
* we may need to activate two extents in one go */
|
|
|
|
unsigned first = i->sector >> (AL_EXTENT_SHIFT-9);
|
|
|
|
unsigned last = i->size == 0 ? first : (i->sector + (i->size >> 9) - 1) >> (AL_EXTENT_SHIFT-9);
|
|
|
|
unsigned nr_al_extents;
|
|
|
|
unsigned available_update_slots;
|
|
|
|
unsigned enr;
|
|
|
|
|
2011-06-27 22:23:33 +08:00
|
|
|
D_ASSERT(device, first <= last);
|
2013-03-20 01:16:56 +08:00
|
|
|
|
|
|
|
nr_al_extents = 1 + last - first; /* worst case: all touched extends are cold. */
|
|
|
|
available_update_slots = min(al->nr_elements - al->used,
|
|
|
|
al->max_pending_changes - al->pending_changes);
|
|
|
|
|
|
|
|
/* We want all necessary updates for a given request within the same transaction
|
|
|
|
* We could first check how many updates are *actually* needed,
|
|
|
|
* and use that instead of the worst-case nr_al_extents */
|
2014-05-08 04:41:28 +08:00
|
|
|
if (available_update_slots < nr_al_extents) {
|
|
|
|
/* Too many activity log extents are currently "hot".
|
|
|
|
*
|
|
|
|
* If we have accumulated pending changes already,
|
|
|
|
* we made progress.
|
|
|
|
*
|
|
|
|
* If we cannot get even a single pending change through,
|
|
|
|
* stop the fast path until we made some progress,
|
|
|
|
* or requests to "cold" extents could be starved. */
|
|
|
|
if (!al->pending_changes)
|
|
|
|
__set_bit(__LC_STARVING, &device->act_log->flags);
|
|
|
|
return -ENOBUFS;
|
|
|
|
}
|
2013-03-20 01:16:56 +08:00
|
|
|
|
|
|
|
/* Is resync active in this area? */
|
|
|
|
for (enr = first; enr <= last; enr++) {
|
|
|
|
struct lc_element *tmp;
|
2011-07-03 19:26:43 +08:00
|
|
|
tmp = lc_find(device->resync, enr/AL_EXT_PER_BM_SECT);
|
2013-03-20 01:16:56 +08:00
|
|
|
if (unlikely(tmp != NULL)) {
|
|
|
|
struct bm_extent *bm_ext = lc_entry(tmp, struct bm_extent, lce);
|
|
|
|
if (test_bit(BME_NO_WRITES, &bm_ext->flags)) {
|
2013-03-27 21:08:49 +08:00
|
|
|
if (!test_and_set_bit(BME_PRIORITY, &bm_ext->flags))
|
2013-03-20 01:16:56 +08:00
|
|
|
return -EBUSY;
|
|
|
|
return -EWOULDBLOCK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Checkout the refcounts.
|
|
|
|
* Given that we checked for available elements and update slots above,
|
|
|
|
* this has to be successful. */
|
|
|
|
for (enr = first; enr <= last; enr++) {
|
|
|
|
struct lc_element *al_ext;
|
2011-07-03 19:26:43 +08:00
|
|
|
al_ext = lc_get_cumulative(device->act_log, enr);
|
2013-03-20 01:16:56 +08:00
|
|
|
if (!al_ext)
|
2011-07-03 23:53:52 +08:00
|
|
|
drbd_info(device, "LOGIC BUG for enr=%u\n", enr);
|
2013-03-20 01:16:56 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
void drbd_al_complete_io(struct drbd_device *device, struct drbd_interval *i)
|
2009-09-26 07:07:19 +08:00
|
|
|
{
|
2011-04-01 16:38:30 +08:00
|
|
|
/* for bios crossing activity log extent boundaries,
|
|
|
|
* we may need to activate two extents in one go */
|
|
|
|
unsigned first = i->sector >> (AL_EXTENT_SHIFT-9);
|
2012-07-30 15:00:54 +08:00
|
|
|
unsigned last = i->size == 0 ? first : (i->sector + (i->size >> 9) - 1) >> (AL_EXTENT_SHIFT-9);
|
2011-04-01 16:38:30 +08:00
|
|
|
unsigned enr;
|
2009-09-26 07:07:19 +08:00
|
|
|
struct lc_element *extent;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2011-06-27 22:23:33 +08:00
|
|
|
D_ASSERT(device, first <= last);
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_lock_irqsave(&device->al_lock, flags);
|
2009-09-26 07:07:19 +08:00
|
|
|
|
2011-04-01 16:38:30 +08:00
|
|
|
for (enr = first; enr <= last; enr++) {
|
2011-07-03 19:26:43 +08:00
|
|
|
extent = lc_find(device->act_log, enr);
|
2011-04-01 16:38:30 +08:00
|
|
|
if (!extent) {
|
2011-07-03 23:53:52 +08:00
|
|
|
drbd_err(device, "al_complete_io() called on inactive extent %u\n", enr);
|
2011-04-01 16:38:30 +08:00
|
|
|
continue;
|
|
|
|
}
|
2011-07-03 19:26:43 +08:00
|
|
|
lc_put(device->act_log, extent);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_unlock_irqrestore(&device->al_lock, flags);
|
|
|
|
wake_up(&device->al_wait);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
static int _try_lc_del(struct drbd_device *device, struct lc_element *al_ext)
|
2009-09-26 07:07:19 +08:00
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_lock_irq(&device->al_lock);
|
2009-09-26 07:07:19 +08:00
|
|
|
rv = (al_ext->refcnt == 0);
|
|
|
|
if (likely(rv))
|
2011-07-03 19:26:43 +08:00
|
|
|
lc_del(device->act_log, al_ext);
|
|
|
|
spin_unlock_irq(&device->al_lock);
|
2009-09-26 07:07:19 +08:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drbd_al_shrink() - Removes all active extents form the activity log
|
2011-07-03 19:26:43 +08:00
|
|
|
* @device: DRBD device.
|
2009-09-26 07:07:19 +08:00
|
|
|
*
|
|
|
|
* Removes all active extents form the activity log, waiting until
|
|
|
|
* the reference count of each entry dropped to 0 first, of course.
|
|
|
|
*
|
2011-07-03 19:26:43 +08:00
|
|
|
* You need to lock device->act_log with lc_try_lock() / lc_unlock()
|
2009-09-26 07:07:19 +08:00
|
|
|
*/
|
2011-07-03 19:26:43 +08:00
|
|
|
void drbd_al_shrink(struct drbd_device *device)
|
2009-09-26 07:07:19 +08:00
|
|
|
{
|
|
|
|
struct lc_element *al_ext;
|
|
|
|
int i;
|
|
|
|
|
2011-06-27 22:23:33 +08:00
|
|
|
D_ASSERT(device, test_bit(__LC_LOCKED, &device->act_log->flags));
|
2009-09-26 07:07:19 +08:00
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
for (i = 0; i < device->act_log->nr_elements; i++) {
|
|
|
|
al_ext = lc_element_by_index(device->act_log, i);
|
2009-09-26 07:07:19 +08:00
|
|
|
if (al_ext->lc_number == LC_FREE)
|
|
|
|
continue;
|
2011-07-03 19:26:43 +08:00
|
|
|
wait_event(device->al_wait, _try_lc_del(device, al_ext));
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
wake_up(&device->al_wait);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
|
drbd: avoid potential deadlock during handshake
During handshake communication, we also reconsider our device size,
using drbd_determine_dev_size(). Just in case we need to change the
offsets or layout of our on-disk metadata, we lock out application
and other meta data IO, and wait for the activity log to be "idle"
(no more referenced extents).
If this handshake happens just after a connection loss, with a fencing
policy of "resource-and-stonith", we have frozen IO.
If, additionally, the activity log was "starving" (too many incoming
random writes at that point in time), it won't become idle, ever,
because of the frozen IO, and this would be a lockup of the receiver
thread, and consquentially of DRBD.
Previous logic (re-)initialized with a special "empty" transaction
block, which required the activity log to fully drain first.
Instead, write out some standard activity log transactions.
Using lc_try_lock_for_transaction() instead of lc_try_lock() does not
care about pending activity log references, avoiding the potential
deadlock.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-08 21:18:45 +08:00
|
|
|
int drbd_al_initialize(struct drbd_device *device, void *buffer)
|
2013-06-25 22:50:08 +08:00
|
|
|
{
|
|
|
|
struct al_transaction_on_disk *al = buffer;
|
2011-07-03 19:26:43 +08:00
|
|
|
struct drbd_md *md = &device->ldev->md;
|
2013-06-25 22:50:08 +08:00
|
|
|
int al_size_4k = md->al_stripes * md->al_stripe_size_4k;
|
|
|
|
int i;
|
|
|
|
|
drbd: avoid potential deadlock during handshake
During handshake communication, we also reconsider our device size,
using drbd_determine_dev_size(). Just in case we need to change the
offsets or layout of our on-disk metadata, we lock out application
and other meta data IO, and wait for the activity log to be "idle"
(no more referenced extents).
If this handshake happens just after a connection loss, with a fencing
policy of "resource-and-stonith", we have frozen IO.
If, additionally, the activity log was "starving" (too many incoming
random writes at that point in time), it won't become idle, ever,
because of the frozen IO, and this would be a lockup of the receiver
thread, and consquentially of DRBD.
Previous logic (re-)initialized with a special "empty" transaction
block, which required the activity log to fully drain first.
Instead, write out some standard activity log transactions.
Using lc_try_lock_for_transaction() instead of lc_try_lock() does not
care about pending activity log references, avoiding the potential
deadlock.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-08 21:18:45 +08:00
|
|
|
__al_write_transaction(device, al);
|
|
|
|
/* There may or may not have been a pending transaction. */
|
|
|
|
spin_lock_irq(&device->al_lock);
|
|
|
|
lc_committed(device->act_log);
|
|
|
|
spin_unlock_irq(&device->al_lock);
|
2013-06-25 22:50:08 +08:00
|
|
|
|
drbd: avoid potential deadlock during handshake
During handshake communication, we also reconsider our device size,
using drbd_determine_dev_size(). Just in case we need to change the
offsets or layout of our on-disk metadata, we lock out application
and other meta data IO, and wait for the activity log to be "idle"
(no more referenced extents).
If this handshake happens just after a connection loss, with a fencing
policy of "resource-and-stonith", we have frozen IO.
If, additionally, the activity log was "starving" (too many incoming
random writes at that point in time), it won't become idle, ever,
because of the frozen IO, and this would be a lockup of the receiver
thread, and consquentially of DRBD.
Previous logic (re-)initialized with a special "empty" transaction
block, which required the activity log to fully drain first.
Instead, write out some standard activity log transactions.
Using lc_try_lock_for_transaction() instead of lc_try_lock() does not
care about pending activity log references, avoiding the potential
deadlock.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-08 21:18:45 +08:00
|
|
|
/* The rest of the transactions will have an empty "updates" list, and
|
|
|
|
* are written out only to provide the context, and to initialize the
|
|
|
|
* on-disk ring buffer. */
|
|
|
|
for (i = 1; i < al_size_4k; i++) {
|
|
|
|
int err = __al_write_transaction(device, al);
|
2013-06-25 22:50:08 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
static const char *drbd_change_sync_fname[] = {
|
|
|
|
[RECORD_RS_FAILED] = "drbd_rs_failed_io",
|
|
|
|
[SET_IN_SYNC] = "drbd_set_in_sync",
|
|
|
|
[SET_OUT_OF_SYNC] = "drbd_set_out_of_sync"
|
|
|
|
};
|
|
|
|
|
2009-09-26 07:07:19 +08:00
|
|
|
/* ATTENTION. The AL's extents are 4MB each, while the extents in the
|
|
|
|
* resync LRU-cache are 16MB each.
|
|
|
|
* The caller of this function has to hold an get_ldev() reference.
|
|
|
|
*
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
* Adjusts the caching members ->rs_left (success) or ->rs_failed (!success),
|
|
|
|
* potentially pulling in (and recounting the corresponding bits)
|
|
|
|
* this resync extent into the resync extent lru cache.
|
|
|
|
*
|
|
|
|
* Returns whether all bits have been cleared for this resync extent,
|
|
|
|
* precisely: (rs_left <= rs_failed)
|
|
|
|
*
|
2009-09-26 07:07:19 +08:00
|
|
|
* TODO will be obsoleted once we have a caching lru of the on disk bitmap
|
|
|
|
*/
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
static bool update_rs_extent(struct drbd_device *device,
|
|
|
|
unsigned int enr, int count,
|
|
|
|
enum update_sync_bits_mode mode)
|
2009-09-26 07:07:19 +08:00
|
|
|
{
|
|
|
|
struct lc_element *e;
|
|
|
|
|
2011-06-27 22:23:33 +08:00
|
|
|
D_ASSERT(device, atomic_read(&device->local_cnt));
|
2009-09-26 07:07:19 +08:00
|
|
|
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
/* When setting out-of-sync bits,
|
|
|
|
* we don't need it cached (lc_find).
|
|
|
|
* But if it is present in the cache,
|
|
|
|
* we should update the cached bit count.
|
|
|
|
* Otherwise, that extent should be in the resync extent lru cache
|
|
|
|
* already -- or we want to pull it in if necessary -- (lc_get),
|
|
|
|
* then update and check rs_left and rs_failed. */
|
|
|
|
if (mode == SET_OUT_OF_SYNC)
|
|
|
|
e = lc_find(device->resync, enr);
|
|
|
|
else
|
|
|
|
e = lc_get(device->resync, enr);
|
2009-09-26 07:07:19 +08:00
|
|
|
if (e) {
|
|
|
|
struct bm_extent *ext = lc_entry(e, struct bm_extent, lce);
|
|
|
|
if (ext->lce.lc_number == enr) {
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
if (mode == SET_IN_SYNC)
|
2009-09-26 07:07:19 +08:00
|
|
|
ext->rs_left -= count;
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
else if (mode == SET_OUT_OF_SYNC)
|
|
|
|
ext->rs_left += count;
|
2009-09-26 07:07:19 +08:00
|
|
|
else
|
|
|
|
ext->rs_failed += count;
|
|
|
|
if (ext->rs_left < ext->rs_failed) {
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
drbd_warn(device, "BAD! enr=%u rs_left=%d "
|
2011-11-17 17:11:47 +08:00
|
|
|
"rs_failed=%d count=%d cstate=%s\n",
|
2009-09-26 07:07:19 +08:00
|
|
|
ext->lce.lc_number, ext->rs_left,
|
2011-11-17 17:11:47 +08:00
|
|
|
ext->rs_failed, count,
|
2011-07-03 19:26:43 +08:00
|
|
|
drbd_conn_str(device->state.conn));
|
2011-11-17 17:11:47 +08:00
|
|
|
|
|
|
|
/* We don't expect to be able to clear more bits
|
|
|
|
* than have been set when we originally counted
|
|
|
|
* the set bits to cache that value in ext->rs_left.
|
|
|
|
* Whatever the reason (disconnect during resync,
|
|
|
|
* delayed local completion of an application write),
|
|
|
|
* try to fix it up by recounting here. */
|
2011-07-03 19:26:43 +08:00
|
|
|
ext->rs_left = drbd_bm_e_weight(device, enr);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Normally this element should be in the cache,
|
|
|
|
* since drbd_rs_begin_io() pulled it already in.
|
|
|
|
*
|
|
|
|
* But maybe an application write finished, and we set
|
|
|
|
* something outside the resync lru_cache in sync.
|
|
|
|
*/
|
2011-07-03 19:26:43 +08:00
|
|
|
int rs_left = drbd_bm_e_weight(device, enr);
|
2009-09-26 07:07:19 +08:00
|
|
|
if (ext->flags != 0) {
|
2011-07-03 23:53:52 +08:00
|
|
|
drbd_warn(device, "changing resync lce: %d[%u;%02lx]"
|
2009-09-26 07:07:19 +08:00
|
|
|
" -> %d[%u;00]\n",
|
|
|
|
ext->lce.lc_number, ext->rs_left,
|
|
|
|
ext->flags, enr, rs_left);
|
|
|
|
ext->flags = 0;
|
|
|
|
}
|
|
|
|
if (ext->rs_failed) {
|
2011-07-03 23:53:52 +08:00
|
|
|
drbd_warn(device, "Kicking resync_lru element enr=%u "
|
2009-09-26 07:07:19 +08:00
|
|
|
"out with rs_failed=%d\n",
|
|
|
|
ext->lce.lc_number, ext->rs_failed);
|
|
|
|
}
|
|
|
|
ext->rs_left = rs_left;
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
ext->rs_failed = (mode == RECORD_RS_FAILED) ? count : 0;
|
2011-02-21 20:21:01 +08:00
|
|
|
/* we don't keep a persistent log of the resync lru,
|
|
|
|
* we can commit any change right away. */
|
2011-07-03 19:26:43 +08:00
|
|
|
lc_committed(device->resync);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
if (mode != SET_OUT_OF_SYNC)
|
|
|
|
lc_put(device->resync, &ext->lce);
|
2009-09-26 07:07:19 +08:00
|
|
|
/* no race, we are within the al_lock! */
|
|
|
|
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
if (ext->rs_left <= ext->rs_failed) {
|
2009-09-26 07:07:19 +08:00
|
|
|
ext->rs_failed = 0;
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
return true;
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
} else if (mode != SET_OUT_OF_SYNC) {
|
|
|
|
/* be quiet if lc_find() did not find it. */
|
2011-07-03 23:53:52 +08:00
|
|
|
drbd_err(device, "lc_get() failed! locked=%d/%d flags=%lu\n",
|
2011-07-03 19:26:43 +08:00
|
|
|
device->resync_locked,
|
|
|
|
device->resync->nr_elements,
|
|
|
|
device->resync->flags);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
return false;
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
void drbd_advance_rs_marks(struct drbd_device *device, unsigned long still_to_go)
|
2010-11-05 16:23:37 +08:00
|
|
|
{
|
|
|
|
unsigned long now = jiffies;
|
2011-07-03 19:26:43 +08:00
|
|
|
unsigned long last = device->rs_mark_time[device->rs_last_mark];
|
|
|
|
int next = (device->rs_last_mark + 1) % DRBD_SYNC_MARKS;
|
2010-11-05 16:23:37 +08:00
|
|
|
if (time_after_eq(now, last + DRBD_SYNC_MARK_STEP)) {
|
2011-07-03 19:26:43 +08:00
|
|
|
if (device->rs_mark_left[device->rs_last_mark] != still_to_go &&
|
|
|
|
device->state.conn != C_PAUSED_SYNC_T &&
|
|
|
|
device->state.conn != C_PAUSED_SYNC_S) {
|
|
|
|
device->rs_mark_time[next] = now;
|
|
|
|
device->rs_mark_left[next] = still_to_go;
|
|
|
|
device->rs_last_mark = next;
|
2010-11-05 16:23:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
/* It is called lazy update, so don't do write-out too often. */
|
|
|
|
static bool lazy_bitmap_update_due(struct drbd_device *device)
|
2009-09-26 07:07:19 +08:00
|
|
|
{
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
return time_after(jiffies, device->rs_last_bcast + 2*HZ);
|
|
|
|
}
|
2009-09-26 07:07:19 +08:00
|
|
|
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
static void maybe_schedule_on_disk_bitmap_update(struct drbd_device *device, bool rs_done)
|
|
|
|
{
|
|
|
|
if (rs_done)
|
|
|
|
set_bit(RS_DONE, &device->flags);
|
|
|
|
/* and also set RS_PROGRESS below */
|
|
|
|
else if (!lazy_bitmap_update_due(device))
|
2009-09-26 07:07:19 +08:00
|
|
|
return;
|
2012-10-19 20:21:22 +08:00
|
|
|
|
2014-02-11 16:30:49 +08:00
|
|
|
drbd_device_post_work(device, RS_PROGRESS);
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
}
|
2009-09-26 07:07:19 +08:00
|
|
|
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
static int update_sync_bits(struct drbd_device *device,
|
|
|
|
unsigned long sbnr, unsigned long ebnr,
|
|
|
|
enum update_sync_bits_mode mode)
|
|
|
|
{
|
2009-09-26 07:07:19 +08:00
|
|
|
/*
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
* We keep a count of set bits per resync-extent in the ->rs_left
|
|
|
|
* caching member, so we need to loop and work within the resync extent
|
|
|
|
* alignment. Typically this loop will execute exactly once.
|
2009-09-26 07:07:19 +08:00
|
|
|
*/
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
unsigned long flags;
|
|
|
|
unsigned long count = 0;
|
|
|
|
unsigned int cleared = 0;
|
|
|
|
while (sbnr <= ebnr) {
|
|
|
|
/* set temporary boundary bit number to last bit number within
|
|
|
|
* the resync extent of the current start bit number,
|
|
|
|
* but cap at provided end bit number */
|
|
|
|
unsigned long tbnr = min(ebnr, sbnr | BM_BLOCKS_PER_BM_EXT_MASK);
|
|
|
|
unsigned long c;
|
|
|
|
|
|
|
|
if (mode == RECORD_RS_FAILED)
|
|
|
|
/* Only called from drbd_rs_failed_io(), bits
|
|
|
|
* supposedly still set. Recount, maybe some
|
|
|
|
* of the bits have been successfully cleared
|
|
|
|
* by application IO meanwhile.
|
|
|
|
*/
|
|
|
|
c = drbd_bm_count_bits(device, sbnr, tbnr);
|
|
|
|
else if (mode == SET_IN_SYNC)
|
|
|
|
c = drbd_bm_clear_bits(device, sbnr, tbnr);
|
|
|
|
else /* if (mode == SET_OUT_OF_SYNC) */
|
|
|
|
c = drbd_bm_set_bits(device, sbnr, tbnr);
|
|
|
|
|
|
|
|
if (c) {
|
|
|
|
spin_lock_irqsave(&device->al_lock, flags);
|
|
|
|
cleared += update_rs_extent(device, BM_BIT_TO_EXT(sbnr), c, mode);
|
|
|
|
spin_unlock_irqrestore(&device->al_lock, flags);
|
|
|
|
count += c;
|
|
|
|
}
|
|
|
|
sbnr = tbnr + 1;
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
if (count) {
|
|
|
|
if (mode == SET_IN_SYNC) {
|
|
|
|
unsigned long still_to_go = drbd_bm_total_weight(device);
|
|
|
|
bool rs_is_done = (still_to_go <= device->rs_failed);
|
|
|
|
drbd_advance_rs_marks(device, still_to_go);
|
|
|
|
if (cleared || rs_is_done)
|
|
|
|
maybe_schedule_on_disk_bitmap_update(device, rs_is_done);
|
|
|
|
} else if (mode == RECORD_RS_FAILED)
|
|
|
|
device->rs_failed += count;
|
2011-07-03 19:26:43 +08:00
|
|
|
wake_up(&device->al_wait);
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
}
|
|
|
|
return count;
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
/* clear the bit corresponding to the piece of storage in question:
|
|
|
|
* size byte of data starting from sector. Only clear a bits of the affected
|
|
|
|
* one ore more _aligned_ BM_BLOCK_SIZE blocks.
|
|
|
|
*
|
|
|
|
* called by worker on C_SYNC_TARGET and receiver on SyncSource.
|
2009-09-26 07:07:19 +08:00
|
|
|
*
|
|
|
|
*/
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
int __drbd_change_sync(struct drbd_device *device, sector_t sector, int size,
|
2014-11-11 00:21:09 +08:00
|
|
|
enum update_sync_bits_mode mode)
|
2009-09-26 07:07:19 +08:00
|
|
|
{
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
/* Is called from worker and receiver context _only_ */
|
|
|
|
unsigned long sbnr, ebnr, lbnr;
|
|
|
|
unsigned long count = 0;
|
2009-09-26 07:07:19 +08:00
|
|
|
sector_t esector, nr_sectors;
|
|
|
|
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
/* This would be an empty REQ_FLUSH, be silent. */
|
|
|
|
if ((mode == SET_OUT_OF_SYNC) && size == 0)
|
2012-07-30 15:00:54 +08:00
|
|
|
return 0;
|
|
|
|
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_DISCARD_SIZE) {
|
|
|
|
drbd_err(device, "%s: sector=%llus size=%d nonsense!\n",
|
|
|
|
drbd_change_sync_fname[mode],
|
|
|
|
(unsigned long long)sector, size);
|
2010-10-27 20:33:00 +08:00
|
|
|
return 0;
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
if (!get_ldev(device))
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
return 0; /* no disk, no metadata, no bitmap to manipulate bits in */
|
2009-09-26 07:07:19 +08:00
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
nr_sectors = drbd_get_capacity(device->this_bdev);
|
2009-09-26 07:07:19 +08:00
|
|
|
esector = sector + (size >> 9) - 1;
|
|
|
|
|
2010-12-16 02:31:20 +08:00
|
|
|
if (!expect(sector < nr_sectors))
|
2009-09-26 07:07:19 +08:00
|
|
|
goto out;
|
2010-12-16 02:31:20 +08:00
|
|
|
if (!expect(esector < nr_sectors))
|
|
|
|
esector = nr_sectors - 1;
|
2009-09-26 07:07:19 +08:00
|
|
|
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
lbnr = BM_SECT_TO_BIT(nr_sectors-1);
|
2009-09-26 07:07:19 +08:00
|
|
|
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
if (mode == SET_IN_SYNC) {
|
|
|
|
/* Round up start sector, round down end sector. We make sure
|
|
|
|
* we only clear full, aligned, BM_BLOCK_SIZE blocks. */
|
|
|
|
if (unlikely(esector < BM_SECT_PER_BIT-1))
|
|
|
|
goto out;
|
|
|
|
if (unlikely(esector == (nr_sectors-1)))
|
|
|
|
ebnr = lbnr;
|
|
|
|
else
|
|
|
|
ebnr = BM_SECT_TO_BIT(esector - (BM_SECT_PER_BIT-1));
|
|
|
|
sbnr = BM_SECT_TO_BIT(sector + BM_SECT_PER_BIT-1);
|
|
|
|
} else {
|
|
|
|
/* We set it out of sync, or record resync failure.
|
|
|
|
* Should not round anything here. */
|
|
|
|
sbnr = BM_SECT_TO_BIT(sector);
|
|
|
|
ebnr = BM_SECT_TO_BIT(esector);
|
|
|
|
}
|
2009-09-26 07:07:19 +08:00
|
|
|
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 22:58:22 +08:00
|
|
|
count = update_sync_bits(device, sbnr, ebnr, mode);
|
2009-09-26 07:07:19 +08:00
|
|
|
out:
|
2011-07-03 19:26:43 +08:00
|
|
|
put_ldev(device);
|
2010-10-27 20:33:00 +08:00
|
|
|
return count;
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2011-07-03 19:26:43 +08:00
|
|
|
struct bm_extent *_bme_get(struct drbd_device *device, unsigned int enr)
|
2009-09-26 07:07:19 +08:00
|
|
|
{
|
|
|
|
struct lc_element *e;
|
|
|
|
struct bm_extent *bm_ext;
|
|
|
|
int wakeup = 0;
|
|
|
|
unsigned long rs_flags;
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_lock_irq(&device->al_lock);
|
|
|
|
if (device->resync_locked > device->resync->nr_elements/2) {
|
|
|
|
spin_unlock_irq(&device->al_lock);
|
2009-09-26 07:07:19 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-07-03 19:26:43 +08:00
|
|
|
e = lc_get(device->resync, enr);
|
2009-09-26 07:07:19 +08:00
|
|
|
bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL;
|
|
|
|
if (bm_ext) {
|
|
|
|
if (bm_ext->lce.lc_number != enr) {
|
2011-07-03 19:26:43 +08:00
|
|
|
bm_ext->rs_left = drbd_bm_e_weight(device, enr);
|
2009-09-26 07:07:19 +08:00
|
|
|
bm_ext->rs_failed = 0;
|
2011-07-03 19:26:43 +08:00
|
|
|
lc_committed(device->resync);
|
2009-09-26 07:07:19 +08:00
|
|
|
wakeup = 1;
|
|
|
|
}
|
|
|
|
if (bm_ext->lce.refcnt == 1)
|
2011-07-03 19:26:43 +08:00
|
|
|
device->resync_locked++;
|
2009-09-26 07:07:19 +08:00
|
|
|
set_bit(BME_NO_WRITES, &bm_ext->flags);
|
|
|
|
}
|
2011-07-03 19:26:43 +08:00
|
|
|
rs_flags = device->resync->flags;
|
|
|
|
spin_unlock_irq(&device->al_lock);
|
2009-09-26 07:07:19 +08:00
|
|
|
if (wakeup)
|
2011-07-03 19:26:43 +08:00
|
|
|
wake_up(&device->al_wait);
|
2009-09-26 07:07:19 +08:00
|
|
|
|
|
|
|
if (!bm_ext) {
|
|
|
|
if (rs_flags & LC_STARVING)
|
2011-07-03 23:53:52 +08:00
|
|
|
drbd_warn(device, "Have to wait for element"
|
2009-09-26 07:07:19 +08:00
|
|
|
" (resync LRU too small?)\n");
|
2011-02-21 20:21:01 +08:00
|
|
|
BUG_ON(rs_flags & LC_LOCKED);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return bm_ext;
|
|
|
|
}
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
static int _is_in_al(struct drbd_device *device, unsigned int enr)
|
2009-09-26 07:07:19 +08:00
|
|
|
{
|
2011-02-21 20:21:01 +08:00
|
|
|
int rv;
|
2009-09-26 07:07:19 +08:00
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_lock_irq(&device->al_lock);
|
|
|
|
rv = lc_is_used(device->act_log, enr);
|
|
|
|
spin_unlock_irq(&device->al_lock);
|
2009-09-26 07:07:19 +08:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drbd_rs_begin_io() - Gets an extent in the resync LRU cache and sets it to BME_LOCKED
|
2011-07-03 19:26:43 +08:00
|
|
|
* @device: DRBD device.
|
2009-09-26 07:07:19 +08:00
|
|
|
* @sector: The sector number.
|
|
|
|
*
|
2010-08-12 05:28:00 +08:00
|
|
|
* This functions sleeps on al_wait. Returns 0 on success, -EINTR if interrupted.
|
2009-09-26 07:07:19 +08:00
|
|
|
*/
|
2011-07-03 19:26:43 +08:00
|
|
|
int drbd_rs_begin_io(struct drbd_device *device, sector_t sector)
|
2009-09-26 07:07:19 +08:00
|
|
|
{
|
|
|
|
unsigned int enr = BM_SECT_TO_EXT(sector);
|
|
|
|
struct bm_extent *bm_ext;
|
|
|
|
int i, sig;
|
2014-04-29 00:43:19 +08:00
|
|
|
bool sa;
|
2009-09-26 07:07:19 +08:00
|
|
|
|
2010-11-09 20:59:41 +08:00
|
|
|
retry:
|
2011-07-03 19:26:43 +08:00
|
|
|
sig = wait_event_interruptible(device->al_wait,
|
|
|
|
(bm_ext = _bme_get(device, enr)));
|
2009-09-26 07:07:19 +08:00
|
|
|
if (sig)
|
2010-08-12 05:28:00 +08:00
|
|
|
return -EINTR;
|
2009-09-26 07:07:19 +08:00
|
|
|
|
|
|
|
if (test_bit(BME_LOCKED, &bm_ext->flags))
|
2010-08-12 05:28:00 +08:00
|
|
|
return 0;
|
2009-09-26 07:07:19 +08:00
|
|
|
|
2014-04-29 00:43:19 +08:00
|
|
|
/* step aside only while we are above c-min-rate; unless disabled. */
|
|
|
|
sa = drbd_rs_c_min_rate_throttle(device);
|
|
|
|
|
2009-09-26 07:07:19 +08:00
|
|
|
for (i = 0; i < AL_EXT_PER_BM_SECT; i++) {
|
2011-07-03 19:26:43 +08:00
|
|
|
sig = wait_event_interruptible(device->al_wait,
|
|
|
|
!_is_in_al(device, enr * AL_EXT_PER_BM_SECT + i) ||
|
2014-04-29 00:43:19 +08:00
|
|
|
(sa && test_bit(BME_PRIORITY, &bm_ext->flags)));
|
2010-11-09 20:59:41 +08:00
|
|
|
|
2014-04-29 00:43:19 +08:00
|
|
|
if (sig || (sa && test_bit(BME_PRIORITY, &bm_ext->flags))) {
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_lock_irq(&device->al_lock);
|
|
|
|
if (lc_put(device->resync, &bm_ext->lce) == 0) {
|
2010-11-09 20:59:41 +08:00
|
|
|
bm_ext->flags = 0; /* clears BME_NO_WRITES and eventually BME_PRIORITY */
|
2011-07-03 19:26:43 +08:00
|
|
|
device->resync_locked--;
|
|
|
|
wake_up(&device->al_wait);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_unlock_irq(&device->al_lock);
|
2010-11-09 20:59:41 +08:00
|
|
|
if (sig)
|
|
|
|
return -EINTR;
|
|
|
|
if (schedule_timeout_interruptible(HZ/10))
|
|
|
|
return -EINTR;
|
|
|
|
goto retry;
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
set_bit(BME_LOCKED, &bm_ext->flags);
|
2010-08-12 05:28:00 +08:00
|
|
|
return 0;
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drbd_try_rs_begin_io() - Gets an extent in the resync LRU cache, does not sleep
|
2011-07-03 19:26:43 +08:00
|
|
|
* @device: DRBD device.
|
2009-09-26 07:07:19 +08:00
|
|
|
* @sector: The sector number.
|
|
|
|
*
|
|
|
|
* Gets an extent in the resync LRU cache, sets it to BME_NO_WRITES, then
|
|
|
|
* tries to set it to BME_LOCKED. Returns 0 upon success, and -EAGAIN
|
|
|
|
* if there is still application IO going on in this area.
|
|
|
|
*/
|
2011-07-03 19:26:43 +08:00
|
|
|
int drbd_try_rs_begin_io(struct drbd_device *device, sector_t sector)
|
2009-09-26 07:07:19 +08:00
|
|
|
{
|
|
|
|
unsigned int enr = BM_SECT_TO_EXT(sector);
|
|
|
|
const unsigned int al_enr = enr*AL_EXT_PER_BM_SECT;
|
|
|
|
struct lc_element *e;
|
|
|
|
struct bm_extent *bm_ext;
|
|
|
|
int i;
|
2013-12-20 18:22:13 +08:00
|
|
|
bool throttle = drbd_rs_should_slow_down(device, sector, true);
|
|
|
|
|
|
|
|
/* If we need to throttle, a half-locked (only marked BME_NO_WRITES,
|
|
|
|
* not yet BME_LOCKED) extent needs to be kicked out explicitly if we
|
|
|
|
* need to throttle. There is at most one such half-locked extent,
|
|
|
|
* which is remembered in resync_wenr. */
|
|
|
|
|
|
|
|
if (throttle && device->resync_wenr != enr)
|
|
|
|
return -EAGAIN;
|
2009-09-26 07:07:19 +08:00
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_lock_irq(&device->al_lock);
|
|
|
|
if (device->resync_wenr != LC_FREE && device->resync_wenr != enr) {
|
2009-09-26 07:07:19 +08:00
|
|
|
/* in case you have very heavy scattered io, it may
|
|
|
|
* stall the syncer undefined if we give up the ref count
|
|
|
|
* when we try again and requeue.
|
|
|
|
*
|
|
|
|
* if we don't give up the refcount, but the next time
|
|
|
|
* we are scheduled this extent has been "synced" by new
|
|
|
|
* application writes, we'd miss the lc_put on the
|
|
|
|
* extent we keep the refcount on.
|
|
|
|
* so we remembered which extent we had to try again, and
|
|
|
|
* if the next requested one is something else, we do
|
|
|
|
* the lc_put here...
|
|
|
|
* we also have to wake_up
|
|
|
|
*/
|
2011-07-03 19:26:43 +08:00
|
|
|
e = lc_find(device->resync, device->resync_wenr);
|
2009-09-26 07:07:19 +08:00
|
|
|
bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL;
|
|
|
|
if (bm_ext) {
|
2011-06-27 22:23:33 +08:00
|
|
|
D_ASSERT(device, !test_bit(BME_LOCKED, &bm_ext->flags));
|
|
|
|
D_ASSERT(device, test_bit(BME_NO_WRITES, &bm_ext->flags));
|
2009-09-26 07:07:19 +08:00
|
|
|
clear_bit(BME_NO_WRITES, &bm_ext->flags);
|
2011-07-03 19:26:43 +08:00
|
|
|
device->resync_wenr = LC_FREE;
|
2013-12-20 18:22:13 +08:00
|
|
|
if (lc_put(device->resync, &bm_ext->lce) == 0) {
|
|
|
|
bm_ext->flags = 0;
|
2011-07-03 19:26:43 +08:00
|
|
|
device->resync_locked--;
|
2013-12-20 18:22:13 +08:00
|
|
|
}
|
2011-07-03 19:26:43 +08:00
|
|
|
wake_up(&device->al_wait);
|
2009-09-26 07:07:19 +08:00
|
|
|
} else {
|
2011-07-03 23:53:52 +08:00
|
|
|
drbd_alert(device, "LOGIC BUG\n");
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* TRY. */
|
2011-07-03 19:26:43 +08:00
|
|
|
e = lc_try_get(device->resync, enr);
|
2009-09-26 07:07:19 +08:00
|
|
|
bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL;
|
|
|
|
if (bm_ext) {
|
|
|
|
if (test_bit(BME_LOCKED, &bm_ext->flags))
|
|
|
|
goto proceed;
|
|
|
|
if (!test_and_set_bit(BME_NO_WRITES, &bm_ext->flags)) {
|
2011-07-03 19:26:43 +08:00
|
|
|
device->resync_locked++;
|
2009-09-26 07:07:19 +08:00
|
|
|
} else {
|
|
|
|
/* we did set the BME_NO_WRITES,
|
|
|
|
* but then could not set BME_LOCKED,
|
|
|
|
* so we tried again.
|
|
|
|
* drop the extra reference. */
|
|
|
|
bm_ext->lce.refcnt--;
|
2011-06-27 22:23:33 +08:00
|
|
|
D_ASSERT(device, bm_ext->lce.refcnt > 0);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
goto check_al;
|
|
|
|
} else {
|
|
|
|
/* do we rather want to try later? */
|
2011-07-03 19:26:43 +08:00
|
|
|
if (device->resync_locked > device->resync->nr_elements-3)
|
2009-09-26 07:07:19 +08:00
|
|
|
goto try_again;
|
|
|
|
/* Do or do not. There is no try. -- Yoda */
|
2011-07-03 19:26:43 +08:00
|
|
|
e = lc_get(device->resync, enr);
|
2009-09-26 07:07:19 +08:00
|
|
|
bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL;
|
|
|
|
if (!bm_ext) {
|
2011-07-03 19:26:43 +08:00
|
|
|
const unsigned long rs_flags = device->resync->flags;
|
2009-09-26 07:07:19 +08:00
|
|
|
if (rs_flags & LC_STARVING)
|
2011-07-03 23:53:52 +08:00
|
|
|
drbd_warn(device, "Have to wait for element"
|
2009-09-26 07:07:19 +08:00
|
|
|
" (resync LRU too small?)\n");
|
2011-02-21 20:21:01 +08:00
|
|
|
BUG_ON(rs_flags & LC_LOCKED);
|
2009-09-26 07:07:19 +08:00
|
|
|
goto try_again;
|
|
|
|
}
|
|
|
|
if (bm_ext->lce.lc_number != enr) {
|
2011-07-03 19:26:43 +08:00
|
|
|
bm_ext->rs_left = drbd_bm_e_weight(device, enr);
|
2009-09-26 07:07:19 +08:00
|
|
|
bm_ext->rs_failed = 0;
|
2011-07-03 19:26:43 +08:00
|
|
|
lc_committed(device->resync);
|
|
|
|
wake_up(&device->al_wait);
|
2011-06-27 22:23:33 +08:00
|
|
|
D_ASSERT(device, test_bit(BME_LOCKED, &bm_ext->flags) == 0);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
set_bit(BME_NO_WRITES, &bm_ext->flags);
|
2011-06-27 22:23:33 +08:00
|
|
|
D_ASSERT(device, bm_ext->lce.refcnt == 1);
|
2011-07-03 19:26:43 +08:00
|
|
|
device->resync_locked++;
|
2009-09-26 07:07:19 +08:00
|
|
|
goto check_al;
|
|
|
|
}
|
|
|
|
check_al:
|
|
|
|
for (i = 0; i < AL_EXT_PER_BM_SECT; i++) {
|
2011-07-03 19:26:43 +08:00
|
|
|
if (lc_is_used(device->act_log, al_enr+i))
|
2009-09-26 07:07:19 +08:00
|
|
|
goto try_again;
|
|
|
|
}
|
|
|
|
set_bit(BME_LOCKED, &bm_ext->flags);
|
|
|
|
proceed:
|
2011-07-03 19:26:43 +08:00
|
|
|
device->resync_wenr = LC_FREE;
|
|
|
|
spin_unlock_irq(&device->al_lock);
|
2009-09-26 07:07:19 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
try_again:
|
2013-12-20 18:22:13 +08:00
|
|
|
if (bm_ext) {
|
|
|
|
if (throttle) {
|
|
|
|
D_ASSERT(device, !test_bit(BME_LOCKED, &bm_ext->flags));
|
|
|
|
D_ASSERT(device, test_bit(BME_NO_WRITES, &bm_ext->flags));
|
|
|
|
clear_bit(BME_NO_WRITES, &bm_ext->flags);
|
|
|
|
device->resync_wenr = LC_FREE;
|
|
|
|
if (lc_put(device->resync, &bm_ext->lce) == 0) {
|
|
|
|
bm_ext->flags = 0;
|
|
|
|
device->resync_locked--;
|
|
|
|
}
|
|
|
|
wake_up(&device->al_wait);
|
|
|
|
} else
|
|
|
|
device->resync_wenr = enr;
|
|
|
|
}
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_unlock_irq(&device->al_lock);
|
2009-09-26 07:07:19 +08:00
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
void drbd_rs_complete_io(struct drbd_device *device, sector_t sector)
|
2009-09-26 07:07:19 +08:00
|
|
|
{
|
|
|
|
unsigned int enr = BM_SECT_TO_EXT(sector);
|
|
|
|
struct lc_element *e;
|
|
|
|
struct bm_extent *bm_ext;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_lock_irqsave(&device->al_lock, flags);
|
|
|
|
e = lc_find(device->resync, enr);
|
2009-09-26 07:07:19 +08:00
|
|
|
bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL;
|
|
|
|
if (!bm_ext) {
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_unlock_irqrestore(&device->al_lock, flags);
|
2009-09-26 07:07:19 +08:00
|
|
|
if (__ratelimit(&drbd_ratelimit_state))
|
2011-07-03 23:53:52 +08:00
|
|
|
drbd_err(device, "drbd_rs_complete_io() called, but extent not found\n");
|
2009-09-26 07:07:19 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bm_ext->lce.refcnt == 0) {
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_unlock_irqrestore(&device->al_lock, flags);
|
2011-07-03 23:53:52 +08:00
|
|
|
drbd_err(device, "drbd_rs_complete_io(,%llu [=%u]) called, "
|
2009-09-26 07:07:19 +08:00
|
|
|
"but refcnt is 0!?\n",
|
|
|
|
(unsigned long long)sector, enr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
if (lc_put(device->resync, &bm_ext->lce) == 0) {
|
2010-11-07 22:56:29 +08:00
|
|
|
bm_ext->flags = 0; /* clear BME_LOCKED, BME_NO_WRITES and BME_PRIORITY */
|
2011-07-03 19:26:43 +08:00
|
|
|
device->resync_locked--;
|
|
|
|
wake_up(&device->al_wait);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_unlock_irqrestore(&device->al_lock, flags);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drbd_rs_cancel_all() - Removes all extents from the resync LRU (even BME_LOCKED)
|
2011-07-03 19:26:43 +08:00
|
|
|
* @device: DRBD device.
|
2009-09-26 07:07:19 +08:00
|
|
|
*/
|
2011-07-03 19:26:43 +08:00
|
|
|
void drbd_rs_cancel_all(struct drbd_device *device)
|
2009-09-26 07:07:19 +08:00
|
|
|
{
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_lock_irq(&device->al_lock);
|
2009-09-26 07:07:19 +08:00
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
if (get_ldev_if_state(device, D_FAILED)) { /* Makes sure ->resync is there. */
|
|
|
|
lc_reset(device->resync);
|
|
|
|
put_ldev(device);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
2011-07-03 19:26:43 +08:00
|
|
|
device->resync_locked = 0;
|
|
|
|
device->resync_wenr = LC_FREE;
|
|
|
|
spin_unlock_irq(&device->al_lock);
|
|
|
|
wake_up(&device->al_wait);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drbd_rs_del_all() - Gracefully remove all extents from the resync LRU
|
2011-07-03 19:26:43 +08:00
|
|
|
* @device: DRBD device.
|
2009-09-26 07:07:19 +08:00
|
|
|
*
|
|
|
|
* Returns 0 upon success, -EAGAIN if at least one reference count was
|
|
|
|
* not zero.
|
|
|
|
*/
|
2011-07-03 19:26:43 +08:00
|
|
|
int drbd_rs_del_all(struct drbd_device *device)
|
2009-09-26 07:07:19 +08:00
|
|
|
{
|
|
|
|
struct lc_element *e;
|
|
|
|
struct bm_extent *bm_ext;
|
|
|
|
int i;
|
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_lock_irq(&device->al_lock);
|
2009-09-26 07:07:19 +08:00
|
|
|
|
2011-07-03 19:26:43 +08:00
|
|
|
if (get_ldev_if_state(device, D_FAILED)) {
|
2009-09-26 07:07:19 +08:00
|
|
|
/* ok, ->resync is there. */
|
2011-07-03 19:26:43 +08:00
|
|
|
for (i = 0; i < device->resync->nr_elements; i++) {
|
|
|
|
e = lc_element_by_index(device->resync, i);
|
2010-04-02 14:40:33 +08:00
|
|
|
bm_ext = lc_entry(e, struct bm_extent, lce);
|
2009-09-26 07:07:19 +08:00
|
|
|
if (bm_ext->lce.lc_number == LC_FREE)
|
|
|
|
continue;
|
2011-07-03 19:26:43 +08:00
|
|
|
if (bm_ext->lce.lc_number == device->resync_wenr) {
|
2011-07-03 23:53:52 +08:00
|
|
|
drbd_info(device, "dropping %u in drbd_rs_del_all, apparently"
|
2009-09-26 07:07:19 +08:00
|
|
|
" got 'synced' by application io\n",
|
2011-07-03 19:26:43 +08:00
|
|
|
device->resync_wenr);
|
2011-06-27 22:23:33 +08:00
|
|
|
D_ASSERT(device, !test_bit(BME_LOCKED, &bm_ext->flags));
|
|
|
|
D_ASSERT(device, test_bit(BME_NO_WRITES, &bm_ext->flags));
|
2009-09-26 07:07:19 +08:00
|
|
|
clear_bit(BME_NO_WRITES, &bm_ext->flags);
|
2011-07-03 19:26:43 +08:00
|
|
|
device->resync_wenr = LC_FREE;
|
|
|
|
lc_put(device->resync, &bm_ext->lce);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
|
|
|
if (bm_ext->lce.refcnt != 0) {
|
2011-07-03 23:53:52 +08:00
|
|
|
drbd_info(device, "Retrying drbd_rs_del_all() later. "
|
2009-09-26 07:07:19 +08:00
|
|
|
"refcnt=%d\n", bm_ext->lce.refcnt);
|
2011-07-03 19:26:43 +08:00
|
|
|
put_ldev(device);
|
|
|
|
spin_unlock_irq(&device->al_lock);
|
2009-09-26 07:07:19 +08:00
|
|
|
return -EAGAIN;
|
|
|
|
}
|
2011-06-27 22:23:33 +08:00
|
|
|
D_ASSERT(device, !test_bit(BME_LOCKED, &bm_ext->flags));
|
|
|
|
D_ASSERT(device, !test_bit(BME_NO_WRITES, &bm_ext->flags));
|
2011-07-03 19:26:43 +08:00
|
|
|
lc_del(device->resync, &bm_ext->lce);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
2011-06-27 22:23:33 +08:00
|
|
|
D_ASSERT(device, device->resync->used == 0);
|
2011-07-03 19:26:43 +08:00
|
|
|
put_ldev(device);
|
2009-09-26 07:07:19 +08:00
|
|
|
}
|
2011-07-03 19:26:43 +08:00
|
|
|
spin_unlock_irq(&device->al_lock);
|
|
|
|
wake_up(&device->al_wait);
|
2009-09-26 07:07:19 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|