]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - block/bsg.c
lib/vsprintf.c: remove %Z support
[karo-tx-linux.git] / block / bsg.c
index a57046de2f07f00eae78aaabe9b5e43c1ecc178f..74835dbf0c47c3fc1c6f2f80c9da53ee112402da 100644 (file)
@@ -85,7 +85,6 @@ struct bsg_command {
        struct bio *bidi_bio;
        int err;
        struct sg_io_v4 hdr;
-       char sense[SCSI_SENSE_BUFFERSIZE];
 };
 
 static void bsg_free_command(struct bsg_command *bc)
@@ -140,18 +139,20 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
                                struct sg_io_v4 *hdr, struct bsg_device *bd,
                                fmode_t has_write_perm)
 {
+       struct scsi_request *req = scsi_req(rq);
+
        if (hdr->request_len > BLK_MAX_CDB) {
-               rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
-               if (!rq->cmd)
+               req->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
+               if (!req->cmd)
                        return -ENOMEM;
        }
 
-       if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
+       if (copy_from_user(req->cmd, (void __user *)(unsigned long)hdr->request,
                           hdr->request_len))
                return -EFAULT;
 
        if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
-               if (blk_verify_command(rq->cmd, has_write_perm))
+               if (blk_verify_command(req->cmd, has_write_perm))
                        return -EPERM;
        } else if (!capable(CAP_SYS_RAWIO))
                return -EPERM;
@@ -159,7 +160,7 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
        /*
         * fill in request structure
         */
-       rq->cmd_len = hdr->request_len;
+       req->cmd_len = hdr->request_len;
 
        rq->timeout = msecs_to_jiffies(hdr->timeout);
        if (!rq->timeout)
@@ -176,7 +177,7 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
  * Check if sg_io_v4 from user is allowed and valid
  */
 static int
-bsg_validate_sgv4_hdr(struct sg_io_v4 *hdr, int *rw)
+bsg_validate_sgv4_hdr(struct sg_io_v4 *hdr, int *op)
 {
        int ret = 0;
 
@@ -197,7 +198,7 @@ bsg_validate_sgv4_hdr(struct sg_io_v4 *hdr, int *rw)
                ret = -EINVAL;
        }
 
-       *rw = hdr->dout_xfer_len ? WRITE : READ;
+       *op = hdr->dout_xfer_len ? REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN;
        return ret;
 }
 
@@ -205,13 +206,12 @@ bsg_validate_sgv4_hdr(struct sg_io_v4 *hdr, int *rw)
  * map sg_io_v4 to a request.
  */
 static struct request *
-bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
-           u8 *sense)
+bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm)
 {
        struct request_queue *q = bd->queue;
        struct request *rq, *next_rq = NULL;
-       int ret, rw;
-       unsigned int dxfer_len;
+       int ret;
+       unsigned int op, dxfer_len;
        void __user *dxferp = NULL;
        struct bsg_class_device *bcd = &q->bsg_dev;
 
@@ -226,36 +226,35 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
                hdr->dout_xfer_len, (unsigned long long) hdr->din_xferp,
                hdr->din_xfer_len);
 
-       ret = bsg_validate_sgv4_hdr(hdr, &rw);
+       ret = bsg_validate_sgv4_hdr(hdr, &op);
        if (ret)
                return ERR_PTR(ret);
 
        /*
         * map scatter-gather elements separately and string them to request
         */
-       rq = blk_get_request(q, rw, GFP_KERNEL);
+       rq = blk_get_request(q, op, GFP_KERNEL);
        if (IS_ERR(rq))
                return rq;
-       blk_rq_set_block_pc(rq);
+       scsi_req_init(rq);
 
        ret = blk_fill_sgv4_hdr_rq(q, rq, hdr, bd, has_write_perm);
        if (ret)
                goto out;
 
-       if (rw == WRITE && hdr->din_xfer_len) {
+       if (op == REQ_OP_SCSI_OUT && hdr->din_xfer_len) {
                if (!test_bit(QUEUE_FLAG_BIDI, &q->queue_flags)) {
                        ret = -EOPNOTSUPP;
                        goto out;
                }
 
-               next_rq = blk_get_request(q, READ, GFP_KERNEL);
+               next_rq = blk_get_request(q, REQ_OP_SCSI_IN, GFP_KERNEL);
                if (IS_ERR(next_rq)) {
                        ret = PTR_ERR(next_rq);
                        next_rq = NULL;
                        goto out;
                }
                rq->next_rq = next_rq;
-               next_rq->cmd_type = rq->cmd_type;
 
                dxferp = (void __user *)(unsigned long)hdr->din_xferp;
                ret =  blk_rq_map_user(q, next_rq, NULL, dxferp,
@@ -280,13 +279,9 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
                        goto out;
        }
 
-       rq->sense = sense;
-       rq->sense_len = 0;
-
        return rq;
 out:
-       if (rq->cmd != rq->__cmd)
-               kfree(rq->cmd);
+       scsi_req_free_cmd(scsi_req(rq));
        blk_put_request(rq);
        if (next_rq) {
                blk_rq_unmap_user(next_rq->bio);
@@ -393,6 +388,7 @@ static struct bsg_command *bsg_get_done_cmd(struct bsg_device *bd)
 static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
                                    struct bio *bio, struct bio *bidi_bio)
 {
+       struct scsi_request *req = scsi_req(rq);
        int ret = 0;
 
        dprintk("rq %p bio %p 0x%x\n", rq, bio, rq->errors);
@@ -407,12 +403,12 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
                hdr->info |= SG_INFO_CHECK;
        hdr->response_len = 0;
 
-       if (rq->sense_len && hdr->response) {
+       if (req->sense_len && hdr->response) {
                int len = min_t(unsigned int, hdr->max_response_len,
-                                       rq->sense_len);
+                                       req->sense_len);
 
                ret = copy_to_user((void __user *)(unsigned long)hdr->response,
-                                  rq->sense, len);
+                                  req->sense, len);
                if (!ret)
                        hdr->response_len = len;
                else
@@ -420,14 +416,14 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
        }
 
        if (rq->next_rq) {
-               hdr->dout_resid = rq->resid_len;
-               hdr->din_resid = rq->next_rq->resid_len;
+               hdr->dout_resid = req->resid_len;
+               hdr->din_resid = scsi_req(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->resid_len;
+               hdr->din_resid = req->resid_len;
        else
-               hdr->dout_resid = rq->resid_len;
+               hdr->dout_resid = req->resid_len;
 
        /*
         * If the request generated a negative error number, return it
@@ -439,8 +435,7 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
                ret = rq->errors;
 
        blk_rq_unmap_user(bio);
-       if (rq->cmd != rq->__cmd)
-               kfree(rq->cmd);
+       scsi_req_free_cmd(req);
        blk_put_request(rq);
 
        return ret;
@@ -578,7 +573,7 @@ bsg_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
        int ret;
        ssize_t bytes_read;
 
-       dprintk("%s: read %Zd bytes\n", bd->name, count);
+       dprintk("%s: read %zd bytes\n", bd->name, count);
 
        bsg_set_block(bd, file);
 
@@ -625,7 +620,7 @@ static int __bsg_write(struct bsg_device *bd, const char __user *buf,
                /*
                 * get a request, fill in the blanks, and add to request queue
                 */
-               rq = bsg_map_hdr(bd, &bc->hdr, has_write_perm, bc->sense);
+               rq = bsg_map_hdr(bd, &bc->hdr, has_write_perm);
                if (IS_ERR(rq)) {
                        ret = PTR_ERR(rq);
                        rq = NULL;
@@ -653,7 +648,7 @@ bsg_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
        ssize_t bytes_written;
        int ret;
 
-       dprintk("%s: write %Zd bytes\n", bd->name, count);
+       dprintk("%s: write %zd bytes\n", bd->name, count);
 
        if (unlikely(segment_eq(get_fs(), KERNEL_DS)))
                return -EINVAL;
@@ -672,7 +667,7 @@ bsg_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
        if (!bytes_written || err_block_err(ret))
                bytes_written = ret;
 
-       dprintk("%s: returning %Zd\n", bd->name, bytes_written);
+       dprintk("%s: returning %zd\n", bd->name, bytes_written);
        return bytes_written;
 }
 
@@ -911,12 +906,11 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                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)))
                        return -EFAULT;
 
-               rq = bsg_map_hdr(bd, &hdr, file->f_mode & FMODE_WRITE, sense);
+               rq = bsg_map_hdr(bd, &hdr, file->f_mode & FMODE_WRITE);
                if (IS_ERR(rq))
                        return PTR_ERR(rq);