[PATCH] block: genhd: Add disk/partition specific uevent callbacks for partition info

From: John Stultz
Date: Thu Oct 22 2015 - 13:27:47 EST


From: San Mehat <san@xxxxxxxxxx>

This patch has been carried in the Android tree for quite some
time and is one of the few patches required to get a mainline
kernel up and running with an exsiting Android userspace. So I
wanted to submit it for review and consideration if it should
be merged.

For disk devices, a new uevent parameter 'NPARTS' specifies the number
of partitions detected by the kernel. Partition devices get 'PARTN' which
specifies the partitions index in the table, and 'PARTNAME', which
specifies PARTNAME specifices the partition name of a partition device

Android's userspace uses this for creating device node links from the
partition name and number: ie:
/dev/block/platform/soc/by-name/system
or
/dev/block/platform/soc/by-num/p1

One can see its usage here:
https://android.googlesource.com/platform/system/core/+/master/init/devices.cpp#355
and
https://android.googlesource.com/platform/system/core/+/master/init/devices.cpp#494

Thoughts and feedback would be greatly appreciated!

Cc: Jens Axboe <axboe@xxxxxxxxx>
Cc: Rom Lemarchand <romlem@xxxxxxxxxx>
Cc: Android Kernel Team <kernel-team@xxxxxxxxxxx>
Signed-off-by: Dima Zavin <dima@xxxxxxxxxxx>
[jstultz: Added more context to commit message & whitespace fix]
Signed-off-by: John Stultz <john.stultz@xxxxxxxxxx>
---
block/genhd.c | 17 +++++++++++++++++
block/partition-generic.c | 11 +++++++++++
2 files changed, 28 insertions(+)

diff --git a/block/genhd.c b/block/genhd.c
index 0c706f3..248139e 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1115,6 +1115,22 @@ static void disk_release(struct device *dev)
blk_put_queue(disk->queue);
kfree(disk);
}
+
+static int disk_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+ struct gendisk *disk = dev_to_disk(dev);
+ struct disk_part_iter piter;
+ struct hd_struct *part;
+ int cnt = 0;
+
+ disk_part_iter_init(&piter, disk, 0);
+ while ((part = disk_part_iter_next(&piter)))
+ cnt++;
+ disk_part_iter_exit(&piter);
+ add_uevent_var(env, "NPARTS=%u", cnt);
+ return 0;
+}
+
struct class block_class = {
.name = "block",
};
@@ -1134,6 +1150,7 @@ static struct device_type disk_type = {
.groups = disk_attr_groups,
.release = disk_release,
.devnode = block_devnode,
+ .uevent = disk_uevent,
};

#ifdef CONFIG_PROC_FS
diff --git a/block/partition-generic.c b/block/partition-generic.c
index e771113..e5d91c9 100644
--- a/block/partition-generic.c
+++ b/block/partition-generic.c
@@ -216,10 +216,21 @@ static void part_release(struct device *dev)
kfree(p);
}

+static int part_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+ struct hd_struct *part = dev_to_part(dev);
+
+ add_uevent_var(env, "PARTN=%u", part->partno);
+ if (part->info && part->info->volname[0])
+ add_uevent_var(env, "PARTNAME=%s", part->info->volname);
+ return 0;
+}
+
struct device_type part_type = {
.name = "partition",
.groups = part_attr_groups,
.release = part_release,
+ .uevent = part_uevent,
};

static void delete_partition_rcu_cb(struct rcu_head *head)
--
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/