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.
12 #include <linux/config.h>
13 #include <linux/interrupt.h>
14 #include <linux/major.h>
16 #include <linux/blkpg.h>
18 #include <asm/ccwdev.h>
19 #include <asm/uaccess.h>
22 #define PRINTK_HEADER "dasd_ioctl:"
27 * SECTION: ioctl functions.
29 static struct list_head dasd_ioctl_list = LIST_HEAD_INIT(dasd_ioctl_list);
32 * Find the ioctl with number no.
34 static struct dasd_ioctl *
35 dasd_find_ioctl(int no)
37 struct dasd_ioctl *ioctl;
39 list_for_each_entry (ioctl, &dasd_ioctl_list, list)
46 * Register ioctl with number no.
49 dasd_ioctl_no_register(struct module *owner, int no, dasd_ioctl_fn_t handler)
51 struct dasd_ioctl *new;
52 if (dasd_find_ioctl(no))
54 new = kmalloc(sizeof (struct dasd_ioctl), GFP_KERNEL);
59 new->handler = handler;
60 list_add(&new->list, &dasd_ioctl_list);
65 * Deregister ioctl with number no.
68 dasd_ioctl_no_unregister(struct module *owner, int no, dasd_ioctl_fn_t handler)
70 struct dasd_ioctl *old = dasd_find_ioctl(no);
73 if (old->no != no || old->handler != handler || owner != old->owner)
81 dasd_ioctl_api_version(void __user *argp)
83 int ver = DASD_API_VERSION;
84 return put_user(ver, (int *)argp);
89 * used by dasdfmt after BIODASDDISABLE to retrigger blocksize detection
92 dasd_ioctl_enable(struct block_device *bdev)
94 struct dasd_device *device = bdev->bd_disk->private_data;
96 if (!capable(CAP_SYS_ADMIN))
99 dasd_enable_device(device);
100 /* Formatting the dasd device can change the capacity. */
101 mutex_lock(&bdev->bd_mutex);
102 i_size_write(bdev->bd_inode, (loff_t)get_capacity(device->gdp) << 9);
103 mutex_unlock(&bdev->bd_mutex);
109 * Used by dasdfmt. Disable I/O operations but allow ioctls.
112 dasd_ioctl_disable(struct block_device *bdev)
114 struct dasd_device *device = bdev->bd_disk->private_data;
116 if (!capable(CAP_SYS_ADMIN))
120 * Man this is sick. We don't do a real disable but only downgrade
121 * the device to DASD_STATE_BASIC. The reason is that dasdfmt uses
122 * BIODASDDISABLE to disable accesses to the device via the block
123 * device layer but it still wants to do i/o on the device by
124 * using the BIODASDFMT ioctl. Therefore the correct state for the
125 * device is DASD_STATE_BASIC that allows to do basic i/o.
127 dasd_set_target_state(device, DASD_STATE_BASIC);
129 * Set i_size to zero, since read, write, etc. check against this
132 mutex_lock(&bdev->bd_mutex);
133 i_size_write(bdev->bd_inode, 0);
134 mutex_unlock(&bdev->bd_mutex);
142 dasd_ioctl_quiesce(struct dasd_device *device)
146 if (!capable (CAP_SYS_ADMIN))
149 DEV_MESSAGE (KERN_DEBUG, device, "%s",
150 "Quiesce IO on device");
151 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
152 device->stopped |= DASD_STOPPED_QUIESCE;
153 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
162 dasd_ioctl_resume(struct dasd_device *device)
166 if (!capable (CAP_SYS_ADMIN))
169 DEV_MESSAGE (KERN_DEBUG, device, "%s",
170 "resume IO on device");
172 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
173 device->stopped &= ~DASD_STOPPED_QUIESCE;
174 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
176 dasd_schedule_bh (device);
181 * performs formatting of _device_ according to _fdata_
182 * Note: The discipline's format_function is assumed to deliver formatting
183 * commands to format a single unit of the device. In terms of the ECKD
184 * devices this means CCWs are generated to format a single track.
187 dasd_format(struct dasd_device * device, struct format_data_t * fdata)
189 struct dasd_ccw_req *cqr;
192 if (device->discipline->format_device == NULL)
195 if (device->state != DASD_STATE_BASIC) {
196 DEV_MESSAGE(KERN_WARNING, device, "%s",
197 "dasd_format: device is not disabled! ");
201 DBF_DEV_EVENT(DBF_NOTICE, device,
202 "formatting units %d to %d (%d B blocks) flags %d",
204 fdata->stop_unit, fdata->blksize, fdata->intensity);
206 /* Since dasdfmt keeps the device open after it was disabled,
207 * there still exists an inode for this device.
208 * We must update i_blkbits, otherwise we might get errors when
209 * enabling the device later.
211 if (fdata->start_unit == 0) {
212 struct block_device *bdev = bdget_disk(device->gdp, 0);
213 bdev->bd_inode->i_blkbits = blksize_bits(fdata->blksize);
217 while (fdata->start_unit <= fdata->stop_unit) {
218 cqr = device->discipline->format_device(device, fdata);
221 rc = dasd_sleep_on_interruptible(cqr);
222 dasd_sfree_request(cqr, cqr->device);
224 if (rc != -ERESTARTSYS)
225 DEV_MESSAGE(KERN_ERR, device,
226 " Formatting of unit %d failed "
228 fdata->start_unit, rc);
240 dasd_ioctl_format(struct block_device *bdev, void __user *argp)
242 struct dasd_device *device = bdev->bd_disk->private_data;
243 struct format_data_t fdata;
245 if (!capable(CAP_SYS_ADMIN))
250 if (device->features & DASD_FEATURE_READONLY)
252 if (copy_from_user(&fdata, argp, sizeof(struct format_data_t)))
254 if (bdev != bdev->bd_contains) {
255 DEV_MESSAGE(KERN_WARNING, device, "%s",
256 "Cannot low-level format a partition");
259 return dasd_format(device, &fdata);
262 #ifdef CONFIG_DASD_PROFILE
264 * Reset device profile information
267 dasd_ioctl_reset_profile(struct dasd_device *device)
269 memset(&device->profile, 0, sizeof (struct dasd_profile_info_t));
274 * Return device profile information
277 dasd_ioctl_read_profile(struct dasd_device *device, void __user *argp)
279 if (dasd_profile_level == DASD_PROFILE_OFF)
281 if (copy_to_user(argp, &device->profile,
282 sizeof (struct dasd_profile_info_t)))
288 dasd_ioctl_reset_profile(struct dasd_device *device)
294 dasd_ioctl_read_profile(struct dasd_device *device, void __user *argp)
301 * Return dasd information. Used for BIODASDINFO and BIODASDINFO2.
304 dasd_ioctl_information(struct dasd_device *device,
305 unsigned int cmd, void __user *argp)
307 struct dasd_information2_t *dasd_info;
310 struct ccw_device *cdev;
312 if (!device->discipline->fill_info)
315 dasd_info = kmalloc(sizeof(struct dasd_information2_t), GFP_KERNEL);
316 if (dasd_info == NULL)
319 rc = device->discipline->fill_info(device, dasd_info);
327 dasd_info->devno = _ccw_device_get_device_number(device->cdev);
328 dasd_info->schid = _ccw_device_get_subchannel_number(device->cdev);
329 dasd_info->cu_type = cdev->id.cu_type;
330 dasd_info->cu_model = cdev->id.cu_model;
331 dasd_info->dev_type = cdev->id.dev_type;
332 dasd_info->dev_model = cdev->id.dev_model;
333 dasd_info->status = device->state;
335 * The open_count is increased for every opener, that includes
336 * the blkdev_get in dasd_scan_partitions.
337 * This must be hidden from user-space.
339 dasd_info->open_count = atomic_read(&device->open_count);
341 dasd_info->open_count++;
344 * check if device is really formatted
345 * LDL / CDL was returned by 'fill_info'
347 if ((device->state < DASD_STATE_READY) ||
348 (dasd_check_blocksize(device->bp_block)))
349 dasd_info->format = DASD_FORMAT_NONE;
351 dasd_info->features |=
352 ((device->features & DASD_FEATURE_READONLY) != 0);
354 if (device->discipline)
355 memcpy(dasd_info->type, device->discipline->name, 4);
357 memcpy(dasd_info->type, "none", 4);
358 dasd_info->req_queue_len = 0;
359 dasd_info->chanq_len = 0;
360 if (device->request_queue->request_fn) {
362 #ifdef DASD_EXTENDED_PROFILING
365 spin_lock_irqsave(&device->lock, flags);
366 list_for_each(l, &device->request_queue->queue_head)
367 dasd_info->req_queue_len++;
368 spin_unlock_irqrestore(&device->lock, flags);
370 #endif /* DASD_EXTENDED_PROFILING */
371 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
372 list_for_each(l, &device->ccw_queue)
373 dasd_info->chanq_len++;
374 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
379 if (copy_to_user(argp, dasd_info,
380 ((cmd == (unsigned int) BIODASDINFO2) ?
381 sizeof (struct dasd_information2_t) :
382 sizeof (struct dasd_information_t))))
392 dasd_ioctl_set_ro(struct block_device *bdev, void __user *argp)
394 struct dasd_device *device = bdev->bd_disk->private_data;
397 if (!capable(CAP_SYS_ADMIN))
399 if (bdev != bdev->bd_contains)
400 // ro setting is not allowed for partitions
402 if (get_user(intval, (int *)argp))
405 set_disk_ro(bdev->bd_disk, intval);
406 return dasd_set_feature(device->cdev, DASD_FEATURE_READONLY, intval);
410 dasd_ioctl(struct inode *inode, struct file *file,
411 unsigned int cmd, unsigned long arg)
413 struct block_device *bdev = inode->i_bdev;
414 struct dasd_device *device = bdev->bd_disk->private_data;
415 void __user *argp = (void __user *)arg;
416 struct dasd_ioctl *ioctl;
422 if ((_IOC_DIR(cmd) != _IOC_NONE) && !arg) {
423 PRINT_DEBUG("empty data ptr");
429 return dasd_ioctl_disable(bdev);
431 return dasd_ioctl_enable(bdev);
433 return dasd_ioctl_quiesce(device);
435 return dasd_ioctl_resume(device);
437 return dasd_ioctl_format(bdev, argp);
439 return dasd_ioctl_information(device, cmd, argp);
441 return dasd_ioctl_information(device, cmd, argp);
443 return dasd_ioctl_read_profile(device, argp);
445 return dasd_ioctl_reset_profile(device);
447 return dasd_ioctl_set_ro(bdev, argp);
449 return dasd_ioctl_api_version(argp);
451 /* resort to the deprecated dynamic ioctl list */
452 list_for_each_entry(ioctl, &dasd_ioctl_list, list) {
453 if (ioctl->no == cmd) {
454 /* Found a matching ioctl. Call it. */
455 if (!try_module_get(ioctl->owner))
457 rc = ioctl->handler(bdev, cmd, arg);
458 module_put(ioctl->owner);
467 dasd_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
472 rval = dasd_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
475 return (rval == -EINVAL) ? -ENOIOCTLCMD : rval;
478 EXPORT_SYMBOL(dasd_ioctl_no_register);
479 EXPORT_SYMBOL(dasd_ioctl_no_unregister);