Skip to content

Commit 633a08b

Browse files
author
Al Viro
committed
[PATCH] introduce __blkdev_driver_ioctl()
Analog of blkdev_driver_ioctl() with sane arguments. For now uses fake struct file, by the end of the series it won't and blkdev_driver_ioctl() will become a wrapper around it. Signed-off-by: Al Viro <[email protected]>
1 parent a0eb62a commit 633a08b

File tree

5 files changed

+39
-19
lines changed

5 files changed

+39
-19
lines changed

block/ioctl.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,37 @@ int blkdev_driver_ioctl(struct inode *inode, struct file *file,
283283
}
284284
EXPORT_SYMBOL_GPL(blkdev_driver_ioctl);
285285

286+
int __blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode,
287+
unsigned cmd, unsigned long arg)
288+
{
289+
struct gendisk *disk = bdev->bd_disk;
290+
int ret;
291+
/* you bet it'll go away by the end of patch series */
292+
struct file fake_file = {};
293+
struct dentry fake_dentry = {};
294+
fake_file.f_mode = mode;
295+
fake_file.f_path.dentry = &fake_dentry;
296+
fake_dentry.d_inode = bdev->bd_inode;
297+
298+
if (disk->fops->unlocked_ioctl)
299+
return disk->fops->unlocked_ioctl(&fake_file, cmd, arg);
300+
301+
if (disk->fops->ioctl) {
302+
lock_kernel();
303+
ret = disk->fops->ioctl(bdev->bd_inode, &fake_file, cmd, arg);
304+
unlock_kernel();
305+
return ret;
306+
}
307+
308+
return -ENOTTY;
309+
}
310+
/*
311+
* For the record: _GPL here is only because somebody decided to slap it
312+
* on the previous export. Sheer idiocy, since it wasn't copyrightable
313+
* at all and could be open-coded without any exports by anybody who cares.
314+
*/
315+
EXPORT_SYMBOL_GPL(__blkdev_driver_ioctl);
316+
286317
/*
287318
* always keep this in sync with compat_blkdev_ioctl() and
288319
* compat_blkdev_locked_ioctl()

drivers/block/pktcdvd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2819,8 +2819,8 @@ static int pkt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u
28192819
case CDROM_LAST_WRITTEN:
28202820
case CDROM_SEND_PACKET:
28212821
case SCSI_IOCTL_SEND_COMMAND:
2822-
return blkdev_driver_ioctl(pd->bdev->bd_inode, pd->bdev->bd_disk,
2823-
file, cmd, arg);
2822+
return __blkdev_driver_ioctl(pd->bdev, file ? file->f_mode : 0,
2823+
cmd, arg);
28242824

28252825
default:
28262826
VPRINTK(DRIVER_NAME": Unknown ioctl for %s (%x)\n", pd->name, cmd);

drivers/md/dm-linear.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,7 @@ static int linear_ioctl(struct dm_target *ti, unsigned int cmd,
114114
unsigned long arg)
115115
{
116116
struct linear_c *lc = (struct linear_c *) ti->private;
117-
struct block_device *bdev = lc->dev->bdev;
118-
struct file fake_file = {};
119-
struct dentry fake_dentry = {};
120-
121-
fake_file.f_mode = lc->dev->mode;
122-
fake_file.f_path.dentry = &fake_dentry;
123-
fake_dentry.d_inode = bdev->bd_inode;
124-
125-
return blkdev_driver_ioctl(bdev->bd_inode, &fake_file, bdev->bd_disk, cmd, arg);
117+
return __blkdev_driver_ioctl(lc->dev->bdev, lc->dev->mode, cmd, arg);
126118
}
127119

128120
static int linear_merge(struct dm_target *ti, struct bvec_merge_data *bvm,

drivers/md/dm-mpath.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,22 +1400,18 @@ static int multipath_ioctl(struct dm_target *ti, unsigned int cmd,
14001400
{
14011401
struct multipath *m = (struct multipath *) ti->private;
14021402
struct block_device *bdev = NULL;
1403+
fmode_t mode = 0;
14031404
unsigned long flags;
1404-
struct file fake_file = {};
1405-
struct dentry fake_dentry = {};
14061405
int r = 0;
14071406

1408-
fake_file.f_path.dentry = &fake_dentry;
1409-
14101407
spin_lock_irqsave(&m->lock, flags);
14111408

14121409
if (!m->current_pgpath)
14131410
__choose_pgpath(m);
14141411

14151412
if (m->current_pgpath) {
14161413
bdev = m->current_pgpath->path.dev->bdev;
1417-
fake_dentry.d_inode = bdev->bd_inode;
1418-
fake_file.f_mode = m->current_pgpath->path.dev->mode;
1414+
mode = m->current_pgpath->path.dev->mode;
14191415
}
14201416

14211417
if (m->queue_io)
@@ -1425,8 +1421,7 @@ static int multipath_ioctl(struct dm_target *ti, unsigned int cmd,
14251421

14261422
spin_unlock_irqrestore(&m->lock, flags);
14271423

1428-
return r ? : blkdev_driver_ioctl(bdev->bd_inode, &fake_file,
1429-
bdev->bd_disk, cmd, arg);
1424+
return r ? : __blkdev_driver_ioctl(bdev, mode, cmd, arg);
14301425
}
14311426

14321427
/*-----------------------------------------------------------------

include/linux/blkdev.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,8 @@ struct block_device_operations {
10741074
struct module *owner;
10751075
};
10761076

1077+
extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
1078+
unsigned long);
10771079
#else /* CONFIG_BLOCK */
10781080
/*
10791081
* stubs for when the block layer is configured out

0 commit comments

Comments
 (0)