From patchwork Tue Jul 21 16:13:06 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Broz X-Patchwork-Id: 36563 Received: from hormel.redhat.com (hormel1.redhat.com [209.132.177.33]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n6LGDFuR006169 for ; Tue, 21 Jul 2009 16:13:15 GMT Received: from listman.util.phx.redhat.com (listman.util.phx.redhat.com [10.8.4.110]) by hormel.redhat.com (Postfix) with ESMTP id 7C55B619B07; Tue, 21 Jul 2009 12:13:14 -0400 (EDT) Received: from int-mx2.corp.redhat.com ([172.16.27.26]) by listman.util.phx.redhat.com (8.13.1/8.13.1) with ESMTP id n6LGDAAB032282 for ; Tue, 21 Jul 2009 12:13:10 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n6LGD915017727; Tue, 21 Jul 2009 12:13:10 -0400 Received: from [10.34.32.183] (mazybook.englab.brq.redhat.com [10.34.32.183]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n6LGD6aj009834; Tue, 21 Jul 2009 12:13:07 -0400 Message-ID: <4A65E912.6020706@redhat.com> Date: Tue, 21 Jul 2009 18:13:06 +0200 From: Milan Broz User-Agent: Thunderbird 2.0.0.22 (X11/20090605) MIME-Version: 1.0 To: device-mapper development References: <200907081414.50698.knikanth@suse.de> <20090720182324.GD32330@agk-dp.fab.redhat.com> In-Reply-To: <20090720182324.GD32330@agk-dp.fab.redhat.com> X-Enigmail-Version: 0.96.0 X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 X-loop: dm-devel@redhat.com Cc: Nikanth Karthikesan , Alasdair G Kergon , Jens Axboe Subject: [dm-devel] [PATCH][RFC] Emulate BLKRRPART on device-mapper X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.5 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com Alasdair G Kergon wrote: > On Wed, Jul 08, 2009 at 02:14:50PM +0530, Nikanth Karthikesan wrote: > >> From: Hannes Reinecke >> Subject: Emulate BLKRRPART on device-mapper >> >> Partitions on device-mapper devices are managed by kpartx (if at >> all). So if we were just to send out a 'change' event if someone >> called BLKRRPART on these devices, kpartx will be triggered via udev >> and can manage the partitions accordingly. >> >> > Please could I have a 'Tested-by' for this one? > I am afraid that this patch cannot work, BLRRPART never reach this code. I tried another idea - or is there better way how to achieve that? Milan --- From: Milan Broz Add genhd flag requesting notification of partition changes only. This patch provides notification mechanism which allows handle partition code in userspace. If the BLKRRPART ioctl arrives and GENHD_FL_PARTITION_CHANGE_NOTIFY is set, just send uevent and ignore in-kernel partitioning code. This is useful e.g. for device-mapper devices, which can use kpartx or similar tool in udev rules. Signed-off-by: Milan Broz --- block/ioctl.c | 3 ++- drivers/md/dm.c | 1 + fs/partitions/check.c | 6 ++++++ include/linux/genhd.h | 8 ++++++++ 4 files changed, 17 insertions(+), 1 deletions(-) -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel diff --git a/block/ioctl.c b/block/ioctl.c index 500e4c7..bce793f 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -101,7 +101,8 @@ static int blkdev_reread_part(struct block_device *bdev) struct gendisk *disk = bdev->bd_disk; int res; - if (!disk_partitionable(disk) || bdev != bdev->bd_contains) + if (!disk_userspace_partitions(disk) && + (!disk_partitionable(disk) || bdev != bdev->bd_contains)) return -EINVAL; if (!capable(CAP_SYS_ADMIN)) return -EACCES; diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 9acd54a..1186ce1 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1791,6 +1791,7 @@ static struct mapped_device *alloc_dev(int minor) md->disk->queue = md->queue; md->disk->private_data = md; sprintf(md->disk->disk_name, "dm-%d", minor); + md->disk->flags |= GENHD_FL_PARTITION_CHANGE_NOTIFY; add_disk(md->disk); format_dev_t(md->name, MKDEV(_major, minor)); diff --git a/fs/partitions/check.c b/fs/partitions/check.c index ea4e6cb..bb42c44 100644 --- a/fs/partitions/check.c +++ b/fs/partitions/check.c @@ -521,6 +521,12 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev) struct parsed_partitions *state; int p, highest, res; + /* partitions handled in userspace, just send change event */ + if (disk_userspace_partitions(disk)) { + kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE); + return 0; + } + if (bdev->bd_part_count) return -EBUSY; res = invalidate_partition(disk, 0); diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 45fc320..a241bd6 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -116,6 +116,9 @@ struct hd_struct { #define GENHD_FL_EXT_DEVT 64 /* allow extended devt */ #define GENHD_FL_NATIVE_CAPACITY 128 +/* notify udev instead of use in-kernel partitioning */ +#define GENHD_FL_PARTITION_CHANGE_NOTIFY 256 + #define BLK_SCSI_MAX_CMDS (256) #define BLK_SCSI_CMD_PER_LONG (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8)) @@ -180,6 +183,11 @@ static inline struct gendisk *part_to_disk(struct hd_struct *part) return NULL; } +static inline bool disk_userspace_partitions(struct gendisk *disk) +{ + return (disk->flags & GENHD_FL_PARTITION_CHANGE_NOTIFY) ? 1 : 0; +} + static inline int disk_max_parts(struct gendisk *disk) { if (disk->flags & GENHD_FL_EXT_DEVT)