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/smp_lock.h>
20 #include <linux/slab.h>
21 #include <asm/compat.h>
22 #include <asm/ccwdev.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_block
*block
= bdev
->bd_disk
->private_data
;
48 if (!capable(CAP_SYS_ADMIN
))
51 dasd_enable_device(block
->base
);
52 /* Formatting the dasd device can change the capacity. */
53 mutex_lock(&bdev
->bd_mutex
);
54 i_size_write(bdev
->bd_inode
, (loff_t
)get_capacity(block
->gdp
) << 9);
55 mutex_unlock(&bdev
->bd_mutex
);
61 * Used by dasdfmt. Disable I/O operations but allow ioctls.
64 dasd_ioctl_disable(struct block_device
*bdev
)
66 struct dasd_block
*block
= bdev
->bd_disk
->private_data
;
68 if (!capable(CAP_SYS_ADMIN
))
72 * Man this is sick. We don't do a real disable but only downgrade
73 * the device to DASD_STATE_BASIC. The reason is that dasdfmt uses
74 * BIODASDDISABLE to disable accesses to the device via the block
75 * device layer but it still wants to do i/o on the device by
76 * using the BIODASDFMT ioctl. Therefore the correct state for the
77 * device is DASD_STATE_BASIC that allows to do basic i/o.
79 dasd_set_target_state(block
->base
, DASD_STATE_BASIC
);
81 * Set i_size to zero, since read, write, etc. check against this
84 mutex_lock(&bdev
->bd_mutex
);
85 i_size_write(bdev
->bd_inode
, 0);
86 mutex_unlock(&bdev
->bd_mutex
);
93 static int dasd_ioctl_quiesce(struct dasd_block
*block
)
96 struct dasd_device
*base
;
99 if (!capable (CAP_SYS_ADMIN
))
102 pr_info("%s: The DASD has been put in the quiesce "
103 "state\n", dev_name(&base
->cdev
->dev
));
104 spin_lock_irqsave(get_ccwdev_lock(base
->cdev
), flags
);
105 dasd_device_set_stop_bits(base
, DASD_STOPPED_QUIESCE
);
106 spin_unlock_irqrestore(get_ccwdev_lock(base
->cdev
), flags
);
114 static int dasd_ioctl_resume(struct dasd_block
*block
)
117 struct dasd_device
*base
;
120 if (!capable (CAP_SYS_ADMIN
))
123 pr_info("%s: I/O operations have been resumed "
124 "on the DASD\n", dev_name(&base
->cdev
->dev
));
125 spin_lock_irqsave(get_ccwdev_lock(base
->cdev
), flags
);
126 dasd_device_remove_stop_bits(base
, DASD_STOPPED_QUIESCE
);
127 spin_unlock_irqrestore(get_ccwdev_lock(base
->cdev
), flags
);
129 dasd_schedule_block_bh(block
);
134 * performs formatting of _device_ according to _fdata_
135 * Note: The discipline's format_function is assumed to deliver formatting
136 * commands to format a single unit of the device. In terms of the ECKD
137 * devices this means CCWs are generated to format a single track.
139 static int dasd_format(struct dasd_block
*block
, struct format_data_t
*fdata
)
141 struct dasd_ccw_req
*cqr
;
142 struct dasd_device
*base
;
146 if (base
->discipline
->format_device
== NULL
)
149 if (base
->state
!= DASD_STATE_BASIC
) {
150 pr_warning("%s: The DASD cannot be formatted while it is "
151 "enabled\n", dev_name(&base
->cdev
->dev
));
155 DBF_DEV_EVENT(DBF_NOTICE
, base
,
156 "formatting units %u to %u (%u B blocks) flags %u",
158 fdata
->stop_unit
, fdata
->blksize
, fdata
->intensity
);
160 /* Since dasdfmt keeps the device open after it was disabled,
161 * there still exists an inode for this device.
162 * We must update i_blkbits, otherwise we might get errors when
163 * enabling the device later.
165 if (fdata
->start_unit
== 0) {
166 struct block_device
*bdev
= bdget_disk(block
->gdp
, 0);
167 bdev
->bd_inode
->i_blkbits
= blksize_bits(fdata
->blksize
);
171 while (fdata
->start_unit
<= fdata
->stop_unit
) {
172 cqr
= base
->discipline
->format_device(base
, fdata
);
175 rc
= dasd_sleep_on_interruptible(cqr
);
176 dasd_sfree_request(cqr
, cqr
->memdev
);
178 if (rc
!= -ERESTARTSYS
)
179 pr_err("%s: Formatting unit %d failed with "
180 "rc=%d\n", dev_name(&base
->cdev
->dev
),
181 fdata
->start_unit
, rc
);
193 dasd_ioctl_format(struct block_device
*bdev
, void __user
*argp
)
195 struct dasd_block
*block
= bdev
->bd_disk
->private_data
;
196 struct format_data_t fdata
;
198 if (!capable(CAP_SYS_ADMIN
))
203 if (block
->base
->features
& DASD_FEATURE_READONLY
||
204 test_bit(DASD_FLAG_DEVICE_RO
, &block
->base
->flags
))
206 if (copy_from_user(&fdata
, argp
, sizeof(struct format_data_t
)))
208 if (bdev
!= bdev
->bd_contains
) {
209 pr_warning("%s: The specified DASD is a partition and cannot "
211 dev_name(&block
->base
->cdev
->dev
));
214 return dasd_format(block
, &fdata
);
217 #ifdef CONFIG_DASD_PROFILE
219 * Reset device profile information
221 static int dasd_ioctl_reset_profile(struct dasd_block
*block
)
223 memset(&block
->profile
, 0, sizeof(struct dasd_profile_info_t
));
228 * Return device profile information
230 static int dasd_ioctl_read_profile(struct dasd_block
*block
, void __user
*argp
)
232 if (dasd_profile_level
== DASD_PROFILE_OFF
)
234 if (copy_to_user(argp
, &block
->profile
,
235 sizeof(struct dasd_profile_info_t
)))
240 static int dasd_ioctl_reset_profile(struct dasd_block
*block
)
245 static int dasd_ioctl_read_profile(struct dasd_block
*block
, void __user
*argp
)
252 * Return dasd information. Used for BIODASDINFO and BIODASDINFO2.
254 static int dasd_ioctl_information(struct dasd_block
*block
,
255 unsigned int cmd
, void __user
*argp
)
257 struct dasd_information2_t
*dasd_info
;
260 struct dasd_device
*base
;
261 struct ccw_device
*cdev
;
262 struct ccw_dev_id dev_id
;
265 if (!base
->discipline
|| !base
->discipline
->fill_info
)
268 dasd_info
= kzalloc(sizeof(struct dasd_information2_t
), GFP_KERNEL
);
269 if (dasd_info
== NULL
)
272 rc
= base
->discipline
->fill_info(base
, dasd_info
);
279 ccw_device_get_id(cdev
, &dev_id
);
281 dasd_info
->devno
= dev_id
.devno
;
282 dasd_info
->schid
= _ccw_device_get_subchannel_number(base
->cdev
);
283 dasd_info
->cu_type
= cdev
->id
.cu_type
;
284 dasd_info
->cu_model
= cdev
->id
.cu_model
;
285 dasd_info
->dev_type
= cdev
->id
.dev_type
;
286 dasd_info
->dev_model
= cdev
->id
.dev_model
;
287 dasd_info
->status
= base
->state
;
289 * The open_count is increased for every opener, that includes
290 * the blkdev_get in dasd_scan_partitions.
291 * This must be hidden from user-space.
293 dasd_info
->open_count
= atomic_read(&block
->open_count
);
295 dasd_info
->open_count
++;
298 * check if device is really formatted
299 * LDL / CDL was returned by 'fill_info'
301 if ((base
->state
< DASD_STATE_READY
) ||
302 (dasd_check_blocksize(block
->bp_block
)))
303 dasd_info
->format
= DASD_FORMAT_NONE
;
305 dasd_info
->features
|=
306 ((base
->features
& DASD_FEATURE_READONLY
) != 0);
308 memcpy(dasd_info
->type
, base
->discipline
->name
, 4);
310 if (block
->request_queue
->request_fn
) {
312 #ifdef DASD_EXTENDED_PROFILING
315 spin_lock_irqsave(&block
->lock
, flags
);
316 list_for_each(l
, &block
->request_queue
->queue_head
)
317 dasd_info
->req_queue_len
++;
318 spin_unlock_irqrestore(&block
->lock
, flags
);
320 #endif /* DASD_EXTENDED_PROFILING */
321 spin_lock_irqsave(get_ccwdev_lock(base
->cdev
), flags
);
322 list_for_each(l
, &base
->ccw_queue
)
323 dasd_info
->chanq_len
++;
324 spin_unlock_irqrestore(get_ccwdev_lock(base
->cdev
),
329 if (copy_to_user(argp
, dasd_info
,
330 ((cmd
== (unsigned int) BIODASDINFO2
) ?
331 sizeof(struct dasd_information2_t
) :
332 sizeof(struct dasd_information_t
))))
342 dasd_ioctl_set_ro(struct block_device
*bdev
, void __user
*argp
)
344 struct dasd_block
*block
= bdev
->bd_disk
->private_data
;
347 if (!capable(CAP_SYS_ADMIN
))
349 if (bdev
!= bdev
->bd_contains
)
350 // ro setting is not allowed for partitions
352 if (get_user(intval
, (int __user
*)argp
))
354 if (!intval
&& test_bit(DASD_FLAG_DEVICE_RO
, &block
->base
->flags
))
356 set_disk_ro(bdev
->bd_disk
, intval
);
357 return dasd_set_feature(block
->base
->cdev
, DASD_FEATURE_READONLY
, intval
);
360 static int dasd_ioctl_readall_cmb(struct dasd_block
*block
, unsigned int cmd
,
361 struct cmbdata __user
*argp
)
363 size_t size
= _IOC_SIZE(cmd
);
367 ret
= cmf_readall(block
->base
->cdev
, &data
);
368 if (!ret
&& copy_to_user(argp
, &data
, min(size
, sizeof(*argp
))))
374 dasd_do_ioctl(struct block_device
*bdev
, fmode_t mode
,
375 unsigned int cmd
, unsigned long arg
)
377 struct dasd_block
*block
= bdev
->bd_disk
->private_data
;
380 if (is_compat_task())
381 argp
= compat_ptr(arg
);
383 argp
= (void __user
*)arg
;
388 if ((_IOC_DIR(cmd
) != _IOC_NONE
) && !arg
) {
389 PRINT_DEBUG("empty data ptr");
395 return dasd_ioctl_disable(bdev
);
397 return dasd_ioctl_enable(bdev
);
399 return dasd_ioctl_quiesce(block
);
401 return dasd_ioctl_resume(block
);
403 return dasd_ioctl_format(bdev
, argp
);
405 return dasd_ioctl_information(block
, cmd
, argp
);
407 return dasd_ioctl_information(block
, cmd
, argp
);
409 return dasd_ioctl_read_profile(block
, argp
);
411 return dasd_ioctl_reset_profile(block
);
413 return dasd_ioctl_set_ro(bdev
, argp
);
415 return dasd_ioctl_api_version(argp
);
416 case BIODASDCMFENABLE
:
417 return enable_cmf(block
->base
->cdev
);
418 case BIODASDCMFDISABLE
:
419 return disable_cmf(block
->base
->cdev
);
420 case BIODASDREADALLCMB
:
421 return dasd_ioctl_readall_cmb(block
, cmd
, argp
);
423 /* if the discipline has an ioctl method try it. */
424 if (block
->base
->discipline
->ioctl
) {
425 int rval
= block
->base
->discipline
->ioctl(block
, cmd
, argp
);
426 if (rval
!= -ENOIOCTLCMD
)
434 int dasd_ioctl(struct block_device
*bdev
, fmode_t mode
,
435 unsigned int cmd
, unsigned long arg
)
440 rc
= dasd_do_ioctl(bdev
, mode
, cmd
, arg
);