Skip to content

Commit

Permalink
scsi: block: Remove the remaining SG_IO-related fields from struct re…
Browse files Browse the repository at this point in the history
…quest_queue

Move the sg_timeout and sg_reserved_size fields into the bsg_device and
scsi_device structures as they have nothing to do with generic block I/O.
Note that these values are now separate for bsg vs. SCSI device node
access, but that just matches how /dev/sg vs the other nodes has always
behaved.

Link: https://lore.kernel.org/r/20210729064845.1044147-4-hch@lst.de
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
  • Loading branch information
Christoph Hellwig authored and martinkpetersen committed Jul 31, 2021
1 parent cf93a27 commit 1e61c1a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 45 deletions.
2 changes: 0 additions & 2 deletions block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -3298,8 +3298,6 @@ int blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
set->map[HCTX_TYPE_POLL].nr_queues)
blk_queue_flag_set(QUEUE_FLAG_POLL, q);

q->sg_reserved_size = INT_MAX;

INIT_DELAYED_WORK(&q->requeue_work, blk_mq_requeue_work);
INIT_LIST_HEAD(&q->requeue_list);
spin_lock_init(&q->requeue_lock);
Expand Down
13 changes: 8 additions & 5 deletions block/bsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct bsg_device {
struct device device;
struct cdev cdev;
int max_queue;
unsigned int timeout;
unsigned int reserved_size;
};

static inline struct bsg_device *to_bsg_device(struct inode *inode)
Expand Down Expand Up @@ -71,7 +73,7 @@ static int bsg_sg_io(struct bsg_device *bd, fmode_t mode, void __user *uarg)

rq->timeout = msecs_to_jiffies(hdr.timeout);
if (!rq->timeout)
rq->timeout = rq->q->sg_timeout;
rq->timeout = bd->timeout;
if (!rq->timeout)
rq->timeout = BLK_DEFAULT_SG_TIMEOUT;
if (rq->timeout < BLK_MIN_SG_TIMEOUT)
Expand Down Expand Up @@ -161,19 +163,19 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
case SG_SET_TIMEOUT:
if (get_user(val, intp))
return -EFAULT;
q->sg_timeout = clock_t_to_jiffies(val);
bd->timeout = clock_t_to_jiffies(val);
return 0;
case SG_GET_TIMEOUT:
return jiffies_to_clock_t(q->sg_timeout);
return jiffies_to_clock_t(bd->timeout);
case SG_GET_RESERVED_SIZE:
return put_user(min(q->sg_reserved_size, queue_max_bytes(q)),
return put_user(min(bd->reserved_size, queue_max_bytes(q)),
intp);
case SG_SET_RESERVED_SIZE:
if (get_user(val, intp))
return -EFAULT;
if (val < 0)
return -EINVAL;
q->sg_reserved_size =
bd->reserved_size =
min_t(unsigned int, val, queue_max_bytes(q));
return 0;
case SG_EMULATED_HOST:
Expand Down Expand Up @@ -219,6 +221,7 @@ struct bsg_device *bsg_register_queue(struct request_queue *q,
if (!bd)
return ERR_PTR(-ENOMEM);
bd->max_queue = BSG_DEFAULT_CMDS;
bd->reserved_size = INT_MAX;
bd->queue = q;
bd->ops = ops;

Expand Down
63 changes: 30 additions & 33 deletions drivers/scsi/scsi_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,29 +173,25 @@ static int sg_get_version(int __user *p)
return put_user(sg_version_num, p);
}

static int sg_get_timeout(struct request_queue *q)
{
return jiffies_to_clock_t(q->sg_timeout);
}

static int sg_set_timeout(struct request_queue *q, int __user *p)
static int sg_set_timeout(struct scsi_device *sdev, int __user *p)
{
int timeout, err = get_user(timeout, p);

if (!err)
q->sg_timeout = clock_t_to_jiffies(timeout);
sdev->sg_timeout = clock_t_to_jiffies(timeout);

return err;
}

static int sg_get_reserved_size(struct request_queue *q, int __user *p)
static int sg_get_reserved_size(struct scsi_device *sdev, int __user *p)
{
int val = min(q->sg_reserved_size, queue_max_bytes(q));
int val = min(sdev->sg_reserved_size,
queue_max_bytes(sdev->request_queue));

return put_user(val, p);
}

static int sg_set_reserved_size(struct request_queue *q, int __user *p)
static int sg_set_reserved_size(struct scsi_device *sdev, int __user *p)
{
int size, err = get_user(size, p);

Expand All @@ -205,7 +201,8 @@ static int sg_set_reserved_size(struct request_queue *q, int __user *p)
if (size < 0)
return -EINVAL;

q->sg_reserved_size = min_t(unsigned int, size, queue_max_bytes(q));
sdev->sg_reserved_size = min_t(unsigned int, size,
queue_max_bytes(sdev->request_queue));
return 0;
}

Expand Down Expand Up @@ -345,7 +342,7 @@ bool scsi_cmd_allowed(unsigned char *cmd, fmode_t mode)
}
EXPORT_SYMBOL(scsi_cmd_allowed);

