]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/s390/block/dasd_genhd.c
ads7846: Add disable sysfs entry / fix spin lock init, driver cleanup
[linux-2.6-omap-h63xx.git] / drivers / s390 / block / dasd_genhd.c
1 /*
2  * File...........: linux/drivers/s390/block/dasd_genhd.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
9  *
10  * gendisk related functions for the dasd driver.
11  *
12  */
13
14 #include <linux/config.h>
15 #include <linux/interrupt.h>
16 #include <linux/fs.h>
17 #include <linux/blkpg.h>
18
19 #include <asm/uaccess.h>
20
21 /* This is ugly... */
22 #define PRINTK_HEADER "dasd_gendisk:"
23
24 #include "dasd_int.h"
25
26 /*
27  * Allocate and register gendisk structure for device.
28  */
29 int
30 dasd_gendisk_alloc(struct dasd_device *device)
31 {
32         struct gendisk *gdp;
33         int len;
34
35         /* Make sure the minor for this device exists. */
36         if (device->devindex >= DASD_PER_MAJOR)
37                 return -EBUSY;
38
39         gdp = alloc_disk(1 << DASD_PARTN_BITS);
40         if (!gdp)
41                 return -ENOMEM;
42
43         /* Initialize gendisk structure. */
44         gdp->major = DASD_MAJOR;
45         gdp->first_minor = device->devindex << DASD_PARTN_BITS;
46         gdp->fops = &dasd_device_operations;
47         gdp->driverfs_dev = &device->cdev->dev;
48
49         /*
50          * Set device name.
51          *   dasda - dasdz : 26 devices
52          *   dasdaa - dasdzz : 676 devices, added up = 702
53          *   dasdaaa - dasdzzz : 17576 devices, added up = 18278
54          *   dasdaaaa - dasdzzzz : 456976 devices, added up = 475252
55          */
56         len = sprintf(gdp->disk_name, "dasd");
57         if (device->devindex > 25) {
58                 if (device->devindex > 701) {
59                         if (device->devindex > 18277)
60                                 len += sprintf(gdp->disk_name + len, "%c",
61                                                'a'+(((device->devindex-18278)
62                                                      /17576)%26));
63                         len += sprintf(gdp->disk_name + len, "%c",
64                                        'a'+(((device->devindex-702)/676)%26));
65                 }
66                 len += sprintf(gdp->disk_name + len, "%c",
67                                'a'+(((device->devindex-26)/26)%26));
68         }
69         len += sprintf(gdp->disk_name + len, "%c", 'a'+(device->devindex%26));
70
71         sprintf(gdp->devfs_name, "dasd/%s", device->cdev->dev.bus_id);
72
73         if (device->features & DASD_FEATURE_READONLY)
74                 set_disk_ro(gdp, 1);
75         gdp->private_data = device;
76         gdp->queue = device->request_queue;
77         device->gdp = gdp;
78         set_capacity(device->gdp, 0);
79         add_disk(device->gdp);
80         return 0;
81 }
82
83 /*
84  * Unregister and free gendisk structure for device.
85  */
86 void
87 dasd_gendisk_free(struct dasd_device *device)
88 {
89         del_gendisk(device->gdp);
90         device->gdp->queue = 0;
91         put_disk(device->gdp);
92         device->gdp = 0;
93 }
94
95 /*
96  * Trigger a partition detection.
97  */
98 int
99 dasd_scan_partitions(struct dasd_device * device)
100 {
101         struct block_device *bdev;
102
103         /* Make the disk known. */
104         set_capacity(device->gdp, device->blocks << device->s2b_shift);
105         bdev = bdget_disk(device->gdp, 0);
106         if (!bdev || blkdev_get(bdev, FMODE_READ, 1) < 0)
107                 return -ENODEV;
108         /*
109          * See fs/partition/check.c:register_disk,rescan_partitions
110          * Can't call rescan_partitions directly. Use ioctl.
111          */
112         ioctl_by_bdev(bdev, BLKRRPART, 0);
113         /*
114          * Since the matching blkdev_put call to the blkdev_get in
115          * this function is not called before dasd_destroy_partitions
116          * the offline open_count limit needs to be increased from
117          * 0 to 1. This is done by setting device->bdev (see
118          * dasd_generic_set_offline). As long as the partition
119          * detection is running no offline should be allowed. That
120          * is why the assignment to device->bdev is done AFTER
121          * the BLKRRPART ioctl.
122          */
123         device->bdev = bdev;
124         return 0;
125 }
126
127 /*
128  * Remove all inodes in the system for a device, delete the
129  * partitions and make device unusable by setting its size to zero.
130  */
131 void
132 dasd_destroy_partitions(struct dasd_device * device)
133 {
134         /* The two structs have 168/176 byte on 31/64 bit. */
135         struct blkpg_partition bpart;
136         struct blkpg_ioctl_arg barg;
137         struct block_device *bdev;
138
139         /*
140          * Get the bdev pointer from the device structure and clear
141          * device->bdev to lower the offline open_count limit again.
142          */
143         bdev = device->bdev;
144         device->bdev = 0;
145
146         /*
147          * See fs/partition/check.c:delete_partition
148          * Can't call delete_partitions directly. Use ioctl.
149          * The ioctl also does locking and invalidation.
150          */
151         memset(&bpart, 0, sizeof(struct blkpg_partition));
152         memset(&barg, 0, sizeof(struct blkpg_ioctl_arg));
153         barg.data = &bpart;
154         barg.op = BLKPG_DEL_PARTITION;
155         for (bpart.pno = device->gdp->minors - 1; bpart.pno > 0; bpart.pno--)
156                 ioctl_by_bdev(bdev, BLKPG, (unsigned long) &barg);
157
158         invalidate_partition(device->gdp, 0);
159         /* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */
160         blkdev_put(bdev);
161         set_capacity(device->gdp, 0);
162 }
163
164 int
165 dasd_gendisk_init(void)
166 {
167         int rc;
168
169         /* Register to static dasd major 94 */
170         rc = register_blkdev(DASD_MAJOR, "dasd");
171         if (rc != 0) {
172                 MESSAGE(KERN_WARNING,
173                         "Couldn't register successfully to "
174                         "major no %d", DASD_MAJOR);
175                 return rc;
176         }
177         return 0;
178 }
179
180 void
181 dasd_gendisk_exit(void)
182 {
183         unregister_blkdev(DASD_MAJOR, "dasd");
184 }