From patchwork Fri Feb 2 08:27:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lu Fengqi X-Patchwork-Id: 10196371 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 60E2B60362 for ; Fri, 2 Feb 2018 08:28:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E77628BF2 for ; Fri, 2 Feb 2018 08:28:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4379228E0F; Fri, 2 Feb 2018 08:28:14 +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 CA91F28BF2 for ; Fri, 2 Feb 2018 08:28:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751900AbeBBI2L (ORCPT ); Fri, 2 Feb 2018 03:28:11 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:33627 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751856AbeBBI2H (ORCPT ); Fri, 2 Feb 2018 03:28:07 -0500 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="36672979" Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 02 Feb 2018 16:28:01 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id C8F7649F19C3 for ; Fri, 2 Feb 2018 16:28:02 +0800 (CST) Received: from localhost.localdomain (10.167.226.155) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 2 Feb 2018 16:28:00 +0800 From: Lu Fengqi To: Subject: [PATCH 04/10] btrfs-progs: undelete-subvol: introduce is_subvol_intact Date: Fri, 2 Feb 2018 16:27:45 +0800 Message-ID: <20180202082751.26225-5-lufq.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202082751.26225-1-lufq.fnst@cn.fujitsu.com> References: <20180202082751.26225-1-lufq.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.155] X-yoursite-MailScanner-ID: C8F7649F19C3.AC2D9 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 --- Makefile | 3 ++- undelete-subvol.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ undelete-subvol.h | 17 +++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 undelete-subvol.c create mode 100644 undelete-subvol.h diff --git a/Makefile b/Makefile index 327cdfa08eba..accbd4069ad9 100644 --- a/Makefile +++ b/Makefile @@ -106,7 +106,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..00fcc4895778 --- /dev/null +++ b/undelete-subvol.c @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2018 Fujitsu. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include "ctree.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_root *root, u64 subvol_id) +{ + struct btrfs_path path; + struct btrfs_key key; + struct extent_buffer *leaf; + struct btrfs_root_item root_item; + u64 offset; + int ret; + + key.objectid = subvol_id; + key.type = BTRFS_ROOT_ITEM_KEY; + key.offset = 0; + + btrfs_init_path(&path); + ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0); + if (ret) { + ret = false; + goto out; + } + + leaf = path.nodes[0]; + offset = btrfs_item_ptr_offset(leaf, path.slots[0]); + + read_extent_buffer(leaf, &root_item, offset, sizeof(root_item)); + + /* the subvolume is intact if the objectid of drop_progress == 0 */ + ret = btrfs_disk_key_objectid(&root_item.drop_progress) ? false : true; + +out: + btrfs_release_path(&path); + return ret; +} diff --git a/undelete-subvol.h b/undelete-subvol.h new file mode 100644 index 000000000000..7cfd100cce37 --- /dev/null +++ b/undelete-subvol.h @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2018 Fujitsu. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#ifndef __BTRFS_UNDELETE_SUBVOLUME_H__ +#define __BTRFS_UNDELETE_SUBVOLUME_H__ + +#endif