aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/genhd.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/genhd.h')
-rw-r--r--include/linux/genhd.h363
1 files changed, 182 insertions, 181 deletions
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index be4f5e5bfe06..206cdf96c3a7 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -11,12 +11,15 @@
11 11
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/kdev_t.h> 13#include <linux/kdev_t.h>
14#include <linux/rcupdate.h>
14 15
15#ifdef CONFIG_BLOCK 16#ifdef CONFIG_BLOCK
16 17
17#define kobj_to_dev(k) container_of(k, struct device, kobj) 18#define kobj_to_dev(k) container_of((k), struct device, kobj)
18#define dev_to_disk(device) container_of(device, struct gendisk, dev) 19#define dev_to_disk(device) container_of((device), struct gendisk, part0.__dev)
19#define dev_to_part(device) container_of(device, struct hd_struct, dev) 20#define dev_to_part(device) container_of((device), struct hd_struct, __dev)
21#define disk_to_dev(disk) (&(disk)->part0.__dev)
22#define part_to_dev(part) (&((part)->__dev))
20 23
21extern struct device_type part_type; 24extern struct device_type part_type;
22extern struct kobject *block_depr; 25extern struct kobject *block_depr;
@@ -55,6 +58,9 @@ enum {
55 UNIXWARE_PARTITION = 0x63, /* Same as GNU_HURD and SCO Unix */ 58 UNIXWARE_PARTITION = 0x63, /* Same as GNU_HURD and SCO Unix */
56}; 59};
57 60
61#define DISK_MAX_PARTS 256
62#define DISK_NAME_LEN 32
63
58#include <linux/major.h> 64#include <linux/major.h>
59#include <linux/device.h> 65#include <linux/device.h>
60#include <linux/smp.h> 66#include <linux/smp.h>
@@ -87,7 +93,7 @@ struct disk_stats {
87struct hd_struct { 93struct hd_struct {
88 sector_t start_sect; 94 sector_t start_sect;
89 sector_t nr_sects; 95 sector_t nr_sects;
90 struct device dev; 96 struct device __dev;
91 struct kobject *holder_dir; 97 struct kobject *holder_dir;
92 int policy, partno; 98 int policy, partno;
93#ifdef CONFIG_FAIL_MAKE_REQUEST 99#ifdef CONFIG_FAIL_MAKE_REQUEST
@@ -100,6 +106,7 @@ struct hd_struct {
100#else 106#else
101 struct disk_stats dkstats; 107 struct disk_stats dkstats;
102#endif 108#endif
109 struct rcu_head rcu_head;
103}; 110};
104 111
105#define GENHD_FL_REMOVABLE 1 112#define GENHD_FL_REMOVABLE 1
@@ -108,100 +115,148 @@ struct hd_struct {
108#define GENHD_FL_CD 8 115#define GENHD_FL_CD 8
109#define GENHD_FL_UP 16 116#define GENHD_FL_UP 16
110#define GENHD_FL_SUPPRESS_PARTITION_INFO 32 117#define GENHD_FL_SUPPRESS_PARTITION_INFO 32
111#define GENHD_FL_FAIL 64 118#define GENHD_FL_EXT_DEVT 64 /* allow extended devt */
119
120#define BLK_SCSI_MAX_CMDS (256)
121#define BLK_SCSI_CMD_PER_LONG (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8))
122
123struct blk_scsi_cmd_filter {
124 unsigned long read_ok[BLK_SCSI_CMD_PER_LONG];
125 unsigned long write_ok[BLK_SCSI_CMD_PER_LONG];
126 struct kobject kobj;
127};
128
129struct disk_part_tbl {
130 struct rcu_head rcu_head;
131 int len;
132 struct hd_struct *part[];
133};
112 134
113struct gendisk { 135struct gendisk {
136 /* major, first_minor and minors are input parameters only,
137 * don't use directly. Use disk_devt() and disk_max_parts().
138 */
114 int major; /* major number of driver */ 139 int major; /* major number of driver */
115 int first_minor; 140 int first_minor;
116 int minors; /* maximum number of minors, =1 for 141 int minors; /* maximum number of minors, =1 for
117 * disks that can't be partitioned. */ 142 * disks that can't be partitioned. */
118 char disk_name[32]; /* name of major driver */ 143
119 struct hd_struct **part; /* [indexed by minor] */ 144 char disk_name[DISK_NAME_LEN]; /* name of major driver */
145
146 /* Array of pointers to partitions indexed by partno.
147 * Protected with matching bdev lock but stat and other
148 * non-critical accesses use RCU. Always access through
149 * helpers.
150 */
151 struct disk_part_tbl *part_tbl;
152 struct hd_struct part0;
153
120 struct block_device_operations *fops; 154 struct block_device_operations *fops;
121 struct request_queue *queue; 155 struct request_queue *queue;
122 void *private_data; 156 void *private_data;
123 sector_t capacity;
124 157
125 int flags; 158 int flags;
126 struct device *driverfs_dev; // FIXME: remove 159 struct device *driverfs_dev; // FIXME: remove
127 struct device dev;
128 struct kobject *holder_dir;
129 struct kobject *slave_dir; 160 struct kobject *slave_dir;
130 161
131 struct timer_rand_state *random; 162 struct timer_rand_state *random;
132 int policy;
133 163
134 atomic_t sync_io; /* RAID */ 164 atomic_t sync_io; /* RAID */
135 unsigned long stamp;
136 int in_flight;
137#ifdef CONFIG_SMP
138 struct disk_stats *dkstats;
139#else
140 struct disk_stats dkstats;
141#endif
142 struct work_struct async_notify; 165 struct work_struct async_notify;
143#ifdef CONFIG_BLK_DEV_INTEGRITY 166#ifdef CONFIG_BLK_DEV_INTEGRITY
144 struct blk_integrity *integrity; 167 struct blk_integrity *integrity;
145#endif 168#endif
169 int node_id;
146}; 170};
147 171
148/* 172static inline struct gendisk *part_to_disk(struct hd_struct *part)
149 * Macros to operate on percpu disk statistics:
150 *
151 * The __ variants should only be called in critical sections. The full
152 * variants disable/enable preemption.
153 */
154static inline struct hd_struct *get_part(struct gendisk *gendiskp,
155 sector_t sector)
156{ 173{
157 struct hd_struct *part; 174 if (likely(part)) {
158 int i; 175 if (part->partno)
159 for (i = 0; i < gendiskp->minors - 1; i++) { 176 return dev_to_disk(part_to_dev(part)->parent);
160 part = gendiskp->part[i]; 177 else
161 if (part && part->start_sect <= sector 178 return dev_to_disk(part_to_dev(part));
162 && sector < part->start_sect + part->nr_sects)
163 return part;
164 } 179 }
165 return NULL; 180 return NULL;
166} 181}
167 182
168#ifdef CONFIG_SMP 183static inline int disk_max_parts(struct gendisk *disk)
169#define __disk_stat_add(gendiskp, field, addnd) \ 184{
170 (per_cpu_ptr(gendiskp->dkstats, smp_processor_id())->field += addnd) 185 if (disk->flags & GENHD_FL_EXT_DEVT)
186 return DISK_MAX_PARTS;
187 return disk->minors;
188}
171 189
172#define disk_stat_read(gendiskp, field) \ 190static inline bool disk_partitionable(struct gendisk *disk)
173({ \ 191{
174 typeof(gendiskp->dkstats->field) res = 0; \ 192 return disk_max_parts(disk) > 1;
175 int i; \ 193}
176 for_each_possible_cpu(i) \
177 res += per_cpu_ptr(gendiskp->dkstats, i)->field; \
178 res; \
179})
180 194
181static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) { 195static inline dev_t disk_devt(struct gendisk *disk)
182 int i; 196{
197 return disk_to_dev(disk)->devt;
198}
183 199
184 for_each_possible_cpu(i) 200static inline dev_t part_devt(struct hd_struct *part)
185 memset(per_cpu_ptr(gendiskp->dkstats, i), value, 201{
186 sizeof(struct disk_stats)); 202 return part_to_dev(part)->devt;
187} 203}
188 204
189#define __part_stat_add(part, field, addnd) \ 205extern struct hd_struct *disk_get_part(struct gendisk *disk, int partno);
190 (per_cpu_ptr(part->dkstats, smp_processor_id())->field += addnd)
191 206
192#define __all_stat_add(gendiskp, part, field, addnd, sector) \ 207static inline void disk_put_part(struct hd_struct *part)
193({ \ 208{
194 if (part) \ 209 if (likely(part))
195 __part_stat_add(part, field, addnd); \ 210 put_device(part_to_dev(part));
196 __disk_stat_add(gendiskp, field, addnd); \ 211}
197}) 212
213/*
214 * Smarter partition iterator without context limits.
215 */
216#define DISK_PITER_REVERSE (1 << 0) /* iterate in the reverse direction */
217#define DISK_PITER_INCL_EMPTY (1 << 1) /* include 0-sized parts */
218#define DISK_PITER_INCL_PART0 (1 << 2) /* include partition 0 */
219
220struct disk_part_iter {
221 struct gendisk *disk;
222 struct hd_struct *part;
223 int idx;
224 unsigned int flags;
225};
226
227extern void disk_part_iter_init(struct disk_part_iter *piter,
228 struct gendisk *disk, unsigned int flags);
229extern struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter);
230extern void disk_part_iter_exit(struct disk_part_iter *piter);
231
232extern struct hd_struct *disk_map_sector_rcu(struct gendisk *disk,
233 sector_t sector);
234
235/*
236 * Macros to operate on percpu disk statistics:
237 *
238 * {disk|part|all}_stat_{add|sub|inc|dec}() modify the stat counters
239 * and should be called between disk_stat_lock() and
240 * disk_stat_unlock().
241 *
242 * part_stat_read() can be called at any time.
243 *
244 * part_stat_{add|set_all}() and {init|free}_part_stats are for
245 * internal use only.
246 */
247#ifdef CONFIG_SMP
248#define part_stat_lock() ({ rcu_read_lock(); get_cpu(); })
249#define part_stat_unlock() do { put_cpu(); rcu_read_unlock(); } while (0)
250
251#define __part_stat_add(cpu, part, field, addnd) \
252 (per_cpu_ptr((part)->dkstats, (cpu))->field += (addnd))
198 253
199#define part_stat_read(part, field) \ 254#define part_stat_read(part, field) \
200({ \ 255({ \
201 typeof(part->dkstats->field) res = 0; \ 256 typeof((part)->dkstats->field) res = 0; \
202 int i; \ 257 int i; \
203 for_each_possible_cpu(i) \ 258 for_each_possible_cpu(i) \
204 res += per_cpu_ptr(part->dkstats, i)->field; \ 259 res += per_cpu_ptr((part)->dkstats, i)->field; \
205 res; \ 260 res; \
206}) 261})
207 262
@@ -213,171 +268,107 @@ static inline void part_stat_set_all(struct hd_struct *part, int value)
213 memset(per_cpu_ptr(part->dkstats, i), value, 268 memset(per_cpu_ptr(part->dkstats, i), value,
214 sizeof(struct disk_stats)); 269 sizeof(struct disk_stats));
215} 270}
216
217#else /* !CONFIG_SMP */
218#define __disk_stat_add(gendiskp, field, addnd) \
219 (gendiskp->dkstats.field += addnd)
220#define disk_stat_read(gendiskp, field) (gendiskp->dkstats.field)
221 271
222static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) 272static inline int init_part_stats(struct hd_struct *part)
223{ 273{
224 memset(&gendiskp->dkstats, value, sizeof (struct disk_stats)); 274 part->dkstats = alloc_percpu(struct disk_stats);
275 if (!part->dkstats)
276 return 0;
277 return 1;
225} 278}
226 279
227#define __part_stat_add(part, field, addnd) \ 280static inline void free_part_stats(struct hd_struct *part)
228 (part->dkstats.field += addnd)
229
230#define __all_stat_add(gendiskp, part, field, addnd, sector) \
231({ \
232 if (part) \
233 part->dkstats.field += addnd; \
234 __disk_stat_add(gendiskp, field, addnd); \
235})
236
237#define part_stat_read(part, field) (part->dkstats.field)
238
239static inline void part_stat_set_all(struct hd_struct *part, int value)
240{ 281{
241 memset(&part->dkstats, value, sizeof(struct disk_stats)); 282 free_percpu(part->dkstats);
242} 283}
243 284
244#endif /* CONFIG_SMP */ 285#else /* !CONFIG_SMP */
286#define part_stat_lock() ({ rcu_read_lock(); 0; })
287#define part_stat_unlock() rcu_read_unlock()
245 288
246#define disk_stat_add(gendiskp, field, addnd) \ 289#define __part_stat_add(cpu, part, field, addnd) \
247 do { \ 290 ((part)->dkstats.field += addnd)
248 preempt_disable(); \ 291
249 __disk_stat_add(gendiskp, field, addnd); \ 292#define part_stat_read(part, field) ((part)->dkstats.field)
250 preempt_enable(); \
251 } while (0)
252
253#define __disk_stat_dec(gendiskp, field) __disk_stat_add(gendiskp, field, -1)
254#define disk_stat_dec(gendiskp, field) disk_stat_add(gendiskp, field, -1)
255
256#define __disk_stat_inc(gendiskp, field) __disk_stat_add(gendiskp, field, 1)
257#define disk_stat_inc(gendiskp, field) disk_stat_add(gendiskp, field, 1)
258
259#define __disk_stat_sub(gendiskp, field, subnd) \
260 __disk_stat_add(gendiskp, field, -subnd)
261#define disk_stat_sub(gendiskp, field, subnd) \
262 disk_stat_add(gendiskp, field, -subnd)
263
264#define part_stat_add(gendiskp, field, addnd) \
265 do { \
266 preempt_disable(); \
267 __part_stat_add(gendiskp, field, addnd);\
268 preempt_enable(); \
269 } while (0)
270
271#define __part_stat_dec(gendiskp, field) __part_stat_add(gendiskp, field, -1)
272#define part_stat_dec(gendiskp, field) part_stat_add(gendiskp, field, -1)
273
274#define __part_stat_inc(gendiskp, field) __part_stat_add(gendiskp, field, 1)
275#define part_stat_inc(gendiskp, field) part_stat_add(gendiskp, field, 1)
276
277#define __part_stat_sub(gendiskp, field, subnd) \
278 __part_stat_add(gendiskp, field, -subnd)
279#define part_stat_sub(gendiskp, field, subnd) \
280 part_stat_add(gendiskp, field, -subnd)
281
282#define all_stat_add(gendiskp, part, field, addnd, sector) \
283 do { \
284 preempt_disable(); \
285 __all_stat_add(gendiskp, part, field, addnd, sector); \
286 preempt_enable(); \
287 } while (0)
288
289#define __all_stat_dec(gendiskp, field, sector) \
290 __all_stat_add(gendiskp, field, -1, sector)
291#define all_stat_dec(gendiskp, field, sector) \
292 all_stat_add(gendiskp, field, -1, sector)
293
294#define __all_stat_inc(gendiskp, part, field, sector) \
295 __all_stat_add(gendiskp, part, field, 1, sector)
296#define all_stat_inc(gendiskp, part, field, sector) \
297 all_stat_add(gendiskp, part, field, 1, sector)
298
299#define __all_stat_sub(gendiskp, part, field, subnd, sector) \
300 __all_stat_add(gendiskp, part, field, -subnd, sector)
301#define all_stat_sub(gendiskp, part, field, subnd, sector) \
302 all_stat_add(gendiskp, part, field, -subnd, sector)
303
304/* Inlines to alloc and free disk stats in struct gendisk */
305#ifdef CONFIG_SMP
306static inline int init_disk_stats(struct gendisk *disk)
307{
308 disk->dkstats = alloc_percpu(struct disk_stats);
309 if (!disk->dkstats)
310 return 0;
311 return 1;
312}
313 293
314static inline void free_disk_stats(struct gendisk *disk) 294static inline void part_stat_set_all(struct hd_struct *part, int value)
315{ 295{
316 free_percpu(disk->dkstats); 296 memset(&part->dkstats, value, sizeof(struct disk_stats));
317} 297}
318 298
319static inline int init_part_stats(struct hd_struct *part) 299static inline int init_part_stats(struct hd_struct *part)
320{ 300{
321 part->dkstats = alloc_percpu(struct disk_stats);
322 if (!part->dkstats)
323 return 0;
324 return 1; 301 return 1;
325} 302}
326 303
327static inline void free_part_stats(struct hd_struct *part) 304static inline void free_part_stats(struct hd_struct *part)
328{ 305{
329 free_percpu(part->dkstats);
330}
331
332#else /* CONFIG_SMP */
333static inline int init_disk_stats(struct gendisk *disk)
334{
335 return 1;
336} 306}
337 307
338static inline void free_disk_stats(struct gendisk *disk) 308#endif /* CONFIG_SMP */
339{
340}
341 309
342static inline int init_part_stats(struct hd_struct *part) 310#define part_stat_add(cpu, part, field, addnd) do { \
311 __part_stat_add((cpu), (part), field, addnd); \
312 if ((part)->partno) \
313 __part_stat_add((cpu), &part_to_disk((part))->part0, \
314 field, addnd); \
315} while (0)
316
317#define part_stat_dec(cpu, gendiskp, field) \
318 part_stat_add(cpu, gendiskp, field, -1)
319#define part_stat_inc(cpu, gendiskp, field) \
320 part_stat_add(cpu, gendiskp, field, 1)
321#define part_stat_sub(cpu, gendiskp, field, subnd) \
322 part_stat_add(cpu, gendiskp, field, -subnd)
323
324static inline void part_inc_in_flight(struct hd_struct *part)
343{ 325{
344 return 1; 326 part->in_flight++;
327 if (part->partno)
328 part_to_disk(part)->part0.in_flight++;
345} 329}
346 330
347static inline void free_part_stats(struct hd_struct *part) 331static inline void part_dec_in_flight(struct hd_struct *part)
348{ 332{
333 part->in_flight--;
334 if (part->partno)
335 part_to_disk(part)->part0.in_flight--;
349} 336}
350#endif /* CONFIG_SMP */
351 337
352/* drivers/block/ll_rw_blk.c */ 338/* drivers/block/ll_rw_blk.c */
353extern void disk_round_stats(struct gendisk *disk); 339extern void part_round_stats(int cpu, struct hd_struct *part);
354extern void part_round_stats(struct hd_struct *part);
355 340
356/* drivers/block/genhd.c */ 341/* drivers/block/genhd.c */
357extern int get_blkdev_list(char *, int); 342extern int get_blkdev_list(char *, int);
358extern void add_disk(struct gendisk *disk); 343extern void add_disk(struct gendisk *disk);
359extern void del_gendisk(struct gendisk *gp); 344extern void del_gendisk(struct gendisk *gp);
360extern void unlink_gendisk(struct gendisk *gp); 345extern void unlink_gendisk(struct gendisk *gp);
361extern struct gendisk *get_gendisk(dev_t dev, int *part); 346extern struct gendisk *get_gendisk(dev_t dev, int *partno);
347extern struct block_device *bdget_disk(struct gendisk *disk, int partno);
362 348
363extern void set_device_ro(struct block_device *bdev, int flag); 349extern void set_device_ro(struct block_device *bdev, int flag);
364extern void set_disk_ro(struct gendisk *disk, int flag); 350extern void set_disk_ro(struct gendisk *disk, int flag);
365 351
352static inline int get_disk_ro(struct gendisk *disk)
353{
354 return disk->part0.policy;
355}
356
366/* drivers/char/random.c */ 357/* drivers/char/random.c */
367extern void add_disk_randomness(struct gendisk *disk); 358extern void add_disk_randomness(struct gendisk *disk);
368extern void rand_initialize_disk(struct gendisk *disk); 359extern void rand_initialize_disk(struct gendisk *disk);
369 360
370static inline sector_t get_start_sect(struct block_device *bdev) 361static inline sector_t get_start_sect(struct block_device *bdev)
371{ 362{
372 return bdev->bd_contains == bdev ? 0 : bdev->bd_part->start_sect; 363 return bdev->bd_part->start_sect;
373} 364}
374static inline sector_t get_capacity(struct gendisk *disk) 365static inline sector_t get_capacity(struct gendisk *disk)
375{ 366{
376 return disk->capacity; 367 return disk->part0.nr_sects;
377} 368}
378static inline void set_capacity(struct gendisk *disk, sector_t size) 369static inline void set_capacity(struct gendisk *disk, sector_t size)
379{ 370{
380 disk->capacity = size; 371 disk->part0.nr_sects = size;
381} 372}
382 373
383#ifdef CONFIG_SOLARIS_X86_PARTITION 374#ifdef CONFIG_SOLARIS_X86_PARTITION
@@ -527,9 +518,12 @@ struct unixware_disklabel {
527#define ADDPART_FLAG_RAID 1 518#define ADDPART_FLAG_RAID 1
528#define ADDPART_FLAG_WHOLEDISK 2 519#define ADDPART_FLAG_WHOLEDISK 2
529 520
530extern dev_t blk_lookup_devt(const char *name, int part); 521extern int blk_alloc_devt(struct hd_struct *part, dev_t *devt);
531extern char *disk_name (struct gendisk *hd, int part, char *buf); 522extern void blk_free_devt(dev_t devt);
523extern dev_t blk_lookup_devt(const char *name, int partno);
524extern char *disk_name (struct gendisk *hd, int partno, char *buf);
532 525
526extern int disk_expand_part_tbl(struct gendisk *disk, int target);
533extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev); 527extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev);
534extern int __must_check add_partition(struct gendisk *, int, sector_t, sector_t, int); 528extern int __must_check add_partition(struct gendisk *, int, sector_t, sector_t, int);
535extern void delete_partition(struct gendisk *, int); 529extern void delete_partition(struct gendisk *, int);
@@ -546,16 +540,23 @@ extern void blk_register_region(dev_t devt, unsigned long range,
546 void *data); 540 void *data);
547extern void blk_unregister_region(dev_t devt, unsigned long range); 541extern void blk_unregister_region(dev_t devt, unsigned long range);
548 542
549static inline struct block_device *bdget_disk(struct gendisk *disk, int index) 543extern ssize_t part_size_show(struct device *dev,
550{ 544 struct device_attribute *attr, char *buf);
551 return bdget(MKDEV(disk->major, disk->first_minor) + index); 545extern ssize_t part_stat_show(struct device *dev,
552} 546 struct device_attribute *attr, char *buf);
547#ifdef CONFIG_FAIL_MAKE_REQUEST
548extern ssize_t part_fail_show(struct device *dev,
549 struct device_attribute *attr, char *buf);
550extern ssize_t part_fail_store(struct device *dev,
551 struct device_attribute *attr,
552 const char *buf, size_t count);
553#endif /* CONFIG_FAIL_MAKE_REQUEST */
553 554
554#else /* CONFIG_BLOCK */ 555#else /* CONFIG_BLOCK */
555 556
556static inline void printk_all_partitions(void) { } 557static inline void printk_all_partitions(void) { }
557 558
558static inline dev_t blk_lookup_devt(const char *name, int part) 559static inline dev_t blk_lookup_devt(const char *name, int partno)
559{ 560{
560 dev_t devt = MKDEV(0, 0); 561 dev_t devt = MKDEV(0, 0);
561 return devt; 562 return devt;