From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9CE2C4361A for ; Fri, 4 Dec 2020 14:41:18 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2C41722571 for ; Fri, 4 Dec 2020 14:41:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2C41722571 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1klCGq-0001yL-Uh for qemu-devel@archiver.kernel.org; Fri, 04 Dec 2020 09:41:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klCFk-0001RL-1n for qemu-devel@nongnu.org; Fri, 04 Dec 2020 09:40:08 -0500 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]:39382) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1klCFi-0000cT-7F for qemu-devel@nongnu.org; Fri, 04 Dec 2020 09:40:07 -0500 Received: by mail-ed1-x541.google.com with SMTP id c7so6054001edv.6 for ; Fri, 04 Dec 2020 06:40:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7L+cOp7Rr28XgH3I9u8syuq6ZvKSAZla9VJhW1pFxyU=; b=ofLcaKR9e1tai1R018QvJMouNjWgj+0s19JKuMjlQJFeyniBX/gRBrhPonJwGCI03g RSr9ULJjqHkvF2PKqEkbVtLpUUvb13G4R/Y5XBPeugteIjew9A2P2eZlGdu0SeF1w3OF FVcjLHaA6Vr28xwhPYDfrpMBGR9r4eBILvZa3Pa5Xia1p+e6FIygNdiLxgmyWmv96JoL hxqIk3KDY9wzUoQ9ZV9yHtmz+2XB+6p1LIsGDgqVOvFR9SnYXZ8scksdK0md0hqpB0Mp PBED6ZOUXU9qDzqJpSPOdfHsjPHhws3ZxJDHyjTIM/3uuYB1mCmrKnrsVlWAOHCB62Pz bbAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7L+cOp7Rr28XgH3I9u8syuq6ZvKSAZla9VJhW1pFxyU=; b=AjjWxIDVSvVcrPtDXQMpwbKsHqXWZ9jsK+bFwn0PRW7kC0sqEhkILnVLawlcG9p+mi 4SWz7jXEluHHJ+if2OkDeMH0RQ4r/7CI2snYsP+V3cQjwBnLxTAoSvPlxJ7LJqnz0mFC 1I4GCu9B7VYUX7/HjnHSCklu9MXwAwLDX02FKUeXsi1i0HQdw3Hz/9E5aKMUSv98DKu3 Je6Dp7XT2vLs4PFsrfy+BakDTv7pyXs+Vd4mo41JlVPAeAuwv+jsTAzyJT5SvE1RkM4M lhAgRe7u/c1AdleXXVgJBKnjCneCakdHNxSzMNmpL/yobiceU9mrjqdX2zYWhe9+btf8 u5lA== X-Gm-Message-State: AOAM532jHrI2+81QPCTkciPcfUT30EDgFpJqo9IrUKzAcrFJkcXV+5zx EFcxrt4y/wB1IXIr+8Q9zWYAp9Br5HujYCk+U+g= X-Google-Smtp-Source: ABdhPJwSdg+Y+JJdyW3p5odh0kUcBS3r/bN1se6azrvWoMD+FJjiAEDESSUTNJ/dvDtCBhn6dCIDdjkQwb+cjlfjOBU= X-Received: by 2002:aa7:c558:: with SMTP id s24mr7905967edr.257.1607092804291; Fri, 04 Dec 2020 06:40:04 -0800 (PST) MIME-Version: 1.0 References: <599c6eb3f07b3ef16f29ad8fda005ddecc038566.1602784930.git.jag.raman@oracle.com> In-Reply-To: <599c6eb3f07b3ef16f29ad8fda005ddecc038566.1602784930.git.jag.raman@oracle.com> From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= Date: Fri, 4 Dec 2020 18:39:52 +0400 Message-ID: Subject: Re: [PATCH v11 05/19] multi-process: add qio channel function to transmit To: Jagannathan Raman Content-Type: multipart/alternative; boundary="000000000000b8924b05b5a4736f" Received-SPF: pass client-ip=2a00:1450:4864:20::541; envelope-from=marcandre.lureau@gmail.com; helo=mail-ed1-x541.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Elena Ufimtseva , Fam Zheng , Swapnil Ingle , John G Johnson , QEMU , Gerd Hoffmann , Juan Quintela , "Michael S. Tsirkin" , Markus Armbruster , Kanth Ghatraju , Felipe Franciosi , Thomas Huth , Eduardo Habkost , Konrad Rzeszutek Wilk , "Dr. David Alan Gilbert" , Alex Williamson , Stefan Hajnoczi , Thanos Makatos , Richard Henderson , Kevin Wolf , "Daniel P. Berrange" , Max Reitz , Ross Lagerwall , Paolo Bonzini Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --000000000000b8924b05b5a4736f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Oct 15, 2020 at 10:05 PM Jagannathan Raman wrote: > From: Elena Ufimtseva > > The entire array of the memory regions and file handlers. > Will be used in the next patch. > > Signed-off-by: Elena Ufimtseva > Signed-off-by: John G Johnson > Signed-off-by: Jagannathan Raman > Reviewed-by: Stefan Hajnoczi > --- > include/io/channel.h | 24 ++++++++++++++++++++++++ > io/channel.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 69 insertions(+) > > diff --git a/include/io/channel.h b/include/io/channel.h > index 3c04f0e..6807506 100644 > --- a/include/io/channel.h > +++ b/include/io/channel.h > @@ -773,5 +773,29 @@ void qio_channel_set_aio_fd_handler(QIOChannel *ioc, > IOHandler *io_read, > IOHandler *io_write, > void *opaque); > +/** > + * qio_channel_writev_full_all: > + * @ioc: the channel object > + * @iov: the array of memory regions to write data from > + * @niov: the length of the @iov array > + * @fds: an array of file handles to send > + * @nfds: number of file handles in @fds > + * @errp: pointer to a NULL-initialized error object > + * > + * > + * Behaves like qio_channel_writev_full but will attempt > + * to send all data passed (file handles and memory regions). > + * The function will wait for all requested data > + * to be written, yielding from the current coroutine > + * if required. > + * > + * Returns: 0 if all bytes were written, or -1 on error > + */ > + > +int qio_channel_writev_full_all(QIOChannel *ioc, > + const struct iovec *iov, > + size_t niov, > + int *fds, size_t nfds, > + Error **errp); > > #endif /* QIO_CHANNEL_H */ > diff --git a/io/channel.c b/io/channel.c > index e4376eb..22c10c5 100644 > --- a/io/channel.c > +++ b/io/channel.c > @@ -190,6 +190,51 @@ int qio_channel_writev_all(QIOChannel *ioc, > return ret; > } > > +int qio_channel_writev_full_all(QIOChannel *ioc, > + const struct iovec *iov, > + size_t niov, > + int *fds, size_t nfds, > + Error **errp) > +{ > Please make qio_channel_writev_all() call qio_channel_writev_full_all() to avoid logic duplication. thanks + int ret =3D -1; > + struct iovec *local_iov =3D g_new(struct iovec, niov); > + struct iovec *local_iov_head =3D local_iov; > + unsigned int nlocal_iov =3D niov; > + > + nlocal_iov =3D iov_copy(local_iov, nlocal_iov, > + iov, niov, > + 0, iov_size(iov, niov)); > + > + while (nlocal_iov > 0) { > + ssize_t len; > + len =3D qio_channel_writev_full(ioc, local_iov, nlocal_iov, fds, > + nfds, errp); > + if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { > + if (qemu_in_coroutine()) { > + qio_channel_yield(ioc, G_IO_OUT); > + } else { > + qio_channel_wait(ioc, G_IO_OUT); > + } > + continue; > + } > + if (len < 0) { > + goto cleanup; > + } > + > + iov_discard_front(&local_iov, &nlocal_iov, len); > + > + if (len > 0) { > + fds =3D NULL; > + nfds =3D 0; > + } > + } > + > + ret =3D 0; > + cleanup: > + g_free(local_iov_head); > + return ret; > +} > + > ssize_t qio_channel_readv(QIOChannel *ioc, > const struct iovec *iov, > size_t niov, > -- > 1.8.3.1 > > --=20 Marc-Andr=C3=A9 Lureau --000000000000b8924b05b5a4736f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Thu, Oct 15, 2020 at 10:05 PM Jaga= nnathan Raman <jag.raman@oracle.= com> wrote:
From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

