From patchwork Mon Jul 31 19:13:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 128859 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2244377vqg; Mon, 31 Jul 2023 13:17:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlH44V3mlQPSlVaWglaKBd8rS81GwqldWgw22mtAhCWXhw6VJOTue64P91AB5WmFa6q8ba/V X-Received: by 2002:a05:6a20:3942:b0:13d:af0e:4edb with SMTP id r2-20020a056a20394200b0013daf0e4edbmr4633318pzg.62.1690834640448; Mon, 31 Jul 2023 13:17:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690834640; cv=none; d=google.com; s=arc-20160816; b=L/LupZY9FaRWe1wlgqyQTaYCGtWSQ1J30y1L2YAAPbD0Qur6K66pQaA9Mg0cUv3DK+ Cmyc0wCTuy9bfZr1Sv5e8YopXTfuRRcRfROaiuOrMRIbnUYo335J4AqnFWF6PC0L5KRV hVDCzCKGPC+JVxybVKwy/NqH4PTVdjKY7BLbLHWgnqKlivMw3pL+NrOPNG5N8gcHjMpg OAckOSXTqSmIZUL4naISwGpbcau+c3I4tAnLNoff1pjCHkfVtOhe5w7Jc6k8yTVlH9r1 FLNqcVtFG6yTg1upXxWl64srrvOwXzsb1U1+mpWcbxJeEyPD0IErWO8Aq0aCmIe2lbEv 5EXw== 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=kFGsI/e2yvLWxse1j39HJ6gb+i8cDJSBRhHonL9x+u0=; b=a9FClI/GUW960/djqHBVGrSeXZ/0Jx9Hs/0qxdFXoFxGslKyKj7Sa+SnU64tJmxMFT SC1Vqn+0kZ28JgbGMWUWpAVpJDuONVMOeU7SQDeDg047pJWl9C58isPqQMcEmxHDhjmM iOi7TPxkV9amS4guGIzLO57/trP8CZEcCYAyo1bcRUgFUCPcVP+K4x+QIS8ye47nCAku pWO16dcgwZyRodnBCOrI5CEioVK7Oy3A/a+bVcq6aIEnbHl7bvaHCkhpmo7VyYAYHEb6 2zNjUCFlMnV+nxqegqop2RKMeX9yJAdKLcAb2mV7PZ4n6l3EbCbmVusG8ywzI/unv1o5 Yclg== 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 c20-20020a056a00249400b0068703c4dd35si6740705pfv.1.2023.07.31.13.17.07; Mon, 31 Jul 2023 13:17:20 -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 S231310AbjGaTNb (ORCPT + 99 others); Mon, 31 Jul 2023 15:13:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229875AbjGaTN3 (ORCPT ); Mon, 31 Jul 2023 15:13:29 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80EE9184 for ; Mon, 31 Jul 2023 12:13:25 -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 1qQYKY-0001iC-0W; Mon, 31 Jul 2023 19:13:23 +0000 Date: Mon, 31 Jul 2023 20:13:11 +0100 From: Daniel Golle To: Richard Weinberger , Miquel Raynal , Vignesh Raghavendra , linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [PATCH 4/6] 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, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: 1772968624400476644 X-GMAIL-MSGID: 1772968624400476644 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, };