From 9674df3543fd2ca8dc722f51100c5732e3dbdd7b Mon Sep 17 00:00:00 2001 From: Sebastian Schmelzer Date: Wed, 9 Apr 2008 01:56:28 +0000 Subject: * added fixes for kernel api changes (kernel >= 2.6.24) (rq_for_each_bio + bio_for_each_segment => rq_for_each_segment) * added kernel version check to exclude devfs_* includes/commands (devfs_* was dropped with 2.6.18) git-svn-id: http://svn.openslx.org/svn/openslx/contrib/dnbd/trunk@1733 95ad53e4-c205-0410-b2fa-d234c58c8868 --- kernel/cache.c | 15 +++++++++++++-- kernel/main.c | 27 +++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/kernel/cache.c b/kernel/cache.c index e72b2ff..b47e32b 100644 --- a/kernel/cache.c +++ b/kernel/cache.c @@ -10,6 +10,7 @@ #include /* use red-black library of kernel */ #include +#include #include #include "../common/dnbd-cliserv.h" @@ -42,8 +43,12 @@ int dnbd_cache_search(dnbd_cache_t * cache, struct request *req) size_t blksize; void *kaddr; - int i; - struct bio *bio; + #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)) + int i; + struct bio *bio; + #else + struct req_iterator iter; + #endif struct bio_vec *bvec; int result = 0, rbytes; @@ -75,8 +80,12 @@ int dnbd_cache_search(dnbd_cache_t * cache, struct request *req) found: cache->hits++; offset = cn->rb_data * blksize; + #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)) rq_for_each_bio(bio, req) { bio_for_each_segment(bvec, bio, i) { + #else + rq_for_each_segment(bvec, req, iter) { + #endif if (bvec->bv_len > blksize) { printk(KERN_WARNING "bvec->bv_len greater than cache block size\n"); @@ -103,7 +112,9 @@ int dnbd_cache_search(dnbd_cache_t * cache, struct request *req) result += rbytes; if (result == blksize) goto out; + #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)) } + #endif } out: diff --git a/kernel/main.c b/kernel/main.c index 22a6032..f0eea1c 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -15,6 +15,7 @@ * */ +#include #include #include #include @@ -25,7 +26,9 @@ #include #include /* error codes */ +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)) #include +#endif #include #include @@ -213,7 +216,6 @@ static void dnbd_xfer_to_cache(dnbd_device_t * dnbd, struct sk_buff *skb, static int inline dnbd_recv_reply(dnbd_device_t * dnbd) { mm_segment_t oldfs = get_fs(); - int i; unsigned int nsect = 0; int err; struct sk_buff *skb; @@ -221,7 +223,12 @@ static int inline dnbd_recv_reply(dnbd_device_t * dnbd) int remain, offset, tocopy; dnbd_reply_t *reply; struct request *req = NULL; - struct bio *bio; + #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)) + int i; + struct bio *bio; + #else + struct req_iterator iter; + #endif struct bio_vec *bvec; int tt; void *kaddr; @@ -306,8 +313,12 @@ static int inline dnbd_recv_reply(dnbd_device_t * dnbd) nsect = 0; err = 0; /* copy network data to BIOs */ - rq_for_each_bio(bio, req) { - bio_for_each_segment(bvec, bio, i) { + #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)) + rq_for_each_bio(bio, req) { + bio_for_each_segment(bvec, bio, i) { + #else + rq_for_each_segment(bvec, req, iter) { + #endif tocopy = bvec->bv_len; if (tocopy > remain) goto nobytesleft; @@ -329,7 +340,9 @@ static int inline dnbd_recv_reply(dnbd_device_t * dnbd) offset += tocopy; remain -= tocopy; nsect += bvec->bv_len >> 9; + #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)) } + #endif } nobytesleft: /* end request partially or fully */ @@ -1160,7 +1173,9 @@ static int __init dnbd_init(void) printk(KERN_INFO "dnbd: module loaded with major %i\n", dnbd_major); +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)) devfs_mk_dir("dnbd"); +#endif for (i = 0; i < MAX_DNBD; i++) { struct gendisk *disk = dnbd_dev[i].disk; dnbd_dev[i].state = DNBD_STATE_LOADED; @@ -1194,7 +1209,9 @@ static int __init dnbd_init(void) disk->private_data = &dnbd_dev[i]; disk->flags |= GENHD_FL_SUPPRESS_PARTITION_INFO; sprintf(disk->disk_name, "dnbd%d", i); + #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)) sprintf(disk->devfs_name, "dnbd/%d", i); + #endif set_capacity(disk, 0); /* initialize cache */ @@ -1243,7 +1260,9 @@ static void __exit dnbd_exit(void) put_disk(disk); } } + #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)) devfs_remove("dnbd"); + #endif unregister_blkdev(dnbd_major, "dnbd"); for (i = 0; (i < MAX_DNBD && i < 100); i++) { -- cgit v1.2.3-55-g7522