static int scsi_fill_sghdr_rq(struct request_queue *q, struct request *rq,
static int scsi_fill_sghdr_rq(struct scsi_device *sdev, struct request *rq,
struct sg_io_hdr *hdr, fmode_t mode)
{
struct scsi_request *req = scsi_req(rq);
Expand All @@ -362,7 +359,7 @@ static int scsi_fill_sghdr_rq(struct request_queue *q, struct request *rq,

rq->timeout = msecs_to_jiffies(hdr->timeout);
if (!rq->timeout)
rq->timeout = q->sg_timeout;
rq->timeout = sdev->sg_timeout;
if (!rq->timeout)
rq->timeout = BLK_DEFAULT_SG_TIMEOUT;
if (rq->timeout < BLK_MIN_SG_TIMEOUT)
Expand Down Expand Up @@ -409,7 +406,7 @@ static int scsi_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr,
return ret;
}

static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
static int sg_io(struct scsi_device *sdev, struct gendisk *disk,
struct sg_io_hdr *hdr, fmode_t mode)
{
unsigned long start_time;
Expand All @@ -423,7 +420,7 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
if (hdr->interface_id != 'S')
return -EINVAL;

if (hdr->dxfer_len > (queue_max_hw_sectors(q) << 9))
if (hdr->dxfer_len > (queue_max_hw_sectors(sdev->request_queue) << 9))
return -EIO;

if (hdr->dxfer_len)
Expand All @@ -441,7 +438,8 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
at_head = 1;

ret = -ENOMEM;
rq = blk_get_request(q, writing ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0);
rq = blk_get_request(sdev->request_queue, writing ?
REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0);
if (IS_ERR(rq))
return PTR_ERR(rq);
req = scsi_req(rq);
Expand All @@ -452,7 +450,7 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
goto out_put_request;
}

ret = scsi_fill_sghdr_rq(q, rq, hdr, mode);
ret = scsi_fill_sghdr_rq(sdev, rq, hdr, mode);
if (ret < 0)
goto out_free_cdb;

Expand All @@ -469,11 +467,11 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
/* SG_IO howto says that the shorter of the two wins */
iov_iter_truncate(&i, hdr->dxfer_len);

ret = blk_rq_map_user_iov(q, rq, NULL, &i, GFP_KERNEL);
ret = blk_rq_map_user_iov(rq->q, rq, NULL, &i, GFP_KERNEL);
kfree(iov);
} else if (hdr->dxfer_len)
ret = blk_rq_map_user(q, rq, NULL, hdr->dxferp, hdr->dxfer_len,
GFP_KERNEL);
ret = blk_rq_map_user(rq->q, rq, NULL, hdr->dxferp,
hdr->dxfer_len, GFP_KERNEL);

if (ret)
goto out_free_cdb;
Expand All @@ -483,7 +481,7 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,

start_time = jiffies;

blk_execute_rq(bd_disk, rq, at_head);
blk_execute_rq(disk, rq, at_head);

hdr->duration = jiffies_to_msecs(jiffies - start_time);

Expand Down Expand Up @@ -806,9 +804,8 @@ static int scsi_put_cdrom_generic_arg(const struct cdrom_generic_command *cgc,
return 0;
}

static int scsi_cdrom_send_packet(struct request_queue *q,
struct gendisk *bd_disk,
fmode_t mode, void __user *arg)
static int scsi_cdrom_send_packet(struct scsi_device *sdev, struct gendisk *disk,
fmode_t mode, void __user *arg)
{
struct cdrom_generic_command cgc;
struct sg_io_hdr hdr;
Expand Down Expand Up @@ -848,7 +845,7 @@ static int scsi_cdrom_send_packet(struct request_queue *q,
hdr.cmdp = ((struct cdrom_generic_command __user *) arg)->cmd;
hdr.cmd_len = sizeof(cgc.cmd);

err = sg_io(q, bd_disk, &hdr, mode);
err = sg_io(sdev, disk, &hdr, mode);
if (err == -EFAULT)
return -EFAULT;

Expand All @@ -863,7 +860,7 @@ static int scsi_cdrom_send_packet(struct request_queue *q,
return err;
}

static int scsi_ioctl_sg_io(struct request_queue *q, struct gendisk *disk,
static int scsi_ioctl_sg_io(struct scsi_device *sdev, struct gendisk *disk,
fmode_t mode, void __user *argp)
{
struct sg_io_hdr hdr;
Expand All @@ -872,7 +869,7 @@ static int scsi_ioctl_sg_io(struct request_queue *q, struct gendisk *disk,
error = get_sg_io_hdr(&hdr, argp);
if (error)
return error;
error = sg_io(q, disk, &hdr, mode);
error = sg_io(sdev, disk, &hdr, mode);
if (error == -EFAULT)
return error;
if (put_sg_io_hdr(&hdr, argp))
Expand Down Expand Up @@ -918,21 +915,21 @@ int scsi_ioctl(struct scsi_device *sdev, struct gendisk *disk, fmode_t mode,
case SG_GET_VERSION_NUM:
return sg_get_version(arg);
case SG_SET_TIMEOUT:
return sg_set_timeout(q, arg);
return sg_set_timeout(sdev, arg);
case SG_GET_TIMEOUT:
return sg_get_timeout(q);
return jiffies_to_clock_t(sdev->sg_timeout);
case SG_GET_RESERVED_SIZE:
return sg_get_reserved_size(q, arg);
return sg_get_reserved_size(sdev, arg);
case SG_SET_RESERVED_SIZE:
return sg_set_reserved_size(q, arg);
return sg_set_reserved_size(sdev, arg);
case SG_EMULATED_HOST:
return sg_emulated_host(q, arg);
case SG_IO:
return scsi_ioctl_sg_io(q, disk, mode, arg);
return scsi_ioctl_sg_io(sdev, disk, mode, arg);
case SCSI_IOCTL_SEND_COMMAND:
return sg_scsi_ioctl(q, disk, mode, arg);
case CDROM_SEND_PACKET:
return scsi_cdrom_send_packet(q, disk, mode, arg);
return scsi_cdrom_send_packet(sdev, disk, mode, arg);
case CDROMCLOSETRAY:
return scsi_send_start_stop(sdev, 3);
case CDROMEJECT:
Expand Down
2 changes: 2 additions & 0 deletions drivers/scsi/scsi_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
*/
sdev->borken = 1;

sdev->sg_reserved_size = INT_MAX;

q = blk_mq_init_queue(&sdev->host->tag_set);
if (IS_ERR(q)) {
/* release fn is set up in scsi_sysfs_device_initialise, so
Expand Down
5 changes: 0 additions & 5 deletions include/linux/blkdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,6 @@ struct request_queue {
unsigned int max_active_zones;
#endif /* CONFIG_BLK_DEV_ZONED */

/*
* sg stuff
*/
unsigned int sg_timeout;
unsigned int sg_reserved_size;
int node;
struct mutex debugfs_mutex;
#ifdef CONFIG_BLK_DEV_IO_TRACE
Expand Down
3 changes: 3 additions & 0 deletions include/scsi/scsi_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ struct scsi_device {
size_t dma_drain_len;
void *dma_drain_buf;

unsigned int sg_timeout;
unsigned int sg_reserved_size;

struct bsg_device *bsg_dev;
unsigned char access_state;
struct mutex state_mutex;
Expand Down

0 comments on commit 1e61c1a

Please sign in to comment.