From patchwork Fri Feb 2 08:27:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lu Fengqi X-Patchwork-Id: 10196373 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 C5CBB60362 for ; Fri, 2 Feb 2018 08:28:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B481828BF2 for ; Fri, 2 Feb 2018 08:28:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A997E28E0F; Fri, 2 Feb 2018 08:28:17 +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 30B1E28BF2 for ; Fri, 2 Feb 2018 08:28:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751907AbeBBI2P (ORCPT ); Fri, 2 Feb 2018 03:28:15 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:38023 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751837AbeBBI2G (ORCPT ); Fri, 2 Feb 2018 03:28:06 -0500 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="36672983" 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 64C6849F19BA for ; Fri, 2 Feb 2018 16:28:01 +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:27:59 +0800 From: Lu Fengqi To: Subject: [PATCH 01/10] btrfs-progs: copy btrfs_del_orphan_item from kernel Date: Fri, 2 Feb 2018 16:27:42 +0800 Message-ID: <20180202082751.26225-2-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: 64C6849F19BA.AAF38 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 Add btrfs_del_orphan_item for the later subvolume undelete. Signed-off-by: Lu Fengqi --- ctree.h | 2 ++ inode.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/ctree.h b/ctree.h index 17cdac76c58c..84bad186a349 100644 --- a/ctree.h +++ b/ctree.h @@ -2784,6 +2784,8 @@ int btrfs_unlink(struct btrfs_trans_handle *trans, struct btrfs_root *root, int btrfs_add_orphan_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_path *path, u64 ino); +int btrfs_del_orphan_item(struct btrfs_trans_handle *trans, + struct btrfs_root *root, u64 offset); int btrfs_mkdir(struct btrfs_trans_handle *trans, struct btrfs_root *root, char *name, int namelen, u64 parent_ino, u64 *ino, int mode); struct btrfs_root *btrfs_mksubvol(struct btrfs_root *root, const char *base, diff --git a/inode.c b/inode.c index 2398bca4a109..8d0812c7cf50 100644 --- a/inode.c +++ b/inode.c @@ -262,6 +262,36 @@ int btrfs_add_orphan_item(struct btrfs_trans_handle *trans, return btrfs_insert_empty_item(trans, root, path, &key, 0); } +int btrfs_del_orphan_item(struct btrfs_trans_handle *trans, + struct btrfs_root *root, u64 offset) +{ + struct btrfs_path *path; + struct btrfs_key key; + int ret = 0; + + key.objectid = BTRFS_ORPHAN_OBJECTID; + key.type = BTRFS_ORPHAN_ITEM_KEY; + key.offset = offset; + + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + + ret = btrfs_search_slot(trans, root, &key, path, -1, 1); + if (ret < 0) + goto out; + if (ret) { + ret = -ENOENT; + goto out; + } + + ret = btrfs_del_item(trans, root, path); + +out: + btrfs_free_path(path); + return ret; +} + /* * Unlink an inode, which will remove its backref and corresponding dir_index/ * dir_item if any of them exists.