Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/1877713/?format=api
{ "id": 1877713, "url": "http://patchwork.ozlabs.org/api/patches/1877713/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linux-mtd/patch/2b34c485ac7ab0a3bd3b7314063263ff6c3b071e.1702952891.git.daniel@makrotopia.org/", "project": { "id": 3, "url": "http://patchwork.ozlabs.org/api/projects/3/?format=api", "name": "Linux MTD development", "link_name": "linux-mtd", "list_id": "linux-mtd.lists.infradead.org", "list_email": "linux-mtd@lists.infradead.org", "web_url": null, "scm_url": null, "webscm_url": null, "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<2b34c485ac7ab0a3bd3b7314063263ff6c3b071e.1702952891.git.daniel@makrotopia.org>", "list_archive_url": null, "date": "2023-12-19T02:33:24", "name": "[v7,5/7] mtd: ubi: introduce pre-removal notification for UBI volumes", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "168763382d7f3646ca61bcac790d4dbcd3579c66", "submitter": { "id": 64091, "url": "http://patchwork.ozlabs.org/api/people/64091/?format=api", "name": "Daniel Golle", "email": "daniel@makrotopia.org" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/linux-mtd/patch/2b34c485ac7ab0a3bd3b7314063263ff6c3b071e.1702952891.git.daniel@makrotopia.org/mbox/", "series": [ { "id": 387243, "url": "http://patchwork.ozlabs.org/api/series/387243/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linux-mtd/list/?series=387243", "date": "2023-12-19T02:32:00", "name": "mtd: ubi: allow UBI volumes to provide NVMEM", "version": 7, "mbox": "http://patchwork.ozlabs.org/series/387243/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/1877713/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/1877713/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "\n <linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=lists.infradead.org header.i=@lists.infradead.org\n header.a=rsa-sha256 header.s=bombadil.20210309 header.b=hAAFuMlH;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=none (no SPF record) smtp.mailfrom=lists.infradead.org\n (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org;\n envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n receiver=patchwork.ozlabs.org)" ], "Received": [ "from bombadil.infradead.org (bombadil.infradead.org\n [IPv6:2607:7c80:54:3::133])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4SvLPn1ccFz20H4\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 19 Dec 2023 13:34:53 +1100 (AEDT)", "from localhost ([::1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux))\n\tid 1rFPvb-00Cb8W-1m;\n\tTue, 19 Dec 2023 02:33:51 +0000", "from pidgin.makrotopia.org ([185.142.180.65])\n\tby bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux))\n\tid 1rFPvH-00Cb1z-2H\n\tfor linux-mtd@lists.infradead.org;\n\tTue, 19 Dec 2023 02:33:35 +0000", "from local\n\tby pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256)\n\t (Exim 4.96.2)\n\t(envelope-from <daniel@makrotopia.org>)\n\tid 1rFPvC-0008JR-1v;\n\tTue, 19 Dec 2023 02:33:27 +0000" ], "DKIM-Signature": "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20210309; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:\n\tMessage-ID:Subject:To:From:Date:Reply-To:Cc:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=AftuUqhLin+dbyyyBbqyeGW+V97QrpQdjrw1zb9dbF4=; b=hAAFuMlHduaWKL\n\t74BODUO1ymxQxKQ3u+2AFKx+XlFK2p77THgzpP9iNu+wn3dUypFN0ScskdA00DNYKhMTaR8tFU7T0\n\tvfyNJMI0NYU1n/RossUGlnKfKTwUcRpE0J9qHwzUz/7hngPpo72yIUtBQosLzY9ifaZIkl6qEnaxf\n\tdY4hLSnEyWQf+EbaLMVCA356WX0dWuM74NYyPlTvhfz4+FH1adLSKMoYGAIcOkpRp7dpn337xpF5v\n\tw4tmslOu2U0nf58u7jKVpYB+SYrCdVPcRtsMVpDQMHwLZQTqI4xROcryfBL0nqK+cXeXE42gRFqB7\n\titRR3eRu6jRXa2ZyNLzg==;", "Date": "Tue, 19 Dec 2023 02:33:24 +0000", "From": "Daniel Golle <daniel@makrotopia.org>", "To": "Miquel Raynal <miquel.raynal@bootlin.com>,\n\tRichard Weinberger <richard@nod.at>,\n\tVignesh Raghavendra <vigneshr@ti.com>,\n\tRob Herring <robh+dt@kernel.org>,\n\tKrzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,\n\tConor Dooley <conor+dt@kernel.org>,\n\tDaniel Golle <daniel@makrotopia.org>, linux-mtd@lists.infradead.org,\n\tdevicetree@vger.kernel.org, linux-kernel@vger.kernel.org", "Subject": "[PATCH v7 5/7] mtd: ubi: introduce pre-removal notification for UBI\n volumes", "Message-ID": "\n <2b34c485ac7ab0a3bd3b7314063263ff6c3b071e.1702952891.git.daniel@makrotopia.org>", "References": "<cover.1702952891.git.daniel@makrotopia.org>", "MIME-Version": "1.0", "Content-Disposition": "inline", "In-Reply-To": "<cover.1702952891.git.daniel@makrotopia.org>", "X-CRM114-Version": "20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ", "X-CRM114-CacheID": "sfid-20231218_183331_816079_950646C9 ", "X-CRM114-Status": "GOOD ( 21.37 )", "X-Spam-Score": "0.0 (/)", "X-Spam-Report": "Spam detection software,\n running on the system \"bombadil.infradead.org\",\n has NOT identified this incoming email as spam. The original\n message has been attached to this so you can view it or label\n similar future email. If you have any questions, see\n the administrator of that system for details.\n Content preview: Introduce a new notification type UBI_VOLUME_SHUTDOWN to\n inform\n users that a volume is just about to be removed. This is needed because\n users\n (such as the NVMEM subsystem) expect that at the time thei [...]\n Content analysis details: (0.0 points, 5.0 required)\n pts rule name description\n ---- ----------------------\n --------------------------------------------------\n -0.0 SPF_PASS SPF: sender matches SPF record\n 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record", "X-BeenThere": "linux-mtd@lists.infradead.org", "X-Mailman-Version": "2.1.34", "Precedence": "list", "List-Id": "Linux MTD discussion mailing list <linux-mtd.lists.infradead.org>", "List-Unsubscribe": "<http://lists.infradead.org/mailman/options/linux-mtd>,\n <mailto:linux-mtd-request@lists.infradead.org?subject=unsubscribe>", "List-Archive": "<http://lists.infradead.org/pipermail/linux-mtd/>", "List-Post": "<mailto:linux-mtd@lists.infradead.org>", "List-Help": "<mailto:linux-mtd-request@lists.infradead.org?subject=help>", "List-Subscribe": "<http://lists.infradead.org/mailman/listinfo/linux-mtd>,\n <mailto:linux-mtd-request@lists.infradead.org?subject=subscribe>", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Sender": "\"linux-mtd\" <linux-mtd-bounces@lists.infradead.org>", "Errors-To": "linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org" }, "content": "Introduce a new notification type UBI_VOLUME_SHUTDOWN to inform users\nthat a volume is just about to be removed.\nThis is needed because users (such as the NVMEM subsystem) expect that\nat the time their removal function is called, the parenting device is\nstill available (for removal of sysfs nodes, for example, in case of\nNVMEM which otherwise WARNs on volume removal).\n\nSigned-off-by: Daniel Golle <daniel@makrotopia.org>\n---\n drivers/mtd/ubi/build.c | 19 ++++++++++++++-----\n drivers/mtd/ubi/kapi.c | 2 +-\n drivers/mtd/ubi/ubi.h | 2 ++\n drivers/mtd/ubi/vmt.c | 17 +++++++++++++++--\n include/linux/mtd/ubi.h | 2 ++\n 5 files changed, 34 insertions(+), 8 deletions(-)", "diff": "diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c\nindex 8c3f763e4ddb8..a7e3a6246c0e9 100644\n--- a/drivers/mtd/ubi/build.c\n+++ b/drivers/mtd/ubi/build.c\n@@ -93,7 +93,7 @@ static struct ubi_device *ubi_devices[UBI_MAX_DEVICES];\n /* Serializes UBI devices creations and removals */\n DEFINE_MUTEX(ubi_devices_mutex);\n \n-/* Protects @ubi_devices and @ubi->ref_count */\n+/* Protects @ubi_devices, @ubi->ref_count and @ubi->is_dead */\n static DEFINE_SPINLOCK(ubi_devices_lock);\n \n /* \"Show\" method for files in '/<sysfs>/class/ubi/' */\n@@ -261,6 +261,9 @@ struct ubi_device *ubi_get_device(int ubi_num)\n \n \tspin_lock(&ubi_devices_lock);\n \tubi = ubi_devices[ubi_num];\n+\tif (ubi && ubi->is_dead)\n+\t\tubi = NULL;\n+\n \tif (ubi) {\n \t\tubi_assert(ubi->ref_count >= 0);\n \t\tubi->ref_count += 1;\n@@ -298,7 +301,7 @@ struct ubi_device *ubi_get_by_major(int major)\n \tspin_lock(&ubi_devices_lock);\n \tfor (i = 0; i < UBI_MAX_DEVICES; i++) {\n \t\tubi = ubi_devices[i];\n-\t\tif (ubi && MAJOR(ubi->cdev.dev) == major) {\n+\t\tif (ubi && !ubi->is_dead && MAJOR(ubi->cdev.dev) == major) {\n \t\t\tubi_assert(ubi->ref_count >= 0);\n \t\t\tubi->ref_count += 1;\n \t\t\tget_device(&ubi->dev);\n@@ -327,7 +330,7 @@ int ubi_major2num(int major)\n \tfor (i = 0; i < UBI_MAX_DEVICES; i++) {\n \t\tstruct ubi_device *ubi = ubi_devices[i];\n \n-\t\tif (ubi && MAJOR(ubi->cdev.dev) == major) {\n+\t\tif (ubi && !ubi->is_dead && MAJOR(ubi->cdev.dev) == major) {\n \t\t\tubi_num = ubi->ubi_num;\n \t\t\tbreak;\n \t\t}\n@@ -514,7 +517,7 @@ static void ubi_free_volumes_from(struct ubi_device *ubi, int from)\n \tint i;\n \n \tfor (i = from; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {\n-\t\tif (!ubi->volumes[i])\n+\t\tif (!ubi->volumes[i] || ubi->volumes[i]->is_dead)\n \t\t\tcontinue;\n \t\tubi_eba_replace_table(ubi->volumes[i], NULL);\n \t\tubi_fastmap_destroy_checkmap(ubi->volumes[i]);\n@@ -1099,7 +1102,6 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)\n \t\treturn -EINVAL;\n \n \tspin_lock(&ubi_devices_lock);\n-\tput_device(&ubi->dev);\n \tubi->ref_count -= 1;\n \tif (ubi->ref_count) {\n \t\tif (!anyway) {\n@@ -1110,6 +1112,13 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)\n \t\tubi_err(ubi, \"%s reference count %d, destroy anyway\",\n \t\t\tubi->ubi_name, ubi->ref_count);\n \t}\n+\tubi->is_dead = true;\n+\tspin_unlock(&ubi_devices_lock);\n+\n+\tubi_notify_all(ubi, UBI_VOLUME_SHUTDOWN, NULL);\n+\n+\tspin_lock(&ubi_devices_lock);\n+\tput_device(&ubi->dev);\n \tubi_devices[ubi_num] = NULL;\n \tspin_unlock(&ubi_devices_lock);\n \ndiff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c\nindex fbf3a7fe2af79..f1ea8677467fb 100644\n--- a/drivers/mtd/ubi/kapi.c\n+++ b/drivers/mtd/ubi/kapi.c\n@@ -152,7 +152,7 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode)\n \n \tspin_lock(&ubi->volumes_lock);\n \tvol = ubi->volumes[vol_id];\n-\tif (!vol)\n+\tif (!vol || vol->is_dead)\n \t\tgoto out_unlock;\n \n \terr = -EBUSY;\ndiff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h\nindex 17b463804c979..56a74a3e2d9ab 100644\n--- a/drivers/mtd/ubi/ubi.h\n+++ b/drivers/mtd/ubi/ubi.h\n@@ -348,6 +348,7 @@ struct ubi_volume {\n \tint writers;\n \tint exclusive;\n \tint metaonly;\n+\tbool is_dead;\n \n \tint reserved_pebs;\n \tint vol_type;\n@@ -568,6 +569,7 @@ struct ubi_device {\n \tspinlock_t volumes_lock;\n \tint ref_count;\n \tint image_seq;\n+\tbool is_dead;\n \n \tint rsvd_pebs;\n \tint avail_pebs;\ndiff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c\nindex 2c867d16f89f7..ee80c04d1d5d0 100644\n--- a/drivers/mtd/ubi/vmt.c\n+++ b/drivers/mtd/ubi/vmt.c\n@@ -59,7 +59,7 @@ static ssize_t vol_attribute_show(struct device *dev,\n \tstruct ubi_device *ubi = vol->ubi;\n \n \tspin_lock(&ubi->volumes_lock);\n-\tif (!ubi->volumes[vol->vol_id]) {\n+\tif (!ubi->volumes[vol->vol_id] || ubi->volumes[vol->vol_id]->is_dead) {\n \t\tspin_unlock(&ubi->volumes_lock);\n \t\treturn -ENODEV;\n \t}\n@@ -189,7 +189,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)\n \n \t/* Ensure that the name is unique */\n \tfor (i = 0; i < ubi->vtbl_slots; i++)\n-\t\tif (ubi->volumes[i] &&\n+\t\tif (ubi->volumes[i] && !ubi->volumes[i]->is_dead &&\n \t\t ubi->volumes[i]->name_len == req->name_len &&\n \t\t !strcmp(ubi->volumes[i]->name, req->name)) {\n \t\t\tubi_err(ubi, \"volume \\\"%s\\\" exists (ID %d)\",\n@@ -352,6 +352,19 @@ int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl)\n \t\terr = -EBUSY;\n \t\tgoto out_unlock;\n \t}\n+\n+\t/*\n+\t * Mark volume as dead at this point to prevent that anyone\n+\t * can take a reference to the volume from now on.\n+\t * This is necessary as we have to release the spinlock before\n+\t * calling ubi_volume_notify.\n+\t */\n+\tvol->is_dead = true;\n+\tspin_unlock(&ubi->volumes_lock);\n+\n+\tubi_volume_notify(ubi, vol, UBI_VOLUME_SHUTDOWN);\n+\n+\tspin_lock(&ubi->volumes_lock);\n \tubi->volumes[vol_id] = NULL;\n \tspin_unlock(&ubi->volumes_lock);\n \ndiff --git a/include/linux/mtd/ubi.h b/include/linux/mtd/ubi.h\nindex a529347fd75b2..562f92504f2b7 100644\n--- a/include/linux/mtd/ubi.h\n+++ b/include/linux/mtd/ubi.h\n@@ -192,6 +192,7 @@ struct ubi_device_info {\n *\t\t\tor a volume was removed)\n * @UBI_VOLUME_RESIZED: a volume has been re-sized\n * @UBI_VOLUME_RENAMED: a volume has been re-named\n+ * @UBI_VOLUME_SHUTDOWN: a volume is going to removed, shutdown users\n * @UBI_VOLUME_UPDATED: data has been written to a volume\n *\n * These constants define which type of event has happened when a volume\n@@ -202,6 +203,7 @@ enum {\n \tUBI_VOLUME_REMOVED,\n \tUBI_VOLUME_RESIZED,\n \tUBI_VOLUME_RENAMED,\n+\tUBI_VOLUME_SHUTDOWN,\n \tUBI_VOLUME_UPDATED,\n };\n \n", "prefixes": [ "v7", "5/7" ] }