diff options
author | Lars Ellenberg <lars.ellenberg@linbit.com> | 2013-11-22 06:40:58 -0500 |
---|---|---|
committer | Philipp Reisner <philipp.reisner@linbit.com> | 2014-07-10 09:22:22 -0400 |
commit | 44a4d551846b8c61aa430b9432c1fcdf88444708 (patch) | |
tree | 8188189bed59234fdf943702ebb55c9c17106215 /drivers/block/drbd/drbd_state.c | |
parent | 35b5ed5bbac2432acdfce1d9dec8dbf8fe7d60dd (diff) |
drbd: refactor use of first_peer_device()
Reduce the number of calls to first_peer_device(). Instead, call
first_peer_device() just once to assign a local variable peer_device.
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_state.c')
-rw-r--r-- | drivers/block/drbd/drbd_state.c | 65 |
1 files changed, 33 insertions, 32 deletions
diff --git a/drivers/block/drbd/drbd_state.c b/drivers/block/drbd/drbd_state.c index a5d8aae00e04..19da7c7590cd 100644 --- a/drivers/block/drbd/drbd_state.c +++ b/drivers/block/drbd/drbd_state.c | |||
@@ -952,6 +952,8 @@ enum drbd_state_rv | |||
952 | __drbd_set_state(struct drbd_device *device, union drbd_state ns, | 952 | __drbd_set_state(struct drbd_device *device, union drbd_state ns, |
953 | enum chg_state_flags flags, struct completion *done) | 953 | enum chg_state_flags flags, struct completion *done) |
954 | { | 954 | { |
955 | struct drbd_peer_device *peer_device = first_peer_device(device); | ||
956 | struct drbd_connection *connection = peer_device ? peer_device->connection : NULL; | ||
955 | union drbd_state os; | 957 | union drbd_state os; |
956 | enum drbd_state_rv rv = SS_SUCCESS; | 958 | enum drbd_state_rv rv = SS_SUCCESS; |
957 | enum sanitize_state_warnings ssw; | 959 | enum sanitize_state_warnings ssw; |
@@ -978,9 +980,9 @@ __drbd_set_state(struct drbd_device *device, union drbd_state ns, | |||
978 | this happen...*/ | 980 | this happen...*/ |
979 | 981 | ||
980 | if (is_valid_state(device, os) == rv) | 982 | if (is_valid_state(device, os) == rv) |
981 | rv = is_valid_soft_transition(os, ns, first_peer_device(device)->connection); | 983 | rv = is_valid_soft_transition(os, ns, connection); |
982 | } else | 984 | } else |
983 | rv = is_valid_soft_transition(os, ns, first_peer_device(device)->connection); | 985 | rv = is_valid_soft_transition(os, ns, connection); |
984 | } | 986 | } |
985 | 987 | ||
986 | if (rv < SS_SUCCESS) { | 988 | if (rv < SS_SUCCESS) { |
@@ -997,7 +999,7 @@ __drbd_set_state(struct drbd_device *device, union drbd_state ns, | |||
997 | sanitize_state(). Only display it here if we where not called from | 999 | sanitize_state(). Only display it here if we where not called from |
998 | _conn_request_state() */ | 1000 | _conn_request_state() */ |
999 | if (!(flags & CS_DC_SUSP)) | 1001 | if (!(flags & CS_DC_SUSP)) |
1000 | conn_pr_state_change(first_peer_device(device)->connection, os, ns, | 1002 | conn_pr_state_change(connection, os, ns, |
1001 | (flags & ~CS_DC_MASK) | CS_DC_SUSP); | 1003 | (flags & ~CS_DC_MASK) | CS_DC_SUSP); |
1002 | 1004 | ||
1003 | /* if we are going -> D_FAILED or D_DISKLESS, grab one extra reference | 1005 | /* if we are going -> D_FAILED or D_DISKLESS, grab one extra reference |
@@ -1017,19 +1019,19 @@ __drbd_set_state(struct drbd_device *device, union drbd_state ns, | |||
1017 | 1019 | ||
1018 | /* put replicated vs not-replicated requests in seperate epochs */ | 1020 | /* put replicated vs not-replicated requests in seperate epochs */ |
1019 | if (did_remote != should_do_remote) | 1021 | if (did_remote != should_do_remote) |
1020 | start_new_tl_epoch(first_peer_device(device)->connection); | 1022 | start_new_tl_epoch(connection); |
1021 | 1023 | ||
1022 | if (os.disk == D_ATTACHING && ns.disk >= D_NEGOTIATING) | 1024 | if (os.disk == D_ATTACHING && ns.disk >= D_NEGOTIATING) |
1023 | drbd_print_uuids(device, "attached to UUIDs"); | 1025 | drbd_print_uuids(device, "attached to UUIDs"); |
1024 | 1026 | ||
1025 | /* Wake up role changes, that were delayed because of connection establishing */ | 1027 | /* Wake up role changes, that were delayed because of connection establishing */ |
1026 | if (os.conn == C_WF_REPORT_PARAMS && ns.conn != C_WF_REPORT_PARAMS && | 1028 | if (os.conn == C_WF_REPORT_PARAMS && ns.conn != C_WF_REPORT_PARAMS && |
1027 | no_peer_wf_report_params(first_peer_device(device)->connection)) | 1029 | no_peer_wf_report_params(connection)) |
1028 | clear_bit(STATE_SENT, &first_peer_device(device)->connection->flags); | 1030 | clear_bit(STATE_SENT, &connection->flags); |
1029 | 1031 | ||
1030 | wake_up(&device->misc_wait); | 1032 | wake_up(&device->misc_wait); |
1031 | wake_up(&device->state_wait); | 1033 | wake_up(&device->state_wait); |
1032 | wake_up(&first_peer_device(device)->connection->ping_wait); | 1034 | wake_up(&connection->ping_wait); |
1033 | 1035 | ||
1034 | /* Aborted verify run, or we reached the stop sector. | 1036 | /* Aborted verify run, or we reached the stop sector. |
1035 | * Log the last position, unless end-of-device. */ | 1037 | * Log the last position, unless end-of-device. */ |
@@ -1118,21 +1120,21 @@ __drbd_set_state(struct drbd_device *device, union drbd_state ns, | |||
1118 | 1120 | ||
1119 | /* Receiver should clean up itself */ | 1121 | /* Receiver should clean up itself */ |
1120 | if (os.conn != C_DISCONNECTING && ns.conn == C_DISCONNECTING) | 1122 | if (os.conn != C_DISCONNECTING && ns.conn == C_DISCONNECTING) |
1121 | drbd_thread_stop_nowait(&first_peer_device(device)->connection->receiver); | 1123 | drbd_thread_stop_nowait(&connection->receiver); |
1122 | 1124 | ||
1123 | /* Now the receiver finished cleaning up itself, it should die */ | 1125 | /* Now the receiver finished cleaning up itself, it should die */ |
1124 | if (os.conn != C_STANDALONE && ns.conn == C_STANDALONE) | 1126 | if (os.conn != C_STANDALONE && ns.conn == C_STANDALONE) |
1125 | drbd_thread_stop_nowait(&first_peer_device(device)->connection->receiver); | 1127 | drbd_thread_stop_nowait(&connection->receiver); |
1126 | 1128 | ||
1127 | /* Upon network failure, we need to restart the receiver. */ | 1129 | /* Upon network failure, we need to restart the receiver. */ |
1128 | if (os.conn > C_WF_CONNECTION && | 1130 | if (os.conn > C_WF_CONNECTION && |
1129 | ns.conn <= C_TEAR_DOWN && ns.conn >= C_TIMEOUT) | 1131 | ns.conn <= C_TEAR_DOWN && ns.conn >= C_TIMEOUT) |
1130 | drbd_thread_restart_nowait(&first_peer_device(device)->connection->receiver); | 1132 | drbd_thread_restart_nowait(&connection->receiver); |
1131 | 1133 | ||
1132 | /* Resume AL writing if we get a connection */ | 1134 | /* Resume AL writing if we get a connection */ |
1133 | if (os.conn < C_CONNECTED && ns.conn >= C_CONNECTED) { | 1135 | if (os.conn < C_CONNECTED && ns.conn >= C_CONNECTED) { |
1134 | drbd_resume_al(device); | 1136 | drbd_resume_al(device); |
1135 | first_peer_device(device)->connection->connect_cnt++; | 1137 | connection->connect_cnt++; |
1136 | } | 1138 | } |
1137 | 1139 | ||
1138 | /* remember last attach time so request_timer_fn() won't | 1140 | /* remember last attach time so request_timer_fn() won't |
@@ -1150,7 +1152,7 @@ __drbd_set_state(struct drbd_device *device, union drbd_state ns, | |||
1150 | ascw->w.cb = w_after_state_ch; | 1152 | ascw->w.cb = w_after_state_ch; |
1151 | ascw->device = device; | 1153 | ascw->device = device; |
1152 | ascw->done = done; | 1154 | ascw->done = done; |
1153 | drbd_queue_work(&first_peer_device(device)->connection->sender_work, | 1155 | drbd_queue_work(&connection->sender_work, |
1154 | &ascw->w); | 1156 | &ascw->w); |
1155 | } else { | 1157 | } else { |
1156 | drbd_err(device, "Could not kmalloc an ascw\n"); | 1158 | drbd_err(device, "Could not kmalloc an ascw\n"); |
@@ -1222,6 +1224,8 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, | |||
1222 | union drbd_state ns, enum chg_state_flags flags) | 1224 | union drbd_state ns, enum chg_state_flags flags) |
1223 | { | 1225 | { |
1224 | struct drbd_resource *resource = device->resource; | 1226 | struct drbd_resource *resource = device->resource; |
1227 | struct drbd_peer_device *peer_device = first_peer_device(device); | ||
1228 | struct drbd_connection *connection = peer_device ? peer_device->connection : NULL; | ||
1225 | struct sib_info sib; | 1229 | struct sib_info sib; |
1226 | 1230 | ||
1227 | sib.sib_reason = SIB_STATE_CHANGE; | 1231 | sib.sib_reason = SIB_STATE_CHANGE; |
@@ -1245,7 +1249,6 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, | |||
1245 | state change. This function might sleep */ | 1249 | state change. This function might sleep */ |
1246 | 1250 | ||
1247 | if (ns.susp_nod) { | 1251 | if (ns.susp_nod) { |
1248 | struct drbd_connection *connection = first_peer_device(device)->connection; | ||
1249 | enum drbd_req_event what = NOTHING; | 1252 | enum drbd_req_event what = NOTHING; |
1250 | 1253 | ||
1251 | spin_lock_irq(&device->resource->req_lock); | 1254 | spin_lock_irq(&device->resource->req_lock); |
@@ -1267,8 +1270,6 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, | |||
1267 | } | 1270 | } |
1268 | 1271 | ||
1269 | if (ns.susp_fen) { | 1272 | if (ns.susp_fen) { |
1270 | struct drbd_connection *connection = first_peer_device(device)->connection; | ||
1271 | |||
1272 | spin_lock_irq(&device->resource->req_lock); | 1273 | spin_lock_irq(&device->resource->req_lock); |
1273 | if (resource->susp_fen && conn_lowest_conn(connection) >= C_CONNECTED) { | 1274 | if (resource->susp_fen && conn_lowest_conn(connection) >= C_CONNECTED) { |
1274 | /* case2: The connection was established again: */ | 1275 | /* case2: The connection was established again: */ |
@@ -1294,8 +1295,8 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, | |||
1294 | * which is unexpected. */ | 1295 | * which is unexpected. */ |
1295 | if ((os.conn != C_SYNC_SOURCE && os.conn != C_PAUSED_SYNC_S) && | 1296 | if ((os.conn != C_SYNC_SOURCE && os.conn != C_PAUSED_SYNC_S) && |
1296 | (ns.conn == C_SYNC_SOURCE || ns.conn == C_PAUSED_SYNC_S) && | 1297 | (ns.conn == C_SYNC_SOURCE || ns.conn == C_PAUSED_SYNC_S) && |
1297 | first_peer_device(device)->connection->agreed_pro_version >= 96 && get_ldev(device)) { | 1298 | connection->agreed_pro_version >= 96 && get_ldev(device)) { |
1298 | drbd_gen_and_send_sync_uuid(first_peer_device(device)); | 1299 | drbd_gen_and_send_sync_uuid(peer_device); |
1299 | put_ldev(device); | 1300 | put_ldev(device); |
1300 | } | 1301 | } |
1301 | 1302 | ||
@@ -1309,8 +1310,8 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, | |||
1309 | atomic_set(&device->rs_pending_cnt, 0); | 1310 | atomic_set(&device->rs_pending_cnt, 0); |
1310 | drbd_rs_cancel_all(device); | 1311 | drbd_rs_cancel_all(device); |
1311 | 1312 | ||
1312 | drbd_send_uuids(first_peer_device(device)); | 1313 | drbd_send_uuids(peer_device); |
1313 | drbd_send_state(first_peer_device(device), ns); | 1314 | drbd_send_state(peer_device, ns); |
1314 | } | 1315 | } |
1315 | /* No point in queuing send_bitmap if we don't have a connection | 1316 | /* No point in queuing send_bitmap if we don't have a connection |
1316 | * anymore, so check also the _current_ state, not only the new state | 1317 | * anymore, so check also the _current_ state, not only the new state |
@@ -1335,7 +1336,7 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, | |||
1335 | set_bit(NEW_CUR_UUID, &device->flags); | 1336 | set_bit(NEW_CUR_UUID, &device->flags); |
1336 | } else { | 1337 | } else { |
1337 | drbd_uuid_new_current(device); | 1338 | drbd_uuid_new_current(device); |
1338 | drbd_send_uuids(first_peer_device(device)); | 1339 | drbd_send_uuids(peer_device); |
1339 | } | 1340 | } |
1340 | } | 1341 | } |
1341 | put_ldev(device); | 1342 | put_ldev(device); |
@@ -1346,7 +1347,7 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, | |||
1346 | if (os.peer == R_SECONDARY && ns.peer == R_PRIMARY && | 1347 | if (os.peer == R_SECONDARY && ns.peer == R_PRIMARY && |
1347 | device->ldev->md.uuid[UI_BITMAP] == 0 && ns.disk >= D_UP_TO_DATE) { | 1348 | device->ldev->md.uuid[UI_BITMAP] == 0 && ns.disk >= D_UP_TO_DATE) { |
1348 | drbd_uuid_new_current(device); | 1349 | drbd_uuid_new_current(device); |
1349 | drbd_send_uuids(first_peer_device(device)); | 1350 | drbd_send_uuids(peer_device); |
1350 | } | 1351 | } |
1351 | /* D_DISKLESS Peer becomes secondary */ | 1352 | /* D_DISKLESS Peer becomes secondary */ |
1352 | if (os.peer == R_PRIMARY && ns.peer == R_SECONDARY) | 1353 | if (os.peer == R_PRIMARY && ns.peer == R_SECONDARY) |
@@ -1373,16 +1374,16 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, | |||
1373 | /* Last part of the attaching process ... */ | 1374 | /* Last part of the attaching process ... */ |
1374 | if (ns.conn >= C_CONNECTED && | 1375 | if (ns.conn >= C_CONNECTED && |
1375 | os.disk == D_ATTACHING && ns.disk == D_NEGOTIATING) { | 1376 | os.disk == D_ATTACHING && ns.disk == D_NEGOTIATING) { |
1376 | drbd_send_sizes(first_peer_device(device), 0, 0); /* to start sync... */ | 1377 | drbd_send_sizes(peer_device, 0, 0); /* to start sync... */ |
1377 | drbd_send_uuids(first_peer_device(device)); | 1378 | drbd_send_uuids(peer_device); |
1378 | drbd_send_state(first_peer_device(device), ns); | 1379 | drbd_send_state(peer_device, ns); |
1379 | } | 1380 | } |
1380 | 1381 | ||
1381 | /* We want to pause/continue resync, tell peer. */ | 1382 | /* We want to pause/continue resync, tell peer. */ |
1382 | if (ns.conn >= C_CONNECTED && | 1383 | if (ns.conn >= C_CONNECTED && |
1383 | ((os.aftr_isp != ns.aftr_isp) || | 1384 | ((os.aftr_isp != ns.aftr_isp) || |
1384 | (os.user_isp != ns.user_isp))) | 1385 | (os.user_isp != ns.user_isp))) |
1385 | drbd_send_state(first_peer_device(device), ns); | 1386 | drbd_send_state(peer_device, ns); |
1386 | 1387 | ||
1387 | /* In case one of the isp bits got set, suspend other devices. */ | 1388 | /* In case one of the isp bits got set, suspend other devices. */ |
1388 | if ((!os.aftr_isp && !os.peer_isp && !os.user_isp) && | 1389 | if ((!os.aftr_isp && !os.peer_isp && !os.user_isp) && |
@@ -1392,10 +1393,10 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, | |||
1392 | /* Make sure the peer gets informed about eventual state | 1393 | /* Make sure the peer gets informed about eventual state |
1393 | changes (ISP bits) while we were in WFReportParams. */ | 1394 | changes (ISP bits) while we were in WFReportParams. */ |
1394 | if (os.conn == C_WF_REPORT_PARAMS && ns.conn >= C_CONNECTED) | 1395 | if (os.conn == C_WF_REPORT_PARAMS && ns.conn >= C_CONNECTED) |
1395 | drbd_send_state(first_peer_device(device), ns); | 1396 | drbd_send_state(peer_device, ns); |
1396 | 1397 | ||
1397 | if (os.conn != C_AHEAD && ns.conn == C_AHEAD) | 1398 | if (os.conn != C_AHEAD && ns.conn == C_AHEAD) |
1398 | drbd_send_state(first_peer_device(device), ns); | 1399 | drbd_send_state(peer_device, ns); |
1399 | 1400 | ||
1400 | /* We are in the progress to start a full sync... */ | 1401 | /* We are in the progress to start a full sync... */ |
1401 | if ((os.conn != C_STARTING_SYNC_T && ns.conn == C_STARTING_SYNC_T) || | 1402 | if ((os.conn != C_STARTING_SYNC_T && ns.conn == C_STARTING_SYNC_T) || |
@@ -1449,7 +1450,7 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, | |||
1449 | drbd_disk_str(device->state.disk)); | 1450 | drbd_disk_str(device->state.disk)); |
1450 | 1451 | ||
1451 | if (ns.conn >= C_CONNECTED) | 1452 | if (ns.conn >= C_CONNECTED) |
1452 | drbd_send_state(first_peer_device(device), ns); | 1453 | drbd_send_state(peer_device, ns); |
1453 | 1454 | ||
1454 | drbd_rs_cancel_all(device); | 1455 | drbd_rs_cancel_all(device); |
1455 | 1456 | ||
@@ -1473,7 +1474,7 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, | |||
1473 | drbd_disk_str(device->state.disk)); | 1474 | drbd_disk_str(device->state.disk)); |
1474 | 1475 | ||
1475 | if (ns.conn >= C_CONNECTED) | 1476 | if (ns.conn >= C_CONNECTED) |
1476 | drbd_send_state(first_peer_device(device), ns); | 1477 | drbd_send_state(peer_device, ns); |
1477 | /* corresponding get_ldev in __drbd_set_state | 1478 | /* corresponding get_ldev in __drbd_set_state |
1478 | * this may finally trigger drbd_ldev_destroy. */ | 1479 | * this may finally trigger drbd_ldev_destroy. */ |
1479 | put_ldev(device); | 1480 | put_ldev(device); |
@@ -1481,7 +1482,7 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, | |||
1481 | 1482 | ||
1482 | /* Notify peer that I had a local IO error, and did not detached.. */ | 1483 | /* Notify peer that I had a local IO error, and did not detached.. */ |
1483 | if (os.disk == D_UP_TO_DATE && ns.disk == D_INCONSISTENT && ns.conn >= C_CONNECTED) | 1484 | if (os.disk == D_UP_TO_DATE && ns.disk == D_INCONSISTENT && ns.conn >= C_CONNECTED) |
1484 | drbd_send_state(first_peer_device(device), ns); | 1485 | drbd_send_state(peer_device, ns); |
1485 | 1486 | ||
1486 | /* Disks got bigger while they were detached */ | 1487 | /* Disks got bigger while they were detached */ |
1487 | if (ns.disk > D_NEGOTIATING && ns.pdsk > D_NEGOTIATING && | 1488 | if (ns.disk > D_NEGOTIATING && ns.pdsk > D_NEGOTIATING && |
@@ -1499,14 +1500,14 @@ static void after_state_ch(struct drbd_device *device, union drbd_state os, | |||
1499 | /* sync target done with resync. Explicitly notify peer, even though | 1500 | /* sync target done with resync. Explicitly notify peer, even though |
1500 | * it should (at least for non-empty resyncs) already know itself. */ | 1501 | * it should (at least for non-empty resyncs) already know itself. */ |
1501 | if (os.disk < D_UP_TO_DATE && os.conn >= C_SYNC_SOURCE && ns.conn == C_CONNECTED) | 1502 | if (os.disk < D_UP_TO_DATE && os.conn >= C_SYNC_SOURCE && ns.conn == C_CONNECTED) |
1502 | drbd_send_state(first_peer_device(device), ns); | 1503 | drbd_send_state(peer_device, ns); |
1503 | 1504 | ||
1504 | /* Verify finished, or reached stop sector. Peer did not know about | 1505 | /* Verify finished, or reached stop sector. Peer did not know about |
1505 | * the stop sector, and we may even have changed the stop sector during | 1506 | * the stop sector, and we may even have changed the stop sector during |
1506 | * verify to interrupt/stop early. Send the new state. */ | 1507 | * verify to interrupt/stop early. Send the new state. */ |
1507 | if (os.conn == C_VERIFY_S && ns.conn == C_CONNECTED | 1508 | if (os.conn == C_VERIFY_S && ns.conn == C_CONNECTED |
1508 | && verify_can_do_stop_sector(device)) | 1509 | && verify_can_do_stop_sector(device)) |
1509 | drbd_send_state(first_peer_device(device), ns); | 1510 | drbd_send_state(peer_device, ns); |
1510 | 1511 | ||
1511 | /* This triggers bitmap writeout of potentially still unwritten pages | 1512 | /* This triggers bitmap writeout of potentially still unwritten pages |
1512 | * if the resync finished cleanly, or aborted because of peer disk | 1513 | * if the resync finished cleanly, or aborted because of peer disk |