Skip to content

Commit 0a11cc3

Browse files
committed
virtio_blk: remove nents member.
It's simply a flag as to whether we have data now, so make it an explicit function parameter rather than a member of struct virtblk_req. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Reviewed-by: Asias He <asias@redhat.com>
1 parent 20af3cf commit 0a11cc3

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

‎drivers/block/virtio_blk.c‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ struct virtblk_req
6262
struct virtio_blk *vblk;
6363
int flags;
6464
u8 status;
65-
int nents;
6665
struct scatterlist sg[];
6766
};
6867

@@ -104,7 +103,7 @@ static inline struct virtblk_req *virtblk_alloc_req(struct virtio_blk *vblk,
104103
static int __virtblk_add_req(struct virtqueue *vq,
105104
struct virtblk_req *vbr,
106105
struct scatterlist *data_sg,
107-
unsigned data_nents)
106+
bool have_data)
108107
{
109108
struct scatterlist hdr, status, cmd, sense, inhdr, *sgs[6];
110109
unsigned int num_out = 0, num_in = 0;
@@ -124,7 +123,7 @@ static int __virtblk_add_req(struct virtqueue *vq,
124123
sgs[num_out++] = &cmd;
125124
}
126125

127-
if (data_nents) {
126+
if (have_data) {
128127
if (vbr->out_hdr.type & VIRTIO_BLK_T_OUT)
129128
sgs[num_out++] = data_sg;
130129
else
@@ -144,15 +143,15 @@ static int __virtblk_add_req(struct virtqueue *vq,
144143
return virtqueue_add_sgs(vq, sgs, num_out, num_in, vbr, GFP_ATOMIC);
145144
}
146145

147-
static void virtblk_add_req(struct virtblk_req *vbr)
146+
static void virtblk_add_req(struct virtblk_req *vbr, bool have_data)
148147
{
149148
struct virtio_blk *vblk = vbr->vblk;
150149
DEFINE_WAIT(wait);
151150
int ret;
152151

153152
spin_lock_irq(vblk->disk->queue->queue_lock);
154153
while (unlikely((ret = __virtblk_add_req(vblk->vq, vbr, vbr->sg,
155-
vbr->nents)) < 0)) {
154+
have_data)) < 0)) {
156155
prepare_to_wait_exclusive(&vblk->queue_wait, &wait,
157156
TASK_UNINTERRUPTIBLE);
158157

@@ -173,30 +172,31 @@ static void virtblk_bio_send_flush(struct virtblk_req *vbr)
173172
vbr->out_hdr.type = VIRTIO_BLK_T_FLUSH;
174173
vbr->out_hdr.sector = 0;
175174
vbr->out_hdr.ioprio = 0;
176-
vbr->nents = 0;
177175

178-
virtblk_add_req(vbr);
176+
virtblk_add_req(vbr, false);
179177
}
180178

181179
static void virtblk_bio_send_data(struct virtblk_req *vbr)
182180
{
183181
struct virtio_blk *vblk = vbr->vblk;
184182
struct bio *bio = vbr->bio;
183+
bool have_data;
185184

186185
vbr->flags &= ~VBLK_IS_FLUSH;
187186
vbr->out_hdr.type = 0;
188187
vbr->out_hdr.sector = bio->bi_sector;
189188
vbr->out_hdr.ioprio = bio_prio(bio);
190189

191-
vbr->nents = blk_bio_map_sg(vblk->disk->queue, bio, vbr->sg);
192-
if (vbr->nents) {
190+
if (blk_bio_map_sg(vblk->disk->queue, bio, vbr->sg)) {
191+
have_data = true;
193192
if (bio->bi_rw & REQ_WRITE)
194193
vbr->out_hdr.type |= VIRTIO_BLK_T_OUT;
195194
else
196195
vbr->out_hdr.type |= VIRTIO_BLK_T_IN;
197-
}
196+
} else
197+
have_data = false;
198198

199-
virtblk_add_req(vbr);
199+
virtblk_add_req(vbr, have_data);
200200
}
201201

202202
static void virtblk_bio_send_data_work(struct work_struct *work)

0 commit comments

Comments
 (0)