[{"id":3677292,"web_url":"http://patchwork.ozlabs.org/comment/3677292/","msgid":"<87eckhzgf5.fsf@suse.de>","list_archive_url":null,"date":"2026-04-14T15:54:06","subject":"Re: [PATCH v3 2/4] io/channel: introduce qio_channel_pwrite{v,\n }_all()","submitter":{"id":85343,"url":"http://patchwork.ozlabs.org/api/people/85343/","name":"Fabiano Rosas","email":"farosas@suse.de"},"content":"Junjie Cao <junjie.cao@intel.com> writes:\n\n> Add positioned write helpers that retry on short writes, matching\n> the pread_all family from the previous patch.\n>\n>   qio_channel_pwritev_all()  -- retry loop; returns 0 on success,\n>                                  -1 on error.\n>   qio_channel_pwrite_all()   -- single-buffer convenience wrapper.\n>\n> Signed-off-by: Junjie Cao <junjie.cao@intel.com>\n> ---\n>  include/io/channel.h | 41 +++++++++++++++++++++++++++++++++++++\n>  io/channel.c         | 48 ++++++++++++++++++++++++++++++++++++++++++++\n>  2 files changed, 89 insertions(+)\n>\n> diff --git a/include/io/channel.h b/include/io/channel.h\n> index 47af409ede..287d10cd6f 100644\n> --- a/include/io/channel.h\n> +++ b/include/io/channel.h\n> @@ -598,6 +598,47 @@ ssize_t qio_channel_pwritev(QIOChannel *ioc, const struct iovec *iov,\n>  ssize_t qio_channel_pwrite(QIOChannel *ioc, void *buf, size_t buflen,\n>                             off_t offset, Error **errp);\n>  \n> +/**\n> + * qio_channel_pwritev_all:\n> + * @ioc: the channel object\n> + * @iov: the array of memory regions to write data from\n> + * @niov: the length of the @iov array\n> + * @offset: the starting offset in the channel to write to\n> + * @errp: pointer to a NULL-initialized error object\n> + *\n> + * Writes @iov, possibly blocking or (if the channel is non-blocking)\n> + * yielding from the current coroutine multiple times until the entire\n> + * content is written.  Otherwise behaves as qio_channel_pwritev().\n> + *\n> + * Returns: 0 if all bytes were written, or -1 on error\n> + */\n> +int coroutine_mixed_fn qio_channel_pwritev_all(QIOChannel *ioc,\n> +                                               const struct iovec *iov,\n> +                                               size_t niov,\n> +                                               off_t offset,\n> +                                               Error **errp);\n> +\n> +/**\n> + * qio_channel_pwrite_all:\n> + * @ioc: the channel object\n> + * @buf: the memory region to write data from\n> + * @buflen: the number of bytes to write from @buf\n> + * @offset: the starting offset in the channel to write to\n> + * @errp: pointer to a NULL-initialized error object\n> + *\n> + * Writes @buflen bytes from @buf, possibly blocking or (if the\n> + * channel is non-blocking) yielding from the current coroutine\n> + * multiple times until the entire content is written.  Otherwise\n> + * behaves as qio_channel_pwrite().\n> + *\n> + * Returns: 0 if all bytes were written, or -1 on error\n> + */\n> +int coroutine_mixed_fn qio_channel_pwrite_all(QIOChannel *ioc,\n> +                                              const void *buf,\n> +                                              size_t buflen,\n> +                                              off_t offset,\n> +                                              Error **errp);\n> +\n>  /**\n>   * qio_channel_preadv\n>   * @ioc: the channel object\n> diff --git a/io/channel.c b/io/channel.c\n> index 52c1abfcbc..2853dadb68 100644\n> --- a/io/channel.c\n> +++ b/io/channel.c\n> @@ -478,6 +478,54 @@ ssize_t qio_channel_pwrite(QIOChannel *ioc, void *buf, size_t buflen,\n>      return qio_channel_pwritev(ioc, &iov, 1, offset, errp);\n>  }\n>  \n> +int coroutine_mixed_fn qio_channel_pwritev_all(QIOChannel *ioc,\n> +                                               const struct iovec *iov,\n> +                                               size_t niov,\n> +                                               off_t offset,\n> +                                               Error **errp)\n> +{\n> +    int ret = -1;\n> +    struct iovec *local_iov = g_new(struct iovec, niov);\n> +    struct iovec *local_iov_head = local_iov;\n> +    unsigned int nlocal_iov = niov;\n> +\n> +    nlocal_iov = iov_copy(local_iov, nlocal_iov,\n> +                          iov, niov,\n> +                          0, iov_size(iov, niov));\n> +\n> +    while (nlocal_iov > 0) {\n> +        ssize_t len;\n> +\n> +        len = qio_channel_pwritev(ioc, local_iov, nlocal_iov, offset, errp);\n> +\n> +        if (len == QIO_CHANNEL_ERR_BLOCK) {\n> +            qio_channel_wait_cond(ioc, G_IO_OUT);\n> +            continue;\n> +        }\n> +        if (len < 0) {\n> +            goto cleanup;\n> +        }\n> +\n> +        offset += len;\n> +        iov_discard_front(&local_iov, &nlocal_iov, len);\n> +    }\n> +\n> +    ret = 0;\n> + cleanup:\n> +    g_free(local_iov_head);\n> +    return ret;\n> +}\n> +\n> +int coroutine_mixed_fn qio_channel_pwrite_all(QIOChannel *ioc,\n> +                                              const void *buf,\n> +                                              size_t buflen,\n> +                                              off_t offset,\n> +                                              Error **errp)\n> +{\n> +    struct iovec iov = { .iov_base = (char *)buf, .iov_len = buflen };\n> +    return qio_channel_pwritev_all(ioc, &iov, 1, offset, errp);\n> +}\n> +\n>  ssize_t qio_channel_preadv(QIOChannel *ioc, const struct iovec *iov,\n>                             size_t niov, off_t offset, Error **errp)\n>  {\n\nReviewed-by: Fabiano Rosas <farosas@suse.de>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256\n header.s=susede2_rsa header.b=zK0brRpg;\n\tdkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256\n header.s=susede2_ed25519 header.b=Xz+Iyeoa;\n\tdkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de\n header.a=rsa-sha256 header.s=susede2_rsa header.b=zK0brRpg;\n\tdkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256\n header.s=susede2_ed25519 header.b=Xz+Iyeoa;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)","smtp-out2.suse.de;\n dkim=pass header.d=suse.de header.s=susede2_rsa header.b=zK0brRpg;\n dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Xz+Iyeoa"],"Received":["from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fw83g04dwz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 15 Apr 2026 01:54:38 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wCg5e-0003zN-Ad; Tue, 14 Apr 2026 11:54:14 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <farosas@suse.de>) id 1wCg5c-0003zF-RV\n for qemu-devel@nongnu.org; Tue, 14 Apr 2026 11:54:12 -0400","from smtp-out2.suse.de ([195.135.223.131])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <farosas@suse.de>) id 1wCg5b-00007F-20\n for qemu-devel@nongnu.org; Tue, 14 Apr 2026 11:54:12 -0400","from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org\n [IPv6:2a07:de40:b281:104:10:150:64:97])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n (No client certificate requested)\n by smtp-out2.suse.de (Postfix) with ESMTPS id 291AF5BD63;\n Tue, 14 Apr 2026 15:54:09 +0000 (UTC)","from imap1.dmz-prg2.suse.org (localhost [127.0.0.1])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n (No client certificate requested)\n by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B92424B512;\n Tue, 14 Apr 2026 15:54:08 +0000 (UTC)","from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167])\n by imap1.dmz-prg2.suse.org with ESMTPSA id 1VgfIiBj3mmaUgAAD6G6ig\n (envelope-from <farosas@suse.de>); Tue, 14 Apr 2026 15:54:08 +0000"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_rsa;\n t=1776182049;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=x0JI6Yi1cNU64aP7T/QtmVs8UEH86dtaFxrBG6njszo=;\n b=zK0brRpgH6fsL8YnGH/iCtRmTpjYSbSqAvJU0JsYVhFWoHRAevZ2atE8aeePIQLt+DmtXY\n QsX6pXKKcyvpF+oFHFVJSFQk9wmooYuzBYJ70l4OFPQqq0dtrDQsSXndbq3YoYFY97TZip\n QT4chq//vVf5M8y6ZW9SHbmlsJKyzOY=","v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_ed25519; t=1776182049;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=x0JI6Yi1cNU64aP7T/QtmVs8UEH86dtaFxrBG6njszo=;\n b=Xz+Iyeoa77XGRJAD8UMd5yW9dfVsviBCVRnUJIE3qMIo1xAIYBxNEceKcN4OwRGjqk4lzw\n 8QHweVeMo8Tb9DDQ==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_rsa;\n t=1776182049;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=x0JI6Yi1cNU64aP7T/QtmVs8UEH86dtaFxrBG6njszo=;\n b=zK0brRpgH6fsL8YnGH/iCtRmTpjYSbSqAvJU0JsYVhFWoHRAevZ2atE8aeePIQLt+DmtXY\n QsX6pXKKcyvpF+oFHFVJSFQk9wmooYuzBYJ70l4OFPQqq0dtrDQsSXndbq3YoYFY97TZip\n QT4chq//vVf5M8y6ZW9SHbmlsJKyzOY=","v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_ed25519; t=1776182049;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=x0JI6Yi1cNU64aP7T/QtmVs8UEH86dtaFxrBG6njszo=;\n b=Xz+Iyeoa77XGRJAD8UMd5yW9dfVsviBCVRnUJIE3qMIo1xAIYBxNEceKcN4OwRGjqk4lzw\n 8QHweVeMo8Tb9DDQ=="],"From":"Fabiano Rosas <farosas@suse.de>","To":"Junjie Cao <junjie.cao@intel.com>, qemu-devel@nongnu.org","Cc":"berrange@redhat.com, peterx@redhat.com, junjie.cao@intel.com","Subject":"Re: [PATCH v3 2/4] io/channel: introduce qio_channel_pwrite{v,\n }_all()","In-Reply-To":"<20260413214549.926435-3-junjie.cao@intel.com>","References":"<20260413214549.926435-1-junjie.cao@intel.com>\n <20260413214549.926435-3-junjie.cao@intel.com>","Date":"Tue, 14 Apr 2026 12:54:06 -0300","Message-ID":"<87eckhzgf5.fsf@suse.de>","MIME-Version":"1.0","Content-Type":"text/plain","X-Spamd-Result":"default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%];\n NEURAL_HAM_LONG(-1.00)[-1.000];\n R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519];\n NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain];\n MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[];\n RCVD_TLS_ALL(0.00)[]; MISSING_XM_UA(0.00)[];\n TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+];\n SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from];\n FUZZY_RATELIMITED(0.00)[rspamd.com];\n MID_RHS_MATCH_FROM(0.00)[];\n DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519];\n FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[];\n RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_TWO(0.00)[2];\n TO_MATCH_ENVRCPT_ALL(0.00)[];\n DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:mid,suse.de:dkim,suse.de:email,intel.com:email];\n DKIM_TRACE(0.00)[suse.de:+]","X-Rspamd-Action":"no action","X-Spam-Score":"-4.51","X-Rspamd-Server":"rspamd1.dmz-prg2.suse.org","X-Rspamd-Queue-Id":"291AF5BD63","Received-SPF":"pass client-ip=195.135.223.131; envelope-from=farosas@suse.de;\n helo=smtp-out2.suse.de","X-Spam_score_int":"-43","X-Spam_score":"-4.4","X-Spam_bar":"----","X-Spam_report":"(-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001,\n RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001,\n 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.29","Precedence":"list","List-Id":"qemu development <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"}}]