vmxnet3: fix typo setting confPA
[linux-2.6/libata-dev.git] / drivers / s390 / block / dasd_ioctl.c
blob26075e95b1bad786db8ff7b0e8504521fe8f3d68
1 /*
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>
17 #include <linux/fs.h>
18 #include <linux/blkpg.h>
19 #include <linux/slab.h>
20 #include <asm/compat.h>
21 #include <asm/ccwdev.h>
22 #include <asm/cmb.h>
23 #include <asm/uaccess.h>
25 /* This is ugly... */
26 #define PRINTK_HEADER "dasd_ioctl:"
28 #include "dasd_int.h"
31 static int
32 dasd_ioctl_api_version(void __user *argp)
34 int ver = DASD_API_VERSION;
35 return put_user(ver, (int __user *)argp);
39 * Enable device.
40 * used by dasdfmt after BIODASDDISABLE to retrigger blocksize detection
42 static int
43 dasd_ioctl_enable(struct block_device *bdev)
45 struct dasd_block *block = bdev->bd_disk->private_data;
47 if (!capable(CAP_SYS_ADMIN))
48 return -EACCES;
50 dasd_enable_device(block->base);
51 /* Formatting the dasd device can change the capacity. */
52 mutex_lock(&bdev->bd_mutex);
53 i_size_write(bdev->bd_inode, (loff_t)get_capacity(block->gdp) << 9);
54 mutex_unlock(&bdev->bd_mutex);
55 return 0;
59 * Disable device.
60 * Used by dasdfmt. Disable I/O operations but allow ioctls.
62 static int
63 dasd_ioctl_disable(struct block_device *bdev)
65 struct dasd_block *block = bdev->bd_disk->private_data;
67 if (!capable(CAP_SYS_ADMIN))
68 return -EACCES;
71 * Man this is sick. We don't do a real disable but only downgrade
72 * the device to DASD_STATE_BASIC. The reason is that dasdfmt uses
73 * BIODASDDISABLE to disable accesses to the device via the block
74 * device layer but it still wants to do i/o on the device by
75 * using the BIODASDFMT ioctl. Therefore the correct state for the
76 * device is DASD_STATE_BASIC that allows to do basic i/o.
78 dasd_set_target_state(block->base, DASD_STATE_BASIC);
80 * Set i_size to zero, since read, write, etc. check against this
81 * value.
83 mutex_lock(&bdev->bd_mutex);
84 i_size_write(bdev->bd_inode, 0);
85 mutex_unlock(&bdev->bd_mutex);
86 return 0;
90 * Quiesce device.
92 static int dasd_ioctl_quiesce(struct dasd_block *block)
94 unsigned long flags;
95 struct dasd_device *base;
97 base = block->base;
98 if (!capable (CAP_SYS_ADMIN))
99 return -EACCES;
101 pr_info("%s: The DASD has been put in the quiesce "
102 "state\n", dev_name(&base->cdev->dev));
103 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
104 dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE);
105 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags);
106 return 0;
111 * Resume device.
113 static int dasd_ioctl_resume(struct dasd_block *block)
115 unsigned long flags;
116 struct dasd_device *base;
118 base = block->base;
119 if (!capable (CAP_SYS_ADMIN))
120 return -EACCES;
122 pr_info("%s: I/O operations have been resumed "
123 "on the DASD\n", dev_name(&base->cdev->dev));
124 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
125 dasd_device_remove_stop_bits(base, DASD_STOPPED_QUIESCE);
126 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags);
128 dasd_schedule_block_bh(block);
129 return 0;
133 * performs formatting of _device_ according to _fdata_
134 * Note: The discipline's format_function is assumed to deliver formatting
135 * commands to format a single unit of the device. In terms of the ECKD
136 * devices this means CCWs are generated to format a single track.
138 static int dasd_format(struct dasd_block *block, struct format_data_t *fdata)
140 struct dasd_ccw_req *cqr;
141 struct dasd_device *base;
142 int rc;
144 base = block->base;
145 if (base->discipline->format_device == NULL)
146 return -EPERM;
148 if (base->state != DASD_STATE_BASIC) {
149 pr_warning("%s: The DASD cannot be formatted while it is "
150 "enabled\n", dev_name(&base->cdev->dev));
151 return -EBUSY;
154 DBF_DEV_EVENT(DBF_NOTICE, base,
155 "formatting units %u to %u (%u B blocks) flags %u",
156 fdata->start_unit,
157 fdata->stop_unit, fdata->blksize, fdata->intensity);
159 /* Since dasdfmt keeps the device open after it was disabled,
160 * there still exists an inode for this device.
161 * We must update i_blkbits, otherwise we might get errors when
162 * enabling the device later.
164 if (fdata->start_unit == 0) {
165 struct block_device *bdev = bdget_disk(block->gdp, 0);
166 bdev->bd_inode->i_blkbits = blksize_bits(fdata->blksize);
167 bdput(bdev);
170 while (fdata->start_unit <= fdata->stop_unit) {
171 cqr = base->discipline->format_device(base, fdata);
172 if (IS_ERR(cqr))
173 return PTR_ERR(cqr);
174 rc = dasd_sleep_on_interruptible(cqr);
175 dasd_sfree_request(cqr, cqr->memdev);
176 if (rc) {
177 if (rc != -ERESTARTSYS)
178 pr_err("%s: Formatting unit %d failed with "
179 "rc=%d\n", dev_name(&base->cdev->dev),
180 fdata->start_unit, rc);
181 return rc;
183 fdata->start_unit++;
185 return 0;
189 * Format device.
191 static int
192 dasd_ioctl_format(struct block_device *bdev, void __user *argp)
194 struct dasd_block *block = bdev->bd_disk->private_data;
195 struct format_data_t fdata;
197 if (!capable(CAP_SYS_ADMIN))
198 return -EACCES;
199 if (!argp)
200 return -EINVAL;
202 if (block->base->features & DASD_FEATURE_READONLY ||
203 test_bit(DASD_FLAG_DEVICE_RO, &block->base->flags))
204 return -EROFS;
205 if (copy_from_user(&fdata, argp, sizeof(struct format_data_t)))
206 return -EFAULT;
207 if (bdev != bdev->bd_contains) {
208 pr_warning("%s: The specified DASD is a partition and cannot "
209 "be formatted\n",
210 dev_name(&block->base->cdev->dev));
211 return -EINVAL;
213 return dasd_format(block, &fdata);
216 #ifdef CONFIG_DASD_PROFILE
218 * Reset device profile information
220 static int dasd_ioctl_reset_profile(struct dasd_block *block)
222 memset(&block->profile, 0, sizeof(struct dasd_profile_info_t));
223 return 0;
227 * Return device profile information
229 static int dasd_ioctl_read_profile(struct dasd_block *block, void __user *argp)
231 if (dasd_profile_level == DASD_PROFILE_OFF)
232 return -EIO;
233 if (copy_to_user(argp, &block->profile,
234 sizeof(struct dasd_profile_info_t)))
235 return -EFAULT;
236 return 0;
238 #else
239 static int dasd_ioctl_reset_profile(struct dasd_block *block)
241 return -ENOSYS;
244 static int dasd_ioctl_read_profile(struct dasd_block *block, void __user *argp)
246 return -ENOSYS;
248 #endif
251 * Return dasd information. Used for BIODASDINFO and BIODASDINFO2.
253 static int dasd_ioctl_information(struct dasd_block *block,
254 unsigned int cmd, void __user *argp)
256 struct dasd_information2_t *dasd_info;
257 unsigned long flags;
258 int rc;
259 struct dasd_device *base;
260 struct ccw_device *cdev;
261 struct ccw_dev_id dev_id;
263 base = block->base;
264 if (!base->discipline || !base->discipline->fill_info)
265 return -EINVAL;
267 dasd_info = kzalloc(sizeof(struct dasd_information2_t), GFP_KERNEL);
268 if (dasd_info == NULL)
269 return -ENOMEM;
271 rc = base->discipline->fill_info(base, dasd_info);
272 if (rc) {
273 kfree(dasd_info);
274 return rc;
277 cdev = base->cdev;
278 ccw_device_get_id(cdev, &dev_id);
280 dasd_info->devno = dev_id.devno;
281 dasd_info->schid = _ccw_device_get_subchannel_number(base->cdev);
282 dasd_info->cu_type = cdev->id.cu_type;
283 dasd_info->cu_model = cdev->id.cu_model;
284 dasd_info->dev_type = cdev->id.dev_type;
285 dasd_info->dev_model = cdev->id.dev_model;
286 dasd_info->status = base->state;
288 * The open_count is increased for every opener, that includes
289 * the blkdev_get in dasd_scan_partitions.
290 * This must be hidden from user-space.
292 dasd_info->open_count = atomic_read(&block->open_count);
293 if (!block->bdev)
294 dasd_info->open_count++;
297 * check if device is really formatted
298 * LDL / CDL was returned by 'fill_info'
300 if ((base->state < DASD_STATE_READY) ||
301 (dasd_check_blocksize(block->bp_block)))
302 dasd_info->format = DASD_FORMAT_NONE;
304 dasd_info->features |=
305 ((base->features & DASD_FEATURE_READONLY) != 0);
307 memcpy(dasd_info->type, base->discipline->name, 4);
309 if (block->request_queue->request_fn) {
310 struct list_head *l;
311 #ifdef DASD_EXTENDED_PROFILING
313 struct list_head *l;
314 spin_lock_irqsave(&block->lock, flags);
315 list_for_each(l, &block->request_queue->queue_head)
316 dasd_info->req_queue_len++;
317 spin_unlock_irqrestore(&block->lock, flags);
319 #endif /* DASD_EXTENDED_PROFILING */
320 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
321 list_for_each(l, &base->ccw_queue)
322 dasd_info->chanq_len++;
323 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
324 flags);
327 rc = 0;
328 if (copy_to_user(argp, dasd_info,
329 ((cmd == (unsigned int) BIODASDINFO2) ?
330 sizeof(struct dasd_information2_t) :
331 sizeof(struct dasd_information_t))))
332 rc = -EFAULT;
333 kfree(dasd_info);
334 return rc;
338 * Set read only
340 static int
341 dasd_ioctl_set_ro(struct block_device *bdev, void __user *argp)
343 struct dasd_block *block = bdev->bd_disk->private_data;
344 int intval;
346 if (!capable(CAP_SYS_ADMIN))
347 return -EACCES;
348 if (bdev != bdev->bd_contains)
349 // ro setting is not allowed for partitions
350 return -EINVAL;
351 if (get_user(intval, (int __user *)argp))
352 return -EFAULT;
353 if (!intval && test_bit(DASD_FLAG_DEVICE_RO, &block->base->flags))
354 return -EROFS;
355 set_disk_ro(bdev->bd_disk, intval);
356 return dasd_set_feature(block->base->cdev, DASD_FEATURE_READONLY, intval);
359 static int dasd_ioctl_readall_cmb(struct dasd_block *block, unsigned int cmd,
360 struct cmbdata __user *argp)
362 size_t size = _IOC_SIZE(cmd);
363 struct cmbdata data;
364 int ret;
366 ret = cmf_readall(block->base->cdev, &data);
367 if (!ret && copy_to_user(argp, &data, min(size, sizeof(*argp))))
368 return -EFAULT;
369 return ret;
372 int dasd_ioctl(struct block_device *bdev, fmode_t mode,
373 unsigned int cmd, unsigned long arg)
375 struct dasd_block *block = bdev->bd_disk->private_data;
376 void __user *argp;
378 if (is_compat_task())
379 argp = compat_ptr(arg);
380 else
381 argp = (void __user *)arg;
383 if (!block)
384 return -ENODEV;
386 if ((_IOC_DIR(cmd) != _IOC_NONE) && !arg) {
387 PRINT_DEBUG("empty data ptr");
388 return -EINVAL;
391 switch (cmd) {
392 case BIODASDDISABLE:
393 return dasd_ioctl_disable(bdev);
394 case BIODASDENABLE:
395 return dasd_ioctl_enable(bdev);
396 case BIODASDQUIESCE:
397 return dasd_ioctl_quiesce(block);
398 case BIODASDRESUME:
399 return dasd_ioctl_resume(block);
400 case BIODASDFMT:
401 return dasd_ioctl_format(bdev, argp);
402 case BIODASDINFO:
403 return dasd_ioctl_information(block, cmd, argp);
404 case BIODASDINFO2:
405 return dasd_ioctl_information(block, cmd, argp);
406 case BIODASDPRRD:
407 return dasd_ioctl_read_profile(block, argp);
408 case BIODASDPRRST:
409 return dasd_ioctl_reset_profile(block);
410 case BLKROSET:
411 return dasd_ioctl_set_ro(bdev, argp);
412 case DASDAPIVER:
413 return dasd_ioctl_api_version(argp);
414 case BIODASDCMFENABLE:
415 return enable_cmf(block->base->cdev);
416 case BIODASDCMFDISABLE:
417 return disable_cmf(block->base->cdev);
418 case BIODASDREADALLCMB:
419 return dasd_ioctl_readall_cmb(block, cmd, argp);
420 default:
421 /* if the discipline has an ioctl method try it. */
422 if (block->base->discipline->ioctl) {
423 int rval = block->base->discipline->ioctl(block, cmd, argp);
424 if (rval != -ENOIOCTLCMD)
425 return rval;
428 return -EINVAL;