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