62 #include <linux/kernel.h>
63 #include <linux/device.h>
64 #include <linux/module.h>
66 #include <linux/slab.h>
72 #define DRV_NAME "osdblk"
73 #define PFX DRV_NAME ": "
77 #define OSDBLK_DEBUG(fmt, a...) \
78 printk(KERN_NOTICE "osdblk @%s:%d: " fmt, __func__, __LINE__, ##a)
80 #define OSDBLK_DEBUG(fmt, a...) \
81 do { if (0) printk(fmt, ##a); } while (0)
125 static struct class *class_osdblk;
129 static const struct block_device_operations osdblk_bd_ops = {
165 void *caller_context,
u8 *
cred)
221 attr = g_attr_logical_length;
222 ret = extract_attr_from_req(or, &attr);
234 static void osdblk_osd_complete(
struct osd_request *or,
void *
private)
238 int ret = osd_req_decode_sense(or, &osi);
252 static void bio_chain_put(
struct bio *
chain)
258 chain = chain->bi_next;
264 static struct bio *bio_chain_clone(
struct bio *old_chain,
gfp_t gfpmask)
269 tmp = bio_clone_kmalloc(old_chain, gfpmask);
278 new_chain = tail =
tmp;
284 old_chain = old_chain->bi_next;
291 bio_chain_put(new_chain);
312 if (rq->cmd_type != REQ_TYPE_FS) {
325 do_write = (rq_data_dir(rq) ==
WRITE);
343 orq = &osdev->
req[rq->tag];
354 bio, blk_rq_bytes(rq));
357 bio, blk_rq_bytes(rq));
360 do_flush ?
"flush" : do_write ?
361 "write" :
"read", blk_rq_bytes(rq),
362 blk_rq_pos(rq) * 512ULL);
365 if (osd_async_op(or, osdblk_osd_complete, orq,
383 struct gendisk *disk = osdev->
disk;
388 if (disk->flags & GENHD_FL_UP)
397 struct gendisk *disk;
403 rc = osdblk_get_obj_size(osdev, &obj_size);
413 disk->major = osdev->
major;
414 disk->first_minor = 0;
415 disk->fops = &osdblk_bd_ops;
416 disk->private_data = osdev;
444 q->queuedata = osdev;
450 set_capacity(disk, obj_size / 512ULL);
454 disk->disk_name, (
unsigned long long)obj_size);
466 static void class_osdblk_release(
struct class *cls)
471 static ssize_t class_osdblk_list(
struct class *
c,
485 n +=
sprintf(data+n,
"%d %d %llu %llu %s\n",
488 osdev->
obj.partition,
497 static ssize_t class_osdblk_add(
struct class *
c,
518 INIT_LIST_HEAD(&osdev->
node);
528 if (osdev->
id > new_id)
529 new_id = osdev->
id + 1;
540 if (
sscanf(buf,
"%llu %llu %s", &osdev->
obj.partition, &osdev->
obj.id,
551 if (IS_ERR(osdev->
osd)) {
552 rc = PTR_ERR(osdev->
osd);
557 osdblk_make_credential(osdev->
obj_cred, &osdev->
obj);
569 rc = osdblk_init_disk(osdev);
581 list_del_init(&osdev->
node);
591 static ssize_t class_osdblk_remove(
struct class *
c,
606 target_id = (
int) ul;
615 if (osdev->
id == target_id) {
616 list_del_init(&osdev->
node);
628 osdblk_free_disk(osdev);
641 __ATTR(
remove, 0200,
NULL, class_osdblk_remove),
646 static int osdblk_sysfs_init(
void)
654 class_osdblk = kzalloc(
sizeof(*class_osdblk),
GFP_KERNEL);
667 printk(
PFX "failed to create class osdblk\n");
674 static void osdblk_sysfs_cleanup(
void)
681 static int __init osdblk_init(
void)
685 rc = osdblk_sysfs_init();
692 static void __exit osdblk_exit(
void)
694 osdblk_sysfs_cleanup();