[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 2/2][PV-on-HVM][linux-2.6.18-xen.hg] Enable Front-end drivers for 2.4 kernels



[PATCH 2/2][PV-on-HVM][linux-2.6.18-xen.hg] Enable Front-end drivers for 2.4 kernels

This patch enables front end drivers to build under Linux 2.4 (RHEL3-U8)

Signed-off-by: Paul Burkacki <pburkacki@xxxxxxxxxxxxxxx>
Signed-off-by: Ben Guthro <buthro@xxxxxxxxxxxxxxx>


diffstat linux-RHEL3U8-port.patch
b/include/xen/kerncompat.h | 216 +++++++++++++++++++++++++++
drivers/xen/balloon/balloon.c                |    4
drivers/xen/balloon/sysfs.c                  |    4
drivers/xen/blkfront/blkfront.c              |  124 +++++++++++++--
drivers/xen/blkfront/block.h                 |    8 +
drivers/xen/blkfront/vbd.c | 207 +++++++++++++++++++++++++
drivers/xen/core/features.c                  |    4
drivers/xen/core/gnttab.c                    |    6
drivers/xen/core/reboot.c                    |   16 +-
drivers/xen/netfront/accel.c                 |    4
drivers/xen/netfront/netfront.c              |    2
drivers/xen/xenbus/Makefile                  |   21 ++
drivers/xen/xenbus/xenbus_client.c           |    4
drivers/xen/xenbus/xenbus_comms.c            |    4
drivers/xen/xenbus/xenbus_dev.c              |    6
drivers/xen/xenbus/xenbus_probe.c            |    4
drivers/xen/xenbus/xenbus_probe_backend.c    |    4
drivers/xen/xenbus/xenbus_xs.c               |    4
include/asm-i386/mach-xen/asm/synch_bitops.h |    4
19 files changed, 577 insertions(+), 69 deletions(-)

[PATCH 2/2][PV-on-HVM][linux-2.6.18-xen.hg] Enable Front-end drivers for 2.4 
kernels

This patch enables front end drivers to build under Linux 2.4 (RHEL3-U8)

Signed-off-by: Paul Burkacki <pburkacki@xxxxxxxxxxxxxxx>
Signed-off-by: Ben Guthro <buthro@xxxxxxxxxxxxxxx>

diff -r fc406f9e9a0a drivers/xen/balloon/balloon.c
--- a/drivers/xen/balloon/balloon.c     Fri Dec 14 11:28:40 2007 +0000
+++ b/drivers/xen/balloon/balloon.c     Tue Dec 18 11:27:24 2007 -0500
@@ -59,9 +59,7 @@
 #include <xen/xenbus.h>
 #include "common.h"
 
-#ifdef HAVE_XEN_PLATFORM_COMPAT_H
-#include <xen/platform-compat.h>
-#endif
+#include <xen/kerncompat.h>
 
 #ifdef CONFIG_PROC_FS
 static struct proc_dir_entry *balloon_pde;
diff -r fc406f9e9a0a drivers/xen/balloon/sysfs.c
--- a/drivers/xen/balloon/sysfs.c       Fri Dec 14 11:28:40 2007 +0000
+++ b/drivers/xen/balloon/sysfs.c       Tue Dec 18 11:27:24 2007 -0500
@@ -35,9 +35,7 @@
 #include <linux/sysdev.h>
 #include "common.h"
 
-#ifdef HAVE_XEN_PLATFORM_COMPAT_H
-#include <xen/platform-compat.h>
-#endif
+#include <xen/kerncompat.h>
 
 #define BALLOON_CLASS_NAME "memory"
 
diff -r fc406f9e9a0a drivers/xen/blkfront/blkfront.c
--- a/drivers/xen/blkfront/blkfront.c   Fri Dec 14 11:28:40 2007 +0000
+++ b/drivers/xen/blkfront/blkfront.c   Tue Dec 18 16:35:19 2007 -0500
@@ -49,9 +49,7 @@
 #include <asm/hypervisor.h>
 #include <asm/maddr.h>
 
-#ifdef HAVE_XEN_PLATFORM_COMPAT_H
-#include <xen/platform-compat.h>
-#endif
+#include <xen/kerncompat.h>
 
 #define BLKIF_STATE_DISCONNECTED 0
 #define BLKIF_STATE_CONNECTED    1
@@ -353,7 +351,7 @@ static void connect(struct blkfront_info
        kick_pending_request_queues(info);
        spin_unlock_irq(&blkif_io_lock);
 
-       add_disk(info->gd);
+       compat_add_disk(info->gd, info->dev);
 
        info->is_ready = 1;
 }
@@ -460,7 +458,11 @@ static void blkif_restart_queue_callback
 
 int blkif_open(struct inode *inode, struct file *filep)
 {
-       struct blkfront_info *info = inode->i_bdev->bd_disk->private_data;
+       struct blkfront_info *info = compat_inode_to_info(inode);
+
+       if (info == NULL)
+               return -ENODEV;
+
        info->users++;
        return 0;
 }
