Received: by 10.223.185.116 with SMTP id b49csp5439087wrg; Wed, 7 Mar 2018 11:46:10 -0800 (PST) X-Google-Smtp-Source: AG47ELsBDXxfRL/LZB9GYfPk31km5WryXfiV+SzlK4+bQN8VEmnt+uOiD5jNqcYUU7D05266Kga3 X-Received: by 10.167.131.199 with SMTP id j7mr23312028pfn.99.1520451970201; Wed, 07 Mar 2018 11:46:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520451970; cv=none; d=google.com; s=arc-20160816; b=nSBvdlSfZcnJivSrEYrnfbhjQB2U/PY3HeYF77Z5Ymv+7lP3TtuFHw00Gwm700ePzz xumaouCl4VMQ64a1gOPGvBiRjbTzKFBZmJBs6faAE+OQVQt+wULUQDYLT5fXeGK8Ef8h 3kk8wdpOAwnabk3caoMn4QPDG0LzNTqwCEbobBzvR3//w/XjogC0ZQEnsoxVv1HlI4NN kujCtaOI3129Ei5Jb2x6trhOiNX2lasowJMp3Xn9uzqu/iHGPYmQHLGXrF87PhIjaHOn 6E317AGAt10SIjaBluYO9+84tRnV1xKUkOgraUGi5fNtjnlheByEzPuTUVCWJ5FLrWto OCQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=TSMjgN2/y/lX87rJ8fTEPPjI5ohIEGRyVkEaRX50evI=; b=rsaTZFUbGbt3O3bRQCsIZ5fZgGZxqNIdBWv0AVdsj7GChzjXy6XNXoODjSy8uI2MUu iFJN32IQ5bXgDUEVQekZ7P/QBLpmbrVWqpG6ixvC/JVRQmS76yX+IQyzLoqlMPu4WDgj gzMTprXcms3XTEgiYMuIDxdrUlq2L7/tSm47FXcpHSS1DY72QHz3uZLy3uWowhsOotQf 3O1CuZ0p/rRkan+xv0Rg9y0KxnEOY8ijw9xGHCfdx2wcQEHgzZl/4ngGOgwOH+guYYgQ bjUs50ItlP4bDk3beiXELZLR2xhgmncKFo9I7PrKduw51i3omy5c+ICNvMJbYYqE/7eR zuGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bb2-v6si2947491plb.565.2018.03.07.11.45.55; Wed, 07 Mar 2018 11:46:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965231AbeCGTpG (ORCPT + 99 others); Wed, 7 Mar 2018 14:45:06 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:44026 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965182AbeCGTpE (ORCPT ); Wed, 7 Mar 2018 14:45:04 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C58AFF2F; Wed, 7 Mar 2018 19:45:03 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anand Jain , Liu Bo , David Sterba Subject: [PATCH 4.14 024/110] btrfs: use proper endianness accessors for super_copy Date: Wed, 7 Mar 2018 11:38:07 -0800 Message-Id: <20180307191042.810088712@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307191039.748351103@linuxfoundation.org> References: <20180307191039.748351103@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Anand Jain commit 3c181c12c431fe33b669410d663beb9cceefcd1b upstream. The fs_info::super_copy is a byte copy of the on-disk structure and all members must use the accessor macros/functions to obtain the right value. This was missing in update_super_roots and in sysfs readers. Moving between opposite endianness hosts will report bogus numbers in sysfs, and mount may fail as the root will not be restored correctly. If the filesystem is always used on a same endian host, this will not be a problem. Fix this by using the btrfs_set_super...() functions to set fs_info::super_copy values, and for the sysfs, use the cached fs_info::nodesize/sectorsize values. CC: stable@vger.kernel.org Fixes: df93589a17378 ("btrfs: export more from FS_INFO to sysfs") Signed-off-by: Anand Jain Reviewed-by: Liu Bo Reviewed-by: David Sterba [ update changelog ] Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/sysfs.c | 8 +++----- fs/btrfs/transaction.c | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -422,7 +422,7 @@ static ssize_t btrfs_nodesize_show(struc { struct btrfs_fs_info *fs_info = to_fs_info(kobj); - return snprintf(buf, PAGE_SIZE, "%u\n", fs_info->super_copy->nodesize); + return snprintf(buf, PAGE_SIZE, "%u\n", fs_info->nodesize); } BTRFS_ATTR(nodesize, btrfs_nodesize_show); @@ -432,8 +432,7 @@ static ssize_t btrfs_sectorsize_show(str { struct btrfs_fs_info *fs_info = to_fs_info(kobj); - return snprintf(buf, PAGE_SIZE, "%u\n", - fs_info->super_copy->sectorsize); + return snprintf(buf, PAGE_SIZE, "%u\n", fs_info->sectorsize); } BTRFS_ATTR(sectorsize, btrfs_sectorsize_show); @@ -443,8 +442,7 @@ static ssize_t btrfs_clone_alignment_sho { struct btrfs_fs_info *fs_info = to_fs_info(kobj); - return snprintf(buf, PAGE_SIZE, "%u\n", - fs_info->super_copy->sectorsize); + return snprintf(buf, PAGE_SIZE, "%u\n", fs_info->sectorsize); } BTRFS_ATTR(clone_alignment, btrfs_clone_alignment_show); --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1722,19 +1722,23 @@ static void update_super_roots(struct bt super = fs_info->super_copy; + /* update latest btrfs_super_block::chunk_root refs */ root_item = &fs_info->chunk_root->root_item; - super->chunk_root = root_item->bytenr; - super->chunk_root_generation = root_item->generation; - super->chunk_root_level = root_item->level; + btrfs_set_super_chunk_root(super, root_item->bytenr); + btrfs_set_super_chunk_root_generation(super, root_item->generation); + btrfs_set_super_chunk_root_level(super, root_item->level); + /* update latest btrfs_super_block::root refs */ root_item = &fs_info->tree_root->root_item; - super->root = root_item->bytenr; - super->generation = root_item->generation; - super->root_level = root_item->level; + btrfs_set_super_root(super, root_item->bytenr); + btrfs_set_super_generation(super, root_item->generation); + btrfs_set_super_root_level(super, root_item->level); + if (btrfs_test_opt(fs_info, SPACE_CACHE)) - super->cache_generation = root_item->generation; + btrfs_set_super_cache_generation(super, root_item->generation); if (test_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags)) - super->uuid_tree_generation = root_item->generation; + btrfs_set_super_uuid_tree_generation(super, + root_item->generation); } int btrfs_transaction_in_commit(struct btrfs_fs_info *info)