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_ioctl_api_version(struct block_device
*bdev
, int no
, long args
)
122 int ver
= DASD_API_VERSION
;
123 return put_user(ver
, (int __user
*) args
);
128 * used by dasdfmt after BIODASDDISABLE to retrigger blocksize detection
131 dasd_ioctl_enable(struct block_device
*bdev
, int no
, long args
)
133 struct dasd_device
*device
;
135 if (!capable(CAP_SYS_ADMIN
))
137 device
= bdev
->bd_disk
->private_data
;
140 dasd_enable_device(device
);
141 /* Formatting the dasd device can change the capacity. */
143 i_size_write(bdev
->bd_inode
, (loff_t
)get_capacity(device
->gdp
) << 9);
150 * Used by dasdfmt. Disable I/O operations but allow ioctls.
153 dasd_ioctl_disable(struct block_device
*bdev
, int no
, long args
)
155 struct dasd_device
*device
;
157 if (!capable(CAP_SYS_ADMIN
))
159 device
= bdev
->bd_disk
->private_data
;
163 * Man this is sick. We don't do a real disable but only downgrade
164 * the device to DASD_STATE_BASIC. The reason is that dasdfmt uses
165 * BIODASDDISABLE to disable accesses to the device via the block
166 * device layer but it still wants to do i/o on the device by
167 * using the BIODASDFMT ioctl. Therefore the correct state for the
168 * device is DASD_STATE_BASIC that allows to do basic i/o.
170 dasd_set_target_state(device
, DASD_STATE_BASIC
);
172 * Set i_size to zero, since read, write, etc. check against this
176 i_size_write(bdev
->bd_inode
, 0);
185 dasd_ioctl_quiesce(struct block_device
*bdev
, int no
, long args
)
187 struct dasd_device
*device
;
190 if (!capable (CAP_SYS_ADMIN
))
193 device
= bdev
->bd_disk
->private_data
;
197 DEV_MESSAGE (KERN_DEBUG
, device
, "%s",
198 "Quiesce IO on device");
199 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
200 device
->stopped
|= DASD_STOPPED_QUIESCE
;
201 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
210 dasd_ioctl_resume(struct block_device
*bdev
, int no
, long args
)
212 struct dasd_device
*device
;
215 if (!capable (CAP_SYS_ADMIN
))
218 device
= bdev
->bd_disk
->private_data
;
222 DEV_MESSAGE (KERN_DEBUG
, device
, "%s",
223 "resume IO on device");
225 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
226 device
->stopped
&= ~DASD_STOPPED_QUIESCE
;
227 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
229 dasd_schedule_bh (device
);
234 * performs formatting of _device_ according to _fdata_
235 * Note: The discipline's format_function is assumed to deliver formatting
236 * commands to format a single unit of the device. In terms of the ECKD
237 * devices this means CCWs are generated to format a single track.
240 dasd_format(struct dasd_device
* device
, struct format_data_t
* fdata
)
242 struct dasd_ccw_req
*cqr
;
245 if (device
->discipline
->format_device
== NULL
)
248 if (device
->state
!= DASD_STATE_BASIC
) {
249 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
250 "dasd_format: device is not disabled! ");
254 DBF_DEV_EVENT(DBF_NOTICE
, device
,
255 "formatting units %d to %d (%d B blocks) flags %d",
257 fdata
->stop_unit
, fdata
->blksize
, fdata
->intensity
);
259 /* Since dasdfmt keeps the device open after it was disabled,
260 * there still exists an inode for this device.
261 * We must update i_blkbits, otherwise we might get errors when
262 * enabling the device later.
264 if (fdata
->start_unit
== 0) {
265 struct block_device
*bdev
= bdget_disk(device
->gdp
, 0);
266 bdev
->bd_inode
->i_blkbits
= blksize_bits(fdata
->blksize
);
270 while (fdata
->start_unit
<= fdata
->stop_unit
) {
271 cqr
= device
->discipline
->format_device(device
, fdata
);
274 rc
= dasd_sleep_on_interruptible(cqr
);
275 dasd_sfree_request(cqr
, cqr
->device
);
277 if (rc
!= -ERESTARTSYS
)
278 DEV_MESSAGE(KERN_ERR
, device
,
279 " Formatting of unit %d failed "
281 fdata
->start_unit
, rc
);
293 dasd_ioctl_format(struct block_device
*bdev
, int no
, long args
)
295 struct dasd_device
*device
;
296 struct format_data_t fdata
;
298 if (!capable(CAP_SYS_ADMIN
))
302 /* fdata == NULL is no longer a valid arg to dasd_format ! */
303 device
= bdev
->bd_disk
->private_data
;
307 if (test_bit(DASD_FLAG_RO
, &device
->flags
))
309 if (copy_from_user(&fdata
, (void __user
*) args
,
310 sizeof (struct format_data_t
)))
312 if (bdev
!= bdev
->bd_contains
) {
313 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
314 "Cannot low-level format a partition");
317 return dasd_format(device
, &fdata
);
320 #ifdef CONFIG_DASD_PROFILE
322 * Reset device profile information
325 dasd_ioctl_reset_profile(struct block_device
*bdev
, int no
, long args
)
327 struct dasd_device
*device
;
329 if (!capable(CAP_SYS_ADMIN
))
332 device
= bdev
->bd_disk
->private_data
;
336 memset(&device
->profile
, 0, sizeof (struct dasd_profile_info_t
));
341 * Return device profile information
344 dasd_ioctl_read_profile(struct block_device
*bdev
, int no
, long args
)
346 struct dasd_device
*device
;
348 device
= bdev
->bd_disk
->private_data
;
352 if (copy_to_user((long __user
*) args
, (long *) &device
->profile
,
353 sizeof (struct dasd_profile_info_t
)))
359 dasd_ioctl_reset_profile(struct block_device
*bdev
, int no
, long args
)
365 dasd_ioctl_read_profile(struct block_device
*bdev
, int no
, long args
)
372 * Return dasd information. Used for BIODASDINFO and BIODASDINFO2.
375 dasd_ioctl_information(struct block_device
*bdev
, int no
, long args
)
377 struct dasd_device
*device
;
378 struct dasd_information2_t
*dasd_info
;
381 struct ccw_device
*cdev
;
383 device
= bdev
->bd_disk
->private_data
;
387 if (!device
->discipline
->fill_info
)
390 dasd_info
= kmalloc(sizeof(struct dasd_information2_t
), GFP_KERNEL
);
391 if (dasd_info
== NULL
)
394 rc
= device
->discipline
->fill_info(device
, dasd_info
);
402 dasd_info
->devno
= _ccw_device_get_device_number(device
->cdev
);
403 dasd_info
->schid
= _ccw_device_get_subchannel_number(device
->cdev
);
404 dasd_info
->cu_type
= cdev
->id
.cu_type
;
405 dasd_info
->cu_model
= cdev
->id
.cu_model
;
406 dasd_info
->dev_type
= cdev
->id
.dev_type
;
407 dasd_info
->dev_model
= cdev
->id
.dev_model
;
408 dasd_info
->open_count
= atomic_read(&device
->open_count
);
409 dasd_info
->status
= device
->state
;
412 * check if device is really formatted
413 * LDL / CDL was returned by 'fill_info'
415 if ((device
->state
< DASD_STATE_READY
) ||
416 (dasd_check_blocksize(device
->bp_block
)))
417 dasd_info
->format
= DASD_FORMAT_NONE
;
419 dasd_info
->features
|= test_bit(DASD_FLAG_RO
, &device
->flags
) ?
420 DASD_FEATURE_READONLY
: DASD_FEATURE_DEFAULT
;
422 if (device
->discipline
)
423 memcpy(dasd_info
->type
, device
->discipline
->name
, 4);
425 memcpy(dasd_info
->type
, "none", 4);
426 dasd_info
->req_queue_len
= 0;
427 dasd_info
->chanq_len
= 0;
428 if (device
->request_queue
->request_fn
) {
430 #ifdef DASD_EXTENDED_PROFILING
433 spin_lock_irqsave(&device
->lock
, flags
);
434 list_for_each(l
, &device
->request_queue
->queue_head
)
435 dasd_info
->req_queue_len
++;
436 spin_unlock_irqrestore(&device
->lock
, flags
);
438 #endif /* DASD_EXTENDED_PROFILING */
439 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
440 list_for_each(l
, &device
->ccw_queue
)
441 dasd_info
->chanq_len
++;
442 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
),
447 if (copy_to_user((long __user
*) args
, (long *) dasd_info
,
448 ((no
== (unsigned int) BIODASDINFO2
) ?
449 sizeof (struct dasd_information2_t
) :
450 sizeof (struct dasd_information_t
))))
460 dasd_ioctl_set_ro(struct block_device
*bdev
, int no
, long args
)
462 struct dasd_device
*device
;
465 if (!capable(CAP_SYS_ADMIN
))
467 if (bdev
!= bdev
->bd_contains
)
468 // ro setting is not allowed for partitions
470 if (get_user(intval
, (int __user
*) args
))
472 device
= bdev
->bd_disk
->private_data
;
475 set_disk_ro(bdev
->bd_disk
, intval
);
477 set_bit(DASD_FLAG_RO
, &device
->flags
);
479 clear_bit(DASD_FLAG_RO
, &device
->flags
);
484 * Return disk geometry.
487 dasd_ioctl_getgeo(struct block_device
*bdev
, int no
, long args
)
489 struct hd_geometry geo
= { 0, };
490 struct dasd_device
*device
;
492 device
= bdev
->bd_disk
->private_data
;
496 if (device
== NULL
|| device
->discipline
== NULL
||
497 device
->discipline
->fill_geometry
== NULL
)
500 geo
= (struct hd_geometry
) {};
501 device
->discipline
->fill_geometry(device
, &geo
);
502 geo
.start
= get_start_sect(bdev
) >> device
->s2b_shift
;
503 if (copy_to_user((struct hd_geometry __user
*) args
, &geo
,
504 sizeof (struct hd_geometry
)))
511 * List of static ioctls.
513 static struct { int no
; dasd_ioctl_fn_t fn
; } dasd_ioctls
[] =
515 { BIODASDDISABLE
, dasd_ioctl_disable
},
516 { BIODASDENABLE
, dasd_ioctl_enable
},
517 { BIODASDQUIESCE
, dasd_ioctl_quiesce
},
518 { BIODASDRESUME
, dasd_ioctl_resume
},
519 { BIODASDFMT
, dasd_ioctl_format
},
520 { BIODASDINFO
, dasd_ioctl_information
},
521 { BIODASDINFO2
, dasd_ioctl_information
},
522 { BIODASDPRRD
, dasd_ioctl_read_profile
},
523 { BIODASDPRRST
, dasd_ioctl_reset_profile
},
524 { BLKROSET
, dasd_ioctl_set_ro
},
525 { DASDAPIVER
, dasd_ioctl_api_version
},
526 { HDIO_GETGEO
, dasd_ioctl_getgeo
},
531 dasd_ioctl_init(void)
535 for (i
= 0; dasd_ioctls
[i
].no
!= -1; i
++)
536 dasd_ioctl_no_register(NULL
, dasd_ioctls
[i
].no
,
543 dasd_ioctl_exit(void)
547 for (i
= 0; dasd_ioctls
[i
].no
!= -1; i
++)
548 dasd_ioctl_no_unregister(NULL
, dasd_ioctls
[i
].no
,
553 EXPORT_SYMBOL(dasd_ioctl_no_register
);
554 EXPORT_SYMBOL(dasd_ioctl_no_unregister
);