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(struct inode
*inp
, struct file
*filp
,
82 unsigned int no
, unsigned long data
)
84 struct block_device
*bdev
= inp
->i_bdev
;
85 struct dasd_device
*device
= bdev
->bd_disk
->private_data
;
86 struct dasd_ioctl
*ioctl
;
90 if ((_IOC_DIR(no
) != _IOC_NONE
) && (data
== 0)) {
91 PRINT_DEBUG("empty data ptr");
94 dir
= _IOC_DIR (no
) == _IOC_NONE
? "0" :
95 _IOC_DIR (no
) == _IOC_READ
? "r" :
96 _IOC_DIR (no
) == _IOC_WRITE
? "w" :
97 _IOC_DIR (no
) == (_IOC_READ
| _IOC_WRITE
) ? "rw" : "u";
98 DBF_DEV_EVENT(DBF_DEBUG
, device
,
99 "ioctl 0x%08x %s'0x%x'%d(%d) with data %8lx", no
,
100 dir
, _IOC_TYPE(no
), _IOC_NR(no
), _IOC_SIZE(no
), data
);
101 /* Search for ioctl no in the ioctl list. */
102 list_for_each_entry(ioctl
, &dasd_ioctl_list
, list
) {
103 if (ioctl
->no
== no
) {
104 /* Found a matching ioctl. Call it. */
105 if (!try_module_get(ioctl
->owner
))
107 rc
= ioctl
->handler(bdev
, no
, data
);
108 module_put(ioctl
->owner
);
112 /* No ioctl with number no. */
113 DBF_DEV_EVENT(DBF_INFO
, device
,
114 "unknown ioctl 0x%08x=%s'0x%x'%d(%d) data %8lx", no
,
115 dir
, _IOC_TYPE(no
), _IOC_NR(no
), _IOC_SIZE(no
), data
);
120 dasd_compat_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
)
125 rval
= dasd_ioctl(filp
->f_dentry
->d_inode
, filp
, cmd
, arg
);
128 return (rval
== -EINVAL
) ? -ENOIOCTLCMD
: rval
;
132 dasd_ioctl_api_version(struct block_device
*bdev
, int no
, long args
)
134 int ver
= DASD_API_VERSION
;
135 return put_user(ver
, (int __user
*) args
);
140 * used by dasdfmt after BIODASDDISABLE to retrigger blocksize detection
143 dasd_ioctl_enable(struct block_device
*bdev
, int no
, long args
)
145 struct dasd_device
*device
;
147 if (!capable(CAP_SYS_ADMIN
))
149 device
= bdev
->bd_disk
->private_data
;
152 dasd_enable_device(device
);
153 /* Formatting the dasd device can change the capacity. */
155 i_size_write(bdev
->bd_inode
, (loff_t
)get_capacity(device
->gdp
) << 9);
162 * Used by dasdfmt. Disable I/O operations but allow ioctls.
165 dasd_ioctl_disable(struct block_device
*bdev
, int no
, long args
)
167 struct dasd_device
*device
;
169 if (!capable(CAP_SYS_ADMIN
))
171 device
= bdev
->bd_disk
->private_data
;
175 * Man this is sick. We don't do a real disable but only downgrade
176 * the device to DASD_STATE_BASIC. The reason is that dasdfmt uses
177 * BIODASDDISABLE to disable accesses to the device via the block
178 * device layer but it still wants to do i/o on the device by
179 * using the BIODASDFMT ioctl. Therefore the correct state for the
180 * device is DASD_STATE_BASIC that allows to do basic i/o.
182 dasd_set_target_state(device
, DASD_STATE_BASIC
);
184 * Set i_size to zero, since read, write, etc. check against this
188 i_size_write(bdev
->bd_inode
, 0);
197 dasd_ioctl_quiesce(struct block_device
*bdev
, int no
, long args
)
199 struct dasd_device
*device
;
202 if (!capable (CAP_SYS_ADMIN
))
205 device
= bdev
->bd_disk
->private_data
;
209 DEV_MESSAGE (KERN_DEBUG
, device
, "%s",
210 "Quiesce IO on device");
211 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
212 device
->stopped
|= DASD_STOPPED_QUIESCE
;
213 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
222 dasd_ioctl_resume(struct block_device
*bdev
, int no
, long args
)
224 struct dasd_device
*device
;
227 if (!capable (CAP_SYS_ADMIN
))
230 device
= bdev
->bd_disk
->private_data
;
234 DEV_MESSAGE (KERN_DEBUG
, device
, "%s",
235 "resume IO on device");
237 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
238 device
->stopped
&= ~DASD_STOPPED_QUIESCE
;
239 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
241 dasd_schedule_bh (device
);
246 * performs formatting of _device_ according to _fdata_
247 * Note: The discipline's format_function is assumed to deliver formatting
248 * commands to format a single unit of the device. In terms of the ECKD
249 * devices this means CCWs are generated to format a single track.
252 dasd_format(struct dasd_device
* device
, struct format_data_t
* fdata
)
254 struct dasd_ccw_req
*cqr
;
257 if (device
->discipline
->format_device
== NULL
)
260 if (device
->state
!= DASD_STATE_BASIC
) {
261 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
262 "dasd_format: device is not disabled! ");
266 DBF_DEV_EVENT(DBF_NOTICE
, device
,
267 "formatting units %d to %d (%d B blocks) flags %d",
269 fdata
->stop_unit
, fdata
->blksize
, fdata
->intensity
);
271 /* Since dasdfmt keeps the device open after it was disabled,
272 * there still exists an inode for this device.
273 * We must update i_blkbits, otherwise we might get errors when
274 * enabling the device later.
276 if (fdata
->start_unit
== 0) {
277 struct block_device
*bdev
= bdget_disk(device
->gdp
, 0);
278 bdev
->bd_inode
->i_blkbits
= blksize_bits(fdata
->blksize
);
282 while (fdata
->start_unit
<= fdata
->stop_unit
) {
283 cqr
= device
->discipline
->format_device(device
, fdata
);
286 rc
= dasd_sleep_on_interruptible(cqr
);
287 dasd_sfree_request(cqr
, cqr
->device
);
289 if (rc
!= -ERESTARTSYS
)
290 DEV_MESSAGE(KERN_ERR
, device
,
291 " Formatting of unit %d failed "
293 fdata
->start_unit
, rc
);
305 dasd_ioctl_format(struct block_device
*bdev
, int no
, long args
)
307 struct dasd_device
*device
;
308 struct format_data_t fdata
;
310 if (!capable(CAP_SYS_ADMIN
))
314 /* fdata == NULL is no longer a valid arg to dasd_format ! */
315 device
= bdev
->bd_disk
->private_data
;
320 if (device
->features
& DASD_FEATURE_READONLY
)
322 if (copy_from_user(&fdata
, (void __user
*) args
,
323 sizeof (struct format_data_t
)))
325 if (bdev
!= bdev
->bd_contains
) {
326 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
327 "Cannot low-level format a partition");
330 return dasd_format(device
, &fdata
);
333 #ifdef CONFIG_DASD_PROFILE
335 * Reset device profile information
338 dasd_ioctl_reset_profile(struct block_device
*bdev
, int no
, long args
)
340 struct dasd_device
*device
;
342 if (!capable(CAP_SYS_ADMIN
))
345 device
= bdev
->bd_disk
->private_data
;
349 memset(&device
->profile
, 0, sizeof (struct dasd_profile_info_t
));
354 * Return device profile information
357 dasd_ioctl_read_profile(struct block_device
*bdev
, int no
, long args
)
359 struct dasd_device
*device
;
361 device
= bdev
->bd_disk
->private_data
;
365 if (dasd_profile_level
== DASD_PROFILE_OFF
)
368 if (copy_to_user((long __user
*) args
, (long *) &device
->profile
,
369 sizeof (struct dasd_profile_info_t
)))
375 dasd_ioctl_reset_profile(struct block_device
*bdev
, int no
, long args
)
381 dasd_ioctl_read_profile(struct block_device
*bdev
, int no
, long args
)
388 * Return dasd information. Used for BIODASDINFO and BIODASDINFO2.
391 dasd_ioctl_information(struct block_device
*bdev
, int no
, long args
)
393 struct dasd_device
*device
;
394 struct dasd_information2_t
*dasd_info
;
397 struct ccw_device
*cdev
;
399 device
= bdev
->bd_disk
->private_data
;
403 if (!device
->discipline
->fill_info
)
406 dasd_info
= kmalloc(sizeof(struct dasd_information2_t
), GFP_KERNEL
);
407 if (dasd_info
== NULL
)
410 rc
= device
->discipline
->fill_info(device
, dasd_info
);
418 dasd_info
->devno
= _ccw_device_get_device_number(device
->cdev
);
419 dasd_info
->schid
= _ccw_device_get_subchannel_number(device
->cdev
);
420 dasd_info
->cu_type
= cdev
->id
.cu_type
;
421 dasd_info
->cu_model
= cdev
->id
.cu_model
;
422 dasd_info
->dev_type
= cdev
->id
.dev_type
;
423 dasd_info
->dev_model
= cdev
->id
.dev_model
;
424 dasd_info
->status
= device
->state
;
426 * The open_count is increased for every opener, that includes
427 * the blkdev_get in dasd_scan_partitions.
428 * This must be hidden from user-space.
430 dasd_info
->open_count
= atomic_read(&device
->open_count
);
432 dasd_info
->open_count
++;
435 * check if device is really formatted
436 * LDL / CDL was returned by 'fill_info'
438 if ((device
->state
< DASD_STATE_READY
) ||
439 (dasd_check_blocksize(device
->bp_block
)))
440 dasd_info
->format
= DASD_FORMAT_NONE
;
442 dasd_info
->features
|=
443 ((device
->features
& DASD_FEATURE_READONLY
) != 0);
445 if (device
->discipline
)
446 memcpy(dasd_info
->type
, device
->discipline
->name
, 4);
448 memcpy(dasd_info
->type
, "none", 4);
449 dasd_info
->req_queue_len
= 0;
450 dasd_info
->chanq_len
= 0;
451 if (device
->request_queue
->request_fn
) {
453 #ifdef DASD_EXTENDED_PROFILING
456 spin_lock_irqsave(&device
->lock
, flags
);
457 list_for_each(l
, &device
->request_queue
->queue_head
)
458 dasd_info
->req_queue_len
++;
459 spin_unlock_irqrestore(&device
->lock
, flags
);
461 #endif /* DASD_EXTENDED_PROFILING */
462 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
463 list_for_each(l
, &device
->ccw_queue
)
464 dasd_info
->chanq_len
++;
465 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
),
470 if (copy_to_user((long __user
*) args
, (long *) dasd_info
,
471 ((no
== (unsigned int) BIODASDINFO2
) ?
472 sizeof (struct dasd_information2_t
) :
473 sizeof (struct dasd_information_t
))))
483 dasd_ioctl_set_ro(struct block_device
*bdev
, int no
, long args
)
485 struct dasd_device
*device
;
488 if (!capable(CAP_SYS_ADMIN
))
490 if (bdev
!= bdev
->bd_contains
)
491 // ro setting is not allowed for partitions
493 if (get_user(intval
, (int __user
*) args
))
495 device
= bdev
->bd_disk
->private_data
;
499 set_disk_ro(bdev
->bd_disk
, intval
);
500 rc
= dasd_set_feature(device
->cdev
, DASD_FEATURE_READONLY
, intval
);
506 * List of static ioctls.
508 static struct { int no
; dasd_ioctl_fn_t fn
; } dasd_ioctls
[] =
510 { BIODASDDISABLE
, dasd_ioctl_disable
},
511 { BIODASDENABLE
, dasd_ioctl_enable
},
512 { BIODASDQUIESCE
, dasd_ioctl_quiesce
},
513 { BIODASDRESUME
, dasd_ioctl_resume
},
514 { BIODASDFMT
, dasd_ioctl_format
},
515 { BIODASDINFO
, dasd_ioctl_information
},
516 { BIODASDINFO2
, dasd_ioctl_information
},
517 { BIODASDPRRD
, dasd_ioctl_read_profile
},
518 { BIODASDPRRST
, dasd_ioctl_reset_profile
},
519 { BLKROSET
, dasd_ioctl_set_ro
},
520 { DASDAPIVER
, dasd_ioctl_api_version
},
525 dasd_ioctl_init(void)
529 for (i
= 0; dasd_ioctls
[i
].no
!= -1; i
++)
530 dasd_ioctl_no_register(NULL
, dasd_ioctls
[i
].no
,
537 dasd_ioctl_exit(void)
541 for (i
= 0; dasd_ioctls
[i
].no
!= -1; i
++)
542 dasd_ioctl_no_unregister(NULL
, dasd_ioctls
[i
].no
,
547 EXPORT_SYMBOL(dasd_ioctl_no_register
);
548 EXPORT_SYMBOL(dasd_ioctl_no_unregister
);