From: Stefan Hajnoczi <stefanha@redhat.com>
To: Li Qiang <liq3ea@gmail.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-block@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>,
Qemu Developers <qemu-devel@nongnu.org>,
Max Reitz <mreitz@redhat.com>, Alexander Bulekov <alxndr@bu.edu>,
"Gonglei \(Arei\)" <arei.gonglei@huawei.com>
Subject: Re: [PATCH 1/3] util/iov: add iov_discard_undo()
Date: Wed, 16 Sep 2020 11:09:05 +0100 [thread overview]
Message-ID: <20200916100905.GA756046@stefanha-x1.localdomain> (raw)
In-Reply-To: <CAKXe6S+nUWQGFDKRu8mBBOTKc1kWc7YfO=p+F7+ObnmW017atg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3020 bytes --]
On Sun, Aug 16, 2020 at 04:26:45PM +0800, Li Qiang wrote:
> Stefan Hajnoczi <stefanha@redhat.com> 于2020年8月12日周三 下午6:52写道:
Thanks for your review!
> > + /* Discard more bytes than vector size */
> > + iov_random(&iov, &iov_cnt);
> > + iov_orig = g_memdup(iov, sizeof(iov[0]) * iov_cnt);
> > + iov_tmp = iov;
> > + iov_cnt_tmp = iov_cnt;
> > + size = iov_size(iov, iov_cnt);
> > + iov_discard_front_undoable(&iov_tmp, &iov_cnt_tmp, size + 1, &undo);
> > + iov_discard_undo(&undo);
> > + assert(iov_equals(iov, iov_orig, iov_cnt));
> >
>
> The 'iov_discard_front_undoable' will change the 'iov_tmp' it will not
> touch 'iov_orig'.
> So the test will be always passed. The actually function will not be tested.
The test verifies that the iovec elements are restored to their previous
state by iov_discard_undo().
I think you are saying you'd like iov_discard_undo() to reset the
iov_tmp pointer? Currently that is not how the API works. The caller is
assumed to have the original pointer (e.g. virtio-blk has
req->elem.in/out_sg) and therefore it is not necessary to reset iov_tmp.
> Also, maybe we could abstract a function to do these discard test?
The structure of the test cases is similar but they vary in different
places. I'm not sure if this can be abstracted nicely.
> > diff --git a/util/iov.c b/util/iov.c
> > index 45ef3043ee..efcf04b445 100644
> > --- a/util/iov.c
> > +++ b/util/iov.c
> > @@ -636,14 +636,33 @@ void qemu_iovec_clone(QEMUIOVector *dest, const
> > QEMUIOVector *src, void *buf)
> > }
> > }
> >
> > -size_t iov_discard_front(struct iovec **iov, unsigned int *iov_cnt,
> > - size_t bytes)
> > +void iov_discard_undo(IOVDiscardUndo *undo)
> > +{
> > + /* Restore original iovec if it was modified */
> > + if (undo->modified_iov) {
> > + *undo->modified_iov = undo->orig;
> > + }
> > +}
> > +
> > +size_t iov_discard_front_undoable(struct iovec **iov,
> > + unsigned int *iov_cnt,
> > + size_t bytes,
> > + IOVDiscardUndo *undo)
> > {
> > size_t total = 0;
> > struct iovec *cur;
> >
> > + if (undo) {
> > + undo->modified_iov = NULL;
> > + }
> > +
> > for (cur = *iov; *iov_cnt > 0; cur++) {
> > if (cur->iov_len > bytes) {
> > + if (undo) {
> > + undo->modified_iov = cur;
> > + undo->orig = *cur;
> > + }
> > +
> >
>
> Why here we remember the 'cur'? 'cur' is the some of the 'iov'.
> Maybe we remember the 'iov'. I think we need the undo structure like this:
>
> struct IOVUndo {
> iov **modified_iov;
> iov *orig;
> };
>
> Then we can remeber the origin 'iov'.
Yes, this could be done but it's not needed (yet?). VirtQueueElement has
the original struct iovec pointers so adding this would be redundant.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2020-09-16 10:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-12 10:49 [PATCH 0/3] virtio: restore elem->in/out_sg after iov_discard_front/back() Stefan Hajnoczi
2020-08-12 10:49 ` [PATCH 1/3] util/iov: add iov_discard_undo() Stefan Hajnoczi
2020-08-16 8:26 ` Li Qiang
2020-09-16 10:09 ` Stefan Hajnoczi [this message]
2020-09-16 15:36 ` Li Qiang
2020-08-12 10:49 ` [PATCH 2/3] virtio-blk: undo destructive iov_discard_*() operations Stefan Hajnoczi
2020-09-16 15:38 ` Li Qiang
2020-09-17 9:34 ` Stefan Hajnoczi
2020-08-12 10:49 ` [PATCH 3/3] virtio-crypto: don't modify elem->in/out_sg Stefan Hajnoczi
2020-08-16 8:32 ` Li Qiang
2020-09-16 10:12 ` Stefan Hajnoczi
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=20200916100905.GA756046@stefanha-x1.localdomain \
--to=stefanha@redhat.com \
--cc=alxndr@bu.edu \
--cc=arei.gonglei@huawei.com \
--cc=kwolf@redhat.com \
--cc=liq3ea@gmail.com \
--cc=mreitz@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.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).