Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17177996ybl; Wed, 1 Jan 2020 23:55:00 -0800 (PST) X-Google-Smtp-Source: APXvYqyWeTf3NS81raMbjTtVhVDga7B03R1JjKgeOrC8jBgyO2pXEr9ygEg72jL/LTjQb5TZkwN7 X-Received: by 2002:a05:6830:1d91:: with SMTP id y17mr86090531oti.276.1577951700543; Wed, 01 Jan 2020 23:55:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577951700; cv=none; d=google.com; s=arc-20160816; b=Cwmb/MvXamj/uBh07sSwas/TYo1N2xZSa/PRA3ccfJCt9h9iJQS0h7/vzCCkikYTXv kokpoRXoPiM7GDAG8cCDav3QH+WO6Quxy0e+6a1n8u3v1MmX7x2GbbitbEOPHQIc6djc RUpJKhIFea3wOrYkx+2nYb53nZ9IRn+N1m+AjHTobvVO8322q3R1gf429mpymS4da9eU DxsGnZUn/fDS/Fk3Zb9gjglu4A6Lt2tkXzZv8slUXhr0Uyob17ABntNIxsp3cFb+YzYK bXbpnoi2+2St7Xtg0A9W3Tyr2t4rdQk/BMpibjARrgNXb2lSdwlYe+guMITZBJw3i/5l bhLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:ironport-sdr:dkim-signature; bh=4qUj5u+oxc6hneYGlI2C/8YFgqo7dDcV2dUhIEALWZk=; b=gkgG3+6tOdj/41X/hIEBMHtBxkdmCItqnyfARGyy/O0ouGNhr0PNUeT+YxMhF9P5Y5 i4w4BLndFYyLTO0ZbPWADkfVUTFghFG1Jn6o4YUJeRUfzXcfJ6O5pZWaRiCNtJgUn7dr TlSE18p7l+UlTH4Jc+7k/l0UMRsKx7nF9A/1yYllCLfD4/B2GpHmz8pe7edQg5Ug4B2K H59uVXs3XA9dbpM9MVpWmkKYe+dilpDvT2SzVFMbe/nZWPc1RKKXqNJ/Ood6s0LTRBgS V5nViOLBX+RJ1ItXCMIUJFmbnEb2jY9N5ttbQhQGt8mGkcaARWOikgcMe2jkTbHLECgX 7RLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=VaEYoJu2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p8si10171445otc.118.2020.01.01.23.54.48; Wed, 01 Jan 2020 23:55:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=VaEYoJu2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727815AbgABHxn (ORCPT + 99 others); Thu, 2 Jan 2020 02:53:43 -0500 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:13891 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727767AbgABHxe (ORCPT ); Thu, 2 Jan 2020 02:53:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1577951614; x=1609487614; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=4qUj5u+oxc6hneYGlI2C/8YFgqo7dDcV2dUhIEALWZk=; b=VaEYoJu2j4/kmV0WmTRWhh4izEyWBb44D3dTwgBDJcIjci2OPvqEK6db ueYsddt7VTSZD5Op/j6z9TFMsnvbxUqAc8Qj9dErxIKJ2NU4zGrAntzWK FRA7dLOwmm895mOgskFw1eWwxUzWbP1n99k1i7vkR8IvAiynBdyWkCi7R E=; IronPort-SDR: DdkJEDsnq8BF7n8r5K3LtX4Lt3Cx0ND9gS41qTOlfsRwfIuOoR8+Aud6YpOvPng1lPX/lFdwEM rVXxoDTImHuw== X-IronPort-AV: E=Sophos;i="5.69,385,1571702400"; d="scan'208";a="17779134" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1e-57e1d233.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 02 Jan 2020 07:53:23 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1e-57e1d233.us-east-1.amazon.com (Postfix) with ESMTPS id 003DF1416C4; Thu, 2 Jan 2020 07:53:19 +0000 (UTC) Received: from EX13D01UWA004.ant.amazon.com (10.43.160.99) by EX13MTAUWA001.ant.amazon.com (10.43.160.118) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 2 Jan 2020 07:53:19 +0000 Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX13d01UWA004.ant.amazon.com (10.43.160.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 2 Jan 2020 07:53:18 +0000 Received: from localhost (172.23.204.141) by mail-relay.amazon.com (10.43.61.243) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Thu, 2 Jan 2020 07:53:18 +0000 From: Balbir Singh To: , , CC: , , , , , , Balbir Singh Subject: [resend v1 1/5] block/genhd: Notify udev about capacity change Date: Thu, 2 Jan 2020 07:53:11 +0000 Message-ID: <20200102075315.22652-2-sblbir@amazon.com> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20200102075315.22652-1-sblbir@amazon.com> References: <20200102075315.22652-1-sblbir@amazon.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Someswarudu Sangaraju Signed-off-by: Balbir Singh --- block/genhd.c | 19 +++++++++++++++++++ include/linux/genhd.h | 1 + 2 files changed, 20 insertions(+) diff --git a/block/genhd.c b/block/genhd.c index ff6268970ddc..94faec98607b 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -46,6 +46,25 @@ 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 a927829bb73a..f1a5ddcc781d 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -449,6 +449,7 @@ static inline int get_disk_ro(struct gendisk *disk) extern void disk_block_events(struct gendisk *disk); extern void disk_unblock_events(struct gendisk *disk); extern void disk_flush_events(struct gendisk *disk, unsigned int mask); +extern void disk_set_capacity(struct gendisk *disk, sector_t size); extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask); /* drivers/char/random.c */ -- 2.16.5