diff options
author | Al Viro <al@aretha.pdmi.ras.ru> | 2008-09-18 15:53:24 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2008-10-21 07:49:10 -0400 |
commit | 45048d0961cdbf7ddfba906797ad8cb42489e070 (patch) | |
tree | d471933ccf9e8c52f608d0cef88de0569982a933 /block/ioctl.c | |
parent | e436fdae70a31102d2be32969b80fe8545edebd9 (diff) |
[PATCH] get rid of blkdev_locked_ioctl()
Most of that stuff doesn't need BKL at all; expand in the (only) caller,
merge the switch into one there and leave BKL only around the stuff that
might actually need it.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'block/ioctl.c')
-rw-r--r-- | block/ioctl.c | 142 |
1 files changed, 70 insertions, 72 deletions
diff --git a/block/ioctl.c b/block/ioctl.c index b4e0abed1b4b..bd214cb37f2b 100644 --- a/block/ioctl.c +++ b/block/ioctl.c | |||
@@ -201,70 +201,6 @@ static int put_u64(unsigned long arg, u64 val) | |||
201 | return put_user(val, (u64 __user *)arg); | 201 | return put_user(val, (u64 __user *)arg); |
202 | } | 202 | } |
203 | 203 | ||
204 | static int blkdev_locked_ioctl(struct file *file, struct block_device *bdev, | ||
205 | unsigned cmd, unsigned long arg) | ||
206 | { | ||
207 | struct backing_dev_info *bdi; | ||
208 | int ret, n; | ||
209 | |||
210 | switch (cmd) { | ||
211 | case BLKRAGET: | ||
212 | case BLKFRAGET: | ||
213 | if (!arg) | ||
214 | return -EINVAL; | ||
215 | bdi = blk_get_backing_dev_info(bdev); | ||
216 | if (bdi == NULL) | ||
217 | return -ENOTTY; | ||
218 | return put_long(arg, (bdi->ra_pages * PAGE_CACHE_SIZE) / 512); | ||
219 | case BLKROGET: | ||
220 | return put_int(arg, bdev_read_only(bdev) != 0); | ||
221 | case BLKBSZGET: /* get the logical block size (cf. BLKSSZGET) */ | ||
222 | return put_int(arg, block_size(bdev)); | ||
223 | case BLKSSZGET: /* get block device hardware sector size */ | ||
224 | return put_int(arg, bdev_hardsect_size(bdev)); | ||
225 | case BLKSECTGET: | ||
226 | return put_ushort(arg, bdev_get_queue(bdev)->max_sectors); | ||
227 | case BLKRASET: | ||
228 | case BLKFRASET: | ||
229 | if(!capable(CAP_SYS_ADMIN)) | ||
230 | return -EACCES; | ||
231 | bdi = blk_get_backing_dev_info(bdev); | ||
232 | if (bdi == NULL) | ||
233 | return -ENOTTY; | ||
234 | bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE; | ||
235 | return 0; | ||
236 | case BLKBSZSET: | ||
237 | /* set the logical block size */ | ||
238 | if (!capable(CAP_SYS_ADMIN)) | ||
239 | return -EACCES; | ||
240 | if (!arg) | ||
241 | return -EINVAL; | ||
242 | if (get_user(n, (int __user *) arg)) | ||
243 | return -EFAULT; | ||
244 | if (bd_claim(bdev, file) < 0) | ||
245 | return -EBUSY; | ||
246 | ret = set_blocksize(bdev, n); | ||
247 | bd_release(bdev); | ||
248 | return ret; | ||
249 | case BLKPG: | ||
250 | return blkpg_ioctl(bdev, (struct blkpg_ioctl_arg __user *) arg); | ||
251 | case BLKRRPART: | ||
252 | return blkdev_reread_part(bdev); | ||
253 | case BLKGETSIZE: | ||
254 | if ((bdev->bd_inode->i_size >> 9) > ~0UL) | ||
255 | return -EFBIG; | ||
256 | return put_ulong(arg, bdev->bd_inode->i_size >> 9); | ||
257 | case BLKGETSIZE64: | ||
258 | return put_u64(arg, bdev->bd_inode->i_size); | ||
259 | case BLKTRACESTART: | ||
260 | case BLKTRACESTOP: | ||
261 | case BLKTRACESETUP: | ||
262 | case BLKTRACETEARDOWN: | ||
263 | return blk_trace_ioctl(bdev, cmd, (char __user *) arg); | ||
264 | } | ||
265 | return -ENOIOCTLCMD; | ||
266 | } | ||
267 | |||
268 | int __blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, | 204 | int __blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, |
269 | unsigned cmd, unsigned long arg) | 205 | unsigned cmd, unsigned long arg) |
270 | { | 206 | { |
@@ -299,6 +235,8 @@ int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd, | |||
299 | { | 235 | { |
300 | struct block_device *bdev = inode->i_bdev; | 236 | struct block_device *bdev = inode->i_bdev; |
301 | struct gendisk *disk = bdev->bd_disk; | 237 | struct gendisk *disk = bdev->bd_disk; |
238 | struct backing_dev_info *bdi; | ||
239 | loff_t size; | ||
302 | int ret, n; | 240 | int ret, n; |
303 | fmode_t mode = 0; | 241 | fmode_t mode = 0; |
304 | if (file) { | 242 | if (file) { |
@@ -370,14 +308,74 @@ int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd, | |||
370 | return -EFAULT; | 308 | return -EFAULT; |
371 | return 0; | 309 | return 0; |
372 | } | 310 | } |
373 | } | 311 | case BLKRAGET: |
374 | 312 | case BLKFRAGET: | |
375 | lock_kernel(); | 313 | if (!arg) |
376 | ret = blkdev_locked_ioctl(file, bdev, cmd, arg); | 314 | return -EINVAL; |
377 | unlock_kernel(); | 315 | bdi = blk_get_backing_dev_info(bdev); |
378 | if (ret != -ENOIOCTLCMD) | 316 | if (bdi == NULL) |
317 | return -ENOTTY; | ||
318 | return put_long(arg, (bdi->ra_pages * PAGE_CACHE_SIZE) / 512); | ||
319 | case BLKROGET: | ||
320 | return put_int(arg, bdev_read_only(bdev) != 0); | ||
321 | case BLKBSZGET: /* get the logical block size (cf. BLKSSZGET) */ | ||
322 | return put_int(arg, block_size(bdev)); | ||
323 | case BLKSSZGET: /* get block device hardware sector size */ | ||
324 | return put_int(arg, bdev_hardsect_size(bdev)); | ||
325 | case BLKSECTGET: | ||
326 | return put_ushort(arg, bdev_get_queue(bdev)->max_sectors); | ||
327 | case BLKRASET: | ||
328 | case BLKFRASET: | ||
329 | if(!capable(CAP_SYS_ADMIN)) | ||
330 | return -EACCES; | ||
331 | bdi = blk_get_backing_dev_info(bdev); | ||
332 | if (bdi == NULL) | ||
333 | return -ENOTTY; | ||
334 | lock_kernel(); | ||
335 | bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE; | ||
336 | unlock_kernel(); | ||
337 | return 0; | ||
338 | case BLKBSZSET: | ||
339 | /* set the logical block size */ | ||
340 | if (!capable(CAP_SYS_ADMIN)) | ||
341 | return -EACCES; | ||
342 | if (!arg) | ||
343 | return -EINVAL; | ||
344 | if (get_user(n, (int __user *) arg)) | ||
345 | return -EFAULT; | ||
346 | if (bd_claim(bdev, file) < 0) | ||
347 | return -EBUSY; | ||
348 | ret = set_blocksize(bdev, n); | ||
349 | bd_release(bdev); | ||
379 | return ret; | 350 | return ret; |
380 | 351 | case BLKPG: | |
381 | ret = __blkdev_driver_ioctl(bdev, mode, cmd, arg); | 352 | lock_kernel(); |
353 | ret = blkpg_ioctl(bdev, (struct blkpg_ioctl_arg __user *) arg); | ||
354 | unlock_kernel(); | ||
355 | break; | ||
356 | case BLKRRPART: | ||
357 | lock_kernel(); | ||
358 | ret = blkdev_reread_part(bdev); | ||
359 | unlock_kernel(); | ||
360 | break; | ||
361 | case BLKGETSIZE: | ||
362 | size = bdev->bd_inode->i_size; | ||
363 | if ((size >> 9) > ~0UL) | ||
364 | return -EFBIG; | ||
365 | return put_ulong(arg, size >> 9); | ||
366 | case BLKGETSIZE64: | ||
367 | return put_u64(arg, bdev->bd_inode->i_size); | ||
368 | case BLKTRACESTART: | ||
369 | case BLKTRACESTOP: | ||
370 | case BLKTRACESETUP: | ||
371 | case BLKTRACETEARDOWN: | ||
372 | lock_kernel(); | ||
373 | ret = blk_trace_ioctl(bdev, cmd, (char __user *) arg); | ||
374 | unlock_kernel(); | ||
375 | break; | ||
376 | default: | ||
377 | ret = __blkdev_driver_ioctl(bdev, mode, cmd, arg); | ||
378 | } | ||
379 | return ret; | ||
382 | } | 380 | } |
383 | EXPORT_SYMBOL_GPL(blkdev_ioctl); | 381 | EXPORT_SYMBOL_GPL(blkdev_ioctl); |