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 1497525525386338.5351055982021; Thu, 15 Jun 2017 04:18:45 -0700 (PDT) Received: from localhost ([::1]:53253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLSnR-0007MW-T6 for importer@patchew.org; Thu, 15 Jun 2017 07:18:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLSPK-000069-L9 for qemu-devel@nongnu.org; Thu, 15 Jun 2017 06:53:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dLSPJ-0007fu-Ob for qemu-devel@nongnu.org; Thu, 15 Jun 2017 06:53:46 -0400 Received: from mail-wr0-x22e.google.com ([2a00:1450:400c:c0c::22e]:34293) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dLSPJ-0007fI-Ef for qemu-devel@nongnu.org; Thu, 15 Jun 2017 06:53:45 -0400 Received: by mail-wr0-x22e.google.com with SMTP id 77so16400104wrb.1 for ; Thu, 15 Jun 2017 03:53:45 -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.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jun 2017 03:53:43 -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=9xj63zsl3ySr1KAYBSMBi1AG/OPHMGzmulmbcOPHy+M=; b=bqagZC8rbK6KA2/L8ytp7VAlCNadq3yN4eWtUC1a6OlOsASLs7UYeLmkxI0h4OGsqv z0wlXBQwBGoDXdayEI5D44D53+GdKt7dyq96b5B78meCCc7RkSErO5WSeA+dexnYLMoB 1uh9hXDcHmTEaBJ7okQFIL2xf62jFGgyJOnXDlv9JKj5bbbTfbIJs99R6EOz0j5ILPBX XZJaexLWN4k/zsvIr5oawTvNBW4exWJ1YsEXPSHlBzeVx2BZyGhchmSIug5OjUeoURUZ ErlohtVPSDvyGMuVnF+d2uA4YeY4ZSv5ovGp+qwDMMtFsjvOKII0gPoX7NLuEIhke7wW ARYQ== 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=9xj63zsl3ySr1KAYBSMBi1AG/OPHMGzmulmbcOPHy+M=; b=XaOJ5AEL3Wt1kEuPX7vUAWFl2B0j05MNnqKUMbByg1ECPCtvW2O6+Vj4DvgcwkcZd+ Ik6hlWvu7AvvaSiTM1ZQQJXze7YyPD5cqR+ODrvzW0qhhtlUkKHTwdH1BLg3aSc6t6TK WDvdVInxXxr18Y2x/JByjBQzOjX3xSht40vGFeCoM7bC2N+WpeVE7sCiVoqH5w+kpGMt AMW2acs2s7LERdGX3Qcy8OkcXD2n04QQ+SlbUncD69ji0FKTjr+IvlX3iZ0ud4pnP5df tGbchoGptLy62jzjkbnsEwH6SP+YrsreL1wXMuzepdiRnoDvXy3jvsARIZdzTlfFCibM nHOA== X-Gm-Message-State: AKS2vOxGwa+o8Qo1AEfJiopk/QoduojkqyWhh+kZYqUMUS2eTZsbtvSo 5xiQB4+KALKo1s1Tc2w= X-Received: by 10.223.164.137 with SMTP id g9mr3122736wrb.128.1497524024130; Thu, 15 Jun 2017 03:53:44 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 15 Jun 2017 12:52:50 +0200 Message-Id: <1497523981-38449-31-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::22e Subject: [Qemu-devel] [PULL 30/41] nbd/server: refactor nbd_co_receive_request 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 Move function tail, about receiving next request out of the function. Error path is simplified and nbd_co_receive_request becomes more corresponding to its name. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-Id: <20170602150150.258222-8-vsementsov@virtuozzo.com> Signed-off-by: Paolo Bonzini --- nbd/server.c | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 00a19f6..9fb03ce 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1006,14 +1006,11 @@ static int nbd_co_send_reply(NBDRequestData *req, N= BDReply *reply, int len) static int nbd_co_receive_request(NBDRequestData *req, NBDRequest *request) { NBDClient *client =3D req->client; - int rc; =20 g_assert(qemu_in_coroutine()); assert(client->recv_coroutine =3D=3D qemu_coroutine_self()); - rc =3D nbd_receive_request(client->ioc, request); - if (rc < 0) { - rc =3D -EIO; - goto out; + if (nbd_receive_request(client->ioc, request) < 0) { + return -EIO; } =20 TRACE("Decoding type"); @@ -1027,8 +1024,7 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request) /* Special case: we're going to disconnect without a reply, * whether or not flags, from, or len are bogus */ TRACE("Request type is DISCONNECT"); - rc =3D -EIO; - goto out; + return -EIO; } =20 /* Check for sanity in the parameters, part 1. Defer as many @@ -1036,22 +1032,19 @@ static int nbd_co_receive_request(NBDRequestData *r= eq, NBDRequest *request) * payload, so we can try and keep the connection alive. */ if ((request->from + request->len) < request->from) { LOG("integer overflow detected, you're probably being attacked"); - rc =3D -EINVAL; - goto out; + return -EINVAL; } =20 if (request->type =3D=3D NBD_CMD_READ || request->type =3D=3D NBD_CMD_= WRITE) { if (request->len > NBD_MAX_BUFFER_SIZE) { LOG("len (%" PRIu32" ) is larger than max len (%u)", request->len, NBD_MAX_BUFFER_SIZE); - rc =3D -EINVAL; - goto out; + return -EINVAL; } =20 req->data =3D blk_try_blockalign(client->exp->blk, request->len); if (req->data =3D=3D NULL) { - rc =3D -ENOMEM; - goto out; + return -ENOMEM; } } if (request->type =3D=3D NBD_CMD_WRITE) { @@ -1059,8 +1052,7 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request) =20 if (nbd_read(client->ioc, req->data, request->len, NULL) < 0) { LOG("reading from socket failed"); - rc =3D -EIO; - goto out; + return -EIO; } req->complete =3D true; } @@ -1070,28 +1062,19 @@ static int nbd_co_receive_request(NBDRequestData *r= eq, NBDRequest *request) LOG("operation past EOF; From: %" PRIu64 ", Len: %" PRIu32 ", Size: %" PRIu64, request->from, request->len, (uint64_t)client->exp->size); - rc =3D request->type =3D=3D NBD_CMD_WRITE ? -ENOSPC : -EINVAL; - goto out; + return request->type =3D=3D NBD_CMD_WRITE ? -ENOSPC : -EINVAL; } if (request->flags & ~(NBD_CMD_FLAG_FUA | NBD_CMD_FLAG_NO_HOLE)) { LOG("unsupported flags (got 0x%x)", request->flags); - rc =3D -EINVAL; - goto out; + return -EINVAL; } if (request->type !=3D NBD_CMD_WRITE_ZEROES && (request->flags & NBD_CMD_FLAG_NO_HOLE)) { LOG("unexpected flags (got 0x%x)", request->flags); - rc =3D -EINVAL; - goto out; + return -EINVAL; } =20 - rc =3D 0; - -out: - client->recv_coroutine =3D NULL; - nbd_client_receive_next_request(client); - - return rc; + return 0; } =20 /* Owns a reference to the NBDClient passed as opaque. */ @@ -1113,6 +1096,8 @@ static coroutine_fn void nbd_trip(void *opaque) =20 req =3D nbd_request_get(client); ret =3D nbd_co_receive_request(req, &request); + client->recv_coroutine =3D NULL; + nbd_client_receive_next_request(client); if (ret =3D=3D -EIO) { goto out; } --=20 1.8.3.1