@@ -468,7 +470,8 @@ int blkif_open(struct inode *inode, stru
 
 int blkif_release(struct inode *inode, struct file *filep)
 {
-       struct blkfront_info *info = inode->i_bdev->bd_disk->private_data;
+       struct blkfront_info *info = compat_inode_to_info(inode);
+
        info->users--;
        if (info->users == 0) {
                /* Check whether we have been instructed to close.  We will
@@ -487,6 +490,9 @@ int blkif_ioctl(struct inode *inode, str
 int blkif_ioctl(struct inode *inode, struct file *filep,
                unsigned command, unsigned long argument)
 {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+       struct gendisk *disk = get_gendisk(inode->i_rdev);
+#endif
        int i;
 
        DPRINTK_IOCTL("command: 0x%x, argument: 0x%lx, dev: 0x%04x\n",
@@ -514,6 +520,26 @@ int blkif_ioctl(struct inode *inode, str
                 return 0;
        }
 #endif
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+       case HDIO_GETGEO_BIG:
+// Is this needed?
+               return -ENOSYS;
+
+       case BLKGETSIZE64:
+               return put_user((uint64_t) 
(disk->part[MINOR(inode->i_rdev)].nr_sects * 512),
+                               (uint64_t *) argument);
+
+       case BLKGETSIZE:
+               return put_user(disk->part[MINOR(inode->i_rdev)].nr_sects, 
(unsigned long *) argument);
+
+       case BLKSSZGET:
+               return 
hardsect_size[MAJOR(inode->i_rdev)][MINOR(inode->i_rdev)];
+
+       case BLKRRPART:
+               return blkif_revalidate(inode->i_rdev);
+#endif
+
        case CDROMMULTISESSION:
                DPRINTK("FIXME: support multisession CDs later\n");
                for (i = 0; i < sizeof(struct cdrom_multisession); i++)
@@ -522,10 +548,9 @@ int blkif_ioctl(struct inode *inode, str
                return 0;
 
        case CDROM_GET_CAPABILITY: {
-               struct blkfront_info *info =
-                       inode->i_bdev->bd_disk->private_data;
+               struct blkfront_info *info = compat_inode_to_info(inode);
                struct gendisk *gd = info->gd;
-               if (gd->flags & GENHD_FL_CD)
+               if (compat_get_disk_flags(gd) & GENHD_FL_CD)
                        return 0;
                return -EINVAL;
        }
@@ -538,12 +563,11 @@ int blkif_ioctl(struct inode *inode, str
        return 0;
 }
 
-
 int blkif_getgeo(struct block_device *bd, struct hd_geometry *hg)
 {
        /* We don't have real geometry info, but let's at least return
           values consistent with the size of the device */
-       sector_t nsect = get_capacity(bd->bd_disk);
+       sector_t nsect = compat_get_capacity(bd);
        sector_t cylinders = nsect;
 
        hg->heads = 0xff;
@@ -555,6 +579,59 @@ int blkif_getgeo(struct block_device *bd
        return 0;
 }
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+int blkif_revalidate(dev_t dev)
+{
+       struct block_device *bd;
+       struct gendisk *gd;
+       struct blkfront_info *info;
+       struct inode inode;
+       unsigned long capacity;
+       int i, rc = 0;
+    
+       if ((bd = bdget(dev)) == NULL)
+               return -EINVAL;
+
+       /*
+        * Update of partition info, and check of usage count, is protected
+        * by the per-block-device semaphore.
+        */
+       down(&bd->bd_sem);
+
+       inode.i_rdev = dev;
+
+       if (((gd = get_gendisk(dev)) == NULL) ||
+            ((info = compat_inode_to_info(&inode)) == NULL) ||
+            ((capacity = gd->part[MINOR(dev)].nr_sects) == 0)) {
+               rc = -EINVAL;
+               goto out;
+       }
+
+       /* Only reread partition table if VBDs aren't mapped to partitions. */
+       if (!(gd->flags[MINOR(dev) >> gd->minor_shift] & GENHD_FL_VIRT_PARTNS)) 
{
+               for (i = gd->max_p - 1; i >= 0; i--) {
+                       invalidate_device(dev+i, 1);
+                       gd->part[MINOR(dev+i)].start_sect = 0;
+                       gd->part[MINOR(dev+i)].nr_sects = 0;
+                       gd->sizes[MINOR(dev+i)] = 0;
+               }
+
+               /*
+                * FIXME: The correct thing to do is to re-read the
+                * size from xenbus here. That would be more intrusive
+                * than I would like right now.
+                */
+               gd->part[MINOR(dev)].nr_sects = capacity;
+
+               compat_add_disk(gd, dev);
+       }
+
+ out:
+       up(&bd->bd_sem);
+       bdput(bd);
+       return rc;
+}
+#endif
 
 /*
  * blkif_queue_request
@@ -568,7 +645,7 @@ int blkif_getgeo(struct block_device *bd
  */
 static int blkif_queue_request(struct request *req)
 {
-       struct blkfront_info *info = req->rq_disk->private_data;
+       struct blkfront_info *info = compat_req_to_info(req);
        unsigned long buffer_mfn;
        blkif_request_t *ring_req;
        struct bio *bio;
@@ -598,7 +675,7 @@ static int blkif_queue_request(struct re
        info->shadow[id].request = (unsigned long)req;
 
        ring_req->id = id;
-       ring_req->sector_number = (blkif_sector_t)req->sector;
+       ring_req->sector_number = (blkif_sector_t) 
compat_get_sector_number(req);
        ring_req->handle = info->handle;
 
        ring_req->operation = rq_data_dir(req) ?
@@ -662,21 +739,30 @@ void do_blkif_request(request_queue_t *r
        queued = 0;
 
        while ((req = elv_next_request(rq)) != NULL) {
-               info = req->rq_disk->private_data;
+               info = compat_req_to_info(req);
                if (!blk_fs_request(req)) {
-                       end_request(req, 0);
+                       compat_end_request(req, 0);
                        continue;
                }
 
                if (RING_FULL(&info->ring))
                        goto wait;
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+               DPRINTK("do_blk_req %p: cmd %u, sec %lx, "
+                       "(%lu/%li) buffer:%p [%s]\n",
+                       req, req->cmd, (unsigned long)req->sector,
+                       req->current_nr_sectors,
+                       req->nr_sectors, req->buffer,
+                       rq_data_dir(req) ? "write" : "read");
+#else
                DPRINTK("do_blk_req %p: cmd %p, sec %llx, "
                        "(%u/%li) buffer:%p [%s]\n",
                        req, req->cmd, (long long)req->sector,
                        req->current_nr_sectors,
                        req->nr_sectors, req->buffer,
                        rq_data_dir(req) ? "write" : "read");
+#endif
 
 
                blkdev_dequeue_request(req);
@@ -733,7 +819,7 @@ static irqreturn_t blkif_int(int irq, vo
                case BLKIF_OP_WRITE_BARRIER:
                        if (unlikely(bret->status == BLKIF_RSP_EOPNOTSUPP)) {
                                printk("blkfront: %s: write barrier op 
failed\n",
-                                      info->gd->disk_name);
+                                      compat_get_disk_name(info));
                                uptodate = -EOPNOTSUPP;
                                info->feature_barrier = 0;
                                xlvbd_barrier(info);
@@ -745,10 +831,10 @@ static irqreturn_t blkif_int(int irq, vo
                                DPRINTK("Bad return from blkdev data "
                                        "request: %x\n", bret->status);
 
-                       ret = end_that_request_first(req, uptodate,
-                               req->hard_nr_sectors);
+                       ret = compat_end_that_request_first(req, uptodate,
+                                                           
req->hard_nr_sectors);
                        BUG_ON(ret);
-                       end_that_request_last(req, uptodate);
+                       compat_end_that_request_last(req, uptodate);
                        break;
                default:
                        BUG();
diff -r fc406f9e9a0a drivers/xen/blkfront/block.h
--- a/drivers/xen/blkfront/block.h      Fri Dec 14 11:28:40 2007 +0000
+++ b/drivers/xen/blkfront/block.h      Tue Dec 18 16:35:19 2007 -0500
@@ -118,6 +118,11 @@ struct blkfront_info
         * hot-unplug unless this is 0.
         */
        int users;
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+       request_queue_t req_queue;
+       int req_queue_busy;
+#endif
 };
 
 extern spinlock_t blkif_io_lock;
@@ -139,5 +144,8 @@ int xlvbd_add(blkif_sector_t capacity, i
              u16 vdisk_info, u16 sector_size, struct blkfront_info *info);
 void xlvbd_del(struct blkfront_info *info);
 int xlvbd_barrier(struct blkfront_info *info);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+void xlvbd_register_disk(struct gendisk *gd, dev_t dev);
+#endif
 
 #endif /* __XEN_DRIVERS_BLOCK_H__ */
diff -r fc406f9e9a0a drivers/xen/blkfront/vbd.c
--- a/drivers/xen/blkfront/vbd.c        Fri Dec 14 11:28:40 2007 +0000
+++ b/drivers/xen/blkfront/vbd.c        Tue Dec 18 11:27:24 2007 -0500
@@ -36,9 +36,7 @@
 #include <linux/blkdev.h>
 #include <linux/list.h>
 
-#ifdef HAVE_XEN_PLATFORM_COMPAT_H
-#include <xen/platform-compat.h>
-#endif
+#include <xen/kerncompat.h>
 
 #define BLKIF_MAJOR(dev) ((dev)>>8)
 #define BLKIF_MINOR(dev) ((dev) & 0xff)
@@ -98,9 +96,15 @@ static struct block_device_operations xl
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
        .getgeo = blkif_getgeo
 #endif
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+        .revalidate = blkif_revalidate,
+#endif
 };
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 DEFINE_SPINLOCK(blkif_io_lock);
+#endif
 
 static struct xlbd_major_info *
 xlbd_alloc_major_info(int major, int minor, int index)
@@ -128,7 +132,7 @@ xlbd_alloc_major_info(int major, int min
                break;
        }
 
-       if (register_blkdev(ptr->major, ptr->type->devname)) {
+       if (compat_register_blkdev(ptr->major, ptr->type->devname, 
&xlvbd_block_fops)) {
                kfree(ptr);
                return NULL;
        }
@@ -183,6 +187,163 @@ xlbd_put_major_info(struct xlbd_major_in
        /* XXX: release major if 0 */
 }
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+static inline request_queue_t * xlvbd_find_queue(dev_t dev)
+{
+       struct inode inode;
+       struct blkfront_info *info;
+
+       inode.i_rdev = dev;
+       info = compat_inode_to_info(&inode);
+
+       if (info)
+               return info->rq;
+
+       return NULL;
+}
+
+static int xlvbd_alloc_gendisk(int minor, blkif_sector_t capacity, int vdevice,
+                              u16 vdisk_info, u16 sector_size, struct 
blkfront_info *info)
+{
+       struct gendisk *gd;
+       struct xlbd_major_info *mi;
+       int nr_minors = 1;
+       int i;
+       int err = -ENODEV;
+
+       BUG_ON(info->gd != NULL);
+       BUG_ON(info->mi != NULL);
+       BUG_ON(info->rq != NULL);
+
+       mi = xlbd_get_major_info(vdevice);
+       if (mi == NULL)
+               goto out;
+       info->mi = mi;
+
+       if ((minor & ((1 << mi->type->partn_shift) - 1)) == 0)
+               nr_minors = 1 << mi->type->partn_shift;
+
+       if ((gd = get_gendisk(vdevice)) != NULL)
+               goto already_got_one;
+
+       gd = kmalloc(sizeof(struct gendisk), GFP_KERNEL);
+
+       if (gd == NULL) {
+               err = -ENOMEM;
+               goto out;
+       }
+
+       memset(gd, 0, sizeof(struct gendisk));
+
+       /*
+        * Initialize kernel's block device arrays.
+        *
+        * TODO: note that 8192 bytes of data can be saved here when IDE disks
+        * are accelerated.  This is because only disks of type SCSI and VBD
+        * create 256 minors (mi->type->disks_per_major * (1 << 
mi->type->partn_shift)).
+        * Disks of type IDE need only 128.  However, for now, a hardcoded value
+        * of 256 is used below.
+        */
+       blksize_size[mi->major] = kmalloc(256 * sizeof(int), GFP_KERNEL);
+       hardsect_size[mi->major] = kmalloc(256 * sizeof(int), GFP_KERNEL);
+       max_sectors[mi->major] = kmalloc(256 * sizeof(int), GFP_KERNEL);
+
+       if (blksize_size[mi->major] == NULL || hardsect_size[mi->major] == NULL 
||
+           max_sectors[mi->major] == NULL)
+               goto out_free;
+
+       for (i = 0; i < 256; i++) {
+               blksize_size[mi->major][i] = 1024;
+               hardsect_size[mi->major][i] = 512;
+               max_sectors[mi->major][i] = BLKIF_MAX_SEGMENTS_PER_REQUEST;
+       }
+
+       read_ahead[mi->major] = 8;
+
+       blk_dev[MAJOR(vdevice)].queue = xlvbd_find_queue;
+
+       gd->major = mi->major;
+       gd->major_name = mi->type->devname;
+       gd->fops = &xlvbd_block_fops;
+       gd->minor_shift = mi->type->partn_shift;
+       gd->max_p = 1 << mi->type->partn_shift;
+       gd->nr_real = mi->type->disks_per_major;
+
+       gd->real_devices = kmalloc(gd->max_p * gd->nr_real * sizeof(struct 
blkfront_info *),
+                                  GFP_KERNEL);
+       memset(gd->real_devices, 0, gd->max_p * gd->nr_real * sizeof(struct 
blkfront_info *));
+
+       gd->sizes = kmalloc(gd->max_p * gd->nr_real * sizeof(int), GFP_KERNEL);
+       gd->part = kmalloc(gd->max_p * gd->nr_real * sizeof(struct hd_struct), 
GFP_KERNEL);
+       memset(gd->sizes, 0, gd->max_p * gd->nr_real * sizeof(int));
+       memset(gd->part, 0, gd->max_p * gd->nr_real * sizeof(struct hd_struct));
+
+       gd->next = NULL;
+
+       gd->de_arr = kmalloc(gd->nr_real * sizeof(*gd->de_arr), GFP_KERNEL);
+       gd->flags  = kmalloc(gd->nr_real * sizeof(*gd->flags), GFP_KERNEL);
+       memset(gd->de_arr, 0, gd->nr_real * sizeof(*gd->de_arr));
+       memset(gd->flags, 0, gd->nr_real *  sizeof(*gd->flags));
+
+       blk_size[mi->major] = gd->sizes;
+
+       add_gendisk(gd);
+
+already_got_one:
+       memset(&info->req_queue, 0, sizeof(request_queue_t));
+       info->req_queue_busy = 0;
+
+       blk_init_queue(&info->req_queue, do_blkif_request);
+       /*
+        * Xen implementation makes this call but our original code chose not
+        * to.  Should we go ahead and call this?
+        */
+//     blk_queue_headactive(&info->req_queue, 0);
+
+       info->rq = &info->req_queue;
+
+       ((struct blkfront_info **)gd->real_devices)[minor] = info;
+
+       /* Setup needed for partitions with minors other than 0. */
+       if (minor & (gd->max_p - 1)) {
+               gd->part[minor].start_sect = 0; 
+               gd->flags[minor >> gd->minor_shift] |= GENHD_FL_VIRT_PARTNS;
+       }
+
+       /* Setup needed for all partitions. */
+       gd->part[minor].nr_sects = capacity;
+       gd->sizes[minor] = capacity >> (BLOCK_SIZE_BITS - 9);
+       hardsect_size[mi->major][minor] = sector_size;
+       set_blocksize(vdevice, sector_size);
+
+       if (vdisk_info & VDISK_READONLY)
+               set_device_ro(vdevice, 1);
+
+       if (vdisk_info & VDISK_REMOVABLE)
+               gd->flags[minor >> gd->minor_shift] |= GENHD_FL_REMOVABLE;
+
+       if (vdisk_info & VDISK_CDROM)
+               gd->flags[gd->major] |= GENHD_FL_CD;
+
+       info->gd = gd;
+
+       return 0;
+
+ out_free:
+       kfree(blksize_size[mi->major]);
+       kfree(hardsect_size[mi->major]);
+       kfree(max_sectors[mi->major]);
+       kfree(gd);
+
+ out:
+       if (mi)
+               xlbd_put_major_info(mi);
+       info->mi = NULL;
+       return err;
+}
+
+#else /* 2.6 version of xlvbd_init_blk_queue() and xlvbd_alloc_gendisk() */
+
 static int
 xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size)
 {
@@ -312,6 +473,8 @@ xlvbd_alloc_gendisk(int minor, blkif_sec
        return err;
 }
 
+#endif
+
 int
 xlvbd_add(blkif_sector_t capacity, int vdevice, u16 vdisk_info,
          u16 sector_size, struct blkfront_info *info)
@@ -335,6 +498,14 @@ void
 void
 xlvbd_del(struct blkfront_info *info)
 {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+       struct block_device *bd;
+
+       bd = bdget(info->dev);
+       if (bd == NULL)
+               return;
+#endif
+
        if (info->mi == NULL)
                return;
 
@@ -349,6 +520,19 @@ xlvbd_del(struct blkfront_info *info)
        BUG_ON(info->rq == NULL);
        blk_cleanup_queue(info->rq);
        info->rq = NULL;
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+       /* Clean up the global arrays */
+       read_ahead[MAJOR(info->dev)] = 0;
+       kfree(blk_size[MAJOR(info->dev)]);
+       blk_size[MAJOR(info->dev)] = NULL;
+       kfree(blksize_size[MAJOR(info->dev)]);
+       blksize_size[MAJOR(info->dev)] = NULL;
+       kfree(hardsect_size[MAJOR(info->dev)]);
+       hardsect_size[MAJOR(info->dev)] = NULL;
+
+       bdput(bd);
+#endif
 }
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
@@ -362,14 +546,25 @@ xlvbd_barrier(struct blkfront_info *info
        if (err)
                return err;
        printk(KERN_INFO "blkfront: %s: barriers %s\n",
-              info->gd->disk_name, info->feature_barrier ? "enabled" : 
"disabled");
+              compat_get_disk_name(info), info->feature_barrier ? "enabled" : 
"disabled");
        return 0;
 }
 #else
 int
 xlvbd_barrier(struct blkfront_info *info)
 {
-       printk(KERN_INFO "blkfront: %s: barriers disabled\n", 
info->gd->disk_name);
+       printk(KERN_INFO "blkfront: %s: barriers disabled\n", 
compat_get_disk_name(info));
        return -ENOSYS;
 }
 #endif
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+void xlvbd_register_disk(struct gendisk *gd, dev_t dev)
+{
+       if ((gd->max_p - 1) & dev)
+               return;
+
+       register_disk(gd, dev, gd->max_p, &xlvbd_block_fops,
+                     gd->part[MINOR(dev)].nr_sects);
+}
+#endif
diff -r fc406f9e9a0a drivers/xen/core/features.c
--- a/drivers/xen/core/features.c       Fri Dec 14 11:28:40 2007 +0000
+++ b/drivers/xen/core/features.c       Tue Dec 18 11:27:24 2007 -0500
@@ -11,9 +11,7 @@
 #include <asm/hypervisor.h>
 #include <xen/features.h>
 
-#ifdef HAVE_XEN_PLATFORM_COMPAT_H
-#include <xen/platform-compat.h>
-#endif
+#include <xen/kerncompat.h>
 
 u8 xen_features[XENFEAT_NR_SUBMAPS * 32] __read_mostly;
 /* Not a GPL symbol: used in ubiquitous macros, so too restrictive. */
diff -r fc406f9e9a0a drivers/xen/core/gnttab.c
--- a/drivers/xen/core/gnttab.c Fri Dec 14 11:28:40 2007 +0000
+++ b/drivers/xen/core/gnttab.c Tue Dec 18 11:27:24 2007 -0500
@@ -45,9 +45,7 @@
 #include <xen/driver_util.h>
 #include <asm/gnttab_dma.h>
 
-#ifdef HAVE_XEN_PLATFORM_COMPAT_H
-#include <xen/platform-compat.h>
-#endif
+#include <xen/kerncompat.h>
 
 /* External tools reserve first few grant table entries. */
 #define NR_RESERVED_ENTRIES 8
@@ -120,7 +118,7 @@ static void do_free_callbacks(void)
 
 static inline void check_free_callbacks(void)
 {
-       if (unlikely(gnttab_free_callback_list))
+       if (unlikely(gnttab_free_callback_list != NULL))
                do_free_callbacks();
 }
 
diff -r fc406f9e9a0a drivers/xen/core/reboot.c
--- a/drivers/xen/core/reboot.c Fri Dec 14 11:28:40 2007 +0000
+++ b/drivers/xen/core/reboot.c Tue Dec 18 16:36:01 2007 -0500
@@ -9,11 +9,11 @@
 #include <xen/xenbus.h>
 #include <linux/kmod.h>
 #include <linux/slab.h>
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 #include <linux/workqueue.h>
-
-#ifdef HAVE_XEN_PLATFORM_COMPAT_H
-#include <xen/platform-compat.h>
 #endif
+
+#include <xen/kerncompat.h>
 
 MODULE_LICENSE("Dual BSD/GPL");
 
@@ -49,8 +49,8 @@ static int shutdown_process(void *__unus
 
        if ((shutting_down == SHUTDOWN_POWEROFF) ||
            (shutting_down == SHUTDOWN_HALT)) {
-               if (call_usermodehelper("/sbin/poweroff", poweroff_argv,
-                                       envp, 0) < 0) {
+               if (compat_call_usermodehelper("/sbin/poweroff", poweroff_argv,
+                                               envp, 0) < 0) {
 #ifdef CONFIG_XEN
                        sys_reboot(LINUX_REBOOT_MAGIC1,
                                   LINUX_REBOOT_MAGIC2,
@@ -69,8 +69,8 @@ static int xen_suspend(void *__unused)
 {
        int err;
 
-       daemonize("suspend");
-       err = set_cpus_allowed(current, cpumask_of_cpu(0));
+       compat_daemonize("suspend");
+       err = compat_set_cpus_allowed(current, cpumask_of_cpu(0));
        if (err) {
                printk(KERN_ERR "Xen suspend can't run on CPU0 (%d)\n", err);
                goto out;
@@ -177,7 +177,7 @@ static void sysrq_handler(struct xenbus_
 
 #ifdef CONFIG_MAGIC_SYSRQ
        if (sysrq_key != '\0')
-               handle_sysrq(sysrq_key, NULL, NULL);
+               compat_handle_sysrq(sysrq_key, NULL, NULL);
 #endif
 }
 
diff -r fc406f9e9a0a drivers/xen/netfront/accel.c
--- a/drivers/xen/netfront/accel.c      Fri Dec 14 11:28:40 2007 +0000
+++ b/drivers/xen/netfront/accel.c      Tue Dec 18 11:27:24 2007 -0500
@@ -37,6 +37,8 @@
 
 #include "netfront.h"
 
+#include <xen/kerncompat.h>
+
 #define DPRINTK(fmt, args...)                          \
        pr_debug("netfront/accel (%s:%d) " fmt,         \
               __FUNCTION__, __LINE__, ##args)
@@ -272,7 +274,7 @@ int netfront_load_accelerator(struct net
        DPRINTK("requesting module %s\n", frontend);
 
        /* load module */
-       request_module("%s", frontend);
+       compat_request_module("%s", frontend);
 
        /*
         * Module should now call netfront_accelerator_loaded() once
diff -r fc406f9e9a0a drivers/xen/netfront/netfront.c
--- a/drivers/xen/netfront/netfront.c   Fri Dec 14 11:28:40 2007 +0000
+++ b/drivers/xen/netfront/netfront.c   Tue Dec 18 16:35:19 2007 -0500
@@ -1862,6 +1862,7 @@ static struct ethtool_ops network_ethtoo
 {
        .get_tx_csum = ethtool_op_get_tx_csum,
        .set_tx_csum = ethtool_op_set_tx_csum,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
        .get_sg = ethtool_op_get_sg,
        .set_sg = xennet_set_sg,
 #if HAVE_TSO
@@ -1869,6 +1870,7 @@ static struct ethtool_ops network_ethtoo
        .set_tso = xennet_set_tso,
 #endif
        .get_link = ethtool_op_get_link,
+#endif
 };
 
 #ifdef CONFIG_SYSFS
diff -r fc406f9e9a0a drivers/xen/xenbus/Makefile
--- a/drivers/xen/xenbus/Makefile       Fri Dec 14 11:28:40 2007 +0000
+++ b/drivers/xen/xenbus/Makefile       Tue Dec 18 11:27:24 2007 -0500
@@ -1,3 +1,4 @@ obj-y += xenbus_client.o xenbus_comms.o 
+ifeq ($(VERSION).$(PATCHLEVEL),2.6)
 obj-y += xenbus_client.o xenbus_comms.o xenbus_xs.o xenbus_probe.o
 obj-$(CONFIG_XEN_BACKEND) += xenbus_be.o
 
@@ -7,3 +8,23 @@ xenbus-$(CONFIG_XEN_BACKEND) += xenbus_p
 xenbus-$(CONFIG_XEN_BACKEND) += xenbus_probe_backend.o
 obj-y += $(xenbus-y) $(xenbus-m)
 obj-$(CONFIG_XEN_XENBUS_DEV) += xenbus_dev.o
+endif
+
+ifeq ($(VERSION).$(PATCHLEVEL),2.4)
+O_TARGET := xenbus_be.o
+
+export-objs := xenbus_client.o xenbus_probe.o xenbus_xs.o 
xenbus_backend_client.o
+
+obj-y := xenbus_client.o xenbus_comms.o xenbus_xs.o xenbus_probe.o 
xenbus_backend_client.o
+obj-$(CONFIG_XEN_BACKEND) += $(O_TARGET)
+
+
+O_TARGET := xenbus_dev.o
+
+export-objs := xenbus_probe_backend.o
+
+obj-y := xenbus_probe_backend.o
+obj-$(CONFIG_XEN_XENBUS_DEV) += $(O_TARGET)
+
+include $(TOPDIR)/Rules.make
+endif
diff -r fc406f9e9a0a drivers/xen/xenbus/xenbus_client.c
--- a/drivers/xen/xenbus/xenbus_client.c        Fri Dec 14 11:28:40 2007 +0000
+++ b/drivers/xen/xenbus/xenbus_client.c        Tue Dec 18 11:27:24 2007 -0500
@@ -36,9 +36,7 @@
 #include <xen/xenbus.h>
 #include <xen/driver_util.h>
 
-#ifdef HAVE_XEN_PLATFORM_COMPAT_H
-#include <xen/platform-compat.h>
-#endif
+#include <xen/kerncompat.h>
 
 #define DPRINTK(fmt, args...) \
     pr_debug("xenbus_client (%s:%d) " fmt ".\n", __FUNCTION__, __LINE__, 
##args)
diff -r fc406f9e9a0a drivers/xen/xenbus/xenbus_comms.c
--- a/drivers/xen/xenbus/xenbus_comms.c Fri Dec 14 11:28:40 2007 +0000
+++ b/drivers/xen/xenbus/xenbus_comms.c Tue Dec 18 11:27:24 2007 -0500
@@ -43,9 +43,7 @@
 
 #include "xenbus_comms.h"
 
-#ifdef HAVE_XEN_PLATFORM_COMPAT_H
-#include <xen/platform-compat.h>
-#endif
+#include <xen/kerncompat.h>
 
 static int xenbus_irq;
 
diff -r fc406f9e9a0a drivers/xen/xenbus/xenbus_dev.c
--- a/drivers/xen/xenbus/xenbus_dev.c   Fri Dec 14 11:28:40 2007 +0000
+++ b/drivers/xen/xenbus/xenbus_dev.c   Tue Dec 18 11:27:24 2007 -0500
@@ -49,9 +49,7 @@
 #include <xen/xen_proc.h>
 #include <asm/hypervisor.h>
 
-#ifdef HAVE_XEN_PLATFORM_COMPAT_H
-#include <xen/platform-compat.h>
-#endif
+#include <xen/kerncompat.h>
 
 struct xenbus_dev_transaction {
        struct list_head list;
@@ -398,7 +396,7 @@ int xenbus_dev_init(void)
 {
        xenbus_dev_intf = create_xen_proc_entry("xenbus", 0400);
        if (xenbus_dev_intf)
-               xenbus_dev_intf->proc_fops = &xenbus_dev_file_ops;
+               xenbus_dev_intf->proc_fops = (struct file_operations *) 
&xenbus_dev_file_ops;
 
        return 0;
 }
diff -r fc406f9e9a0a drivers/xen/xenbus/xenbus_probe.c
--- a/drivers/xen/xenbus/xenbus_probe.c Fri Dec 14 11:28:40 2007 +0000
+++ b/drivers/xen/xenbus/xenbus_probe.c Tue Dec 18 16:35:19 2007 -0500
@@ -59,9 +59,7 @@
 #include "xenbus_comms.h"
 #include "xenbus_probe.h"
 
-#ifdef HAVE_XEN_PLATFORM_COMPAT_H
-#include <xen/platform-compat.h>
-#endif
+#include <xen/kerncompat.h>
 
 int xen_store_evtchn;
 struct xenstore_domain_interface *xen_store_interface;
diff -r fc406f9e9a0a drivers/xen/xenbus/xenbus_probe_backend.c
--- a/drivers/xen/xenbus/xenbus_probe_backend.c Fri Dec 14 11:28:40 2007 +0000
+++ b/drivers/xen/xenbus/xenbus_probe_backend.c Tue Dec 18 16:35:19 2007 -0500
@@ -57,9 +57,7 @@
 #include "xenbus_comms.h"
 #include "xenbus_probe.h"
 
-#ifdef HAVE_XEN_PLATFORM_COMPAT_H
-#include <xen/platform-compat.h>
-#endif
+#include <xen/kerncompat.h>
 
 static int xenbus_uevent_backend(struct device *dev, char **envp,
                                 int num_envp, char *buffer, int buffer_size);
diff -r fc406f9e9a0a drivers/xen/xenbus/xenbus_xs.c
--- a/drivers/xen/xenbus/xenbus_xs.c    Fri Dec 14 11:28:40 2007 +0000
+++ b/drivers/xen/xenbus/xenbus_xs.c    Tue Dec 18 11:27:24 2007 -0500
@@ -47,9 +47,7 @@
 #include <xen/xenbus.h>
 #include "xenbus_comms.h"
 
-#ifdef HAVE_XEN_PLATFORM_COMPAT_H
-#include <xen/platform-compat.h>
-#endif
+#include <xen/kerncompat.h>
 
 #ifndef PF_NOFREEZE /* Old kernel (pre-2.6.6). */
 #define PF_NOFREEZE    0
diff -r fc406f9e9a0a include/asm-i386/mach-xen/asm/synch_bitops.h
--- a/include/asm-i386/mach-xen/asm/synch_bitops.h      Fri Dec 14 11:28:40 
2007 +0000
+++ b/include/asm-i386/mach-xen/asm/synch_bitops.h      Tue Dec 18 11:27:24 
2007 -0500
@@ -7,9 +7,7 @@
  * when communicating with Xen or other guest OSes running on other CPUs.
  */
 
-#ifdef HAVE_XEN_PLATFORM_COMPAT_H
-#include <xen/platform-compat.h>
-#endif
+#include <xen/kerncompat.h>
 
 #define ADDR (*(volatile long *) addr)
 
diff -r fc406f9e9a0a include/xen/kerncompat.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/include/xen/kerncompat.h  Tue Dec 18 11:27:24 2007 -0500
@@ -0,0 +1,216 @@
+#ifndef _XEN_KERNCOMPAT_H_
+#define _XEN_KERNCOMPAT_H_
+
+#ifdef HAVE_XEN_PLATFORM_COMPAT_H
+#include <xen/platform-compat.h>
+#endif
+
+#include <linux/version.h>
+
+/*
+ * Define a compatibility macro to hide the difference between the 2.6 and
+ * the 2.4 version of handle_sysrq().
+ */
+#if defined(_LINUX_SYSRQ_H) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)
+#define handle_sysrq(x,y,z) handle_sysrq(x,y)
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
+#define compat_handle_sysrq(x, y, z)    handle_sysrq(x, y, z)
+#elif defined(__LINUX_SYSRQ_H__)
+#define compat_handle_sysrq(x, y, z)    handle_sysrq(x, y, z, NULL)
+#endif
+
+/*
+ * Hide the difference between the 2.4 and 2.6 version of 
call_usermodehelper().
+ */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+#include <linux/kmod.h>
+#define compat_call_usermodehelper(path, argv, envp, wait)    
call_usermodehelper((path), (argv), (envp))
+#else
+#define compat_call_usermodehelper(path, argv, envp, wait)    
call_usermodehelper((path), (argv), (envp), (wait))
+#endif
+
+/*
+ * Hide the difference between the 2.4 and 2.6 version of daemonize().
+ */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+#define compat_daemonize(name)    daemonize()
+#else
+#define compat_daemonize(name)    daemonize(name)
+#endif
+
+/*
+ * Hide the difference between the 2.4 and 2.6 version of request_module().
+ */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+#define compat_request_module(name,...) request_module(name)
+#else
+#define compat_request_module(name,...) request_module(name,## __VA_ARGS__)
+#endif
+
+/*
+ * Provide a kernel 2.4 version of set_cpus_allowed().
+ */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+#define compat_set_cpus_allowed(current, mask)                 \
+({                                                             \
+    cpumask_t _old_mask;                                       \
+    int _ret = 0;                                              \
+                                                               \
+    _old_mask = (current)->cpus_allowed;                       \
+    set_cpus_allowed((current), mask);                         \
+                                                               \
+    if ( (cpumask_of_cpu(smp_processor_id()) & (mask))==0 ) {  \
+        set_cpus_allowed((current), _old_mask);                \
+        _ret = 1;                                              \
+    }                                                          \
+    _ret;                                                      \
+})
+#else
+#define compat_set_cpus_allowed(current, mask)    set_cpus_allowed((current), 
(mask))
+#endif
+
+/*
+ * Hide the difference between the 2.4 and 2.6 version of register_blkdev().
+ */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+#define compat_register_blkdev(major, name, fsops)    register_blkdev((major), 
(name), (fsops))
+#else
+#define compat_register_blkdev(major, name, fsops)    register_blkdev((major), 
(name))
+#endif
+
+/*
+ * Provide compatibility macros for geometry calculation under kernel 2.4.
+ */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+
+#define get_start_sect(bd)                        \
+({                                                \
+    struct gendisk *__disk;                       \
+                                                  \
+    __disk = get_gendisk((bd)->bd_dev);           \
+    __disk->part[MINOR((bd)->bd_dev)].start_sect; \
+})
+
+#define compat_get_capacity(bd)                 \
+({                                              \
+    struct gendisk *__disk;                     \
+                                                \
+    __disk = get_gendisk((bd)->bd_dev);         \
+    __disk->part[MINOR((bd)->bd_dev)].nr_sects; \
+})
+
+#define compat_get_sector_number(req)                                    \
+({                                                                       \
+    struct blkfront_info *__info;                                        \
+                                                                         \
+    __info = compat_req_to_info(req);                                    \
+    (req)->sector + (__info)->gd->part[MINOR((req)->rq_dev)].start_sect; \
+})
+
+#else
+
+#define compat_get_capacity(bd)    get_capacity((bd)->bd_disk)
+#define compat_get_sector_number(req)    ((req)->sector)
+
+#endif
+
+/*
+ * Provide compatibility macros for resolution of blkfront driver's private
+ * information structure.
+ */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+
+#define compat_get_info(disk, minor)                                           
                   \
+({                                                                             
                   \
+    ((struct blkfront_info **)(disk)->real_devices)[(minor)] ?                 
                   \
+    ((struct blkfront_info **)(disk)->real_devices)[(minor)] :                 
                   \
+    ((struct blkfront_info **)(disk)->real_devices)[(minor) & ~((1 << 
(disk)->minor_shift) - 1)]; \
+})
+
+#define compat_inode_to_info(inode)                               \
+({                                                                \
+    struct gendisk *__disk;                                       \
+    struct blkfront_info *__info = NULL;                          \
+                                                                  \
+    __disk = get_gendisk((inode)->i_rdev);                        \
+                                                                  \
+    if (__disk != NULL)                                           \
+        __info = compat_get_info(__disk, MINOR((inode)->i_rdev)); \
+                                                                  \
+    __info;                                                       \
+})
+
+#define compat_req_to_info(req)                                 \
+({                                                              \
+    struct gendisk *__disk;                                     \
+    struct blkfront_info *__info = NULL;                        \
+                                                                \
+    __disk = get_gendisk((req)->rq_dev);                        \
+                                                                \
+    if (__disk != NULL)                                         \
+        __info = compat_get_info(__disk, MINOR((req)->rq_dev)); \
+                                                                \
+    __info;                                                     \
+})
+
+#else
+
+#define compat_inode_to_info(inode)    ((inode)->i_bdev->bd_disk->private_data)
+#define compat_req_to_info(req)    ((req)->rq_disk->private_data)
+
+#endif
+
+/*
+ * Provide compatibility macros for end_request processing.
+ */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+#define compat_end_request(req, uptodate)                                 \
+({                                                                        \
+    struct blkfront_info *__info;                                         \
+                                                                          \
+    __info = compat_req_to_info(req);                                     \
+                                                                          \
+    if (!end_that_request_first((req), (uptodate),                        \
+                                (char *) compat_get_disk_name(__info))) { \
+        blkdev_dequeue_request(req);                                      \
+        end_that_request_last(req);                                       \
+    }                                                                     \
+})
+
+#define compat_end_that_request_first(req, uptodate, nr_sect)                  
\
+({                                                                             
\
+    struct blkfront_info *__info;                                              
\
+    int __ret;                                                                 
\
+                                                                               
\
+    __info = compat_req_to_info(req);                                          
\
+                                                                               
\
+    do {                                                                       
\
+        __ret = end_that_request_first((req), (uptodate),                      
\
+                                       (char *) compat_get_disk_name(__info)); 
\
+    } while (__ret != 0);                                                      
\
+                                                                               
\
+    __ret;                                                                     
\
+})
+
+#define compat_end_that_request_last(req, uptodate)    
end_that_request_last(req)
+#else
+#define compat_end_request(req, uptodate)    end_request((req), (uptodate))
+#define compat_end_that_request_first(req, uptodate, nr_sect)    
end_that_request_first((req), (uptodate), (nr_sect))
+#define compat_end_that_request_last(req, uptodate)    
end_that_request_last((req), (uptodate))
+#endif
+
+/*
+ * Compatibility macros which hide differences in generic disk APIs between
+ * kernel 2.4 and kernel 2.6.
+ */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+#define compat_add_disk(gd, dev)    xlvbd_register_disk((gd), (dev))
+#define compat_get_disk_name(info)  ((info)->gd->major_name)
+#define compat_get_disk_flags(gd)   ((int)*((gd)->flags))
+#else
+#define compat_add_disk(gd, dev)    add_disk(gd)
+#define compat_get_disk_name(info)  ((info)->gd->disk_name)
+#define compat_get_disk_flags(gd)   ((gd)->flags)
+#endif
+
+#endif
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.