From patchwork Fri Aug 3 09:48:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 1270131 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id E793B3FCFC for ; Fri, 3 Aug 2012 09:51:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752768Ab2HCJvc (ORCPT ); Fri, 3 Aug 2012 05:51:32 -0400 Received: from rcsinet15.oracle.com ([148.87.113.117]:46589 "EHLO rcsinet15.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752532Ab2HCJvb (ORCPT ); Fri, 3 Aug 2012 05:51:31 -0400 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by rcsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q739pTAK026320 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 Aug 2012 09:51:30 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q739pToc007663 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 3 Aug 2012 09:51:29 GMT Received: from abhmt119.oracle.com (abhmt119.oracle.com [141.146.116.71]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q739pTx2002257; Fri, 3 Aug 2012 04:51:29 -0500 Received: from localhost.localdomain (/10.186.101.18) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 03 Aug 2012 02:51:28 -0700 From: Anand jain To: linux-btrfs@vger.kernel.org Cc: Ilya Dryomov Subject: [PATCH 3/9] Btrfs-progs: refactor resolve_root() function a bit Date: Fri, 3 Aug 2012 17:48:52 +0800 Message-Id: <1343987338-10612-5-git-send-email-Anand.Jain@oracle.com> X-Mailer: git-send-email 1.7.7 In-Reply-To: <1343987338-10612-1-git-send-email-Anand.Jain@oracle.com> References: <1343822481-26707-1-git-send-email-Anand.Jain@oracle.com> <1343987338-10612-1-git-send-email-Anand.Jain@oracle.com> X-Source-IP: acsinet21.oracle.com [141.146.126.237] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Ilya Dryomov Don't pass a pointer to root_id to resolve_root(). It's always the same as ri->root_id, passing a pointer hints that root_id can somehow change which is not true. Signed-off-by: Ilya Dryomov --- btrfs-list.c | 21 ++++++++++----------- 1 files changed, 10 insertions(+), 11 deletions(-) diff --git a/btrfs-list.c b/btrfs-list.c index 680dd03..5c21cac 100644 --- a/btrfs-list.c +++ b/btrfs-list.c @@ -202,7 +202,7 @@ static int add_root(struct root_lookup *root_lookup, * in by lookup_ino_path */ static int resolve_root(struct root_lookup *rl, struct root_info *ri, - u64 *root_id, u64 *parent_id, u64 *top_id, char **path) + u64 *parent_id, u64 *top_id, char **path) { char *full_path = NULL; int len = 0; @@ -256,7 +256,6 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri, } } - *root_id = ri->root_id; *path = full_path; return 0; @@ -700,23 +699,23 @@ int list_subvols(int fd, int print_parent) n = rb_last(&root_lookup.root); while (n) { struct root_info *entry; - u64 root_id; u64 level; u64 parent_id; char *path; + entry = rb_entry(n, struct root_info, rb_node); - resolve_root(&root_lookup, entry, &root_id, &parent_id, - &level, &path); + resolve_root(&root_lookup, entry, &parent_id, &level, &path); if (print_parent) { printf("ID %llu parent %llu top level %llu path %s\n", - (unsigned long long)root_id, + (unsigned long long)entry->root_id, (unsigned long long)parent_id, (unsigned long long)level, path); } else { printf("ID %llu top level %llu path %s\n", - (unsigned long long)root_id, + (unsigned long long)entry->root_id, (unsigned long long)level, path); } + free(path); n = rb_prev(n); } @@ -922,17 +921,17 @@ char *path_for_root(int fd, u64 root) n = rb_last(&root_lookup.root); while (n) { struct root_info *entry; - u64 root_id; u64 parent_id; u64 level; char *path; + entry = rb_entry(n, struct root_info, rb_node); - resolve_root(&root_lookup, entry, &root_id, &parent_id, &level, - &path); - if (root_id == root) + resolve_root(&root_lookup, entry, &parent_id, &level, &path); + if (entry->root_id == root) ret_path = path; else free(path); + n = rb_prev(n); }