Ed L. Cashin | 52e112b | 2008-02-08 04:20:09 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2007 Coraid, Inc. See COPYING for GPL terms. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * aoeblk.c |
| 4 | * block device routines |
| 5 | */ |
| 6 | |
| 7 | #include <linux/hdreg.h> |
| 8 | #include <linux/blkdev.h> |
Andrew Morton | 43cbe2c | 2007-12-10 15:49:13 -0800 | [diff] [blame] | 9 | #include <linux/backing-dev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/fs.h> |
| 11 | #include <linux/ioctl.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/genhd.h> |
| 14 | #include <linux/netdevice.h> |
| 15 | #include "aoe.h" |
| 16 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 17 | static struct kmem_cache *buf_pool_cache; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 19 | static ssize_t aoedisk_show_state(struct device *dev, |
| 20 | struct device_attribute *attr, char *page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | { |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 22 | struct gendisk *disk = dev_to_disk(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | struct aoedev *d = disk->private_data; |
| 24 | |
| 25 | return snprintf(page, PAGE_SIZE, |
| 26 | "%s%s\n", |
| 27 | (d->flags & DEVFL_UP) ? "up" : "down", |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 28 | (d->flags & DEVFL_KICKME) ? ",kickme" : |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 29 | (d->nopen && !(d->flags & DEVFL_UP)) ? ",closewait" : ""); |
| 30 | /* I'd rather see nopen exported so we can ditch closewait */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | } |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 32 | static ssize_t aoedisk_show_mac(struct device *dev, |
| 33 | struct device_attribute *attr, char *page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 35 | struct gendisk *disk = dev_to_disk(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | struct aoedev *d = disk->private_data; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 37 | struct aoetgt *t = d->targets[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 39 | if (t == NULL) |
| 40 | return snprintf(page, PAGE_SIZE, "none\n"); |
Harvey Harrison | 411c41e | 2008-11-25 00:40:37 -0800 | [diff] [blame] | 41 | return snprintf(page, PAGE_SIZE, "%pm\n", t->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | } |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 43 | static ssize_t aoedisk_show_netif(struct device *dev, |
| 44 | struct device_attribute *attr, char *page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 46 | struct gendisk *disk = dev_to_disk(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | struct aoedev *d = disk->private_data; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 48 | struct net_device *nds[8], **nd, **nnd, **ne; |
| 49 | struct aoetgt **t, **te; |
| 50 | struct aoeif *ifp, *e; |
| 51 | char *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 53 | memset(nds, 0, sizeof nds); |
| 54 | nd = nds; |
| 55 | ne = nd + ARRAY_SIZE(nds); |
| 56 | t = d->targets; |
| 57 | te = t + NTARGETS; |
| 58 | for (; t < te && *t; t++) { |
| 59 | ifp = (*t)->ifs; |
| 60 | e = ifp + NAOEIFS; |
| 61 | for (; ifp < e && ifp->nd; ifp++) { |
| 62 | for (nnd = nds; nnd < nd; nnd++) |
| 63 | if (*nnd == ifp->nd) |
| 64 | break; |
| 65 | if (nnd == nd && nd != ne) |
| 66 | *nd++ = ifp->nd; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | ne = nd; |
| 71 | nd = nds; |
| 72 | if (*nd == NULL) |
| 73 | return snprintf(page, PAGE_SIZE, "none\n"); |
| 74 | for (p = page; nd < ne; nd++) |
| 75 | p += snprintf(p, PAGE_SIZE - (p-page), "%s%s", |
| 76 | p == page ? "" : ",", (*nd)->name); |
| 77 | p += snprintf(p, PAGE_SIZE - (p-page), "\n"); |
| 78 | return p-page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
Ed L Cashin | 4613ed2 | 2005-04-29 10:24:25 -0400 | [diff] [blame] | 80 | /* firmware version */ |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 81 | static ssize_t aoedisk_show_fwver(struct device *dev, |
| 82 | struct device_attribute *attr, char *page) |
Ed L Cashin | 4613ed2 | 2005-04-29 10:24:25 -0400 | [diff] [blame] | 83 | { |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 84 | struct gendisk *disk = dev_to_disk(dev); |
Ed L Cashin | 4613ed2 | 2005-04-29 10:24:25 -0400 | [diff] [blame] | 85 | struct aoedev *d = disk->private_data; |
| 86 | |
| 87 | return snprintf(page, PAGE_SIZE, "0x%04x\n", (unsigned int) d->fw_ver); |
| 88 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 90 | static DEVICE_ATTR(state, S_IRUGO, aoedisk_show_state, NULL); |
| 91 | static DEVICE_ATTR(mac, S_IRUGO, aoedisk_show_mac, NULL); |
| 92 | static DEVICE_ATTR(netif, S_IRUGO, aoedisk_show_netif, NULL); |
| 93 | static struct device_attribute dev_attr_firmware_version = { |
Parag Warudkar | 01e8ef1 | 2008-10-18 20:28:50 -0700 | [diff] [blame] | 94 | .attr = { .name = "firmware-version", .mode = S_IRUGO }, |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 95 | .show = aoedisk_show_fwver, |
Ed L Cashin | 4613ed2 | 2005-04-29 10:24:25 -0400 | [diff] [blame] | 96 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Greg Kroah-Hartman | 4ca5224 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 98 | static struct attribute *aoe_attrs[] = { |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 99 | &dev_attr_state.attr, |
| 100 | &dev_attr_mac.attr, |
| 101 | &dev_attr_netif.attr, |
| 102 | &dev_attr_firmware_version.attr, |
| 103 | NULL, |
Greg Kroah-Hartman | 4ca5224 | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | static const struct attribute_group attr_group = { |
| 107 | .attrs = aoe_attrs, |
| 108 | }; |
| 109 | |
| 110 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | aoedisk_add_sysfs(struct aoedev *d) |
| 112 | { |
Tejun Heo | ed9e198 | 2008-08-25 19:56:05 +0900 | [diff] [blame] | 113 | return sysfs_create_group(&disk_to_dev(d->gd)->kobj, &attr_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | void |
| 116 | aoedisk_rm_sysfs(struct aoedev *d) |
| 117 | { |
Tejun Heo | ed9e198 | 2008-08-25 19:56:05 +0900 | [diff] [blame] | 118 | sysfs_remove_group(&disk_to_dev(d->gd)->kobj, &attr_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static int |
Al Viro | 94562c1 | 2008-03-02 09:23:18 -0500 | [diff] [blame] | 122 | aoeblk_open(struct block_device *bdev, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
Al Viro | 94562c1 | 2008-03-02 09:23:18 -0500 | [diff] [blame] | 124 | struct aoedev *d = bdev->bd_disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | ulong flags; |
| 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | spin_lock_irqsave(&d->lock, flags); |
| 128 | if (d->flags & DEVFL_UP) { |
| 129 | d->nopen++; |
| 130 | spin_unlock_irqrestore(&d->lock, flags); |
| 131 | return 0; |
| 132 | } |
| 133 | spin_unlock_irqrestore(&d->lock, flags); |
| 134 | return -ENODEV; |
| 135 | } |
| 136 | |
| 137 | static int |
Al Viro | 94562c1 | 2008-03-02 09:23:18 -0500 | [diff] [blame] | 138 | aoeblk_release(struct gendisk *disk, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | { |
Al Viro | 94562c1 | 2008-03-02 09:23:18 -0500 | [diff] [blame] | 140 | struct aoedev *d = disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | ulong flags; |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | spin_lock_irqsave(&d->lock, flags); |
| 144 | |
Ed L. Cashin | 5f7702f | 2006-01-19 13:46:27 -0500 | [diff] [blame] | 145 | if (--d->nopen == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | spin_unlock_irqrestore(&d->lock, flags); |
| 147 | aoecmd_cfg(d->aoemajor, d->aoeminor); |
| 148 | return 0; |
| 149 | } |
| 150 | spin_unlock_irqrestore(&d->lock, flags); |
| 151 | |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | static int |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 156 | aoeblk_make_request(struct request_queue *q, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 158 | struct sk_buff_head queue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | struct aoedev *d; |
| 160 | struct buf *buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | ulong flags; |
| 162 | |
| 163 | blk_queue_bounce(q, &bio); |
| 164 | |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 165 | if (bio == NULL) { |
| 166 | printk(KERN_ERR "aoe: bio is NULL\n"); |
| 167 | BUG(); |
| 168 | return 0; |
| 169 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | d = bio->bi_bdev->bd_disk->private_data; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 171 | if (d == NULL) { |
| 172 | printk(KERN_ERR "aoe: bd_disk->private_data is NULL\n"); |
| 173 | BUG(); |
| 174 | bio_endio(bio, -ENXIO); |
| 175 | return 0; |
Christoph Hellwig | 7b6d91d | 2010-08-07 18:20:39 +0200 | [diff] [blame^] | 176 | } else if (bio->bi_rw & REQ_HARDBARRIER) { |
Ed Cashin | 18d8217 | 2009-09-10 22:30:47 +0200 | [diff] [blame] | 177 | bio_endio(bio, -EOPNOTSUPP); |
| 178 | return 0; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 179 | } else if (bio->bi_io_vec == NULL) { |
| 180 | printk(KERN_ERR "aoe: bi_io_vec is NULL\n"); |
| 181 | BUG(); |
| 182 | bio_endio(bio, -ENXIO); |
| 183 | return 0; |
| 184 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | buf = mempool_alloc(d->bufpool, GFP_NOIO); |
| 186 | if (buf == NULL) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 187 | printk(KERN_INFO "aoe: buf allocation failure\n"); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 188 | bio_endio(bio, -ENOMEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | return 0; |
| 190 | } |
| 191 | memset(buf, 0, sizeof(*buf)); |
| 192 | INIT_LIST_HEAD(&buf->bufs); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 193 | buf->stime = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | buf->bio = bio; |
| 195 | buf->resid = bio->bi_size; |
| 196 | buf->sector = bio->bi_sector; |
Ed L. Cashin | 392e484 | 2006-09-20 14:36:50 -0400 | [diff] [blame] | 197 | buf->bv = &bio->bi_io_vec[bio->bi_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | buf->bv_resid = buf->bv->bv_len; |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 199 | WARN_ON(buf->bv_resid == 0); |
| 200 | buf->bv_off = buf->bv->bv_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | spin_lock_irqsave(&d->lock, flags); |
| 203 | |
| 204 | if ((d->flags & DEVFL_UP) == 0) { |
Ed L. Cashin | 1d75981 | 2008-02-08 04:20:08 -0800 | [diff] [blame] | 205 | printk(KERN_INFO "aoe: device %ld.%d is not up\n", |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 206 | d->aoemajor, d->aoeminor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | spin_unlock_irqrestore(&d->lock, flags); |
| 208 | mempool_free(buf, d->bufpool); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 209 | bio_endio(bio, -ENXIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | list_add_tail(&buf->bufs, &d->bufq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 215 | aoecmd_work(d); |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 216 | __skb_queue_head_init(&queue); |
| 217 | skb_queue_splice_init(&d->sendq, &queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
| 219 | spin_unlock_irqrestore(&d->lock, flags); |
David S. Miller | e9bb8fb | 2008-09-21 22:36:49 -0700 | [diff] [blame] | 220 | aoenet_xmit(&queue); |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | return 0; |
| 223 | } |
| 224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | static int |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 226 | aoeblk_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 228 | struct aoedev *d = bdev->bd_disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | if ((d->flags & DEVFL_UP) == 0) { |
Ed L. Cashin | a12c93f | 2006-09-20 14:36:51 -0400 | [diff] [blame] | 231 | printk(KERN_ERR "aoe: disk not up\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | return -ENODEV; |
| 233 | } |
| 234 | |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 235 | geo->cylinders = d->geo.cylinders; |
| 236 | geo->heads = d->geo.heads; |
| 237 | geo->sectors = d->geo.sectors; |
| 238 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 241 | static const struct block_device_operations aoe_bdops = { |
Al Viro | 94562c1 | 2008-03-02 09:23:18 -0500 | [diff] [blame] | 242 | .open = aoeblk_open, |
| 243 | .release = aoeblk_release, |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 244 | .getgeo = aoeblk_getgeo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | .owner = THIS_MODULE, |
| 246 | }; |
| 247 | |
| 248 | /* alloc_disk and add_disk can sleep */ |
| 249 | void |
| 250 | aoeblk_gdalloc(void *vp) |
| 251 | { |
| 252 | struct aoedev *d = vp; |
| 253 | struct gendisk *gd; |
| 254 | ulong flags; |
| 255 | |
| 256 | gd = alloc_disk(AOE_PARTITIONS); |
| 257 | if (gd == NULL) { |
Ed L. Cashin | 1d75981 | 2008-02-08 04:20:08 -0800 | [diff] [blame] | 258 | printk(KERN_ERR |
| 259 | "aoe: cannot allocate disk structure for %ld.%d\n", |
Ed L. Cashin | 6bb6285f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 260 | d->aoemajor, d->aoeminor); |
Andrew Morton | 43cbe2c | 2007-12-10 15:49:13 -0800 | [diff] [blame] | 261 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Matthew Dobson | 93d2341 | 2006-03-26 01:37:50 -0800 | [diff] [blame] | 264 | d->bufpool = mempool_create_slab_pool(MIN_BUFS, buf_pool_cache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | if (d->bufpool == NULL) { |
Ed L. Cashin | 1d75981 | 2008-02-08 04:20:08 -0800 | [diff] [blame] | 266 | printk(KERN_ERR "aoe: cannot allocate bufpool for %ld.%d\n", |
Ed L. Cashin | 6bb6285f | 2006-09-20 14:36:49 -0400 | [diff] [blame] | 267 | d->aoemajor, d->aoeminor); |
Andrew Morton | 43cbe2c | 2007-12-10 15:49:13 -0800 | [diff] [blame] | 268 | goto err_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Ed Cashin | 7135a71b | 2009-09-09 14:10:18 +0200 | [diff] [blame] | 271 | d->blkq = blk_alloc_queue(GFP_KERNEL); |
| 272 | if (!d->blkq) |
Andrew Morton | 43cbe2c | 2007-12-10 15:49:13 -0800 | [diff] [blame] | 273 | goto err_mempool; |
Ed Cashin | 7135a71b | 2009-09-09 14:10:18 +0200 | [diff] [blame] | 274 | blk_queue_make_request(d->blkq, aoeblk_make_request); |
Jens Axboe | d993831 | 2009-06-12 14:45:52 +0200 | [diff] [blame] | 275 | d->blkq->backing_dev_info.name = "aoe"; |
Ed Cashin | 7135a71b | 2009-09-09 14:10:18 +0200 | [diff] [blame] | 276 | if (bdi_init(&d->blkq->backing_dev_info)) |
| 277 | goto err_blkq; |
Andrew Morton | 43cbe2c | 2007-12-10 15:49:13 -0800 | [diff] [blame] | 278 | spin_lock_irqsave(&d->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | gd->major = AOE_MAJOR; |
| 280 | gd->first_minor = d->sysminor * AOE_PARTITIONS; |
| 281 | gd->fops = &aoe_bdops; |
| 282 | gd->private_data = d; |
Tejun Heo | 80795ae | 2008-08-25 19:56:07 +0900 | [diff] [blame] | 283 | set_capacity(gd, d->ssize); |
Ed L. Cashin | 68e0d42 | 2008-02-08 04:20:00 -0800 | [diff] [blame] | 284 | snprintf(gd->disk_name, sizeof gd->disk_name, "etherd/e%ld.%d", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | d->aoemajor, d->aoeminor); |
| 286 | |
Ed Cashin | 7135a71b | 2009-09-09 14:10:18 +0200 | [diff] [blame] | 287 | gd->queue = d->blkq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | d->gd = gd; |
Ed L. Cashin | 3ae1c24 | 2006-01-19 13:46:19 -0500 | [diff] [blame] | 289 | d->flags &= ~DEVFL_GDALLOC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | d->flags |= DEVFL_UP; |
| 291 | |
| 292 | spin_unlock_irqrestore(&d->lock, flags); |
| 293 | |
| 294 | add_disk(gd); |
| 295 | aoedisk_add_sysfs(d); |
Andrew Morton | 43cbe2c | 2007-12-10 15:49:13 -0800 | [diff] [blame] | 296 | return; |
| 297 | |
Ed Cashin | 7135a71b | 2009-09-09 14:10:18 +0200 | [diff] [blame] | 298 | err_blkq: |
| 299 | blk_cleanup_queue(d->blkq); |
| 300 | d->blkq = NULL; |
Andrew Morton | 43cbe2c | 2007-12-10 15:49:13 -0800 | [diff] [blame] | 301 | err_mempool: |
| 302 | mempool_destroy(d->bufpool); |
| 303 | err_disk: |
| 304 | put_disk(gd); |
| 305 | err: |
| 306 | spin_lock_irqsave(&d->lock, flags); |
| 307 | d->flags &= ~DEVFL_GDALLOC; |
| 308 | spin_unlock_irqrestore(&d->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | void |
| 312 | aoeblk_exit(void) |
| 313 | { |
| 314 | kmem_cache_destroy(buf_pool_cache); |
| 315 | } |
| 316 | |
| 317 | int __init |
| 318 | aoeblk_init(void) |
| 319 | { |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 320 | buf_pool_cache = kmem_cache_create("aoe_bufs", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | sizeof(struct buf), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 322 | 0, 0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | if (buf_pool_cache == NULL) |
| 324 | return -ENOMEM; |
| 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |