From: Martin Peschke <mp3@de.ibm.com>
To: virtualization@lists.linux-foundation.org
Subject: Re: [PATCH 2/3] Virtio draft IV: the block driver
Date: Mon, 09 Jul 2007 17:54:30 +0200 [thread overview]
Message-ID: <1183996470.9982.30.camel@dix> (raw)
In-Reply-To: <46924364.3070006@de.ibm.com>
On Mon, 2007-07-09 at 16:17 +0200, Martin Peschke wrote:
> > +static void do_virtblk_request(request_queue_t *q)
> > +{
> > + struct virtio_blk *vblk = NULL;
> > + struct request *req;
> > + struct virtblk_req *vbr;
> > +
> > + while ((req = elv_next_request(q)) != NULL) {
> > + vblk = req->rq_disk->private_data;
> > +
> > + vbr = mempool_alloc(vblk->pool, GFP_ATOMIC);
> > + if (!vbr)
> > + goto stop;
> > +
> > + BUG_ON(req->nr_phys_segments > ARRAY_SIZE(vblk->sg));
> > + vbr->req = req;
> > + if (!do_req(q, vblk, vbr))
> > + goto stop;
> > + blkdev_dequeue_request(req);
> > + }
> > +
> > +sync:
> > + if (vblk)
>
>
> this check looks bogus, as vblk->pool has been accessed unconditionally above
Sorry, I have been seduced by the code to misread it.
The check is correct and needed.
Looks like we can make it more readable, though.
- get rid of convoluted goto's
- no need for calling mempool_free() with NULL-pointer
- read private data from q->queuedata once instead of poking inside
every request
- use a local variable to track issued requests and the need for
a sync-operation
- pass req to do_req() as it is used there throughout the function
(nice symmetry in parameter list, isn't it?)
It's just an untested and incomplete sketch done while I am acquainting
myself with the virtio code without having set up lguest yet.
static void do_virtblk_request(request_queue_t *q)
{
struct virtio_blk *vblk = q->queuedata;
struct request *req;
struct virtblk_req *vbr;
int issued = 0;
while ((req = elv_next_request(q)) != NULL) {
vbr = mempool_alloc(vblk->pool, GFP_ATOMIC);
if (!vbr) {
blk_stop_queue(q);
break;
}
BUG_ON(req->nr_phys_segments > ARRAY_SIZE(vblk->sg));
vbr->req = req;
if (!do_req(q, vblk, req, vbr)) {
/* Queue full? Wait. */
blk_stop_queue(q);
mempool_free(vbr, vblk->pool);
break;
}
blkdev_dequeue_request(req);
issued++;
}
if (issued)
vblk->vq->ops->sync(vblk->vq);
}
next prev parent reply other threads:[~2007-07-09 15:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-09 14:17 [PATCH 2/3] Virtio draft IV: the block driver Martin Peschke
2007-07-09 15:54 ` Martin Peschke [this message]
2007-07-10 4:42 ` Rusty Russell
2007-07-10 12:12 ` Martin Peschke
-- strict thread matches above, loose matches on Subject: below --
2007-07-04 4:12 [PATCH 1/3] Virtio draft IV Rusty Russell
2007-07-04 4:19 ` [PATCH 2/3] Virtio draft IV: the block driver Rusty Russell
2007-07-05 7:32 ` Christian Borntraeger
2007-07-06 0:33 ` Rusty Russell
2007-07-23 11:13 ` Christian Borntraeger
2007-07-24 3:02 ` Rusty Russell
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=1183996470.9982.30.camel@dix \
--to=mp3@de.ibm.com \
--cc=virtualization@lists.linux-foundation.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).