From patchwork Tue Mar 13 18:03:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 885409 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4013j71l4Sz9sT3 for ; Wed, 14 Mar 2018 05:46:19 +1100 (AEDT) Received: from localhost ([::1]:42047 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evowC-000406-Od for incoming@patchwork.ozlabs.org; Tue, 13 Mar 2018 14:46:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evoGz-0000zR-Sz for qemu-devel@nongnu.org; Tue, 13 Mar 2018 14:03:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evoGv-0008AY-Pw for qemu-devel@nongnu.org; Tue, 13 Mar 2018 14:03:41 -0400 Received: from relay.sw.ru ([185.231.240.75]:37686) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evoGk-000801-6P; Tue, 13 Mar 2018 14:03:26 -0400 Received: from msk-vpn.virtuozzo.com ([195.214.232.6] helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.89) (envelope-from ) id 1evoGi-0002JZ-KW; Tue, 13 Mar 2018 21:03:24 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 21:03:15 +0300 Message-Id: <20180313180320.339796-9-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20180313180320.339796-1-vsementsov@virtuozzo.com> References: <20180313180320.339796-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v11 08/13] migration/qemu-file: add qemu_put_counted_string() 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: kwolf@redhat.com, peter.maydell@linaro.org, vsementsov@virtuozzo.com, famz@redhat.com, lirans@il.ibm.com, quintela@redhat.com, jsnow@redhat.com, armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, amit.shah@redhat.com, pbonzini@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add function opposite to qemu_get_counted_string. qemu_put_counted_string puts one-byte length of the string (string should not be longer than 255 characters), and then it puts the string, without last zero byte. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow Reviewed-by: Juan Quintela Reviewed-by: Fam Zheng --- migration/qemu-file.h | 2 ++ migration/qemu-file.c | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/migration/qemu-file.h b/migration/qemu-file.h index aae4e5ed36..f4f356ab12 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -174,4 +174,6 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset, ram_addr_t offset, size_t size, uint64_t *bytes_sent); +void qemu_put_counted_string(QEMUFile *f, const char *name); + #endif diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 2ab2bf362d..e85f501f86 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -734,6 +734,19 @@ size_t qemu_get_counted_string(QEMUFile *f, char buf[256]) } /* + * Put a string with one preceding byte containing its length. The length of + * the string should be less than 256. + */ +void qemu_put_counted_string(QEMUFile *f, const char *str) +{ + size_t len = strlen(str); + + assert(len < 256); + qemu_put_byte(f, len); + qemu_put_buffer(f, (const uint8_t *)str, len); +} + +/* * Set the blocking state of the QEMUFile. * Note: On some transports the OS only keeps a single blocking state for * both directions, and thus changing the blocking on the main