From patchwork Fri Oct 31 18:01:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 5206231 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 910B69F349 for ; Fri, 31 Oct 2014 18:02:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B092D2013D for ; Fri, 31 Oct 2014 18:02:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C8AAC2013A for ; Fri, 31 Oct 2014 18:02:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751502AbaJaSCL (ORCPT ); Fri, 31 Oct 2014 14:02:11 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:32685 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750912AbaJaSCJ (ORCPT ); Fri, 31 Oct 2014 14:02:09 -0400 Received: from pps.filterd (m0044012 [127.0.0.1]) by mx0a-00082601.pphosted.com (8.14.5/8.14.5) with SMTP id s9VHpwRf026777; Fri, 31 Oct 2014 11:02:08 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=0soo7IXhhcCPLGi8ierMGB4Kcz1sZj7QWpHSxb/pr5M=; b=kwm5ZDfrg1VY9a3Q3C4UUM6PWxHjzn39M2kv5XK8NWLSNIbmUUGaXVzd0obDiBt1II9r 9h13g9tZ1JIsJwsrU5Yewk7+Jgis1SjsDUW33/wNC16/g+hwyCiEBN5ZN0WuJymKV8vy wdW2WpIXS2NK4llqj1tDn9I1CWH90oQKb9M= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 1qbwhc220d-15 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=OK); Fri, 31 Oct 2014 11:02:08 -0700 Received: from localhost (192.168.57.29) by mail.thefacebook.com (192.168.16.19) with Microsoft SMTP Server (TLS) id 14.3.195.1; Fri, 31 Oct 2014 11:01:35 -0700 From: Josef Bacik To: , Subject: [PATCH 01/11] Btrfs-progs: add the ability to delete items Date: Fri, 31 Oct 2014 14:01:19 -0400 Message-ID: <1414778489-4049-2-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1414778489-4049-1-git-send-email-jbacik@fb.com> References: <1414778489-4049-1-git-send-email-jbacik@fb.com> MIME-Version: 1.0 X-Originating-IP: [192.168.57.29] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.12.52, 1.0.28, 0.0.0000 definitions=2014-10-31_08:2014-10-31, 2014-10-31, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 spamscore=0 suspectscore=2 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1410310168 X-FB-Internal: deliver Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Somtetimes you just need to delete an item, add that functionality to btrfs-corrupt-block. Thanks, Signed-off-by: Josef Bacik --- btrfs-corrupt-block.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c index 171c81d..af9ae4d 100644 --- a/btrfs-corrupt-block.c +++ b/btrfs-corrupt-block.c @@ -111,6 +111,7 @@ static void print_usage(void) fprintf(stderr, "\t-I An item to corrupt (must also specify the field " "to corrupt and a root+key for the item)\n"); fprintf(stderr, "\t-D Corrupt a dir item, must specify key and field\n"); + fprintf(stderr, "\t-d Delete this item (must specify -K)\n"); exit(1); } @@ -811,6 +812,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' }, @@ -828,6 +862,7 @@ static struct option long_options[] = { { "key", 1, NULL, 'K'}, { "item", 0, NULL, 'I'}, { "dir-item", 0, NULL, 'D'}, + { "delete", 0, NULL, 'd'}, { 0, 0, 0, 0} }; @@ -993,6 +1028,7 @@ int main(int ac, char **av) int chunk_tree = 0; int corrupt_item = 0; int corrupt_di = 0; + int delete = 0; u64 metadata_block = 0; u64 inode = 0; u64 file_extent = (u64)-1; @@ -1004,7 +1040,7 @@ int main(int ac, char **av) while(1) { int c; - c = getopt_long(ac, av, "l:c:b:eEkuUi:f:x:m:K:ID", long_options, + c = getopt_long(ac, av, "l:c:b:eEkuUi:f:x:m:K:IDd", long_options, &option_index); if (c < 0) break; @@ -1060,6 +1096,8 @@ int main(int ac, char **av) break; case 'I': corrupt_item = 1; + case 'd': + delete = 1; break; default: print_usage(); @@ -1167,6 +1205,11 @@ int main(int ac, char **av) if (!key.objectid) print_usage(); ret = corrupt_btrfs_item(root, &key, field); + } + if (delete) { + if (!key.objectid) + print_usage(); + ret = delete_item(root, &key); goto out_close; } if (key.objectid || key.offset || key.type) {