All of lore.kernel.org
 help / color / mirror / Atom feed
From: Milan Broz <mbroz@redhat.com>
To: dm-devel@redhat.com, kay.sievers@vrfy.org
Cc: Milan Broz <mbroz@redhat.com>
Subject: [PATCH 2/3] Add genhd flag requesting notification of partition changes only.
Date: Thu, 18 Mar 2010 14:58:13 +0100	[thread overview]
Message-ID: <1268920694-10960-2-git-send-email-mbroz@redhat.com> (raw)
In-Reply-To: <1268920694-10960-1-git-send-email-mbroz@redhat.com>

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 <mbroz@redhat.com>
---
 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(-)

diff --git a/block/ioctl.c b/block/ioctl.c
index be48ea5..77faed3 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 7b364d7..57da1f7 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1934,6 +1934,7 @@ static struct mapped_device *alloc_dev(int minor)
 	md->disk->private_data = md;
 	sprintf(md->disk->disk_name, "dm-%d", minor);
 	md->disk->flags |= GENHD_FL_SUPPRESS_ADD_EVENT;
+	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 916173b..b66253f 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -548,6 +548,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 ade71ff..64b25f0 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -118,6 +118,9 @@ struct hd_struct {
 #define GENHD_FL_NATIVE_CAPACITY		128
 #define GENHD_FL_SUPPRESS_ADD_EVENT		256
 
+/* notify udev instead of use in-kernel partitioning */
+#define GENHD_FL_PARTITION_CHANGE_NOTIFY	512
+
 #define BLK_SCSI_MAX_CMDS	(256)
 #define BLK_SCSI_CMD_PER_LONG	(BLK_SCSI_MAX_CMDS / (sizeof(long) * 8))
 
@@ -182,6 +185,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)
-- 
1.7.0

  reply	other threads:[~2010-03-18 13:58 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-18 13:58 [PATCH 1/3] Send KOBJ_ADD event after dm resume ioctl Milan Broz
2010-03-18 13:58 ` Milan Broz [this message]
2010-03-18 13:58 ` [PATCH 3/3] Do not send multiple REMOVE events for kobjects Milan Broz
2010-03-18 16:13 ` [PATCH 1/3] Send KOBJ_ADD event after dm resume ioctl Kay Sievers
2010-03-18 17:24   ` Alasdair G Kergon
2010-03-18 21:35   ` Milan Broz
2010-03-19  8:27     ` Kay Sievers
2010-03-19  9:06       ` Lars Ellenberg
2010-03-19  9:24         ` Kay Sievers
2010-03-19  9:49           ` Milan Broz
2010-03-19 10:16             ` Kay Sievers
2010-03-19 11:14               ` Milan Broz
2010-03-19 11:44                 ` Kay Sievers
2010-03-19 12:08                   ` Milan Broz
2010-03-19 12:14                     ` Kay Sievers
2010-03-19 11:50                 ` Hannes Reinecke
2010-03-19 12:00               ` Alasdair G Kergon
2010-03-19 12:12               ` Alasdair G Kergon
2010-03-19 12:16                 ` Kay Sievers
2010-03-19 13:17                   ` Peter Rajnoha
2010-03-19 13:24           ` Peter Rajnoha
2010-03-19 13:43             ` Kay Sievers
2010-03-19 13:47               ` Alasdair G Kergon
2010-03-19 13:58               ` David Zeuthen
2010-03-19 14:34                 ` Alasdair G Kergon
2010-03-19 14:59                   ` David Zeuthen
2010-03-19 15:24                     ` Alasdair G Kergon
2010-03-19 16:01                       ` David Zeuthen
2010-03-19 16:36                         ` Alasdair G Kergon
2010-03-22 10:11                         ` Milan Broz
2010-03-19 15:55                 ` Mike Snitzer
2010-03-19 16:08                   ` David Zeuthen
2010-03-19 14:08             ` Hannes Reinecke
2010-03-19 15:05               ` Peter Rajnoha
2010-03-19 15:14                 ` David Zeuthen
2010-03-19 15:51                   ` Peter Rajnoha
2010-03-19  9:10       ` Milan Broz
2010-03-19  9:22         ` Kay Sievers
2010-03-19  9:42 ` Hannes Reinecke
2010-03-19 12:27   ` Alasdair G Kergon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1268920694-10960-2-git-send-email-mbroz@redhat.com \
    --to=mbroz@redhat.com \
    --cc=dm-devel@redhat.com \
    --cc=kay.sievers@vrfy.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.