The entire array of the memory regions and file handlers.
Will be used in the next patch.

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
=C2=A0include/io/channel.h | 24 ++++++++++++++++++++++++
=C2=A0io/channel.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 45 ++++++++++++++++++= +++++++++++++++++++++++++++
=C2=A02 files changed, 69 insertions(+)

diff --git a/include/io/channel.h b/include/io/channel.h
index 3c04f0e..6807506 100644
--- a/include/io/channel.h
+++ b/include/io/channel.h
@@ -773,5 +773,29 @@ void qio_channel_set_aio_fd_handler(QIOChannel *ioc, =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0IOHandler *io_re= ad,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0IOHandler *io_wr= ite,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0void *opaque); +/**
+ * qio_channel_writev_full_all:
+ * @ioc: the channel object
+ * @iov: the array of memory regions to write data from
+ * @niov: the length of the @iov array
+ * @fds: an array of file handles to send
+ * @nfds: number of file handles in @fds
+ * @errp: pointer to a NULL-initialized error object
+ *
+ *
+ * Behaves like qio_channel_writev_full but will attempt
+ * to send all data passed (file handles and memory regions).
+ * The function will wait for all requested data
+ * to be written, yielding from the current coroutine
+ * if required.
+ *
+ * Returns: 0 if all bytes were written, or -1 on error
+ */
+
+int qio_channel_writev_full_all(QIOChannel *ioc,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0const struct iovec *iov,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0size_t niov,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0int *fds, size_t nfds,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0Error **errp);

