From: "Mário Kuka" <kuka@cesnet.cz>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: dev@dpdk.org, mdr@ashroe.eu, reshma.pattan@intel.com
Subject: Re: [PATCH v2 2/2] pcapng: check if writev() returns a partial write
Date: Fri, 29 Jul 2022 19:08:41 +0200 [thread overview]
Message-ID: <de583499-85e2-c35b-dd65-70b4fcafd3c0@cesnet.cz> (raw)
In-Reply-To: <20220729090028.25674943@hermes.local>
[-- Attachment #1: Type: text/plain, Size: 2056 bytes --]
> Since this is being written to a file, handling partial writes makes little
> sense. The only case where partial write would happen would be if filesystem
> was full. Retrying just adds unnecessary complexity.
>
> If you really want to track this, then add a dropped counter.
But the file descriptor doesn't have to refer to just a regular file, what
if it's a socket or a pipe or some device? The pcapng documentation doesn't
say anything about any restrictions, so the implementation should be fully
generic. What's the point of a function to write packets to a file
descriptor
where there's a risk that it won't write all the packets or that the
file will
by corrupted due to a partial write and still not even let me know about
it?
On 29/07/2022 18:00, Stephen Hemminger wrote:
> On Fri, 29 Jul 2022 09:18:41 +0200
> Mário Kuka <kuka@cesnet.cz> wrote:
>
>> +pcapng_writev(int fd, struct iovec *iov, const int count)
>> +{
>> + size_t total = 0;
>> + int at = 0;
>> +
>> + while (at < count) {
>> + /*
>> + * Note: writev() can return the following on a write request:
>> + * Complete:
>> + * written = [sum of all iov.iov_len]
>> + * Partial:
>> + * written < [sum of all iov.iov_len]
>> + * Deferred:
>> + * written = -1, errno = [EAGAIN]
>> + *
>> + * Partial and deferred writes are only possible with O_NONBLOCK set.
>> + *
>> + * If we get a partial result, we have to call the writev() again on any ivo buffers
>> + * that have not been fully written.
>> + */
>> + ssize_t written = writev(fd, &iov[at], count - at);
>> + if (unlikely(written < 0))
>> + return written;
>> +
>> + total += written;
>> + at += pcapng_update_iov(&iov[at], count - at, written);
>> + }
>> +
>> + return total;
> Since this is being written to a file, handling partial writes makes little
> sense. The only case where partial write would happen would be if filesystem
> was full. Retrying just adds unnecessary complexity.
>
> If you really want to track this, then add a dropped counter.
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4299 bytes --]
next prev parent reply other threads:[~2022-07-29 17:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-25 15:28 [PATCH] pcapng: fix write more packets than IOV_MAX limit Mário Kuka
2022-07-25 15:57 ` Stephen Hemminger
2022-07-25 16:10 ` Stephen Hemminger
2022-07-29 7:18 ` [PATCH v2 0/2] pcapng: fix some issues with writing packets Mário Kuka
2022-07-29 7:18 ` [PATCH v2 1/2] pcapng: fix write more packets than IOV_MAX limit Mário Kuka
2022-07-29 7:18 ` [PATCH v2 2/2] pcapng: check if writev() returns a partial write Mário Kuka
2022-07-29 16:00 ` Stephen Hemminger
2022-07-29 17:08 ` Mário Kuka [this message]
2022-07-29 18:14 ` Stephen Hemminger
2022-08-01 8:42 ` Mário Kuka
2022-07-29 15:58 ` [PATCH v2 0/2] pcapng: fix some issues with writing packets Stephen Hemminger
2022-07-29 17:33 ` Mário Kuka
2022-08-01 8:40 ` [PATCH v3] pcapng: fix write more packets than IOV_MAX limit Mário Kuka
2022-08-01 15:33 ` Stephen Hemminger
2022-10-10 0:40 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=de583499-85e2-c35b-dd65-70b4fcafd3c0@cesnet.cz \
--to=kuka@cesnet.cz \
--cc=dev@dpdk.org \
--cc=mdr@ashroe.eu \
--cc=reshma.pattan@intel.com \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).