Skip to content

Commit

Permalink
Merged in DW-1398-close-socket-cancel-hang (pull request #403)
Browse files Browse the repository at this point in the history
DW-1398 close socket cancel hang

Approved-by: sekim
Approved-by: swon
Approved-by: sachoi
Approved-by: hunn lim
  • Loading branch information
HyunjunLee authored and sungeun-kim committed Feb 15, 2017
2 parents 1f24a7e + 75ec335 commit 629c2f3
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
2 changes: 2 additions & 0 deletions drbd-headers/drbd_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ struct drbd_transport {

#ifdef _WIN32
atomic_t listening;
// DW-1398: accepted all peers and listening socket is no longer available.
atomic_t listening_done;
#endif
};

Expand Down
5 changes: 5 additions & 0 deletions drbd/drbd_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -2309,6 +2309,11 @@ extern struct drbd_resource *drbd_find_resource(const char *name);
extern void drbd_destroy_resource(struct kref *kref);
extern void conn_free_crypto(struct drbd_connection *connection);

#ifdef _WIN32
// DW-1398
extern void dtt_put_listeners(struct drbd_transport *);
#endif

/* drbd_req */
extern void do_submit(struct work_struct *ws);
#ifdef _WIN32
Expand Down
5 changes: 5 additions & 0 deletions drbd/drbd_receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -8062,6 +8062,11 @@ void conn_disconnect(struct drbd_connection *connection)

change_cstate(connection, C_NETWORK_FAILURE, CS_HARD);

#ifdef _WIN32
// DW-1398: closing listening socket busts accepted socket, put those sockets here instead.
dtt_put_listeners(&connection->transport);
#endif

del_connect_timer(connection);

/* ack_receiver does not clean up anything. it must not interfere, either */
Expand Down
23 changes: 22 additions & 1 deletion drbd/drbd_transport_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,19 @@ static void dtt_incoming_connection(struct sock *sock)
spin_unlock(&listener->listener.waiters_lock);
return STATUS_REQUEST_NOT_ACCEPTED;
}

#ifdef _WIN32
// DW-1398: do not accept if already connected.
if (atomic_read(&waiter->transport->listening_done))
{
WDRBD_WARN("listening is done for this transport, request won't be accepted\n");
kfree(s_estab->sk_linux_attr);
kfree(s_estab);
spin_unlock(&listener->listener.waiters_lock);
return STATUS_REQUEST_NOT_ACCEPTED;
}
#endif

struct dtt_path * path = container_of(waiter, struct dtt_path, waiter);

if (path)
Expand Down Expand Up @@ -1517,6 +1530,8 @@ static int dtt_create_listener(struct drbd_transport *transport,
err = -1;
goto out;
}
// DW-1398: initialize.
atomic_set(&transport->listening_done, false);
#endif
return 0;
out:
Expand Down Expand Up @@ -1547,7 +1562,12 @@ static void dtt_cleanup_accepted_sockets(struct dtt_path *path)
}
#endif

#ifdef _WIN32
// DW-1398
void dtt_put_listeners(struct drbd_transport *transport)
#else
static void dtt_put_listeners(struct drbd_transport *transport)
#endif
{
struct drbd_tcp_transport *tcp_transport =
container_of(transport, struct drbd_tcp_transport, transport);
Expand Down Expand Up @@ -1852,7 +1872,8 @@ static int dtt_connect(struct drbd_transport *transport)
connect_to_path->path.established = true;
drbd_path_event(transport, &connect_to_path->path);
#ifdef _WIN32
dtt_put_listeners(transport);
// DW-1398: closing listening socket here makes accepted socket be unavailable, putting listeners is moved to conn_disconnect()
atomic_set(&transport->listening_done, true);
#else
dtt_put_listeners(transport);
#endif
Expand Down
33 changes: 33 additions & 0 deletions wdrbd9/wsk2.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,27 @@ NTAPI CompletionRoutineAsync(
}
#endif

// DW-1398: Implementing a cancel routine.
VOID CancelRoutine(
IN PDEVICE_OBJECT pDeviceObject,
IN PIRP Irp)
{
IoReleaseCancelSpinLock(Irp->CancelIrql);
Irp->IoStatus.Status = STATUS_CANCELLED;
Irp->IoStatus.Information = 0;

IoCompleteRequest(Irp, IO_NO_INCREMENT);
}

NTSTATUS
InitWskData(
__out PIRP* pIrp,
__out PKEVENT CompletionEvent,
__in BOOLEAN bRawIrp
)
{
KIRQL irql;

ASSERT(pIrp);
ASSERT(CompletionEvent);

Expand All @@ -69,6 +83,11 @@ InitWskData(

KeInitializeEvent(CompletionEvent, SynchronizationEvent, FALSE);
IoSetCompletionRoutine(*pIrp, CompletionRoutine, CompletionEvent, TRUE, TRUE, TRUE);

// DW-1398: set cancel routine
IoAcquireCancelSpinLock(&irql);
IoSetCancelRoutine(*pIrp, CancelRoutine);
IoReleaseCancelSpinLock(irql);

return STATUS_SUCCESS;
}
Expand All @@ -81,6 +100,8 @@ InitWskDataAsync(
__in BOOLEAN bRawIrp
)
{
KIRQL irql;

ASSERT(pIrp);
ASSERT(CompletionEvent);

Expand All @@ -99,6 +120,11 @@ InitWskDataAsync(
//KeInitializeEvent(CompletionEvent, SynchronizationEvent, FALSE);
IoSetCompletionRoutine(*pIrp, CompletionRoutineAsync, NULL, TRUE, TRUE, TRUE);

// DW-1398: set cancel routine
IoAcquireCancelSpinLock(&irql);
IoSetCancelRoutine(*pIrp, CancelRoutine);
IoReleaseCancelSpinLock(irql);

return STATUS_SUCCESS;
}
#endif
Expand All @@ -109,13 +135,20 @@ __out PIRP* pIrp,
__out PKEVENT CompletionEvent
)
{
KIRQL irql;

ASSERT(pIrp);
ASSERT(CompletionEvent);

KeResetEvent(CompletionEvent);
IoReuseIrp(*pIrp, STATUS_UNSUCCESSFUL);
IoSetCompletionRoutine(*pIrp, CompletionRoutine, CompletionEvent, TRUE, TRUE, TRUE);

// DW-1398: set cancel routine
IoAcquireCancelSpinLock(&irql);
IoSetCancelRoutine(*pIrp, CancelRoutine);
IoReleaseCancelSpinLock(irql);

return;
}

Expand Down

0 comments on commit 629c2f3

Please sign in to comment.