From nobody Sun Feb 8 20:12:52 2026 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; 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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1559033259; cv=none; d=zoho.com; s=zohoarc; b=oMEWJiI/vBEwfMz2VYvTHh5/3UTz8k9LHEfkpIS9nxBPeeQdXXW8nZIbeIfmCt3POCno4sLgoMlo17RFastkSGGOimBSKwN6MGBQWMktXsptKjNhBZiThTXO460fkJyfXJt8WwoSq8W6ZNZRCqIdufO+LWT/uO4qtvpJL0PZPnY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559033259; 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=8kJ1/mF48E5hWqjVgJoM2TimnNbzY7/cMyEzjK9F+xs=; b=KZyana7IkWXySBxptbn4s24jQvbHSIYKMoZ5mfhEvl8aDSocSdtAtuVf3ZFl4cInJBK7S7iPwHBcxutJ6Mly3H5w7dasUtmI2qCH+XliQoT2Vke1TiW3jvtQZniQGqxqynEgQBlY73h9/lse7bMTuVbLZSEgJmqe8GzQfGDbcbc= ARC-Authentication-Results: i=1; mx.zoho.com; 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 1559033259286745.0972891130094; Tue, 28 May 2019 01:47:39 -0700 (PDT) Received: from localhost ([127.0.0.1]:59275 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVXla-0007Lc-92 for importer@patchew.org; Tue, 28 May 2019 04:47:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58034) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVXjz-0006Wz-B2 for qemu-devel@nongnu.org; Tue, 28 May 2019 04:45:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hVXjx-00038O-VM for qemu-devel@nongnu.org; Tue, 28 May 2019 04:45:51 -0400 Received: from relay.sw.ru ([185.231.240.75]:57172) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hVXjx-00035t-OH; Tue, 28 May 2019 04:45:49 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hVXju-0001Ec-I5; Tue, 28 May 2019 11:45:46 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 28 May 2019 11:45:43 +0300 Message-Id: <20190528084544.183558-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190528084544.183558-1-vsementsov@virtuozzo.com> References: <20190528084544.183558-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 1/2] util/iov: introduce qemu_iovec_init_extended 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, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Introduce new initialization API, to create requests with padding. Will be used in the following patch. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/qemu/iov.h | 5 +++ util/iov.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/include/qemu/iov.h b/include/qemu/iov.h index 48b45987b7..1c5be66102 100644 --- a/include/qemu/iov.h +++ b/include/qemu/iov.h @@ -199,6 +199,11 @@ static inline void *qemu_iovec_buf(QEMUIOVector *qiov) =20 void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint); void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int n= iov); +void qemu_iovec_init_extended( + QEMUIOVector *qiov, + void *left, size_t left_len, + QEMUIOVector *middle, size_t middle_offset, size_t middle_len, + void *right, size_t right_len); void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len); void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t soffset, size_t sbytes); diff --git a/util/iov.c b/util/iov.c index 74e6ca8ed7..6bfd609998 100644 --- a/util/iov.c +++ b/util/iov.c @@ -353,6 +353,95 @@ void qemu_iovec_concat(QEMUIOVector *dst, qemu_iovec_concat_iov(dst, src->iov, src->niov, soffset, sbytes); } =20 +/* + * qiov_find_iov + * + * Return iov, where byte at @offset (in @qiov) is. + * Update @offset to be offset inside that iov to the smae byte. + */ +static struct iovec *qiov_find_iov(QEMUIOVector *qiov, size_t *offset) +{ + struct iovec *iov =3D qiov->iov; + + assert(*offset < qiov->size); + + while (*offset >=3D iov->iov_len) { + *offset -=3D iov->iov_len; + iov++; + } + + return iov; +} + +/* + * qiov_slice + * + * Fund subarray of iovec's, containing requested range. @head would + * be offset in first iov (retruned by the function), @tail would be + * count of extra bytes in last iov (returned iov + @niov - 1). + */ +static struct iovec *qiov_slice(QEMUIOVector *qiov, + size_t offset, size_t len, + size_t *head, size_t *tail, int *niov) +{ + struct iovec *iov =3D qiov_find_iov(qiov, &offset), *end_iov; + size_t end_offset; + + assert(offset + len <=3D qiov->size); + + end_offset =3D iov->iov_len; + end_iov =3D iov + 1; + + while (end_offset - offset < len) { + end_offset +=3D end_iov->iov_len; + end_iov++; + } + + *niov =3D end_iov - iov; + *head =3D offset; + *tail =3D (end_offset - offset) - len; + + return iov; +} + +/* + * Compile new iovec, combining @head_buf buffer, sub-qiov of @mid_qiov, + * and @tail_buf buffer into new qiov. + */ +void qemu_iovec_init_extended( + QEMUIOVector *qiov, + void *head_buf, size_t head_len, + QEMUIOVector *mid_qiov, size_t mid_offset, size_t mid_len, + void *tail_buf, size_t tail_len) +{ + size_t mid_head, mid_tail; + int niov; + struct iovec *p, *mid_iov =3D qiov_slice(mid_qiov, mid_offset, mid_len, + &mid_head, &mid_tail, &niov); + + assert(niov); + qiov->niov =3D qiov->nalloc =3D niov + !!head_len + !!tail_len; + qiov->size =3D head_len + mid_len + tail_len; + + p =3D qiov->iov =3D g_new(struct iovec, qiov->niov); + if (head_len) { + p->iov_base =3D head_buf; + p->iov_len =3D head_len; + p++; + } + + memcpy(p, mid_iov, niov * sizeof(*p)); + p[0].iov_base =3D (uint8_t *)p[0].iov_base + mid_head; + p[0].iov_len -=3D mid_head; + p[niov - 1].iov_len -=3D mid_tail; + p +=3D niov; + + if (tail_len) { + p->iov_base =3D tail_buf; + p->iov_len =3D tail_len; + } +} + /* * Check if the contents of the iovecs are all zero */ --=20 2.18.0