From: Josef Bacik <jbacik@fb.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH] Btrfs-progs: add the ability to delete items
Date: Thu, 2 Oct 2014 14:50:17 -0400 [thread overview]
Message-ID: <1412275817-8005-1-git-send-email-jbacik@fb.com> (raw)
Somtetimes you just need to delete an item, add that functionality to
btrfs-corrupt-block. Thanks,
Signed-off-by: Josef Bacik <jbacik@fb.com>
---
btrfs-corrupt-block.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 46 insertions(+), 1 deletion(-)
diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index 22390b5..278a56f 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -108,6 +108,7 @@ static void print_usage(void)
fprintf(stderr, "\t-K The key to corrupt in the format "
"<num>,<num>,<num> (must also specify -f for the field)\n");
fprintf(stderr, "\t-f The field in the item to corrupt\n");
+ fprintf(stderr, "\t-d Delete this item (must specify -K)\n");
exit(1);
}
@@ -645,6 +646,39 @@ out:
return ret;
}
+static int delete_item(struct btrfs_root *root, struct btrfs_key *key)
+{
+ struct btrfs_trans_handle *trans;
+ struct btrfs_path *path;
+ int ret;
+
+ path = btrfs_alloc_path();
+ if (!path)
+ return -ENOMEM;
+
+ trans = btrfs_start_transaction(root, 1);
+ if (IS_ERR(trans)) {
+ btrfs_free_path(path);
+ fprintf(stderr, "Couldn't start transaction %ld\n",
+ PTR_ERR(trans));
+ return PTR_ERR(trans);
+ }
+
+ ret = btrfs_search_slot(trans, root, key, path, -1, 1);
+ if (ret) {
+ if (ret > 0)
+ ret = -ENOENT;
+ fprintf(stderr, "Error searching to node %d\n", ret);
+ goto out;
+ }
+ ret = btrfs_del_item(trans, root, path);
+ btrfs_mark_buffer_dirty(path->nodes[0]);
+out:
+ btrfs_commit_transaction(trans, root);
+ btrfs_free_path(path);
+ return ret;
+}
+
static struct option long_options[] = {
/* { "byte-count", 1, NULL, 'b' }, */
{ "logical", 1, NULL, 'l' },
@@ -660,6 +694,7 @@ static struct option long_options[] = {
{ "metadata-block", 1, NULL, 'm'},
{ "field", 1, NULL, 'f'},
{ "key", 1, NULL, 'K'},
+ { "delete", 0, NULL, 'd'},
{ 0, 0, 0, 0}
};
@@ -823,6 +858,7 @@ int main(int ac, char **av)
int corrupt_block_keys = 0;
int chunk_rec = 0;
int chunk_tree = 0;
+ int delete = 0;
u64 metadata_block = 0;
u64 inode = 0;
u64 file_extent = (u64)-1;
@@ -834,7 +870,7 @@ int main(int ac, char **av)
while(1) {
int c;
- c = getopt_long(ac, av, "l:c:b:eEkuUi:f:x:m:K:", long_options,
+ c = getopt_long(ac, av, "l:c:b:eEkuUi:f:x:m:K:d", long_options,
&option_index);
if (c < 0)
break;
@@ -885,6 +921,9 @@ int main(int ac, char **av)
print_usage();
}
break;
+ case 'd':
+ delete = 1;
+ break;
default:
print_usage();
}
@@ -981,6 +1020,12 @@ int main(int ac, char **av)
ret = corrupt_metadata_block(root, metadata_block, field);
goto out_close;
}
+ if (delete) {
+ if (!key.objectid)
+ print_usage();
+ ret = delete_item(root, &key);
+ goto out_close;
+ }
if (key.objectid || key.offset || key.type) {
if (!strlen(field))
print_usage();
--
1.8.3.1
reply other threads:[~2014-10-02 18:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1412275817-8005-1-git-send-email-jbacik@fb.com \
--to=jbacik@fb.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).