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
10 * i/o controls for the dasd driver.
13 #define KMSG_COMPONENT "dasd"
15 #include <linux/interrupt.h>
16 #include <linux/major.h>
18 #include <linux/blkpg.h>
20 #include <asm/ccwdev.h>
22 #include <asm/uaccess.h>
25 #define PRINTK_HEADER "dasd_ioctl:"
31 dasd_ioctl_api_version(void __user *argp)
33 int ver = DASD_API_VERSION;
34 return put_user(ver, (int __user *)argp);
39 * used by dasdfmt after BIODASDDISABLE to retrigger blocksize detection
42 dasd_ioctl_enable(struct block_device *bdev)
44 struct dasd_block *block = bdev->bd_disk->private_data;
46 if (!capable(CAP_SYS_ADMIN))
49 dasd_enable_device(block->base);
50 /* Formatting the dasd device can change the capacity. */
51 mutex_lock(&bdev->bd_mutex);
52 i_size_write(bdev->bd_inode, (loff_t)get_capacity(block->gdp) << 9);
53 mutex_unlock(&bdev->bd_mutex);
59 * Used by dasdfmt. Disable I/O operations but allow ioctls.
62 dasd_ioctl_disable(struct block_device *bdev)
64 struct dasd_block *block = bdev->bd_disk->private_data;
66 if (!capable(CAP_SYS_ADMIN))
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.
77 dasd_set_target_state(block->base, DASD_STATE_BASIC);
79 * Set i_size to zero, since read, write, etc. check against this
82 mutex_lock(&bdev->bd_mutex);
83 i_size_write(bdev->bd_inode, 0);
84 mutex_unlock(&bdev->bd_mutex);
91 static int dasd_ioctl_quiesce(struct dasd_block *block)
94 struct dasd_device *base;
97 if (!capable (CAP_SYS_ADMIN))
100 dev_info(&base->cdev->dev, "The DASD has been put in the quiesce "
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);
112 static int dasd_ioctl_resume(struct dasd_block *block)
115 struct dasd_device *base;
118 if (!capable (CAP_SYS_ADMIN))
121 dev_info(&base->cdev->dev, "I/O operations have been resumed "
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);
127 dasd_schedule_block_bh(block);
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.
137 static int dasd_format(struct dasd_block *block, struct format_data_t *fdata)
139 struct dasd_ccw_req *cqr;
140 struct dasd_device *base;
144 if (base->discipline->format_device == NULL)
147 if (base->state != DASD_STATE_BASIC) {
148 dev_warn(&base->cdev->dev,
149 "The DASD cannot be formatted while it is enabled\n");
153 DBF_DEV_EVENT(DBF_NOTICE, base,
154 "formatting units %u to %u (%u B blocks) flags %u",
156 fdata->stop_unit, fdata->blksize, fdata->intensity);
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.
163 if (fdata->start_unit == 0) {
164 struct block_device *bdev = bdget_disk(block->gdp, 0);
165 bdev->bd_inode->i_blkbits = blksize_bits(fdata->blksize);
169 while (fdata->start_unit <= fdata->stop_unit) {
170 cqr = base->discipline->format_device(base, fdata);
173 rc = dasd_sleep_on_interruptible(cqr);
174 dasd_sfree_request(cqr, cqr->memdev);
176 if (rc != -ERESTARTSYS)
177 dev_err(&base->cdev->dev,
178 "Formatting unit %d failed with "
179 "rc=%d\n", fdata->start_unit, rc);
191 dasd_ioctl_format(struct block_device *bdev, void __user *argp)
193 struct dasd_block *block = bdev->bd_disk->private_data;
194 struct format_data_t fdata;
196 if (!capable(CAP_SYS_ADMIN))
201 if (block->base->features & DASD_FEATURE_READONLY)
203 if (copy_from_user(&fdata, argp, sizeof(struct format_data_t)))
205 if (bdev != bdev->bd_contains) {
206 dev_warn(&block->base->cdev->dev,
207 "The specified DASD is a partition and cannot be "
211 return dasd_format(block, &fdata);
214 #ifdef CONFIG_DASD_PROFILE
216 * Reset device profile information
218 static int dasd_ioctl_reset_profile(struct dasd_block *block)
220 memset(&block->profile, 0, sizeof(struct dasd_profile_info_t));
225 * Return device profile information
227 static int dasd_ioctl_read_profile(struct dasd_block *block, void __user *argp)
229 if (dasd_profile_level == DASD_PROFILE_OFF)
231 if (copy_to_user(argp, &block->profile,
232 sizeof(struct dasd_profile_info_t)))
237 static int dasd_ioctl_reset_profile(struct dasd_block *block)
242 static int dasd_ioctl_read_profile(struct dasd_block *block, void __user *argp)
249 * Return dasd information. Used for BIODASDINFO and BIODASDINFO2.
251 static int dasd_ioctl_information(struct dasd_block *block,
252 unsigned int cmd, void __user *argp)
254 struct dasd_information2_t *dasd_info;
257 struct dasd_device *base;
258 struct ccw_device *cdev;
259 struct ccw_dev_id dev_id;
262 if (!base->discipline->fill_info)
265 dasd_info = kzalloc(sizeof(struct dasd_information2_t), GFP_KERNEL);
266 if (dasd_info == NULL)
269 rc = base->discipline->fill_info(base, dasd_info);
276 ccw_device_get_id(cdev, &dev_id);
278 dasd_info->devno = dev_id.devno;
279 dasd_info->schid = _ccw_device_get_subchannel_number(base->cdev);
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;
284 dasd_info->status = base->state;
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.
290 dasd_info->open_count = atomic_read(&block->open_count);
292 dasd_info->open_count++;
295 * check if device is really formatted
296 * LDL / CDL was returned by 'fill_info'
298 if ((base->state < DASD_STATE_READY) ||
299 (dasd_check_blocksize(block->bp_block)))
300 dasd_info->format = DASD_FORMAT_NONE;
302 dasd_info->features |=
303 ((base->features & DASD_FEATURE_READONLY) != 0);
305 if (base->discipline)
306 memcpy(dasd_info->type, base->discipline->name, 4);
308 memcpy(dasd_info->type, "none", 4);
310 if (block->request_queue->request_fn) {
312 #ifdef DASD_EXTENDED_PROFILING
315 spin_lock_irqsave(&block->lock, flags);
316 list_for_each(l, &block->request_queue->queue_head)
317 dasd_info->req_queue_len++;
318 spin_unlock_irqrestore(&block->lock, flags);
320 #endif /* DASD_EXTENDED_PROFILING */
321 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
322 list_for_each(l, &base->ccw_queue)
323 dasd_info->chanq_len++;
324 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
329 if (copy_to_user(argp, dasd_info,
330 ((cmd == (unsigned int) BIODASDINFO2) ?
331 sizeof(struct dasd_information2_t) :
332 sizeof(struct dasd_information_t))))
342 dasd_ioctl_set_ro(struct block_device *bdev, void __user *argp)
344 struct dasd_block *block = bdev->bd_disk->private_data;
347 if (!capable(CAP_SYS_ADMIN))
349 if (bdev != bdev->bd_contains)
350 // ro setting is not allowed for partitions
352 if (get_user(intval, (int __user *)argp))
355 set_disk_ro(bdev->bd_disk, intval);
356 return dasd_set_feature(block->base->cdev, DASD_FEATURE_READONLY, intval);
359 static int dasd_ioctl_readall_cmb(struct dasd_block *block, unsigned int cmd,
362 struct cmbdata __user *argp = (void __user *) arg;
363 size_t size = _IOC_SIZE(cmd);
367 ret = cmf_readall(block->base->cdev, &data);
368 if (!ret && copy_to_user(argp, &data, min(size, sizeof(*argp))))
374 dasd_do_ioctl(struct block_device *bdev, fmode_t mode,
375 unsigned int cmd, unsigned long arg)
377 struct dasd_block *block = bdev->bd_disk->private_data;
378 void __user *argp = (void __user *)arg;
383 if ((_IOC_DIR(cmd) != _IOC_NONE) && !arg) {
384 PRINT_DEBUG("empty data ptr");
390 return dasd_ioctl_disable(bdev);
392 return dasd_ioctl_enable(bdev);
394 return dasd_ioctl_quiesce(block);
396 return dasd_ioctl_resume(block);
398 return dasd_ioctl_format(bdev, argp);
400 return dasd_ioctl_information(block, cmd, argp);
402 return dasd_ioctl_information(block, cmd, argp);
404 return dasd_ioctl_read_profile(block, argp);
406 return dasd_ioctl_reset_profile(block);
408 return dasd_ioctl_set_ro(bdev, argp);
410 return dasd_ioctl_api_version(argp);
411 case BIODASDCMFENABLE:
412 return enable_cmf(block->base->cdev);
413 case BIODASDCMFDISABLE:
414 return disable_cmf(block->base->cdev);
415 case BIODASDREADALLCMB:
416 return dasd_ioctl_readall_cmb(block, cmd, arg);
418 /* if the discipline has an ioctl method try it. */
419 if (block->base->discipline->ioctl) {
420 int rval = block->base->discipline->ioctl(block, cmd, argp);
421 if (rval != -ENOIOCTLCMD)
429 int dasd_ioctl(struct block_device *bdev, fmode_t mode,
430 unsigned int cmd, unsigned long arg)
435 rc = dasd_do_ioctl(bdev, mode, cmd, arg);