From nobody Thu Nov 6 08:36:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497525173075101.20409921277576; Thu, 15 Jun 2017 04:12:53 -0700 (PDT) Received: from localhost ([::1]:53216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLShl-0001WZ-Ja for importer@patchew.org; Thu, 15 Jun 2017 07:12:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41202) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLSPQ-0000Df-4V for qemu-devel@nongnu.org; Thu, 15 Jun 2017 06:53:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dLSPP-0007jD-0L for qemu-devel@nongnu.org; Thu, 15 Jun 2017 06:53:52 -0400 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:33506) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dLSPO-0007iq-Nx for qemu-devel@nongnu.org; Thu, 15 Jun 2017 06:53:50 -0400 Received: by mail-wr0-x242.google.com with SMTP id x23so2770096wrb.0 for ; Thu, 15 Jun 2017 03:53:50 -0700 (PDT) Received: from 640k.lan (94-39-191-51.adsl-ull.clienti.tiscali.it. [94.39.191.51]) by smtp.gmail.com with ESMTPSA id f21sm3258597wra.5.2017.06.15.03.53.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jun 2017 03:53:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=tTCeDty5mdR0/PeQgw9TMhV8rRvrt9Xx8MwH+Q5932E=; b=dNhj2hYg30ST2WjyE/fj9YBPCs6Kk4gtDvVkAZPx4uNge8ypPf3oYQBCkGIgEtzQmf jE7LfAoxZMDqwUhqxWfaWYa9Wo6WLJreTwTGI6xZ0vrCzsvaqdXxu06ohNHYi6HAcJxh 0WnHPGsx+Cg9oOKMiNh5XLuEaeq33iMQuY8yj3LgwcSQfophIXxpyd3wCo/YKoZ9EpOW N40o7hmEEveeB/cSTvEn4nip74ccYzj2JudWaovF5/ru9zSF2qRtsb8wfjDjT+mMT7S3 kdlKKdL3vS+wlfo6C03xHiln+/7ePUFlej8VAD+MgVOwESvKyyka5RUisOOOsGBvp20p +W4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=tTCeDty5mdR0/PeQgw9TMhV8rRvrt9Xx8MwH+Q5932E=; b=M7RujJl67jXge5hKcdxkfQwf5M+hyZquV1eJx1zTmxm3NI2k2eLTBd3H/HSf6dmhzf e+9rkIrFiito9toyJ6XmQWNBGAHGGYgL98hFseV0Dfokayid9DInOOSsG/EzX/OfF5mL GW34vBEBbFP4oOV5tPMrbDKZ03qMEdnOrns5BUeSHUOa6HmV9Nl4jMfrM3ecIkSxS3xF /sGJpLlaIV6TpdyEWwEkHPZRg0Z+8lbKY0oEnqtiF3A36sR9BOMy9h7GFnRRlt0L41Ft EAqOHw8Bommoa09BjSVb9Yzzahd+iz4pPbeFE3KQzucktyVylBB3mM/s7L5Z71FbgU4h yYzA== X-Gm-Message-State: AKS2vOy3FKdVIcD6NntYPHZpJn+yutuBS+c/8L9CVpccms0kwgKFHWT9 4C6WSoY49aFZAeGY27A= X-Received: by 10.28.24.202 with SMTP id 193mr3177201wmy.125.1497524029313; Thu, 15 Jun 2017 03:53:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 15 Jun 2017 12:52:55 +0200 Message-Id: <1497523981-38449-36-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1497523981-38449-1-git-send-email-pbonzini@redhat.com> References: <1497523981-38449-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PULL 35/41] nbd/server: refactor nbd_trip X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vladimir Sementsov-Ogievskiy Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy - do not use 'goto error_reply' outside a switch to jump into the middle of the switch's default case label - reduce code duplication Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20170602150150.258222-13-vsementsov@virtuozzo.com> Signed-off-by: Paolo Bonzini --- nbd/server.c | 53 ++++++++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index f19f5fd..8a70c05 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1078,6 +1078,7 @@ static coroutine_fn void nbd_trip(void *opaque) NBDReply reply; int ret; int flags; + int reply_data_len =3D 0; =20 TRACE("Reading request."); if (client->closing) { @@ -1090,7 +1091,7 @@ static coroutine_fn void nbd_trip(void *opaque) client->recv_coroutine =3D NULL; nbd_client_receive_next_request(client); if (ret =3D=3D -EIO) { - goto out; + goto disconnect; } =20 reply.handle =3D request.handle; @@ -1098,7 +1099,7 @@ static coroutine_fn void nbd_trip(void *opaque) =20 if (ret < 0) { reply.error =3D -ret; - goto error_reply; + goto reply; } =20 if (client->closing) { @@ -1119,7 +1120,7 @@ static coroutine_fn void nbd_trip(void *opaque) if (ret < 0) { LOG("flush failed"); reply.error =3D -ret; - goto error_reply; + break; } } =20 @@ -1128,12 +1129,12 @@ static coroutine_fn void nbd_trip(void *opaque) if (ret < 0) { LOG("reading from file failed"); reply.error =3D -ret; - goto error_reply; + break; } =20 + reply_data_len =3D request.len; TRACE("Read %" PRIu32" byte(s)", request.len); - if (nbd_co_send_reply(req, &reply, request.len) < 0) - goto out; + break; case NBD_CMD_WRITE: TRACE("Request type is WRITE"); @@ -1141,7 +1142,7 @@ static coroutine_fn void nbd_trip(void *opaque) if (exp->nbdflags & NBD_FLAG_READ_ONLY) { TRACE("Server is read-only, return error"); reply.error =3D EROFS; - goto error_reply; + break; } =20 TRACE("Writing to device"); @@ -1155,21 +1156,16 @@ static coroutine_fn void nbd_trip(void *opaque) if (ret < 0) { LOG("writing to file failed"); reply.error =3D -ret; - goto error_reply; } =20 - if (nbd_co_send_reply(req, &reply, 0) < 0) { - goto out; - } break; - case NBD_CMD_WRITE_ZEROES: TRACE("Request type is WRITE_ZEROES"); =20 if (exp->nbdflags & NBD_FLAG_READ_ONLY) { TRACE("Server is read-only, return error"); reply.error =3D EROFS; - goto error_reply; + break; } =20 TRACE("Writing to device"); @@ -1186,14 +1182,9 @@ static coroutine_fn void nbd_trip(void *opaque) if (ret < 0) { LOG("writing to file failed"); reply.error =3D -ret; - goto error_reply; } =20 - if (nbd_co_send_reply(req, &reply, 0) < 0) { - goto out; - } break; - case NBD_CMD_DISC: /* unreachable, thanks to special case in nbd_co_receive_request()= */ abort(); @@ -1206,9 +1197,7 @@ static coroutine_fn void nbd_trip(void *opaque) LOG("flush failed"); reply.error =3D -ret; } - if (nbd_co_send_reply(req, &reply, 0) < 0) { - goto out; - } + break; case NBD_CMD_TRIM: TRACE("Request type is TRIM"); @@ -1218,21 +1207,19 @@ static coroutine_fn void nbd_trip(void *opaque) LOG("discard failed"); reply.error =3D -ret; } - if (nbd_co_send_reply(req, &reply, 0) < 0) { - goto out; - } + break; default: LOG("invalid request type (%" PRIu32 ") received", request.type); reply.error =3D EINVAL; - error_reply: - /* We must disconnect after NBD_CMD_WRITE if we did not - * read the payload. - */ - if (nbd_co_send_reply(req, &reply, 0) < 0 || !req->complete) { - goto out; - } - break; + } + +reply: + /* We must disconnect after NBD_CMD_WRITE if we did not + * read the payload. + */ + if (nbd_co_send_reply(req, &reply, reply_data_len) < 0 || !req->comple= te) { + goto disconnect; } =20 TRACE("Request/Reply complete"); @@ -1242,7 +1229,7 @@ done: nbd_client_put(client); return; =20 -out: +disconnect: nbd_request_put(req); client_close(client, true); nbd_client_put(client); --=20 1.8.3.1