Re: [resend v1 1/5] block/genhd: Notify udev about capacity change

From: Chaitanya Kulkarni
Date: Fri Jan 03 2020 - 01:17:10 EST


On 01/01/2020 11:53 PM, Balbir Singh wrote:
> Allow block/genhd to notify user space (via udev) about disk size changes
> using a new helper disk_set_capacity(), which is a wrapper on top
> of set_capacity(). disk_set_capacity() will only notify via udev if
> the current capacity or the target capacity is not zero.
>
> Suggested-by: Christoph Hellwig<hch@xxxxxx>
> Signed-off-by: Someswarudu Sangaraju<ssomesh@xxxxxxxxxx>
> Signed-off-by: Balbir Singh<sblbir@xxxxxxxxxx>
> ---

Since disk_set_capacity(() is on the same line as set_capacity()
we should follow the same convention, which is :-

1. Avoid exporting symbol.
2. Mark new function in-line.

Unless there is a very specific reason for breaking the pattern.

Why not this (totally untested but easy convey above comment)
on the top of this patch ?

# git diff
diff --git a/block/genhd.c b/block/genhd.c
index 94faec98607b..ff6268970ddc 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -46,25 +46,6 @@ static void disk_add_events(struct gendisk *disk);
static void disk_del_events(struct gendisk *disk);
static void disk_release_events(struct gendisk *disk);

-/*
- * Set disk capacity and notify if the size is not currently
- * zero and will not be set to zero
- */
-void disk_set_capacity(struct gendisk *disk, sector_t size)
-{
- sector_t capacity = get_capacity(disk);
-
- set_capacity(disk, size);
- if (capacity != 0 && size != 0) {
- char *envp[] = { "RESIZE=1", NULL };
-
- kobject_uevent_env(&disk_to_dev(disk)->kobj,
KOBJ_CHANGE, envp);
- }
-}
-
-EXPORT_SYMBOL_GPL(disk_set_capacity);
-
-
void part_inc_in_flight(struct request_queue *q, struct hd_struct
*part, int rw)
{
if (queue_is_mq(q))
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index d5e87d7cc357..5e595a28f893 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -469,6 +469,22 @@ static inline void set_capacity(struct gendisk
*disk, sector_t size)
disk->part0.nr_sects = size;
}

+/*
+ * Set disk capacity and notify if the size is not currently
+ * zero and will not be set to zero
+ */
+static inline void disk_set_capacity(struct gendisk *disk, sector_t size)
+{
+ sector_t capacity = get_capacity(disk);
+
+ set_capacity(disk, size);
+ if (capacity != 0 && size != 0) {
+ char *envp[] = { "RESIZE=1", NULL };
+
+ kobject_uevent_env(&disk_to_dev(disk)->kobj,
KOBJ_CHANGE, envp);
+ }
+}
+
#ifdef CONFIG_SOLARIS_X86_PARTITION