netns xfrm: fix "ip xfrm state|policy count" misreport
[safe/jmp/linux-2.6] / block / bsg.c
index 0ce8806..a9fd2d8 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/blkdev.h>
 #include <linux/poll.h>
 #include <linux/cdev.h>
+#include <linux/jiffies.h>
 #include <linux/percpu.h>
 #include <linux/uio.h>
 #include <linux/idr.h>
@@ -186,7 +187,7 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
                return -EFAULT;
 
        if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
-               if (blk_verify_command(&q->cmd_filter, rq->cmd, has_write_perm))
+               if (blk_verify_command(rq->cmd, has_write_perm))
                        return -EPERM;
        } else if (!capable(CAP_SYS_RAWIO))
                return -EPERM;
@@ -197,7 +198,7 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
        rq->cmd_len = hdr->request_len;
        rq->cmd_type = REQ_TYPE_BLOCK_PC;
 
-       rq->timeout = (hdr->timeout * HZ) / 1000;
+       rq->timeout = msecs_to_jiffies(hdr->timeout);
        if (!rq->timeout)
                rq->timeout = q->sg_timeout;
        if (!rq->timeout)
@@ -218,9 +219,6 @@ bsg_validate_sgv4_hdr(struct request_queue *q, struct sg_io_v4 *hdr, int *rw)
 
        if (hdr->guard != 'Q')
                return -EINVAL;
-       if (hdr->dout_xfer_len > (q->max_sectors << 9) ||
-           hdr->din_xfer_len > (q->max_sectors << 9))
-               return -EIO;
 
        switch (hdr->protocol) {
        case BSG_PROTOCOL_SCSI:
@@ -353,6 +351,8 @@ static void bsg_rq_end_io(struct request *rq, int uptodate)
 static void bsg_add_command(struct bsg_device *bd, struct request_queue *q,
                            struct bsg_command *bc, struct request *rq)
 {
+       int at_head = (0 == (bc->hdr.flags & BSG_FLAG_Q_AT_TAIL));
+
        /*
         * add bc command to busy queue and submit rq for io
         */
@@ -368,7 +368,7 @@ static void bsg_add_command(struct bsg_device *bd, struct request_queue *q,
        dprintk("%s: queueing rq %p, bc %p\n", bd->name, rq, bc);
 
        rq->end_io_data = bc;
-       blk_execute_rq_nowait(q, NULL, rq, 1, bsg_rq_end_io);
+       blk_execute_rq_nowait(q, NULL, rq, at_head, bsg_rq_end_io);
 }
 
 static struct bsg_command *bsg_next_done_cmd(struct bsg_device *bd)
@@ -446,14 +446,14 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
        }
 
        if (rq->next_rq) {
-               hdr->dout_resid = rq->data_len;
-               hdr->din_resid = rq->next_rq->data_len;
+               hdr->dout_resid = rq->resid_len;
+               hdr->din_resid = rq->next_rq->resid_len;
                blk_rq_unmap_user(bidi_bio);
                blk_put_request(rq->next_rq);
        } else if (rq_data_dir(rq) == READ)
-               hdr->din_resid = rq->data_len;
+               hdr->din_resid = rq->resid_len;
        else
-               hdr->dout_resid = rq->data_len;
+               hdr->dout_resid = rq->resid_len;
 
        /*
         * If the request generated a negative error number, return it
@@ -924,6 +924,7 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                struct request *rq;
                struct bio *bio, *bidi_bio = NULL;
                struct sg_io_v4 hdr;
+               int at_head;
                u8 sense[SCSI_SENSE_BUFFERSIZE];
 
                if (copy_from_user(&hdr, uarg, sizeof(hdr)))
@@ -936,7 +937,9 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                bio = rq->bio;
                if (rq->next_rq)
                        bidi_bio = rq->next_rq->bio;
-               blk_execute_rq(bd->queue, NULL, rq, 0);
+
+               at_head = (0 == (hdr.flags & BSG_FLAG_Q_AT_TAIL));
+               blk_execute_rq(bd->queue, NULL, rq, at_head);
                ret = blk_complete_sgv4_hdr_rq(rq, &hdr, bio, bidi_bio);
 
                if (copy_to_user(uarg, &hdr, sizeof(hdr)))
@@ -1060,6 +1063,11 @@ EXPORT_SYMBOL_GPL(bsg_register_queue);
 
 static struct cdev bsg_cdev;
 
+static char *bsg_devnode(struct device *dev, mode_t *mode)
+{
+       return kasprintf(GFP_KERNEL, "bsg/%s", dev_name(dev));
+}
+
 static int __init bsg_init(void)
 {
        int ret, i;
@@ -1080,6 +1088,7 @@ static int __init bsg_init(void)
                ret = PTR_ERR(bsg_class);
                goto destroy_kmemcache;
        }
+       bsg_class->devnode = bsg_devnode;
 
        ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg");
        if (ret)