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.
13 #define KMSG_COMPONENT "dasd"
15 #include <linux/interrupt.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>
23 #include <asm/uaccess.h>
26 #define PRINTK_HEADER "dasd_ioctl:"
32 dasd_ioctl_api_version(void __user
*argp
)
34 int ver
= DASD_API_VERSION
;
35 return put_user(ver
, (int __user
*)argp
);
40 * used by dasdfmt after BIODASDDISABLE to retrigger blocksize detection
43 dasd_ioctl_enable(struct block_device
*bdev
)
45 struct dasd_device
*base
;
47 if (!capable(CAP_SYS_ADMIN
))
50 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
54 dasd_enable_device(base
);
55 /* Formatting the dasd device can change the capacity. */
56 mutex_lock(&bdev
->bd_mutex
);
57 i_size_write(bdev
->bd_inode
,
58 (loff_t
)get_capacity(base
->block
->gdp
) << 9);
59 mutex_unlock(&bdev
->bd_mutex
);
60 dasd_put_device(base
);
66 * Used by dasdfmt. Disable I/O operations but allow ioctls.
69 dasd_ioctl_disable(struct block_device
*bdev
)
71 struct dasd_device
*base
;
73 if (!capable(CAP_SYS_ADMIN
))
76 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
80 * Man this is sick. We don't do a real disable but only downgrade
81 * the device to DASD_STATE_BASIC. The reason is that dasdfmt uses
82 * BIODASDDISABLE to disable accesses to the device via the block
83 * device layer but it still wants to do i/o on the device by
84 * using the BIODASDFMT ioctl. Therefore the correct state for the
85 * device is DASD_STATE_BASIC that allows to do basic i/o.
87 dasd_set_target_state(base
, DASD_STATE_BASIC
);
89 * Set i_size to zero, since read, write, etc. check against this
92 mutex_lock(&bdev
->bd_mutex
);
93 i_size_write(bdev
->bd_inode
, 0);
94 mutex_unlock(&bdev
->bd_mutex
);
95 dasd_put_device(base
);
102 static int dasd_ioctl_quiesce(struct dasd_block
*block
)
105 struct dasd_device
*base
;
108 if (!capable (CAP_SYS_ADMIN
))
111 pr_info("%s: The DASD has been put in the quiesce "
112 "state\n", dev_name(&base
->cdev
->dev
));
113 spin_lock_irqsave(get_ccwdev_lock(base
->cdev
), flags
);
114 dasd_device_set_stop_bits(base
, DASD_STOPPED_QUIESCE
);
115 spin_unlock_irqrestore(get_ccwdev_lock(base
->cdev
), flags
);
123 static int dasd_ioctl_resume(struct dasd_block
*block
)
126 struct dasd_device
*base
;
129 if (!capable (CAP_SYS_ADMIN
))
132 pr_info("%s: I/O operations have been resumed "
133 "on the DASD\n", dev_name(&base
->cdev
->dev
));
134 spin_lock_irqsave(get_ccwdev_lock(base
->cdev
), flags
);
135 dasd_device_remove_stop_bits(base
, DASD_STOPPED_QUIESCE
);
136 spin_unlock_irqrestore(get_ccwdev_lock(base
->cdev
), flags
);
138 dasd_schedule_block_bh(block
);
143 * performs formatting of _device_ according to _fdata_
144 * Note: The discipline's format_function is assumed to deliver formatting
145 * commands to format a single unit of the device. In terms of the ECKD
146 * devices this means CCWs are generated to format a single track.
148 static int dasd_format(struct dasd_block
*block
, struct format_data_t
*fdata
)
150 struct dasd_ccw_req
*cqr
;
151 struct dasd_device
*base
;
155 if (base
->discipline
->format_device
== NULL
)
158 if (base
->state
!= DASD_STATE_BASIC
) {
159 pr_warning("%s: The DASD cannot be formatted while it is "
160 "enabled\n", dev_name(&base
->cdev
->dev
));
164 DBF_DEV_EVENT(DBF_NOTICE
, base
,
165 "formatting units %u to %u (%u B blocks) flags %u",
167 fdata
->stop_unit
, fdata
->blksize
, fdata
->intensity
);
169 /* Since dasdfmt keeps the device open after it was disabled,
170 * there still exists an inode for this device.
171 * We must update i_blkbits, otherwise we might get errors when
172 * enabling the device later.
174 if (fdata
->start_unit
== 0) {
175 struct block_device
*bdev
= bdget_disk(block
->gdp
, 0);
176 bdev
->bd_inode
->i_blkbits
= blksize_bits(fdata
->blksize
);
180 while (fdata
->start_unit
<= fdata
->stop_unit
) {
181 cqr
= base
->discipline
->format_device(base
, fdata
);
184 rc
= dasd_sleep_on_interruptible(cqr
);
185 dasd_sfree_request(cqr
, cqr
->memdev
);
187 if (rc
!= -ERESTARTSYS
)
188 pr_err("%s: Formatting unit %d failed with "
189 "rc=%d\n", dev_name(&base
->cdev
->dev
),
190 fdata
->start_unit
, rc
);
202 dasd_ioctl_format(struct block_device
*bdev
, void __user
*argp
)
204 struct dasd_device
*base
;
205 struct format_data_t fdata
;
208 if (!capable(CAP_SYS_ADMIN
))
212 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
215 if (base
->features
& DASD_FEATURE_READONLY
||
216 test_bit(DASD_FLAG_DEVICE_RO
, &base
->flags
)) {
217 dasd_put_device(base
);
220 if (copy_from_user(&fdata
, argp
, sizeof(struct format_data_t
))) {
221 dasd_put_device(base
);
224 if (bdev
!= bdev
->bd_contains
) {
225 pr_warning("%s: The specified DASD is a partition and cannot "
227 dev_name(&base
->cdev
->dev
));
228 dasd_put_device(base
);
231 rc
= dasd_format(base
->block
, &fdata
);
232 dasd_put_device(base
);
236 #ifdef CONFIG_DASD_PROFILE
238 * Reset device profile information
240 static int dasd_ioctl_reset_profile(struct dasd_block
*block
)
242 memset(&block
->profile
, 0, sizeof(struct dasd_profile_info_t
));
247 * Return device profile information
249 static int dasd_ioctl_read_profile(struct dasd_block
*block
, void __user
*argp
)
251 if (dasd_profile_level
== DASD_PROFILE_OFF
)
253 if (copy_to_user(argp
, &block
->profile
,
254 sizeof(struct dasd_profile_info_t
)))
259 static int dasd_ioctl_reset_profile(struct dasd_block
*block
)
264 static int dasd_ioctl_read_profile(struct dasd_block
*block
, void __user
*argp
)
271 * Return dasd information. Used for BIODASDINFO and BIODASDINFO2.
273 static int dasd_ioctl_information(struct dasd_block
*block
,
274 unsigned int cmd
, void __user
*argp
)
276 struct dasd_information2_t
*dasd_info
;
279 struct dasd_device
*base
;
280 struct ccw_device
*cdev
;
281 struct ccw_dev_id dev_id
;
284 if (!base
->discipline
|| !base
->discipline
->fill_info
)
287 dasd_info
= kzalloc(sizeof(struct dasd_information2_t
), GFP_KERNEL
);
288 if (dasd_info
== NULL
)
291 rc
= base
->discipline
->fill_info(base
, dasd_info
);
298 ccw_device_get_id(cdev
, &dev_id
);
300 dasd_info
->devno
= dev_id
.devno
;
301 dasd_info
->schid
= _ccw_device_get_subchannel_number(base
->cdev
);
302 dasd_info
->cu_type
= cdev
->id
.cu_type
;
303 dasd_info
->cu_model
= cdev
->id
.cu_model
;
304 dasd_info
->dev_type
= cdev
->id
.dev_type
;
305 dasd_info
->dev_model
= cdev
->id
.dev_model
;
306 dasd_info
->status
= base
->state
;
308 * The open_count is increased for every opener, that includes
309 * the blkdev_get in dasd_scan_partitions.
310 * This must be hidden from user-space.
312 dasd_info
->open_count
= atomic_read(&block
->open_count
);
314 dasd_info
->open_count
++;
317 * check if device is really formatted
318 * LDL / CDL was returned by 'fill_info'
320 if ((base
->state
< DASD_STATE_READY
) ||
321 (dasd_check_blocksize(block
->bp_block
)))
322 dasd_info
->format
= DASD_FORMAT_NONE
;
324 dasd_info
->features
|=
325 ((base
->features
& DASD_FEATURE_READONLY
) != 0);
327 memcpy(dasd_info
->type
, base
->discipline
->name
, 4);
329 if (block
->request_queue
->request_fn
) {
331 #ifdef DASD_EXTENDED_PROFILING
334 spin_lock_irqsave(&block
->lock
, flags
);
335 list_for_each(l
, &block
->request_queue
->queue_head
)
336 dasd_info
->req_queue_len
++;
337 spin_unlock_irqrestore(&block
->lock
, flags
);
339 #endif /* DASD_EXTENDED_PROFILING */
340 spin_lock_irqsave(get_ccwdev_lock(base
->cdev
), flags
);
341 list_for_each(l
, &base
->ccw_queue
)
342 dasd_info
->chanq_len
++;
343 spin_unlock_irqrestore(get_ccwdev_lock(base
->cdev
),
348 if (copy_to_user(argp
, dasd_info
,
349 ((cmd
== (unsigned int) BIODASDINFO2
) ?
350 sizeof(struct dasd_information2_t
) :
351 sizeof(struct dasd_information_t
))))
361 dasd_ioctl_set_ro(struct block_device
*bdev
, void __user
*argp
)
363 struct dasd_device
*base
;
366 if (!capable(CAP_SYS_ADMIN
))
368 if (bdev
!= bdev
->bd_contains
)
369 // ro setting is not allowed for partitions
371 if (get_user(intval
, (int __user
*)argp
))
373 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
376 if (!intval
&& test_bit(DASD_FLAG_DEVICE_RO
, &base
->flags
)) {
377 dasd_put_device(base
);
380 set_disk_ro(bdev
->bd_disk
, intval
);
381 rc
= dasd_set_feature(base
->cdev
, DASD_FEATURE_READONLY
, intval
);
382 dasd_put_device(base
);
386 static int dasd_ioctl_readall_cmb(struct dasd_block
*block
, unsigned int cmd
,
387 struct cmbdata __user
*argp
)
389 size_t size
= _IOC_SIZE(cmd
);
393 ret
= cmf_readall(block
->base
->cdev
, &data
);
394 if (!ret
&& copy_to_user(argp
, &data
, min(size
, sizeof(*argp
))))
399 int dasd_ioctl(struct block_device
*bdev
, fmode_t mode
,
400 unsigned int cmd
, unsigned long arg
)
402 struct dasd_block
*block
;
403 struct dasd_device
*base
;
407 if (is_compat_task())
408 argp
= compat_ptr(arg
);
410 argp
= (void __user
*)arg
;
412 if ((_IOC_DIR(cmd
) != _IOC_NONE
) && !arg
) {
413 PRINT_DEBUG("empty data ptr");
417 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
424 rc
= dasd_ioctl_disable(bdev
);
427 rc
= dasd_ioctl_enable(bdev
);
430 rc
= dasd_ioctl_quiesce(block
);
433 rc
= dasd_ioctl_resume(block
);
436 rc
= dasd_ioctl_format(bdev
, argp
);
439 rc
= dasd_ioctl_information(block
, cmd
, argp
);
442 rc
= dasd_ioctl_information(block
, cmd
, argp
);
445 rc
= dasd_ioctl_read_profile(block
, argp
);
448 rc
= dasd_ioctl_reset_profile(block
);
451 rc
= dasd_ioctl_set_ro(bdev
, argp
);
454 rc
= dasd_ioctl_api_version(argp
);
456 case BIODASDCMFENABLE
:
457 rc
= enable_cmf(base
->cdev
);
459 case BIODASDCMFDISABLE
:
460 rc
= disable_cmf(base
->cdev
);
462 case BIODASDREADALLCMB
:
463 rc
= dasd_ioctl_readall_cmb(block
, cmd
, argp
);
466 /* if the discipline has an ioctl method try it. */
467 if (base
->discipline
->ioctl
) {
468 rc
= base
->discipline
->ioctl(block
, cmd
, argp
);
469 if (rc
== -ENOIOCTLCMD
)
474 dasd_put_device(base
);