From nobody Fri Apr 26 07:35:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1568208631; cv=none; d=zoho.com; s=zohoarc; b=d77qucPaoo5XgPFeXs+LcTzB4Z0xdTDf8vCD/7zdy2HC3pygHZVBpDSzCO4ujPq8Jsw3TDr2m2Qx2O1tgxXakCflqGlzIXSXPtnHtd7hUx3SHTSuPOySw0DiG4nMB4jxZYPWAFt1wG1Xx3A72X2EBCUgPXhi3PKufTBLPlFtAyI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568208631; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=V1495VjBr5Eee/kq6x6EHhYczJaWW3yVjCdU/LV7Ty4=; b=UKqogdkoHLOOwCGfwv7xj4XUBvbRfUQXnYb5aC/me8IBj1JJiZFQjyQdEQDoLT8L/Iy3uHTh3nTQSMm7zppZ2MtyAUbwtckCWexcQ/RtFV+nZKi7iELJXZtzQLOgqbpJHUhdpbHWoyz94F0akV21ZwYu89OAM+K9zS9k13I8Bvg= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568208631033729.4389914162716; Wed, 11 Sep 2019 06:30:31 -0700 (PDT) Received: from localhost ([::1]:51096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i82hS-0004Xl-Bc for importer@patchew.org; Wed, 11 Sep 2019 09:30:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59991) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i82fx-0003Iv-TR for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:28:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i82fx-00025i-13 for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:28:49 -0400 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]:33210) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i82fw-00025J-Rm for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:28:48 -0400 Received: by mail-ed1-x52f.google.com with SMTP id o9so20683401edq.0 for ; Wed, 11 Sep 2019 06:28:48 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id l1sm4152298edc.11.2019.09.11.06.28.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Sep 2019 06:28:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=V1495VjBr5Eee/kq6x6EHhYczJaWW3yVjCdU/LV7Ty4=; b=u1dC051LW77bp9B23kRV6AmfNSzZIwY/X9BYF2a6TDEKc1AeTGHez/Kl7AMII19QMV 1ECJN244Q9y5QOvl0JcryTbTpMY2XM+fueQOZLhMlVvoULrTdLvqJ8BFxIdvA/QOPQwS 2JDO0bhu/0AT8kOg0n6XkNuQXXMrzzf1ReMXQmDQAuEftQIqghKDFif3neBwQ43lNuGC pOw0robJ2T0N+DHPpDe14PCK+21g9zJEajzJPZmSOnaq/N7ZL7hyG0qQOF2KJw7WRDmV anDpsFPoElyTxOmpRY5Oe7IQgFdb6X4RSe+foX5Agidqs7rA14C2jb9xKtqyXpljpCfW 3isw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=V1495VjBr5Eee/kq6x6EHhYczJaWW3yVjCdU/LV7Ty4=; b=cEgHL2NTmY9X6zWPFoPxj46/XfaTNEjm3wc87YUnkBxO5QSMql5uitzWRDse6UA0Fo ZbTu9HQ9efhkXEQmjpg6MNhku4XhRNoQE24aj/NTYb1v8a+zKFUl5VYehZDLyqEI9GJm 3o2nKqMO1PSiu0mnMPBg5i0a6FcfMc6wXwO3uVWKaoaaS7xtB1uiaeIX3pgepQbFq4cf wgdVTuG+CubTJ5dTZ7ZTjEoInqRTSP3QF75+fdN9RokHIEdjO5AHlgSbOkQERI+uzVVu VoyNWWzXIBa5H60xVrPBgf+yuZCulmCqlW7RuRXeN+jVwMZoSDJV0QqIgkN+gxTNnEUX qNMQ== X-Gm-Message-State: APjAAAUsb1dLtBeJbwIQx0Lm2Ncs2rzqux9hiVhDNPC22afwXjsHJlu0 sNDVOsBJVEbPnEaqDGZ7PSiiHKDD X-Google-Smtp-Source: APXvYqz/zsLNxS3uISJ4ENjDI6gz6yqweEDYUKpv3fPJd3m3hDB+9uFfrQIG3F4redSfZZ9VB4qmOg== X-Received: by 2002:a17:906:aad2:: with SMTP id kt18mr29677939ejb.201.1568208527577; Wed, 11 Sep 2019 06:28:47 -0700 (PDT) From: Wei Yang To: qemu-devel@nongnu.org Date: Wed, 11 Sep 2019 13:28:38 +0000 Message-Id: <20190911132839.23336-2-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190911132839.23336-1-richard.weiyang@gmail.com> References: <20190911132839.23336-1-richard.weiyang@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::52f Subject: [Qemu-devel] [PATCH V2 1/2] migration/qemu-file: remove check on writev_buffer in qemu_put_compression_data X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wei Yang , dgilbert@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Yang The check of writev_buffer is in qemu_fflush, which means it is not harmful if it is NULL. And removing it will make the code consistent since all other add_to_iovec() is called without the check. Signed-off-by: Wei Yang Reviewed-by: Dr. David Alan Gilbert --- migration/qemu-file.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index e33c46764f..47f16d0e54 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -761,9 +761,7 @@ ssize_t qemu_put_compression_data(QEMUFile *f, z_stream= *stream, } =20 qemu_put_be32(f, blen); - if (f->ops->writev_buffer) { - add_to_iovec(f, f->buf + f->buf_index, blen, false); - } + add_to_iovec(f, f->buf + f->buf_index, blen, false); f->buf_index +=3D blen; if (f->buf_index =3D=3D IO_BUF_SIZE) { qemu_fflush(f); --=20 2.15.1 From nobody Fri Apr 26 07:35:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1568208633; cv=none; d=zoho.com; s=zohoarc; b=gvxUT0PQlk967+Ytxrcthx4ktWnuBoD659yNeu9As7sk/vacD9qZqaxG1zfIAJYc3E93QjQVAYEuQXw77476KFRFLi6sOZJZfuN0OAfcaXgtTiPzHvcTCWWsDN1ioPSCxNqe9Un2NGJfNwJFsb6KYaQ6D1dZ6/qPLwP8glcaZRM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568208633; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=pHX+56qH2ZwoTB579TAA15MpZKo/s5P4WenS+gMTRWg=; b=eOiQvsj6DpR5k/BI+SPY50TF7I7OtFJyqsX1prJOwNvEx4fVfOfpGRnTYHYDkj2QBLxpl8D+5XMzEPrOFyOqXeZ76Biwr8g+esYkHSflHWdWQsobM6kJ3syfIteN4u3xop9Yc/QRCK1Z/Rzxf1aSvlfARxIVPloLTteVUVqSQm8= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568208633471502.88151935074586; Wed, 11 Sep 2019 06:30:33 -0700 (PDT) Received: from localhost ([::1]:51098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i82hW-0004Zs-IP for importer@patchew.org; Wed, 11 Sep 2019 09:30:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60007) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i82fz-0003Ja-3r for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:28:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i82fy-00026B-1f for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:28:51 -0400 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]:44887) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i82fx-00025v-Rv for qemu-devel@nongnu.org; Wed, 11 Sep 2019 09:28:50 -0400 Received: by mail-ed1-x543.google.com with SMTP id p2so19439868edx.11 for ; Wed, 11 Sep 2019 06:28:49 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id g21sm4092827edv.0.2019.09.11.06.28.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Sep 2019 06:28:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pHX+56qH2ZwoTB579TAA15MpZKo/s5P4WenS+gMTRWg=; b=MGyAIpleehtxH6pdx2yq4RyY+Z8pj2XFpfb8d9DVnyI/aC+qAtPTl37I1a/H+h1xom ZTOcfa5ixU67yj3WKIQrrfG8uehxWsdoFfdsJojvQGiXGESZHgDR03aw5BdRUCIFtTzQ N2j3axT+bIS1Q9Jfr/tj6rZP7WuD8k3jtS7tnw15lqzvPtRptx5+yf5eCGLaj+GOQ8mH FqW6+Tj8t+KvsRT+FMTGmsCXSiUzG9334AH3Z70ekolrbEemKODjG/ukFc/c2/TNjPVP VI2kjAR5UTCaPOnIa/9bNmtvEBBbWazG8qEuhL3BII0/RbGMDzX9EOX6ST+JUmpNhG2J wR1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pHX+56qH2ZwoTB579TAA15MpZKo/s5P4WenS+gMTRWg=; b=HIB8nDvwTEmpgbhScvgaChPBrlp/x7FTv8UL7WAp+KkCp2S552xMyYmbOLpx9Eekig L7RS+GDzJ9PBbAIdYWOUAkdlzNnUM+7tMg1lA7fQFCKRha4tdW94HdolxYKEgfZBJsVc 1TZk1Oxix2DVaUqDt/Um4HzXjICO8RLhtFDJZ9MNczvn1xrlKuC/Ltw3gRlKOqqAyeSK M69JIMwylV3PvIJ6/kTbi/K0Qb/Lw4zYeDD3Bk/3i6D9k6RzuauB7Ad6Kn1u9pfVDfAD PNM6bRBHMuxIL/gBBRYeYsdk9Q4gMurmmVIOy+Y60zHCezyHSxtzgn0GcowtBnC6IlqT FEwg== X-Gm-Message-State: APjAAAUQuqSYWqNfNXFi6UB50HKklcN7W3Oz1xa1hAphb5mvwiRAYPzy V5o/vC5/oS9uxdawJ1gJTxaWkafY X-Google-Smtp-Source: APXvYqx0KI5xzVhsptG+WBnyra6WRiiVluZzUw77ymZ2Q5mtcu2CGnpxS41TvgLq4TnhyFt34miGrQ== X-Received: by 2002:a50:8933:: with SMTP id e48mr2963617ede.51.1568208528694; Wed, 11 Sep 2019 06:28:48 -0700 (PDT) From: Wei Yang To: qemu-devel@nongnu.org Date: Wed, 11 Sep 2019 13:28:39 +0000 Message-Id: <20190911132839.23336-3-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190911132839.23336-1-richard.weiyang@gmail.com> References: <20190911132839.23336-1-richard.weiyang@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::543 Subject: [Qemu-devel] [PATCH V2 2/2] migration/qemu-file: fix potential buf waste for extra buf_index adjustment X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wei Yang , dgilbert@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Yang In add_to_iovec(), qemu_fflush() will be called if iovec is full. If this happens, buf_index is reset. Currently, this is not checked and buf_index would always been adjust with buf size. This is not harmful, but will waste some space in file buffer. This patch make add_to_iovec() return 1 when it has flushed the file. Then the caller could check the return value to see whether it is necessary to adjust the buf_index any more. Signed-off-by: Wei Yang Reviewed-by: Dr. David Alan Gilbert --- v2: * wrap these common steps into add_buf_to_iovec() --- migration/qemu-file.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 47f16d0e54..417eeba64b 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -382,8 +382,16 @@ int qemu_fclose(QEMUFile *f) return ret; } =20 -static void add_to_iovec(QEMUFile *f, const uint8_t *buf, size_t size, - bool may_free) +/* + * Add buf to iovec. Do flush if iovec is full. + * + * Return values: + * 1 iovec is full and flushed + * 0 iovec is not flushed + * + */ +static int add_to_iovec(QEMUFile *f, const uint8_t *buf, size_t size, + bool may_free) { /* check for adjacent buffer and coalesce them */ if (f->iovcnt > 0 && buf =3D=3D f->iov[f->iovcnt - 1].iov_base + @@ -401,6 +409,19 @@ static void add_to_iovec(QEMUFile *f, const uint8_t *b= uf, size_t size, =20 if (f->iovcnt >=3D MAX_IOV_SIZE) { qemu_fflush(f); + return 1; + } + + return 0; +} + +static void add_buf_to_iovec(QEMUFile *f, size_t len) +{ + if (!add_to_iovec(f, f->buf + f->buf_index, len, false)) { + f->buf_index +=3D len; + if (f->buf_index =3D=3D IO_BUF_SIZE) { + qemu_fflush(f); + } } } =20 @@ -430,11 +451,7 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, = size_t size) } memcpy(f->buf + f->buf_index, buf, l); f->bytes_xfer +=3D l; - add_to_iovec(f, f->buf + f->buf_index, l, false); - f->buf_index +=3D l; - if (f->buf_index =3D=3D IO_BUF_SIZE) { - qemu_fflush(f); - } + add_buf_to_iovec(f, l); if (qemu_file_get_error(f)) { break; } @@ -451,11 +468,7 @@ void qemu_put_byte(QEMUFile *f, int v) =20 f->buf[f->buf_index] =3D v; f->bytes_xfer++; - add_to_iovec(f, f->buf + f->buf_index, 1, false); - f->buf_index++; - if (f->buf_index =3D=3D IO_BUF_SIZE) { - qemu_fflush(f); - } + add_buf_to_iovec(f, 1); } =20 void qemu_file_skip(QEMUFile *f, int size) @@ -761,11 +774,7 @@ ssize_t qemu_put_compression_data(QEMUFile *f, z_strea= m *stream, } =20 qemu_put_be32(f, blen); - add_to_iovec(f, f->buf + f->buf_index, blen, false); - f->buf_index +=3D blen; - if (f->buf_index =3D=3D IO_BUF_SIZE) { - qemu_fflush(f); - } + add_buf_to_iovec(f, blen); return blen + sizeof(int32_t); } =20 --=20 2.15.1