From patchwork Mon Mar 16 12:36:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 6017641 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4E2F99F399 for ; Mon, 16 Mar 2015 12:40:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6E7BF204D8 for ; Mon, 16 Mar 2015 12:40:51 +0000 (UTC) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 56E18204D1 for ; Mon, 16 Mar 2015 12:40:50 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id t2GCcGkm027934; Mon, 16 Mar 2015 08:38:17 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id t2GCbG9u028773 for ; Mon, 16 Mar 2015 08:37:16 -0400 Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2GCbGGi020894; Mon, 16 Mar 2015 08:37:16 -0400 Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2GCbCtR003080 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=FAIL); Mon, 16 Mar 2015 08:37:13 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 56A20ADC2; Mon, 16 Mar 2015 12:37:08 +0000 (UTC) From: Hannes Reinecke To: Christophe Varoqui Date: Mon, 16 Mar 2015 13:36:04 +0100 Message-Id: <1426509425-15978-18-git-send-email-hare@suse.de> In-Reply-To: <1426509425-15978-1-git-send-email-hare@suse.de> References: <1426509425-15978-1-git-send-email-hare@suse.de> X-RedHat-Spam-Score: -7.309 (BAYES_00, DCC_REPUT_00_12, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, URIBL_BLOCKED) 195.135.220.15 cantor2.suse.de 195.135.220.15 cantor2.suse.de X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.21 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH 17/78] Allow for empty path argument when printing information X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 When calling the various print functions we should be allowing for empty path argument. Signed-off-by: Hannes Reinecke --- libmultipath/print.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/libmultipath/print.c b/libmultipath/print.c index 130a9af..39b4f98 100644 --- a/libmultipath/print.c +++ b/libmultipath/print.c @@ -287,7 +287,7 @@ snprint_path_uuid (char * buff, size_t len, struct path * pp) static int snprint_hcil (char * buff, size_t len, struct path * pp) { - if (pp->sg_id.host_no < 0) + if (!pp || pp->sg_id.host_no < 0) return snprintf(buff, len, "#:#:#:#"); return snprintf(buff, len, "%i:%i:%i:%i", @@ -300,7 +300,7 @@ snprint_hcil (char * buff, size_t len, struct path * pp) static int snprint_dev (char * buff, size_t len, struct path * pp) { - if (!strlen(pp->dev)) + if (!pp || !strlen(pp->dev)) return snprintf(buff, len, "-"); else return snprint_str(buff, len, pp->dev); @@ -309,7 +309,7 @@ snprint_dev (char * buff, size_t len, struct path * pp) static int snprint_dev_t (char * buff, size_t len, struct path * pp) { - if (!strlen(pp->dev)) + if (!pp || !strlen(pp->dev)) return snprintf(buff, len, "#:#"); else return snprint_str(buff, len, pp->dev_t); @@ -318,8 +318,12 @@ snprint_dev_t (char * buff, size_t len, struct path * pp) static int snprint_offline (char * buff, size_t len, struct path * pp) { - if (pp->offline) + if (!pp) + return snprintf(buff, len, "unknown"); + else if (pp->offline) return snprintf(buff, len, "offline"); + else if (!pp->mpp) + return snprintf(buff, len, "orphan"); else return snprintf(buff, len, "running"); } @@ -327,6 +331,9 @@ snprint_offline (char * buff, size_t len, struct path * pp) static int snprint_chk_state (char * buff, size_t len, struct path * pp) { + if (!pp) + return snprintf(buff, len, "undef"); + switch (pp->state) { case PATH_UP: return snprintf(buff, len, "ready"); @@ -350,6 +357,9 @@ snprint_chk_state (char * buff, size_t len, struct path * pp) static int snprint_dm_path_state (char * buff, size_t len, struct path * pp) { + if (!pp) + return snprintf(buff, len, "undef"); + switch (pp->dmstate) { case PSTATE_ACTIVE: return snprintf(buff, len, "active"); @@ -370,7 +380,7 @@ snprint_vpr (char * buff, size_t len, struct path * pp) static int snprint_next_check (char * buff, size_t len, struct path * pp) { - if (!pp->mpp) + if (!pp || !pp->mpp) return snprintf(buff, len, "orphan"); return snprint_progress(buff, len, pp->tick, pp->checkint); @@ -379,7 +389,7 @@ snprint_next_check (char * buff, size_t len, struct path * pp) static int snprint_pri (char * buff, size_t len, struct path * pp) { - return snprint_int(buff, len, pp->priority); + return snprint_int(buff, len, pp ? pp->priority : -1); } static int