[Tux3] Tux3 kernel port - nicer bio io?

Daniel Phillips phillips at phunq.net
Fri Sep 19 16:28:10 PDT 2008


This verges on wanking, I apologize in advance:

int vecio(int rw, struct block_device *dev, sector_t sector,
	bio_end_io_t endio, void *data, unsigned vecs, struct bio_vec *vec)
{
	struct bio *bio = bio_alloc(GFP_KERNEL, vecs);
	if (!bio)
		return -ENOMEM;
	bio->bi_bdev = dev;
	bio->bi_sector = sector;
	bio->bi_size = SB_SIZE;
	bio->bi_end_io = endio;
	bio->bi_private = data;
	while (vecs--) {
		bio->bi_io_vec[bio->bi_vcnt] = *vec++;
		bio->bi_size += bio->bi_io_vec[bio->bi_vcnt++].bv_len;
	}
	submit_bio(rw, bio);
	return 0;
}

struct biosync { struct semaphore sem; int err; };

static void sync_endio(struct bio *bio, int err)
{
	struct biosync *sync = bio->bi_private;
	bio_put(bio);
	sync->err = err;
	up(&sync->sem);
}

int syncio(int rw, struct block_device *dev, sector_t sector, unsigned vecs, struct bio_vec *vec)
{
	struct biosync sync = { __SEMAPHORE_INITIALIZER(sync.sem, 0) };
	int err = vecio(rw, dev, sector, sync_endio, &sync, vecs, vec);
	if (err)
		return err;
	down(&sync.sem);
	return sync.err;
}

#define SB_SIZE 512

static int junkfs_fill_super(struct super_block *sb, void *data, int silent)
{
	u8 *buf = kmalloc(SB_SIZE, GFP_KERNEL);
	int i, err;

	if (!buf)
		return -ENOMEM;
	if ((err = syncio(READ, sb->s_bdev, 0, 1,
		&(struct bio_vec){
			.bv_page = virt_to_page(buf),
			.bv_offset = offset_in_page(buf),
			.bv_len = SB_SIZE }))) {
		kfree(buf);
		return err;
	}
	printk("super = ");
	for(i = 0; i < 16; i++)
		printk(" %02X", buf[i]);
	printk("\n");
	kfree(buf);
	return 0;
}

_______________________________________________
Tux3 mailing list
Tux3 at tux3.org
http://tux3.org/cgi-bin/mailman/listinfo/tux3



More information about the Tux3 mailing list