Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4044547ybv; Tue, 25 Feb 2020 12:03:54 -0800 (PST) X-Google-Smtp-Source: APXvYqwPuh0Fi865zX9CEOu987TkxQYLujiexFTzHRmmsCQ3Kq5ucZawmishy1Ud9LY1wNJ7qyEq X-Received: by 2002:aca:e106:: with SMTP id y6mr464819oig.131.1582661034138; Tue, 25 Feb 2020 12:03:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582661034; cv=none; d=google.com; s=arc-20160816; b=fsnr25QYQVkcaLRCySz3+b6/sHsvJ0+FW8+sjEtrhnzIeIcG+Idjp9xaNiHc59Li0j jC1qQfgMuRQj3mlwp5KLA+47wo6jeHjW1OHrcRb9vLKhVjTG41mahdObM6OBcczMdU9b EcUup0cSOi6jZbOIUczEhh39HgSrH+hfJ9mNlRmN+wZDQksEIdrhWVlm32KUZTvTmhjX GjXt2aVrXyyP/D5sgWu2rfhkNWabuwN/QZCCN/l4whWZrzS58MCzBvQeNVdqSunhPS1e gVIqZ7cBgG8rM0afUk0M2qPc25OZexIULCti9B4gi17AA4wFYxO3A/HYTOd7VwYqxXEi TT+Q== 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=88Zx2T7WCBJVENwjrv8btKUmZjU2WnlNsWj7L+qkaVc=; b=zXZ0h5pnf2fZ2aQRuHMJuASkJVVTtrleJ5SbupoNRbtGJtpDu2Fg3Z95+7OjUotMJp NRyJERiAm7mJDP06OEohJo+7Z9KrXiChTlW3f1SBdtktqKFm3fyWZpgFjW9WK9LgeMTj Ru58Es/heceSgyDNSrpoxaeNZH2U3r13K/ak6SYAb81Y0A/Q4wpv7XLQ5UOXNpw+zNYW VdJiCYicNs7e36/PafNS69Ysef8lzIhEKTA+2YNrB/FPQ6a/NMjdx74HfDUx4yy1dpXy pD4Ax4EaPRrrxzIE5WKMrqDu2zNaX0TO3AFyK37cDeCSTIi6PCTjRA1+AINdghXXmsmR LtBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=vaotqlGj; 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 u23si138139otj.242.2020.02.25.12.03.41; Tue, 25 Feb 2020 12:03:54 -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=vaotqlGj; 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 S1731502AbgBYUB5 (ORCPT + 99 others); Tue, 25 Feb 2020 15:01:57 -0500 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]:10808 "EHLO smtp-fw-6001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730793AbgBYUB5 (ORCPT ); Tue, 25 Feb 2020 15:01:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1582660916; x=1614196916; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=88Zx2T7WCBJVENwjrv8btKUmZjU2WnlNsWj7L+qkaVc=; b=vaotqlGj6oIu4fQ0U1rNUzlpYabl+HgJ6nI5Nb06MMTI93Y1oIPDhcvP 5FLWx4D3OL2Q0yRLFGvC4yDyEFitexs984ccLXZn3c74Awr9ucu2bJeKa STwoCY9akYxfjcVgMhtjl5I29cvQqnMZndPisDEoPrW9YcyBCQMZyNagJ Y=; IronPort-SDR: 5CLN0VWdABdktqWY1FUB1mol1m/QEG+VE+D1kMB8M7JKZ4KRriFR/v+hbZ54hcgqxSD9dWjnEe R1LxXjDB2sbw== X-IronPort-AV: E=Sophos;i="5.70,485,1574121600"; d="scan'208";a="19630616" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-2225282c.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 25 Feb 2020 20:01:43 +0000 Received: from EX13MTAUWC001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2c-2225282c.us-west-2.amazon.com (Postfix) with ESMTPS id 32F2FA1D85; Tue, 25 Feb 2020 20:01:42 +0000 (UTC) Received: from EX13D11UWC003.ant.amazon.com (10.43.162.162) by EX13MTAUWC001.ant.amazon.com (10.43.162.135) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 25 Feb 2020 20:01:41 +0000 Received: from EX13MTAUWC001.ant.amazon.com (10.43.162.135) by EX13D11UWC003.ant.amazon.com (10.43.162.162) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 25 Feb 2020 20:01:41 +0000 Received: from localhost (10.2.75.237) by mail-relay.amazon.com (10.43.162.232) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 25 Feb 2020 20:01:41 +0000 From: Balbir Singh To: , , CC: , , , , , Balbir Singh , Someswarudu Sangaraju Subject: [PATCH v2 1/5] block/genhd: Notify udev about capacity change Date: Tue, 25 Feb 2020 20:01:25 +0000 Message-ID: <20200225200129.6687-2-sblbir@amazon.com> X-Mailer: git-send-email 2.16.6 In-Reply-To: <20200225200129.6687-1-sblbir@amazon.com> References: <20200225200129.6687-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 set_capacity_revalidate_and_notify(), which is a wrapper on top of set_capacity(). set_capacity_revalidate_and_notify() will only notify via udev if the current capacity or the target capacity is not zero and iff the capacity changes. Suggested-by: Christoph Hellwig Signed-off-by: Someswarudu Sangaraju Signed-off-by: Balbir Singh Reviewed-by: Bob Liu --- block/genhd.c | 24 ++++++++++++++++++++++++ include/linux/genhd.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/block/genhd.c b/block/genhd.c index ff6268970ddc..6a60131baffa 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -46,6 +46,30 @@ 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 set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size, + bool revalidate) +{ + sector_t capacity = get_capacity(disk); + + set_capacity(disk, size); + + if (revalidate) + revalidate_disk(disk); + + if (capacity != size && capacity != 0 && size != 0) { + char *envp[] = { "RESIZE=1", NULL }; + + kobject_uevent_env(&disk_to_dev(disk)->kobj, KOBJ_CHANGE, envp); + } +} + +EXPORT_SYMBOL_GPL(set_capacity_revalidate_and_notify); + + 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 6fbe58538ad6..f77f5095f20b 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -461,6 +461,8 @@ 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 set_capacity_revalidate_and_notify(struct gendisk *disk, + sector_t size, bool revalidate); extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask); /* drivers/char/random.c */ -- 2.16.6