2010-07-30 09:39:04

by Kay Sievers

[permalink] [raw]
Subject: [PATCH] block: move del_gendisk() from fs/partitions/check.c to block/genhd.c

From: Kay Sievers <[email protected]>
Subject: block: move del_gendisk() from fs/partitions/check.c to block/genhd.c

Disk code belongs into genhd, not into the partition scanner code.

Signed-Off-By: Kay Sievers <[email protected]>
---
block/genhd.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
fs/partitions/check.c | 51 -------------------------------------------------
2 files changed, 52 insertions(+), 51 deletions(-)

--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1344,3 +1344,55 @@ int invalidate_partition(struct gendisk
}

EXPORT_SYMBOL(invalidate_partition);
+
+void del_gendisk(struct gendisk *disk)
+{
+ struct disk_part_iter piter;
+ struct hd_struct *part;
+
+ /* invalidate stuff */
+ disk_part_iter_init(&piter, disk,
+ DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE);
+ while ((part = disk_part_iter_next(&piter))) {
+ invalidate_partition(disk, part->partno);
+ delete_partition(disk, part->partno);
+ }
+ disk_part_iter_exit(&piter);
+
+ invalidate_partition(disk, 0);
+ blk_free_devt(disk_to_dev(disk)->devt);
+ set_capacity(disk, 0);
+ disk->flags &= ~GENHD_FL_UP;
+ unlink_gendisk(disk);
+ part_stat_set_all(&disk->part0, 0);
+ disk->part0.stamp = 0;
+
+ kobject_put(disk->part0.holder_dir);
+ kobject_put(disk->slave_dir);
+ disk->driverfs_dev = NULL;
+#ifndef CONFIG_SYSFS_DEPRECATED
+ sysfs_remove_link(block_depr, dev_name(disk_to_dev(disk)));
+#endif
+ device_del(disk_to_dev(disk));
+}
+
+unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector *p)
+{
+ struct address_space *mapping = bdev->bd_inode->i_mapping;
+ struct page *page;
+
+ page = read_mapping_page(mapping, (pgoff_t)(n >> (PAGE_CACHE_SHIFT-9)),
+ NULL);
+ if (!IS_ERR(page)) {
+ if (PageError(page))
+ goto fail;
+ p->v = page;
+ return (unsigned char *)page_address(page) + ((n & ((1 << (PAGE_CACHE_SHIFT - 9)) - 1)) << 9);
+fail:
+ page_cache_release(page);
+ }
+ p->v = NULL;
+ return NULL;
+}
+
+EXPORT_SYMBOL(read_dev_sector);
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -619,54 +619,3 @@ rescan:
return 0;
}

-unsigned char *read_dev_sector(struct block_device *bdev, sector_t n, Sector *p)
-{
- struct address_space *mapping = bdev->bd_inode->i_mapping;
- struct page *page;
-
- page = read_mapping_page(mapping, (pgoff_t)(n >> (PAGE_CACHE_SHIFT-9)),
- NULL);
- if (!IS_ERR(page)) {
- if (PageError(page))
- goto fail;
- p->v = page;
- return (unsigned char *)page_address(page) + ((n & ((1 << (PAGE_CACHE_SHIFT - 9)) - 1)) << 9);
-fail:
- page_cache_release(page);
- }
- p->v = NULL;
- return NULL;
-}
-
-EXPORT_SYMBOL(read_dev_sector);
-
-void del_gendisk(struct gendisk *disk)
-{
- struct disk_part_iter piter;
- struct hd_struct *part;
-
- /* invalidate stuff */
- disk_part_iter_init(&piter, disk,
- DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE);
- while ((part = disk_part_iter_next(&piter))) {
- invalidate_partition(disk, part->partno);
- delete_partition(disk, part->partno);
- }
- disk_part_iter_exit(&piter);
-
- invalidate_partition(disk, 0);
- blk_free_devt(disk_to_dev(disk)->devt);
- set_capacity(disk, 0);
- disk->flags &= ~GENHD_FL_UP;
- unlink_gendisk(disk);
- part_stat_set_all(&disk->part0, 0);
- disk->part0.stamp = 0;
-
- kobject_put(disk->part0.holder_dir);
- kobject_put(disk->slave_dir);
- disk->driverfs_dev = NULL;
-#ifndef CONFIG_SYSFS_DEPRECATED
- sysfs_remove_link(block_depr, dev_name(disk_to_dev(disk)));
-#endif
- device_del(disk_to_dev(disk));
-}


