[v3,04/10] btrfs-progs: undelete-subvol: introduce is_subvol_intact
diff mbox

Message ID 20180507031033.4125-5-lufq.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Lu Fengqi May 7, 2018, 3:10 a.m. UTC
The function is used to determine whether the subvolume is intact.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
---
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

Patch
diff mbox

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);
+}