From patchwork Thu Jan 26 03:33:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 48489 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp77611wrn; Wed, 25 Jan 2023 19:44:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXsea8nlmed1cr3s677AVcO+Li/IVCeBfwz1U1ePzv+mBbXAbCGfKQy54R/g/cSWAGd332Ez X-Received: by 2002:a17:907:20f6:b0:84d:21b2:735a with SMTP id rh22-20020a17090720f600b0084d21b2735amr33828350ejb.54.1674704695106; Wed, 25 Jan 2023 19:44:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674704695; cv=none; d=google.com; s=arc-20160816; b=g3mBaQNT5k7Y8jofI8xLzGKZ3FIqYokqdZ6bkxvWVHaj8+H8GFmRtXqJFWVndu2bAF M7rSij6rvidV37AeTqUivt8jf5R5Q36nnP4XSBP+/VxLK2mrlj12si3S0NS1zVtY9JAA d1kpjfliAcBkGy7qbL0WxU6uhrl5uMuPWVOurwlOs4fj9RNUWoO36sRJGC/gLoKX86WK qNRRBvV84Yf1ONubMr2xJgj4Vu2XMbapzs+FOx+6A4joj0euyY8vg42PmEir0bQzPOmU QOvOk8h7cmFYe+Szvym929/C7d1M/dfPmZDGBjiNMD02Lv5KIdLBE+ftrn4C01EJxsPn v9dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=V4qU6xBczXYBxuAJBBtWt5596TfV6Bd4Dyk+YpmwRl4=; b=JKgaEmwHq7ACq7TpjdiYLluPkOcwdKH7cPNsY3Xs0UqjzPhQoCJs5DukkEGxDRXecL 2QBG3j/D6IXasBMnlELmlIhbwY42lg6LyUcEfzT87Nzaa30FwVzK6OIckbkBiJWz5xYB dAIx4O8aQSkgZFqujDKudW7+veKewZTCqLAjj00jgevVLChjj8t0BwgDZhOj6EKkGgGQ bKbc5why7SryOcbiPIIh4Dl/jaGUswpz+y3Or8YjQgWMnvC70WGetPoTTHtYA5fhPx4B JZf0KZD7TifR4sHLNW2Y+lYfFHmGbo0IN+5F28g6WtnOmM6RIG6LBe1DYLjE5+WbWDga zRPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@invisiblethingslab.com header.s=fm3 header.b=CuRQlVlI; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=G9bxwKaZ; 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 gj20-20020a170907741400b00876b91c8783si7662729ejc.7.2023.01.25.19.44.30; Wed, 25 Jan 2023 19:44:55 -0800 (PST) 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; dkim=pass header.i=@invisiblethingslab.com header.s=fm3 header.b=CuRQlVlI; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=G9bxwKaZ; 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 S236437AbjAZDeq (ORCPT + 99 others); Wed, 25 Jan 2023 22:34:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229846AbjAZDei (ORCPT ); Wed, 25 Jan 2023 22:34:38 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 726D256EFE; Wed, 25 Jan 2023 19:34:22 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id CBD635C0153; Wed, 25 Jan 2023 22:34:21 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Wed, 25 Jan 2023 22:34:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm3; t= 1674704061; x=1674790461; bh=V4qU6xBczXYBxuAJBBtWt5596TfV6Bd4Dyk +YpmwRl4=; b=CuRQlVlIShgx+Q3OebmHVhmoUi/3WbvG8C7kvnQPwXe1QU0tnFD XmXhEOq6gJBc6ipUhy7jKIip+gM3ffn5Znohlz62xTB8F1yHGTtB13fNiydmxq8e 2NjBisXqiKFl0vK9uPtshH9lj1xhj6MDUbOxxBL4KbfXVOMP7KwQ4DrSGSnoqz5v d6dv73iHBERop8YVJX5LqtEdHvUdr0xm4S09J7FjPLp5bR7H52os2QZqiFTm67i9 WSyDDhKmA7AG5cp7E0sqeAwVvYFz7eBL5YnZTmc2OuyQSug0g4Q6R7UsbbvzwEBp VBXdD9UALLDVFotjfYSfUvP34A7I/PNUiFw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1674704061; x=1674790461; bh=V4qU6xBczXYBx uAJBBtWt5596TfV6Bd4Dyk+YpmwRl4=; b=G9bxwKaZXTcN/J3Y2b7exagftg8il c5jEtm6ch7lOIR5yCje41RguRYT6IRbn7gpcD3VHhIl+gCjLBkRtp4h/UAu98A0e 7H98igegXsNN79gnXc7QzoSxLZLguaUyAYegjyRxUITnysoDIeVqdrWD/iyE9DUJ 01Hj38zqEP6unZz26qbaMVQ0cu7ymak7KVLI3QeEssr7vVUZp21eJAhutlVu6KV/ KL9QJ9/r/Mba6IKukxPiuLInp9TnFA58SK240NHNIxaXY2vb4wxe4pklBQI9NGVt 5avPzNEuaIKk0yRBDDkmAc1gSsTYrCTxsk0OSevDGJ1k8LPKZX83qcDtw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddvfedgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgvmhhi ucforghrihgvucfqsggvnhhouhhruceouggvmhhisehinhhvihhsihgslhgvthhhihhngh hslhgrsgdrtghomheqnecuggftrfgrthhtvghrnhepjeffjefggfeugeduvedvjeekgfeh gffhhfffjeetkeelueefffetfffhtdduheetnecuvehluhhsthgvrhfuihiivgepudenuc frrghrrghmpehmrghilhhfrhhomhepuggvmhhisehinhhvihhsihgslhgvthhhihhnghhs lhgrsgdrtghomh X-ME-Proxy: Feedback-ID: iac594737:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Jan 2023 22:34:21 -0500 (EST) From: Demi Marie Obenour To: Jens Axboe , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Juergen Gross Cc: Demi Marie Obenour , =?utf-8?q?Marek_Marczy?= =?utf-8?q?kowski-G=C3=B3recki?= , xen-devel@lists.xenproject.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 7/7] xen/blkback: Inform userspace that device has been opened Date: Wed, 25 Jan 2023 22:33:58 -0500 Message-Id: <20230126033358.1880-7-demi@invisiblethingslab.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230126033358.1880-1-demi@invisiblethingslab.com> References: <20230126033358.1880-1-demi@invisiblethingslab.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756055150414392846?= X-GMAIL-MSGID: =?utf-8?q?1756055150414392846?= This allows userspace to use block devices with delete-on-close behavior, which is necessary to ensure virtual devices (such as loop or device-mapper devices) are cleaned up automatically. Protocol details are included in comments. Signed-off-by: Demi Marie Obenour --- drivers/block/xen-blkback/xenbus.c | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 2c43bfc7ab5ba6954f11d4b949a5668660dbd290..ca8dae05985038da490c5ac93364509913f6b4c7 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -3,6 +3,19 @@ Copyright (C) 2005 Rusty Russell Copyright (C) 2005 XenSource Ltd +In addition to the XenStore nodes required by the Xen block device +specification, this implementation of blkback uses a new XenStore +node: "opened". blkback sets "opened" to "0" before the hotplug script +is called. Once the device node has been opened, blkback sets "opened" +to "1". + +"opened" is used exclusively by userspace. It serves two purposes: + +1. It tells userspace that diskseq@major:minor syntax for "physical-device" is + supported. +2. It tells userspace that it can wait for "opened" to be set to 1. Once + "opened" is 1, blkback has a reference to the device, so userspace doesn't + need to keep one. */ @@ -698,6 +711,14 @@ static int xen_blkbk_probe(struct xenbus_device *dev, if (err) pr_warn("%s write out 'max-ring-page-order' failed\n", __func__); + /* + * This informs userspace that the "opened" node will be set to "1" when + * the device has been opened successfully. + */ + err = xenbus_write(XBT_NIL, dev->nodename, "opened", "0"); + if (err) + goto fail; + err = xenbus_switch_state(dev, XenbusStateInitWait); if (err) goto fail; @@ -824,6 +845,19 @@ static void backend_changed(struct xenbus_watch *watch, goto fail; } + /* + * Tell userspace that the device has been opened and that blkback has a + * reference to it. Userspace can then close the device or mark it as + * delete-on-close, knowing that blkback will keep the device open as + * long as necessary. + */ + err = xenbus_write(XBT_NIL, dev->nodename, "opened", "1"); + if (err) { + xenbus_dev_fatal(dev, err, "%s: notifying userspace device has been opened", + dev->nodename); + goto free_vbd; + } + err = xenvbd_sysfs_addif(dev); if (err) { xenbus_dev_fatal(dev, err, "creating sysfs entries");