Unverified Commit 2a2e7e9c authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!1863 nbd: pass nbd_sock to nbd_read_reply() instead of index

parents 048d8eeb 92050518
Loading
Loading
Loading
Loading
+22 −13
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ struct nbd_sock {
struct recv_thread_args {
	struct work_struct work;
	struct nbd_device *nbd;
	struct nbd_sock *nsock;
	int index;
};

@@ -453,15 +454,9 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
	return BLK_EH_DONE;
}

/*
 *  Send or receive packet. Return a positive value on success and
 *  negtive value on failue, and never return 0.
 */
static int sock_xmit(struct nbd_device *nbd, int index, int send,
static int __sock_xmit(struct nbd_device *nbd, struct socket *sock, int send,
		       struct iov_iter *iter, int msg_flags, int *sent)
{
	struct nbd_config *config = nbd->config;
	struct socket *sock = config->socks[index]->sock;
	int result;
	struct msghdr msg;
	unsigned int noreclaim_flag;
@@ -503,6 +498,19 @@ static int sock_xmit(struct nbd_device *nbd, int index, int send,
	return result;
}

/*
 *  Send or receive packet. Return a positive value on success and
 *  negtive value on failure, and never return 0.
 */
static int sock_xmit(struct nbd_device *nbd, int index, int send,
		     struct iov_iter *iter, int msg_flags, int *sent)
{
	struct nbd_config *config = nbd->config;
	struct socket *sock = config->socks[index]->sock;

	return __sock_xmit(nbd, sock, send, iter, msg_flags, sent);
}

/*
 * Different settings for sk->sk_sndtimeo can result in different return values
 * if there is a signal pending when we enter sendmsg, because reasons?
@@ -664,7 +672,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
	return 0;
}

static int nbd_read_reply(struct nbd_device *nbd, int index,
static int nbd_read_reply(struct nbd_device *nbd, struct socket *sock,
			  struct nbd_reply *reply)
{
	struct kvec iov = {.iov_base = reply, .iov_len = sizeof(*reply)};
@@ -673,7 +681,7 @@ static int nbd_read_reply(struct nbd_device *nbd, int index,

	reply->magic = 0;
	iov_iter_kvec(&to, READ | ITER_KVEC, &iov, 1, sizeof(*reply));
	result = sock_xmit(nbd, index, 0, &to, MSG_WAITALL, NULL);
	result = __sock_xmit(nbd, sock, 0, &to, MSG_WAITALL, NULL);
	if (result < 0) {
		if (!nbd_disconnected(nbd->config))
			dev_err(disk_to_dev(nbd->disk),
@@ -798,13 +806,13 @@ static void recv_work(struct work_struct *work)
	struct nbd_device *nbd = args->nbd;
	struct nbd_config *config = nbd->config;
	struct request_queue *q = nbd->disk->queue;
	struct nbd_sock *nsock;
	struct nbd_sock *nsock = args->nsock;
	struct nbd_cmd *cmd;

	while (1) {
		struct nbd_reply reply;

		if (nbd_read_reply(nbd, args->index, &reply))
		if (nbd_read_reply(nbd, nsock->sock, &reply))
			break;

		/*
@@ -829,7 +837,6 @@ static void recv_work(struct work_struct *work)
		percpu_ref_put(&q->q_usage_counter);
	}

	nsock = config->socks[args->index];
	mutex_lock(&nsock->tx_lock);
	nbd_mark_nsock_dead(nbd, nsock, 1);
	mutex_unlock(&nsock->tx_lock);
@@ -1164,6 +1171,7 @@ static int nbd_reconnect_socket(struct nbd_device *nbd, unsigned long arg)
		INIT_WORK(&args->work, recv_work);
		args->index = i;
		args->nbd = nbd;
		args->nsock = nsock;
		nsock->cookie++;
		mutex_unlock(&nsock->tx_lock);
		sockfd_put(old);
@@ -1354,6 +1362,7 @@ static int nbd_start_device(struct nbd_device *nbd)
		refcount_inc(&nbd->config_refs);
		INIT_WORK(&args->work, recv_work);
		args->nbd = nbd;
		args->nsock = config->socks[i];
		args->index = i;
		queue_work(nbd->recv_workq, &args->work);
	}