Skip to content

Commit

Permalink
drbd: make suspend_io() / resume_io() must be thread and recursion safe
Browse files Browse the repository at this point in the history
Avoid to prematurely resume application IO: don't set/clear a single
bit, but inc/dec an atomic counter.

Signed-off-by: Philipp Reisner <[email protected]>
Signed-off-by: Lars Ellenberg <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Philipp-Reisner authored and axboe committed Nov 25, 2015
1 parent f85d9f2 commit 7dbb438
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions drivers/block/drbd/drbd_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ enum {

MD_NO_FUA, /* Users wants us to not use FUA/FLUSH on meta data dev */

SUSPEND_IO, /* suspend application io */
BITMAP_IO, /* suspend application io;
once no more io in flight, start bitmap io */
BITMAP_IO_QUEUED, /* Started bitmap IO */
Expand Down Expand Up @@ -880,6 +879,7 @@ struct drbd_device {
atomic_t rs_pending_cnt; /* RS request/data packets on the wire */
atomic_t unacked_cnt; /* Need to send replies for */
atomic_t local_cnt; /* Waiting for local completion */
atomic_t suspend_cnt;

/* Interval tree of pending local requests */
struct rb_root read_requests;
Expand Down Expand Up @@ -2263,7 +2263,7 @@ static inline bool may_inc_ap_bio(struct drbd_device *device)

if (drbd_suspended(device))
return false;
if (test_bit(SUSPEND_IO, &device->flags))
if (atomic_read(&device->suspend_cnt))
return false;

/* to avoid potential deadlock or bitmap corruption,
Expand Down
8 changes: 5 additions & 3 deletions drivers/block/drbd/drbd_nl.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,18 +865,20 @@ char *ppsize(char *buf, unsigned long long size)
* and can be long lived.
* This changes an device->flag, is triggered by drbd internals,
* and should be short-lived. */
/* It needs to be a counter, since multiple threads might
independently suspend and resume IO. */
void drbd_suspend_io(struct drbd_device *device)
{
set_bit(SUSPEND_IO, &device->flags);
atomic_inc(&device->suspend_cnt);
if (drbd_suspended(device))
return;
wait_event(device->misc_wait, !atomic_read(&device->ap_bio_cnt));
}

void drbd_resume_io(struct drbd_device *device)
{
clear_bit(SUSPEND_IO, &device->flags);
wake_up(&device->misc_wait);
if (atomic_dec_and_test(&device->suspend_cnt))
wake_up(&device->misc_wait);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion drivers/block/drbd/drbd_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ int drbd_bitmap_io_from_worker(struct drbd_device *device,
D_ASSERT(device, current == first_peer_device(device)->connection->worker.task);

/* open coded non-blocking drbd_suspend_io(device); */
set_bit(SUSPEND_IO, &device->flags);
atomic_inc(&device->suspend_cnt);

drbd_bm_lock(device, why, flags);
rv = io_fn(device);
Expand Down

0 comments on commit 7dbb438

Please sign in to comment.