From patchwork Wed Feb 14 16:42:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 201037 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1343832dyb; Wed, 14 Feb 2024 08:43:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXN/FRGomzE+Tz99Mqg45+Z4YBUk1MQzRrWROnbsHb0BizBAJMNOHmdh60jBOinnj1BjSU99qRwe1Bo37xhEKTGBBSMFA== X-Google-Smtp-Source: AGHT+IHRiYqCaKo1uy785TbvYH08v8WqNs1+fJiDVTDfKrOU8lwIMnG1LOJs2cAsGPqxylyqUXTd X-Received: by 2002:a17:906:f8ce:b0:a38:3f63:1ae4 with SMTP id lh14-20020a170906f8ce00b00a383f631ae4mr2146083ejb.27.1707929020940; Wed, 14 Feb 2024 08:43:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707929020; cv=pass; d=google.com; s=arc-20160816; b=PtdNagzHM50Dh/y3JLMPU8mABY9FxkgWDPSto2X53fFK4l4NAvPpmUJBHC0joU+mWh 0hDxzHHqX5rgv5iQ+nYzk8O/moGvVwGseBln92MxyV+pgLlyUF3Jq9y4Sm8+Fv1y2cuQ 8Jg56Ux9IGGYnNvexvgDsGBhrrm6Gv5ouI/FrsWn6tcJ2jJAG8nTiOoxZP+SY+4HmYfF Eb+D4xBAbc6rXArhLJtFVh8bnvobIbGBXl/munTqLRW73LDeGfhmheljWpJLV7Kx/N4q Yq+GJMBW9N7CU+0fMtS3+JAmGSI/6oOxIzefQ3aL7dp5odgxesrpT7h9rcniH2d1jn/X 82iQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:wdcironportexception:ironport-sdr:ironport-sdr :dkim-signature; bh=6pN2wwhnS0lyFNJg3lUbU9Ww2RiHO1BzyBPiKrWplh0=; fh=gLo29HoyXQt4uUOfzOUHNTs3B2WdVTVXKhbBKvE1sDw=; b=usM6A8UM51ud7N0RaQsRpu6BA5i2sh4cdAxeByHM2fiVFc0LEDVG2gknQz4xr15dgB 7vWNB7fG9lnLeZwzjovOCNrF1oNCA7u3sjMdIlWIXfnrE4mXHvdR9QLOnvvG6p4dgqjx BS3Chrb92o/ZLqXtb9yFeIC1s5VlakmwWTptX3tHg2xVlOaisq6tvAMKhJiKr9gGrrOC PSoENqhryMF7If1G3R6ePQujgoLhfXHdK0MtpJd6QunHHVlb8EtqmxAXYogdZ68RW1La 5v3x9+qDj5EPp4nv6OqoWL3lTnrv1LmFT/GGG3rBcIYtNrByBVwJmEULfQ2bg8YSwv+x reUg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wdc.com header.s=dkim.wdc.com header.b=gWyeO5M2; arc=pass (i=1 spf=pass spfdomain=wdc.com dkim=pass dkdomain=wdc.com dmarc=pass fromdomain=wdc.com); spf=pass (google.com: domain of linux-kernel+bounces-65572-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65572-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com X-Forwarded-Encrypted: i=2; AJvYcCWDX1ZF+pVUlndpkudY4TgZwf6MVJX2X2zWpsM9I1w9GpywQ7qB3Q8Y3a1j4Xj1Q1DZncA6kql9EJW0vVkWDuw6FYIxdw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c26-20020a170906695a00b00a3d303d987fsi1050157ejs.292.2024.02.14.08.43.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 08:43:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65572-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@wdc.com header.s=dkim.wdc.com header.b=gWyeO5M2; arc=pass (i=1 spf=pass spfdomain=wdc.com dkim=pass dkdomain=wdc.com dmarc=pass fromdomain=wdc.com); spf=pass (google.com: domain of linux-kernel+bounces-65572-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65572-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 61F371F221C9 for ; Wed, 14 Feb 2024 16:43:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 20860612E2; Wed, 14 Feb 2024 16:42:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="gWyeO5M2" Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 518AF60860; Wed, 14 Feb 2024 16:42:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928941; cv=none; b=SbQQ1KwLgD2QYohU8C6joPKRm+yfAxCHMK1jgdBFq9kxDEJL0NcyZYKRdp3h61ojWK6bavbT91uhp4YYKNR44Yw3Ny33NqNZffW4RBTCp2+KpfdKth/NAYwz4SXuEQyaVTOORL19t2a+JaUd/1RSeurOa5IvNpBQWiY+pYYASuU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928941; c=relaxed/simple; bh=1xeJ1LAvHPKE2uqjKayiHpy8JrwfEHaEiYJ0ln71pjA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZKfIl9GqHNKCJEWHe3wvtQsyVMmfMdK40jUL/cP/XDk9m2lG87FhlMoGosxIX7uEt6T3SKQ7pSjenZM6dT5PaD0hF94LzvCdbm/bKbfADuAFylPre/wgLn5IUnQ5jrOTI1q7fyjMBJnY+niuSCwNr176uO4PLjGmEZtNTc4/Z1c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=gWyeO5M2; arc=none smtp.client-ip=216.71.154.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1707928938; x=1739464938; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=1xeJ1LAvHPKE2uqjKayiHpy8JrwfEHaEiYJ0ln71pjA=; b=gWyeO5M2DW33/34phvrG7H17PTtXUMtYAvTUzhfHyxGicWhM2W9SE1fM U57l+Na17W6/vVcEGTl+WkGWG7XW9U2rNubCSpDhD3RpT6iWW7olbrZXF kMoWao3TzdSrlTnr/2YD2ir49FcGxCNiFGXaU1szEaNS3YFva7EZo4UeV ns3JlruveX9B+JK15hJ42M+kwEmNCZjhhYMxaoJE9KaT0tUw/rJsgAQV+ cd4ks9phyaOG6Tp4+DdX9VYELIEo/VBa4XR76METyZokfC55qS80FmqWR 9fjIbTyBx8zhMVYsc8s7MESJYSt3Jp3hvBq6/fJNbvKlplNDNu5/u5/VU A==; X-CSE-ConnectionGUID: BSdo3bonT1awm+9IyK8hhQ== X-CSE-MsgGUID: kessTWlvSrKc7mwPYVF/cA== X-IronPort-AV: E=Sophos;i="6.06,159,1705334400"; d="scan'208";a="9294734" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2024 00:42:17 +0800 IronPort-SDR: FBPImsUYqgy2slPze6245I3L7boT3T5vL9pTLSjYHJC/yqxdRAi6sbXdfa4F5lg1rUfRB8wicI FJ2KfAeXBD0Q== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2024 07:51:52 -0800 IronPort-SDR: Tq7El7VtOBEASrvLRsJaPhJ3TJtkXIAzXvaipqaQxReCEvamLj5riI1VV30aXXcK62y96V957B wdBi8O8E63XQ== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 14 Feb 2024 08:42:15 -0800 From: Johannes Thumshirn Date: Wed, 14 Feb 2024 08:42:12 -0800 Subject: [PATCH 1/5] btrfs: always open the device read-only in btrfs_scan_one_device Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240214-hch-device-open-v1-1-b153428b4f72@wdc.com> References: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> In-Reply-To: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> To: Chris Mason , Josef Bacik , David Sterba , Christoph Hellwig Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707928933; l=3992; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=I14e53DoeQrG1yDNK+J7DI2KG2AGVZJx0PKdwyMYBvM=; b=Hc3gvACCQXK46UZERZp3NW3WwFKPPZM0OXn0ZdSDS1ytfZw068ymxH7eAvEAqSp7XR+nuiaIQ CNt/P+GtokWDaknu/D346I71mNYhm/cHImof6ZfmrmOCmx4eOK0LzMl X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790893380640973969 X-GMAIL-MSGID: 1790893380640973969 From: Christoph Hellwig btrfs_scan_one_device opens the block device only to read the super block. Instead of passing a blk_mode_t argument to sometimes open it for writing, just hard code BLK_OPEN_READ as it will never write to the device or hand the block_device out to someone else. Signed-off-by: Christoph Hellwig Signed-off-by: Johannes Thumshirn --- fs/btrfs/super.c | 9 ++++----- fs/btrfs/volumes.c | 4 ++-- fs/btrfs/volumes.h | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 40ae264fd3ed..b6cadf4f21b8 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -299,10 +299,9 @@ static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *param) break; case Opt_device: { struct btrfs_device *device; - blk_mode_t mode = btrfs_open_mode(fc); mutex_lock(&uuid_mutex); - device = btrfs_scan_one_device(param->string, mode, false); + device = btrfs_scan_one_device(param->string, false); mutex_unlock(&uuid_mutex); if (IS_ERR(device)) return PTR_ERR(device); @@ -1808,7 +1807,7 @@ static int btrfs_get_tree_super(struct fs_context *fc) * With 'true' passed to btrfs_scan_one_device() (mount time) we expect * either a valid device or an error. */ - device = btrfs_scan_one_device(fc->source, mode, true); + device = btrfs_scan_one_device(fc->source, true); ASSERT(device != NULL); if (IS_ERR(device)) { mutex_unlock(&uuid_mutex); @@ -2210,7 +2209,7 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, * Scanning outside of mount can return NULL which would turn * into 0 error code. */ - device = btrfs_scan_one_device(vol->name, BLK_OPEN_READ, false); + device = btrfs_scan_one_device(vol->name, false); ret = PTR_ERR_OR_ZERO(device); mutex_unlock(&uuid_mutex); break; @@ -2228,7 +2227,7 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, * Scanning outside of mount can return NULL which would turn * into 0 error code. */ - device = btrfs_scan_one_device(vol->name, BLK_OPEN_READ, false); + device = btrfs_scan_one_device(vol->name, false); if (IS_ERR_OR_NULL(device)) { mutex_unlock(&uuid_mutex); ret = PTR_ERR(device); diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 4ad9eca9b46c..44caf1a48d33 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1308,7 +1308,7 @@ int btrfs_forget_devices(dev_t devt) * the device or return an error. Multi-device and seeding devices are registered * in both cases. */ -struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags, +struct btrfs_device *btrfs_scan_one_device(const char *path, bool mount_arg_dev) { struct btrfs_super_block *disk_super; @@ -1337,7 +1337,7 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags, * values temporarily, as the device paths of the fsid are the only * required information for assembling the volume. */ - bdev_handle = bdev_open_by_path(path, flags, NULL, NULL); + bdev_handle = bdev_open_by_path(path, BLK_OPEN_READ, NULL, NULL); if (IS_ERR(bdev_handle)) return ERR_CAST(bdev_handle); diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 21d4de0e3f1f..97c7284e7565 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -655,7 +655,7 @@ struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans, void btrfs_mapping_tree_free(struct btrfs_fs_info *fs_info); int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, blk_mode_t flags, void *holder); -struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags, +struct btrfs_device *btrfs_scan_one_device(const char *path, bool mount_arg_dev); int btrfs_forget_devices(dev_t devt); void btrfs_close_devices(struct btrfs_fs_devices *fs_devices); From patchwork Wed Feb 14 16:42:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 201054 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1369423dyb; Wed, 14 Feb 2024 09:19:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVlq3lVXpR9jp8sECfy0MEUn8H7dPFXAy/e2hwnLrqmx0HiwYoYcJx7Bhj1RxtamJY7BO+52Fj3ktJTtLmoDrGQKmJMpg== X-Google-Smtp-Source: AGHT+IEf5sJaDReNg0aPWqz9+sAkWXx4KUmELztgrjUIRTX81girTO9YtWRgzOepn2AiZ+imWTE5 X-Received: by 2002:a17:90b:605:b0:296:2057:28c with SMTP id gb5-20020a17090b060500b002962057028cmr3193834pjb.31.1707931158100; Wed, 14 Feb 2024 09:19:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707931158; cv=pass; d=google.com; s=arc-20160816; b=kcFI2LOIO4yAd6wAtR2300/C6FcSf52wqVMxseJb/4crDaZ+kgR0eSZOfdIpcz2+Aw g4K0ZO+DK5pQ03JMosAd5WljBNnltZnCUGoZQO8qi94vY4Yd+GTk6H9uprj1nlvxF2ob DqHYhg4UHSkN+ofdCYLD+wzI1D0sin5Ci97TyoJ6ErKwrV1XeKQ/NaZK3IlMzD1xGrdI EQtuJy1uE86E32YoLQw6mLlvLzJbzdaCfBZIJfRCbfhqOAli0ZsF9+GDJqimjgi1fHcI KHVxvhHuwNNLVHNiQ9vzh+n94NnWP2BrK7MBzypkMnux0TkuTJv2H9aiC5klzqrmBsKm sf3Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:wdcironportexception:ironport-sdr:ironport-sdr :dkim-signature; bh=uXulHQbHEfzImih0+yihxhETShQVQXNXxwxwG8SNW2w=; fh=EsLzSgqsCTwgvCFM/0Eluun6bZHdea5maicLqtBuBSE=; b=mA/xmwhNbUikjnvC7k0DJB4prvuTq+LS1nZYLS5035cVc5bYADKnShq/fZUfaq3Krv zXFHbW/uGYrA1TNfuKVzAJdiBBiMVMWyEZWCU56feGfJ4IDRqviHLjgUh0mm9sRN0Ubu VIFPmV1yCGmt21TvO5OqQVt8XX8JzTR//jJvsNrxHxr7V7icp33nsDYF5yWz3th2VN04 PFo5vXWqX5SLN83v5e19q5DjT/ozWqX+VWq/MlqL0an+fEPg3SsS3DdehiRW9yLq+6sm x0Y8CYIkmffEoMfQQBId6Dgctg66Mb1GI4E+IHd2GPijHc5BDu4/v9HkQSHafNsUSxJj QGQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wdc.com header.s=dkim.wdc.com header.b="OTXlyxz/"; arc=pass (i=1 spf=pass spfdomain=wdc.com dkim=pass dkdomain=wdc.com dmarc=pass fromdomain=wdc.com); spf=pass (google.com: domain of linux-kernel+bounces-65573-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65573-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id p11-20020a17090a2d8b00b00297302cb8f9si1453808pjd.91.2024.02.14.09.19.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:19:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65573-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@wdc.com header.s=dkim.wdc.com header.b="OTXlyxz/"; arc=pass (i=1 spf=pass spfdomain=wdc.com dkim=pass dkdomain=wdc.com dmarc=pass fromdomain=wdc.com); spf=pass (google.com: domain of linux-kernel+bounces-65573-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65573-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 494CAB300ED for ; Wed, 14 Feb 2024 16:43:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 57398612FE; Wed, 14 Feb 2024 16:42:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="OTXlyxz/" Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BB426088E; Wed, 14 Feb 2024 16:42:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928941; cv=none; b=B/cLux9nKy6JndNdhRlrB3SRb4CeO2l5+3OswYN2oASX1Kaw3buPOSx4wRjrH/RPoy1qjWXO+PqzlhkHpeSaP21VMK2ApxJQXbl38sDuaG3ITsdFIs3LISHAcs/1+izDya/wiOA1H3gBl8BuBINxA5Rqw3EAwme887U/6kzRpR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928941; c=relaxed/simple; bh=SA54NmB9VaxafMJvx4jeBf6OXC9qGXNN/wzW6KwJc0I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mNXoH6iR5Uvr0urGtsryURAl0EK0ac22a/2RjHL5sELZwlzWdmIpuWRRWXNYXCFNWfEZ8g0uSxBlVHgQAUeL8vWS7rxStwqxPDhZeYyFj6H8rhNpDSDWohUMXVAP9l09D0bO6/Gpy6eY3XmKVQli5aSj2kwLJ6xrwxMYUU0+dW4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=OTXlyxz/; arc=none smtp.client-ip=216.71.154.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1707928939; x=1739464939; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=SA54NmB9VaxafMJvx4jeBf6OXC9qGXNN/wzW6KwJc0I=; b=OTXlyxz/jrALoPlvgPJzl2l3j6Ad2++yq69zKJX2aTzWfccC7e3VhP3w xzDD4VsDppbE2IU9VFQirwqm92ebYBdMDO2DTf4cO7IYxPxWOmf/cQ2Hu dHEAZTJVfo9vQA1GfuCmK2lx/4zemARnrb2O+k5XJufUYW4uFpMgYLfZa ytaRQs80t8cEbvpBjeQph44kkPQh2n9cwAT6RXkGbJc7Ip/utogFzpXYH EFIVEVmu1dZLBBfOCtCfTR6qmzM9pAeSpULfyp9kJokGsLCroC7VMI3yd LTlAZXMhxABCVeXsQyw2VvS04HZd7ONCAYXEMXnf4ImLep3kya/YrN/BP w==; X-CSE-ConnectionGUID: 7QyyfYlsS8mTXGUHHx2Y4w== X-CSE-MsgGUID: m0Inx8HrSS6WwaLWObvFWg== X-IronPort-AV: E=Sophos;i="6.06,159,1705334400"; d="scan'208";a="9294737" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2024 00:42:18 +0800 IronPort-SDR: SSrVPLBH4vuMc4cfZHfQ/b+pDujGtMWHIns6NHaF9lyahd7FbJ8+K0Ph82pk76CGBQ3dPPJcyE LD/icZemTUzQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2024 07:51:54 -0800 IronPort-SDR: 8lGAdnDhx9j3WWMhmeE/nADvuABDMthU2whT2b4eR+cuepsze0JD82+A9/n3GNyZi4iPcg+MnS eZJ0R8+KqUwA== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 14 Feb 2024 08:42:16 -0800 From: Johannes Thumshirn Date: Wed, 14 Feb 2024 08:42:13 -0800 Subject: [PATCH 2/5] btrfs: call btrfs_close_devices from ->kill_sb Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240214-hch-device-open-v1-2-b153428b4f72@wdc.com> References: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> In-Reply-To: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> To: Chris Mason , Josef Bacik , David Sterba , Christoph Hellwig Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707928933; l=3686; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=RnNhAJkrtFJkaTBsB+8lN1Jcoq+lAOAadAngBZomtdQ=; b=fdg6RARFVrH5MCrjpINABNkYuCuzvEPtTY7ekxao+ARnqHZcN8sMsTmI86xex910XbA9fCcTd wrZYN8wJ1xrAZ+y0BCAWlDIvZLKuRm+kYV5Qmk6G3YUPq7BAjec6DTh X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790895622271584560 X-GMAIL-MSGID: 1790895622271584560 From: Christoph Hellwig blkdev_put must not be called under sb->s_umount to avoid a lock order reversal with disk->open_mutex once call backs from block devices to the file system using the holder ops are supported. Move the call to btrfs_close_devices into btrfs_free_fs_info so that it is closed from ->kill_sb (which is also called from the mount failure handling path unlike ->put_super) as well as when an fs_info is freed because an existing superblock already exists. Signed-off-by: Christoph Hellwig Signed-off-by: Johannes Thumshirn --- fs/btrfs/disk-io.c | 4 ++-- fs/btrfs/super.c | 27 ++++++++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 8ab185182c30..4aa67e2a48f6 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1266,6 +1266,8 @@ static void free_global_roots(struct btrfs_fs_info *fs_info) void btrfs_free_fs_info(struct btrfs_fs_info *fs_info) { + if (fs_info->fs_devices) + btrfs_close_devices(fs_info->fs_devices); percpu_counter_destroy(&fs_info->dirty_metadata_bytes); percpu_counter_destroy(&fs_info->delalloc_bytes); percpu_counter_destroy(&fs_info->ordered_bytes); @@ -3609,7 +3611,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device iput(fs_info->btree_inode); fail: - btrfs_close_devices(fs_info->fs_devices); ASSERT(ret < 0); return ret; } @@ -4389,7 +4390,6 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info) iput(fs_info->btree_inode); btrfs_mapping_tree_free(fs_info); - btrfs_close_devices(fs_info->fs_devices); } void btrfs_mark_buffer_dirty(struct btrfs_trans_handle *trans, diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index b6cadf4f21b8..51b8fd272b15 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1822,10 +1822,8 @@ static int btrfs_get_tree_super(struct fs_context *fc) if (ret) return ret; - if (!(fc->sb_flags & SB_RDONLY) && fs_devices->rw_devices == 0) { - ret = -EACCES; - goto error; - } + if (!(fc->sb_flags & SB_RDONLY) && fs_devices->rw_devices == 0) + return -EACCES; bdev = fs_devices->latest_dev->bdev; @@ -1839,15 +1837,12 @@ static int btrfs_get_tree_super(struct fs_context *fc) * otherwise it's tied to the lifetime of the super_block. */ sb = sget_fc(fc, btrfs_fc_test_super, set_anon_super_fc); - if (IS_ERR(sb)) { - ret = PTR_ERR(sb); - goto error; - } + if (IS_ERR(sb)) + return PTR_ERR(sb); set_device_specific_options(fs_info); if (sb->s_root) { - btrfs_close_devices(fs_devices); if ((fc->sb_flags ^ sb->s_flags) & SB_RDONLY) ret = -EBUSY; } else { @@ -1866,10 +1861,6 @@ static int btrfs_get_tree_super(struct fs_context *fc) fc->root = dget(sb->s_root); return 0; - -error: - btrfs_close_devices(fs_devices); - return ret; } /* @@ -1962,10 +1953,20 @@ static int btrfs_get_tree_super(struct fs_context *fc) */ static struct vfsmount *btrfs_reconfigure_for_mount(struct fs_context *fc) { + struct btrfs_fs_info *fs_info = fc->s_fs_info; struct vfsmount *mnt; int ret; const bool ro2rw = !(fc->sb_flags & SB_RDONLY); + /* + * We got a reference to our fs_devices, so we need to close it here to + * make sure we don't leak our reference on the fs_devices. + */ + if (fs_info->fs_devices) { + btrfs_close_devices(fs_info->fs_devices); + fs_info->fs_devices = NULL; + } + /* * We got an EBUSY because our SB_RDONLY flag didn't match the existing * super block, so invert our setting here and retry the mount so we From patchwork Wed Feb 14 16:42:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 201039 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1344821dyb; Wed, 14 Feb 2024 08:45:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV//CRBv2iZ/QBz7vKxj3JAmacqbp6Yii726Vm8rUaLrX/KK6I+gd0ExcUEqGH6l6Mna1uTmJ93hJJ3I83KXDpPIcxKfQ== X-Google-Smtp-Source: AGHT+IEAz3jG4FzzRvoZ9MNB8c3v3ezrnqMyD4OiGNNtbhkqRBWUTg8FNtTMIQYb9LQQqcZzwaPn X-Received: by 2002:a05:6a00:80ce:b0:6de:3b41:2845 with SMTP id ei14-20020a056a0080ce00b006de3b412845mr2450936pfb.32.1707929123747; Wed, 14 Feb 2024 08:45:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707929123; cv=pass; d=google.com; s=arc-20160816; b=q1PmJ1tsntwPoot0qY1ivDKMBQgXUWnF9sV2LxjDWC41fM+MsNiJ1929dtLYgI6ehg J3r0USOA2D4i+0EUKWGpvnwvykdwoFAz8qmzSIWXvhJ8XsM7GLGk38LtwKMkGXvIbO+5 Adx92VpdN9CGhaNixP+aVAp2OoMyPVS4x2xZFOJov/vDRt+5hpAAg133glciqDnPINnm 3cWH/TZRHZK88VOGns9BGTpoMQN6vPiXtwMnlqa+DbdOlfu+q08+0PPHodhx1nVlSbRU L0LlgRS2pxoY59FKlwhHgZhfojXupYX5n5i4ylGdpS/avQeSgDuC8p8SvbXr0zP4bCCt SQyA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:wdcironportexception:ironport-sdr:ironport-sdr :dkim-signature; bh=AdC18LWwFT7acVzRoUKokdMSvPkbPOEinmhfa+pBzK8=; fh=Krx0dZ28SZ02oTojGzZeYEaZQaBCg3l0dCLawTBUG9E=; b=dQdlEbYQ2X9LB9zyaVe0fulIA0NHoL0B0i1EjG36l3nAVxnF/6XgemHmxZIKMELJt7 b36a6Avio24wXgRN9DmreoJqlUhJinh9Ko9VTXu/fhOVO1pJEa/3wKBimI1YAEFg34h1 ka15aJD1mkpJBE1xxI5T+m2NXTZkYlktlN/vPGSUerEVEg1v7WWWM0vXZ0fah9zvc/jk MVHMpDTXRvkcSTNAviivIIUuqZJ7iA139VnHigeqjARH18P9pIMeUHX312tcz2jygY7c 9Nri7s8pKQMXLAoDTSGi23uYmS4zbJTn2RZLs9Bs3fTdl9b6L8p7pyYENLfmtH43PGOa gF6g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wdc.com header.s=dkim.wdc.com header.b=e8giFPlK; arc=pass (i=1 spf=pass spfdomain=wdc.com dkim=pass dkdomain=wdc.com dmarc=pass fromdomain=wdc.com); spf=pass (google.com: domain of linux-kernel+bounces-65574-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65574-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com X-Forwarded-Encrypted: i=2; AJvYcCVYavjAivtVbYoAAk1etJ1gPv2fewTxzl1fa0Ksb8JQbZZmGe4M5heOQCi5jyRY4UsdAHO+em2u2Og7PRTQFRcRIBF2lA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id r65-20020a632b44000000b005dc48449b0bsi4050787pgr.690.2024.02.14.08.45.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 08:45:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65574-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@wdc.com header.s=dkim.wdc.com header.b=e8giFPlK; arc=pass (i=1 spf=pass spfdomain=wdc.com dkim=pass dkdomain=wdc.com dmarc=pass fromdomain=wdc.com); spf=pass (google.com: domain of linux-kernel+bounces-65574-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65574-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B632928226C for ; Wed, 14 Feb 2024 16:43:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C5C6962170; Wed, 14 Feb 2024 16:42:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="e8giFPlK" Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B1BF60DC4; Wed, 14 Feb 2024 16:42:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928943; cv=none; b=J7rETqQN4RVmIdQn6JYycW/CisxrQTu7upZsgSIRUu8MPXakz1Ww4U6W498kUPFvy1TWWdjEKOCAN17MPXwuWv19nviHHTBStFNwWVTxDwXN6Xky1KoVG8Xg5LpO6j7VsjVrS8TVjZPOfbF+ry1kwpwPgta9bVyfspzDHrc04eQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928943; c=relaxed/simple; bh=x+9XsgsJofMkp/phXpfhTtoOFnnITRJ8Y+D2z+U3vrI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ha9GObcN3dZkAMqmhqKUUz366vrGoxBM40aoY9FrwK4DWySzSf5fYcAET+tUnteqwPY8lYwpwbHMtU2PinDWEMXAIOTYAs8Iz6ZcVWDuLcJiRXUoptMWCctyzw9BlR7UXpP0cbkL1ngL8ne5+ajQ2dGHpiIfpKR9he9iK6A9H5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=e8giFPlK; arc=none smtp.client-ip=216.71.154.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1707928941; x=1739464941; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=x+9XsgsJofMkp/phXpfhTtoOFnnITRJ8Y+D2z+U3vrI=; b=e8giFPlKAyYFeuj9BXHpasdhA6aTK9PVDhueudCFBc9C8pyykB5ejcwa LL5JpzG3ouBhFdlunhQcMR0OrRdIt7Tzn9sgRSX3J55nT0h9Hj0/5SKqa JMdkKTewDVCTIL/hdb1LXTgG+EG5tj3TGlz9KkMe38I9LPvxO/HX5BGAS ElUrSaVxsJx8iF0BCjzt4TePyFoR1WNZT+/CSs5zsifdtqTWGZrgmxqdD HGLp+9u10xU6fsWrVrsd5a3kc6glvgymtViv2LNcY30OBUGy0lbp9MQaU AEkSRChUeLY+XKmM3MZBgaB/T+1VKIQ0w+XcCJfo0v9w35R7DNDRUO7Iy A==; X-CSE-ConnectionGUID: 6xxSmU/ORtSOGRLm4HW5nw== X-CSE-MsgGUID: w0+miKYWQCuvoZ7o/OvvBg== X-IronPort-AV: E=Sophos;i="6.06,159,1705334400"; d="scan'208";a="9294741" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2024 00:42:20 +0800 IronPort-SDR: 8TCrt7yX0Q48V8HjcqzQEwKMlalzZRSlOa3kRgFQBfGmlg1Im2R1bmF7wNuHCcXlRGPOCP61+a RdtngOX2GeBQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2024 07:51:55 -0800 IronPort-SDR: iuSycV2C7J0cH1F3CsA6m8xOWSjY3EWg//M6hxtOqxSaWP2SjXECa+d46LefzsFRyg0ezdBZCN BD6Qy+KqWBqg== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 14 Feb 2024 08:42:18 -0800 From: Johannes Thumshirn Date: Wed, 14 Feb 2024 08:42:14 -0800 Subject: [PATCH 3/5] btrfs: split btrfs_fs_devices.opened Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240214-hch-device-open-v1-3-b153428b4f72@wdc.com> References: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> In-Reply-To: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> To: Chris Mason , Josef Bacik , David Sterba , Christoph Hellwig Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707928933; l=7104; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=7OH2aIo02sm6W0LG0E/ZUUuGzuFnEGpt1qc6hy3w+JE=; b=FkYNdzB4EGUPbJR4wd55k6sFzciP0YyBfUAzNUq1ey9V5wEM/iIDoRfoMUh/Vw8IxzfKp+2VQ t40Z+ink6bQCOPfiFPCC+9oIcuwtwtNXlxrWawYpnyLqFQKjxkLU/EV X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790893488426903513 X-GMAIL-MSGID: 1790893488426903513 From: Christoph Hellwig The btrfs_fs_devices.opened member mixes an in use counter for the fs_devices structure that prevents it from being garbage collected with a flag if the underlying devices were actually opened. This not only makes the code hard to follow, but also prevents btrfs from switching to opening the block device only after super block creation. Split it into an in_use counter and an is_open boolean flag instead. Signed-off-by: Christoph Hellwig Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 51 +++++++++++++++++++++++++++++---------------------- fs/btrfs/volumes.h | 6 ++++-- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 44caf1a48d33..f27af155abf0 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -412,7 +412,8 @@ static void free_fs_devices(struct btrfs_fs_devices *fs_devices) { struct btrfs_device *device; - WARN_ON(fs_devices->opened); + WARN_ON_ONCE(fs_devices->in_use); + WARN_ON_ONCE(fs_devices->is_open); while (!list_empty(&fs_devices->devices)) { device = list_entry(fs_devices->devices.next, struct btrfs_device, dev_list); @@ -535,7 +536,7 @@ static int btrfs_free_stale_devices(dev_t devt, struct btrfs_device *skip_device continue; if (devt && devt != device->devt) continue; - if (fs_devices->opened) { + if (fs_devices->in_use) { if (devt) ret = -EBUSY; break; @@ -607,7 +608,7 @@ static struct btrfs_fs_devices *find_fsid_by_device( if (found_by_devt) { /* Existing device. */ if (fsid_fs_devices == NULL) { - if (devt_fs_devices->opened == 0) { + if (devt_fs_devices->in_use == 0) { /* Stale device. */ return NULL; } else { @@ -795,7 +796,7 @@ static noinline struct btrfs_device *device_list_add(const char *path, if (!device) { unsigned int nofs_flag; - if (fs_devices->opened) { + if (fs_devices->in_use) { btrfs_err(NULL, "device %s belongs to fsid %pU, and the fs is already mounted, scanned by %s (%d)", path, fs_devices->fsid, current->comm, @@ -860,7 +861,7 @@ static noinline struct btrfs_device *device_list_add(const char *path, * tracking a problem where systems fail mount by subvolume id * when we reject replacement on a mounted FS. */ - if (!fs_devices->opened && found_transid < device->generation) { + if (!fs_devices->in_use && found_transid < device->generation) { /* * That is if the FS is _not_ mounted and if you * are here, that means there is more than one @@ -921,7 +922,7 @@ static noinline struct btrfs_device *device_list_add(const char *path, * it back. We need it to pick the disk with largest generation * (as above). */ - if (!fs_devices->opened) { + if (!fs_devices->in_use) { device->generation = found_transid; fs_devices->latest_generation = max_t(u64, found_transid, fs_devices->latest_generation); @@ -1120,15 +1121,19 @@ static void close_fs_devices(struct btrfs_fs_devices *fs_devices) lockdep_assert_held(&uuid_mutex); - if (--fs_devices->opened > 0) + if (--fs_devices->in_use > 0) return; + if (!fs_devices->is_open) + goto done; + list_for_each_entry_safe(device, tmp, &fs_devices->devices, dev_list) btrfs_close_one_device(device); WARN_ON(fs_devices->open_devices); WARN_ON(fs_devices->rw_devices); - fs_devices->opened = 0; + fs_devices->is_open = false; +done: fs_devices->seeding = false; fs_devices->fs_info = NULL; } @@ -1140,7 +1145,7 @@ void btrfs_close_devices(struct btrfs_fs_devices *fs_devices) mutex_lock(&uuid_mutex); close_fs_devices(fs_devices); - if (!fs_devices->opened) { + if (!fs_devices->in_use) { list_splice_init(&fs_devices->seed_list, &list); /* @@ -1188,7 +1193,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices, if (fs_devices->open_devices == 0) return -EINVAL; - fs_devices->opened = 1; + fs_devices->is_open = true; fs_devices->latest_dev = latest_dev; fs_devices->total_rw_bytes = 0; fs_devices->chunk_alloc_policy = BTRFS_CHUNK_ALLOC_REGULAR; @@ -1225,16 +1230,14 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, * We also don't need the lock here as this is called during mount and * exclusion is provided by uuid_mutex */ - - if (fs_devices->opened) { - fs_devices->opened++; - ret = 0; - } else { + if (!fs_devices->is_open) { list_sort(NULL, &fs_devices->devices, devid_cmp); ret = open_fs_devices(fs_devices, flags, holder); + if (ret) + return ret; } - - return ret; + fs_devices->in_use++; + return 0; } void btrfs_release_disk_super(struct btrfs_super_block *super) @@ -2201,13 +2204,14 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, * This can happen if cur_devices is the private seed devices list. We * cannot call close_fs_devices() here because it expects the uuid_mutex * to be held, but in fact we don't need that for the private - * seed_devices, we can simply decrement cur_devices->opened and then + * seed_devices, we can simply decrement cur_devices->in_use and then * remove it from our list and free the fs_devices. */ if (cur_devices->num_devices == 0) { list_del_init(&cur_devices->seed_list); - ASSERT(cur_devices->opened == 1); - cur_devices->opened--; + ASSERT(cur_devices->in_use == 1); + cur_devices->in_use--; + cur_devices->is_open = false; free_fs_devices(cur_devices); } @@ -2437,7 +2441,8 @@ static struct btrfs_fs_devices *btrfs_init_sprout(struct btrfs_fs_info *fs_info) list_add(&old_devices->fs_list, &fs_uuids); memcpy(seed_devices, fs_devices, sizeof(*seed_devices)); - seed_devices->opened = 1; + seed_devices->in_use = 1; + seed_devices->is_open = true; INIT_LIST_HEAD(&seed_devices->devices); INIT_LIST_HEAD(&seed_devices->alloc_list); mutex_init(&seed_devices->device_list_mutex); @@ -7115,7 +7120,8 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_fs_info *fs_info, return fs_devices; fs_devices->seeding = true; - fs_devices->opened = 1; + fs_devices->in_use = 1; + fs_devices->is_open = true; return fs_devices; } @@ -7132,6 +7138,7 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_fs_info *fs_info, free_fs_devices(fs_devices); return ERR_PTR(ret); } + fs_devices->in_use = 1; if (!fs_devices->seeding) { close_fs_devices(fs_devices); diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 97c7284e7565..d6dc41c62998 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -372,8 +372,10 @@ struct btrfs_fs_devices { struct list_head seed_list; - /* Count fs-devices opened. */ - int opened; + /* Count if fs_device is in used. */ + unsigned int in_use; + /* True if the devices were opened. */ + bool is_open; /* Set when we find or add a device that doesn't have the nonrot flag set. */ bool rotating; From patchwork Wed Feb 14 16:42:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 201038 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1344421dyb; Wed, 14 Feb 2024 08:44:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUKWxQf/73SA9yW9bMuydyt3X8F678sC40t2vJJmBeP2hmfpiR/JFRgFdyykRs5BbufCDUTy02P2bCj6MtZOQinIOcDjQ== X-Google-Smtp-Source: AGHT+IH26Ny9TWsd5aWIl1DZBPWAXPQ/9teL79VNKnQhPtatOLQumejDrzmGyRZugJ+izTEBTYbY X-Received: by 2002:a05:6870:658c:b0:21a:5866:f619 with SMTP id fp12-20020a056870658c00b0021a5866f619mr3375521oab.27.1707929085083; Wed, 14 Feb 2024 08:44:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707929085; cv=pass; d=google.com; s=arc-20160816; b=TrvmAHGofeh+ew+w5espsYyASsZsSURW2AND5mFt2WMnC/ZBGtYdTjkeaFaiJd4xjP VOK5LHEC+LhSJ3iRZGQCOqM5c5boDBY0GaocgT2tAFv/r1UsQtzBF746MeLXLtb03Xfg rX9I+HrbIf09czjzPeQvfPKVAk3P4s7VfYV9zJFRD3o+ZWgx+OQECDMGLDfMuvyFC7mP qOu3Q0A4J7kd+OH03TZLoZs2Q7X87sdvsuIrZeqhrLah96hJzWXPTm7cUES83GOoiMrO +RlXLGPHQM2u5I2975I27gXUb+YwgcAkNOmYhaAVw8GDZoddNxdlGY8ZBfOBfpuw9Y+q 1o6Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:wdcironportexception:ironport-sdr:ironport-sdr :dkim-signature; bh=DPr2H4z9C6WrBKqgJgswNo+R++XOB/GpMFkHsfZ8WiA=; fh=VBpPOVN+q+PfAjNrg4I+d9Q/fxUZnPL+SjXyqVNBarY=; b=yuN4MAyRWCGfw+4fesZJIdIpVd59s9bvWkPphA0eZSaoRIOtf2178HIJWdNFFSrqV9 WjcQNDC2L5SEFNcgzVJVAdWekNhaQTcyo0gQLjz3ACaUnJrb0/0gUKPfWiZH3KciFPHo nRxJIugeBihHfFpa8mbvh9nq4Iipwb8lqfHPDoqGPPZMK9JhiLAvNL2lWIE+BT1d9T05 POyt8JyL85CwrGaqCS5J1qEDe1Z/EtJbcmAqNn9GxenEOW3cTECZ3OEDkMAv2bxeHx8m glqMn/DoxHFS77f73RN/0qpDN/tUvSLyysFgB/Yjk1nptd9jX5vefGykiRjoZsAcDWhq ZuJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wdc.com header.s=dkim.wdc.com header.b="d/BdmOG0"; arc=pass (i=1 spf=pass spfdomain=wdc.com dkim=pass dkdomain=wdc.com dmarc=pass fromdomain=wdc.com); spf=pass (google.com: domain of linux-kernel+bounces-65575-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65575-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com X-Forwarded-Encrypted: i=2; AJvYcCUYLjVDSv9fFhnm0S0BEJMlWRWk8BVjLZ3BG7g42s6keTotOjSF/+pvq5jLHN94EjvbM2jXAZFYOgcGq1G5IwRASBZqUw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bm27-20020a05620a199b00b007872edac214si1261620qkb.603.2024.02.14.08.44.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 08:44:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65575-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@wdc.com header.s=dkim.wdc.com header.b="d/BdmOG0"; arc=pass (i=1 spf=pass spfdomain=wdc.com dkim=pass dkdomain=wdc.com dmarc=pass fromdomain=wdc.com); spf=pass (google.com: domain of linux-kernel+bounces-65575-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65575-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 425B91C288F2 for ; Wed, 14 Feb 2024 16:44:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CFE87634F6; Wed, 14 Feb 2024 16:42:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="d/BdmOG0" Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A36C61690; Wed, 14 Feb 2024 16:42:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928946; cv=none; b=WhOXRdtTcRfQAQFP8xUFZKnABSCbhbxLRgB45UcsAQkmy3M2Zx2u1eHzpUOGTIMoILz0I7r/C/SFJDJT/2GiVFmTC47VECrwfZSiNdMTydTrMSA3IHmwxtxO/LpYn63Kgiik9inIy1973YFNYRm18URHY9lL9VV0fljiS/MjBeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928946; c=relaxed/simple; bh=bH6vWRw60xnuXV0jlirxZDKuiOZGmQa5D7tTxE57gpM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EFVsLQOekGiNBqQwrjFcDvv2hc/7Pz2EiD7F02stiqIKuAbazCdhFDTbU/3ZAGG2rr8uThjXwPIJbO0u56xICu2Lysc262i7z+LwlsMksEjHQf3eH8UcK/GU3j0oPWpICPLm5rV82cXXVlBJP24kVpezKcQN4mrVybJwIUCG/tY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=d/BdmOG0; arc=none smtp.client-ip=216.71.154.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1707928945; x=1739464945; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=bH6vWRw60xnuXV0jlirxZDKuiOZGmQa5D7tTxE57gpM=; b=d/BdmOG0rUTis69cavNFSxT/qUmh+8lAB4x2Rw/OlCqlLqkAP2E2JVUf 9HhskvMWb1tr+/NfNjZ26vo2InuOFhCZJT1KJ0FJ6hWohJzkZ98YA8F5Y A+ETILS0xBMaCLpFAuAD7khkrnLpq3AnRyPhXN0A2tYP3YDAB8QIkg+Lw Is8PwkOEXvjgLDKNy3yQ/dCpy6OfTxe8zlNufEo1Tkewj8MJKQM2xJGTV 3O5lnggEF8NKfNvZt+6dY5rZZpRlKzFGty1izQsINT5Kskerkubq1q333 1Gi1g3+vnOtvb29v7EK78e/9dXjbQdKEmVtc5GzI9tdeuAWlSUzuga9fV g==; X-CSE-ConnectionGUID: 9drc1YFoQvaidyriv7WFXA== X-CSE-MsgGUID: 1iiedHrNQFeM2XliwCveJw== X-IronPort-AV: E=Sophos;i="6.06,159,1705334400"; d="scan'208";a="9294745" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2024 00:42:23 +0800 IronPort-SDR: HDZ2Vp1/6Jl6rHnVkIgbbev376ZIPH6QAGHVdQ4BFcUDRhNY7aAjSM2HQQNk+XuE6RhaTJrLSc 2a80kDhOYg9A== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2024 07:51:58 -0800 IronPort-SDR: sQgZ3eP1XpqDvjkE+iOQ0S3gHN20lFei3m2a7KcuC3C15nUIrDy/vEBRQRaz8S+T2zm0rZY0YB iia0adWGSQxQ== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 14 Feb 2024 08:42:20 -0800 From: Johannes Thumshirn Date: Wed, 14 Feb 2024 08:42:15 -0800 Subject: [PATCH 4/5] btrfs: open block devices after superblock creation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240214-hch-device-open-v1-4-b153428b4f72@wdc.com> References: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> In-Reply-To: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> To: Chris Mason , Josef Bacik , David Sterba , Christoph Hellwig Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707928933; l=4352; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=BhQPNDpB6/btBxArh/7gqFHYFe5pci1QG9ex6aK98P8=; b=v3u1ICI2D2ErbuWaEOekpBh2t3TtBEN3cbKtZ8iM6jF6pkBBUMzIEybn0Do9bfzM/wXANeICX QTKnpY1mqK3B6BtWioo70IqPyFlv4LU2/jLdo32dTbJ408sqVww6yC+ X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790893448486633559 X-GMAIL-MSGID: 1790893448486633559 From: Christoph Hellwig Currently btrfs_mount_root opens the block devices before committing to allocating a super block. That creates problems for restricting the number of writers to a device, and also leads to a unusual and not very helpful holder (the fs_type). Reorganize the code to first check whether the superblock for a particular fsid does already exist and open the block devices only if it doesn't, mirroring the recent changes to the VFS mount helpers. To do this the increment of the in_use counter moves out of btrfs_open_devices and into the only caller in btrfs_mount_root so that it happens before dropping uuid_mutex around the call to sget. Signed-off-by: Christoph Hellwig Signed-off-by: Johannes Thumshirn --- fs/btrfs/super.c | 41 +++++++++++++++++++++++++---------------- fs/btrfs/volumes.c | 15 +++++---------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 51b8fd272b15..1fa7d83d02c1 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1794,7 +1794,6 @@ static int btrfs_get_tree_super(struct fs_context *fc) struct btrfs_fs_info *fs_info = fc->s_fs_info; struct btrfs_fs_context *ctx = fc->fs_private; struct btrfs_fs_devices *fs_devices = NULL; - struct block_device *bdev; struct btrfs_device *device; struct super_block *sb; blk_mode_t mode = btrfs_open_mode(fc); @@ -1817,15 +1816,8 @@ static int btrfs_get_tree_super(struct fs_context *fc) fs_devices = device->fs_devices; fs_info->fs_devices = fs_devices; - ret = btrfs_open_devices(fs_devices, mode, &btrfs_fs_type); + fs_devices->in_use++; mutex_unlock(&uuid_mutex); - if (ret) - return ret; - - if (!(fc->sb_flags & SB_RDONLY) && fs_devices->rw_devices == 0) - return -EACCES; - - bdev = fs_devices->latest_dev->bdev; /* * From now on the error handling is not straightforward. @@ -1843,24 +1835,41 @@ static int btrfs_get_tree_super(struct fs_context *fc) set_device_specific_options(fs_info); if (sb->s_root) { - if ((fc->sb_flags ^ sb->s_flags) & SB_RDONLY) + if ((fc->sb_flags ^ sb->s_flags) & SB_RDONLY) { ret = -EBUSY; + goto error_deactivate; + } } else { - snprintf(sb->s_id, sizeof(sb->s_id), "%pg", bdev); + struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; + + mutex_lock(&uuid_mutex); + ret = btrfs_open_devices(fs_devices, mode, &btrfs_fs_type); + mutex_unlock(&uuid_mutex); + if (ret) + goto error_deactivate; + + if (!(fc->sb_flags & SB_RDONLY) && !fs_devices->rw_devices) { + ret = -EACCES; + goto error_deactivate; + } + + snprintf(sb->s_id, sizeof(sb->s_id), "%pg", + fs_devices->latest_dev->bdev); shrinker_debugfs_rename(sb->s_shrink, "sb-btrfs:%s", sb->s_id); btrfs_sb(sb)->bdev_holder = &btrfs_fs_type; ret = btrfs_fill_super(sb, fs_devices, NULL); - } - - if (ret) { - deactivate_locked_super(sb); - return ret; + if (ret) + goto error_deactivate; } btrfs_clear_oneshot_options(fs_info); fc->root = dget(sb->s_root); return 0; + +error_deactivate: + deactivate_locked_super(sb); + return ret; } /* diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index f27af155abf0..6e82bd7ce501 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1220,8 +1220,6 @@ static int devid_cmp(void *priv, const struct list_head *a, int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, blk_mode_t flags, void *holder) { - int ret; - lockdep_assert_held(&uuid_mutex); /* * The device_list_mutex cannot be taken here in case opening the @@ -1230,14 +1228,11 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, * We also don't need the lock here as this is called during mount and * exclusion is provided by uuid_mutex */ - if (!fs_devices->is_open) { - list_sort(NULL, &fs_devices->devices, devid_cmp); - ret = open_fs_devices(fs_devices, flags, holder); - if (ret) - return ret; - } - fs_devices->in_use++; - return 0; + ASSERT(fs_devices->in_use); + if (fs_devices->is_open) + return 0; + list_sort(NULL, &fs_devices->devices, devid_cmp); + return open_fs_devices(fs_devices, flags, holder); } void btrfs_release_disk_super(struct btrfs_super_block *super) From patchwork Wed Feb 14 16:42:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 201040 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1345540dyb; Wed, 14 Feb 2024 08:46:34 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUPwmMSTOqcZRyVKOiXUfTbKi774icc5lkDsQy0ogmBD/xaXMfadInq8OyaBamW+4TEyoOGja3Vp0+DkWS8GNaE7yOKig== X-Google-Smtp-Source: AGHT+IEDTuuILKx7d69PK21cAa+xjrnCX6Ds29X73i/R+AmN7lf7oItcOEP5IR0Bg26EqSS6D9vv X-Received: by 2002:a92:cb11:0:b0:363:b166:ea2 with SMTP id s17-20020a92cb11000000b00363b1660ea2mr3299827ilo.9.1707929194107; Wed, 14 Feb 2024 08:46:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707929194; cv=pass; d=google.com; s=arc-20160816; b=btE9tlsPhWDV6mKq5oLBAl9eKnHPTe0nRQjMr9Xl0BmpofdRwmwjE8VoBiNugPPoe5 gpDiysu0LWnDl2imm4/rVqCaMR7yVMpBQ5rgjxleZZ5seglGKqw3c+6FcysLoPl3W6Dy lwjN5D9Kpuj/lnXQIqaTec470eTe0hwD+COomRReKo7zdENRBxJlk2KI8GIiddwg9Hof xQCI3BQSmim+4XUkO2yjnRpusm1dO3utglc4HrsZrUHQufrEHuG1e1bsp1N8HdyVDOTV GO7fURCBFqusVupDME9oumQSl6Dy7uWAVPcuGhRjeabgJxcA7NpGlC9myMPJokaK3kiJ RT/g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:wdcironportexception:ironport-sdr:ironport-sdr :dkim-signature; bh=OwLPiVuuJkH+qNvkvSgk3m86Fi7bDHF1sr5aZCgkKxo=; fh=0YF3XZ9q4zNm/f5VzFg39Ugp4Gtpp9eo12HECNTUC1I=; b=JeO7v7Yka9+RgbJuaEmfzmwJmnMuqszTJiMWBGDENSbCCQ6b0h1ZNsYWYkU3e2A1VA WlMmrYaRtHy/STdZPPNPi8jVRtB6kOxKBrzFtjLfUzjpSKa3Cf5IeFVi/7q4ctfbyLHR pNFdhT5HT16HKF5e1ZViCXv7411gTbRCNAxiZedBsmg8FFTN5cUUWhyX8i9ituU1MHFp LrkKbDuZVCguSiyx7j6wBXGGkb2dTWx7UyNWx/miXQca+/0zVS/2f1Tjc8EAzI7hIUlv cH1pI3rSqjuEgZhxwnH8WdAvVxRoM/9Y4UKtMFjpmTRiNHfiF58bJxRBOkZ3ckfA0Fgb scOg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wdc.com header.s=dkim.wdc.com header.b=BqTZuWEZ; arc=pass (i=1 spf=pass spfdomain=wdc.com dkim=pass dkdomain=wdc.com dmarc=pass fromdomain=wdc.com); spf=pass (google.com: domain of linux-kernel+bounces-65576-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65576-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com X-Forwarded-Encrypted: i=2; AJvYcCXoray3+nHyDLoc8Jj/6ZKGryWMbT6I57Ieb08YFasW04rZh3Sbg8xnu3fNGtGKkueeUGcjE7SHN00XorSf4RlxJ5Fj3Q== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id r21-20020a638f55000000b005d47866f376si3893902pgn.854.2024.02.14.08.46.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 08:46:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65576-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@wdc.com header.s=dkim.wdc.com header.b=BqTZuWEZ; arc=pass (i=1 spf=pass spfdomain=wdc.com dkim=pass dkdomain=wdc.com dmarc=pass fromdomain=wdc.com); spf=pass (google.com: domain of linux-kernel+bounces-65576-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65576-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C33C9280D9B for ; Wed, 14 Feb 2024 16:44:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 945B6634E8; Wed, 14 Feb 2024 16:42:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="BqTZuWEZ" Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 401A761695; Wed, 14 Feb 2024 16:42:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928947; cv=none; b=uZl5QRCvb852R/GPCacDcDhwHFPXlthGbVcfH0iLcR3bONJU/2+f5QFYp5N6bbrXf7V8VIcEhBPFgLLST9/yRBiWKfPIiYoMyO75kNf7k85YA5TNviD9oWambqPd/2LCIMvJzqSeBTXKVThigOvbT+c9jT2WEg0a7hw2d7Isddo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928947; c=relaxed/simple; bh=n/Ct+FOCPnbG6TCxKfw5AO3FWijGxGRtmVbb789OJTM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ILtSj1VWUASBZGvy/KXiwnqdu7GORtmE1twnAR5NFSErthNGku1yPjdEtI1w1FdgkbLo0nmvuVYmUOOxtXcJDNwLCo4QgtxrYKx/lHxA9b9+GqvHeeRxxNauNtiCUIqabA3k9K3Z+DJv+YtWkSmDGdVEACXXYo5Y8+HXUdzxyk8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=BqTZuWEZ; arc=none smtp.client-ip=216.71.154.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1707928945; x=1739464945; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=n/Ct+FOCPnbG6TCxKfw5AO3FWijGxGRtmVbb789OJTM=; b=BqTZuWEZE8YUEPxhjGR4fbzg1nQbl4ttkg14Bs3PCw5WOX0bh+X1UHZy kX216bsZwX6lcZwjhu68P/HtyH8DYx0OcJbojGT+XiKhiAvaRbZYG/kdE iRgvLvRLA3fHCxggF+kM2SfxGBnd0Sy/FNOAjLT7VG9G/zyD0uh9jbxnl /XM7weEPIy5g0DS771TjTq9tBavolPHGu6b0hVvmclv2hyxfw+OVlws6A 72nWsI5FK00mLti2H7/xD7lxYYHqN+eA+Q+o5mPQg4p1NPb/E+TK7sC5a SBmV1Uz4v7GHPbjN2UHZ3khkOCnQmG3FhssqauFoCiepqRrCjyVgMO4Yq A==; X-CSE-ConnectionGUID: 3PqAXj1mRHCgh1akvRC+cw== X-CSE-MsgGUID: qvE74kfMRh+XStqcluh2OA== X-IronPort-AV: E=Sophos;i="6.06,159,1705334400"; d="scan'208";a="9294747" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2024 00:42:24 +0800 IronPort-SDR: F6k1MLOE5/8J8qKOpxUSURReH5Yusmwr/nIa58Ltsl2GXDjoysUKZnXpdmsY27sfc0rQGqJpsI Da6NvglNaSQg== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Feb 2024 07:51:59 -0800 IronPort-SDR: gqvyFZhGSaw04+Ud78YXDxHFnxQddOfK8ygif5khsnA6k0J5jME4Cy2ASv3MXe0GseQVdGmh5s aDi1iUDBXXGg== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 14 Feb 2024 08:42:22 -0800 From: Johannes Thumshirn Date: Wed, 14 Feb 2024 08:42:16 -0800 Subject: [PATCH 5/5] btrfs: use the super_block as holder when mounting file systems Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240214-hch-device-open-v1-5-b153428b4f72@wdc.com> References: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> In-Reply-To: <20240214-hch-device-open-v1-0-b153428b4f72@wdc.com> To: Chris Mason , Josef Bacik , David Sterba , Christoph Hellwig Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707928933; l=1407; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=5rfa6IXupj7Jvp1HyDQOjFATBDPTi0LqbzcMFjmSCro=; b=YI3WD5e/SUmGdIE0DfNpjyBwSXRjmr39hdskYzorTvIHh9L6oUFmy4XE+lzd7sgCkziaYG8x2 iNlLie//3u3DKi7tZZpXW/p1nuhTq0YEolIZFV0utmEplJ4NRDB7IDR X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790893562663655807 X-GMAIL-MSGID: 1790893562663655807 From: Christoph Hellwig The file system type is not a very useful holder as it doesn't allow us to go back to the actual file system instance. Pass the super_block instead which is useful when passed back to the file system driver. This matches what is done for all other block device based file systems. Signed-off-by: Christoph Hellwig Signed-off-by: Johannes Thumshirn --- fs/btrfs/super.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 1fa7d83d02c1..0c7956e8f21e 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1843,7 +1843,7 @@ static int btrfs_get_tree_super(struct fs_context *fc) struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; mutex_lock(&uuid_mutex); - ret = btrfs_open_devices(fs_devices, mode, &btrfs_fs_type); + ret = btrfs_open_devices(fs_devices, mode, sb); mutex_unlock(&uuid_mutex); if (ret) goto error_deactivate; @@ -1856,7 +1856,7 @@ static int btrfs_get_tree_super(struct fs_context *fc) snprintf(sb->s_id, sizeof(sb->s_id), "%pg", fs_devices->latest_dev->bdev); shrinker_debugfs_rename(sb->s_shrink, "sb-btrfs:%s", sb->s_id); - btrfs_sb(sb)->bdev_holder = &btrfs_fs_type; + btrfs_sb(sb)->bdev_holder = sb; ret = btrfs_fill_super(sb, fs_devices, NULL); if (ret) goto error_deactivate;