-int (*ops[])(struct ctree_root *root, struct radix_tree_root *radix) =
-{ ins_one, insert_dup, del_one, lookup_item, lookup_enoent };
+static int empty_tree(struct btrfs_trans_handle *trans, struct btrfs_root
+ *root, struct radix_tree_root *radix, int nr)
+{
+ struct btrfs_path path;
+ struct btrfs_key key;
+ unsigned long found = 0;
+ int ret;
+ int slot;
+ int *ptr;
+ int count = 0;
+
+ key.offset = 0;
+ key.flags = 0;
+ key.type = BTRFS_STRING_ITEM_KEY;
+ key.objectid = (unsigned long)-1;
+ while(nr-- >= 0) {
+ btrfs_init_path(&path);
+ ret = btrfs_search_slot(trans, root, &key, &path, -1, 1);
+ if (ret < 0) {
+ btrfs_release_path(&path);
+ return ret;
+ }
+ if (ret != 0) {
+ if (path.slots[0] == 0) {
+ btrfs_release_path(&path);
+ break;
+ }
+ path.slots[0] -= 1;
+ }
+ slot = path.slots[0];
+ found = btrfs_disk_key_objectid(
+ &path.nodes[0]->leaf.items[slot].key);
+ ret = btrfs_del_item(trans, root, &path);
+ count++;
+ if (ret) {
+ fprintf(stderr,
+ "failed to remove %lu from tree\n",
+ found);
+ return ret;
+ }
+ btrfs_release_path(&path);
+ ptr = radix_tree_delete(radix, found);
+ if (!ptr)
+ goto error;
+ if (!keep_running)
+ break;
+ }
+ return 0;
+error:
+ fprintf(stderr, "failed to delete from the radix %lu\n", found);
+ return -ENOENT;
+}