From patchwork Mon May 7 03:10:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lu Fengqi X-Patchwork-Id: 10383165 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 B72106053A for ; Mon, 7 May 2018 03:10:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8CAB28478 for ; Mon, 7 May 2018 03:10:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DA3A28B21; Mon, 7 May 2018 03:10:57 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 4160D28478 for ; Mon, 7 May 2018 03:10:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751987AbeEGDKz (ORCPT ); Sun, 6 May 2018 23:10:55 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:56801 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751920AbeEGDKq (ORCPT ); Sun, 6 May 2018 23:10:46 -0400 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="39622269" Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 07 May 2018 11:10:44 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 0E9774B31495 for ; Mon, 7 May 2018 11:10:44 +0800 (CST) Received: from fnst.localdomain (10.167.226.155) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 7 May 2018 11:10:45 +0800 From: Lu Fengqi To: Subject: [PATCH v3 04/10] btrfs-progs: undelete-subvol: introduce is_subvol_intact Date: Mon, 7 May 2018 11:10:27 +0800 Message-ID: <20180507031033.4125-5-lufq.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180507031033.4125-1-lufq.fnst@cn.fujitsu.com> References: <20180507031033.4125-1-lufq.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.155] X-yoursite-MailScanner-ID: 0E9774B31495.AB586 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: lufq.fnst@cn.fujitsu.com 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 The function is used to determine whether the subvolume is intact. Signed-off-by: Lu Fengqi --- V3: add SPDX-License-Identifier; pass btrfs_fs_info instead of btrfs_root; use btrfs_read_fs_root instead of manually search; remove empty header file. Makefile | 3 ++- undelete-subvol.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 undelete-subvol.c diff --git a/Makefile b/Makefile index cbd855336b2f..6a425e3a65dd 100644 --- a/Makefile +++ b/Makefile @@ -116,7 +116,8 @@ objects = ctree.o disk-io.o kernel-lib/radix-tree.o extent-tree.o print-tree.o \ qgroup.o free-space-cache.o kernel-lib/list_sort.o props.o \ kernel-shared/ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \ inode.o file.o find-root.o free-space-tree.o help.o send-dump.o \ - fsfeatures.o kernel-lib/tables.o kernel-lib/raid56.o transaction.o + fsfeatures.o kernel-lib/tables.o kernel-lib/raid56.o transaction.o \ + undelete-subvol.o cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \ cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \ cmds-quota.o cmds-qgroup.o cmds-replace.o check/main.o \ diff --git a/undelete-subvol.c b/undelete-subvol.c new file mode 100644 index 000000000000..26e156092011 --- /dev/null +++ b/undelete-subvol.c @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018 Fujitsu. All rights reserved. + */ + +#include "ctree.h" +#include "disk-io.h" + +/* + * Determines whether the subvolume is intact, according to the drop_progress + * of the root item specified by @subvol_id. + * + * Return true if the subvolume is intact, otherwise return false. + */ +static bool is_subvol_intact(struct btrfs_fs_info *fs_info, u64 subvol_id) +{ + struct btrfs_key key; + struct btrfs_root *root; + + key.objectid = subvol_id; + key.type = BTRFS_ROOT_ITEM_KEY; + key.offset = -1; + + root = btrfs_read_fs_root(fs_info, &key); + if (IS_ERR(root)) + return false; + + /* the subvolume is intact if the objectid of drop_progress == 0 */ + return !btrfs_disk_key_objectid(&root->root_item.drop_progress); +}