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