2 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
3 * Horst Hummel <Horst.Hummel@de.ibm.com>
4 * Carsten Otte <Cotte@de.ibm.com>
5 * Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Bugreports.to..: <Linux390@de.ibm.com>
7 * Copyright IBM Corp. 1999, 2001
9 * i/o controls for the dasd driver.
12 #define KMSG_COMPONENT "dasd"
14 #include <linux/interrupt.h>
15 #include <linux/compat.h>
16 #include <linux/major.h>
18 #include <linux/blkpg.h>
19 #include <linux/slab.h>
20 #include <asm/compat.h>
21 #include <asm/ccwdev.h>
22 #include <asm/schid.h>
24 #include <asm/uaccess.h>
27 #define PRINTK_HEADER "dasd_ioctl:"
33 dasd_ioctl_api_version(void __user
*argp
)
35 int ver
= DASD_API_VERSION
;
36 return put_user(ver
, (int __user
*)argp
);
41 * used by dasdfmt after BIODASDDISABLE to retrigger blocksize detection
44 dasd_ioctl_enable(struct block_device
*bdev
)
46 struct dasd_device
*base
;
48 if (!capable(CAP_SYS_ADMIN
))
51 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
55 dasd_enable_device(base
);
56 /* Formatting the dasd device can change the capacity. */
57 mutex_lock(&bdev
->bd_mutex
);
58 i_size_write(bdev
->bd_inode
,
59 (loff_t
)get_capacity(base
->block
->gdp
) << 9);
60 mutex_unlock(&bdev
->bd_mutex
);
61 dasd_put_device(base
);
67 * Used by dasdfmt. Disable I/O operations but allow ioctls.
70 dasd_ioctl_disable(struct block_device
*bdev
)
72 struct dasd_device
*base
;
74 if (!capable(CAP_SYS_ADMIN
))
77 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
81 * Man this is sick. We don't do a real disable but only downgrade
82 * the device to DASD_STATE_BASIC. The reason is that dasdfmt uses
83 * BIODASDDISABLE to disable accesses to the device via the block
84 * device layer but it still wants to do i/o on the device by
85 * using the BIODASDFMT ioctl. Therefore the correct state for the
86 * device is DASD_STATE_BASIC that allows to do basic i/o.
88 dasd_set_target_state(base
, DASD_STATE_BASIC
);
90 * Set i_size to zero, since read, write, etc. check against this
93 mutex_lock(&bdev
->bd_mutex
);
94 i_size_write(bdev
->bd_inode
, 0);
95 mutex_unlock(&bdev
->bd_mutex
);
96 dasd_put_device(base
);
103 static int dasd_ioctl_quiesce(struct dasd_block
*block
)
106 struct dasd_device
*base
;
109 if (!capable (CAP_SYS_ADMIN
))
112 pr_info("%s: The DASD has been put in the quiesce "
113 "state\n", dev_name(&base
->cdev
->dev
));
114 spin_lock_irqsave(get_ccwdev_lock(base
->cdev
), flags
);
115 dasd_device_set_stop_bits(base
, DASD_STOPPED_QUIESCE
);
116 spin_unlock_irqrestore(get_ccwdev_lock(base
->cdev
), flags
);
124 static int dasd_ioctl_resume(struct dasd_block
*block
)
127 struct dasd_device
*base
;
130 if (!capable (CAP_SYS_ADMIN
))
133 pr_info("%s: I/O operations have been resumed "
134 "on the DASD\n", dev_name(&base
->cdev
->dev
));
135 spin_lock_irqsave(get_ccwdev_lock(base
->cdev
), flags
);
136 dasd_device_remove_stop_bits(base
, DASD_STOPPED_QUIESCE
);
137 spin_unlock_irqrestore(get_ccwdev_lock(base
->cdev
), flags
);
139 dasd_schedule_block_bh(block
);
144 * Abort all failfast I/O on a device.
146 static int dasd_ioctl_abortio(struct dasd_block
*block
)
149 struct dasd_device
*base
;
150 struct dasd_ccw_req
*cqr
, *n
;
153 if (!capable(CAP_SYS_ADMIN
))
156 if (test_and_set_bit(DASD_FLAG_ABORTALL
, &base
->flags
))
158 DBF_DEV_EVENT(DBF_NOTICE
, base
, "%s", "abortall flag set");
160 spin_lock_irqsave(&block
->request_queue_lock
, flags
);
161 spin_lock(&block
->queue_lock
);
162 list_for_each_entry_safe(cqr
, n
, &block
->ccw_queue
, blocklist
) {
163 if (test_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
) &&
164 cqr
->callback_data
&&
165 cqr
->callback_data
!= DASD_SLEEPON_START_TAG
&&
166 cqr
->callback_data
!= DASD_SLEEPON_END_TAG
) {
167 spin_unlock(&block
->queue_lock
);
168 blk_abort_request(cqr
->callback_data
);
169 spin_lock(&block
->queue_lock
);
172 spin_unlock(&block
->queue_lock
);
173 spin_unlock_irqrestore(&block
->request_queue_lock
, flags
);
175 dasd_schedule_block_bh(block
);
180 * Allow I/O on a device
182 static int dasd_ioctl_allowio(struct dasd_block
*block
)
184 struct dasd_device
*base
;
187 if (!capable(CAP_SYS_ADMIN
))
190 if (test_and_clear_bit(DASD_FLAG_ABORTALL
, &base
->flags
))
191 DBF_DEV_EVENT(DBF_NOTICE
, base
, "%s", "abortall flag unset");
197 * performs formatting of _device_ according to _fdata_
198 * Note: The discipline's format_function is assumed to deliver formatting
199 * commands to format multiple units of the device. In terms of the ECKD
200 * devices this means CCWs are generated to format multiple tracks.
203 dasd_format(struct dasd_block
*block
, struct format_data_t
*fdata
)
205 struct dasd_device
*base
;
209 if (base
->discipline
->format_device
== NULL
)
212 if (base
->state
!= DASD_STATE_BASIC
) {
213 pr_warn("%s: The DASD cannot be formatted while it is enabled\n",
214 dev_name(&base
->cdev
->dev
));
218 DBF_DEV_EVENT(DBF_NOTICE
, base
,
219 "formatting units %u to %u (%u B blocks) flags %u",
221 fdata
->stop_unit
, fdata
->blksize
, fdata
->intensity
);
223 /* Since dasdfmt keeps the device open after it was disabled,
224 * there still exists an inode for this device.
225 * We must update i_blkbits, otherwise we might get errors when
226 * enabling the device later.
228 if (fdata
->start_unit
== 0) {
229 struct block_device
*bdev
= bdget_disk(block
->gdp
, 0);
230 bdev
->bd_inode
->i_blkbits
= blksize_bits(fdata
->blksize
);
234 rc
= base
->discipline
->format_device(base
, fdata
);
245 dasd_ioctl_format(struct block_device
*bdev
, void __user
*argp
)
247 struct dasd_device
*base
;
248 struct format_data_t fdata
;
251 if (!capable(CAP_SYS_ADMIN
))
255 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
258 if (base
->features
& DASD_FEATURE_READONLY
||
259 test_bit(DASD_FLAG_DEVICE_RO
, &base
->flags
)) {
260 dasd_put_device(base
);
263 if (copy_from_user(&fdata
, argp
, sizeof(struct format_data_t
))) {
264 dasd_put_device(base
);
267 if (bdev
!= bdev
->bd_contains
) {
268 pr_warning("%s: The specified DASD is a partition and cannot "
270 dev_name(&base
->cdev
->dev
));
271 dasd_put_device(base
);
274 rc
= dasd_format(base
->block
, &fdata
);
275 dasd_put_device(base
);
279 #ifdef CONFIG_DASD_PROFILE
281 * Reset device profile information
283 static int dasd_ioctl_reset_profile(struct dasd_block
*block
)
285 dasd_profile_reset(&block
->profile
);
290 * Return device profile information
292 static int dasd_ioctl_read_profile(struct dasd_block
*block
, void __user
*argp
)
294 struct dasd_profile_info_t
*data
;
297 data
= kmalloc(sizeof(*data
), GFP_KERNEL
);
301 spin_lock_bh(&block
->profile
.lock
);
302 if (block
->profile
.data
) {
303 data
->dasd_io_reqs
= block
->profile
.data
->dasd_io_reqs
;
304 data
->dasd_io_sects
= block
->profile
.data
->dasd_io_sects
;
305 memcpy(data
->dasd_io_secs
, block
->profile
.data
->dasd_io_secs
,
306 sizeof(data
->dasd_io_secs
));
307 memcpy(data
->dasd_io_times
, block
->profile
.data
->dasd_io_times
,
308 sizeof(data
->dasd_io_times
));
309 memcpy(data
->dasd_io_timps
, block
->profile
.data
->dasd_io_timps
,
310 sizeof(data
->dasd_io_timps
));
311 memcpy(data
->dasd_io_time1
, block
->profile
.data
->dasd_io_time1
,
312 sizeof(data
->dasd_io_time1
));
313 memcpy(data
->dasd_io_time2
, block
->profile
.data
->dasd_io_time2
,
314 sizeof(data
->dasd_io_time2
));
315 memcpy(data
->dasd_io_time2ps
,
316 block
->profile
.data
->dasd_io_time2ps
,
317 sizeof(data
->dasd_io_time2ps
));
318 memcpy(data
->dasd_io_time3
, block
->profile
.data
->dasd_io_time3
,
319 sizeof(data
->dasd_io_time3
));
320 memcpy(data
->dasd_io_nr_req
,
321 block
->profile
.data
->dasd_io_nr_req
,
322 sizeof(data
->dasd_io_nr_req
));
323 spin_unlock_bh(&block
->profile
.lock
);
325 spin_unlock_bh(&block
->profile
.lock
);
329 if (copy_to_user(argp
, data
, sizeof(*data
)))
336 static int dasd_ioctl_reset_profile(struct dasd_block
*block
)
341 static int dasd_ioctl_read_profile(struct dasd_block
*block
, void __user
*argp
)
348 * Return dasd information. Used for BIODASDINFO and BIODASDINFO2.
350 static int dasd_ioctl_information(struct dasd_block
*block
,
351 unsigned int cmd
, void __user
*argp
)
353 struct dasd_information2_t
*dasd_info
;
354 struct subchannel_id sch_id
;
355 struct ccw_dev_id dev_id
;
356 struct dasd_device
*base
;
357 struct ccw_device
*cdev
;
362 if (!base
->discipline
|| !base
->discipline
->fill_info
)
365 dasd_info
= kzalloc(sizeof(struct dasd_information2_t
), GFP_KERNEL
);
366 if (dasd_info
== NULL
)
369 rc
= base
->discipline
->fill_info(base
, dasd_info
);
376 ccw_device_get_id(cdev
, &dev_id
);
377 ccw_device_get_schid(cdev
, &sch_id
);
379 dasd_info
->devno
= dev_id
.devno
;
380 dasd_info
->schid
= sch_id
.sch_no
;
381 dasd_info
->cu_type
= cdev
->id
.cu_type
;
382 dasd_info
->cu_model
= cdev
->id
.cu_model
;
383 dasd_info
->dev_type
= cdev
->id
.dev_type
;
384 dasd_info
->dev_model
= cdev
->id
.dev_model
;
385 dasd_info
->status
= base
->state
;
387 * The open_count is increased for every opener, that includes
388 * the blkdev_get in dasd_scan_partitions.
389 * This must be hidden from user-space.
391 dasd_info
->open_count
= atomic_read(&block
->open_count
);
393 dasd_info
->open_count
++;
396 * check if device is really formatted
397 * LDL / CDL was returned by 'fill_info'
399 if ((base
->state
< DASD_STATE_READY
) ||
400 (dasd_check_blocksize(block
->bp_block
)))
401 dasd_info
->format
= DASD_FORMAT_NONE
;
403 dasd_info
->features
|=
404 ((base
->features
& DASD_FEATURE_READONLY
) != 0);
406 memcpy(dasd_info
->type
, base
->discipline
->name
, 4);
408 if (block
->request_queue
->request_fn
) {
410 #ifdef DASD_EXTENDED_PROFILING
413 spin_lock_irqsave(&block
->lock
, flags
);
414 list_for_each(l
, &block
->request_queue
->queue_head
)
415 dasd_info
->req_queue_len
++;
416 spin_unlock_irqrestore(&block
->lock
, flags
);
418 #endif /* DASD_EXTENDED_PROFILING */
419 spin_lock_irqsave(get_ccwdev_lock(base
->cdev
), flags
);
420 list_for_each(l
, &base
->ccw_queue
)
421 dasd_info
->chanq_len
++;
422 spin_unlock_irqrestore(get_ccwdev_lock(base
->cdev
),
427 if (copy_to_user(argp
, dasd_info
,
428 ((cmd
== (unsigned int) BIODASDINFO2
) ?
429 sizeof(struct dasd_information2_t
) :
430 sizeof(struct dasd_information_t
))))
440 dasd_ioctl_set_ro(struct block_device
*bdev
, void __user
*argp
)
442 struct dasd_device
*base
;
445 if (!capable(CAP_SYS_ADMIN
))
447 if (bdev
!= bdev
->bd_contains
)
448 // ro setting is not allowed for partitions
450 if (get_user(intval
, (int __user
*)argp
))
452 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
455 if (!intval
&& test_bit(DASD_FLAG_DEVICE_RO
, &base
->flags
)) {
456 dasd_put_device(base
);
459 set_disk_ro(bdev
->bd_disk
, intval
);
460 rc
= dasd_set_feature(base
->cdev
, DASD_FEATURE_READONLY
, intval
);
461 dasd_put_device(base
);
465 static int dasd_ioctl_readall_cmb(struct dasd_block
*block
, unsigned int cmd
,
466 struct cmbdata __user
*argp
)
468 size_t size
= _IOC_SIZE(cmd
);
472 ret
= cmf_readall(block
->base
->cdev
, &data
);
473 if (!ret
&& copy_to_user(argp
, &data
, min(size
, sizeof(*argp
))))
478 int dasd_ioctl(struct block_device
*bdev
, fmode_t mode
,
479 unsigned int cmd
, unsigned long arg
)
481 struct dasd_block
*block
;
482 struct dasd_device
*base
;
486 if (is_compat_task())
487 argp
= compat_ptr(arg
);
489 argp
= (void __user
*)arg
;
491 if ((_IOC_DIR(cmd
) != _IOC_NONE
) && !arg
) {
492 PRINT_DEBUG("empty data ptr");
496 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
503 rc
= dasd_ioctl_disable(bdev
);
506 rc
= dasd_ioctl_enable(bdev
);
509 rc
= dasd_ioctl_quiesce(block
);
512 rc
= dasd_ioctl_resume(block
);
515 rc
= dasd_ioctl_abortio(block
);
518 rc
= dasd_ioctl_allowio(block
);
521 rc
= dasd_ioctl_format(bdev
, argp
);
524 rc
= dasd_ioctl_information(block
, cmd
, argp
);
527 rc
= dasd_ioctl_information(block
, cmd
, argp
);
530 rc
= dasd_ioctl_read_profile(block
, argp
);
533 rc
= dasd_ioctl_reset_profile(block
);
536 rc
= dasd_ioctl_set_ro(bdev
, argp
);
539 rc
= dasd_ioctl_api_version(argp
);
541 case BIODASDCMFENABLE
:
542 rc
= enable_cmf(base
->cdev
);
544 case BIODASDCMFDISABLE
:
545 rc
= disable_cmf(base
->cdev
);
547 case BIODASDREADALLCMB
:
548 rc
= dasd_ioctl_readall_cmb(block
, cmd
, argp
);
551 /* if the discipline has an ioctl method try it. */
553 if (base
->discipline
->ioctl
)
554 rc
= base
->discipline
->ioctl(block
, cmd
, argp
);
556 dasd_put_device(base
);