From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Ian Campbell <ian.campbell@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>,
Ian Jackson <Ian.Jackson@eu.citrix.com>,
Xen-devel <xen-devel@lists.xen.org>
Subject: Re: [PATCH v5] tools/libxc: Implement writev_exact() in the same style as write_exact()
Date: Thu, 19 Feb 2015 16:58:08 +0000 [thread overview]
Message-ID: <54E61620.1080207@citrix.com> (raw)
In-Reply-To: <1424363980.30924.125.camel@citrix.com>
On 19/02/15 16:39, Ian Campbell wrote:
> On Thu, 2015-02-19 at 11:45 +0000, Andrew Cooper wrote:
>
>> + while ( iov_idx < iovcnt )
>> + {
>> + /* Skip over iov[] entries with 0 length. */
>> + while ( iov[iov_idx].iov_len == 0 )
>> + if ( ++iov_idx == iovcnt )
>> + goto out;
> Is this required for some reason or just an optimisation?
Experimentally, submitting a writev() with every iov of length 0 results
in an EINVAL on CentOS 5.x
This causes a failure if a partial write adjustment happens and only iov
entries of length 0 remain in the set.
>
>> +
>> + len = writev(fd, &iov[iov_idx], min(iovcnt - iov_idx, IOV_MAX));
>> + saved_errno = errno;
>> +
>> + if ( (len == -1) && (errno == EINTR) )
>> + continue;
>> + if ( len <= 0 )
>> + {
>> + rc = -1;
>> + goto out;
>> + }
>> +
>> + /* Check iov[] to see whether we had a partial or complete write. */
>> + while ( len > 0 && (iov_idx < iovcnt) )
>> + {
>> + if ( len >= iov[iov_idx].iov_len )
>> + len -= iov[iov_idx++].iov_len;
>> + else
>> + {
>> + /* Partial write of iov[iov_idx]. Copy iov so we can adjust
>> + * element iov_idx and resubmit the rest. */
> I suppose we can't / don't want to just declare that the input is
> non-const and potentially corrupted?
That was the v1 implementation, and specifically objected to during review.
>
>> + if ( !local_iov )
>> + {
>> + local_iov = malloc(iovcnt * sizeof(*iov));
>> + if ( !local_iov )
>> + {
>> + saved_errno = ENOMEM;
>> + goto out;
> What is rc at this point? I think it is 0, but I think you want it to be
> -1?
>
> It might be better to drop the inialiser of rc and set it in the one or
> two places which would then need it (the goto out in the skip-0-length
> loop and just before the out label AFAICT).
>
>
Hmm yes - I shall do.
For what it is worth, I can't find any way of provoking a partial write
of an individual iov element, and I don't realistically expect this
codepath to actually be used. POSIX however doesn't guarantee that it
can't happen.
~Andrew
next prev parent reply other threads:[~2015-02-19 16:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-19 11:45 [PATCH v5] tools/libxc: Implement writev_exact() in the same style as write_exact() Andrew Cooper
2015-02-19 16:39 ` Ian Campbell
2015-02-19 16:58 ` Andrew Cooper [this message]
2015-02-19 17:01 ` Ian Campbell
2015-02-19 18:20 ` Andrew Cooper
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=54E61620.1080207@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=ian.campbell@citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.