From patchwork Fri Aug 11 01:38:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 134292 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp825629vqi; Thu, 10 Aug 2023 20:11:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLjlSczLrYex2vtZyNQ43x/vzz+XWpb3Z7VKGGOZ0619S79RYA47AobLtqzV14x/GMD0Mf X-Received: by 2002:a05:6a00:4690:b0:64d:42b9:6895 with SMTP id de16-20020a056a00469000b0064d42b96895mr4369386pfb.5.1691723515430; Thu, 10 Aug 2023 20:11:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691723515; cv=none; d=google.com; s=arc-20160816; b=Nbm06wm5xQ2+pORYa0oqjc0T4Mzhbi9cpGn+b1bF5jGXZz+1qzFyCWpf8OXz4L0C/v txDLqLKE4ogdoVyauywKlh7uZBxr3kKk8wfCW9V0BSbK3s1kLL7asILUmQZMeZ+l7LmS BFmvu1yrT641gOUta0GeKC63G9zeZb6gb5VzXscjqWonQPHVpZ48DZ1ZBDsu/iNd8Pu1 xS0ibAjjwFzDcppsnLjDDgyOh+ZT8y8j+XESsW53z/u4bOi/kRlXE8t5AalXdrbIpoDM 6vSnOoLIoswzcOz0odVQ+54iTOhO/oaEq73iBI3uXjL6+nGxUVIdn5vdjRN1ymEJWQwm YNYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date; bh=2ZMFvnqg2YpdkSzv6vBNptDi787ZNGsdqaeBN9c5mX8=; fh=fqW8oMY9ydixFpWZdFhmrmd4m3lvFBw58fIoJyq/l8o=; b=v5kZzNK0AuP1j0xkcNf9UXVjMFRuiU+kztDdB8/NghE4JdpOP63vj1vAALro3dBEc/ I7jImkaNjWzVj6ISmLNdNh9ZUI1/d+JypmgP/HBkPM5jiJeGWYljhn6X8KdqAjJhRbgQ svctMVCJ0mksNvIUc2zsgpAjuUNn0aLvIBPWbhiS9siPhdNOMdfKaH9irl1+5+fT5b6V uq1y6n8Z732zaO3+6cSnkgh5eK6KewYTQmF+s6fmB1AE68Dtf7pKbOzWrXDENSM+QsHD qZwDhwNiik60bNaXUkggfvMhVQmOvx5jSgxhqDy4KJtR/1CtDxMVDi9GBZH0jrh8/bFK q5MA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y7-20020a056a00180700b00682909b9671si2699714pfa.75.2023.08.10.20.11.41; Thu, 10 Aug 2023 20:11:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232879AbjHKBiW (ORCPT + 99 others); Thu, 10 Aug 2023 21:38:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231285AbjHKBiU (ORCPT ); Thu, 10 Aug 2023 21:38:20 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C6492123; Thu, 10 Aug 2023 18:38:20 -0700 (PDT) Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1qUH6S-00055e-0g; Fri, 11 Aug 2023 01:38:12 +0000 Date: Fri, 11 Aug 2023 02:38:05 +0100 From: Daniel Golle To: Randy Dunlap , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Daniel Golle , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 6/8] mtd: ubi: introduce pre-removal notification for UBI volumes Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773900677142329201 X-GMAIL-MSGID: 1773900677142329201 Introduce a new notification type UBI_VOLUME_SHUTDOWN to inform users that a volume is just about to be removed. This is needed because users (such as the NVMEM subsystem) expect that at the time their removal function is called, the parenting device is still available (for removal of sysfs nodes, for example, in case of NVMEM which otherwise WARNs on volume removal). Signed-off-by: Daniel Golle --- drivers/mtd/ubi/block.c | 26 ++++++++++++++++++++++++++ drivers/mtd/ubi/build.c | 7 ++++++- drivers/mtd/ubi/vmt.c | 5 +++++ include/linux/mtd/ubi.h | 2 ++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c index 99b5f502c9dbc..1d5148371991b 100644 --- a/drivers/mtd/ubi/block.c +++ b/drivers/mtd/ubi/block.c @@ -533,6 +533,29 @@ static int ubiblock_resize(struct ubi_volume_info *vi) return 0; } +static int ubiblock_shutdown(struct ubi_volume_info *vi) +{ + struct ubiblock *dev; + struct gendisk *disk; + int ret = 0; + + mutex_lock(&devices_mutex); + dev = find_dev_nolock(vi->ubi_num, vi->vol_id); + if (!dev) { + ret = -ENODEV; + goto out_unlock; + } + disk = dev->gd; + +out_unlock: + mutex_unlock(&devices_mutex); + + if (!ret) + blk_mark_disk_dead(disk); + + return ret; +}; + static bool match_volume_desc(struct ubi_volume_info *vi, const char *name, int ubi_num, int vol_id) { @@ -624,6 +647,9 @@ static int ubiblock_notify(struct notifier_block *nb, case UBI_VOLUME_REMOVED: ubiblock_remove(&nt->vi, true); break; + case UBI_VOLUME_SHUTDOWN: + ubiblock_shutdown(&nt->vi); + break; case UBI_VOLUME_RESIZED: ubiblock_resize(&nt->vi); break; diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index c153373c13dab..ccee4a28ffe97 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c @@ -1088,7 +1088,6 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway, bool have_lock) return -EINVAL; spin_lock(&ubi_devices_lock); - put_device(&ubi->dev); ubi->ref_count -= 1; if (ubi->ref_count) { if (!anyway) { @@ -1099,6 +1098,12 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway, bool have_lock) ubi_err(ubi, "%s reference count %d, destroy anyway", ubi->ubi_name, ubi->ref_count); } + spin_unlock(&ubi_devices_lock); + + ubi_notify_all(ubi, UBI_VOLUME_SHUTDOWN, NULL); + + spin_lock(&ubi_devices_lock); + put_device(&ubi->dev); ubi_devices[ubi_num] = NULL; spin_unlock(&ubi_devices_lock); diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c index 2c867d16f89f7..eed4b57c61bda 100644 --- a/drivers/mtd/ubi/vmt.c +++ b/drivers/mtd/ubi/vmt.c @@ -352,6 +352,11 @@ int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl) err = -EBUSY; goto out_unlock; } + spin_unlock(&ubi->volumes_lock); + + ubi_volume_notify(ubi, vol, UBI_VOLUME_SHUTDOWN); + + spin_lock(&ubi->volumes_lock); ubi->volumes[vol_id] = NULL; spin_unlock(&ubi->volumes_lock); diff --git a/include/linux/mtd/ubi.h b/include/linux/mtd/ubi.h index a529347fd75b2..562f92504f2b7 100644 --- a/include/linux/mtd/ubi.h +++ b/include/linux/mtd/ubi.h @@ -192,6 +192,7 @@ struct ubi_device_info { * or a volume was removed) * @UBI_VOLUME_RESIZED: a volume has been re-sized * @UBI_VOLUME_RENAMED: a volume has been re-named + * @UBI_VOLUME_SHUTDOWN: a volume is going to removed, shutdown users * @UBI_VOLUME_UPDATED: data has been written to a volume * * These constants define which type of event has happened when a volume @@ -202,6 +203,7 @@ enum { UBI_VOLUME_REMOVED, UBI_VOLUME_RESIZED, UBI_VOLUME_RENAMED, + UBI_VOLUME_SHUTDOWN, UBI_VOLUME_UPDATED, };