dm snapshot: style cleanups
[linux-2.6.git] / block / ioctl.c
index 1cfa8d4..1124cd2 100644 (file)
@@ -5,7 +5,6 @@
 #include <linux/hdreg.h>
 #include <linux/backing-dev.h>
 #include <linux/buffer_head.h>
-#include <linux/smp_lock.h>
 #include <linux/blktrace_api.h>
 #include <asm/uaccess.h>
 
@@ -62,7 +61,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
 
                        /* all seems OK */
                        part = add_partition(disk, partno, start, length,
-                                            ADDPART_FLAG_NONE);
+                                            ADDPART_FLAG_NONE, NULL);
                        mutex_unlock(&bdev->bd_mutex);
                        return IS_ERR(part) ? PTR_ERR(part) : 0;
                case BLKPG_DEL_PARTITION:
@@ -114,8 +113,10 @@ static int blkdev_reread_part(struct block_device *bdev)
 }
 
 static int blk_ioctl_discard(struct block_device *bdev, uint64_t start,
-                            uint64_t len)
+                            uint64_t len, int secure)
 {
+       unsigned long flags = 0;
+
        if (start & 511)
                return -EINVAL;
        if (len & 511)
@@ -123,10 +124,11 @@ static int blk_ioctl_discard(struct block_device *bdev, uint64_t start,
        start >>= 9;
        len >>= 9;
 
-       if (start + len > (bdev->bd_inode->i_size >> 9))
+       if (start + len > (i_size_read(bdev->bd_inode) >> 9))
                return -EINVAL;
-       return blkdev_issue_discard(bdev, start, len, GFP_KERNEL,
-                                   BLKDEV_IFL_WAIT);
+       if (secure)
+               flags |= BLKDEV_DISCARD_SECURE;
+       return blkdev_issue_discard(bdev, start, len, GFP_KERNEL, flags);
 }
 
 static int put_ushort(unsigned long arg, unsigned short val)
@@ -197,10 +199,8 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
                if (ret != -EINVAL && ret != -ENOTTY)
                        return ret;
 
-               lock_kernel();
                fsync_bdev(bdev);
                invalidate_bdev(bdev);
-               unlock_kernel();
                return 0;
 
        case BLKROSET:
@@ -212,12 +212,11 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
                        return -EACCES;
                if (get_user(n, (int __user *)(arg)))
                        return -EFAULT;
-               lock_kernel();
                set_device_ro(bdev, n);
-               unlock_kernel();
                return 0;
 
-       case BLKDISCARD: {
+       case BLKDISCARD:
+       case BLKSECDISCARD: {
                uint64_t range[2];
 
                if (!(mode & FMODE_WRITE))
@@ -226,7 +225,8 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
                if (copy_from_user(range, (void __user *)arg, sizeof(range)))
                        return -EFAULT;
 
-               return blk_ioctl_discard(bdev, range[0], range[1]);
+               return blk_ioctl_discard(bdev, range[0], range[1],
+                                        cmd == BLKSECDISCARD);
        }
 
        case HDIO_GETGEO: {
@@ -241,6 +241,7 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
                 * We need to set the startsect first, the driver may
                 * want to override it.
                 */
+               memset(&geo, 0, sizeof(geo));
                geo.start = get_start_sect(bdev);
                ret = disk->fops->getgeo(bdev, &geo);
                if (ret)
@@ -293,36 +294,33 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
                        return -EINVAL;
                if (get_user(n, (int __user *) arg))
                        return -EFAULT;
-               if (!(mode & FMODE_EXCL) && bd_claim(bdev, &bdev) < 0)
-                       return -EBUSY;
+               if (!(mode & FMODE_EXCL)) {
+                       bdgrab(bdev);
+                       if (blkdev_get(bdev, mode | FMODE_EXCL, &bdev) < 0)
+                               return -EBUSY;
+               }
                ret = set_blocksize(bdev, n);
                if (!(mode & FMODE_EXCL))
-                       bd_release(bdev);
+                       blkdev_put(bdev, mode | FMODE_EXCL);
                return ret;
        case BLKPG:
-               lock_kernel();
                ret = blkpg_ioctl(bdev, (struct blkpg_ioctl_arg __user *) arg);
-               unlock_kernel();
                break;
        case BLKRRPART:
-               lock_kernel();
                ret = blkdev_reread_part(bdev);
-               unlock_kernel();
                break;
        case BLKGETSIZE:
-               size = bdev->bd_inode->i_size;
+               size = i_size_read(bdev->bd_inode);
                if ((size >> 9) > ~0UL)
                        return -EFBIG;
                return put_ulong(arg, size >> 9);
        case BLKGETSIZE64:
-               return put_u64(arg, bdev->bd_inode->i_size);
+               return put_u64(arg, i_size_read(bdev->bd_inode));
        case BLKTRACESTART:
        case BLKTRACESTOP:
        case BLKTRACESETUP:
        case BLKTRACETEARDOWN:
-               lock_kernel();
                ret = blk_trace_ioctl(bdev, cmd, (char __user *) arg);
-               unlock_kernel();
                break;
        default:
                ret = __blkdev_driver_ioctl(bdev, mode, cmd, arg);