Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4572457rwb; Tue, 8 Aug 2023 10:18:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGPyiWhWqOVMgcWii0/7ssw4QkgbbNTxnpB1i/jheO1RIzg9ZlIcdx0yuuZ0Wiox6VnuwiD X-Received: by 2002:a54:4613:0:b0:3a7:56a5:4251 with SMTP id p19-20020a544613000000b003a756a54251mr330460oip.16.1691515096842; Tue, 08 Aug 2023 10:18:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691515096; cv=none; d=google.com; s=arc-20160816; b=au7NbD5evdnMvuY3adrbP5LYD2KJEI6PmaTYMb6BJju+6o+RYlBg2ypmBFEQ3HzS9x iB8N2Ks5lkmhcP2hFwZ3/dWW73EU6CbAx2vS+qW0rUnYLyZf8yCXS/NW8G5JFXP/3DFk rgAub5anVdFleiRxoIhzgBr6TUTKOay85dgTJu7iJC9DBeE4xmgSbX2ecBjt1b5pn+Az v3BGKiwc1sLEuONqXR7q4euCpAvZ5aP5poPK6NCw5/xxWKT5C+/q9UJLQsUHPQfuXULE tfBbyDBswvjZwcGPaQDts24v2MsKyVj4ckyAt5PUZBE4vOC405zLTXumXZQpQggcpsXC ZneQ== 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=c3OWsyH88r0fz4/zE/OpX/fQ8fF2NEJ7ZyZ2N8Jh+I/s8XqYKZsHI4qf10bMLu7vNL oxVxNxIm061FFX/PZdu/OdzyRC8U1p/SYqoXoHPb42ajBlNofbguLMeMjfcuwcHE/geZ XUx7UMVPLyP15wDiVkPsYHsxrwC3bCtNE4BbIASzJc3jixe20ppr41T09FS3y2CbTRHA D5eV8Pl/T2Q3GG++Xg2Yv9TPVFTgF+txtf7+Wsn0zbEDXp8ej5gybOocVqRyB/jZsEc2 OakjoCOanBTZy1813+vuLEs00AZgKz9gFAc9DnLyRgoFPH1sMDBS0OHlQj8NRuM8Yx3W lhVQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q8-20020a17090a2dc800b0024753ec4dccsi5752418pjm.124.2023.08.08.10.18.04; Tue, 08 Aug 2023 10:18:16 -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 S234166AbjHHROw (ORCPT + 99 others); Tue, 8 Aug 2023 13:14:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233689AbjHHROR (ORCPT ); Tue, 8 Aug 2023 13:14:17 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2FD31C134; Tue, 8 Aug 2023 09:05:55 -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 1qTPCq-0007b2-2I; Tue, 08 Aug 2023 16:05:12 +0000 Date: Tue, 8 Aug 2023 17:05:04 +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 v3 6/8] mtd: ubi: introduce pre-removal notification for UBI volumes Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 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, }; -- 2.41.0