From patchwork Thu Jan 10 20:53:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 1962411 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by patchwork1.kernel.org (Postfix) with ESMTP id 436DC3FF0F for ; Thu, 10 Jan 2013 20:56:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r0AKrqcC017516; Thu, 10 Jan 2013 15:53:52 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r0AKrod4022352 for ; Thu, 10 Jan 2013 15:53:50 -0500 Received: from ether.msp.redhat.com (ether.msp.redhat.com [10.15.80.119]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0AKro9R006263 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 10 Jan 2013 15:53:50 -0500 Received: from ether.msp.redhat.com (localhost.localdomain [127.0.0.1]) by ether.msp.redhat.com (8.14.1/8.14.1) with ESMTP id r0AKrnH4027147; Thu, 10 Jan 2013 14:53:49 -0600 Received: (from bmarzins@localhost) by ether.msp.redhat.com (8.14.1/8.14.1/Submit) id r0AKrmpg027146; Thu, 10 Jan 2013 14:53:48 -0600 Date: Thu, 10 Jan 2013 14:53:47 -0600 From: Benjamin Marzinski To: device-mapper development Message-ID: <20130110205347.GY19059@ether.msp.redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.17 (2007-11-01) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-loop: dm-devel@redhat.com Cc: "Chauhan, Vijay" , Christophe Varoqui Subject: [dm-devel] [PATCH v2] multipath: make reservation_key print out correctly 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com This patch fixes the reservation_key print functions, so they print it out like it was in the configuration file. Also, it keeps cli_getprstatus() from writing over random memory. Signed-off-by: Benjamin Marzinski --- libmultipath/dict.c | 31 +++++++++++++++++++++++++++++-- multipathd/cli_handlers.c | 2 +- 2 files changed, 30 insertions(+), 3 deletions(-) -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel Index: multipath-tools-120821/libmultipath/dict.c =================================================================== --- multipath-tools-120821.orig/libmultipath/dict.c +++ multipath-tools-120821/libmultipath/dict.c @@ -2052,8 +2052,22 @@ snprint_mp_prio_args(char * buff, int le static int snprint_mp_reservation_key (char * buff, int len, void * data) { + int i; + unsigned char *keyp; + uint64_t prkey = 0; struct mpentry * mpe = (struct mpentry *)data; - return snprintf(buff, len, "%s" , mpe->reservation_key); + + if (!mpe->reservation_key) + return 0; + keyp = (unsigned char *)mpe->reservation_key; + for (i = 0; i < 8; i++) { + if (i > 0) + prkey <<= 8; + prkey |= *keyp; + keyp++; + } + + return snprintf(buff, len, "0x%" PRIx64, prkey); } static int @@ -2721,7 +2735,20 @@ snprint_def_wwids_file (char * buff, int static int snprint_def_reservation_key(char * buff, int len, void * data) { - return snprintf(buff, len, "%s", conf->reservation_key); + int i; + unsigned char *keyp; + uint64_t prkey = 0; + + if (!conf->reservation_key) + return 0; + keyp = (unsigned char *)conf->reservation_key; + for (i = 0; i < 8; i++) { + if (i > 0) + prkey <<= 8; + prkey |= *keyp; + keyp++; + } + return snprintf(buff, len, "0x%" PRIx64, prkey); } static int Index: multipath-tools-120821/multipathd/cli_handlers.c =================================================================== --- multipath-tools-120821.orig/multipathd/cli_handlers.c +++ multipath-tools-120821/multipathd/cli_handlers.c @@ -947,7 +947,7 @@ cli_getprstatus (void * v, char ** reply sprintf(*reply,"%d",mpp->prflag); - *reply[1]='\0'; + (*reply)[1]='\0'; condlog(3, "%s: reply = %s", param, *reply);