Skip to content

Commit 6d1d805

Browse files
redpigJens Axboe
authored andcommitted
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: 2bfc96a (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>
1 parent 1441779 commit 6d1d805

File tree

5 files changed

+76
-6
lines changed

5 files changed

+76
-6
lines changed

block/genhd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ static void disk_release(struct device *dev)
10041004
kfree(disk->random);
10051005
disk_replace_part_tbl(disk, NULL);
10061006
free_part_stats(&disk->part0);
1007+
free_part_info(&disk->part0);
10071008
kfree(disk);
10081009
}
10091010
struct class block_class = {

block/ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
6262

6363
/* all seems OK */
6464
part = add_partition(disk, partno, start, length,
65-
ADDPART_FLAG_NONE);
65+
ADDPART_FLAG_NONE, NULL);
6666
mutex_unlock(&bdev->bd_mutex);
6767
return IS_ERR(part) ? PTR_ERR(part) : 0;
6868
case BLKPG_DEL_PARTITION:

fs/partitions/check.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ static void part_release(struct device *dev)
352352
{
353353
struct hd_struct *p = dev_to_part(dev);
354354
free_part_stats(p);
355+
free_part_info(p);
355356
kfree(p);
356357
}
357358

@@ -401,7 +402,8 @@ static DEVICE_ATTR(whole_disk, S_IRUSR | S_IRGRP | S_IROTH,
401402
whole_disk_show, NULL);
402403

403404
struct hd_struct *add_partition(struct gendisk *disk, int partno,
404-
sector_t start, sector_t len, int flags)
405+
sector_t start, sector_t len, int flags,
406+
struct partition_meta_info *info)
405407
{
406408
struct hd_struct *p;
407409
dev_t devt = MKDEV(0, 0);
@@ -438,6 +440,14 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
438440
p->partno = partno;
439441
p->policy = get_disk_ro(disk);
440442

443+
if (info) {
444+
struct partition_meta_info *pinfo = alloc_part_info(disk);
445+
if (!pinfo)
446+
goto out_free_stats;
447+
memcpy(pinfo, info, sizeof(*info));
448+
p->info = pinfo;
449+
}
450+
441451
dname = dev_name(ddev);
442452
if (isdigit(dname[strlen(dname) - 1]))
443453
dev_set_name(pdev, "%sp%d", dname, partno);
@@ -451,7 +461,7 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
451461

452462
err = blk_alloc_devt(p, &devt);
453463
if (err)
454-
goto out_free_stats;
464+
goto out_free_info;
455465
pdev->devt = devt;
456466

457467
/* delay uevent until 'holders' subdir is created */
@@ -481,6 +491,8 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
481491

482492
return p;
483493

494+
out_free_info:
495+
free_part_info(p);
484496
out_free_stats:
485497
free_part_stats(p);
486498
out_free:
@@ -642,6 +654,7 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
642654
/* add partitions */
643655
for (p = 1; p < state->limit; p++) {
644656
sector_t size, from;
657+
struct partition_meta_info *info = NULL;
645658

646659
size = state->parts[p].size;
647660
if (!size)
@@ -675,8 +688,12 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
675688
size = get_capacity(disk) - from;
676689
}
677690
}
691+
692+
if (state->parts[p].has_info)
693+
info = &state->parts[p].info;
678694
part = add_partition(disk, p, from, size,
679-
state->parts[p].flags);
695+
state->parts[p].flags,
696+
&state->parts[p].info);
680697
if (IS_ERR(part)) {
681698
printk(KERN_ERR " %s: p%d could not be added: %ld\n",
682699
disk->disk_name, p, -PTR_ERR(part));

fs/partitions/check.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <linux/pagemap.h>
22
#include <linux/blkdev.h>
3+
#include <linux/genhd.h>
34

45
/*
56
* add_gd_partition adds a partitions details to the devices partition
@@ -12,6 +13,8 @@ struct parsed_partitions {
1213
sector_t from;
1314
sector_t size;
1415
int flags;
16+
bool has_info;
17+
struct partition_meta_info info;
1518
} parts[DISK_MAX_PARTS];
1619
int next;
1720
int limit;

include/linux/genhd.h

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/types.h>
1313
#include <linux/kdev_t.h>
1414
#include <linux/rcupdate.h>
15+
#include <linux/slab.h>
1516

1617
#ifdef CONFIG_BLOCK
1718

@@ -86,7 +87,15 @@ struct disk_stats {
8687
unsigned long io_ticks;
8788
unsigned long time_in_queue;
8889
};
89-
90+
91+
#define PARTITION_META_INFO_VOLNAMELTH 64
92+
#define PARTITION_META_INFO_UUIDLTH 16
93+
94+
struct partition_meta_info {
95+
u8 uuid[PARTITION_META_INFO_UUIDLTH]; /* always big endian */
96+
u8 volname[PARTITION_META_INFO_VOLNAMELTH];
97+
};
98+
9099
struct hd_struct {
91100
sector_t start_sect;
92101
sector_t nr_sects;
@@ -95,6 +104,7 @@ struct hd_struct {
95104
struct device __dev;
96105
struct kobject *holder_dir;
97106
int policy, partno;
107+
struct partition_meta_info *info;
98108
#ifdef CONFIG_FAIL_MAKE_REQUEST
99109
int make_it_fail;
100110
#endif
@@ -181,6 +191,30 @@ static inline struct gendisk *part_to_disk(struct hd_struct *part)
181191
return NULL;
182192
}
183193

194+
static inline void part_pack_uuid(const u8 *uuid_str, u8 *to)
195+
{
196+
int i;
197+
for (i = 0; i < 16; ++i) {
198+
*to++ = (hex_to_bin(*uuid_str) << 4) |
199+
(hex_to_bin(*(uuid_str + 1)));
200+
uuid_str += 2;
201+
switch (i) {
202+
case 3:
203+
case 5:
204+
case 7:
205+
case 9:
206+
uuid_str++;
207+
continue;
208+
}
209+
}
210+
}
211+
212+
static inline char *part_unpack_uuid(const u8 *uuid, char *out)
213+
{
214+
sprintf(out, "%pU", uuid);
215+
return out;
216+
}
217+
184218
static inline int disk_max_parts(struct gendisk *disk)
185219
{
186220
if (disk->flags & GENHD_FL_EXT_DEVT)
@@ -342,6 +376,19 @@ static inline int part_in_flight(struct hd_struct *part)
342376
return part->in_flight[0] + part->in_flight[1];
343377
}
344378

379+
static inline struct partition_meta_info *alloc_part_info(struct gendisk *disk)
380+
{
381+
if (disk)
382+
return kzalloc_node(sizeof(struct partition_meta_info),
383+
GFP_KERNEL, disk->node_id);
384+
return kzalloc(sizeof(struct partition_meta_info), GFP_KERNEL);
385+
}
386+
387+
static inline void free_part_info(struct hd_struct *part)
388+
{
389+
kfree(part->info);
390+
}
391+
345392
/* block/blk-core.c */
346393
extern void part_round_stats(int cpu, struct hd_struct *part);
347394

@@ -533,7 +580,9 @@ extern int disk_expand_part_tbl(struct gendisk *disk, int target);
533580
extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev);
534581
extern struct hd_struct * __must_check add_partition(struct gendisk *disk,
535582
int partno, sector_t start,
536-
sector_t len, int flags);
583+
sector_t len, int flags,
584+
struct partition_meta_info
585+
*info);
537586
extern void delete_partition(struct gendisk *, int);
538587
extern void printk_all_partitions(void);
539588

0 commit comments

Comments
 (0)