[dm-devel] [PATCH v2 35/48] multipathd: uxlsnr: use recv() for command length
Benjamin Marzinski
bmarzins at redhat.com
Thu Nov 25 01:54:19 UTC 2021
On Thu, Nov 18, 2021 at 11:58:27PM +0100, mwilck at suse.com wrote:
> From: Martin Wilck <mwilck at suse.com>
>
> If the peer uses libmpathcmd, we can be certain that the first
> 8 bytes are being sent in a single chunk of data. It's overkill
> to try and receive the command length byte-by-byte.
>
Reviewed-by: Benjamin Marzinski <bmarzins at redhat.com>
> Signed-off-by: Martin Wilck <mwilck at suse.com>
> ---
> multipathd/uxlsnr.c | 17 +++++++++--------
> 1 file changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c
> index 24db377..6355279 100644
> --- a/multipathd/uxlsnr.c
> +++ b/multipathd/uxlsnr.c
> @@ -441,6 +441,7 @@ static int client_state_machine(struct client *c, struct vectors *vecs,
> if (!(revents & POLLIN))
> return STM_BREAK;
> if (c->cmd_len == 0) {
> + size_t len;
> /*
> * We got POLLIN; assume that at least the length can
> * be read immediately.
> @@ -449,17 +450,17 @@ static int client_state_machine(struct client *c, struct vectors *vecs,
> c->expires.tv_sec += uxsock_timeout / 1000;
> c->expires.tv_nsec += (uxsock_timeout % 1000) * 1000000;
> normalize_timespec(&c->expires);
> - n = mpath_recv_reply_len(c->fd, 0);
> - if (n == -1) {
> - condlog(1, "%s: cli[%d]: failed to receive reply len",
> - __func__, c->fd);
> - c->error = -ECONNRESET;
> - } else if (n > _MAX_CMD_LEN) {
> - condlog(1, "%s: cli[%d]: overlong command (%zd bytes)",
> + n = recv(c->fd, &len, sizeof(len), 0);
> + if (n < (ssize_t)sizeof(len)) {
> + condlog(1, "%s: cli[%d]: failed to receive reply len: %zd",
> __func__, c->fd, n);
> c->error = -ECONNRESET;
> + } else if (len <= 0 || len > _MAX_CMD_LEN) {
> + condlog(1, "%s: cli[%d]: invalid command length (%zu bytes)",
> + __func__, c->fd, len);
> + c->error = -ECONNRESET;
> } else {
> - c->cmd_len = n;
> + c->cmd_len = len;
> condlog(4, "%s: cli[%d]: connected", __func__, c->fd);
> }
> /* poll for data */
> --
> 2.33.1
More information about the dm-devel
mailing list