From patchwork Mon Feb 9 20:03:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 5803171 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 86569BF440 for ; Mon, 9 Feb 2015 20:04:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A84512011D for ; Mon, 9 Feb 2015 20:04:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC7012011B for ; Mon, 9 Feb 2015 20:04:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760943AbbBIUD4 (ORCPT ); Mon, 9 Feb 2015 15:03:56 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:6896 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760826AbbBIUDx (ORCPT ); Mon, 9 Feb 2015 15:03:53 -0500 Received: from pps.filterd (m0004077 [127.0.0.1]) by mx0b-00082601.pphosted.com (8.14.5/8.14.5) with SMTP id t19K3l5R022536; Mon, 9 Feb 2015 12:03:51 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wit.ai; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=mx2; bh=YOx4qSFvYDDa6oYdU9GlESqST7gzfG7vtIRVVagpe6E=; b=RPfOq2r/mQP8uLIB2GY1/92d66qLTjmEN2RkRxD90elasvPL6D8Nh5df72l12q/Nixc2 jGIBxRAenskbQZ2WxiYZXYAaIxuuofxIYyKmWjBc4RKQd9Nn//z2KBLkcKlZAS35L1ii SVN9xB9cyXvQ4ZYZ58fzL/IY3onIXXYCESkUiHDwrnhyrX6moO/cTuLM5n87cvFgNmlF dYInVsVjkrJ1vcoqRL38gsDgg21DbY3fkduzGQtomEDRdDWB8LA2StGxU4cJ6+NZGEUj sD4qWPbo428/1fUQ/gbBCJtUNTWXZnuYrJPUNRfToIFJ95gv44lkBp5IdptqOTVtz8ZR kQ== 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=YOx4qSFvYDDa6oYdU9GlESqST7gzfG7vtIRVVagpe6E=; b=nGMdFEMyWQv9YYfDALeYr9A8yFt+jMBro8ypDf2nNV4LZ2h7mZjeahyVRTkdOefoIWe2 5imIBAkQ9SnkmzOBpX51g31j+AVExoffJlXen6sD/5sULc9wrs0lHBDH76RR6/1ZaQPO C28eRf1YKED39JnbKnb+RQKSnf7WalujUwM= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0b-00082601.pphosted.com with ESMTP id 1sf2yv04b4-4 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Mon, 09 Feb 2015 12:03:51 -0800 Received: from localhost (192.168.57.29) by mail.thefacebook.com (192.168.16.23) with Microsoft SMTP Server (TLS) id 14.3.195.1; Mon, 9 Feb 2015 12:03:24 -0800 From: Josef Bacik To: , Subject: [PATCH 01/16] Btrfs-progs: let btrfs-corrupt-block specify a root Date: Mon, 9 Feb 2015 15:03:04 -0500 Message-ID: <1423512199-16552-2-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1423512199-16552-1-git-send-email-jbacik@fb.com> References: <1423512199-16552-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.13.68, 1.0.33, 0.0.0000 definitions=2015-02-09_02:2015-02-09, 2015-02-08, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 kscore.is_bulkscore=0 kscore.compositescore=0 circleOfTrustscore=2.00421954885187 compositescore=0.980601336099369 urlsuspect_oldscore=0.980601336099369 suspectscore=0 recipient_domain_to_sender_totalscore=0 phishscore=0 bulkscore=0 kscore.is_spamscore=0 recipient_to_sender_totalscore=0 recipient_domain_to_sender_domain_totalscore=62764 rbsscore=0.980601336099369 spamscore=0 recipient_to_sender_domain_totalscore=0 urlsuspectscore=0.9 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1502090197 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=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,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 Sometimes we want to corrupt specific keys or delete items on different roots, so allow btrfs-corrupt-block to take a root objectid so we can corrupt a specific root. Thanks, Signed-off-by: Josef Bacik --- btrfs-corrupt-block.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c index 5db18a1..f332bdf 100644 --- a/btrfs-corrupt-block.c +++ b/btrfs-corrupt-block.c @@ -109,6 +109,7 @@ static void print_usage(void) "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"); + fprintf(stderr, "\t-r Operate on this root (only works with -d)\n"); exit(1); } @@ -1007,6 +1008,7 @@ int main(int ac, char **av) u64 metadata_block = 0; u64 inode = 0; u64 file_extent = (u64)-1; + u64 root_objectid = 0; char field[FIELD_BUF_LEN]; field[0] = '\0'; @@ -1034,11 +1036,12 @@ int main(int ac, char **av) { "item", 0, NULL, 'I'}, { "dir-item", 0, NULL, 'D'}, { "delete", 0, NULL, 'd'}, + { "root", 0, NULL, 'r'}, { NULL, 0, NULL, 0 } }; - c = getopt_long(ac, av, "l:c:b:eEkuUi:f:x:m:K:IDd", long_options, - &option_index); + c = getopt_long(ac, av, "l:c:b:eEkuUi:f:x:m:K:IDdr:", + long_options, &option_index); if (c < 0) break; switch(c) { @@ -1098,6 +1101,9 @@ int main(int ac, char **av) case 'd': delete = 1; break; + case 'r': + root_objectid = arg_strtou64(optarg); + break; default: print_usage(); } @@ -1206,9 +1212,25 @@ int main(int ac, char **av) ret = corrupt_btrfs_item(root, &key, field); } if (delete) { + struct btrfs_root *target = root; + if (!key.objectid) print_usage(); - ret = delete_item(root, &key); + if (root_objectid) { + struct btrfs_key root_key; + + root_key.objectid = root_objectid; + root_key.type = BTRFS_ROOT_ITEM_KEY; + root_key.offset = (u64)-1; + + target = btrfs_read_fs_root(root->fs_info, &root_key); + if (IS_ERR(target)) { + fprintf(stderr, "Couldn't find root %llu\n", + (unsigned long long)root_objectid); + print_usage(); + } + } + ret = delete_item(target, &key); goto out_close; } if (key.objectid || key.offset || key.type) {