Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * File...........: linux/drivers/s390/block/dasd_ioctl.c |
| 3 | * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com> |
| 4 | * Horst Hummel <Horst.Hummel@de.ibm.com> |
| 5 | * Carsten Otte <Cotte@de.ibm.com> |
| 6 | * Martin Schwidefsky <schwidefsky@de.ibm.com> |
| 7 | * Bugreports.to..: <Linux390@de.ibm.com> |
| 8 | * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001 |
| 9 | * |
| 10 | * i/o controls for the dasd driver. |
| 11 | */ |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 12 | |
| 13 | #define KMSG_COMPONENT "dasd" |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/interrupt.h> |
Heiko Carstens | 048cd4e | 2012-02-27 10:01:52 +0100 | [diff] [blame^] | 16 | #include <linux/compat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/major.h> |
| 18 | #include <linux/fs.h> |
| 19 | #include <linux/blkpg.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Heiko Carstens | 8803486 | 2010-01-13 20:44:29 +0100 | [diff] [blame] | 21 | #include <asm/compat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <asm/ccwdev.h> |
Christoph Hellwig | 8b2eb66 | 2006-03-24 03:15:21 -0800 | [diff] [blame] | 23 | #include <asm/cmb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/uaccess.h> |
| 25 | |
| 26 | /* This is ugly... */ |
| 27 | #define PRINTK_HEADER "dasd_ioctl:" |
| 28 | |
| 29 | #include "dasd_int.h" |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | static int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 33 | dasd_ioctl_api_version(void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
| 35 | int ver = DASD_API_VERSION; |
Bastian Blank | b502962 | 2006-03-24 03:15:32 -0800 | [diff] [blame] | 36 | return put_user(ver, (int __user *)argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | /* |
| 40 | * Enable device. |
| 41 | * used by dasdfmt after BIODASDDISABLE to retrigger blocksize detection |
| 42 | */ |
| 43 | static int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 44 | dasd_ioctl_enable(struct block_device *bdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 46 | struct dasd_device *base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | if (!capable(CAP_SYS_ADMIN)) |
| 49 | return -EACCES; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 50 | |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 51 | base = dasd_device_from_gendisk(bdev->bd_disk); |
| 52 | if (!base) |
| 53 | return -ENODEV; |
| 54 | |
| 55 | dasd_enable_device(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /* Formatting the dasd device can change the capacity. */ |
Arjan van de Ven | c039e31 | 2006-03-23 03:00:28 -0800 | [diff] [blame] | 57 | mutex_lock(&bdev->bd_mutex); |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 58 | i_size_write(bdev->bd_inode, |
| 59 | (loff_t)get_capacity(base->block->gdp) << 9); |
Arjan van de Ven | c039e31 | 2006-03-23 03:00:28 -0800 | [diff] [blame] | 60 | mutex_unlock(&bdev->bd_mutex); |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 61 | dasd_put_device(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * Disable device. |
| 67 | * Used by dasdfmt. Disable I/O operations but allow ioctls. |
| 68 | */ |
| 69 | static int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 70 | dasd_ioctl_disable(struct block_device *bdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 72 | struct dasd_device *base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | if (!capable(CAP_SYS_ADMIN)) |
| 75 | return -EACCES; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 76 | |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 77 | base = dasd_device_from_gendisk(bdev->bd_disk); |
| 78 | if (!base) |
| 79 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | /* |
| 81 | * Man this is sick. We don't do a real disable but only downgrade |
| 82 | * the device to DASD_STATE_BASIC. The reason is that dasdfmt uses |
| 83 | * BIODASDDISABLE to disable accesses to the device via the block |
| 84 | * device layer but it still wants to do i/o on the device by |
| 85 | * using the BIODASDFMT ioctl. Therefore the correct state for the |
| 86 | * device is DASD_STATE_BASIC that allows to do basic i/o. |
| 87 | */ |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 88 | dasd_set_target_state(base, DASD_STATE_BASIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /* |
| 90 | * Set i_size to zero, since read, write, etc. check against this |
| 91 | * value. |
| 92 | */ |
Arjan van de Ven | c039e31 | 2006-03-23 03:00:28 -0800 | [diff] [blame] | 93 | mutex_lock(&bdev->bd_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | i_size_write(bdev->bd_inode, 0); |
Arjan van de Ven | c039e31 | 2006-03-23 03:00:28 -0800 | [diff] [blame] | 95 | mutex_unlock(&bdev->bd_mutex); |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 96 | dasd_put_device(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | /* |
| 101 | * Quiesce device. |
| 102 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 103 | static int dasd_ioctl_quiesce(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | unsigned long flags; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 106 | struct dasd_device *base; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 107 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 108 | base = block->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | if (!capable (CAP_SYS_ADMIN)) |
| 110 | return -EACCES; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 111 | |
Stefan Haberland | ca99dab | 2009-09-11 10:28:30 +0200 | [diff] [blame] | 112 | pr_info("%s: The DASD has been put in the quiesce " |
| 113 | "state\n", dev_name(&base->cdev->dev)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 114 | spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags); |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 115 | dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 116 | spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | |
| 121 | /* |
Stefan Haberland | fc19f38 | 2009-03-26 15:23:49 +0100 | [diff] [blame] | 122 | * Resume device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 124 | static int dasd_ioctl_resume(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | unsigned long flags; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 127 | struct dasd_device *base; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 128 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 129 | base = block->base; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 130 | if (!capable (CAP_SYS_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | return -EACCES; |
| 132 | |
Stefan Haberland | ca99dab | 2009-09-11 10:28:30 +0200 | [diff] [blame] | 133 | pr_info("%s: I/O operations have been resumed " |
| 134 | "on the DASD\n", dev_name(&base->cdev->dev)); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 135 | spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags); |
Stefan Weinhuber | eb6e199 | 2009-12-07 12:51:51 +0100 | [diff] [blame] | 136 | dasd_device_remove_stop_bits(base, DASD_STOPPED_QUIESCE); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 137 | spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags); |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 138 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 139 | dasd_schedule_block_bh(block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * performs formatting of _device_ according to _fdata_ |
| 145 | * Note: The discipline's format_function is assumed to deliver formatting |
| 146 | * commands to format a single unit of the device. In terms of the ECKD |
| 147 | * devices this means CCWs are generated to format a single track. |
| 148 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 149 | static int dasd_format(struct dasd_block *block, struct format_data_t *fdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
| 151 | struct dasd_ccw_req *cqr; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 152 | struct dasd_device *base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | int rc; |
| 154 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 155 | base = block->base; |
| 156 | if (base->discipline->format_device == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | return -EPERM; |
| 158 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 159 | if (base->state != DASD_STATE_BASIC) { |
Stefan Haberland | ca99dab | 2009-09-11 10:28:30 +0200 | [diff] [blame] | 160 | pr_warning("%s: The DASD cannot be formatted while it is " |
| 161 | "enabled\n", dev_name(&base->cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | return -EBUSY; |
| 163 | } |
| 164 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 165 | DBF_DEV_EVENT(DBF_NOTICE, base, |
Stefan Weinhuber | b44b0ab3 | 2009-03-26 15:23:47 +0100 | [diff] [blame] | 166 | "formatting units %u to %u (%u B blocks) flags %u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | fdata->start_unit, |
| 168 | fdata->stop_unit, fdata->blksize, fdata->intensity); |
| 169 | |
| 170 | /* Since dasdfmt keeps the device open after it was disabled, |
| 171 | * there still exists an inode for this device. |
| 172 | * We must update i_blkbits, otherwise we might get errors when |
| 173 | * enabling the device later. |
| 174 | */ |
| 175 | if (fdata->start_unit == 0) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 176 | struct block_device *bdev = bdget_disk(block->gdp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | bdev->bd_inode->i_blkbits = blksize_bits(fdata->blksize); |
| 178 | bdput(bdev); |
| 179 | } |
| 180 | |
| 181 | while (fdata->start_unit <= fdata->stop_unit) { |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 182 | cqr = base->discipline->format_device(base, fdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | if (IS_ERR(cqr)) |
| 184 | return PTR_ERR(cqr); |
| 185 | rc = dasd_sleep_on_interruptible(cqr); |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 186 | dasd_sfree_request(cqr, cqr->memdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | if (rc) { |
| 188 | if (rc != -ERESTARTSYS) |
Stefan Haberland | ca99dab | 2009-09-11 10:28:30 +0200 | [diff] [blame] | 189 | pr_err("%s: Formatting unit %d failed with " |
| 190 | "rc=%d\n", dev_name(&base->cdev->dev), |
| 191 | fdata->start_unit, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | return rc; |
| 193 | } |
| 194 | fdata->start_unit++; |
| 195 | } |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | /* |
| 200 | * Format device. |
| 201 | */ |
| 202 | static int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 203 | dasd_ioctl_format(struct block_device *bdev, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | { |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 205 | struct dasd_device *base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | struct format_data_t fdata; |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 207 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | if (!capable(CAP_SYS_ADMIN)) |
| 210 | return -EACCES; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 211 | if (!argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | return -EINVAL; |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 213 | base = dasd_device_from_gendisk(bdev->bd_disk); |
| 214 | if (!base) |
| 215 | return -ENODEV; |
| 216 | if (base->features & DASD_FEATURE_READONLY || |
| 217 | test_bit(DASD_FLAG_DEVICE_RO, &base->flags)) { |
| 218 | dasd_put_device(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | return -EROFS; |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 220 | } |
| 221 | if (copy_from_user(&fdata, argp, sizeof(struct format_data_t))) { |
| 222 | dasd_put_device(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | return -EFAULT; |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 224 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | if (bdev != bdev->bd_contains) { |
Stefan Haberland | ca99dab | 2009-09-11 10:28:30 +0200 | [diff] [blame] | 226 | pr_warning("%s: The specified DASD is a partition and cannot " |
| 227 | "be formatted\n", |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 228 | dev_name(&base->cdev->dev)); |
| 229 | dasd_put_device(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | return -EINVAL; |
| 231 | } |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 232 | rc = dasd_format(base->block, &fdata); |
| 233 | dasd_put_device(base); |
| 234 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | #ifdef CONFIG_DASD_PROFILE |
| 238 | /* |
| 239 | * Reset device profile information |
| 240 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 241 | static int dasd_ioctl_reset_profile(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 243 | dasd_profile_reset(&block->profile); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | /* |
| 248 | * Return device profile information |
| 249 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 250 | static int dasd_ioctl_read_profile(struct dasd_block *block, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | { |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 252 | struct dasd_profile_info_t *data; |
Julia Lawall | ba465d8 | 2011-08-24 17:15:10 +0200 | [diff] [blame] | 253 | int rc = 0; |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 254 | |
| 255 | data = kmalloc(sizeof(*data), GFP_KERNEL); |
| 256 | if (!data) |
| 257 | return -ENOMEM; |
| 258 | |
| 259 | spin_lock_bh(&block->profile.lock); |
| 260 | if (block->profile.data) { |
| 261 | data->dasd_io_reqs = block->profile.data->dasd_io_reqs; |
| 262 | data->dasd_io_sects = block->profile.data->dasd_io_sects; |
| 263 | memcpy(data->dasd_io_secs, block->profile.data->dasd_io_secs, |
| 264 | sizeof(data->dasd_io_secs)); |
| 265 | memcpy(data->dasd_io_times, block->profile.data->dasd_io_times, |
| 266 | sizeof(data->dasd_io_times)); |
| 267 | memcpy(data->dasd_io_timps, block->profile.data->dasd_io_timps, |
| 268 | sizeof(data->dasd_io_timps)); |
| 269 | memcpy(data->dasd_io_time1, block->profile.data->dasd_io_time1, |
| 270 | sizeof(data->dasd_io_time1)); |
| 271 | memcpy(data->dasd_io_time2, block->profile.data->dasd_io_time2, |
| 272 | sizeof(data->dasd_io_time2)); |
| 273 | memcpy(data->dasd_io_time2ps, |
| 274 | block->profile.data->dasd_io_time2ps, |
| 275 | sizeof(data->dasd_io_time2ps)); |
| 276 | memcpy(data->dasd_io_time3, block->profile.data->dasd_io_time3, |
| 277 | sizeof(data->dasd_io_time3)); |
| 278 | memcpy(data->dasd_io_nr_req, |
| 279 | block->profile.data->dasd_io_nr_req, |
| 280 | sizeof(data->dasd_io_nr_req)); |
| 281 | spin_unlock_bh(&block->profile.lock); |
| 282 | } else { |
| 283 | spin_unlock_bh(&block->profile.lock); |
Julia Lawall | ba465d8 | 2011-08-24 17:15:10 +0200 | [diff] [blame] | 284 | rc = -EIO; |
| 285 | goto out; |
Stefan Weinhuber | 4fa52aa | 2011-07-24 10:48:32 +0200 | [diff] [blame] | 286 | } |
| 287 | if (copy_to_user(argp, data, sizeof(*data))) |
Julia Lawall | ba465d8 | 2011-08-24 17:15:10 +0200 | [diff] [blame] | 288 | rc = -EFAULT; |
| 289 | out: |
| 290 | kfree(data); |
| 291 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | } |
| 293 | #else |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 294 | static int dasd_ioctl_reset_profile(struct dasd_block *block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | { |
| 296 | return -ENOSYS; |
| 297 | } |
| 298 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 299 | static int dasd_ioctl_read_profile(struct dasd_block *block, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | { |
| 301 | return -ENOSYS; |
| 302 | } |
| 303 | #endif |
| 304 | |
| 305 | /* |
| 306 | * Return dasd information. Used for BIODASDINFO and BIODASDINFO2. |
| 307 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 308 | static int dasd_ioctl_information(struct dasd_block *block, |
| 309 | unsigned int cmd, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | struct dasd_information2_t *dasd_info; |
| 312 | unsigned long flags; |
Horst Hummel | c6eb7b7 | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 313 | int rc; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 314 | struct dasd_device *base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | struct ccw_device *cdev; |
Cornelia Huck | 9a92fe4 | 2007-05-10 15:45:42 +0200 | [diff] [blame] | 316 | struct ccw_dev_id dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 318 | base = block->base; |
Stefan Haberland | 294001a | 2010-01-27 10:12:35 +0100 | [diff] [blame] | 319 | if (!base->discipline || !base->discipline->fill_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | return -EINVAL; |
| 321 | |
Horst Hummel | 554a826 | 2006-03-24 03:15:24 -0800 | [diff] [blame] | 322 | dasd_info = kzalloc(sizeof(struct dasd_information2_t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | if (dasd_info == NULL) |
| 324 | return -ENOMEM; |
| 325 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 326 | rc = base->discipline->fill_info(base, dasd_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | if (rc) { |
| 328 | kfree(dasd_info); |
| 329 | return rc; |
| 330 | } |
| 331 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 332 | cdev = base->cdev; |
Cornelia Huck | 9a92fe4 | 2007-05-10 15:45:42 +0200 | [diff] [blame] | 333 | ccw_device_get_id(cdev, &dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
Cornelia Huck | 9a92fe4 | 2007-05-10 15:45:42 +0200 | [diff] [blame] | 335 | dasd_info->devno = dev_id.devno; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 336 | dasd_info->schid = _ccw_device_get_subchannel_number(base->cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | dasd_info->cu_type = cdev->id.cu_type; |
| 338 | dasd_info->cu_model = cdev->id.cu_model; |
| 339 | dasd_info->dev_type = cdev->id.dev_type; |
| 340 | dasd_info->dev_model = cdev->id.dev_model; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 341 | dasd_info->status = base->state; |
Horst Hummel | 5746719 | 2006-02-01 03:06:36 -0800 | [diff] [blame] | 342 | /* |
| 343 | * The open_count is increased for every opener, that includes |
| 344 | * the blkdev_get in dasd_scan_partitions. |
| 345 | * This must be hidden from user-space. |
| 346 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 347 | dasd_info->open_count = atomic_read(&block->open_count); |
| 348 | if (!block->bdev) |
Horst Hummel | 5746719 | 2006-02-01 03:06:36 -0800 | [diff] [blame] | 349 | dasd_info->open_count++; |
Horst Hummel | 138c014 | 2006-06-29 14:58:12 +0200 | [diff] [blame] | 350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | /* |
| 352 | * check if device is really formatted |
| 353 | * LDL / CDL was returned by 'fill_info' |
| 354 | */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 355 | if ((base->state < DASD_STATE_READY) || |
| 356 | (dasd_check_blocksize(block->bp_block))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | dasd_info->format = DASD_FORMAT_NONE; |
Horst Hummel | f24acd4 | 2005-05-01 08:58:59 -0700 | [diff] [blame] | 358 | |
Horst Hummel | c6eb7b7 | 2005-09-03 15:57:58 -0700 | [diff] [blame] | 359 | dasd_info->features |= |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 360 | ((base->features & DASD_FEATURE_READONLY) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
Stefan Haberland | 294001a | 2010-01-27 10:12:35 +0100 | [diff] [blame] | 362 | memcpy(dasd_info->type, base->discipline->name, 4); |
Horst Hummel | 554a826 | 2006-03-24 03:15:24 -0800 | [diff] [blame] | 363 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 364 | if (block->request_queue->request_fn) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | struct list_head *l; |
| 366 | #ifdef DASD_EXTENDED_PROFILING |
| 367 | { |
| 368 | struct list_head *l; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 369 | spin_lock_irqsave(&block->lock, flags); |
| 370 | list_for_each(l, &block->request_queue->queue_head) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | dasd_info->req_queue_len++; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 372 | spin_unlock_irqrestore(&block->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
| 374 | #endif /* DASD_EXTENDED_PROFILING */ |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 375 | spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags); |
| 376 | list_for_each(l, &base->ccw_queue) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | dasd_info->chanq_len++; |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 378 | spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | flags); |
| 380 | } |
| 381 | |
| 382 | rc = 0; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 383 | if (copy_to_user(argp, dasd_info, |
| 384 | ((cmd == (unsigned int) BIODASDINFO2) ? |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 385 | sizeof(struct dasd_information2_t) : |
| 386 | sizeof(struct dasd_information_t)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | rc = -EFAULT; |
| 388 | kfree(dasd_info); |
| 389 | return rc; |
| 390 | } |
| 391 | |
| 392 | /* |
| 393 | * Set read only |
| 394 | */ |
| 395 | static int |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 396 | dasd_ioctl_set_ro(struct block_device *bdev, void __user *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | { |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 398 | struct dasd_device *base; |
| 399 | int intval, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
| 401 | if (!capable(CAP_SYS_ADMIN)) |
| 402 | return -EACCES; |
| 403 | if (bdev != bdev->bd_contains) |
| 404 | // ro setting is not allowed for partitions |
| 405 | return -EINVAL; |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 406 | if (get_user(intval, (int __user *)argp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | return -EFAULT; |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 408 | base = dasd_device_from_gendisk(bdev->bd_disk); |
| 409 | if (!base) |
| 410 | return -ENODEV; |
| 411 | if (!intval && test_bit(DASD_FLAG_DEVICE_RO, &base->flags)) { |
| 412 | dasd_put_device(base); |
Stefan Weinhuber | 33b62a3 | 2010-03-08 12:26:24 +0100 | [diff] [blame] | 413 | return -EROFS; |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 414 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | set_disk_ro(bdev->bd_disk, intval); |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 416 | rc = dasd_set_feature(base->cdev, DASD_FEATURE_READONLY, intval); |
| 417 | dasd_put_device(base); |
| 418 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 421 | static int dasd_ioctl_readall_cmb(struct dasd_block *block, unsigned int cmd, |
Heiko Carstens | 8803486 | 2010-01-13 20:44:29 +0100 | [diff] [blame] | 422 | struct cmbdata __user *argp) |
Christoph Hellwig | 8b2eb66 | 2006-03-24 03:15:21 -0800 | [diff] [blame] | 423 | { |
Christoph Hellwig | 8b2eb66 | 2006-03-24 03:15:21 -0800 | [diff] [blame] | 424 | size_t size = _IOC_SIZE(cmd); |
| 425 | struct cmbdata data; |
| 426 | int ret; |
| 427 | |
Stefan Weinhuber | 8e09f21 | 2008-01-26 14:11:23 +0100 | [diff] [blame] | 428 | ret = cmf_readall(block->base->cdev, &data); |
Christoph Hellwig | 8b2eb66 | 2006-03-24 03:15:21 -0800 | [diff] [blame] | 429 | if (!ret && copy_to_user(argp, &data, min(size, sizeof(*argp)))) |
| 430 | return -EFAULT; |
| 431 | return ret; |
| 432 | } |
| 433 | |
Arnd Bergmann | cfdb00a | 2010-05-31 22:38:40 +0200 | [diff] [blame] | 434 | int dasd_ioctl(struct block_device *bdev, fmode_t mode, |
| 435 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | { |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 437 | struct dasd_block *block; |
| 438 | struct dasd_device *base; |
Heiko Carstens | 8803486 | 2010-01-13 20:44:29 +0100 | [diff] [blame] | 439 | void __user *argp; |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 440 | int rc; |
Heiko Carstens | 8803486 | 2010-01-13 20:44:29 +0100 | [diff] [blame] | 441 | |
| 442 | if (is_compat_task()) |
| 443 | argp = compat_ptr(arg); |
| 444 | else |
| 445 | argp = (void __user *)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 447 | if ((_IOC_DIR(cmd) != _IOC_NONE) && !arg) { |
| 448 | PRINT_DEBUG("empty data ptr"); |
| 449 | return -EINVAL; |
| 450 | } |
| 451 | |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 452 | base = dasd_device_from_gendisk(bdev->bd_disk); |
| 453 | if (!base) |
| 454 | return -ENODEV; |
| 455 | block = base->block; |
| 456 | rc = 0; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 457 | switch (cmd) { |
| 458 | case BIODASDDISABLE: |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 459 | rc = dasd_ioctl_disable(bdev); |
| 460 | break; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 461 | case BIODASDENABLE: |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 462 | rc = dasd_ioctl_enable(bdev); |
| 463 | break; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 464 | case BIODASDQUIESCE: |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 465 | rc = dasd_ioctl_quiesce(block); |
| 466 | break; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 467 | case BIODASDRESUME: |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 468 | rc = dasd_ioctl_resume(block); |
| 469 | break; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 470 | case BIODASDFMT: |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 471 | rc = dasd_ioctl_format(bdev, argp); |
| 472 | break; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 473 | case BIODASDINFO: |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 474 | rc = dasd_ioctl_information(block, cmd, argp); |
| 475 | break; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 476 | case BIODASDINFO2: |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 477 | rc = dasd_ioctl_information(block, cmd, argp); |
| 478 | break; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 479 | case BIODASDPRRD: |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 480 | rc = dasd_ioctl_read_profile(block, argp); |
| 481 | break; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 482 | case BIODASDPRRST: |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 483 | rc = dasd_ioctl_reset_profile(block); |
| 484 | break; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 485 | case BLKROSET: |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 486 | rc = dasd_ioctl_set_ro(bdev, argp); |
| 487 | break; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 488 | case DASDAPIVER: |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 489 | rc = dasd_ioctl_api_version(argp); |
| 490 | break; |
Christoph Hellwig | 8b2eb66 | 2006-03-24 03:15:21 -0800 | [diff] [blame] | 491 | case BIODASDCMFENABLE: |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 492 | rc = enable_cmf(base->cdev); |
| 493 | break; |
Christoph Hellwig | 8b2eb66 | 2006-03-24 03:15:21 -0800 | [diff] [blame] | 494 | case BIODASDCMFDISABLE: |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 495 | rc = disable_cmf(base->cdev); |
| 496 | break; |
Christoph Hellwig | 8b2eb66 | 2006-03-24 03:15:21 -0800 | [diff] [blame] | 497 | case BIODASDREADALLCMB: |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 498 | rc = dasd_ioctl_readall_cmb(block, cmd, argp); |
| 499 | break; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 500 | default: |
Christoph Hellwig | 1107ccf | 2006-03-24 03:15:20 -0800 | [diff] [blame] | 501 | /* if the discipline has an ioctl method try it. */ |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 502 | if (base->discipline->ioctl) { |
| 503 | rc = base->discipline->ioctl(block, cmd, argp); |
| 504 | if (rc == -ENOIOCTLCMD) |
| 505 | rc = -EINVAL; |
| 506 | } else |
| 507 | rc = -EINVAL; |
Christoph Hellwig | 13c6204 | 2006-03-24 03:15:19 -0800 | [diff] [blame] | 508 | } |
Stefan Weinhuber | 65f8da4 | 2011-04-20 10:15:30 +0200 | [diff] [blame] | 509 | dasd_put_device(base); |
| 510 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | } |