Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5904859ybl; Sun, 22 Dec 2019 17:42:33 -0800 (PST) X-Google-Smtp-Source: APXvYqxs1AF/CySwKJjLbnxF+JPnJTNd8gr2HKV2lvbTYck9GeAvD4mqkDl4ZNOMMMvud1hiC4ob X-Received: by 2002:a9d:7c8a:: with SMTP id q10mr27967730otn.124.1577065353329; Sun, 22 Dec 2019 17:42:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577065353; cv=none; d=google.com; s=arc-20160816; b=OluJChuGBzMlL8DOUUf3AHDDAR8WEagcfdH8XHqO9kkmOkqBhucZYSxO7/j5LTV+Qw JQ/FFRqqBdNLIaURs58gLcj29diYOuiXmGuV3lMvWM2beyPVTDsUW+3CGIhBqyjAScxs no+RoNl/K7R7wiCgt92Rr3T8J1yaRw6B5Iiv4deVbuO0OYb3fqutZ8eA+QC1dE9KGnY0 BWnvK8sWEGRPvAFojqxiz8FRT172ws5tubVTR5fQiaLgFXXxqAuMtbIg4vcgwTmufxQ1 cjLeTEXWo+vzbDaGarLc98l7tNUKsrpANmtbV5F/jYrsu1eTHpwlBL0aegD+C6x9/4rH d6jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:ironport-sdr:dkim-signature; bh=wKr/9yXKpnMZ0LLL0aLH8/g6Iv24/1LIBi7EblWcw/k=; b=i5R2PbFAV2ed7598BqcmvBDiUGf5b07bZLNbrnICDK9q7hQZPs2qc2Mw0loERsHPvs rpgxCUqIQX4VrNm7dSktq2MzAH55kVsgOXk4SvP2a4yVASsHubvTfbJfPvrDrsq9cuwU PIzvrxUwTrhHbk/cj006HgYzkX/Pasy9ZzSoTwhVYsGR6QbK8+3P+1Oe7c15Jd1bBqeF 5yBK3vyYRz0imikG4C+32sCr3/WgdzD6NQW3EMe8BVe8RmNvhcrjKMZQRHUyqS64zvyV F9O+FRj47sMWxd/FBirVdVNbV85e6EvbcG9+kqm2wtVyW1SSwWkOLCCKJJt8VkmlMCX1 b6ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=TgNTEqb2; 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 w7si8266353oie.196.2019.12.22.17.42.21; Sun, 22 Dec 2019 17:42:33 -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=TgNTEqb2; 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 S1726877AbfLWBlc (ORCPT + 99 others); Sun, 22 Dec 2019 20:41:32 -0500 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:46524 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726604AbfLWBl3 (ORCPT ); Sun, 22 Dec 2019 20:41:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1577065289; x=1608601289; h=from:to:cc:subject:date:message-id:mime-version; bh=wKr/9yXKpnMZ0LLL0aLH8/g6Iv24/1LIBi7EblWcw/k=; b=TgNTEqb2bESEInE3pkAp3EeyhCRqb39amxgaQO/0Mf5H1s14JEgLul/e aF1V/m4GJKEtZl3bENrNSNPY6Bf6dt7XWblQLjqxNOUg8z2rNGtgzzqBB h9ndaeskTSEx3uuKbUpdthxnZh/4qLVE2cesJSxFhToS6IXrFv0LHZQg/ s=; IronPort-SDR: n71q9NroV3bOEIgKDK8Blv+rWlMYMqLTjJCg5LMBf37eccoympL9f8TkpiAQXjKZ4t9oAtsm7/ k5ehTZknrP8w== X-IronPort-AV: E=Sophos;i="5.69,345,1571702400"; d="scan'208";a="6656913" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1a-67b371d8.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 23 Dec 2019 01:41:18 +0000 Received: from EX13MTAUWC001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1a-67b371d8.us-east-1.amazon.com (Postfix) with ESMTPS id 74829A1DF2; Mon, 23 Dec 2019 01:41:15 +0000 (UTC) Received: from EX13D11UWC002.ant.amazon.com (10.43.162.174) by EX13MTAUWC001.ant.amazon.com (10.43.162.135) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 23 Dec 2019 01:41:14 +0000 Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX13D11UWC002.ant.amazon.com (10.43.162.174) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 23 Dec 2019 01:41:14 +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; Mon, 23 Dec 2019 01:41:13 +0000 From: Balbir Singh To: <=linux-block@vger.kernel.org>, , CC: , , , , , Balbir Singh Subject: [RFC PATCH 1/5] block/genhd: Notify udev about capacity change Date: Mon, 23 Dec 2019 01:40:52 +0000 Message-ID: <20191223014056.17318-1-sblbir@amazon.com> X-Mailer: git-send-email 2.16.5 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. Background: As a part of a patch to allow sending the RESIZE event on disk capacity change, Christoph (hch@lst.de) requested that the patch be made generic and the hacks for virtio block and xen block devices be removed and merged via a generic helper. Testing: 1. I did some basic testing with an NVME device, by resizing it in the backend and ensured that udevd received the event. Suggested-by: Christoph Hellwig Signed-off-by: Balbir Singh 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