Commit 11b0be28 authored by Andreas Gruenbacher's avatar Andreas Gruenbacher Committed by Philipp Reisner

drbd: drbd_get_data_sock(): Return 0 upon success and an error code otherwise

Signed-off-by: default avatarPhilipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: default avatarLars Ellenberg <lars.ellenberg@linbit.com>
parent c0d42c8e
...@@ -1115,24 +1115,15 @@ static inline struct drbd_conf *vnr_to_mdev(struct drbd_tconn *tconn, int vnr) ...@@ -1115,24 +1115,15 @@ static inline struct drbd_conf *vnr_to_mdev(struct drbd_tconn *tconn, int vnr)
return (struct drbd_conf *)idr_find(&tconn->volumes, vnr); return (struct drbd_conf *)idr_find(&tconn->volumes, vnr);
} }
/* returns 1 if it was successful,
* returns 0 if there was no data socket.
* so wherever you are going to use the data.socket, e.g. do
* if (!drbd_get_data_sock(mdev->tconn))
* return 0;
* CODE();
* drbd_get_data_sock(mdev->tconn);
*/
static inline int drbd_get_data_sock(struct drbd_tconn *tconn) static inline int drbd_get_data_sock(struct drbd_tconn *tconn)
{ {
mutex_lock(&tconn->data.mutex); mutex_lock(&tconn->data.mutex);
/* drbd_disconnect() could have called drbd_free_sock() if (!tconn->data.socket) {
* while we were waiting in down()... */ /* Disconnected. */
if (unlikely(tconn->data.socket == NULL)) {
mutex_unlock(&tconn->data.mutex); mutex_unlock(&tconn->data.mutex);
return 0; return -EIO;
} }
return 1; return 0;
} }
static inline void drbd_put_data_sock(struct drbd_tconn *tconn) static inline void drbd_put_data_sock(struct drbd_tconn *tconn)
......
...@@ -773,7 +773,7 @@ int conn_send_cmd2(struct drbd_tconn *tconn, enum drbd_packet cmd, char *data, ...@@ -773,7 +773,7 @@ int conn_send_cmd2(struct drbd_tconn *tconn, enum drbd_packet cmd, char *data,
prepare_header80(&h, cmd, size); prepare_header80(&h, cmd, size);
if (!drbd_get_data_sock(tconn)) if (drbd_get_data_sock(tconn))
return 0; return 0;
ok = (sizeof(h) == ok = (sizeof(h) ==
...@@ -1245,7 +1245,7 @@ int drbd_send_bitmap(struct drbd_conf *mdev) ...@@ -1245,7 +1245,7 @@ int drbd_send_bitmap(struct drbd_conf *mdev)
{ {
int err; int err;
if (!drbd_get_data_sock(mdev->tconn)) if (drbd_get_data_sock(mdev->tconn))
return -1; return -1;
err = !_drbd_send_bitmap(mdev); err = !_drbd_send_bitmap(mdev);
drbd_put_data_sock(mdev->tconn); drbd_put_data_sock(mdev->tconn);
...@@ -1562,7 +1562,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req) ...@@ -1562,7 +1562,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
void *dgb; void *dgb;
int dgs; int dgs;
if (!drbd_get_data_sock(mdev->tconn)) if (drbd_get_data_sock(mdev->tconn))
return 0; return 0;
dgs = (mdev->tconn->agreed_pro_version >= 87 && mdev->tconn->integrity_w_tfm) ? dgs = (mdev->tconn->agreed_pro_version >= 87 && mdev->tconn->integrity_w_tfm) ?
...@@ -1652,7 +1652,7 @@ int drbd_send_block(struct drbd_conf *mdev, enum drbd_packet cmd, ...@@ -1652,7 +1652,7 @@ int drbd_send_block(struct drbd_conf *mdev, enum drbd_packet cmd,
* This one may be interrupted by DRBD_SIG and/or DRBD_SIGKILL * This one may be interrupted by DRBD_SIG and/or DRBD_SIGKILL
* in response to admin command or module unload. * in response to admin command or module unload.
*/ */
if (!drbd_get_data_sock(mdev->tconn)) if (drbd_get_data_sock(mdev->tconn))
return 0; return 0;
ok = sizeof(p) == drbd_send(mdev->tconn, mdev->tconn->data.socket, &p, sizeof(p), dgs ? MSG_MORE : 0); ok = sizeof(p) == drbd_send(mdev->tconn, mdev->tconn->data.socket, &p, sizeof(p), dgs ? MSG_MORE : 0);
......
...@@ -1209,7 +1209,7 @@ int w_send_barrier(struct drbd_work *w, int cancel) ...@@ -1209,7 +1209,7 @@ int w_send_barrier(struct drbd_work *w, int cancel)
if (cancel) if (cancel)
return 1; return 1;
if (!drbd_get_data_sock(mdev->tconn)) if (drbd_get_data_sock(mdev->tconn))
return 0; return 0;
p->barrier = b->br_number; p->barrier = b->br_number;
/* inc_ap_pending was done where this was queued. /* inc_ap_pending was done where this was queued.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment