On 24-02-15, Sascha Hauer wrote: > The partition table of a block device may change when it is written to. > Allow to reparse the partition table when this happens. > This is easy when none of the partitions is opened, in that case just > remove the old partitions and call parse_partition_table() again. > When a partition is opened (including mounted) we can't remove it. In > that case continue with the old partition table and print a warning. > > Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx> Just two nits, to make cdev access more opaque. > --- > common/partitions.c | 20 ++++++++++++++++++++ > include/disks.h | 1 + > 2 files changed, 21 insertions(+) > > diff --git a/common/partitions.c b/common/partitions.c > index 78b68276c3..cfcd0e080b 100644 > --- a/common/partitions.c > +++ b/common/partitions.c > @@ -154,6 +154,26 @@ int parse_partition_table(struct block_device *blk) > return rc; > } > > +int reparse_partition_table(struct block_device *blk) > +{ > + struct cdev *cdev = &blk->cdev; > + struct cdev *c, *tmp; > + > + list_for_each_entry(c, &cdev->partitions, partition_entry) { > + if (c->open) { if (cdev_is_open(c)) > + pr_warn("%s is busy, will continue to use old partition table\n", c->name); > + return -EBUSY; > + } > + } > + > + list_for_each_entry_safe(c, tmp, &cdev->partitions, partition_entry) { > + if (c->flags & DEVFS_PARTITION_FROM_TABLE) if (cdev_flag_set(c, DEVFS_PARTITION_FROM_TABLE)) > + cdevfs_del_partition(c); > + } > + > + return parse_partition_table(blk); > +} > + > int partition_parser_register(struct partition_parser *p) > { > list_add_tail(&p->list, &partition_parser_list); > diff --git a/include/disks.h b/include/disks.h > index 1ca7063c54..ccb50d3ce9 100644 > --- a/include/disks.h > +++ b/include/disks.h > @@ -24,5 +24,6 @@ struct partition_entry { > } __attribute__ ((packed)); > > extern int parse_partition_table(struct block_device*); > +int reparse_partition_table(struct block_device *blk); > > #endif /* DISKS_H */ > -- > 2.39.2 > > >