2001-11-30 01:19:04

by Jeff Garzik

[permalink] [raw]
Subject: PATCH 2.5.1.4: fix rd.c build

Index: drivers/block/rd.c
===================================================================
RCS file: /cvsroot/gkernel/linux_2_5/drivers/block/rd.c,v
retrieving revision 1.3
diff -u -r1.3 rd.c
--- drivers/block/rd.c 2001/11/30 01:10:57 1.3
+++ drivers/block/rd.c 2001/11/30 01:17:24
@@ -239,7 +239,7 @@

index = sbh->bi_sector >> (PAGE_CACHE_SHIFT - 9);
offset = (sbh->bi_sector << 9) & ~PAGE_CACHE_MASK;
- size = bio_size(sbh);
+ size = sbh->bi_size;

do {
int count;
@@ -323,7 +323,7 @@
goto fail;

offset = sbh->bi_sector << 9;
- len = bio_size(sbh);
+ len = sbh->bi_size;

if ((offset + len) > rd_length[minor])
goto fail;


Attachments:
rd.patch (652.00 B)

2001-11-30 07:18:53

by Jens Axboe

[permalink] [raw]
Subject: Re: PATCH 2.5.1.4: fix rd.c build

On Thu, Nov 29 2001, Jeff Garzik wrote:
> ...just a missed s/bio_size/foo->bi_size/ conversion. please apply.
> --
> Jeff Garzik | Only so many songs can be sung
> Building 1024 | with two lips, two lungs, and one tongue.
> MandrakeSoft | - nomeansno
> Index: drivers/block/rd.c
> ===================================================================
> RCS file: /cvsroot/gkernel/linux_2_5/drivers/block/rd.c,v
> retrieving revision 1.3
> diff -u -r1.3 rd.c
> --- drivers/block/rd.c 2001/11/30 01:10:57 1.3
> +++ drivers/block/rd.c 2001/11/30 01:17:24
> @@ -239,7 +239,7 @@
>
> index = sbh->bi_sector >> (PAGE_CACHE_SHIFT - 9);
> offset = (sbh->bi_sector << 9) & ~PAGE_CACHE_MASK;
> - size = bio_size(sbh);
> + size = sbh->bi_size;
>
> do {
> int count;
> @@ -323,7 +323,7 @@
> goto fail;
>
> offset = sbh->bi_sector << 9;
> - len = bio_size(sbh);
> + len = sbh->bi_size;
>
> if ((offset + len) > rd_length[minor])
> goto fail;

Actually, this is not even enough if rd receives a multi page bio.
Something like this should work, untested.

--- /opt/kernel/linux-2.5.1-pre4/drivers/block/rd.c Fri Nov 30 01:59:45 2001
+++ linux/drivers/block/rd.c Fri Nov 30 02:14:06 2001
@@ -228,7 +228,8 @@
commit_write: ramdisk_commit_write,
};

-static int rd_blkdev_pagecache_IO(int rw, struct bio *sbh, int minor)
+static int rd_blkdev_pagecache_IO(int rw, struct bio_vec *vec,
+ sector_t sector, int minor)
{
struct address_space * mapping;
unsigned long index;
@@ -237,9 +238,9 @@
err = -EIO;
mapping = rd_bdev[minor]->bd_inode->i_mapping;

- index = sbh->bi_sector >> (PAGE_CACHE_SHIFT - 9);
- offset = (sbh->bi_sector << 9) & ~PAGE_CACHE_MASK;
- size = bio_size(sbh);
+ index = sector >> (PAGE_CACHE_SHIFT - 9);
+ offset = (sector << 9) & ~PAGE_CACHE_MASK;
+ size = vec->bv_len;

do {
int count;
@@ -276,18 +277,18 @@
if (rw == READ) {
src = kmap(page);
src += offset;
- dst = bio_kmap(sbh);
+ dst = kmap(vec->bv_page) + vec->bv_offset;
} else {
dst = kmap(page);
dst += offset;
- src = bio_kmap(sbh);
+ src = kmap(vec->bv_page) + vec->bv_offset;
}
offset = 0;

memcpy(dst, src, count);

kunmap(page);
- bio_kunmap(sbh);
+ kunmap(vec->bv_page);

if (rw == READ) {
flush_dcache_page(page);
@@ -303,6 +304,22 @@
return err;
}

+static int rd_blkdev_bio_IO(struct bio *bio, unsigned int minor)
+{
+ struct bio_vec *bvec;
+ sector_t sector;
+ int ret = 0, i, rw;
+
+ sector = bio->bi_sector;
+ rw = bio_data_dir(bio);
+ bio_for_each_segment(bvec, bio, i) {
+ ret |= rd_blkdev_pagecache_IO(rw, bvec, sector, minor);
+ sector += bvec->bv_len >> 9;
+ }
+
+ return ret;
+}
+
/*
* Basically, my strategy here is to set up a buffer-head which can't be
* deleted, and make that my Ramdisk. If the request is outside of the
@@ -323,7 +340,7 @@
goto fail;

offset = sbh->bi_sector << 9;
- len = bio_size(sbh);
+ len = sbh->bi_size;

if ((offset + len) > rd_length[minor])
goto fail;
@@ -335,7 +352,7 @@
goto fail;
}

- if (rd_blkdev_pagecache_IO(rw, sbh, minor))
+ if (rd_blkdev_bio_IO(sbh, minor))
goto fail;

set_bit(BIO_UPTODATE, &sbh->bi_flags);
@@ -437,10 +454,11 @@

#ifdef CONFIG_BLK_DEV_INITRD
if (unit == INITRD_MINOR) {
- if (!initrd_start) return -ENODEV;
- spin_lock( &initrd_users_lock );
+ spin_lock(&initrd_users_lock);
initrd_users++;
- spin_unlock( &initrd_users_lock );
+ spin_unlock(&initrd_users_lock);
+ if (!initrd_start)
+ return -ENODEV;
filp->f_op = &initrd_fops;
return 0;
}

--
Jens Axboe

2001-11-30 07:25:13

by Alexander Viro

[permalink] [raw]
Subject: Re: PATCH 2.5.1.4: fix rd.c build



On Fri, 30 Nov 2001, Jens Axboe wrote:

> Actually, this is not even enough if rd receives a multi page bio.
> Something like this should work, untested.
>
> @@ -237,9 +238,9 @@
> err = -EIO;

Make it err = 0...

Another thing being, if you remove explicit call of rd_init() from ll_rw_blk.c
making module_init() unconditional looks like a good idea...

2001-11-30 07:29:43

by Jens Axboe

[permalink] [raw]
Subject: Re: PATCH 2.5.1.4: fix rd.c build

On Fri, Nov 30 2001, Alexander Viro wrote:
>
>
> On Fri, 30 Nov 2001, Jens Axboe wrote:
>
> > Actually, this is not even enough if rd receives a multi page bio.
> > Something like this should work, untested.
> >
> > @@ -237,9 +238,9 @@
> > err = -EIO;
>
> Make it err = 0...

Explain

> Another thing being, if you remove explicit call of rd_init() from
> ll_rw_blk.c making module_init() unconditional looks like a good
> idea...

Indeed, done.

--
Jens Axboe

2001-11-30 07:37:53

by Alexander Viro

[permalink] [raw]
Subject: Re: PATCH 2.5.1.4: fix rd.c build



On Fri, 30 Nov 2001, Jens Axboe wrote:

> On Fri, Nov 30 2001, Alexander Viro wrote:
> >
> >
> > On Fri, 30 Nov 2001, Jens Axboe wrote:
> >
> > > Actually, this is not even enough if rd receives a multi page bio.
> > > Something like this should work, untested.
> > >
> > > @@ -237,9 +238,9 @@
> > > err = -EIO;
> >
> > Make it err = 0...
>
> Explain

Think what happens if you have all these pages in page cache. Already.
Returning -EIO is hardly a good idea in that case. Look through the
loop - we assign err in the body only if we have to allocate a new
page.

Notice that any bh brings the page in. I.e. for smaller-than-page ones
you are going to have a lot of fun...

>From -pre2:

@@ -227,19 +227,18 @@
commit_write: ramdisk_commit_write,
};

-static int rd_blkdev_pagecache_IO(int rw, struct buffer_head * sbh, int minor)
+static int rd_blkdev_pagecache_IO(int rw, struct bio *sbh, int minor)
{
struct address_space * mapping;
unsigned long index;
int offset, size, err;

err = -EIO;
- err = 0;
mapping = rd_bdev[minor]->bd_inode->i_mapping;

Sure, one of these assignments had to go away. You'd picked the wrong one,
though...

2001-11-30 07:45:33

by Jens Axboe

[permalink] [raw]
Subject: Re: PATCH 2.5.1.4: fix rd.c build

On Fri, Nov 30 2001, Alexander Viro wrote:
>
>
> On Fri, 30 Nov 2001, Jens Axboe wrote:
>
> > On Fri, Nov 30 2001, Alexander Viro wrote:
> > >
> > >
> > > On Fri, 30 Nov 2001, Jens Axboe wrote:
> > >
> > > > Actually, this is not even enough if rd receives a multi page bio.
> > > > Something like this should work, untested.
> > > >
> > > > @@ -237,9 +238,9 @@
> > > > err = -EIO;
> > >
> > > Make it err = 0...
> >
> > Explain
>
> Think what happens if you have all these pages in page cache. Already.
> Returning -EIO is hardly a good idea in that case. Look through the
> loop - we assign err in the body only if we have to allocate a new
> page.

Ah ok.

> -static int rd_blkdev_pagecache_IO(int rw, struct buffer_head * sbh, int minor)
> +static int rd_blkdev_pagecache_IO(int rw, struct bio *sbh, int minor)
> {
> struct address_space * mapping;
> unsigned long index;
> int offset, size, err;
>
> err = -EIO;
> - err = 0;
> mapping = rd_bdev[minor]->bd_inode->i_mapping;
>
> Sure, one of these assignments had to go away. You'd picked the wrong one,
> though...

Duh, merge error, don't even remembering making that change. Ok

kernel.org/pub/linux/kernel/people/axboe/patches/v2.5/2.5.1-pre4/bio-pre4-2

should be ok.

--
Jens Axboe