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

!12242 [sync] PR-12227: nbd: Fix signal handling

Merge Pull Request from: @openeuler-sync-bot 
 

Origin pull request: 
https://gitee.com/openeuler/kernel/pulls/12227 
 
PR sync from: Yu Kuai <yukuai3@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/J4OW5A2BRG5C6AUKK5SED2JQVW5FH4IG/ 
Bart Van Assche (2):
  nbd: Improve the documentation of the locking assumptions
  nbd: Fix signal handling


-- 
2.39.2
 
https://gitee.com/openeuler/kernel/issues/IAVLO6?from=project-issue 
 
Link:https://gitee.com/openeuler/kernel/pulls/12242

 

Reviewed-by: default avatarYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
parents 1fef9e0d edd27eec
Loading
Loading
Loading
Loading
+19 −15
Original line number Diff line number Diff line
@@ -564,7 +564,10 @@ static inline int was_interrupted(int result)
	return result == -ERESTARTSYS || result == -EINTR;
}

/* always call with the tx_lock held */
/*
 * Returns BLK_STS_RESOURCE if the caller should retry after a delay. Returns
 * -EAGAIN if the caller should requeue @cmd. Returns -EIO if sending failed.
 */
static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
{
	struct request *req = blk_mq_rq_from_pdu(cmd);
@@ -581,6 +584,9 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
	u32 nbd_cmd_flags = 0;
	int sent = nsock->sent, skip = 0;

	lockdep_assert_held(&cmd->lock);
	lockdep_assert_held(&nsock->tx_lock);

	iov_iter_kvec(&from, WRITE, &iov, 1, sizeof(request));

	type = req_to_nbd_cmd_type(req);
@@ -645,7 +651,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
				nsock->sent = sent;
			}
			set_bit(NBD_CMD_REQUEUED, &cmd->flags);
			return BLK_STS_RESOURCE;
			return (__force int)BLK_STS_RESOURCE;
		}
		dev_err_ratelimited(disk_to_dev(nbd->disk),
			"Send control failed (result %d)\n", result);
@@ -686,7 +692,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
					nsock->pending = req;
					nsock->sent = sent;
					set_bit(NBD_CMD_REQUEUED, &cmd->flags);
					return BLK_STS_RESOURCE;
					return (__force int)BLK_STS_RESOURCE;
				}
				dev_err(disk_to_dev(nbd->disk),
					"Send data failed (result %d)\n",
@@ -981,7 +987,7 @@ static int wait_for_reconnect(struct nbd_device *nbd)
	return !test_bit(NBD_RT_DISCONNECTED, &config->runtime_flags);
}

static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
static blk_status_t nbd_handle_cmd(struct nbd_cmd *cmd, int index)
{
	struct request *req = blk_mq_rq_from_pdu(cmd);
	struct nbd_device *nbd = cmd->nbd;
@@ -989,18 +995,20 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
	struct nbd_sock *nsock;
	int ret;

	lockdep_assert_held(&cmd->lock);

	config = nbd_get_config_unlocked(nbd);
	if (!config) {
		dev_err_ratelimited(disk_to_dev(nbd->disk),
				    "Socks array is empty\n");
		return -EINVAL;
		return BLK_STS_IOERR;
	}

	if (index >= config->num_connections) {
		dev_err_ratelimited(disk_to_dev(nbd->disk),
				    "Attempted send on invalid socket\n");
		nbd_config_put(nbd);
		return -EINVAL;
		return BLK_STS_IOERR;
	}
	cmd->status = BLK_STS_OK;
again:
@@ -1023,7 +1031,7 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
			 */
			sock_shutdown(nbd);
			nbd_config_put(nbd);
			return -EIO;
			return BLK_STS_IOERR;
		}
		goto again;
	}
@@ -1036,7 +1044,7 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
	blk_mq_start_request(req);
	if (unlikely(nsock->pending && nsock->pending != req)) {
		nbd_requeue_cmd(cmd);
		ret = 0;
		ret = BLK_STS_OK;
		goto out;
	}
	/*
@@ -1055,19 +1063,19 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
				    "Request send failed, requeueing\n");
		nbd_mark_nsock_dead(nbd, nsock, 1);
		nbd_requeue_cmd(cmd);
		ret = 0;
		ret = BLK_STS_OK;
	}
out:
	mutex_unlock(&nsock->tx_lock);
	nbd_config_put(nbd);
	return ret;
	return ret < 0 ? BLK_STS_IOERR : (__force blk_status_t)ret;
}

static blk_status_t nbd_queue_rq(struct blk_mq_hw_ctx *hctx,
			const struct blk_mq_queue_data *bd)
{
	struct nbd_cmd *cmd = blk_mq_rq_to_pdu(bd->rq);
	int ret;
	blk_status_t ret;

	/*
	 * Since we look at the bio's to send the request over the network we
@@ -1087,10 +1095,6 @@ static blk_status_t nbd_queue_rq(struct blk_mq_hw_ctx *hctx,
	 * appropriate.
	 */
	ret = nbd_handle_cmd(cmd, hctx->queue_num);
	if (ret < 0)
		ret = BLK_STS_IOERR;
	else if (!ret)
		ret = BLK_STS_OK;
	mutex_unlock(&cmd->lock);

	return ret;