From patchwork Mon Mar 19 08:16:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Misono Tomohiro X-Patchwork-Id: 10291821 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3E24A602C2 for ; Mon, 19 Mar 2018 08:18:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C363926419 for ; Mon, 19 Mar 2018 08:17:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B801E27165; Mon, 19 Mar 2018 08:17:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A8B626247 for ; Mon, 19 Mar 2018 08:17:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932073AbeCSIRv (ORCPT ); Mon, 19 Mar 2018 04:17:51 -0400 Received: from mgwym02.jp.fujitsu.com ([211.128.242.41]:42321 "EHLO mgwym02.jp.fujitsu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750962AbeCSIRt (ORCPT ); Mon, 19 Mar 2018 04:17:49 -0400 Received: from yt-mxauth.gw.nic.fujitsu.com (unknown [192.168.229.68]) by mgwym02.jp.fujitsu.com with smtp id 5a36_adab_5d7bc509_9f11_40c8_aee1_d0a8b0cdad1a; Mon, 19 Mar 2018 17:17:42 +0900 Received: from g01jpfmpwkw03.exch.g01.fujitsu.local (g01jpfmpwkw03.exch.g01.fujitsu.local [10.0.193.57]) by yt-mxauth.gw.nic.fujitsu.com (Postfix) with ESMTP id B2A04AC0065 for ; Mon, 19 Mar 2018 17:17:41 +0900 (JST) Received: from g01jpexchkw33.g01.fujitsu.local (unknown [10.0.193.4]) by g01jpfmpwkw03.exch.g01.fujitsu.local (Postfix) with ESMTP id 02C62BD6625 for ; Mon, 19 Mar 2018 17:17:41 +0900 (JST) X-SecurityPolicyCheck: OK by SHieldMailChecker v2.5.2 X-SHieldMailCheckerPolicyVersion: FJ-ISEC-20170217-enc X-SHieldMailCheckerMailID: 7f9bf799956a4be69406d5b820de8016 From: "Misono, Tomohiro" Subject: [PATCH] btrfs-progs: mkfs: add uuid and otime to ROOT_ITEM of FS_TREE To: linux-btrfs Message-ID: <7ca269db-a724-5938-f4d8-b85e893fd558@jp.fujitsu.com> Date: Mon, 19 Mar 2018 17:16:42 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 Content-Language: en-US X-SecurityPolicyCheck-GC: OK by FENCE-Mail X-TM-AS-MML: disable Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, the top-level subvolume lacks the UUID. As a result, both non-snapshot subvolume and snapshot of top-level subvolume do not have Parent UUID and cannot be distinguisued. Therefore "fi show" of top-level lists all the subvolumes which lacks the UUID in "Snapshot(s)" filed. Also, it lacks the otime information. Fix this by adding the UUID and otime at the mkfs time. As a consequence, snapshots of top-level subvolume now have a Parent UUID and UUID tree will create an entry for top-level subvolume at mount time. This should not cause the problem for current kernel, but user program which relies on the empty Parent UUID may be affected by this change. Signed-off-by: Tomohiro Misono --- This is also needed in order that "sub list -s" works properly for non-privileged user[1] even if there are snapshots of toplevel subvolume. Currently the check if a subvolume is a snapshot is done by looking at the key offset of ROOT_ITEM of subvolume (non-zero for snapshot) used by tree search ioctl. However, non-privileged version of "sub list" won't use tree search ioctl and just looking if parent uuid is null or not. Therefore there is no way to recognize snapshots of toplevel subvolume. [1] https://marc.info/?l=linux-btrfs&m=152144463907830&w=2 mkfs/common.c | 14 ++++++++++++++ mkfs/main.c | 3 +++ 2 files changed, 17 insertions(+) diff --git a/mkfs/common.c b/mkfs/common.c index 16916ca2..6924d9b7 100644 --- a/mkfs/common.c +++ b/mkfs/common.c @@ -44,6 +44,7 @@ static int btrfs_create_tree_root(int fd, struct btrfs_mkfs_config *cfg, u32 itemoff; int ret = 0; int blk; + u8 uuid[BTRFS_UUID_SIZE]; memset(buf->data + sizeof(struct btrfs_header), 0, cfg->nodesize - sizeof(struct btrfs_header)); @@ -77,6 +78,19 @@ static int btrfs_create_tree_root(int fd, struct btrfs_mkfs_config *cfg, btrfs_set_item_offset(buf, btrfs_item_nr(nritems), itemoff); btrfs_set_item_size(buf, btrfs_item_nr(nritems), sizeof(root_item)); + if (blk == MKFS_FS_TREE) { + time_t now = time(NULL); + + uuid_generate(uuid); + memcpy(root_item.uuid, uuid, BTRFS_UUID_SIZE); + btrfs_set_stack_timespec_sec(&root_item.otime, now); + btrfs_set_stack_timespec_sec(&root_item.ctime, now); + } else { + memset(uuid, 0, BTRFS_UUID_SIZE); + memcpy(root_item.uuid, uuid, BTRFS_UUID_SIZE); + btrfs_set_stack_timespec_sec(&root_item.otime, 0); + btrfs_set_stack_timespec_sec(&root_item.ctime, 0); + } write_extent_buffer(buf, &root_item, btrfs_item_ptr_offset(buf, nritems), sizeof(root_item)); diff --git a/mkfs/main.c b/mkfs/main.c index 5a717f70..52d92581 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -315,6 +315,7 @@ static int create_tree(struct btrfs_trans_handle *trans, struct btrfs_key location; struct btrfs_root_item root_item; struct extent_buffer *tmp; + u8 uuid[BTRFS_UUID_SIZE] = {0}; int ret; ret = btrfs_copy_root(trans, root, root->node, &tmp, objectid); @@ -325,6 +326,8 @@ static int create_tree(struct btrfs_trans_handle *trans, btrfs_set_root_bytenr(&root_item, tmp->start); btrfs_set_root_level(&root_item, btrfs_header_level(tmp)); btrfs_set_root_generation(&root_item, trans->transid); + /* clear uuid of source tree */ + memcpy(root_item.uuid, uuid, BTRFS_UUID_SIZE); free_extent_buffer(tmp); location.objectid = objectid;