Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block, partition: add partition_meta_info to hd_struct

I'm reposting this patch series as v4 since there have been no additional
comments, and I cleaned up one extra bit of unneeded code (in 3/3). The patches
are against Linus's tree: 2bfc96a127bc1cc94d26bfaa40159966064f9c8c
(2.6.36-rc3).

Would this patchset be suitable for inclusion in an mm branch?

This changes adds a partition_meta_info struct which itself contains a
union of structures that provide partition table specific metadata.

This change leaves the union empty. The subsequent patch includes an
implementation for CONFIG_EFI_PARTITION-based metadata.

Signed-off-by: Will Drewry <wad@chromium.org>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>

authored by

Will Drewry and committed by
Jens Axboe
6d1d8050 14417799

+76 -6
+1
block/genhd.c
··· 1004 1004 kfree(disk->random); 1005 1005 disk_replace_part_tbl(disk, NULL); 1006 1006 free_part_stats(&disk->part0); 1007 + free_part_info(&disk->part0); 1007 1008 kfree(disk); 1008 1009 } 1009 1010 struct class block_class = {
+1 -1
block/ioctl.c
··· 62 62 63 63 /* all seems OK */ 64 64 part = add_partition(disk, partno, start, length, 65 - ADDPART_FLAG_NONE); 65 + ADDPART_FLAG_NONE, NULL); 66 66 mutex_unlock(&bdev->bd_mutex); 67 67 return IS_ERR(part) ? PTR_ERR(part) : 0; 68 68 case BLKPG_DEL_PARTITION:
+20 -3
fs/partitions/check.c
··· 352 352 { 353 353 struct hd_struct *p = dev_to_part(dev); 354 354 free_part_stats(p); 355 + free_part_info(p); 355 356 kfree(p); 356 357 } 357 358 ··· 402 401 whole_disk_show, NULL); 403 402 404 403 struct hd_struct *add_partition(struct gendisk *disk, int partno, 405 - sector_t start, sector_t len, int flags) 404 + sector_t start, sector_t len, int flags, 405 + struct partition_meta_info *info) 406 406 { 407 407 struct hd_struct *p; 408 408 dev_t devt = MKDEV(0, 0); ··· 440 438 p->partno = partno; 441 439 p->policy = get_disk_ro(disk); 442 440 441 + if (info) { 442 + struct partition_meta_info *pinfo = alloc_part_info(disk); 443 + if (!pinfo) 444 + goto out_free_stats; 445 + memcpy(pinfo, info, sizeof(*info)); 446 + p->info = pinfo; 447 + } 448 + 443 449 dname = dev_name(ddev); 444 450 if (isdigit(dname[strlen(dname) - 1])) 445 451 dev_set_name(pdev, "%sp%d", dname, partno); ··· 461 451 462 452 err = blk_alloc_devt(p, &devt); 463 453 if (err) 464 - goto out_free_stats; 454 + goto out_free_info; 465 455 pdev->devt = devt; 466 456 467 457 /* delay uevent until 'holders' subdir is created */ ··· 491 481 492 482 return p; 493 483 484 + out_free_info: 485 + free_part_info(p); 494 486 out_free_stats: 495 487 free_part_stats(p); 496 488 out_free: ··· 654 642 /* add partitions */ 655 643 for (p = 1; p < state->limit; p++) { 656 644 sector_t size, from; 645 + struct partition_meta_info *info = NULL; 657 646 658 647 size = state->parts[p].size; 659 648 if (!size) ··· 688 675 size = get_capacity(disk) - from; 689 676 } 690 677 } 678 + 679 + if (state->parts[p].has_info) 680 + info = &state->parts[p].info; 691 681 part = add_partition(disk, p, from, size, 692 - state->parts[p].flags); 682 + state->parts[p].flags, 683 + &state->parts[p].info); 693 684 if (IS_ERR(part)) { 694 685 printk(KERN_ERR " %s: p%d could not be added: %ld\n", 695 686 disk->disk_name, p, -PTR_ERR(part));
+3
fs/partitions/check.h
··· 1 1 #include <linux/pagemap.h> 2 2 #include <linux/blkdev.h> 3 + #include <linux/genhd.h> 3 4 4 5 /* 5 6 * add_gd_partition adds a partitions details to the devices partition ··· 13 12 sector_t from; 14 13 sector_t size; 15 14 int flags; 15 + bool has_info; 16 + struct partition_meta_info info; 16 17 } parts[DISK_MAX_PARTS]; 17 18 int next; 18 19 int limit;
+51 -2
include/linux/genhd.h
··· 12 12 #include <linux/types.h> 13 13 #include <linux/kdev_t.h> 14 14 #include <linux/rcupdate.h> 15 + #include <linux/slab.h> 15 16 16 17 #ifdef CONFIG_BLOCK 17 18 ··· 87 86 unsigned long io_ticks; 88 87 unsigned long time_in_queue; 89 88 }; 90 - 89 + 90 + #define PARTITION_META_INFO_VOLNAMELTH 64 91 + #define PARTITION_META_INFO_UUIDLTH 16 92 + 93 + struct partition_meta_info { 94 + u8 uuid[PARTITION_META_INFO_UUIDLTH]; /* always big endian */ 95 + u8 volname[PARTITION_META_INFO_VOLNAMELTH]; 96 + }; 97 + 91 98 struct hd_struct { 92 99 sector_t start_sect; 93 100 sector_t nr_sects; ··· 104 95 struct device __dev; 105 96 struct kobject *holder_dir; 106 97 int policy, partno; 98 + struct partition_meta_info *info; 107 99 #ifdef CONFIG_FAIL_MAKE_REQUEST 108 100 int make_it_fail; 109 101 #endif ··· 189 179 return dev_to_disk(part_to_dev(part)); 190 180 } 191 181 return NULL; 182 + } 183 + 184 + static inline void part_pack_uuid(const u8 *uuid_str, u8 *to) 185 + { 186 + int i; 187 + for (i = 0; i < 16; ++i) { 188 + *to++ = (hex_to_bin(*uuid_str) << 4) | 189 + (hex_to_bin(*(uuid_str + 1))); 190 + uuid_str += 2; 191 + switch (i) { 192 + case 3: 193 + case 5: 194 + case 7: 195 + case 9: 196 + uuid_str++; 197 + continue; 198 + } 199 + } 200 + } 201 + 202 + static inline char *part_unpack_uuid(const u8 *uuid, char *out) 203 + { 204 + sprintf(out, "%pU", uuid); 205 + return out; 192 206 } 193 207 194 208 static inline int disk_max_parts(struct gendisk *disk) ··· 374 340 static inline int part_in_flight(struct hd_struct *part) 375 341 { 376 342 return part->in_flight[0] + part->in_flight[1]; 343 + } 344 + 345 + static inline struct partition_meta_info *alloc_part_info(struct gendisk *disk) 346 + { 347 + if (disk) 348 + return kzalloc_node(sizeof(struct partition_meta_info), 349 + GFP_KERNEL, disk->node_id); 350 + return kzalloc(sizeof(struct partition_meta_info), GFP_KERNEL); 351 + } 352 + 353 + static inline void free_part_info(struct hd_struct *part) 354 + { 355 + kfree(part->info); 377 356 } 378 357 379 358 /* block/blk-core.c */ ··· 580 533 extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev); 581 534 extern struct hd_struct * __must_check add_partition(struct gendisk *disk, 582 535 int partno, sector_t start, 583 - sector_t len, int flags); 536 + sector_t len, int flags, 537 + struct partition_meta_info 538 + *info); 584 539 extern void delete_partition(struct gendisk *, int); 585 540 extern void printk_all_partitions(void); 586 541