diff options
author | Andreas Gruenbacher <agruen@linbit.com> | 2011-03-16 15:31:39 +0100 |
---|---|---|
committer | Philipp Reisner <philipp.reisner@linbit.com> | 2012-11-08 16:44:43 +0100 |
commit | 99920dc5c5fe52182fe922aa70330861e2b6418b (patch) | |
tree | 51890fb25f704bf1cbea56695d794be8166deb81 /drivers/block/drbd/drbd_worker.c | |
parent | b2f0ab62ecfe8711fefb82223b40430f8141a949 (diff) |
drbd: Make all worker callbacks return 0 upon success and an error code otherwise
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
Diffstat (limited to 'drivers/block/drbd/drbd_worker.c')
-rw-r--r-- | drivers/block/drbd/drbd_worker.c | 196 |
1 files changed, 99 insertions, 97 deletions
diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c index d38bf70a16d..0f0beec9a19 100644 --- a/drivers/block/drbd/drbd_worker.c +++ b/drivers/block/drbd/drbd_worker.c @@ -225,7 +225,7 @@ void drbd_request_endio(struct bio *bio, int error) complete_master_bio(mdev, &m); } -long w_read_retry_remote(struct drbd_work *w, int cancel) +int w_read_retry_remote(struct drbd_work *w, int cancel) { struct drbd_request *req = container_of(w, struct drbd_request, w); struct drbd_conf *mdev = w->mdev; @@ -238,7 +238,7 @@ long w_read_retry_remote(struct drbd_work *w, int cancel) if (cancel || mdev->state.pdsk != D_UP_TO_DATE) { _req_mod(req, READ_RETRY_REMOTE_CANCELED); spin_unlock_irq(&mdev->tconn->req_lock); - return 1; + return 0; } spin_unlock_irq(&mdev->tconn->req_lock); @@ -294,13 +294,13 @@ void drbd_csum_bio(struct drbd_conf *mdev, struct crypto_hash *tfm, struct bio * } /* MAYBE merge common code with w_e_end_ov_req */ -static long w_e_send_csum(struct drbd_work *w, int cancel) +static int w_e_send_csum(struct drbd_work *w, int cancel) { struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); struct drbd_conf *mdev = w->mdev; int digest_size; void *digest; - int ok = 1; + int err = 0; if (unlikely(cancel)) goto out; @@ -322,22 +322,22 @@ static long w_e_send_csum(struct drbd_work *w, int cancel) drbd_free_ee(mdev, peer_req); peer_req = NULL; inc_rs_pending(mdev); - ok = !drbd_send_drequest_csum(mdev, sector, size, + err = drbd_send_drequest_csum(mdev, sector, size, digest, digest_size, P_CSUM_RS_REQUEST); kfree(digest); } else { dev_err(DEV, "kmalloc() of digest failed.\n"); - ok = 0; + err = -ENOMEM; } out: if (peer_req) drbd_free_ee(mdev, peer_req); - if (unlikely(!ok)) + if (unlikely(err)) dev_err(DEV, "drbd_send_drequest(..., csum) failed\n"); - return ok; + return err; } #define GFP_TRY (__GFP_HIGHMEM | __GFP_NOWARN) @@ -381,7 +381,7 @@ defer: return -EAGAIN; } -long w_resync_timer(struct drbd_work *w, int cancel) +int w_resync_timer(struct drbd_work *w, int cancel) { struct drbd_conf *mdev = w->mdev; switch (mdev->state.conn) { @@ -393,7 +393,7 @@ long w_resync_timer(struct drbd_work *w, int cancel) break; } - return 1; + return 0; } void resync_timer_fn(unsigned long data) @@ -503,7 +503,7 @@ static int drbd_rs_number_requests(struct drbd_conf *mdev) return number; } -long w_make_resync_request(struct drbd_work *w, int cancel) +int w_make_resync_request(struct drbd_work *w, int cancel) { struct drbd_conf *mdev = w->mdev; unsigned long bit; @@ -515,12 +515,12 @@ long w_make_resync_request(struct drbd_work *w, int cancel) int i = 0; if (unlikely(cancel)) - return 1; + return 0; if (mdev->rs_total == 0) { /* empty resync? */ drbd_resync_finished(mdev); - return 1; + return 0; } if (!get_ldev(mdev)) { @@ -529,7 +529,7 @@ long w_make_resync_request(struct drbd_work *w, int cancel) to continue resync with a broken disk makes no sense at all */ dev_err(DEV, "Disk broke down during resync!\n"); - return 1; + return 0; } max_bio_size = queue_max_hw_sectors(mdev->rq_queue) << 9; @@ -558,7 +558,7 @@ next_sector: if (bit == DRBD_END_OF_BITMAP) { mdev->bm_resync_fo = drbd_bm_bits(mdev); put_ldev(mdev); - return 1; + return 0; } sector = BM_BIT_TO_SECT(bit); @@ -621,7 +621,7 @@ next_sector: switch (read_for_csum(mdev, sector, size)) { case -EIO: /* Disk failure */ put_ldev(mdev); - return 0; + return -EIO; case -EAGAIN: /* allocation failed, or ldev busy */ drbd_rs_complete_io(mdev, sector); mdev->bm_resync_fo = BM_SECT_TO_BIT(sector); @@ -634,13 +634,16 @@ next_sector: BUG(); } } else { + int err; + inc_rs_pending(mdev); - if (drbd_send_drequest(mdev, P_RS_DATA_REQUEST, - sector, size, ID_SYNCER)) { + err = drbd_send_drequest(mdev, P_RS_DATA_REQUEST, + sector, size, ID_SYNCER); + if (err) { dev_err(DEV, "drbd_send_drequest() failed, aborting...\n"); dec_rs_pending(mdev); put_ldev(mdev); - return 0; + return err; } } } @@ -653,14 +656,14 @@ next_sector: * until then resync "work" is "inactive" ... */ put_ldev(mdev); - return 1; + return 0; } requeue: mdev->rs_in_flight += (i << (BM_BLOCK_SHIFT - 9)); mod_timer(&mdev->resync_timer, jiffies + SLEEP_TIME); put_ldev(mdev); - return 1; + return 0; } static int w_make_ov_request(struct drbd_work *w, int cancel) @@ -707,24 +710,24 @@ static int w_make_ov_request(struct drbd_work *w, int cancel) return 1; } -long w_ov_finished(struct drbd_work *w, int cancel) +int w_ov_finished(struct drbd_work *w, int cancel) { struct drbd_conf *mdev = w->mdev; kfree(w); ov_oos_print(mdev); drbd_resync_finished(mdev); - return 1; + return 0; } -static long w_resync_finished(struct drbd_work *w, int cancel) +static int w_resync_finished(struct drbd_work *w, int cancel) { struct drbd_conf *mdev = w->mdev; kfree(w); drbd_resync_finished(mdev); - return 1; + return 0; } static void ping_peer(struct drbd_conf *mdev) @@ -905,35 +908,35 @@ static void move_to_net_ee_or_free(struct drbd_conf *mdev, struct drbd_peer_requ * @w: work object. * @cancel: The connection will be closed anyways */ -long w_e_end_data_req(struct drbd_work *w, int cancel) +int w_e_end_data_req(struct drbd_work *w, int cancel) { struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); struct drbd_conf *mdev = w->mdev; - int ok; + int err; if (unlikely(cancel)) { drbd_free_ee(mdev, peer_req); dec_unacked(mdev); - return 1; + return 0; } if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { - ok = !drbd_send_block(mdev, P_DATA_REPLY, peer_req); + err = drbd_send_block(mdev, P_DATA_REPLY, peer_req); } else { if (__ratelimit(&drbd_ratelimit_state)) dev_err(DEV, "Sending NegDReply. sector=%llus.\n", (unsigned long long)peer_req->i.sector); - ok = !drbd_send_ack(mdev, P_NEG_DREPLY, peer_req); + err = drbd_send_ack(mdev, P_NEG_DREPLY, peer_req); } dec_unacked(mdev); move_to_net_ee_or_free(mdev, peer_req); - if (unlikely(!ok)) + if (unlikely(err)) dev_err(DEV, "drbd_send_block() failed\n"); - return ok; + return err; } /** @@ -942,16 +945,16 @@ long w_e_end_data_req(struct drbd_work *w, int cancel) * @w: work object. * @cancel: The connection will be closed anyways */ -long w_e_end_rsdata_req(struct drbd_work *w, int cancel) +int w_e_end_rsdata_req(struct drbd_work *w, int cancel) { struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); struct drbd_conf *mdev = w->mdev; - int ok; + int err; if (unlikely(cancel)) { drbd_free_ee(mdev, peer_req); dec_unacked(mdev); - return 1; + return 0; } if (get_ldev_if_state(mdev, D_FAILED)) { @@ -960,23 +963,23 @@ long w_e_end_rsdata_req(struct drbd_work *w, int cancel) } if (mdev->state.conn == C_AHEAD) { - ok = !drbd_send_ack(mdev, P_RS_CANCEL, peer_req); + err = drbd_send_ack(mdev, P_RS_CANCEL, peer_req); } else if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { if (likely(mdev->state.pdsk >= D_INCONSISTENT)) { inc_rs_pending(mdev); - ok = !drbd_send_block(mdev, P_RS_DATA_REPLY, peer_req); + err = drbd_send_block(mdev, P_RS_DATA_REPLY, peer_req); } else { if (__ratelimit(&drbd_ratelimit_state)) dev_err(DEV, "Not sending RSDataReply, " "partner DISKLESS!\n"); - ok = 1; + err = 0; } } else { if (__ratelimit(&drbd_ratelimit_state)) dev_err(DEV, "Sending NegRSDReply. sector %llus.\n", (unsigned long long)peer_req->i.sector); - ok = !drbd_send_ack(mdev, P_NEG_RS_DREPLY, peer_req); + err = drbd_send_ack(mdev, P_NEG_RS_DREPLY, peer_req); /* update resync data with failure */ drbd_rs_failed_io(mdev, peer_req->i.sector, peer_req->i.size); @@ -986,24 +989,24 @@ long w_e_end_rsdata_req(struct drbd_work *w, int cancel) move_to_net_ee_or_free(mdev, peer_req); - if (unlikely(!ok)) + if (unlikely(err)) dev_err(DEV, "drbd_send_block() failed\n"); - return ok; + return err; } -long w_e_end_csum_rs_req(struct drbd_work *w, int cancel) +int w_e_end_csum_rs_req(struct drbd_work *w, int cancel) { struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); struct drbd_conf *mdev = w->mdev; struct digest_info *di; int digest_size; void *digest = NULL; - int ok, eq = 0; + int err, eq = 0; if (unlikely(cancel)) { drbd_free_ee(mdev, peer_req); dec_unacked(mdev); - return 1; + return 0; } if (get_ldev(mdev)) { @@ -1032,16 +1035,16 @@ long w_e_end_csum_rs_req(struct drbd_work *w, int cancel) drbd_set_in_sync(mdev, peer_req->i.sector, peer_req->i.size); /* rs_same_csums unit is BM_BLOCK_SIZE */ mdev->rs_same_csum += peer_req->i.size >> BM_BLOCK_SHIFT; - ok = !drbd_send_ack(mdev, P_RS_IS_IN_SYNC, peer_req); + err = drbd_send_ack(mdev, P_RS_IS_IN_SYNC, peer_req); } else { inc_rs_pending(mdev); peer_req->block_id = ID_SYNCER; /* By setting block_id, digest pointer becomes invalid! */ peer_req->flags &= ~EE_HAS_DIGEST; /* This peer request no longer has a digest pointer */ kfree(di); - ok = !drbd_send_block(mdev, P_RS_DATA_REPLY, peer_req); + err = drbd_send_block(mdev, P_RS_DATA_REPLY, peer_req); } } else { - ok = !drbd_send_ack(mdev, P_NEG_RS_DREPLY, peer_req); + err = drbd_send_ack(mdev, P_NEG_RS_DREPLY, peer_req); if (__ratelimit(&drbd_ratelimit_state)) dev_err(DEV, "Sending NegDReply. I guess it gets messy.\n"); } @@ -1049,12 +1052,12 @@ long w_e_end_csum_rs_req(struct drbd_work *w, int cancel) dec_unacked(mdev); move_to_net_ee_or_free(mdev, peer_req); - if (unlikely(!ok)) + if (unlikely(err)) dev_err(DEV, "drbd_send_block/ack() failed\n"); - return ok; + return err; } -long w_e_end_ov_req(struct drbd_work *w, int cancel) +int w_e_end_ov_req(struct drbd_work *w, int cancel) { struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); struct drbd_conf *mdev = w->mdev; @@ -1062,7 +1065,7 @@ long w_e_end_ov_req(struct drbd_work *w, int cancel) unsigned int size = peer_req->i.size; int digest_size; void *digest; - int ok = 1; + int err = 0; if (unlikely(cancel)) goto out; @@ -1070,7 +1073,7 @@ long w_e_end_ov_req(struct drbd_work *w, int cancel) digest_size = crypto_hash_digestsize(mdev->tconn->verify_tfm); digest = kmalloc(digest_size, GFP_NOIO); if (!digest) { - ok = 0; /* terminate the connection in case the allocation failed */ + err = 1; /* terminate the connection in case the allocation failed */ goto out; } @@ -1087,10 +1090,8 @@ long w_e_end_ov_req(struct drbd_work *w, int cancel) drbd_free_ee(mdev, peer_req); peer_req = NULL; inc_rs_pending(mdev); - ok = !drbd_send_drequest_csum(mdev, sector, size, - digest, digest_size, - P_OV_REPLY); - if (!ok) + err = drbd_send_drequest_csum(mdev, sector, size, digest, digest_size, P_OV_REPLY); + if (err) dec_rs_pending(mdev); kfree(digest); @@ -1098,7 +1099,7 @@ out: if (peer_req) drbd_free_ee(mdev, peer_req); dec_unacked(mdev); - return ok; + return err; } void drbd_ov_oos_found(struct drbd_conf *mdev, sector_t sector, int size) @@ -1112,7 +1113,7 @@ void drbd_ov_oos_found(struct drbd_conf *mdev, sector_t sector, int size) drbd_set_out_of_sync(mdev, sector, size); } -long w_e_end_ov_reply(struct drbd_work *w, int cancel) +int w_e_end_ov_reply(struct drbd_work *w, int cancel) { struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); struct drbd_conf *mdev = w->mdev; @@ -1121,12 +1122,12 @@ long w_e_end_ov_reply(struct drbd_work *w, int cancel) sector_t sector = peer_req->i.sector; unsigned int size = peer_req->i.size; int digest_size; - int ok, eq = 0; + int err, eq = 0; if (unlikely(cancel)) { drbd_free_ee(mdev, peer_req); dec_unacked(mdev); - return 1; + return 0; } /* after "cancel", because after drbd_disconnect/drbd_rs_cancel_all @@ -1161,7 +1162,7 @@ long w_e_end_ov_reply(struct drbd_work *w, int cancel) else ov_oos_print(mdev); - ok = !drbd_send_ack_ex(mdev, P_OV_RESULT, sector, size, + err = drbd_send_ack_ex(mdev, P_OV_RESULT, sector, size, eq ? ID_IN_SYNC : ID_OUT_OF_SYNC); dec_unacked(mdev); @@ -1177,23 +1178,23 @@ long w_e_end_ov_reply(struct drbd_work *w, int cancel) drbd_resync_finished(mdev); } - return ok; + return err; } -long w_prev_work_done(struct drbd_work *w, int cancel) +int w_prev_work_done(struct drbd_work *w, int cancel) { struct drbd_wq_barrier *b = container_of(w, struct drbd_wq_barrier, w); complete(&b->done); - return 1; + return 0; } -long w_send_barrier(struct drbd_work *w, int cancel) +int w_send_barrier(struct drbd_work *w, int cancel) { struct drbd_tl_epoch *b = container_of(w, struct drbd_tl_epoch, w); struct drbd_conf *mdev = w->mdev; struct p_barrier *p = &mdev->tconn->data.sbuf.barrier; - int ok = 1; + int err = 0; /* really avoid racing with tl_clear. w.cb may have been referenced * just before it was reassigned and re-queued, so double check that. @@ -1205,44 +1206,45 @@ long w_send_barrier(struct drbd_work *w, int cancel) cancel = 1; spin_unlock_irq(&mdev->tconn->req_lock); if (cancel) - return 1; - - if (drbd_get_data_sock(mdev->tconn)) return 0; + + err = drbd_get_data_sock(mdev->tconn); + if (err) + return err; p->barrier = b->br_number; /* inc_ap_pending was done where this was queued. * dec_ap_pending will be done in got_BarrierAck * or (on connection loss) in w_clear_epoch. */ - ok = !_drbd_send_cmd(mdev, mdev->tconn->data.socket, P_BARRIER, + err = _drbd_send_cmd(mdev, mdev->tconn->data.socket, P_BARRIER, &p->head, sizeof(*p), 0); drbd_put_data_sock(mdev->tconn); - return ok; + return err; } -long w_send_write_hint(struct drbd_work *w, int cancel) +int w_send_write_hint(struct drbd_work *w, int cancel) { struct drbd_conf *mdev = w->mdev; if (cancel) - return 1; - return !drbd_send_short_cmd(mdev, P_UNPLUG_REMOTE); + return 0; + return drbd_send_short_cmd(mdev, P_UNPLUG_REMOTE); } -long w_send_oos(struct drbd_work *w, int cancel) +int w_send_oos(struct drbd_work *w, int cancel) { struct drbd_request *req = container_of(w, struct drbd_request, w); struct drbd_conf *mdev = w->mdev; - int ok; + int err; if (unlikely(cancel)) { req_mod(req, SEND_CANCELED); - return 1; + return 0; } - ok = !drbd_send_oos(mdev, req); + err = drbd_send_oos(mdev, req); req_mod(req, OOS_HANDED_TO_NETWORK); - return ok; + return err; } /** @@ -1251,21 +1253,21 @@ long w_send_oos(struct drbd_work *w, int cancel) * @w: work object. * @cancel: The connection will be closed anyways */ -long w_send_dblock(struct drbd_work *w, int cancel) +int w_send_dblock(struct drbd_work *w, int cancel) { struct drbd_request *req = container_of(w, struct drbd_request, w); struct drbd_conf *mdev = w->mdev; - int ok; + int err; if (unlikely(cancel)) { req_mod(req, SEND_CANCELED); - return 1; + return 0; } - ok = !drbd_send_dblock(mdev, req); - req_mod(req, ok ? HANDED_OVER_TO_NETWORK : SEND_FAILED); + err = drbd_send_dblock(mdev, req); + req_mod(req, err ? SEND_FAILED : HANDED_OVER_TO_NETWORK); - return ok; + return err; } /** @@ -1274,26 +1276,26 @@ long w_send_dblock(struct drbd_work *w, int cancel) * @w: work object. * @cancel: The connection will be closed anyways */ -long w_send_read_req(struct drbd_work *w, int cancel) +int w_send_read_req(struct drbd_work *w, int cancel) { struct drbd_request *req = container_of(w, struct drbd_request, w); struct drbd_conf *mdev = w->mdev; - int ok; + int err; if (unlikely(cancel)) { req_mod(req, SEND_CANCELED); - return 1; + return 0; } - ok = !drbd_send_drequest(mdev, P_DATA_REQUEST, req->i.sector, req->i.size, + err = drbd_send_drequest(mdev, P_DATA_REQUEST, req->i.sector, req->i.size, (unsigned long)req); - req_mod(req, ok ? HANDED_OVER_TO_NETWORK : SEND_FAILED); + req_mod(req, err ? SEND_FAILED : HANDED_OVER_TO_NETWORK); - return ok; + return err; } -long w_restart_disk_io(struct drbd_work *w, int cancel) +int w_restart_disk_io(struct drbd_work *w, int cancel) { struct drbd_request *req = container_of(w, struct drbd_request, w); struct drbd_conf *mdev = w->mdev; @@ -1309,7 +1311,7 @@ long w_restart_disk_io(struct drbd_work *w, int cancel) req->private_bio->bi_bdev = mdev->ldev->backing_bdev; generic_make_request(req->private_bio); - return 1; + return 0; } static int _drbd_may_sync_now(struct drbd_conf *mdev) @@ -1450,7 +1452,7 @@ void start_resync_timer_fn(unsigned long data) drbd_queue_work(&mdev->tconn->data.work, &mdev->start_resync_work); } -long w_start_resync(struct drbd_work *w, int cancel) +int w_start_resync(struct drbd_work *w, int cancel) { struct drbd_conf *mdev = w->mdev; @@ -1458,12 +1460,12 @@ long w_start_resync(struct drbd_work *w, int cancel) dev_warn(DEV, "w_start_resync later...\n"); mdev->start_resync_timer.expires = jiffies + HZ/10; add_timer(&mdev->start_resync_timer); - return 1; + return 0; } drbd_start_resync(mdev, C_SYNC_SOURCE); clear_bit(AHEAD_TO_SYNC_SOURCE, &mdev->current_epoch->flags); - return 1; + return 0; } /** @@ -1691,7 +1693,7 @@ int drbd_worker(struct drbd_thread *thi) list_del_init(&w->list); spin_unlock_irq(&tconn->data.work.q_lock); - if (!w->cb(w, tconn->cstate < C_WF_REPORT_PARAMS)) { + if (w->cb(w, tconn->cstate < C_WF_REPORT_PARAMS)) { /* dev_warn(DEV, "worker: a callback failed! \n"); */ if (tconn->cstate >= C_WF_REPORT_PARAMS) conn_request_state(tconn, NS(conn, C_NETWORK_FAILURE), CS_HARD); |