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
12 * i/o controls for the dasd driver.
14 #include <linux/config.h>
15 #include <linux/interrupt.h>
16 #include <linux/major.h>
18 #include <linux/blkpg.h>
20 #include <asm/ccwdev.h>
21 #include <asm/uaccess.h>
24 #define PRINTK_HEADER "dasd_ioctl:"
29 * SECTION: ioctl functions.
31 static struct list_head dasd_ioctl_list
= LIST_HEAD_INIT(dasd_ioctl_list
);
34 * Find the ioctl with number no.
36 static struct dasd_ioctl
*
37 dasd_find_ioctl(int no
)
39 struct dasd_ioctl
*ioctl
;
41 list_for_each_entry (ioctl
, &dasd_ioctl_list
, list
)
48 * Register ioctl with number no.
51 dasd_ioctl_no_register(struct module
*owner
, int no
, dasd_ioctl_fn_t handler
)
53 struct dasd_ioctl
*new;
54 if (dasd_find_ioctl(no
))
56 new = kmalloc(sizeof (struct dasd_ioctl
), GFP_KERNEL
);
61 new->handler
= handler
;
62 list_add(&new->list
, &dasd_ioctl_list
);
67 * Deregister ioctl with number no.
70 dasd_ioctl_no_unregister(struct module
*owner
, int no
, dasd_ioctl_fn_t handler
)
72 struct dasd_ioctl
*old
= dasd_find_ioctl(no
);
75 if (old
->no
!= no
|| old
->handler
!= handler
|| owner
!= old
->owner
)
83 dasd_ioctl(struct inode
*inp
, struct file
*filp
,
84 unsigned int no
, unsigned long data
)
86 struct block_device
*bdev
= inp
->i_bdev
;
87 struct dasd_device
*device
= bdev
->bd_disk
->private_data
;
88 struct dasd_ioctl
*ioctl
;
92 if ((_IOC_DIR(no
) != _IOC_NONE
) && (data
== 0)) {
93 PRINT_DEBUG("empty data ptr");
96 dir
= _IOC_DIR (no
) == _IOC_NONE
? "0" :
97 _IOC_DIR (no
) == _IOC_READ
? "r" :
98 _IOC_DIR (no
) == _IOC_WRITE
? "w" :
99 _IOC_DIR (no
) == (_IOC_READ
| _IOC_WRITE
) ? "rw" : "u";
100 DBF_DEV_EVENT(DBF_DEBUG
, device
,
101 "ioctl 0x%08x %s'0x%x'%d(%d) with data %8lx", no
,
102 dir
, _IOC_TYPE(no
), _IOC_NR(no
), _IOC_SIZE(no
), data
);
103 /* Search for ioctl no in the ioctl list. */
104 list_for_each_entry(ioctl
, &dasd_ioctl_list
, list
) {
105 if (ioctl
->no
== no
) {
106 /* Found a matching ioctl. Call it. */
107 if (!try_module_get(ioctl
->owner
))
109 rc
= ioctl
->handler(bdev
, no
, data
);
110 module_put(ioctl
->owner
);
114 /* No ioctl with number no. */
115 DBF_DEV_EVENT(DBF_INFO
, device
,
116 "unknown ioctl 0x%08x=%s'0x%x'%d(%d) data %8lx", no
,
117 dir
, _IOC_TYPE(no
), _IOC_NR(no
), _IOC_SIZE(no
), data
);
122 dasd_ioctl_api_version(struct block_device
*bdev
, int no
, long args
)
124 int ver
= DASD_API_VERSION
;
125 return put_user(ver
, (int __user
*) args
);
130 * used by dasdfmt after BIODASDDISABLE to retrigger blocksize detection
133 dasd_ioctl_enable(struct block_device
*bdev
, int no
, long args
)
135 struct dasd_device
*device
;
137 if (!capable(CAP_SYS_ADMIN
))
139 device
= bdev
->bd_disk
->private_data
;
142 dasd_enable_device(device
);
143 /* Formatting the dasd device can change the capacity. */
145 i_size_write(bdev
->bd_inode
, (loff_t
)get_capacity(device
->gdp
) << 9);
152 * Used by dasdfmt. Disable I/O operations but allow ioctls.
155 dasd_ioctl_disable(struct block_device
*bdev
, int no
, long args
)
157 struct dasd_device
*device
;
159 if (!capable(CAP_SYS_ADMIN
))
161 device
= bdev
->bd_disk
->private_data
;
165 * Man this is sick. We don't do a real disable but only downgrade
166 * the device to DASD_STATE_BASIC. The reason is that dasdfmt uses
167 * BIODASDDISABLE to disable accesses to the device via the block
168 * device layer but it still wants to do i/o on the device by
169 * using the BIODASDFMT ioctl. Therefore the correct state for the
170 * device is DASD_STATE_BASIC that allows to do basic i/o.
172 dasd_set_target_state(device
, DASD_STATE_BASIC
);
174 * Set i_size to zero, since read, write, etc. check against this
178 i_size_write(bdev
->bd_inode
, 0);
187 dasd_ioctl_quiesce(struct block_device
*bdev
, int no
, long args
)
189 struct dasd_device
*device
;
192 if (!capable (CAP_SYS_ADMIN
))
195 device
= bdev
->bd_disk
->private_data
;
199 DEV_MESSAGE (KERN_DEBUG
, device
, "%s",
200 "Quiesce IO on device");
201 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
202 device
->stopped
|= DASD_STOPPED_QUIESCE
;
203 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
212 dasd_ioctl_resume(struct block_device
*bdev
, int no
, long args
)
214 struct dasd_device
*device
;
217 if (!capable (CAP_SYS_ADMIN
))
220 device
= bdev
->bd_disk
->private_data
;
224 DEV_MESSAGE (KERN_DEBUG
, device
, "%s",
225 "resume IO on device");
227 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
228 device
->stopped
&= ~DASD_STOPPED_QUIESCE
;
229 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
231 dasd_schedule_bh (device
);
236 * performs formatting of _device_ according to _fdata_
237 * Note: The discipline's format_function is assumed to deliver formatting
238 * commands to format a single unit of the device. In terms of the ECKD
239 * devices this means CCWs are generated to format a single track.
242 dasd_format(struct dasd_device
* device
, struct format_data_t
* fdata
)
244 struct dasd_ccw_req
*cqr
;
247 if (device
->discipline
->format_device
== NULL
)
250 if (device
->state
!= DASD_STATE_BASIC
) {
251 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
252 "dasd_format: device is not disabled! ");
256 DBF_DEV_EVENT(DBF_NOTICE
, device
,
257 "formatting units %d to %d (%d B blocks) flags %d",
259 fdata
->stop_unit
, fdata
->blksize
, fdata
->intensity
);
261 /* Since dasdfmt keeps the device open after it was disabled,
262 * there still exists an inode for this device.
263 * We must update i_blkbits, otherwise we might get errors when
264 * enabling the device later.
266 if (fdata
->start_unit
== 0) {
267 struct block_device
*bdev
= bdget_disk(device
->gdp
, 0);
268 bdev
->bd_inode
->i_blkbits
= blksize_bits(fdata
->blksize
);
272 while (fdata
->start_unit
<= fdata
->stop_unit
) {
273 cqr
= device
->discipline
->format_device(device
, fdata
);
276 rc
= dasd_sleep_on_interruptible(cqr
);
277 dasd_sfree_request(cqr
, cqr
->device
);
279 if (rc
!= -ERESTARTSYS
)
280 DEV_MESSAGE(KERN_ERR
, device
,
281 " Formatting of unit %d failed "
283 fdata
->start_unit
, rc
);
295 dasd_ioctl_format(struct block_device
*bdev
, int no
, long args
)
297 struct dasd_device
*device
;
298 struct format_data_t fdata
;
301 if (!capable(CAP_SYS_ADMIN
))
305 /* fdata == NULL is no longer a valid arg to dasd_format ! */
306 device
= bdev
->bd_disk
->private_data
;
311 feature_ro
= dasd_get_feature(device
->cdev
, DASD_FEATURE_READONLY
);
316 if (copy_from_user(&fdata
, (void __user
*) args
,
317 sizeof (struct format_data_t
)))
319 if (bdev
!= bdev
->bd_contains
) {
320 DEV_MESSAGE(KERN_WARNING
, device
, "%s",
321 "Cannot low-level format a partition");
324 return dasd_format(device
, &fdata
);
327 #ifdef CONFIG_DASD_PROFILE
329 * Reset device profile information
332 dasd_ioctl_reset_profile(struct block_device
*bdev
, int no
, long args
)
334 struct dasd_device
*device
;
336 if (!capable(CAP_SYS_ADMIN
))
339 device
= bdev
->bd_disk
->private_data
;
343 memset(&device
->profile
, 0, sizeof (struct dasd_profile_info_t
));
348 * Return device profile information
351 dasd_ioctl_read_profile(struct block_device
*bdev
, int no
, long args
)
353 struct dasd_device
*device
;
355 device
= bdev
->bd_disk
->private_data
;
359 if (copy_to_user((long __user
*) args
, (long *) &device
->profile
,
360 sizeof (struct dasd_profile_info_t
)))
366 dasd_ioctl_reset_profile(struct block_device
*bdev
, int no
, long args
)
372 dasd_ioctl_read_profile(struct block_device
*bdev
, int no
, long args
)
379 * Return dasd information. Used for BIODASDINFO and BIODASDINFO2.
382 dasd_ioctl_information(struct block_device
*bdev
, int no
, long args
)
384 struct dasd_device
*device
;
385 struct dasd_information2_t
*dasd_info
;
388 struct ccw_device
*cdev
;
390 device
= bdev
->bd_disk
->private_data
;
394 if (!device
->discipline
->fill_info
)
397 feature_ro
= dasd_get_feature(device
->cdev
, DASD_FEATURE_READONLY
);
401 dasd_info
= kmalloc(sizeof(struct dasd_information2_t
), GFP_KERNEL
);
402 if (dasd_info
== NULL
)
405 rc
= device
->discipline
->fill_info(device
, dasd_info
);
413 dasd_info
->devno
= _ccw_device_get_device_number(device
->cdev
);
414 dasd_info
->schid
= _ccw_device_get_subchannel_number(device
->cdev
);
415 dasd_info
->cu_type
= cdev
->id
.cu_type
;
416 dasd_info
->cu_model
= cdev
->id
.cu_model
;
417 dasd_info
->dev_type
= cdev
->id
.dev_type
;
418 dasd_info
->dev_model
= cdev
->id
.dev_model
;
419 dasd_info
->open_count
= atomic_read(&device
->open_count
);
420 dasd_info
->status
= device
->state
;
423 * check if device is really formatted
424 * LDL / CDL was returned by 'fill_info'
426 if ((device
->state
< DASD_STATE_READY
) ||
427 (dasd_check_blocksize(device
->bp_block
)))
428 dasd_info
->format
= DASD_FORMAT_NONE
;
430 dasd_info
->features
|= feature_ro
;
432 if (device
->discipline
)
433 memcpy(dasd_info
->type
, device
->discipline
->name
, 4);
435 memcpy(dasd_info
->type
, "none", 4);
436 dasd_info
->req_queue_len
= 0;
437 dasd_info
->chanq_len
= 0;
438 if (device
->request_queue
->request_fn
) {
440 #ifdef DASD_EXTENDED_PROFILING
443 spin_lock_irqsave(&device
->lock
, flags
);
444 list_for_each(l
, &device
->request_queue
->queue_head
)
445 dasd_info
->req_queue_len
++;
446 spin_unlock_irqrestore(&device
->lock
, flags
);
448 #endif /* DASD_EXTENDED_PROFILING */
449 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
450 list_for_each(l
, &device
->ccw_queue
)
451 dasd_info
->chanq_len
++;
452 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
),
457 if (copy_to_user((long __user
*) args
, (long *) dasd_info
,
458 ((no
== (unsigned int) BIODASDINFO2
) ?
459 sizeof (struct dasd_information2_t
) :
460 sizeof (struct dasd_information_t
))))
470 dasd_ioctl_set_ro(struct block_device
*bdev
, int no
, long args
)
472 struct dasd_device
*device
;
475 if (!capable(CAP_SYS_ADMIN
))
477 if (bdev
!= bdev
->bd_contains
)
478 // ro setting is not allowed for partitions
480 if (get_user(intval
, (int __user
*) args
))
482 device
= bdev
->bd_disk
->private_data
;
486 set_disk_ro(bdev
->bd_disk
, intval
);
487 rc
= dasd_set_feature(device
->cdev
, DASD_FEATURE_READONLY
, intval
);
493 * Return disk geometry.
496 dasd_ioctl_getgeo(struct block_device
*bdev
, int no
, long args
)
498 struct hd_geometry geo
= { 0, };
499 struct dasd_device
*device
;
501 device
= bdev
->bd_disk
->private_data
;
505 if (device
== NULL
|| device
->discipline
== NULL
||
506 device
->discipline
->fill_geometry
== NULL
)
509 geo
= (struct hd_geometry
) {};
510 device
->discipline
->fill_geometry(device
, &geo
);
511 geo
.start
= get_start_sect(bdev
) >> device
->s2b_shift
;
512 if (copy_to_user((struct hd_geometry __user
*) args
, &geo
,
513 sizeof (struct hd_geometry
)))
520 * List of static ioctls.
522 static struct { int no
; dasd_ioctl_fn_t fn
; } dasd_ioctls
[] =
524 { BIODASDDISABLE
, dasd_ioctl_disable
},
525 { BIODASDENABLE
, dasd_ioctl_enable
},
526 { BIODASDQUIESCE
, dasd_ioctl_quiesce
},
527 { BIODASDRESUME
, dasd_ioctl_resume
},
528 { BIODASDFMT
, dasd_ioctl_format
},
529 { BIODASDINFO
, dasd_ioctl_information
},
530 { BIODASDINFO2
, dasd_ioctl_information
},
531 { BIODASDPRRD
, dasd_ioctl_read_profile
},
532 { BIODASDPRRST
, dasd_ioctl_reset_profile
},
533 { BLKROSET
, dasd_ioctl_set_ro
},
534 { DASDAPIVER
, dasd_ioctl_api_version
},
535 { HDIO_GETGEO
, dasd_ioctl_getgeo
},
540 dasd_ioctl_init(void)
544 for (i
= 0; dasd_ioctls
[i
].no
!= -1; i
++)
545 dasd_ioctl_no_register(NULL
, dasd_ioctls
[i
].no
,
552 dasd_ioctl_exit(void)
556 for (i
= 0; dasd_ioctls
[i
].no
!= -1; i
++)
557 dasd_ioctl_no_unregister(NULL
, dasd_ioctls
[i
].no
,
562 EXPORT_SYMBOL(dasd_ioctl_no_register
);
563 EXPORT_SYMBOL(dasd_ioctl_no_unregister
);