From patchwork Sat Dec 10 13:47:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasanth KSR X-Patchwork-Id: 9469337 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 62E76607F0 for ; Sat, 10 Dec 2016 13:48:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 545E22856A for ; Sat, 10 Dec 2016 13:48:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 494B4285A7; Sat, 10 Dec 2016 13:48:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCB5A2859E for ; Sat, 10 Dec 2016 13:48:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932179AbcLJNsX (ORCPT ); Sat, 10 Dec 2016 08:48:23 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:33601 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753382AbcLJNsU (ORCPT ); Sat, 10 Dec 2016 08:48:20 -0500 Received: by mail-pg0-f68.google.com with SMTP id 3so5387298pgd.0 for ; Sat, 10 Dec 2016 05:48:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZZ5Ep2XQYRiRgYdWE/sVWPXGKtDwGJ9vbV4w+X1mtPs=; b=Av04HDyoJRIQBA2nfyqnyopCxq9EXmHynG1NwunEQwKfU8pqJ8ctU48OOep2onp9m8 yMsS+YuGZrIBY149IZx3sFmlLNG87rJkVifIEPGinUxx6SPb+kR8aYCGcTjlt+XgaL82 eG1EbP+8outT4itLQKlL7VCi4VkcQKSJ2sXD/dE11R5OwUaB6alO8y0EnvR+SrexqG9y /4oIreaQoDY+2FfcKRm+BdDmmR4cz3247OmabufmxKuQGUhUJiTESANbPLuMr8mUTDA1 AVbLhSI7/k2p5olDzljpk6smEkiJUsAXWgoSYW/SYYkF3PUgFgLuXHxBS3ECbDitQ6FF E4UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZZ5Ep2XQYRiRgYdWE/sVWPXGKtDwGJ9vbV4w+X1mtPs=; b=M2BP6lCk7VZhzVyChpnOTjscjD5yua6yL51uF0xLbkIu+TokcosXJNOPV+muvXytR2 dqc3RkjCeZiza5Vg6Yk0ysEhky9f3Qu+XTklTNtqr88PIKhIlsX94T2FTkYqzUg5ky7d huX3p0RSQJWsboQt7yxjJbTsBjin+IoCh9EJPPT11k/hasQdmAp5pcpDhIxg9QNmdUI1 k8EZXp01NpJzhSGhRqxOrDNhPvIaUK2kGvtUVqElVJvA2xWVHpbjPI2Hu3P3mu2X+61l bjbuJyWV/EClaQwZh1In5paTkpow7MVOKL0FfieWIdBO5jQtL7OH3DNIxI0L7wwyHykw CEzw== X-Gm-Message-State: AKaTC03b50aaRLc1cR7VfLeKF/TSZv/Dpxb24njLjXGw5ZJCxIT41B0HP4Qd9kHgcE7P0w== X-Received: by 10.84.176.100 with SMTP id u91mr165572943plb.7.1481377700125; Sat, 10 Dec 2016 05:48:20 -0800 (PST) Received: from linux.local ([122.167.185.200]) by smtp.gmail.com with ESMTPSA id w17sm65166394pgm.18.2016.12.10.05.48.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Dec 2016 05:48:19 -0800 (PST) From: Prasanth K S R To: linux-btrfs@vger.kernel.org Cc: Prasanth K S R , dsterba@suse.com Subject: [PATCH 2/3] Btrfs-progs: subvol_uuid_search: Return error encoded pointer Date: Sat, 10 Dec 2016 19:17:43 +0530 Message-Id: <20161210134744.10825-2-kosigiprasanth@gmail.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161210134744.10825-1-kosigiprasanth@gmail.com> References: <20161210134744.10825-1-kosigiprasanth@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Prasanth K S R This commit changes subvol_uuid_search() to return an error encoded pointer on failure. Signed-off-by: Prasanth K S R --- cmds-receive.c | 10 +++++----- cmds-send.c | 19 +++++++++---------- send-utils.c | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/cmds-receive.c b/cmds-receive.c index 6f54c2e..cb42aa2 100644 --- a/cmds-receive.c +++ b/cmds-receive.c @@ -287,13 +287,13 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid, parent_subvol = subvol_uuid_search(&rctx->sus, 0, parent_uuid, parent_ctransid, NULL, subvol_search_by_received_uuid); - if (!parent_subvol) { + if (IS_ERR(parent_subvol)) { parent_subvol = subvol_uuid_search(&rctx->sus, 0, parent_uuid, parent_ctransid, NULL, subvol_search_by_uuid); } - if (!parent_subvol) { - ret = -ENOENT; + if (IS_ERR(parent_subvol)) { + ret = PTR_ERR(parent_subvol); error("cannot find parent subvolume"); goto out; } @@ -750,13 +750,13 @@ static int process_clone(const char *path, u64 offset, u64 len, si = subvol_uuid_search(&rctx->sus, 0, clone_uuid, clone_ctransid, NULL, subvol_search_by_received_uuid); - if (!si) { + if (IS_ERR(si)) { if (memcmp(clone_uuid, rctx->cur_subvol.received_uuid, BTRFS_UUID_SIZE) == 0) { /* TODO check generation of extent */ subvol_path = strdup(rctx->cur_subvol_path); } else { - ret = -ENOENT; + ret = PTR_ERR(si); error("clone: did not find source subvol"); goto out; } diff --git a/cmds-send.c b/cmds-send.c index a4fb126..5da64d8 100644 --- a/cmds-send.c +++ b/cmds-send.c @@ -70,8 +70,8 @@ static int get_root_id(struct btrfs_send *sctx, const char *path, u64 *root_id) si = subvol_uuid_search(&sctx->sus, 0, NULL, 0, path, subvol_search_by_path); - if (!si) - return -ENOENT; + if (IS_ERR(si)) + return PTR_ERR(si); *root_id = si->root_id; free(si->path); free(si); @@ -85,8 +85,8 @@ static struct subvol_info *get_parent(struct btrfs_send *sctx, u64 root_id) si_tmp = subvol_uuid_search(&sctx->sus, root_id, NULL, 0, NULL, subvol_search_by_root_id); - if (!si_tmp) - return NULL; + if (IS_ERR(si_tmp)) + return si_tmp; si = subvol_uuid_search(&sctx->sus, 0, si_tmp->parent_uuid, 0, NULL, subvol_search_by_uuid); @@ -105,8 +105,8 @@ static int find_good_parent(struct btrfs_send *sctx, u64 root_id, u64 *found) int i; parent = get_parent(sctx, root_id); - if (!parent) { - ret = -ENOENT; + if (IS_ERR(parent)) { + ret = PTR_ERR(parent); goto out; } @@ -122,7 +122,7 @@ static int find_good_parent(struct btrfs_send *sctx, u64 root_id, u64 *found) s64 tmp; parent2 = get_parent(sctx, sctx->clone_sources[i]); - if (!parent2) + if (IS_ERR(parent2)) continue; if (parent2->root_id != parent->root_id) { free(parent2->path); @@ -136,9 +136,8 @@ static int find_good_parent(struct btrfs_send *sctx, u64 root_id, u64 *found) parent2 = subvol_uuid_search(&sctx->sus, sctx->clone_sources[i], NULL, 0, NULL, subvol_search_by_root_id); - - if (!parent2) { - ret = -ENOENT; + if (IS_ERR(parent2)) { + ret = PTR_ERR(parent2); goto out; } tmp = parent2->ctransid - parent->ctransid; diff --git a/send-utils.c b/send-utils.c index 5026882..252ca6d 100644 --- a/send-utils.c +++ b/send-utils.c @@ -498,7 +498,7 @@ out: if (ret && info) { free(info->path); free(info); - info = NULL; + return ERR_PTR(ret); } return info;