From patchwork Tue Jun 6 07:39:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 690805 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8E70C7EE2F for ; Tue, 6 Jun 2023 07:41:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236607AbjFFHlU (ORCPT ); Tue, 6 Jun 2023 03:41:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235422AbjFFHlA (ORCPT ); Tue, 6 Jun 2023 03:41:00 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5123AE54; Tue, 6 Jun 2023 00:40:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=qVOrkQYaq+SX22HuuXUcSy5ptKgWrZvwoxfyWDjTNnY=; b=PZGsx1CCD2z+deKxuGotXw5aYf rNyskY7AyOr1FlBkPXZIURauJboA9G1KfRUFRMstjX9XjxTctwtM2HPKli0YcMDhkVBYqgxV4P8dN AfY/988vKFPSDvom3cXJqwcikLjCUkiilmz/+gwcOn5nDIgAUNuOSGNLDV06cMiI9281lfybVMezH xFbiwGKDc/OF7aQ5SMe05WRqmuQy8oe0ms+73QI+rBLYBanvKwVnRMXakGAfOy4EpWBIwGvtfPAwC uN05KHcS/jsxfUhY2GcVWHYTbY1PmJ7g3xAWrnDkJtbQzztiyMOsltH73yikkgoECU5vPMuDMx7WN wprYeXhA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q6RIh-000YuD-04; Tue, 06 Jun 2023 07:40:19 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Richard Weinberger , Josef Bacik , "Md. Haris Iqbal" , Jack Wang , Phillip Potter , Coly Li , Miquel Raynal , Vignesh Raghavendra , "Martin K. Petersen" , Chris Mason , David Sterba , Alexander Viro , Christian Brauner , "Rafael J. Wysocki" , Pavel Machek , dm-devel@redhat.com, linux-block@vger.kernel.org, linux-um@lists.infradead.org, linux-scsi@vger.kernel.org, linux-bcache@vger.kernel.org, linux-mtd@lists.infradead.org, linux-nvme@lists.infradead.org, linux-btrfs@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-nilfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH 08/31] block: share code between disk_check_media_change and disk_force_media_change Date: Tue, 6 Jun 2023 09:39:27 +0200 Message-Id: <20230606073950.225178-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230606073950.225178-1-hch@lst.de> References: <20230606073950.225178-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Factor the common logic between disk_check_media_change and disk_force_media_change into a helper. Signed-off-by: Christoph Hellwig --- block/disk-events.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/block/disk-events.c b/block/disk-events.c index 8b1b63225738f8..06f325662b3494 100644 --- a/block/disk-events.c +++ b/block/disk-events.c @@ -262,6 +262,18 @@ static unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask) return pending; } +static bool __disk_check_media_change(struct gendisk *disk, unsigned int events) +{ + if (!(events & DISK_EVENT_MEDIA_CHANGE)) + return false; + + if (__invalidate_device(disk->part0, true)) + pr_warn("VFS: busy inodes on changed media %s\n", + disk->disk_name); + set_bit(GD_NEED_PART_SCAN, &disk->state); + return true; +} + /** * disk_check_media_change - check if a removable media has been changed * @disk: gendisk to check @@ -274,18 +286,9 @@ static unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask) */ bool disk_check_media_change(struct gendisk *disk) { - unsigned int events; - - events = disk_clear_events(disk, DISK_EVENT_MEDIA_CHANGE | - DISK_EVENT_EJECT_REQUEST); - if (!(events & DISK_EVENT_MEDIA_CHANGE)) - return false; - - if (__invalidate_device(disk->part0, true)) - pr_warn("VFS: busy inodes on changed media %s\n", - disk->disk_name); - set_bit(GD_NEED_PART_SCAN, &disk->state); - return true; + return __disk_check_media_change(disk, + disk_clear_events(disk, DISK_EVENT_MEDIA_CHANGE | + DISK_EVENT_EJECT_REQUEST)); } EXPORT_SYMBOL(disk_check_media_change); @@ -303,15 +306,7 @@ EXPORT_SYMBOL(disk_check_media_change); bool disk_force_media_change(struct gendisk *disk, unsigned int events) { disk_event_uevent(disk, events); - - if (!(events & DISK_EVENT_MEDIA_CHANGE)) - return false; - - if (__invalidate_device(disk->part0, true)) - pr_warn("VFS: busy inodes on changed media %s\n", - disk->disk_name); - set_bit(GD_NEED_PART_SCAN, &disk->state); - return true; + return __disk_check_media_change(disk, events); } EXPORT_SYMBOL_GPL(disk_force_media_change);