2 * bsg.c - block layer implementation of the sg v3 interface
4 * Copyright (C) 2004 Jens Axboe <axboe@suse.de> SUSE Labs
5 * Copyright (C) 2004 Peter M. Jones <pjones@redhat.com>
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License version 2. See the file "COPYING" in the main directory of this
9 * archive for more details.
14 * - Should this get merged, block/scsi_ioctl.c will be migrated into
15 * this file. To keep maintenance down, it's easier to have them
16 * seperated right now.
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/file.h>
22 #include <linux/blkdev.h>
23 #include <linux/poll.h>
24 #include <linux/cdev.h>
25 #include <linux/percpu.h>
26 #include <linux/uio.h>
27 #include <linux/bsg.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_ioctl.h>
31 #include <scsi/scsi_cmnd.h>
34 static char bsg_version
[] = "block layer sg (bsg) 0.4";
38 request_queue_t
*queue
;
40 struct list_head busy_list
;
41 struct list_head done_list
;
42 struct hlist_node dev_list
;
47 wait_queue_head_t wq_done
;
48 wait_queue_head_t wq_free
;
49 char name
[BDEVNAME_SIZE
];
59 #define BSG_DEFAULT_CMDS 64
64 #define dprintk(fmt, args...) printk(KERN_ERR "%s: " fmt, __FUNCTION__, ##args)
66 #define dprintk(fmt, args...)
69 #define list_entry_bc(entry) list_entry((entry), struct bsg_command, list)
74 #define BSG_MAJOR (240)
76 static DEFINE_MUTEX(bsg_mutex
);
77 static int bsg_device_nr
;
79 #define BSG_LIST_SIZE (8)
80 #define bsg_list_idx(minor) ((minor) & (BSG_LIST_SIZE - 1))
81 static struct hlist_head bsg_device_list
[BSG_LIST_SIZE
];
83 static struct class *bsg_class
;
84 static LIST_HEAD(bsg_class_list
);
86 static struct kmem_cache
*bsg_cmd_cachep
;
89 * our internal command type
92 struct bsg_device
*bd
;
93 struct list_head list
;
98 struct sg_io_v4 __user
*uhdr
;
99 char sense
[SCSI_SENSE_BUFFERSIZE
];
102 static void bsg_free_command(struct bsg_command
*bc
)
104 struct bsg_device
*bd
= bc
->bd
;
107 kmem_cache_free(bsg_cmd_cachep
, bc
);
109 spin_lock_irqsave(&bd
->lock
, flags
);
111 spin_unlock_irqrestore(&bd
->lock
, flags
);
113 wake_up(&bd
->wq_free
);
116 static struct bsg_command
*__bsg_alloc_command(struct bsg_device
*bd
)
118 struct bsg_command
*bc
= NULL
;
120 spin_lock_irq(&bd
->lock
);
122 if (bd
->queued_cmds
>= bd
->max_queue
)
126 spin_unlock_irq(&bd
->lock
);
128 bc
= kmem_cache_alloc(bsg_cmd_cachep
, GFP_USER
);
130 spin_lock_irq(&bd
->lock
);
134 memset(bc
, 0, sizeof(*bc
));
136 INIT_LIST_HEAD(&bc
->list
);
137 dprintk("%s: returning free cmd %p\n", bd
->name
, bc
);
142 spin_unlock_irq(&bd
->lock
);
147 bsg_del_done_cmd(struct bsg_device
*bd
, struct bsg_command
*bc
)
154 bsg_add_done_cmd(struct bsg_device
*bd
, struct bsg_command
*bc
)
157 list_add_tail(&bc
->list
, &bd
->done_list
);
158 wake_up(&bd
->wq_done
);
161 static inline int bsg_io_schedule(struct bsg_device
*bd
, int state
)
166 spin_lock_irq(&bd
->lock
);
168 BUG_ON(bd
->done_cmds
> bd
->queued_cmds
);
171 * -ENOSPC or -ENODATA? I'm going for -ENODATA, meaning "I have no
172 * work to do", even though we return -ENOSPC after this same test
173 * during bsg_write() -- there, it means our buffer can't have more
174 * bsg_commands added to it, thus has no space left.
176 if (bd
->done_cmds
== bd
->queued_cmds
) {
181 if (!test_bit(BSG_F_BLOCK
, &bd
->flags
)) {
186 prepare_to_wait(&bd
->wq_done
, &wait
, state
);
187 spin_unlock_irq(&bd
->lock
);
189 finish_wait(&bd
->wq_done
, &wait
);
191 if ((state
== TASK_INTERRUPTIBLE
) && signal_pending(current
))
196 spin_unlock_irq(&bd
->lock
);
201 * get a new free command, blocking if needed and specified
203 static struct bsg_command
*bsg_get_command(struct bsg_device
*bd
)
205 struct bsg_command
*bc
;
209 bc
= __bsg_alloc_command(bd
);
213 ret
= bsg_io_schedule(bd
, TASK_INTERRUPTIBLE
);
224 static int blk_fill_sgv4_hdr_rq(request_queue_t
*q
, struct request
*rq
,
225 struct sg_io_v4
*hdr
, int has_write_perm
)
227 memset(rq
->cmd
, 0, BLK_MAX_CDB
); /* ATAPI hates garbage after CDB */
229 if (copy_from_user(rq
->cmd
, (void *)(unsigned long)hdr
->request
,
232 if (blk_verify_command(rq
->cmd
, has_write_perm
))
236 * fill in request structure
238 rq
->cmd_len
= hdr
->request_len
;
239 rq
->cmd_type
= REQ_TYPE_BLOCK_PC
;
241 rq
->timeout
= (hdr
->timeout
* HZ
) / 1000;
243 rq
->timeout
= q
->sg_timeout
;
245 rq
->timeout
= BLK_DEFAULT_SG_TIMEOUT
;
251 * Check if sg_io_v4 from user is allowed and valid
254 bsg_validate_sgv4_hdr(request_queue_t
*q
, struct sg_io_v4
*hdr
, int *rw
)
256 if (hdr
->guard
!= 'Q')
258 if (hdr
->request_len
> BLK_MAX_CDB
)
260 if (hdr
->dout_xfer_len
> (q
->max_sectors
<< 9) ||
261 hdr
->din_xfer_len
> (q
->max_sectors
<< 9))
264 /* not supported currently */
265 if (hdr
->protocol
|| hdr
->subprotocol
)
269 * looks sane, if no data then it should be fine from our POV
271 if (!hdr
->dout_xfer_len
&& !hdr
->din_xfer_len
)
274 /* not supported currently */
275 if (hdr
->dout_xfer_len
&& hdr
->din_xfer_len
)
278 *rw
= hdr
->dout_xfer_len
? WRITE
: READ
;
284 * map sg_io_v4 to a request.
286 static struct request
*
287 bsg_map_hdr(struct bsg_device
*bd
, struct sg_io_v4
*hdr
)
289 request_queue_t
*q
= bd
->queue
;
291 int ret
, rw
= 0; /* shut up gcc */
292 unsigned int dxfer_len
;
295 dprintk("map hdr %llx/%u %llx/%u\n", (unsigned long long) hdr
->dout_xferp
,
296 hdr
->dout_xfer_len
, (unsigned long long) hdr
->din_xferp
,
299 ret
= bsg_validate_sgv4_hdr(q
, hdr
, &rw
);
304 * map scatter-gather elements seperately and string them to request
306 rq
= blk_get_request(q
, rw
, GFP_KERNEL
);
307 ret
= blk_fill_sgv4_hdr_rq(q
, rq
, hdr
, test_bit(BSG_F_WRITE_PERM
,
314 if (hdr
->dout_xfer_len
) {
315 dxfer_len
= hdr
->dout_xfer_len
;
316 dxferp
= (void*)(unsigned long)hdr
->dout_xferp
;
317 } else if (hdr
->din_xfer_len
) {
318 dxfer_len
= hdr
->din_xfer_len
;
319 dxferp
= (void*)(unsigned long)hdr
->din_xferp
;
324 ret
= blk_rq_map_user(q
, rq
, dxferp
, dxfer_len
);
326 dprintk("failed map at %d\n", ret
);
336 * async completion call-back from the block layer, when scsi/ide/whatever
337 * calls end_that_request_last() on a request
339 static void bsg_rq_end_io(struct request
*rq
, int uptodate
)
341 struct bsg_command
*bc
= rq
->end_io_data
;
342 struct bsg_device
*bd
= bc
->bd
;
345 dprintk("%s: finished rq %p bc %p, bio %p stat %d\n",
346 bd
->name
, rq
, bc
, bc
->bio
, uptodate
);
348 bc
->hdr
.duration
= jiffies_to_msecs(jiffies
- bc
->hdr
.duration
);
350 spin_lock_irqsave(&bd
->lock
, flags
);
352 bsg_add_done_cmd(bd
, bc
);
353 spin_unlock_irqrestore(&bd
->lock
, flags
);
357 * do final setup of a 'bc' and submit the matching 'rq' to the block
360 static void bsg_add_command(struct bsg_device
*bd
, request_queue_t
*q
,
361 struct bsg_command
*bc
, struct request
*rq
)
363 rq
->sense
= bc
->sense
;
367 * add bc command to busy queue and submit rq for io
371 bc
->hdr
.duration
= jiffies
;
372 spin_lock_irq(&bd
->lock
);
373 list_add_tail(&bc
->list
, &bd
->busy_list
);
374 spin_unlock_irq(&bd
->lock
);
376 dprintk("%s: queueing rq %p, bc %p\n", bd
->name
, rq
, bc
);
378 rq
->end_io_data
= bc
;
379 blk_execute_rq_nowait(q
, bd
->disk
, rq
, 1, bsg_rq_end_io
);
382 static inline struct bsg_command
*bsg_next_done_cmd(struct bsg_device
*bd
)
384 struct bsg_command
*bc
= NULL
;
386 spin_lock_irq(&bd
->lock
);
388 bc
= list_entry_bc(bd
->done_list
.next
);
389 bsg_del_done_cmd(bd
, bc
);
391 spin_unlock_irq(&bd
->lock
);
397 * Get a finished command from the done list
399 static struct bsg_command
*__bsg_get_done_cmd(struct bsg_device
*bd
, int state
)
401 struct bsg_command
*bc
;
405 bc
= bsg_next_done_cmd(bd
);
409 ret
= bsg_io_schedule(bd
, state
);
416 dprintk("%s: returning done %p\n", bd
->name
, bc
);
421 static struct bsg_command
*
422 bsg_get_done_cmd(struct bsg_device
*bd
, const struct iovec
*iov
)
424 return __bsg_get_done_cmd(bd
, TASK_INTERRUPTIBLE
);
427 static struct bsg_command
*
428 bsg_get_done_cmd_nosignals(struct bsg_device
*bd
)
430 return __bsg_get_done_cmd(bd
, TASK_UNINTERRUPTIBLE
);
433 static int blk_complete_sgv4_hdr_rq(struct request
*rq
, struct sg_io_v4
*hdr
,
438 dprintk("rq %p bio %p %u\n", rq
, bio
, rq
->errors
);
440 * fill in all the output members
442 hdr
->device_status
= status_byte(rq
->errors
);
443 hdr
->transport_status
= host_byte(rq
->errors
);
444 hdr
->driver_status
= driver_byte(rq
->errors
);
446 if (hdr
->device_status
|| hdr
->transport_status
|| hdr
->driver_status
)
447 hdr
->info
|= SG_INFO_CHECK
;
448 hdr
->din_resid
= rq
->data_len
;
449 hdr
->response_len
= 0;
451 if (rq
->sense_len
&& hdr
->response
) {
452 int len
= min((unsigned int) hdr
->max_response_len
,
455 ret
= copy_to_user((void*)(unsigned long)hdr
->response
,
458 hdr
->response_len
= len
;
463 blk_rq_unmap_user(bio
);
469 static int bsg_complete_all_commands(struct bsg_device
*bd
)
471 struct bsg_command
*bc
;
474 dprintk("%s: entered\n", bd
->name
);
476 set_bit(BSG_F_BLOCK
, &bd
->flags
);
479 * wait for all commands to complete
483 ret
= bsg_io_schedule(bd
, TASK_UNINTERRUPTIBLE
);
485 * look for -ENODATA specifically -- we'll sometimes get
486 * -ERESTARTSYS when we've taken a signal, but we can't
487 * return until we're done freeing the queue, so ignore
488 * it. The signal will get handled when we're done freeing
491 } while (ret
!= -ENODATA
);
494 * discard done commands
498 bc
= bsg_get_done_cmd_nosignals(bd
);
501 * we _must_ complete before restarting, because
502 * bsg_release can't handle this failing.
504 if (PTR_ERR(bc
) == -ERESTARTSYS
)
511 tret
= blk_complete_sgv4_hdr_rq(bc
->rq
, &bc
->hdr
, bc
->bio
);
515 bsg_free_command(bc
);
521 typedef struct bsg_command
*(*bsg_command_callback
)(struct bsg_device
*bd
, const struct iovec
*iov
);
524 __bsg_read(char __user
*buf
, size_t count
, bsg_command_callback get_bc
,
525 struct bsg_device
*bd
, const struct iovec
*iov
, ssize_t
*bytes_read
)
527 struct bsg_command
*bc
;
528 int nr_commands
, ret
;
530 if (count
% sizeof(struct sg_io_v4
))
534 nr_commands
= count
/ sizeof(struct sg_io_v4
);
535 while (nr_commands
) {
536 bc
= get_bc(bd
, iov
);
543 * this is the only case where we need to copy data back
544 * after completing the request. so do that here,
545 * bsg_complete_work() cannot do that for us
547 ret
= blk_complete_sgv4_hdr_rq(bc
->rq
, &bc
->hdr
, bc
->bio
);
549 if (copy_to_user(buf
, (char *) &bc
->hdr
, sizeof(bc
->hdr
)))
552 bsg_free_command(bc
);
557 buf
+= sizeof(struct sg_io_v4
);
558 *bytes_read
+= sizeof(struct sg_io_v4
);
565 static inline void bsg_set_block(struct bsg_device
*bd
, struct file
*file
)
567 if (file
->f_flags
& O_NONBLOCK
)
568 clear_bit(BSG_F_BLOCK
, &bd
->flags
);
570 set_bit(BSG_F_BLOCK
, &bd
->flags
);
573 static inline void bsg_set_write_perm(struct bsg_device
*bd
, struct file
*file
)
575 if (file
->f_mode
& FMODE_WRITE
)
576 set_bit(BSG_F_WRITE_PERM
, &bd
->flags
);
578 clear_bit(BSG_F_WRITE_PERM
, &bd
->flags
);
581 static inline int err_block_err(int ret
)
583 if (ret
&& ret
!= -ENOSPC
&& ret
!= -ENODATA
&& ret
!= -EAGAIN
)
590 bsg_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*ppos
)
592 struct bsg_device
*bd
= file
->private_data
;
596 dprintk("%s: read %Zd bytes\n", bd
->name
, count
);
598 bsg_set_block(bd
, file
);
600 ret
= __bsg_read(buf
, count
, bsg_get_done_cmd
,
601 bd
, NULL
, &bytes_read
);
604 if (!bytes_read
|| (bytes_read
&& err_block_err(ret
)))
610 static ssize_t
__bsg_write(struct bsg_device
*bd
, const char __user
*buf
,
611 size_t count
, ssize_t
*bytes_read
)
613 struct bsg_command
*bc
;
615 int ret
, nr_commands
;
617 if (count
% sizeof(struct sg_io_v4
))
620 nr_commands
= count
/ sizeof(struct sg_io_v4
);
624 while (nr_commands
) {
625 request_queue_t
*q
= bd
->queue
;
627 bc
= bsg_get_command(bd
);
636 bc
->uhdr
= (struct sg_io_v4 __user
*) buf
;
637 if (copy_from_user(&bc
->hdr
, buf
, sizeof(bc
->hdr
))) {
643 * get a request, fill in the blanks, and add to request queue
645 rq
= bsg_map_hdr(bd
, &bc
->hdr
);
652 bsg_add_command(bd
, q
, bc
, rq
);
656 buf
+= sizeof(struct sg_io_v4
);
657 *bytes_read
+= sizeof(struct sg_io_v4
);
661 bsg_free_command(bc
);
667 bsg_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
669 struct bsg_device
*bd
= file
->private_data
;
673 dprintk("%s: write %Zd bytes\n", bd
->name
, count
);
675 bsg_set_block(bd
, file
);
676 bsg_set_write_perm(bd
, file
);
679 ret
= __bsg_write(bd
, buf
, count
, &bytes_read
);
683 * return bytes written on non-fatal errors
685 if (!bytes_read
|| (bytes_read
&& err_block_err(ret
)))
688 dprintk("%s: returning %Zd\n", bd
->name
, bytes_read
);
692 static struct bsg_device
*bsg_alloc_device(void)
694 struct bsg_device
*bd
;
696 bd
= kzalloc(sizeof(struct bsg_device
), GFP_KERNEL
);
700 spin_lock_init(&bd
->lock
);
702 bd
->max_queue
= BSG_DEFAULT_CMDS
;
704 INIT_LIST_HEAD(&bd
->busy_list
);
705 INIT_LIST_HEAD(&bd
->done_list
);
706 INIT_HLIST_NODE(&bd
->dev_list
);
708 init_waitqueue_head(&bd
->wq_free
);
709 init_waitqueue_head(&bd
->wq_done
);
713 static int bsg_put_device(struct bsg_device
*bd
)
717 mutex_lock(&bsg_mutex
);
719 if (!atomic_dec_and_test(&bd
->ref_count
))
722 dprintk("%s: tearing down\n", bd
->name
);
725 * close can always block
727 set_bit(BSG_F_BLOCK
, &bd
->flags
);
730 * correct error detection baddies here again. it's the responsibility
731 * of the app to properly reap commands before close() if it wants
732 * fool-proof error detection
734 ret
= bsg_complete_all_commands(bd
);
736 blk_put_queue(bd
->queue
);
737 hlist_del(&bd
->dev_list
);
740 mutex_unlock(&bsg_mutex
);
744 static struct bsg_device
*bsg_add_device(struct inode
*inode
,
745 struct gendisk
*disk
,
748 struct bsg_device
*bd
= NULL
;
750 unsigned char buf
[32];
753 bd
= bsg_alloc_device();
755 return ERR_PTR(-ENOMEM
);
758 bd
->queue
= disk
->queue
;
759 kobject_get(&disk
->queue
->kobj
);
760 bsg_set_block(bd
, file
);
762 atomic_set(&bd
->ref_count
, 1);
763 bd
->minor
= iminor(inode
);
764 mutex_lock(&bsg_mutex
);
765 hlist_add_head(&bd
->dev_list
,&bsg_device_list
[bsg_list_idx(bd
->minor
)]);
767 strncpy(bd
->name
, disk
->disk_name
, sizeof(bd
->name
) - 1);
768 dprintk("bound to <%s>, max queue %d\n",
769 format_dev_t(buf
, inode
->i_rdev
), bd
->max_queue
);
771 mutex_unlock(&bsg_mutex
);
775 static struct bsg_device
*__bsg_get_device(int minor
)
777 struct hlist_head
*list
= &bsg_device_list
[bsg_list_idx(minor
)];
778 struct bsg_device
*bd
= NULL
;
779 struct hlist_node
*entry
;
781 mutex_lock(&bsg_mutex
);
783 hlist_for_each(entry
, list
) {
784 bd
= hlist_entry(entry
, struct bsg_device
, dev_list
);
785 if (bd
->minor
== minor
) {
786 atomic_inc(&bd
->ref_count
);
793 mutex_unlock(&bsg_mutex
);
797 static struct bsg_device
*bsg_get_device(struct inode
*inode
, struct file
*file
)
799 struct bsg_device
*bd
= __bsg_get_device(iminor(inode
));
800 struct bsg_class_device
*bcd
, *__bcd
;
806 * find the class device
809 mutex_lock(&bsg_mutex
);
810 list_for_each_entry(__bcd
, &bsg_class_list
, list
) {
811 if (__bcd
->minor
== iminor(inode
)) {
816 mutex_unlock(&bsg_mutex
);
819 return ERR_PTR(-ENODEV
);
821 return bsg_add_device(inode
, bcd
->disk
, file
);
824 static int bsg_open(struct inode
*inode
, struct file
*file
)
826 struct bsg_device
*bd
= bsg_get_device(inode
, file
);
831 file
->private_data
= bd
;
835 static int bsg_release(struct inode
*inode
, struct file
*file
)
837 struct bsg_device
*bd
= file
->private_data
;
839 file
->private_data
= NULL
;
840 return bsg_put_device(bd
);
843 static unsigned int bsg_poll(struct file
*file
, poll_table
*wait
)
845 struct bsg_device
*bd
= file
->private_data
;
846 unsigned int mask
= 0;
848 poll_wait(file
, &bd
->wq_done
, wait
);
849 poll_wait(file
, &bd
->wq_free
, wait
);
851 spin_lock_irq(&bd
->lock
);
852 if (!list_empty(&bd
->done_list
))
853 mask
|= POLLIN
| POLLRDNORM
;
854 if (bd
->queued_cmds
>= bd
->max_queue
)
856 spin_unlock_irq(&bd
->lock
);
862 bsg_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
,
865 struct bsg_device
*bd
= file
->private_data
;
866 int __user
*uarg
= (int __user
*) arg
;
875 case SG_GET_COMMAND_Q
:
876 return put_user(bd
->max_queue
, uarg
);
877 case SG_SET_COMMAND_Q
: {
880 if (get_user(queue
, uarg
))
885 spin_lock_irq(&bd
->lock
);
886 bd
->max_queue
= queue
;
887 spin_unlock_irq(&bd
->lock
);
894 case SG_GET_VERSION_NUM
:
895 case SCSI_IOCTL_GET_IDLUN
:
896 case SCSI_IOCTL_GET_BUS_NUMBER
:
899 case SG_GET_RESERVED_SIZE
:
900 case SG_SET_RESERVED_SIZE
:
901 case SG_EMULATED_HOST
:
902 case SCSI_IOCTL_SEND_COMMAND
: {
903 void __user
*uarg
= (void __user
*) arg
;
904 return scsi_cmd_ioctl(file
, bd
->disk
, cmd
, uarg
);
911 if (copy_from_user(&hdr
, uarg
, sizeof(hdr
)))
914 rq
= bsg_map_hdr(bd
, &hdr
);
919 blk_execute_rq(bd
->queue
, bd
->disk
, rq
, 0);
920 blk_complete_sgv4_hdr_rq(rq
, &hdr
, bio
);
922 if (copy_to_user(uarg
, &hdr
, sizeof(hdr
)))
928 * block device ioctls
932 return ioctl_by_bdev(bd
->bdev
, cmd
, arg
);
939 static struct file_operations bsg_fops
= {
944 .release
= bsg_release
,
946 .owner
= THIS_MODULE
,
949 void bsg_unregister_disk(struct gendisk
*disk
)
951 struct bsg_class_device
*bcd
= &disk
->bsg_dev
;
956 mutex_lock(&bsg_mutex
);
957 sysfs_remove_link(&bcd
->disk
->queue
->kobj
, "bsg");
958 class_device_destroy(bsg_class
, MKDEV(BSG_MAJOR
, bcd
->minor
));
959 bcd
->class_dev
= NULL
;
960 list_del_init(&bcd
->list
);
961 mutex_unlock(&bsg_mutex
);
964 int bsg_register_disk(struct gendisk
*disk
)
966 request_queue_t
*q
= disk
->queue
;
967 struct bsg_class_device
*bcd
;
971 * we need a proper transport to send commands, not a stacked device
976 bcd
= &disk
->bsg_dev
;
977 memset(bcd
, 0, sizeof(*bcd
));
978 INIT_LIST_HEAD(&bcd
->list
);
980 mutex_lock(&bsg_mutex
);
981 dev
= MKDEV(BSG_MAJOR
, bsg_device_nr
);
982 bcd
->minor
= bsg_device_nr
;
985 bcd
->class_dev
= class_device_create(bsg_class
, NULL
, dev
, bcd
->dev
, "%s", disk
->disk_name
);
986 list_add_tail(&bcd
->list
, &bsg_class_list
);
987 sysfs_create_link(&q
->kobj
, &bcd
->class_dev
->kobj
, "bsg");
988 mutex_unlock(&bsg_mutex
);
992 static int __init
bsg_init(void)
996 bsg_cmd_cachep
= kmem_cache_create("bsg_cmd",
997 sizeof(struct bsg_command
), 0, 0, NULL
, NULL
);
998 if (!bsg_cmd_cachep
) {
999 printk(KERN_ERR
"bsg: failed creating slab cache\n");
1003 for (i
= 0; i
< BSG_LIST_SIZE
; i
++)
1004 INIT_HLIST_HEAD(&bsg_device_list
[i
]);
1006 bsg_class
= class_create(THIS_MODULE
, "bsg");
1007 if (IS_ERR(bsg_class
)) {
1008 kmem_cache_destroy(bsg_cmd_cachep
);
1009 return PTR_ERR(bsg_class
);
1012 ret
= register_chrdev(BSG_MAJOR
, "bsg", &bsg_fops
);
1014 kmem_cache_destroy(bsg_cmd_cachep
);
1015 class_destroy(bsg_class
);
1019 printk(KERN_INFO
"%s loaded\n", bsg_version
);
1023 MODULE_AUTHOR("Jens Axboe");
1024 MODULE_DESCRIPTION("Block layer SGSI generic (sg) driver");
1025 MODULE_LICENSE("GPL");
1027 subsys_initcall(bsg_init
);