2009-09-26 03:07:19 +04: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 15:21:03 +03:00
|
|
|
#include <linux/crc32c.h>
|
2009-09-26 03:07:19 +04:00
|
|
|
#include <linux/drbd.h>
|
2011-02-21 15:21:03 +03:00
|
|
|
#include <linux/drbd_limits.h>
|
|
|
|
#include <linux/dynamic_debug.h>
|
2009-09-26 03:07:19 +04:00
|
|
|
#include "drbd_int.h"
|
|
|
|
#include "drbd_wrappers.h"
|
|
|
|
|
2011-03-31 14:06:48 +04:00
|
|
|
|
|
|
|
enum al_transaction_types {
|
|
|
|
AL_TR_UPDATE = 0,
|
|
|
|
AL_TR_INITIALIZED = 0xffff
|
|
|
|
};
|
2011-02-21 15:21:03 +03: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 14:06:48 +04:00
|
|
|
* purge-all, set-all-idle, set-all-active, ... to-be-defined
|
|
|
|
* see also enum al_transaction_types */
|
2011-02-21 15:21:03 +03: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 03:07:19 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct update_odbm_work {
|
|
|
|
struct drbd_work w;
|
|
|
|
unsigned int enr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct update_al_work {
|
|
|
|
struct drbd_work w;
|
|
|
|
struct completion event;
|
2011-02-21 15:21:03 +03:00
|
|
|
int err;
|
2009-09-26 03:07:19 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-07-05 17:38:59 +04:00
|
|
|
void *drbd_md_get_buffer(struct drbd_conf *mdev)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
wait_event(mdev->misc_wait,
|
|
|
|
(r = atomic_cmpxchg(&mdev->md_io_in_use, 0, 1)) == 0 ||
|
|
|
|
mdev->state.disk <= D_FAILED);
|
|
|
|
|
|
|
|
return r ? NULL : page_address(mdev->md_io_page);
|
|
|
|
}
|
|
|
|
|
|
|
|
void drbd_md_put_buffer(struct drbd_conf *mdev)
|
|
|
|
{
|
|
|
|
if (atomic_dec_and_test(&mdev->md_io_in_use))
|
|
|
|
wake_up(&mdev->misc_wait);
|
|
|
|
}
|
|
|
|
|
2012-09-27 17:07:11 +04:00
|
|
|
void wait_until_done_or_force_detached(struct drbd_conf *mdev, struct drbd_backing_dev *bdev,
|
2012-02-22 14:51:57 +04:00
|
|
|
unsigned int *done)
|
2011-07-05 17:38:59 +04:00
|
|
|
{
|
2012-02-22 14:51:57 +04: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;
|
|
|
|
|
2012-09-27 17:07:11 +04:00
|
|
|
dt = wait_event_timeout(mdev->misc_wait,
|
|
|
|
*done || test_bit(FORCE_DETACH, &mdev->flags), dt);
|
|
|
|
if (dt == 0) {
|
2012-02-22 14:51:57 +04:00
|
|
|
dev_err(DEV, "meta-data IO operation timed out\n");
|
2012-09-27 17:07:11 +04:00
|
|
|
drbd_chk_io_error(mdev, 1, DRBD_FORCE_DETACH);
|
|
|
|
}
|
2011-07-05 17:38:59 +04:00
|
|
|
}
|
|
|
|
|
2009-09-26 03:07:19 +04:00
|
|
|
static int _drbd_md_sync_page_io(struct drbd_conf *mdev,
|
|
|
|
struct drbd_backing_dev *bdev,
|
|
|
|
struct page *page, sector_t sector,
|
|
|
|
int rw, int size)
|
|
|
|
{
|
|
|
|
struct bio *bio;
|
2010-12-13 04:20:47 +03:00
|
|
|
int err;
|
2009-09-26 03:07:19 +04:00
|
|
|
|
2011-07-05 17:38:59 +04:00
|
|
|
mdev->md_io.done = 0;
|
|
|
|
mdev->md_io.error = -ENODEV;
|
2009-09-26 03:07:19 +04:00
|
|
|
|
2010-08-25 12:21:04 +04:00
|
|
|
if ((rw & WRITE) && !test_bit(MD_NO_FUA, &mdev->flags))
|
2011-06-28 15:22:48 +04:00
|
|
|
rw |= REQ_FUA | REQ_FLUSH;
|
2011-03-09 13:56:30 +03:00
|
|
|
rw |= REQ_SYNC;
|
2009-09-26 03:07:19 +04:00
|
|
|
|
2011-02-23 19:02:01 +03:00
|
|
|
bio = bio_alloc_drbd(GFP_NOIO);
|
2009-09-26 03:07:19 +04:00
|
|
|
bio->bi_bdev = bdev->md_bdev;
|
|
|
|
bio->bi_sector = sector;
|
2010-12-13 04:20:47 +03:00
|
|
|
err = -EIO;
|
|
|
|
if (bio_add_page(bio, page, size, 0) != size)
|
2009-09-26 03:07:19 +04:00
|
|
|
goto out;
|
2011-07-05 17:38:59 +04:00
|
|
|
bio->bi_private = &mdev->md_io;
|
2009-09-26 03:07:19 +04:00
|
|
|
bio->bi_end_io = drbd_md_io_complete;
|
|
|
|
bio->bi_rw = rw;
|
|
|
|
|
2013-03-19 21:16:47 +04:00
|
|
|
if (!(rw & WRITE) && mdev->state.disk == D_DISKLESS && mdev->ldev == NULL)
|
|
|
|
/* special case, drbd_md_read() during drbd_adm_attach(): no get_ldev */
|
|
|
|
;
|
|
|
|
else if (!get_ldev_if_state(mdev, D_ATTACHING)) {
|
|
|
|
/* Corresponding put_ldev in drbd_md_io_complete() */
|
2011-07-05 17:38:59 +04:00
|
|
|
dev_err(DEV, "ASSERT FAILED: get_ldev_if_state() == 1 in _drbd_md_sync_page_io()\n");
|
|
|
|
err = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
bio_get(bio); /* one bio_put() is in the completion handler */
|
|
|
|
atomic_inc(&mdev->md_io_in_use); /* drbd_md_put_buffer() is in the completion handler */
|
2010-12-07 12:43:29 +03:00
|
|
|
if (drbd_insert_fault(mdev, (rw & WRITE) ? DRBD_FAULT_MD_WR : DRBD_FAULT_MD_RD))
|
2009-09-26 03:07:19 +04:00
|
|
|
bio_endio(bio, -EIO);
|
|
|
|
else
|
|
|
|
submit_bio(rw, bio);
|
2012-09-27 17:07:11 +04:00
|
|
|
wait_until_done_or_force_detached(mdev, bdev, &mdev->md_io.done);
|
2010-12-13 04:20:47 +03:00
|
|
|
if (bio_flagged(bio, BIO_UPTODATE))
|
2011-07-05 17:38:59 +04:00
|
|
|
err = mdev->md_io.error;
|
2009-09-26 03:07:19 +04:00
|
|
|
|
|
|
|
out:
|
|
|
|
bio_put(bio);
|
2010-12-13 04:20:47 +03:00
|
|
|
return err;
|
2009-09-26 03:07:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int drbd_md_sync_page_io(struct drbd_conf *mdev, struct drbd_backing_dev *bdev,
|
|
|
|
sector_t sector, int rw)
|
|
|
|
{
|
2010-12-13 04:25:41 +03:00
|
|
|
int err;
|
2009-09-26 03:07:19 +04:00
|
|
|
struct page *iop = mdev->md_io_page;
|
|
|
|
|
2011-07-05 17:38:59 +04:00
|
|
|
D_ASSERT(atomic_read(&mdev->md_io_in_use) == 1);
|
2009-09-26 03:07:19 +04:00
|
|
|
|
|
|
|
BUG_ON(!bdev->md_bdev);
|
|
|
|
|
2013-03-19 21:16:47 +04:00
|
|
|
dev_dbg(DEV, "meta_data io: %s [%d]:%s(,%llus,%s) %pS\n",
|
2011-02-21 15:21:03 +03:00
|
|
|
current->comm, current->pid, __func__,
|
2013-03-19 21:16:47 +04:00
|
|
|
(unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ",
|
|
|
|
(void*)_RET_IP_ );
|
2009-09-26 03:07:19 +04:00
|
|
|
|
|
|
|
if (sector < drbd_md_first_sector(bdev) ||
|
2011-02-21 15:21:03 +03:00
|
|
|
sector + 7 > drbd_md_last_sector(bdev))
|
2009-09-26 03:07:19 +04:00
|
|
|
dev_alert(DEV, "%s [%d]:%s(,%llus,%s) out of range md access!\n",
|
|
|
|
current->comm, current->pid, __func__,
|
|
|
|
(unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ");
|
|
|
|
|
2013-03-19 21:16:43 +04:00
|
|
|
/* we do all our meta data IO in aligned 4k blocks. */
|
|
|
|
err = _drbd_md_sync_page_io(mdev, bdev, iop, sector, rw, 4096);
|
2010-12-13 04:25:41 +03:00
|
|
|
if (err) {
|
2011-08-19 15:47:31 +04:00
|
|
|
dev_err(DEV, "drbd_md_sync_page_io(,%llus,%s) failed with error %d\n",
|
|
|
|
(unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ", err);
|
2009-09-26 03:07:19 +04:00
|
|
|
}
|
2010-12-13 04:25:41 +03:00
|
|
|
return err;
|
2009-09-26 03:07:19 +04:00
|
|
|
}
|
|
|
|
|
2013-03-19 21:16:53 +04:00
|
|
|
static struct bm_extent *find_active_resync_extent(struct drbd_conf *mdev, unsigned int enr)
|
2009-09-26 03:07:19 +04:00
|
|
|
{
|
|
|
|
struct lc_element *tmp;
|
|
|
|
tmp = lc_find(mdev->resync, enr/AL_EXT_PER_BM_SECT);
|
|
|
|
if (unlikely(tmp != NULL)) {
|
|
|
|
struct bm_extent *bm_ext = lc_entry(tmp, struct bm_extent, lce);
|
2013-03-19 21:16:53 +04:00
|
|
|
if (test_bit(BME_NO_WRITES, &bm_ext->flags))
|
|
|
|
return bm_ext;
|
2009-09-26 03:07:19 +04:00
|
|
|
}
|
2013-03-19 21:16:53 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct lc_element *_al_get(struct drbd_conf *mdev, unsigned int enr, bool nonblock)
|
|
|
|
{
|
|
|
|
struct lc_element *al_ext;
|
|
|
|
struct bm_extent *bm_ext;
|
|
|
|
int wake;
|
|
|
|
|
|
|
|
spin_lock_irq(&mdev->al_lock);
|
|
|
|
bm_ext = find_active_resync_extent(mdev, enr);
|
|
|
|
if (bm_ext) {
|
|
|
|
wake = !test_and_set_bit(BME_PRIORITY, &bm_ext->flags);
|
|
|
|
spin_unlock_irq(&mdev->al_lock);
|
|
|
|
if (wake)
|
|
|
|
wake_up(&mdev->al_wait);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (nonblock)
|
|
|
|
al_ext = lc_try_get(mdev->act_log, enr);
|
|
|
|
else
|
|
|
|
al_ext = lc_get(mdev->act_log, enr);
|
2009-09-26 03:07:19 +04:00
|
|
|
spin_unlock_irq(&mdev->al_lock);
|
|
|
|
return al_ext;
|
|
|
|
}
|
|
|
|
|
2013-03-19 21:16:52 +04:00
|
|
|
bool drbd_al_begin_io_fastpath(struct drbd_conf *mdev, struct drbd_interval *i)
|
2009-09-26 03:07:19 +04:00
|
|
|
{
|
2011-03-31 18:00:51 +04:00
|
|
|
/* for bios crossing activity log extent boundaries,
|
|
|
|
* we may need to activate two extents in one go */
|
2011-04-01 12:38:30 +04:00
|
|
|
unsigned first = i->sector >> (AL_EXTENT_SHIFT-9);
|
2012-07-30 11:00:54 +04:00
|
|
|
unsigned last = i->size == 0 ? first : (i->sector + (i->size >> 9) - 1) >> (AL_EXTENT_SHIFT-9);
|
2011-05-03 18:49:20 +04:00
|
|
|
|
2013-03-19 21:16:52 +04:00
|
|
|
D_ASSERT((unsigned)(last - first) <= 1);
|
|
|
|
D_ASSERT(atomic_read(&mdev->local_cnt) > 0);
|
|
|
|
|
|
|
|
/* FIXME figure out a fast path for bios crossing AL extent boundaries */
|
|
|
|
if (first != last)
|
|
|
|
return false;
|
|
|
|
|
2013-03-19 21:16:53 +04:00
|
|
|
return _al_get(mdev, first, true);
|
2013-03-19 21:16:52 +04:00
|
|
|
}
|
2013-03-19 21:16:48 +04:00
|
|
|
|
2013-03-19 21:16:52 +04:00
|
|
|
bool drbd_al_begin_io_prepare(struct drbd_conf *mdev, struct drbd_interval *i)
|
|
|
|
{
|
|
|
|
/* 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 03:07:19 +04:00
|
|
|
|
2012-07-30 11:00:54 +04:00
|
|
|
D_ASSERT(first <= last);
|
2009-09-26 03:07:19 +04:00
|
|
|
D_ASSERT(atomic_read(&mdev->local_cnt) > 0);
|
|
|
|
|
2013-03-19 21:16:49 +04:00
|
|
|
for (enr = first; enr <= last; enr++) {
|
|
|
|
struct lc_element *al_ext;
|
2013-03-19 21:16:53 +04:00
|
|
|
wait_event(mdev->al_wait,
|
|
|
|
(al_ext = _al_get(mdev, enr, false)) != NULL);
|
2013-03-19 21:16:49 +04:00
|
|
|
if (al_ext->lc_number != enr)
|
|
|
|
need_transaction = true;
|
|
|
|
}
|
2013-03-19 21:16:52 +04:00
|
|
|
return need_transaction;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int al_write_transaction(struct drbd_conf *mdev, bool delegate);
|
|
|
|
|
|
|
|
/* When called through generic_make_request(), we must delegate
|
|
|
|
* activity log I/O to the worker thread: a further request
|
|
|
|
* submitted via generic_make_request() within the same task
|
|
|
|
* would be queued on current->bio_list, and would only start
|
|
|
|
* after this function returns (see generic_make_request()).
|
|
|
|
*
|
|
|
|
* However, if we *are* the worker, we must not delegate to ourselves.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @delegate: delegate activity log I/O to the worker thread
|
|
|
|
*/
|
|
|
|
void drbd_al_begin_io_commit(struct drbd_conf *mdev, bool delegate)
|
|
|
|
{
|
|
|
|
bool locked = false;
|
2013-03-19 21:16:49 +04:00
|
|
|
|
2013-03-19 21:16:52 +04:00
|
|
|
BUG_ON(delegate && current == mdev->tconn->worker.task);
|
2009-09-26 03:07:19 +04:00
|
|
|
|
2011-05-03 18:49:20 +04:00
|
|
|
/* Serialize multiple transactions.
|
|
|
|
* This uses test_and_set_bit, memory barrier is implicit.
|
|
|
|
*/
|
|
|
|
wait_event(mdev->al_wait,
|
|
|
|
mdev->act_log->pending_changes == 0 ||
|
|
|
|
(locked = lc_try_lock_for_transaction(mdev->act_log)));
|
|
|
|
|
|
|
|
if (locked) {
|
2011-02-21 15:21:03 +03:00
|
|
|
/* Double check: it may have been committed by someone else,
|
|
|
|
* while we have been waiting for the lock. */
|
2011-04-01 12:38:30 +04:00
|
|
|
if (mdev->act_log->pending_changes) {
|
2012-02-21 00:53:28 +04:00
|
|
|
bool write_al_updates;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
write_al_updates = rcu_dereference(mdev->ldev->disk_conf)->al_updates;
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
2013-03-19 21:16:52 +04:00
|
|
|
if (write_al_updates)
|
2013-03-19 21:16:48 +04:00
|
|
|
al_write_transaction(mdev, delegate);
|
2011-02-21 15:21:03 +03:00
|
|
|
spin_lock_irq(&mdev->al_lock);
|
|
|
|
/* FIXME
|
2011-07-15 19:19:02 +04:00
|
|
|
if (err)
|
2011-02-21 15:21:03 +03:00
|
|
|
we need an "lc_cancel" here;
|
|
|
|
*/
|
|
|
|
lc_committed(mdev->act_log);
|
|
|
|
spin_unlock_irq(&mdev->al_lock);
|
|
|
|
}
|
|
|
|
lc_unlock(mdev->act_log);
|
2009-09-26 03:07:19 +04:00
|
|
|
wake_up(&mdev->al_wait);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-19 21:16:52 +04:00
|
|
|
/*
|
|
|
|
* @delegate: delegate activity log I/O to the worker thread
|
|
|
|
*/
|
|
|
|
void drbd_al_begin_io(struct drbd_conf *mdev, struct drbd_interval *i, bool delegate)
|
|
|
|
{
|
|
|
|
BUG_ON(delegate && current == mdev->tconn->worker.task);
|
|
|
|
|
|
|
|
if (drbd_al_begin_io_prepare(mdev, i))
|
|
|
|
drbd_al_begin_io_commit(mdev, delegate);
|
|
|
|
}
|
|
|
|
|
2013-03-19 21:16:56 +04:00
|
|
|
int drbd_al_begin_io_nonblock(struct drbd_conf *mdev, struct drbd_interval *i)
|
|
|
|
{
|
|
|
|
struct lru_cache *al = mdev->act_log;
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
D_ASSERT(first <= last);
|
|
|
|
|
|
|
|
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 */
|
|
|
|
if (available_update_slots < nr_al_extents)
|
|
|
|
return -EWOULDBLOCK;
|
|
|
|
|
|
|
|
/* Is resync active in this area? */
|
|
|
|
for (enr = first; enr <= last; enr++) {
|
|
|
|
struct lc_element *tmp;
|
|
|
|
tmp = lc_find(mdev->resync, enr/AL_EXT_PER_BM_SECT);
|
|
|
|
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 17:08:49 +04:00
|
|
|
if (!test_and_set_bit(BME_PRIORITY, &bm_ext->flags))
|
2013-03-19 21:16:56 +04: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;
|
|
|
|
al_ext = lc_get_cumulative(mdev->act_log, enr);
|
|
|
|
if (!al_ext)
|
|
|
|
dev_info(DEV, "LOGIC BUG for enr=%u\n", enr);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-31 17:18:56 +04:00
|
|
|
void drbd_al_complete_io(struct drbd_conf *mdev, struct drbd_interval *i)
|
2009-09-26 03:07:19 +04:00
|
|
|
{
|
2011-04-01 12:38:30 +04: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 11:00:54 +04:00
|
|
|
unsigned last = i->size == 0 ? first : (i->sector + (i->size >> 9) - 1) >> (AL_EXTENT_SHIFT-9);
|
2011-04-01 12:38:30 +04:00
|
|
|
unsigned enr;
|
2009-09-26 03:07:19 +04:00
|
|
|
struct lc_element *extent;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2012-07-30 11:00:54 +04:00
|
|
|
D_ASSERT(first <= last);
|
2009-09-26 03:07:19 +04:00
|
|
|
spin_lock_irqsave(&mdev->al_lock, flags);
|
|
|
|
|
2011-04-01 12:38:30 +04:00
|
|
|
for (enr = first; enr <= last; enr++) {
|
|
|
|
extent = lc_find(mdev->act_log, enr);
|
|
|
|
if (!extent) {
|
|
|
|
dev_err(DEV, "al_complete_io() called on inactive extent %u\n", enr);
|
|
|
|
continue;
|
|
|
|
}
|
2011-11-07 13:54:28 +04:00
|
|
|
lc_put(mdev->act_log, extent);
|
2009-09-26 03:07:19 +04:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&mdev->al_lock, flags);
|
2011-04-01 12:38:30 +04:00
|
|
|
wake_up(&mdev->al_wait);
|
2009-09-26 03:07:19 +04:00
|
|
|
}
|
|
|
|
|
2010-12-15 10:59:11 +03: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 unsigned int rs_extent_to_bm_page(unsigned int rs_enr)
|
|
|
|
{
|
|
|
|
return rs_enr >>
|
|
|
|
/* bit to page */
|
|
|
|
((PAGE_SHIFT + 3) -
|
2011-04-28 09:58:24 +04:00
|
|
|
/* resync extent number to bit */
|
2010-12-15 10:59:11 +03:00
|
|
|
(BM_EXT_SHIFT - BM_BLOCK_SHIFT));
|
|
|
|
}
|
|
|
|
|
2013-03-19 21:16:43 +04:00
|
|
|
static sector_t al_tr_number_to_on_disk_sector(struct drbd_conf *mdev)
|
|
|
|
{
|
2013-03-19 21:16:44 +04:00
|
|
|
const unsigned int stripes = mdev->ldev->md.al_stripes;
|
|
|
|
const unsigned int stripe_size_4kB = mdev->ldev->md.al_stripe_size_4k;
|
2013-03-19 21:16:43 +04:00
|
|
|
|
|
|
|
/* transaction number, modulo on-disk ring buffer wrap around */
|
2013-03-19 21:16:44 +04:00
|
|
|
unsigned int t = mdev->al_tr_number % (mdev->ldev->md.al_size_4k);
|
2013-03-19 21:16:43 +04:00
|
|
|
|
|
|
|
/* ... 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 mdev->ldev->md.md_offset + mdev->ldev->md.al_offset + t;
|
|
|
|
}
|
|
|
|
|
2011-03-16 17:31:39 +03:00
|
|
|
static int
|
2011-07-15 19:19:02 +04:00
|
|
|
_al_write_transaction(struct drbd_conf *mdev)
|
2009-09-26 03:07:19 +04:00
|
|
|
{
|
2011-02-21 15:21:03 +03:00
|
|
|
struct al_transaction_on_disk *buffer;
|
|
|
|
struct lc_element *e;
|
2009-09-26 03:07:19 +04:00
|
|
|
sector_t sector;
|
2011-02-21 15:21:03 +03:00
|
|
|
int i, mx;
|
|
|
|
unsigned extent_nr;
|
|
|
|
unsigned crc = 0;
|
2011-07-15 19:19:02 +04:00
|
|
|
int err = 0;
|
2009-09-26 03:07:19 +04:00
|
|
|
|
|
|
|
if (!get_ldev(mdev)) {
|
2011-02-21 15:21:03 +03:00
|
|
|
dev_err(DEV, "disk is %s, cannot start al transaction\n",
|
|
|
|
drbd_disk_str(mdev->state.disk));
|
2011-07-15 19:19:02 +04:00
|
|
|
return -EIO;
|
2009-09-26 03:07:19 +04:00
|
|
|
}
|
|
|
|
|
drbd: fix potential data divergence after multiple failures
If we get an IO-error during an activity log transaction,
if we failed to write the bitmap of the evicted extent,
we must not write the transaction itself.
If we failed to write the transaction,
we must not even submit the corresponding bio,
as its extent is not yet marked in the activity log.
Otherwise, if this was a disconneted Primary (degraded cluster), which
now lost its disk as well, and we later re-attach the same backend
storage, we possibly "forget" to resync some parts of the disk that
potentially have been changed.
On the receiving side, when receiving from a peer with unhealthy disk,
checking for pdsk == D_DISKLESS is not enough, we need to set out of
sync and do AL transactions for everything pdsk < D_INCONSISTENT on the
receiving side.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2010-10-19 01:04:07 +04:00
|
|
|
/* The bitmap write may have failed, causing a state change. */
|
|
|
|
if (mdev->state.disk < D_INCONSISTENT) {
|
|
|
|
dev_err(DEV,
|
2011-02-21 15:21:03 +03:00
|
|
|
"disk is %s, cannot write al transaction\n",
|
|
|
|
drbd_disk_str(mdev->state.disk));
|
drbd: fix potential data divergence after multiple failures
If we get an IO-error during an activity log transaction,
if we failed to write the bitmap of the evicted extent,
we must not write the transaction itself.
If we failed to write the transaction,
we must not even submit the corresponding bio,
as its extent is not yet marked in the activity log.
Otherwise, if this was a disconneted Primary (degraded cluster), which
now lost its disk as well, and we later re-attach the same backend
storage, we possibly "forget" to resync some parts of the disk that
potentially have been changed.
On the receiving side, when receiving from a peer with unhealthy disk,
checking for pdsk == D_DISKLESS is not enough, we need to set out of
sync and do AL transactions for everything pdsk < D_INCONSISTENT on the
receiving side.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2010-10-19 01:04:07 +04:00
|
|
|
put_ldev(mdev);
|
2011-07-15 19:19:02 +04:00
|
|
|
return -EIO;
|
drbd: fix potential data divergence after multiple failures
If we get an IO-error during an activity log transaction,
if we failed to write the bitmap of the evicted extent,
we must not write the transaction itself.
If we failed to write the transaction,
we must not even submit the corresponding bio,
as its extent is not yet marked in the activity log.
Otherwise, if this was a disconneted Primary (degraded cluster), which
now lost its disk as well, and we later re-attach the same backend
storage, we possibly "forget" to resync some parts of the disk that
potentially have been changed.
On the receiving side, when receiving from a peer with unhealthy disk,
checking for pdsk == D_DISKLESS is not enough, we need to set out of
sync and do AL transactions for everything pdsk < D_INCONSISTENT on the
receiving side.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2010-10-19 01:04:07 +04:00
|
|
|
}
|
|
|
|
|
2011-07-05 17:38:59 +04:00
|
|
|
buffer = drbd_md_get_buffer(mdev); /* protects md_io_buffer, al_tr_cycle, ... */
|
|
|
|
if (!buffer) {
|
|
|
|
dev_err(DEV, "disk failed while waiting for md_io buffer\n");
|
|
|
|
put_ldev(mdev);
|
2011-07-15 19:19:02 +04:00
|
|
|
return -ENODEV;
|
2011-07-05 17:38:59 +04:00
|
|
|
}
|
2009-09-26 03:07:19 +04:00
|
|
|
|
2011-02-21 15:21:03 +03:00
|
|
|
memset(buffer, 0, sizeof(*buffer));
|
|
|
|
buffer->magic = cpu_to_be32(DRBD_AL_MAGIC);
|
2009-09-26 03:07:19 +04:00
|
|
|
buffer->tr_number = cpu_to_be32(mdev->al_tr_number);
|
|
|
|
|
2011-02-21 15:21:03 +03:00
|
|
|
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(&mdev->al_lock);
|
|
|
|
list_for_each_entry(e, &mdev->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(mdev,
|
|
|
|
al_extent_to_bm_page(e->lc_number));
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
spin_unlock_irq(&mdev->al_lock);
|
|
|
|
BUG_ON(i > AL_UPDATES_PER_TRANSACTION);
|
2009-09-26 03:07:19 +04:00
|
|
|
|
2011-02-21 15:21:03 +03:00
|
|
|
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);
|
|
|
|
}
|
2009-09-26 03:07:19 +04:00
|
|
|
|
2011-02-21 15:21:03 +03:00
|
|
|
buffer->context_size = cpu_to_be16(mdev->act_log->nr_elements);
|
|
|
|
buffer->context_start_slot_nr = cpu_to_be16(mdev->al_tr_cycle);
|
2009-09-26 03:07:19 +04:00
|
|
|
|
2011-02-21 15:21:03 +03:00
|
|
|
mx = min_t(int, AL_CONTEXT_PER_TRANSACTION,
|
2009-09-26 03:07:19 +04:00
|
|
|
mdev->act_log->nr_elements - mdev->al_tr_cycle);
|
|
|
|
for (i = 0; i < mx; i++) {
|
|
|
|
unsigned idx = mdev->al_tr_cycle + i;
|
|
|
|
extent_nr = lc_element_by_index(mdev->act_log, idx)->lc_number;
|
2011-02-21 15:21:03 +03:00
|
|
|
buffer->context[i] = cpu_to_be32(extent_nr);
|
2009-09-26 03:07:19 +04:00
|
|
|
}
|
2011-02-21 15:21:03 +03:00
|
|
|
for (; i < AL_CONTEXT_PER_TRANSACTION; i++)
|
|
|
|
buffer->context[i] = cpu_to_be32(LC_FREE);
|
|
|
|
|
|
|
|
mdev->al_tr_cycle += AL_CONTEXT_PER_TRANSACTION;
|
2009-09-26 03:07:19 +04:00
|
|
|
if (mdev->al_tr_cycle >= mdev->act_log->nr_elements)
|
|
|
|
mdev->al_tr_cycle = 0;
|
|
|
|
|
2013-03-19 21:16:43 +04:00
|
|
|
sector = al_tr_number_to_on_disk_sector(mdev);
|
2009-09-26 03:07:19 +04:00
|
|
|
|
2011-02-21 15:21:03 +03:00
|
|
|
crc = crc32c(0, buffer, 4096);
|
|
|
|
buffer->crc32c = cpu_to_be32(crc);
|
2009-09-26 03:07:19 +04:00
|
|
|
|
2011-02-21 15:21:03 +03:00
|
|
|
if (drbd_bm_write_hinted(mdev))
|
2011-07-15 19:19:02 +04:00
|
|
|
err = -EIO;
|
2013-03-19 21:16:52 +04:00
|
|
|
else {
|
|
|
|
bool write_al_updates;
|
|
|
|
rcu_read_lock();
|
|
|
|
write_al_updates = rcu_dereference(mdev->ldev->disk_conf)->al_updates;
|
|
|
|
rcu_read_unlock();
|
|
|
|
if (write_al_updates) {
|
|
|
|
if (drbd_md_sync_page_io(mdev, mdev->ldev, sector, WRITE)) {
|
|
|
|
err = -EIO;
|
|
|
|
drbd_chk_io_error(mdev, 1, DRBD_META_IO_ERROR);
|
|
|
|
} else {
|
|
|
|
mdev->al_tr_number++;
|
|
|
|
mdev->al_writ_cnt++;
|
|
|
|
}
|
|
|
|
}
|
2011-02-21 15:21:03 +03:00
|
|
|
}
|
2009-09-26 03:07:19 +04:00
|
|
|
|
2011-07-05 17:38:59 +04:00
|
|
|
drbd_md_put_buffer(mdev);
|
2009-09-26 03:07:19 +04:00
|
|
|
put_ldev(mdev);
|
|
|
|
|
2011-07-15 19:19:02 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int w_al_write_transaction(struct drbd_work *w, int unused)
|
|
|
|
{
|
|
|
|
struct update_al_work *aw = container_of(w, struct update_al_work, w);
|
|
|
|
struct drbd_conf *mdev = w->mdev;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = _al_write_transaction(mdev);
|
|
|
|
aw->err = err;
|
|
|
|
complete(&aw->event);
|
|
|
|
|
|
|
|
return err != -EIO ? err : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calls from worker context (see w_restart_disk_io()) need to write the
|
|
|
|
transaction directly. Others came through generic_make_request(),
|
|
|
|
those need to delegate it to the worker. */
|
2013-03-19 21:16:48 +04:00
|
|
|
static int al_write_transaction(struct drbd_conf *mdev, bool delegate)
|
2011-07-15 19:19:02 +04:00
|
|
|
{
|
2013-03-19 21:16:48 +04:00
|
|
|
if (delegate) {
|
|
|
|
struct update_al_work al_work;
|
|
|
|
init_completion(&al_work.event);
|
|
|
|
al_work.w.cb = w_al_write_transaction;
|
|
|
|
al_work.w.mdev = mdev;
|
|
|
|
drbd_queue_work_front(&mdev->tconn->sender_work, &al_work.w);
|
|
|
|
wait_for_completion(&al_work.event);
|
|
|
|
return al_work.err;
|
|
|
|
} else
|
2011-07-15 19:19:02 +04:00
|
|
|
return _al_write_transaction(mdev);
|
2009-09-26 03:07:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int _try_lc_del(struct drbd_conf *mdev, struct lc_element *al_ext)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
spin_lock_irq(&mdev->al_lock);
|
|
|
|
rv = (al_ext->refcnt == 0);
|
|
|
|
if (likely(rv))
|
|
|
|
lc_del(mdev->act_log, al_ext);
|
|
|
|
spin_unlock_irq(&mdev->al_lock);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drbd_al_shrink() - Removes all active extents form the activity log
|
|
|
|
* @mdev: DRBD device.
|
|
|
|
*
|
|
|
|
* Removes all active extents form the activity log, waiting until
|
|
|
|
* the reference count of each entry dropped to 0 first, of course.
|
|
|
|
*
|
|
|
|
* You need to lock mdev->act_log with lc_try_lock() / lc_unlock()
|
|
|
|
*/
|
|
|
|
void drbd_al_shrink(struct drbd_conf *mdev)
|
|
|
|
{
|
|
|
|
struct lc_element *al_ext;
|
|
|
|
int i;
|
|
|
|
|
2011-02-21 15:21:01 +03:00
|
|
|
D_ASSERT(test_bit(__LC_LOCKED, &mdev->act_log->flags));
|
2009-09-26 03:07:19 +04:00
|
|
|
|
|
|
|
for (i = 0; i < mdev->act_log->nr_elements; i++) {
|
|
|
|
al_ext = lc_element_by_index(mdev->act_log, i);
|
|
|
|
if (al_ext->lc_number == LC_FREE)
|
|
|
|
continue;
|
|
|
|
wait_event(mdev->al_wait, _try_lc_del(mdev, al_ext));
|
|
|
|
}
|
|
|
|
|
|
|
|
wake_up(&mdev->al_wait);
|
|
|
|
}
|
|
|
|
|
2013-06-25 18:50:08 +04:00
|
|
|
int drbd_initialize_al(struct drbd_conf *mdev, void *buffer)
|
|
|
|
{
|
|
|
|
struct al_transaction_on_disk *al = buffer;
|
|
|
|
struct drbd_md *md = &mdev->ldev->md;
|
|
|
|
sector_t al_base = md->md_offset + md->al_offset;
|
|
|
|
int al_size_4k = md->al_stripes * md->al_stripe_size_4k;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
memset(al, 0, 4096);
|
|
|
|
al->magic = cpu_to_be32(DRBD_AL_MAGIC);
|
|
|
|
al->transaction_type = cpu_to_be16(AL_TR_INITIALIZED);
|
|
|
|
al->crc32c = cpu_to_be32(crc32c(0, al, 4096));
|
|
|
|
|
|
|
|
for (i = 0; i < al_size_4k; i++) {
|
|
|
|
int err = drbd_md_sync_page_io(mdev, mdev->ldev, al_base + i * 8, WRITE);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-16 17:31:39 +03:00
|
|
|
static int w_update_odbm(struct drbd_work *w, int unused)
|
2009-09-26 03:07:19 +04:00
|
|
|
{
|
|
|
|
struct update_odbm_work *udw = container_of(w, struct update_odbm_work, w);
|
2011-02-09 20:09:48 +03:00
|
|
|
struct drbd_conf *mdev = w->mdev;
|
2011-03-07 14:49:34 +03:00
|
|
|
struct sib_info sib = { .sib_reason = SIB_SYNC_PROGRESS, };
|
2009-09-26 03:07:19 +04:00
|
|
|
|
|
|
|
if (!get_ldev(mdev)) {
|
|
|
|
if (__ratelimit(&drbd_ratelimit_state))
|
|
|
|
dev_warn(DEV, "Can not update on disk bitmap, local IO disabled.\n");
|
|
|
|
kfree(udw);
|
2011-03-16 17:31:39 +03:00
|
|
|
return 0;
|
2009-09-26 03:07:19 +04:00
|
|
|
}
|
|
|
|
|
2010-12-15 10:59:11 +03:00
|
|
|
drbd_bm_write_page(mdev, rs_extent_to_bm_page(udw->enr));
|
2009-09-26 03:07:19 +04:00
|
|
|
put_ldev(mdev);
|
|
|
|
|
|
|
|
kfree(udw);
|
|
|
|
|
|
|
|
if (drbd_bm_total_weight(mdev) <= mdev->rs_failed) {
|
|
|
|
switch (mdev->state.conn) {
|
|
|
|
case C_SYNC_SOURCE: case C_SYNC_TARGET:
|
|
|
|
case C_PAUSED_SYNC_S: case C_PAUSED_SYNC_T:
|
|
|
|
drbd_resync_finished(mdev);
|
|
|
|
default:
|
|
|
|
/* nothing to do */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-03-07 14:49:34 +03:00
|
|
|
drbd_bcast_event(mdev, &sib);
|
2009-09-26 03:07:19 +04:00
|
|
|
|
2011-03-16 17:31:39 +03:00
|
|
|
return 0;
|
2009-09-26 03:07:19 +04: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.
|
|
|
|
*
|
|
|
|
* TODO will be obsoleted once we have a caching lru of the on disk bitmap
|
|
|
|
*/
|
|
|
|
static void drbd_try_clear_on_disk_bm(struct drbd_conf *mdev, sector_t sector,
|
|
|
|
int count, int success)
|
|
|
|
{
|
|
|
|
struct lc_element *e;
|
|
|
|
struct update_odbm_work *udw;
|
|
|
|
|
|
|
|
unsigned int enr;
|
|
|
|
|
|
|
|
D_ASSERT(atomic_read(&mdev->local_cnt));
|
|
|
|
|
|
|
|
/* I simply assume that a sector/size pair never crosses
|
|
|
|
* a 16 MB extent border. (Currently this is true...) */
|
|
|
|
enr = BM_SECT_TO_EXT(sector);
|
|
|
|
|
|
|
|
e = lc_get(mdev->resync, enr);
|
|
|
|
if (e) {
|
|
|
|
struct bm_extent *ext = lc_entry(e, struct bm_extent, lce);
|
|
|
|
if (ext->lce.lc_number == enr) {
|
|
|
|
if (success)
|
|
|
|
ext->rs_left -= count;
|
|
|
|
else
|
|
|
|
ext->rs_failed += count;
|
|
|
|
if (ext->rs_left < ext->rs_failed) {
|
2011-11-17 13:11:47 +04:00
|
|
|
dev_warn(DEV, "BAD! sector=%llus enr=%u rs_left=%d "
|
|
|
|
"rs_failed=%d count=%d cstate=%s\n",
|
2009-09-26 03:07:19 +04:00
|
|
|
(unsigned long long)sector,
|
|
|
|
ext->lce.lc_number, ext->rs_left,
|
2011-11-17 13:11:47 +04:00
|
|
|
ext->rs_failed, count,
|
|
|
|
drbd_conn_str(mdev->state.conn));
|
|
|
|
|
|
|
|
/* 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. */
|
|
|
|
ext->rs_left = drbd_bm_e_weight(mdev, enr);
|
2009-09-26 03:07:19 +04: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.
|
|
|
|
*/
|
|
|
|
int rs_left = drbd_bm_e_weight(mdev, enr);
|
|
|
|
if (ext->flags != 0) {
|
|
|
|
dev_warn(DEV, "changing resync lce: %d[%u;%02lx]"
|
|
|
|
" -> %d[%u;00]\n",
|
|
|
|
ext->lce.lc_number, ext->rs_left,
|
|
|
|
ext->flags, enr, rs_left);
|
|
|
|
ext->flags = 0;
|
|
|
|
}
|
|
|
|
if (ext->rs_failed) {
|
|
|
|
dev_warn(DEV, "Kicking resync_lru element enr=%u "
|
|
|
|
"out with rs_failed=%d\n",
|
|
|
|
ext->lce.lc_number, ext->rs_failed);
|
|
|
|
}
|
|
|
|
ext->rs_left = rs_left;
|
|
|
|
ext->rs_failed = success ? 0 : count;
|
2011-02-21 15:21:01 +03:00
|
|
|
/* we don't keep a persistent log of the resync lru,
|
|
|
|
* we can commit any change right away. */
|
|
|
|
lc_committed(mdev->resync);
|
2009-09-26 03:07:19 +04:00
|
|
|
}
|
|
|
|
lc_put(mdev->resync, &ext->lce);
|
|
|
|
/* no race, we are within the al_lock! */
|
|
|
|
|
|
|
|
if (ext->rs_left == ext->rs_failed) {
|
|
|
|
ext->rs_failed = 0;
|
|
|
|
|
|
|
|
udw = kmalloc(sizeof(*udw), GFP_ATOMIC);
|
|
|
|
if (udw) {
|
|
|
|
udw->enr = ext->lce.lc_number;
|
|
|
|
udw->w.cb = w_update_odbm;
|
2011-02-08 17:08:49 +03:00
|
|
|
udw->w.mdev = mdev;
|
2011-11-14 18:42:37 +04:00
|
|
|
drbd_queue_work_front(&mdev->tconn->sender_work, &udw->w);
|
2009-09-26 03:07:19 +04:00
|
|
|
} else {
|
|
|
|
dev_warn(DEV, "Could not kmalloc an udw\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dev_err(DEV, "lc_get() failed! locked=%d/%d flags=%lu\n",
|
|
|
|
mdev->resync_locked,
|
|
|
|
mdev->resync->nr_elements,
|
|
|
|
mdev->resync->flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-05 11:23:37 +03:00
|
|
|
void drbd_advance_rs_marks(struct drbd_conf *mdev, unsigned long still_to_go)
|
|
|
|
{
|
|
|
|
unsigned long now = jiffies;
|
|
|
|
unsigned long last = mdev->rs_mark_time[mdev->rs_last_mark];
|
|
|
|
int next = (mdev->rs_last_mark + 1) % DRBD_SYNC_MARKS;
|
|
|
|
if (time_after_eq(now, last + DRBD_SYNC_MARK_STEP)) {
|
|
|
|
if (mdev->rs_mark_left[mdev->rs_last_mark] != still_to_go &&
|
|
|
|
mdev->state.conn != C_PAUSED_SYNC_T &&
|
|
|
|
mdev->state.conn != C_PAUSED_SYNC_S) {
|
|
|
|
mdev->rs_mark_time[next] = now;
|
|
|
|
mdev->rs_mark_left[next] = still_to_go;
|
|
|
|
mdev->rs_last_mark = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-26 03:07:19 +04: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void __drbd_set_in_sync(struct drbd_conf *mdev, sector_t sector, int size,
|
|
|
|
const char *file, const unsigned int line)
|
|
|
|
{
|
|
|
|
/* Is called from worker and receiver context _only_ */
|
|
|
|
unsigned long sbnr, ebnr, lbnr;
|
|
|
|
unsigned long count = 0;
|
|
|
|
sector_t esector, nr_sectors;
|
|
|
|
int wake_up = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2011-02-21 14:41:39 +03:00
|
|
|
if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) {
|
2009-09-26 03:07:19 +04:00
|
|
|
dev_err(DEV, "drbd_set_in_sync: sector=%llus size=%d nonsense!\n",
|
|
|
|
(unsigned long long)sector, size);
|
|
|
|
return;
|
|
|
|
}
|
2012-10-19 16:21:22 +04:00
|
|
|
|
|
|
|
if (!get_ldev(mdev))
|
|
|
|
return; /* no disk, no metadata, no bitmap to clear bits in */
|
|
|
|
|
2009-09-26 03:07:19 +04:00
|
|
|
nr_sectors = drbd_get_capacity(mdev->this_bdev);
|
|
|
|
esector = sector + (size >> 9) - 1;
|
|
|
|
|
2010-12-15 21:31:20 +03:00
|
|
|
if (!expect(sector < nr_sectors))
|
2012-10-19 16:21:22 +04:00
|
|
|
goto out;
|
2010-12-15 21:31:20 +03:00
|
|
|
if (!expect(esector < nr_sectors))
|
|
|
|
esector = nr_sectors - 1;
|
2009-09-26 03:07:19 +04:00
|
|
|
|
|
|
|
lbnr = BM_SECT_TO_BIT(nr_sectors-1);
|
|
|
|
|
|
|
|
/* we clear it (in sync).
|
|
|
|
* round up start sector, round down end sector. we make sure we only
|
|
|
|
* clear full, aligned, BM_BLOCK_SIZE (4K) blocks */
|
|
|
|
if (unlikely(esector < BM_SECT_PER_BIT-1))
|
2012-10-19 16:21:22 +04:00
|
|
|
goto out;
|
2009-09-26 03:07:19 +04:00
|
|
|
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);
|
|
|
|
|
|
|
|
if (sbnr > ebnr)
|
2012-10-19 16:21:22 +04:00
|
|
|
goto out;
|
2009-09-26 03:07:19 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ok, (capacity & 7) != 0 sometimes, but who cares...
|
|
|
|
* we count rs_{total,left} in bits, not sectors.
|
|
|
|
*/
|
|
|
|
count = drbd_bm_clear_bits(mdev, sbnr, ebnr);
|
2012-10-19 16:21:22 +04:00
|
|
|
if (count) {
|
2010-11-05 11:23:37 +03:00
|
|
|
drbd_advance_rs_marks(mdev, drbd_bm_total_weight(mdev));
|
2010-08-11 23:21:50 +04:00
|
|
|
spin_lock_irqsave(&mdev->al_lock, flags);
|
2010-12-09 17:03:57 +03:00
|
|
|
drbd_try_clear_on_disk_bm(mdev, sector, count, true);
|
2010-08-11 23:21:50 +04:00
|
|
|
spin_unlock_irqrestore(&mdev->al_lock, flags);
|
|
|
|
|
2009-09-26 03:07:19 +04:00
|
|
|
/* just wake_up unconditional now, various lc_chaged(),
|
|
|
|
* lc_put() in drbd_try_clear_on_disk_bm(). */
|
|
|
|
wake_up = 1;
|
|
|
|
}
|
2012-10-19 16:21:22 +04:00
|
|
|
out:
|
|
|
|
put_ldev(mdev);
|
2009-09-26 03:07:19 +04:00
|
|
|
if (wake_up)
|
|
|
|
wake_up(&mdev->al_wait);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* this is intended to set one request worth of data out of sync.
|
|
|
|
* affects at least 1 bit,
|
2010-11-11 17:19:07 +03:00
|
|
|
* and at most 1+DRBD_MAX_BIO_SIZE/BM_BLOCK_SIZE bits.
|
2009-09-26 03:07:19 +04:00
|
|
|
*
|
|
|
|
* called by tl_clear and drbd_send_dblock (==drbd_make_request).
|
|
|
|
* so this can be _any_ process.
|
|
|
|
*/
|
2010-10-27 16:33:00 +04:00
|
|
|
int __drbd_set_out_of_sync(struct drbd_conf *mdev, sector_t sector, int size,
|
2009-09-26 03:07:19 +04:00
|
|
|
const char *file, const unsigned int line)
|
|
|
|
{
|
2011-11-07 13:54:28 +04:00
|
|
|
unsigned long sbnr, ebnr, flags;
|
2009-09-26 03:07:19 +04:00
|
|
|
sector_t esector, nr_sectors;
|
2010-10-27 16:33:00 +04:00
|
|
|
unsigned int enr, count = 0;
|
2009-09-26 03:07:19 +04:00
|
|
|
struct lc_element *e;
|
|
|
|
|
2012-07-30 11:00:54 +04:00
|
|
|
/* this should be an empty REQ_FLUSH */
|
|
|
|
if (size == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (size < 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) {
|
2009-09-26 03:07:19 +04:00
|
|
|
dev_err(DEV, "sector: %llus, size: %d\n",
|
|
|
|
(unsigned long long)sector, size);
|
2010-10-27 16:33:00 +04:00
|
|
|
return 0;
|
2009-09-26 03:07:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!get_ldev(mdev))
|
2010-10-27 16:33:00 +04:00
|
|
|
return 0; /* no disk, no metadata, no bitmap to set bits in */
|
2009-09-26 03:07:19 +04:00
|
|
|
|
|
|
|
nr_sectors = drbd_get_capacity(mdev->this_bdev);
|
|
|
|
esector = sector + (size >> 9) - 1;
|
|
|
|
|
2010-12-15 21:31:20 +03:00
|
|
|
if (!expect(sector < nr_sectors))
|
2009-09-26 03:07:19 +04:00
|
|
|
goto out;
|
2010-12-15 21:31:20 +03:00
|
|
|
if (!expect(esector < nr_sectors))
|
|
|
|
esector = nr_sectors - 1;
|
2009-09-26 03:07:19 +04:00
|
|
|
|
|
|
|
/* we set it out of sync,
|
|
|
|
* we do not need to round anything here */
|
|
|
|
sbnr = BM_SECT_TO_BIT(sector);
|
|
|
|
ebnr = BM_SECT_TO_BIT(esector);
|
|
|
|
|
|
|
|
/* ok, (capacity & 7) != 0 sometimes, but who cares...
|
|
|
|
* we count rs_{total,left} in bits, not sectors. */
|
|
|
|
spin_lock_irqsave(&mdev->al_lock, flags);
|
|
|
|
count = drbd_bm_set_bits(mdev, sbnr, ebnr);
|
|
|
|
|
|
|
|
enr = BM_SECT_TO_EXT(sector);
|
|
|
|
e = lc_find(mdev->resync, enr);
|
|
|
|
if (e)
|
|
|
|
lc_entry(e, struct bm_extent, lce)->rs_left += count;
|
|
|
|
spin_unlock_irqrestore(&mdev->al_lock, flags);
|
|
|
|
|
|
|
|
out:
|
|
|
|
put_ldev(mdev);
|
2010-10-27 16:33:00 +04:00
|
|
|
|
|
|
|
return count;
|
2009-09-26 03:07:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
struct bm_extent *_bme_get(struct drbd_conf *mdev, unsigned int enr)
|
|
|
|
{
|
|
|
|
struct lc_element *e;
|
|
|
|
struct bm_extent *bm_ext;
|
|
|
|
int wakeup = 0;
|
|
|
|
unsigned long rs_flags;
|
|
|
|
|
|
|
|
spin_lock_irq(&mdev->al_lock);
|
|
|
|
if (mdev->resync_locked > mdev->resync->nr_elements/2) {
|
|
|
|
spin_unlock_irq(&mdev->al_lock);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
e = lc_get(mdev->resync, enr);
|
|
|
|
bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL;
|
|
|
|
if (bm_ext) {
|
|
|
|
if (bm_ext->lce.lc_number != enr) {
|
|
|
|
bm_ext->rs_left = drbd_bm_e_weight(mdev, enr);
|
|
|
|
bm_ext->rs_failed = 0;
|
2011-02-21 15:21:01 +03:00
|
|
|
lc_committed(mdev->resync);
|
2009-09-26 03:07:19 +04:00
|
|
|
wakeup = 1;
|
|
|
|
}
|
|
|
|
if (bm_ext->lce.refcnt == 1)
|
|
|
|
mdev->resync_locked++;
|
|
|
|
set_bit(BME_NO_WRITES, &bm_ext->flags);
|
|
|
|
}
|
|
|
|
rs_flags = mdev->resync->flags;
|
|
|
|
spin_unlock_irq(&mdev->al_lock);
|
|
|
|
if (wakeup)
|
|
|
|
wake_up(&mdev->al_wait);
|
|
|
|
|
|
|
|
if (!bm_ext) {
|
|
|
|
if (rs_flags & LC_STARVING)
|
|
|
|
dev_warn(DEV, "Have to wait for element"
|
|
|
|
" (resync LRU too small?)\n");
|
2011-02-21 15:21:01 +03:00
|
|
|
BUG_ON(rs_flags & LC_LOCKED);
|
2009-09-26 03:07:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return bm_ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _is_in_al(struct drbd_conf *mdev, unsigned int enr)
|
|
|
|
{
|
2011-02-21 15:21:01 +03:00
|
|
|
int rv;
|
2009-09-26 03:07:19 +04:00
|
|
|
|
|
|
|
spin_lock_irq(&mdev->al_lock);
|
2011-02-21 15:21:01 +03:00
|
|
|
rv = lc_is_used(mdev->act_log, enr);
|
2009-09-26 03:07:19 +04:00
|
|
|
spin_unlock_irq(&mdev->al_lock);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drbd_rs_begin_io() - Gets an extent in the resync LRU cache and sets it to BME_LOCKED
|
|
|
|
* @mdev: DRBD device.
|
|
|
|
* @sector: The sector number.
|
|
|
|
*
|
2010-08-12 01:28:00 +04:00
|
|
|
* This functions sleeps on al_wait. Returns 0 on success, -EINTR if interrupted.
|
2009-09-26 03:07:19 +04:00
|
|
|
*/
|
|
|
|
int drbd_rs_begin_io(struct drbd_conf *mdev, sector_t sector)
|
|
|
|
{
|
|
|
|
unsigned int enr = BM_SECT_TO_EXT(sector);
|
|
|
|
struct bm_extent *bm_ext;
|
|
|
|
int i, sig;
|
2010-11-09 15:59:41 +03:00
|
|
|
int sa = 200; /* Step aside 200 times, then grab the extent and let app-IO wait.
|
|
|
|
200 times -> 20 seconds. */
|
2009-09-26 03:07:19 +04:00
|
|
|
|
2010-11-09 15:59:41 +03:00
|
|
|
retry:
|
2009-09-26 03:07:19 +04:00
|
|
|
sig = wait_event_interruptible(mdev->al_wait,
|
|
|
|
(bm_ext = _bme_get(mdev, enr)));
|
|
|
|
if (sig)
|
2010-08-12 01:28:00 +04:00
|
|
|
return -EINTR;
|
2009-09-26 03:07:19 +04:00
|
|
|
|
|
|
|
if (test_bit(BME_LOCKED, &bm_ext->flags))
|
2010-08-12 01:28:00 +04:00
|
|
|
return 0;
|
2009-09-26 03:07:19 +04:00
|
|
|
|
|
|
|
for (i = 0; i < AL_EXT_PER_BM_SECT; i++) {
|
|
|
|
sig = wait_event_interruptible(mdev->al_wait,
|
2010-11-09 15:59:41 +03:00
|
|
|
!_is_in_al(mdev, enr * AL_EXT_PER_BM_SECT + i) ||
|
2010-11-22 17:49:17 +03:00
|
|
|
test_bit(BME_PRIORITY, &bm_ext->flags));
|
2010-11-09 15:59:41 +03:00
|
|
|
|
|
|
|
if (sig || (test_bit(BME_PRIORITY, &bm_ext->flags) && sa)) {
|
2009-09-26 03:07:19 +04:00
|
|
|
spin_lock_irq(&mdev->al_lock);
|
|
|
|
if (lc_put(mdev->resync, &bm_ext->lce) == 0) {
|
2010-11-09 15:59:41 +03:00
|
|
|
bm_ext->flags = 0; /* clears BME_NO_WRITES and eventually BME_PRIORITY */
|
2009-09-26 03:07:19 +04:00
|
|
|
mdev->resync_locked--;
|
|
|
|
wake_up(&mdev->al_wait);
|
|
|
|
}
|
|
|
|
spin_unlock_irq(&mdev->al_lock);
|
2010-11-09 15:59:41 +03:00
|
|
|
if (sig)
|
|
|
|
return -EINTR;
|
|
|
|
if (schedule_timeout_interruptible(HZ/10))
|
|
|
|
return -EINTR;
|
2010-11-22 17:49:17 +03:00
|
|
|
if (sa && --sa == 0)
|
|
|
|
dev_warn(DEV,"drbd_rs_begin_io() stepped aside for 20sec."
|
|
|
|
"Resync stalled?\n");
|
2010-11-09 15:59:41 +03:00
|
|
|
goto retry;
|
2009-09-26 03:07:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
set_bit(BME_LOCKED, &bm_ext->flags);
|
2010-08-12 01:28:00 +04:00
|
|
|
return 0;
|
2009-09-26 03:07:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drbd_try_rs_begin_io() - Gets an extent in the resync LRU cache, does not sleep
|
|
|
|
* @mdev: DRBD device.
|
|
|
|
* @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.
|
|
|
|
*/
|
|
|
|
int drbd_try_rs_begin_io(struct drbd_conf *mdev, sector_t sector)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
spin_lock_irq(&mdev->al_lock);
|
|
|
|
if (mdev->resync_wenr != LC_FREE && mdev->resync_wenr != enr) {
|
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
e = lc_find(mdev->resync, mdev->resync_wenr);
|
|
|
|
bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL;
|
|
|
|
if (bm_ext) {
|
|
|
|
D_ASSERT(!test_bit(BME_LOCKED, &bm_ext->flags));
|
|
|
|
D_ASSERT(test_bit(BME_NO_WRITES, &bm_ext->flags));
|
|
|
|
clear_bit(BME_NO_WRITES, &bm_ext->flags);
|
|
|
|
mdev->resync_wenr = LC_FREE;
|
|
|
|
if (lc_put(mdev->resync, &bm_ext->lce) == 0)
|
|
|
|
mdev->resync_locked--;
|
|
|
|
wake_up(&mdev->al_wait);
|
|
|
|
} else {
|
|
|
|
dev_alert(DEV, "LOGIC BUG\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* TRY. */
|
|
|
|
e = lc_try_get(mdev->resync, enr);
|
|
|
|
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)) {
|
|
|
|
mdev->resync_locked++;
|
|
|
|
} 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--;
|
|
|
|
D_ASSERT(bm_ext->lce.refcnt > 0);
|
|
|
|
}
|
|
|
|
goto check_al;
|
|
|
|
} else {
|
|
|
|
/* do we rather want to try later? */
|
2009-10-01 11:04:14 +04:00
|
|
|
if (mdev->resync_locked > mdev->resync->nr_elements-3)
|
2009-09-26 03:07:19 +04:00
|
|
|
goto try_again;
|
|
|
|
/* Do or do not. There is no try. -- Yoda */
|
|
|
|
e = lc_get(mdev->resync, enr);
|
|
|
|
bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL;
|
|
|
|
if (!bm_ext) {
|
|
|
|
const unsigned long rs_flags = mdev->resync->flags;
|
|
|
|
if (rs_flags & LC_STARVING)
|
|
|
|
dev_warn(DEV, "Have to wait for element"
|
|
|
|
" (resync LRU too small?)\n");
|
2011-02-21 15:21:01 +03:00
|
|
|
BUG_ON(rs_flags & LC_LOCKED);
|
2009-09-26 03:07:19 +04:00
|
|
|
goto try_again;
|
|
|
|
}
|
|
|
|
if (bm_ext->lce.lc_number != enr) {
|
|
|
|
bm_ext->rs_left = drbd_bm_e_weight(mdev, enr);
|
|
|
|
bm_ext->rs_failed = 0;
|
2011-02-21 15:21:01 +03:00
|
|
|
lc_committed(mdev->resync);
|
2009-09-26 03:07:19 +04:00
|
|
|
wake_up(&mdev->al_wait);
|
|
|
|
D_ASSERT(test_bit(BME_LOCKED, &bm_ext->flags) == 0);
|
|
|
|
}
|
|
|
|
set_bit(BME_NO_WRITES, &bm_ext->flags);
|
|
|
|
D_ASSERT(bm_ext->lce.refcnt == 1);
|
|
|
|
mdev->resync_locked++;
|
|
|
|
goto check_al;
|
|
|
|
}
|
|
|
|
check_al:
|
|
|
|
for (i = 0; i < AL_EXT_PER_BM_SECT; i++) {
|
|
|
|
if (lc_is_used(mdev->act_log, al_enr+i))
|
|
|
|
goto try_again;
|
|
|
|
}
|
|
|
|
set_bit(BME_LOCKED, &bm_ext->flags);
|
|
|
|
proceed:
|
|
|
|
mdev->resync_wenr = LC_FREE;
|
|
|
|
spin_unlock_irq(&mdev->al_lock);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
try_again:
|
|
|
|
if (bm_ext)
|
|
|
|
mdev->resync_wenr = enr;
|
|
|
|
spin_unlock_irq(&mdev->al_lock);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
void drbd_rs_complete_io(struct drbd_conf *mdev, sector_t sector)
|
|
|
|
{
|
|
|
|
unsigned int enr = BM_SECT_TO_EXT(sector);
|
|
|
|
struct lc_element *e;
|
|
|
|
struct bm_extent *bm_ext;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&mdev->al_lock, flags);
|
|
|
|
e = lc_find(mdev->resync, enr);
|
|
|
|
bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL;
|
|
|
|
if (!bm_ext) {
|
|
|
|
spin_unlock_irqrestore(&mdev->al_lock, flags);
|
|
|
|
if (__ratelimit(&drbd_ratelimit_state))
|
|
|
|
dev_err(DEV, "drbd_rs_complete_io() called, but extent not found\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bm_ext->lce.refcnt == 0) {
|
|
|
|
spin_unlock_irqrestore(&mdev->al_lock, flags);
|
|
|
|
dev_err(DEV, "drbd_rs_complete_io(,%llu [=%u]) called, "
|
|
|
|
"but refcnt is 0!?\n",
|
|
|
|
(unsigned long long)sector, enr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lc_put(mdev->resync, &bm_ext->lce) == 0) {
|
2010-11-07 17:56:29 +03:00
|
|
|
bm_ext->flags = 0; /* clear BME_LOCKED, BME_NO_WRITES and BME_PRIORITY */
|
2009-09-26 03:07:19 +04:00
|
|
|
mdev->resync_locked--;
|
|
|
|
wake_up(&mdev->al_wait);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&mdev->al_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drbd_rs_cancel_all() - Removes all extents from the resync LRU (even BME_LOCKED)
|
|
|
|
* @mdev: DRBD device.
|
|
|
|
*/
|
|
|
|
void drbd_rs_cancel_all(struct drbd_conf *mdev)
|
|
|
|
{
|
|
|
|
spin_lock_irq(&mdev->al_lock);
|
|
|
|
|
|
|
|
if (get_ldev_if_state(mdev, D_FAILED)) { /* Makes sure ->resync is there. */
|
|
|
|
lc_reset(mdev->resync);
|
|
|
|
put_ldev(mdev);
|
|
|
|
}
|
|
|
|
mdev->resync_locked = 0;
|
|
|
|
mdev->resync_wenr = LC_FREE;
|
|
|
|
spin_unlock_irq(&mdev->al_lock);
|
|
|
|
wake_up(&mdev->al_wait);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drbd_rs_del_all() - Gracefully remove all extents from the resync LRU
|
|
|
|
* @mdev: DRBD device.
|
|
|
|
*
|
|
|
|
* Returns 0 upon success, -EAGAIN if at least one reference count was
|
|
|
|
* not zero.
|
|
|
|
*/
|
|
|
|
int drbd_rs_del_all(struct drbd_conf *mdev)
|
|
|
|
{
|
|
|
|
struct lc_element *e;
|
|
|
|
struct bm_extent *bm_ext;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
spin_lock_irq(&mdev->al_lock);
|
|
|
|
|
|
|
|
if (get_ldev_if_state(mdev, D_FAILED)) {
|
|
|
|
/* ok, ->resync is there. */
|
|
|
|
for (i = 0; i < mdev->resync->nr_elements; i++) {
|
|
|
|
e = lc_element_by_index(mdev->resync, i);
|
2010-04-02 10:40:33 +04:00
|
|
|
bm_ext = lc_entry(e, struct bm_extent, lce);
|
2009-09-26 03:07:19 +04:00
|
|
|
if (bm_ext->lce.lc_number == LC_FREE)
|
|
|
|
continue;
|
|
|
|
if (bm_ext->lce.lc_number == mdev->resync_wenr) {
|
|
|
|
dev_info(DEV, "dropping %u in drbd_rs_del_all, apparently"
|
|
|
|
" got 'synced' by application io\n",
|
|
|
|
mdev->resync_wenr);
|
|
|
|
D_ASSERT(!test_bit(BME_LOCKED, &bm_ext->flags));
|
|
|
|
D_ASSERT(test_bit(BME_NO_WRITES, &bm_ext->flags));
|
|
|
|
clear_bit(BME_NO_WRITES, &bm_ext->flags);
|
|
|
|
mdev->resync_wenr = LC_FREE;
|
|
|
|
lc_put(mdev->resync, &bm_ext->lce);
|
|
|
|
}
|
|
|
|
if (bm_ext->lce.refcnt != 0) {
|
|
|
|
dev_info(DEV, "Retrying drbd_rs_del_all() later. "
|
|
|
|
"refcnt=%d\n", bm_ext->lce.refcnt);
|
|
|
|
put_ldev(mdev);
|
|
|
|
spin_unlock_irq(&mdev->al_lock);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
D_ASSERT(!test_bit(BME_LOCKED, &bm_ext->flags));
|
|
|
|
D_ASSERT(!test_bit(BME_NO_WRITES, &bm_ext->flags));
|
|
|
|
lc_del(mdev->resync, &bm_ext->lce);
|
|
|
|
}
|
|
|
|
D_ASSERT(mdev->resync->used == 0);
|
|
|
|
put_ldev(mdev);
|
|
|
|
}
|
|
|
|
spin_unlock_irq(&mdev->al_lock);
|
2012-03-26 18:21:37 +04:00
|
|
|
wake_up(&mdev->al_wait);
|
2009-09-26 03:07:19 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drbd_rs_failed_io() - Record information on a failure to resync the specified blocks
|
|
|
|
* @mdev: DRBD device.
|
|
|
|
* @sector: The sector number.
|
|
|
|
* @size: Size of failed IO operation, in byte.
|
|
|
|
*/
|
|
|
|
void drbd_rs_failed_io(struct drbd_conf *mdev, sector_t sector, int size)
|
|
|
|
{
|
|
|
|
/* Is called from worker and receiver context _only_ */
|
|
|
|
unsigned long sbnr, ebnr, lbnr;
|
|
|
|
unsigned long count;
|
|
|
|
sector_t esector, nr_sectors;
|
|
|
|
int wake_up = 0;
|
|
|
|
|
2011-02-21 14:41:39 +03:00
|
|
|
if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) {
|
2009-09-26 03:07:19 +04:00
|
|
|
dev_err(DEV, "drbd_rs_failed_io: sector=%llus size=%d nonsense!\n",
|
|
|
|
(unsigned long long)sector, size);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nr_sectors = drbd_get_capacity(mdev->this_bdev);
|
|
|
|
esector = sector + (size >> 9) - 1;
|
|
|
|
|
2010-12-15 21:31:20 +03:00
|
|
|
if (!expect(sector < nr_sectors))
|
|
|
|
return;
|
|
|
|
if (!expect(esector < nr_sectors))
|
|
|
|
esector = nr_sectors - 1;
|
2009-09-26 03:07:19 +04:00
|
|
|
|
|
|
|
lbnr = BM_SECT_TO_BIT(nr_sectors-1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* round up start sector, round down end sector. we make sure we only
|
|
|
|
* handle full, aligned, BM_BLOCK_SIZE (4K) blocks */
|
|
|
|
if (unlikely(esector < BM_SECT_PER_BIT-1))
|
|
|
|
return;
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (sbnr > ebnr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ok, (capacity & 7) != 0 sometimes, but who cares...
|
|
|
|
* we count rs_{total,left} in bits, not sectors.
|
|
|
|
*/
|
|
|
|
spin_lock_irq(&mdev->al_lock);
|
|
|
|
count = drbd_bm_count_bits(mdev, sbnr, ebnr);
|
|
|
|
if (count) {
|
|
|
|
mdev->rs_failed += count;
|
|
|
|
|
|
|
|
if (get_ldev(mdev)) {
|
2010-12-09 17:03:57 +03:00
|
|
|
drbd_try_clear_on_disk_bm(mdev, sector, count, false);
|
2009-09-26 03:07:19 +04:00
|
|
|
put_ldev(mdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* just wake_up unconditional now, various lc_chaged(),
|
|
|
|
* lc_put() in drbd_try_clear_on_disk_bm(). */
|
|
|
|
wake_up = 1;
|
|
|
|
}
|
|
|
|
spin_unlock_irq(&mdev->al_lock);
|
|
|
|
if (wake_up)
|
|
|
|
wake_up(&mdev->al_wait);
|
|
|
|
}
|