=C2=A0#endif /* QIO_CHANNEL_H */
diff --git a/io/channel.c b/io/channel.c
index e4376eb..22c10c5 100644
--- a/io/channel.c
+++ b/io/channel.c
@@ -190,6 +190,51 @@ int qio_channel_writev_all(QIOChannel *ioc,
=C2=A0 =C2=A0 =C2=A0return ret;
=C2=A0}

+int qio_channel_writev_full_all(QIOChannel *ioc,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 const struct iovec *iov,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size_t niov,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 int *fds, size_t nfds,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Error **errp)
+{

Please make qio_channel_writev_all()= call qio_channel_writev_full_all() to avoid logic duplication.
<= br>
thanks

+=C2=A0 =C2=A0 int ret =3D -1;
+=C2=A0 =C2=A0 struct iovec *local_iov =3D g_new(struct iovec, niov);
+=C2=A0 =C2=A0 struct iovec *local_iov_head =3D local_iov;
+=C2=A0 =C2=A0 unsigned int nlocal_iov =3D niov;
+
+=C2=A0 =C2=A0 nlocal_iov =3D iov_copy(local_iov, nlocal_iov,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 iov, niov,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 0, iov_size(iov, niov));
+
+=C2=A0 =C2=A0 while (nlocal_iov > 0) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 ssize_t len;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 len =3D qio_channel_writev_full(ioc, local_iov= , nlocal_iov, fds,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 nfds, errp); +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (qemu_in_coroutine()) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 qio_channel_yield(= ioc, G_IO_OUT);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } else {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 qio_channel_wait(i= oc, G_IO_OUT);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 continue;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (len < 0) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto cleanup;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 iov_discard_front(&local_iov, &nlocal_= iov, len);
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (len > 0) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fds =3D NULL;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 nfds =3D 0;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 ret =3D 0;
+ cleanup:
+=C2=A0 =C2=A0 g_free(local_iov_head);
+=C2=A0 =C2=A0 return ret;
+}
+
=C2=A0ssize_t qio_channel_readv(QIOChannel *ioc,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0const struct iovec *iov,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0size_t niov,
--
1.8.3.1



--
Marc-Andr=C3=A9 Lureau
--000000000000b8924b05b5a4736f--