2010-07-30 09:40:41

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH] block: move del_gendisk() from fs/partitions/check.c to block/genhd.c

On Fri, Jul 30, 2010 at 11:39:01AM +0200, Kay Sievers wrote:
> From: Kay Sievers <[email protected]>
> Subject: block: move del_gendisk() from fs/partitions/check.c to block/genhd.c
>
> Disk code belongs into genhd, not into the partition scanner code.

Sounds fine for del_gendisk, but read_dev_sector which isn't mentioned
here really is for partitioning.

2010-07-30 09:57:13

by Kay Sievers

[permalink] [raw]
Subject: Re: [PATCH] block: move del_gendisk() from fs/partitions/check.c to block/genhd.c

On Fri, Jul 30, 2010 at 11:40, Christoph Hellwig <[email protected]> wrote:
> On Fri, Jul 30, 2010 at 11:39:01AM +0200, Kay Sievers wrote:
>> From: Kay Sievers <[email protected]>
>> Subject: block: move del_gendisk() from fs/partitions/check.c to block/genhd.c
>>
>> Disk code belongs into genhd, not into the partition scanner code.
>
> Sounds fine for del_gendisk, but read_dev_sector which isn't mentioned
> here really is for partitioning.

Right, the next patch moves it to /block/partition.c, because all the
sysfs and driver core code really should not be below fs/.

If you want me to re reshuffle that, let me know. I was just annoyed
again, and after all these years I though it's time to move that stuff
around. :)

Thanks,
Kay

2010-07-30 09:58:56

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH] block: move del_gendisk() from fs/partitions/check.c to block/genhd.c

On Fri, Jul 30, 2010 at 11:56:56AM +0200, Kay Sievers wrote:
> > Sounds fine for del_gendisk, but read_dev_sector which isn't mentioned
> > here really is for partitioning.
>
> Right, the next patch moves it to /block/partition.c, because all the
> sysfs and driver core code really should not be below fs/.
>
> If you want me to re reshuffle that, let me know. I was just annoyed
> again, and after all these years I though it's time to move that stuff
> around. :)

So then please keep read_dev_sector in the file where it is right now,
and just move the whole directory from fs/partitions/ to
block/partitions. While you're at it fs/bio.c and fs/block_dev.c
really belong into block/, too. The latter could also need some split
up.

2010-07-30 10:04:29

by Kay Sievers

[permalink] [raw]
Subject: Re: [PATCH] block: move del_gendisk() from fs/partitions/check.c to block/genhd.c

On Fri, Jul 30, 2010 at 11:58, Christoph Hellwig <[email protected]> wrote:
> On Fri, Jul 30, 2010 at 11:56:56AM +0200, Kay Sievers wrote:
>> > Sounds fine for del_gendisk, but read_dev_sector which isn't mentioned
>> > here really is for partitioning.
>>
>> Right, the next patch moves it to /block/partition.c, because all the
>> sysfs and driver core code really should not be below fs/.
>>
>> If you want me to re reshuffle that, let me know. I was just annoyed
>> again, and after all these years I though it's time to move that stuff
>> around. :)
>
> So then please keep read_dev_sector in the file where it is right now,
> and just move the whole directory from fs/partitions/ to
> block/partitions.  While you're at it fs/bio.c and fs/block_dev.c
> really belong into block/, too.  The latter could also need some split
> up.

Hehe, the usual thing: "If you want that, fix all of it." :)

Are you sure, that partition formats don't belong in fs/? It's kinda
specific on-disk-layout like a fs, and I would have no problem with
that staying in fs/.

Kay

2010-07-30 10:40:53

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH] block: move del_gendisk() from fs/partitions/check.c to block/genhd.c

On Fri, Jul 30, 2010 at 12:04:09PM +0200, Kay Sievers wrote:
> Are you sure, that partition formats don't belong in fs/? It's kinda
> specific on-disk-layout like a fs, and I would have no problem with
> that staying in fs/.

It's on disk formats, but it's not related to filesystems at all.