Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1324337ybh; Thu, 12 Mar 2020 22:31:08 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvcPnHcpwfdgqtKXEgb5JvZNT5tGu/ano1Bh8F8syIRcBmd9jVSSucIxhuNd9EtBJP+4wiZ X-Received: by 2002:aca:f1c6:: with SMTP id p189mr5730569oih.159.1584077468530; Thu, 12 Mar 2020 22:31:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584077468; cv=none; d=google.com; s=arc-20160816; b=x6Lkm4ZfPlyTikS731PC7zLJgNXXu/Fx8NBbwBUU4HSMr3zjwO5Kls7qNotjzOehBY PGL+eaqLxw5WLMdIZ6GAfS/0yaArHwD6Ndz/LwVp0LyhB9dJJ+a1REnLH13zxxrfCmnA 4UM7WFEcbxqYHra1ad6Egxd/JCRgBLnx9PVPHgWiM+xcqILgvopy2XgMyOFEwxQn1hp3 +OJQaVaziroL7zgAgcAg4ammDL2aSPkDjbbe60x5rZWXqpHJ2nhA8Sw2z1IO0rBqkKRr 5gq4LDlk9QrcJZjtxiHO+OlEVam6yZYyTyGl6uqf5286uhH1h1TI6hMyYbuS491pTqGR HLsQ== 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=VzahlS1xQL3cyYvmrGXLFGO7g8UlbYmJBGeuKNRDaw1hfZ/axgZXdW9A7zDbNiwhFy 4RyNo6l5RLoH7ncSGgHc9NXhn3sAODvUWVDbAATnCJvdM2gKJzTR/5eb99C67i1LBO+8 8N/uP2ij7DO11SDRInyxmFgo8QQgPl0XixyMQmA3LUG0DmRuVHig4+InFDB/19djIYas KbGNBTHaJ3nED9VV+tekmjWoiGV1gZ6WB0FaRYvFC5D91hrmI0X6DOR0/Ci5yySSbuFM pDcWsHqdQdaVTu8RIhjCunpmwlNqj6K+VxG531FXxgsiRU7oMTMwPvx1ntbmu9WJ1ygK KVPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=Co3158PT; 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 n1si4121899otf.102.2020.03.12.22.30.55; Thu, 12 Mar 2020 22:31:08 -0700 (PDT) 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=Co3158PT; 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 S1726393AbgCMFaY (ORCPT + 99 others); Fri, 13 Mar 2020 01:30:24 -0400 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:65343 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725535AbgCMFaX (ORCPT ); Fri, 13 Mar 2020 01:30:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1584077423; x=1615613423; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=88Zx2T7WCBJVENwjrv8btKUmZjU2WnlNsWj7L+qkaVc=; b=Co3158PT34Ol4s7cWJ5JA5Zp5T1Uw31COR1ePlC5Xik48a1jUcaDAxYV PHu13qu7Xy3jpMdcLwT+RrGjciY16+jxrbr/Kx62elEqT3dFiu7WKMxuA cA5UlLv8TyIYg7hL+A9yQH352JaxQWHSJqo+CIf2pSRt7LRkW9dwZ2zXB U=; IronPort-SDR: g32NOkjyZPrHE+l6ytQQqlK1Lm2zjoAu14ly/4ojSH4IYga6i3V+2BWs5y6AZoe7rXTxYAuHjX lzVS0Wubks4A== X-IronPort-AV: E=Sophos;i="5.70,547,1574121600"; d="scan'208";a="32358031" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1e-62350142.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 13 Mar 2020 05:30:21 +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-62350142.us-east-1.amazon.com (Postfix) with ESMTPS id 07FF8A28FA; Fri, 13 Mar 2020 05:30:18 +0000 (UTC) Received: from EX13D01UWA004.ant.amazon.com (10.43.160.99) by EX13MTAUWA001.ant.amazon.com (10.43.160.58) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 13 Mar 2020 05:30:18 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13d01UWA004.ant.amazon.com (10.43.160.99) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 13 Mar 2020 05:30:18 +0000 Received: from localhost (10.2.75.237) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 13 Mar 2020 05:30:18 +0000 From: Balbir Singh To: , , CC: , , , "Balbir Singh" , Someswarudu Sangaraju Subject: [PATCH v3 1/5] block/genhd: Notify udev about capacity change Date: Fri, 13 Mar 2020 05:30:05 +0000 Message-ID: <20200313053009.19866-2-sblbir@amazon.com> X-Mailer: git-send-email 2.16.6 In-Reply-To: <20200313053009.19866-1-sblbir@amazon.com> References: <20200313053009.19866-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