From patchwork Fri Sep 21 23:05:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611175 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 715B3913 for ; Fri, 21 Sep 2018 23:05:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61B122D79D for ; Fri, 21 Sep 2018 23:05:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5609F2E0C3; Fri, 21 Sep 2018 23:05:41 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 033012E0C0 for ; Fri, 21 Sep 2018 23:05:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2327387629; Fri, 21 Sep 2018 23:05:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF2397F377; Fri, 21 Sep 2018 23:05:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 57E024BB75; Fri, 21 Sep 2018 23:05:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LN5ZC5027270 for ; Fri, 21 Sep 2018 19:05:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id BD2597E30B; Fri, 21 Sep 2018 23:05:35 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 7CFF37E30F; Fri, 21 Sep 2018 23:05:31 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:05:31 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:09 -0500 Message-Id: <1537571127-10143-2-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 01/19] libmultipath: fix tur checker timeout X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 21 Sep 2018 23:05:40 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP The code previously was timing out mode if ct->thread was 0 but ct->running wasn't. This combination never happens. The idea was to timeout if for some reason the path checker tried to kill the thread, but it didn't die. The correct thing to check for this is ct->holders. ct->holders will always be at least one when libcheck_check() is called, since libcheck_free() won't get called until the device is no longer being checked. So, if ct->holders is 2, that means that the tur thread is has not shut down yet. Also, instead of returning PATH_TIMEOUT whenever the thread hasn't died, it should only time out if the thread didn't successfully get a value, which means the previous state was already PATH_TIMEOUT. Signed-off-by: Benjamin Marzinski --- libmultipath/checkers/tur.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libmultipath/checkers/tur.c b/libmultipath/checkers/tur.c index bf8486d..275541f 100644 --- a/libmultipath/checkers/tur.c +++ b/libmultipath/checkers/tur.c @@ -355,12 +355,15 @@ int libcheck_check(struct checker * c) } pthread_mutex_unlock(&ct->lock); } else { - if (uatomic_read(&ct->running) != 0) { - /* pthread cancel failed. continue in sync mode */ - pthread_mutex_unlock(&ct->lock); - condlog(3, "%s: tur thread not responding", - tur_devt(devt, sizeof(devt), ct)); - return PATH_TIMEOUT; + if (uatomic_read(&ct->holders) > 1) { + /* pthread cancel failed. If it didn't get the path + state already, timeout */ + if (ct->state == PATH_PENDING) { + pthread_mutex_unlock(&ct->lock); + condlog(3, "%s: tur thread not responding", + tur_devt(devt, sizeof(devt), ct)); + return PATH_TIMEOUT; + } } /* Start new TUR checker */ ct->state = PATH_UNCHECKED; From patchwork Fri Sep 21 23:05:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611177 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DDDF31709 for ; Fri, 21 Sep 2018 23:05:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD1742D79D for ; Fri, 21 Sep 2018 23:05:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C15C42E0C0; Fri, 21 Sep 2018 23:05:43 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 429442D79D for ; Fri, 21 Sep 2018 23:05:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F23F73091D65; Fri, 21 Sep 2018 23:05:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CBFBC7E313; Fri, 21 Sep 2018 23:05:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 54A524A463; Fri, 21 Sep 2018 23:05:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.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 w8LN5dhE027280 for ; Fri, 21 Sep 2018 19:05:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id A13B42010D97; Fri, 21 Sep 2018 23:05:39 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 1FFAB2010D7B; Fri, 21 Sep 2018 23:05:36 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:05:35 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:10 -0500 Message-Id: <1537571127-10143-3-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: dm-devel@redhat.com Cc: Bart Van Assche , Martin Wilck Subject: [dm-devel] [PATCH v3 02/19] libmultipath: fix tur checker double locking X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 21 Sep 2018 23:05:42 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP tur_devt() locks ct->lock. However, it is ocassionally called while ct->lock is already locked. In reality, there is no reason why we need to lock all the accesses to ct->devt. The tur checker only needs to write to this variable one time, when it first gets the file descripter that it is checking. It also never uses ct->devt directly. Instead, it always graps the major and minor, and turns them into a string. This patch changes ct->devt into that string, and sets it in libcheck_init() when it is first initializing the checker context. After that, ct->devt is only ever read. Cc: Bart Van Assche Signed-off-by: Benjamin Marzinski --- libmultipath/checkers/tur.c | 55 +++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/libmultipath/checkers/tur.c b/libmultipath/checkers/tur.c index 275541f..d173648 100644 --- a/libmultipath/checkers/tur.c +++ b/libmultipath/checkers/tur.c @@ -37,36 +37,24 @@ #define MSG_TUR_FAILED "tur checker failed to initialize" struct tur_checker_context { - dev_t devt; + char devt[32]; int state; - int running; + int running; /* uatomic access only */ int fd; unsigned int timeout; time_t time; pthread_t thread; pthread_mutex_t lock; pthread_cond_t active; - int holders; + int holders; /* uatomic access only */ char message[CHECKER_MSG_LEN]; }; -static const char *tur_devt(char *devt_buf, int size, - struct tur_checker_context *ct) -{ - dev_t devt; - - pthread_mutex_lock(&ct->lock); - devt = ct->devt; - pthread_mutex_unlock(&ct->lock); - - snprintf(devt_buf, size, "%d:%d", major(devt), minor(devt)); - return devt_buf; -} - int libcheck_init (struct checker * c) { struct tur_checker_context *ct; pthread_mutexattr_t attr; + struct stat sb; ct = malloc(sizeof(struct tur_checker_context)); if (!ct) @@ -81,6 +69,9 @@ int libcheck_init (struct checker * c) pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&ct->lock, &attr); pthread_mutexattr_destroy(&attr); + if (fstat(c->fd, &sb) == 0) + snprintf(ct->devt, sizeof(ct->devt), "%d:%d", major(sb.st_rdev), + minor(sb.st_rdev)); c->context = ct; return 0; @@ -232,14 +223,12 @@ static void *tur_thread(void *ctx) { struct tur_checker_context *ct = ctx; int state, running; - char devt[32]; /* This thread can be canceled, so setup clean up */ tur_thread_cleanup_push(ct); rcu_register_thread(); - condlog(3, "%s: tur checker starting up", - tur_devt(devt, sizeof(devt), ct)); + condlog(3, "%s: tur checker starting up", ct->devt); /* TUR checker start up */ pthread_mutex_lock(&ct->lock); @@ -256,8 +245,8 @@ static void *tur_thread(void *ctx) pthread_cond_signal(&ct->active); pthread_mutex_unlock(&ct->lock); - condlog(3, "%s: tur checker finished, state %s", - tur_devt(devt, sizeof(devt), ct), checker_state_name(state)); + condlog(3, "%s: tur checker finished, state %s", ct->devt, + checker_state_name(state)); running = uatomic_xchg(&ct->running, 0); if (!running) @@ -305,20 +294,12 @@ int libcheck_check(struct checker * c) { struct tur_checker_context *ct = c->context; struct timespec tsp; - struct stat sb; pthread_attr_t attr; int tur_status, r; - char devt[32]; if (!ct) return PATH_UNCHECKED; - if (fstat(c->fd, &sb) == 0) { - pthread_mutex_lock(&ct->lock); - ct->devt = sb.st_rdev; - pthread_mutex_unlock(&ct->lock); - } - if (c->sync) return tur_check(c->fd, c->timeout, copy_msg_to_checker, c); @@ -327,8 +308,7 @@ int libcheck_check(struct checker * c) */ r = pthread_mutex_lock(&ct->lock); if (r != 0) { - condlog(2, "%s: tur mutex lock failed with %d", - tur_devt(devt, sizeof(devt), ct), r); + condlog(2, "%s: tur mutex lock failed with %d", ct->devt, r); MSG(c, MSG_TUR_FAILED); return PATH_WILD; } @@ -338,14 +318,12 @@ int libcheck_check(struct checker * c) int running = uatomic_xchg(&ct->running, 0); if (running) pthread_cancel(ct->thread); - condlog(3, "%s: tur checker timeout", - tur_devt(devt, sizeof(devt), ct)); + condlog(3, "%s: tur checker timeout", ct->devt); ct->thread = 0; MSG(c, MSG_TUR_TIMEOUT); tur_status = PATH_TIMEOUT; } else if (uatomic_read(&ct->running) != 0) { - condlog(3, "%s: tur checker not finished", - tur_devt(devt, sizeof(devt), ct)); + condlog(3, "%s: tur checker not finished", ct->devt); tur_status = PATH_PENDING; } else { /* TUR checker done */ @@ -361,7 +339,7 @@ int libcheck_check(struct checker * c) if (ct->state == PATH_PENDING) { pthread_mutex_unlock(&ct->lock); condlog(3, "%s: tur thread not responding", - tur_devt(devt, sizeof(devt), ct)); + ct->devt); return PATH_TIMEOUT; } } @@ -381,7 +359,7 @@ int libcheck_check(struct checker * c) ct->thread = 0; pthread_mutex_unlock(&ct->lock); condlog(3, "%s: failed to start tur thread, using" - " sync mode", tur_devt(devt, sizeof(devt), ct)); + " sync mode", ct->devt); return tur_check(c->fd, c->timeout, copy_msg_to_checker, c); } @@ -392,8 +370,7 @@ int libcheck_check(struct checker * c) pthread_mutex_unlock(&ct->lock); if (uatomic_read(&ct->running) != 0 && (tur_status == PATH_PENDING || tur_status == PATH_UNCHECKED)) { - condlog(3, "%s: tur checker still running", - tur_devt(devt, sizeof(devt), ct)); + condlog(3, "%s: tur checker still running", ct->devt); tur_status = PATH_PENDING; } else { int running = uatomic_xchg(&ct->running, 0); From patchwork Fri Sep 21 23:05:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611179 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6B97D1709 for ; Fri, 21 Sep 2018 23:05:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 591622D79D for ; Fri, 21 Sep 2018 23:05:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BDB92E0C0; Fri, 21 Sep 2018 23:05:48 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BEC1D2D79D for ; Fri, 21 Sep 2018 23:05:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA9FA3003078; Fri, 21 Sep 2018 23:05:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 91B437F36B; Fri, 21 Sep 2018 23:05:46 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 50748181A12E; Fri, 21 Sep 2018 23:05:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LN5iMi027297 for ; Fri, 21 Sep 2018 19:05:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id C26F018A74; Fri, 21 Sep 2018 23:05:44 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 8277860F87; Fri, 21 Sep 2018 23:05:40 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:05:39 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:11 -0500 Message-Id: <1537571127-10143-4-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 03/19] libmultipath: fix tur memory misuse X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 21 Sep 2018 23:05:47 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP when tur_thread() was calling tur_check(), it was passing ct->message as the copy argument, but copy_msg_to_tcc() was assuming that it was getting a tur_checker_context pointer. This means it was treating ct->message as ct. This is why the tur checker never printed checker messages. Intead of simply changing the copy argument passed in, I just removed all the copying code, since it is completely unnecessary. The callers of tur_check() can just pass in a buffer that it is safe to write to, and copy it later, if necessary. Signed-off-by: Benjamin Marzinski --- libmultipath/checkers/tur.c | 46 +++++++++++---------------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/libmultipath/checkers/tur.c b/libmultipath/checkers/tur.c index d173648..abda162 100644 --- a/libmultipath/checkers/tur.c +++ b/libmultipath/checkers/tur.c @@ -103,17 +103,8 @@ void libcheck_free (struct checker * c) return; } -#define TUR_MSG(fmt, args...) \ - do { \ - char msg[CHECKER_MSG_LEN]; \ - \ - snprintf(msg, sizeof(msg), fmt, ##args); \ - copy_message(cb_arg, msg); \ - } while (0) - static int -tur_check(int fd, unsigned int timeout, - void (*copy_message)(void *, const char *), void *cb_arg) +tur_check(int fd, unsigned int timeout, char *msg) { struct sg_io_hdr io_hdr; unsigned char turCmdBlk[TUR_CMD_LEN] = { 0x00, 0, 0, 0, 0, 0 }; @@ -132,7 +123,7 @@ retry: io_hdr.timeout = timeout * 1000; io_hdr.pack_id = 0; if (ioctl(fd, SG_IO, &io_hdr) < 0) { - TUR_MSG(MSG_TUR_DOWN); + snprintf(msg, CHECKER_MSG_LEN, MSG_TUR_DOWN); return PATH_DOWN; } if ((io_hdr.status & 0x7e) == 0x18) { @@ -140,7 +131,7 @@ retry: * SCSI-3 arrays might return * reservation conflict on TUR */ - TUR_MSG(MSG_TUR_UP); + snprintf(msg, CHECKER_MSG_LEN, MSG_TUR_UP); return PATH_UP; } if (io_hdr.info & SG_INFO_OK_MASK) { @@ -185,14 +176,14 @@ retry: * LOGICAL UNIT NOT ACCESSIBLE, * TARGET PORT IN STANDBY STATE */ - TUR_MSG(MSG_TUR_GHOST); + snprintf(msg, CHECKER_MSG_LEN, MSG_TUR_GHOST); return PATH_GHOST; } } - TUR_MSG(MSG_TUR_DOWN); + snprintf(msg, CHECKER_MSG_LEN, MSG_TUR_DOWN); return PATH_DOWN; } - TUR_MSG(MSG_TUR_UP); + snprintf(msg, CHECKER_MSG_LEN, MSG_TUR_UP); return PATH_UP; } @@ -210,19 +201,11 @@ static void cleanup_func(void *data) rcu_unregister_thread(); } -static void copy_msg_to_tcc(void *ct_p, const char *msg) -{ - struct tur_checker_context *ct = ct_p; - - pthread_mutex_lock(&ct->lock); - strlcpy(ct->message, msg, sizeof(ct->message)); - pthread_mutex_unlock(&ct->lock); -} - static void *tur_thread(void *ctx) { struct tur_checker_context *ct = ctx; int state, running; + char msg[CHECKER_MSG_LEN]; /* This thread can be canceled, so setup clean up */ tur_thread_cleanup_push(ct); @@ -236,12 +219,13 @@ static void *tur_thread(void *ctx) ct->message[0] = '\0'; pthread_mutex_unlock(&ct->lock); - state = tur_check(ct->fd, ct->timeout, copy_msg_to_tcc, ct->message); + state = tur_check(ct->fd, ct->timeout, msg); pthread_testcancel(); /* TUR checker done */ pthread_mutex_lock(&ct->lock); ct->state = state; + strlcpy(ct->message, msg, sizeof(ct->message)); pthread_cond_signal(&ct->active); pthread_mutex_unlock(&ct->lock); @@ -283,13 +267,6 @@ static int tur_check_async_timeout(struct checker *c) return (now.tv_sec > ct->time); } -static void copy_msg_to_checker(void *c_p, const char *msg) -{ - struct checker *c = c_p; - - strlcpy(c->message, msg, sizeof(c->message)); -} - int libcheck_check(struct checker * c) { struct tur_checker_context *ct = c->context; @@ -301,7 +278,7 @@ int libcheck_check(struct checker * c) return PATH_UNCHECKED; if (c->sync) - return tur_check(c->fd, c->timeout, copy_msg_to_checker, c); + return tur_check(c->fd, c->timeout, c->message); /* * Async mode @@ -360,8 +337,7 @@ int libcheck_check(struct checker * c) pthread_mutex_unlock(&ct->lock); condlog(3, "%s: failed to start tur thread, using" " sync mode", ct->devt); - return tur_check(c->fd, c->timeout, - copy_msg_to_checker, c); + return tur_check(c->fd, c->timeout, c->message); } tur_timeout(&tsp); r = pthread_cond_timedwait(&ct->active, &ct->lock, &tsp); From patchwork Fri Sep 21 23:05:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611181 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 617E7913 for ; Fri, 21 Sep 2018 23:05:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 518B52D79D for ; Fri, 21 Sep 2018 23:05:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 455B72E0C0; Fri, 21 Sep 2018 23:05: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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C57582D79D for ; Fri, 21 Sep 2018 23:05:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E90F232B69C; Fri, 21 Sep 2018 23:05:50 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B84EE83BFC; Fri, 21 Sep 2018 23:05:50 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7DBB5181A12E; Fri, 21 Sep 2018 23:05:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.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 w8LN5meZ027307 for ; Fri, 21 Sep 2018 19:05:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id DADB716D35; Fri, 21 Sep 2018 23:05:48 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 97DE76963D; Fri, 21 Sep 2018 23:05:45 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:05:44 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:12 -0500 Message-Id: <1537571127-10143-5-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 04/19] libmultipath: cleanup tur locking X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 21 Sep 2018 23:05:51 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP There are only three variables whose access needs to be synchronized between the tur thread and the path checker itself: state, message, and active. The rest of the variables are either only written when the tur thread isn't running, or they aren't accessed by the tur thread, or they are atomics that are themselves used to synchronize things. This patch limits the amount of code that is covered by ct->lock to only what needs to be locked. It also makes ct->lock no longer a recursive lock. To make this simpler, tur_thread now only sets the state and message one time, instead of twice, since PATH_UNCHECKED was never able to be returned anyway. One benefit of this is that the tur checker thread gets more time to call tur_check() and return before libcheck_check() gives up and return PATH_PENDING. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/checkers/tur.c | 49 ++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/libmultipath/checkers/tur.c b/libmultipath/checkers/tur.c index abda162..9f6ef51 100644 --- a/libmultipath/checkers/tur.c +++ b/libmultipath/checkers/tur.c @@ -53,7 +53,6 @@ struct tur_checker_context { int libcheck_init (struct checker * c) { struct tur_checker_context *ct; - pthread_mutexattr_t attr; struct stat sb; ct = malloc(sizeof(struct tur_checker_context)); @@ -65,10 +64,7 @@ int libcheck_init (struct checker * c) ct->fd = -1; uatomic_set(&ct->holders, 1); pthread_cond_init_mono(&ct->active); - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&ct->lock, &attr); - pthread_mutexattr_destroy(&attr); + pthread_mutex_init(&ct->lock, NULL); if (fstat(c->fd, &sb) == 0) snprintf(ct->devt, sizeof(ct->devt), "%d:%d", major(sb.st_rdev), minor(sb.st_rdev)); @@ -213,12 +209,6 @@ static void *tur_thread(void *ctx) condlog(3, "%s: tur checker starting up", ct->devt); - /* TUR checker start up */ - pthread_mutex_lock(&ct->lock); - ct->state = PATH_PENDING; - ct->message[0] = '\0'; - pthread_mutex_unlock(&ct->lock); - state = tur_check(ct->fd, ct->timeout, msg); pthread_testcancel(); @@ -283,13 +273,6 @@ int libcheck_check(struct checker * c) /* * Async mode */ - r = pthread_mutex_lock(&ct->lock); - if (r != 0) { - condlog(2, "%s: tur mutex lock failed with %d", ct->devt, r); - MSG(c, MSG_TUR_FAILED); - return PATH_WILD; - } - if (ct->thread) { if (tur_check_async_timeout(c)) { int running = uatomic_xchg(&ct->running, 0); @@ -305,23 +288,29 @@ int libcheck_check(struct checker * c) } else { /* TUR checker done */ ct->thread = 0; + pthread_mutex_lock(&ct->lock); tur_status = ct->state; strlcpy(c->message, ct->message, sizeof(c->message)); + pthread_mutex_unlock(&ct->lock); } - pthread_mutex_unlock(&ct->lock); } else { if (uatomic_read(&ct->holders) > 1) { /* pthread cancel failed. If it didn't get the path state already, timeout */ - if (ct->state == PATH_PENDING) { - pthread_mutex_unlock(&ct->lock); + pthread_mutex_lock(&ct->lock); + tur_status = ct->state; + pthread_mutex_unlock(&ct->lock); + if (tur_status == PATH_PENDING) { condlog(3, "%s: tur thread not responding", ct->devt); return PATH_TIMEOUT; } } /* Start new TUR checker */ - ct->state = PATH_UNCHECKED; + pthread_mutex_lock(&ct->lock); + tur_status = ct->state = PATH_PENDING; + ct->message[0] = '\0'; + pthread_mutex_unlock(&ct->lock); ct->fd = c->fd; ct->timeout = c->timeout; uatomic_add(&ct->holders, 1); @@ -334,20 +323,22 @@ int libcheck_check(struct checker * c) uatomic_sub(&ct->holders, 1); uatomic_set(&ct->running, 0); ct->thread = 0; - pthread_mutex_unlock(&ct->lock); condlog(3, "%s: failed to start tur thread, using" " sync mode", ct->devt); return tur_check(c->fd, c->timeout, c->message); } tur_timeout(&tsp); - r = pthread_cond_timedwait(&ct->active, &ct->lock, &tsp); - tur_status = ct->state; - strlcpy(c->message, ct->message, sizeof(c->message)); + pthread_mutex_lock(&ct->lock); + if (ct->state == PATH_PENDING) + r = pthread_cond_timedwait(&ct->active, &ct->lock, + &tsp); + if (!r) { + tur_status = ct->state; + strlcpy(c->message, ct->message, sizeof(c->message)); + } pthread_mutex_unlock(&ct->lock); - if (uatomic_read(&ct->running) != 0 && - (tur_status == PATH_PENDING || tur_status == PATH_UNCHECKED)) { + if (tur_status == PATH_PENDING) { condlog(3, "%s: tur checker still running", ct->devt); - tur_status = PATH_PENDING; } else { int running = uatomic_xchg(&ct->running, 0); if (running) From patchwork Fri Sep 21 23:05:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611183 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 35DD31709 for ; Fri, 21 Sep 2018 23:05:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 253EA2D79D for ; Fri, 21 Sep 2018 23:05:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 193672E0C0; Fri, 21 Sep 2018 23:05:55 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C0A5B2D79D for ; Fri, 21 Sep 2018 23:05:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D2800307D942; Fri, 21 Sep 2018 23:05:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A344F308BDAE; Fri, 21 Sep 2018 23:05:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6DBC84A460; Fri, 21 Sep 2018 23:05:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LN5oZE027315 for ; Fri, 21 Sep 2018 19:05:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8F3CD7E310; Fri, 21 Sep 2018 23:05:50 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 4D3C37E312; Fri, 21 Sep 2018 23:05:49 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:05:48 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:13 -0500 Message-Id: <1537571127-10143-6-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 05/19] libmultipath: fix tur checker timeout issue X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 21 Sep 2018 23:05:54 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP If the tur checker is run, and the tur_thread has timed out, libcheck_check() doesn't actually check if the thread is still running. This means that the thread could have already completed successfully, but the tur checker would still return PATH_TIMEOUT, instead of the value returned by the thread. This patch makes libcheck_check() actually check if the thread completed, and if so, it returns the proper value. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/checkers/tur.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libmultipath/checkers/tur.c b/libmultipath/checkers/tur.c index 9f6ef51..4e2c7a8 100644 --- a/libmultipath/checkers/tur.c +++ b/libmultipath/checkers/tur.c @@ -276,12 +276,19 @@ int libcheck_check(struct checker * c) if (ct->thread) { if (tur_check_async_timeout(c)) { int running = uatomic_xchg(&ct->running, 0); - if (running) + if (running) { pthread_cancel(ct->thread); - condlog(3, "%s: tur checker timeout", ct->devt); + condlog(3, "%s: tur checker timeout", ct->devt); + MSG(c, MSG_TUR_TIMEOUT); + tur_status = PATH_TIMEOUT; + } else { + pthread_mutex_lock(&ct->lock); + tur_status = ct->state; + strlcpy(c->message, ct->message, + sizeof(c->message)); + pthread_mutex_unlock(&ct->lock); + } ct->thread = 0; - MSG(c, MSG_TUR_TIMEOUT); - tur_status = PATH_TIMEOUT; } else if (uatomic_read(&ct->running) != 0) { condlog(3, "%s: tur checker not finished", ct->devt); tur_status = PATH_PENDING; From patchwork Fri Sep 21 23:05:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611185 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9894B1709 for ; Fri, 21 Sep 2018 23:05:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88FC02D79D for ; Fri, 21 Sep 2018 23:05:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D94C2E0C0; Fri, 21 Sep 2018 23:05:57 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 425EE2D79D for ; Fri, 21 Sep 2018 23:05:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3AB68804F2; Fri, 21 Sep 2018 23:05:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0B5D0308BE75; Fri, 21 Sep 2018 23:05:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C17A84A463; Fri, 21 Sep 2018 23:05:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LN5srY027331 for ; Fri, 21 Sep 2018 19:05:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id DF8CA2AA9D; Fri, 21 Sep 2018 23:05:54 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id A080989E42; Fri, 21 Sep 2018 23:05:50 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:05:50 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:14 -0500 Message-Id: <1537571127-10143-7-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 06/19] libmultipath: fix set_int error path X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 21 Sep 2018 23:05:56 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP set_int() wasn't checking if the line actually had a value before converting it to an integer. Found by coverity. Also, it should be using set_value(). Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/dict.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libmultipath/dict.c b/libmultipath/dict.c index 32524d5..bf4701e 100644 --- a/libmultipath/dict.c +++ b/libmultipath/dict.c @@ -33,7 +33,10 @@ set_int(vector strvec, void *ptr) int *int_ptr = (int *)ptr; char * buff; - buff = VECTOR_SLOT(strvec, 1); + buff = set_value(strvec); + if (!buff) + return 1; + *int_ptr = atoi(buff); return 0; From patchwork Fri Sep 21 23:05:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611187 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17451913 for ; Fri, 21 Sep 2018 23:06:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 081AF2D79D for ; Fri, 21 Sep 2018 23:06:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0CBC2E0C0; Fri, 21 Sep 2018 23:06:01 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9C1212D79D for ; Fri, 21 Sep 2018 23:06:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7524D3C26; Fri, 21 Sep 2018 23:06:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4F7EB2010D78; Fri, 21 Sep 2018 23:06:00 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1394E4A465; Fri, 21 Sep 2018 23:06:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LN5xic027341 for ; Fri, 21 Sep 2018 19:05:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0A825309137F; Fri, 21 Sep 2018 23:05:59 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id BBCEC3091391; Fri, 21 Sep 2018 23:05:55 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:05:54 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:15 -0500 Message-Id: <1537571127-10143-8-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 07/19] libmultipath: fix length issues in get_vpd_sgio X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 21 Sep 2018 23:06:00 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP When get_vpd_sgio() finds out that the vpd info needed to be truncated to fit in the buffer, it doesn't trucate the size as well, which allows it to overwrite the buffer. Also, in once len is set to -ENODATA, get_vpd_sgio() should exit, instead of using the negative len in memcpy(). Found by coverity. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/discovery.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 0b1855d..3e0db7f 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1116,17 +1116,21 @@ get_vpd_sgio (int fd, int pg, char * str, int maxlen) return -ENODATA; } buff_len = get_unaligned_be16(&buff[2]) + 4; - if (buff_len > 4096) + if (buff_len > 4096) { condlog(3, "vpd pg%02x page truncated", pg); - + buff_len = 4096; + } if (pg == 0x80) len = parse_vpd_pg80(buff, str, maxlen); else if (pg == 0x83) len = parse_vpd_pg83(buff, buff_len, str, maxlen); else if (pg == 0xc9 && maxlen >= 8) { - len = buff_len < 8 ? -ENODATA : - (buff_len <= maxlen ? buff_len : maxlen); - memcpy (str, buff, len); + if (buff_len < 8) + len = -ENODATA; + else { + len = (buff_len <= maxlen)? buff_len : maxlen; + memcpy (str, buff, len); + } } else len = -ENOSYS; From patchwork Fri Sep 21 23:05:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611189 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD5711709 for ; Fri, 21 Sep 2018 23:06:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E3602E09C for ; Fri, 21 Sep 2018 23:06:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 92C2A2E0C3; Fri, 21 Sep 2018 23:06:06 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 566CA2E09C for ; Fri, 21 Sep 2018 23:06:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 842C13091D6F; Fri, 21 Sep 2018 23:06:05 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 56FA718B0B; Fri, 21 Sep 2018 23:06:05 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1EAD0181A13A; Fri, 21 Sep 2018 23:06:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LN63LP027351 for ; Fri, 21 Sep 2018 19:06:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id A04087E30A; Fri, 21 Sep 2018 23:06:03 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 5FDE97E31E; Fri, 21 Sep 2018 23:05:59 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:05:59 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:16 -0500 Message-Id: <1537571127-10143-9-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 08/19] libmultipath: _install_keyword cleanup X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 21 Sep 2018 23:06:05 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP _install_keyword should use VECTOR_LAST_SLOT(), which has better error checking. It should also fail if it gets a NULL pointer, instead of dereferencing it. Found by coverity. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/parser.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libmultipath/parser.c b/libmultipath/parser.c index b8b7e0d..92ef7cf 100644 --- a/libmultipath/parser.c +++ b/libmultipath/parser.c @@ -79,12 +79,16 @@ _install_keyword(vector keywords, char *string, struct keyword *keyword; /* fetch last keyword */ - keyword = VECTOR_SLOT(keywords, VECTOR_SIZE(keywords) - 1); + keyword = VECTOR_LAST_SLOT(keywords); + if (!keyword) + return 1; /* position to last sub level */ - for (i = 0; i < sublevel; i++) - keyword = - VECTOR_SLOT(keyword->sub, VECTOR_SIZE(keyword->sub) - 1); + for (i = 0; i < sublevel; i++) { + keyword = VECTOR_LAST_SLOT(keyword->sub); + if (!keyword) + return 1; + } /* First sub level allocation */ if (!keyword->sub) From patchwork Fri Sep 21 23:05:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611191 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E412913 for ; Fri, 21 Sep 2018 23:06:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D87B2D79D for ; Fri, 21 Sep 2018 23:06:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31DA62E0C0; Fri, 21 Sep 2018 23:06:10 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D80802D79D for ; Fri, 21 Sep 2018 23:06:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EDD80301A3BE; Fri, 21 Sep 2018 23:06:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBF5D825EE; Fri, 21 Sep 2018 23:06:08 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 52842181A13B; Fri, 21 Sep 2018 23:06:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.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 w8LN67Bi027362 for ; Fri, 21 Sep 2018 19:06:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 351172010D7B; Fri, 21 Sep 2018 23:06:07 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id E74532010CF7; Fri, 21 Sep 2018 23:06:04 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:06:03 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:17 -0500 Message-Id: <1537571127-10143-10-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 09/19] libmultipath: remove unused code X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 21 Sep 2018 23:06:09 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP since vector_foreach_slot() already checks if the entry is NULL, there's no point in checking it in the loop, since it can't be NULL there. Found by coverity. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/print.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/libmultipath/print.c b/libmultipath/print.c index 9da6a77..7b610b9 100644 --- a/libmultipath/print.c +++ b/libmultipath/print.c @@ -275,8 +275,6 @@ snprint_multipath_vpr (char * buff, size_t len, const struct multipath * mpp) int i, j; vector_foreach_slot(mpp->pg, pgp, i) { - if (!pgp) - continue; vector_foreach_slot(pgp->paths, pp, j) { if (strlen(pp->vendor_id) && strlen(pp->product_id)) return snprintf(buff, len, "%s,%s", @@ -295,8 +293,6 @@ snprint_multipath_vend (char * buff, size_t len, const struct multipath * mpp) int i, j; vector_foreach_slot(mpp->pg, pgp, i) { - if (!pgp) - continue; vector_foreach_slot(pgp->paths, pp, j) { if (strlen(pp->vendor_id)) return snprintf(buff, len, "%s", pp->vendor_id); @@ -313,8 +309,6 @@ snprint_multipath_prod (char * buff, size_t len, const struct multipath * mpp) int i, j; vector_foreach_slot(mpp->pg, pgp, i) { - if (!pgp) - continue; vector_foreach_slot(pgp->paths, pp, j) { if (strlen(pp->product_id)) return snprintf(buff, len, "%s", pp->product_id); @@ -331,8 +325,6 @@ snprint_multipath_rev (char * buff, size_t len, const struct multipath * mpp) int i, j; vector_foreach_slot(mpp->pg, pgp, i) { - if (!pgp) - continue; vector_foreach_slot(pgp->paths, pp, j) { if (strlen(pp->rev)) return snprintf(buff, len, "%s", pp->rev); From patchwork Fri Sep 21 23:05:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611193 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 06E6B913 for ; Fri, 21 Sep 2018 23:06:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBDC32D79D for ; Fri, 21 Sep 2018 23:06:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0A6B2E0C0; Fri, 21 Sep 2018 23:06:12 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A507A2D79D for ; Fri, 21 Sep 2018 23:06:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D12EF87629; Fri, 21 Sep 2018 23:06:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A306D7F372; Fri, 21 Sep 2018 23:06:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 697A5181A13C; Fri, 21 Sep 2018 23:06:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LN689c027370 for ; Fri, 21 Sep 2018 19:06:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id D8AC13091390; Fri, 21 Sep 2018 23:06:08 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 97016309137F; Fri, 21 Sep 2018 23:06:07 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:06:07 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:18 -0500 Message-Id: <1537571127-10143-11-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 10/19] libmultipath: fix memory issue in path_latency prio X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 21 Sep 2018 23:06:12 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP The path_latency prioriziter was assuming that prepare_directio_read() always succeeds. However, it doesn't, and when it fails, the prioritizer used buf without it pointing to alloced memory. Found by coverity. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/prioritizers/path_latency.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libmultipath/prioritizers/path_latency.c b/libmultipath/prioritizers/path_latency.c index 765265c..eeee01e 100644 --- a/libmultipath/prioritizers/path_latency.c +++ b/libmultipath/prioritizers/path_latency.c @@ -237,7 +237,8 @@ int getprio(struct path *pp, char *args, unsigned int timeout) lg_maxavglatency = log(MAX_AVG_LATENCY) / lg_base; lg_minavglatency = log(MIN_AVG_LATENCY) / lg_base; - prepare_directio_read(pp->fd, &blksize, &buf, &restore_flags); + if (prepare_directio_read(pp->fd, &blksize, &buf, &restore_flags) < 0) + return PRIO_UNDEF; temp = io_num; while (temp-- > 0) { From patchwork Fri Sep 21 23:05:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611195 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CC0561709 for ; Fri, 21 Sep 2018 23:06:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA90F2D79D for ; Fri, 21 Sep 2018 23:06:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD4C12E0C0; Fri, 21 Sep 2018 23:06:16 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AAE912D79D for ; Fri, 21 Sep 2018 23:06:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D3182308125E; Fri, 21 Sep 2018 23:06:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A4B5D881E7; Fri, 21 Sep 2018 23:06:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 59C824A469; Fri, 21 Sep 2018 23:06:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.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 w8LN6CQe027382 for ; Fri, 21 Sep 2018 19:06:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id D085E171CD; Fri, 21 Sep 2018 23:06:12 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 8EB36171D6; Fri, 21 Sep 2018 23:06:09 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:06:08 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:19 -0500 Message-Id: <1537571127-10143-12-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 11/19] libmultipath: fix null dereference int alloc_path_group X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 21 Sep 2018 23:06:15 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP If all_pathgroup failed to allocate a vector for pgp->paths, instead of failing after it freed pgp, it would set pgp to NULL and then dereference it. This patch fixes that. Found by coverity. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/structs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmultipath/structs.c b/libmultipath/structs.c index ae847d6..caa178a 100644 --- a/libmultipath/structs.c +++ b/libmultipath/structs.c @@ -165,7 +165,7 @@ alloc_pathgroup (void) if (!pgp->paths) { FREE(pgp); - pgp = NULL; + return NULL; } dm_pathgroup_to_gen(pgp)->ops = &dm_gen_pathgroup_ops; From patchwork Fri Sep 21 23:05:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611197 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 74C6D1709 for ; Fri, 21 Sep 2018 23:06:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6651A2D79D for ; Fri, 21 Sep 2018 23:06:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AB202E0C0; Fri, 21 Sep 2018 23:06:20 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 21C222D79D for ; Fri, 21 Sep 2018 23:06:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4CE7B8046D; Fri, 21 Sep 2018 23:06:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 21A33171CD; Fri, 21 Sep 2018 23:06:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E18DB4A469; Fri, 21 Sep 2018 23:06:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LN6HEP027396 for ; Fri, 21 Sep 2018 19:06:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7828D825E3; Fri, 21 Sep 2018 23:06:17 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 394AD80A4C; Fri, 21 Sep 2018 23:06:13 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:06:12 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:20 -0500 Message-Id: <1537571127-10143-13-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 12/19] libmutipath: don't use malformed uevents X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 21 Sep 2018 23:06:19 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP A uevent that doesn't include the ACTION and DEVPATH fields is malformed. It should be ignored, instead of used with those fields being NULL. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/uevent.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libmultipath/uevent.c b/libmultipath/uevent.c index fd8ca35..5f910e6 100644 --- a/libmultipath/uevent.c +++ b/libmultipath/uevent.c @@ -729,6 +729,12 @@ struct uevent *uevent_from_udev_device(struct udev_device *dev) if (i == HOTPLUG_NUM_ENVP - 1) break; } + if (!uev->devpath || ! uev->action) { + udev_device_unref(dev); + condlog(1, "uevent missing necessary fields"); + FREE(uev); + return NULL; + } uev->udev = dev; uev->envp[i] = NULL; From patchwork Fri Sep 21 23:05:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611199 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C952913 for ; Fri, 21 Sep 2018 23:06:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C8AA2D79D for ; Fri, 21 Sep 2018 23:06:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50ED52E0C0; Fri, 21 Sep 2018 23:06:27 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 17F4C2D79D for ; Fri, 21 Sep 2018 23:06:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4DB713001FCC; Fri, 21 Sep 2018 23:06:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1D97083BFC; Fri, 21 Sep 2018 23:06:26 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DAFE5181A12F; Fri, 21 Sep 2018 23:06:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LN6OgS027414 for ; Fri, 21 Sep 2018 19:06:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5B7C77F34C; Fri, 21 Sep 2018 23:06:24 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 122AC7F646; Fri, 21 Sep 2018 23:06:17 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:06:17 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:21 -0500 Message-Id: <1537571127-10143-14-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 13/19] multipath: fix max array size in print_cmd_valid X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 21 Sep 2018 23:06:26 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP The code is attempting to verify that 0 <= k < 3 However, sizeof(val) is 12, assuming 4 byte integers. The check needs to take integer size into account. Found by coverity. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipath/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multipath/main.c b/multipath/main.c index fc5bf16..d5aad95 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -482,7 +482,7 @@ static int print_cmd_valid(int k, const vector pathvec, struct timespec until; struct path *pp; - if (k < 0 || k >= sizeof(vals)) + if (k < 0 || k >= (sizeof(vals) / sizeof(int))) return 1; if (k == 2) { From patchwork Fri Sep 21 23:05:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611201 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1331C1709 for ; Fri, 21 Sep 2018 23:06:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03B1C2D79D for ; Fri, 21 Sep 2018 23:06:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB3422E0C0; Fri, 21 Sep 2018 23:06:31 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9B9392D79D for ; Fri, 21 Sep 2018 23:06:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BFC6E8666D; Fri, 21 Sep 2018 23:06:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 94AA360F87; Fri, 21 Sep 2018 23:06:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5450E4BB75; Fri, 21 Sep 2018 23:06:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LN6TGo027433 for ; Fri, 21 Sep 2018 19:06:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 067967E30C; Fri, 21 Sep 2018 23:06:29 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id B94D07E311; Fri, 21 Sep 2018 23:06:24 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:06:24 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:22 -0500 Message-Id: <1537571127-10143-15-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 14/19] multipathd: function return value tweaks X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 21 Sep 2018 23:06:31 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP In cli_add_map() the return value of get_refwwid is never used, and refwwid is checked to see if the function returned successfully, so the return value doesn't need to be saved. In resize_map, if setup_map fails, multipathd shouldn't attempt to create the device with resulting params string. It should just fail instead. Found by coverity. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/cli_handlers.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index 5682b5c..bb16472 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -796,8 +796,8 @@ cli_add_map (void * v, char ** reply, int * len, void * data) if (!alias && !count) { condlog(2, "%s: mapname not found for %d:%d", param, major, minor); - rc = get_refwwid(CMD_NONE, param, DEV_DEVMAP, - vecs->pathvec, &refwwid); + get_refwwid(CMD_NONE, param, DEV_DEVMAP, + vecs->pathvec, &refwwid); if (refwwid) { if (coalesce_paths(vecs, NULL, refwwid, FORCE_RELOAD_NONE, CMD_NONE)) @@ -881,7 +881,12 @@ int resize_map(struct multipath *mpp, unsigned long long size, mpp->size = size; update_mpp_paths(mpp, vecs->pathvec); - setup_map(mpp, params, PARAMS_SIZE, vecs); + if (setup_map(mpp, params, PARAMS_SIZE, vecs) != 0) { + condlog(0, "%s: failed to setup map for resize : %s", + mpp->alias, strerror(errno)); + mpp->size = orig_size; + return 1; + } mpp->action = ACT_RESIZE; mpp->force_udev_reload = 1; if (domap(mpp, params, 1) <= 0) { From patchwork Fri Sep 21 23:05:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611203 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C9291709 for ; Fri, 21 Sep 2018 23:06:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D3C12D79D for ; Fri, 21 Sep 2018 23:06:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 015642E0C0; Fri, 21 Sep 2018 23:06:35 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AAFCD2D79D for ; Fri, 21 Sep 2018 23:06:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D346C3002317; Fri, 21 Sep 2018 23:06:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A61C589F55; Fri, 21 Sep 2018 23:06:34 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 54A7B181A130; Fri, 21 Sep 2018 23:06:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LN6Um0027446 for ; Fri, 21 Sep 2018 19:06:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id AC7BFD1CC; Fri, 21 Sep 2018 23:06:30 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 6D85383867; Fri, 21 Sep 2018 23:06:29 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:06:29 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:23 -0500 Message-Id: <1537571127-10143-16-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 15/19] multipathd: minor fixes X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 21 Sep 2018 23:06:35 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP In update_multipath(), conf is set again in a couple of lines, and nothing uses it before then, so there's no point in setting it twice. Also, in ev_remove_path(), strncpy() could end up unterminated, so use strlcpy() instead. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index cc493c1..125a805 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -429,7 +429,7 @@ int update_multipath (struct vectors *vecs, char *mapname, int reset) continue; if (pp->state != PATH_DOWN) { - struct config *conf = get_multipath_config(); + struct config *conf; int oldstate = pp->state; int checkint; @@ -1096,7 +1096,7 @@ ev_remove_path (struct path *pp, struct vectors * vecs, int need_do_map) /* * flush_map will fail if the device is open */ - strncpy(alias, mpp->alias, WWID_SIZE); + strlcpy(alias, mpp->alias, WWID_SIZE); if (mpp->flush_on_last_del == FLUSH_ENABLED) { condlog(2, "%s Last path deleted, disabling queueing", mpp->alias); mpp->retry_tick = 0; From patchwork Fri Sep 21 23:05:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611205 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8D8DB913 for ; Fri, 21 Sep 2018 23:06:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D3D62D79D for ; Fri, 21 Sep 2018 23:06:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7166E2E0C0; Fri, 21 Sep 2018 23:06:37 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 290F32D79D for ; Fri, 21 Sep 2018 23:06:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3FCFC9B459; Fri, 21 Sep 2018 23:06:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F82A89E42; Fri, 21 Sep 2018 23:06:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D03604A460; Fri, 21 Sep 2018 23:06:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LN6YtA027457 for ; Fri, 21 Sep 2018 19:06:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id A547187504; Fri, 21 Sep 2018 23:06:34 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 6417F881E6; Fri, 21 Sep 2018 23:06:31 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:06:30 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:24 -0500 Message-Id: <1537571127-10143-17-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 16/19] multipathd: remove useless check and fix format X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 21 Sep 2018 23:06:36 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP The only thing this patch changes is to remove the check for pp->mpp before the check for pp->mpp->prflags, since check_path() already verified that pp->mpp != NULL. This fixes a number of coverity warnings. Also, I normalized the spacing and indenting of the nearby code. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 125a805..3c2fe7b 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -1978,14 +1978,14 @@ check_path (struct vectors * vecs, struct path * pp, int ticks) return 1; } - if(newstate == PATH_UP || newstate == PATH_GHOST){ - if ( pp->mpp && pp->mpp->prflag ){ + if (newstate == PATH_UP || newstate == PATH_GHOST) { + if (pp->mpp->prflag) { /* * Check Persistent Reservation. */ - condlog(2, "%s: checking persistent reservation " - "registration", pp->dev); - mpath_pr_event_handle(pp); + condlog(2, "%s: checking persistent " + "reservation registration", pp->dev); + mpath_pr_event_handle(pp); } } From patchwork Fri Sep 21 23:05:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611207 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7245C913 for ; Fri, 21 Sep 2018 23:06:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 635CC2D79D for ; Fri, 21 Sep 2018 23:06:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57A052E0C0; Fri, 21 Sep 2018 23:06:41 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F26002D79D for ; Fri, 21 Sep 2018 23:06:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3492F4ACA4; Fri, 21 Sep 2018 23:06:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0974916D35; Fri, 21 Sep 2018 23:06:40 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C7799181A13C; Fri, 21 Sep 2018 23:06:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LN6c12027467 for ; Fri, 21 Sep 2018 19:06:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7B27183BFC; Fri, 21 Sep 2018 23:06:38 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 3808483BFA; Fri, 21 Sep 2018 23:06:35 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:06:34 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:25 -0500 Message-Id: <1537571127-10143-18-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 17/19] multipathd: fix memory leak on error in configure X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 21 Sep 2018 23:06:40 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP If configure fails after allocing mpvec, it must free it. Found by coverity. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 3c2fe7b..61ca455 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2277,7 +2277,7 @@ configure (struct vectors * vecs) ret = path_discovery(vecs->pathvec, DI_ALL); if (ret < 0) { condlog(0, "configure failed at path discovery"); - return 1; + goto fail; } vector_foreach_slot (vecs->pathvec, pp, i){ @@ -2294,7 +2294,7 @@ configure (struct vectors * vecs) } if (map_discovery(vecs)) { condlog(0, "configure failed at map discovery"); - return 1; + goto fail; } /* @@ -2308,7 +2308,7 @@ configure (struct vectors * vecs) force_reload = FORCE_RELOAD_YES; if (ret) { condlog(0, "configure failed while coalescing paths"); - return 1; + goto fail; } /* @@ -2317,7 +2317,7 @@ configure (struct vectors * vecs) */ if (coalesce_maps(vecs, mpvec)) { condlog(0, "configure failed while coalescing maps"); - return 1; + goto fail; } dm_lib_release(); @@ -2353,6 +2353,10 @@ configure (struct vectors * vecs) i--; } return 0; + +fail: + vector_free(mpvec); + return 1; } int From patchwork Fri Sep 21 23:05:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611209 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 61B511709 for ; Fri, 21 Sep 2018 23:06:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5191F2D79D for ; Fri, 21 Sep 2018 23:06:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 444642E0C0; Fri, 21 Sep 2018 23:06:45 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F1CAE2D79D for ; Fri, 21 Sep 2018 23:06:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E7A79E622; Fri, 21 Sep 2018 23:06:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E1B02881F5; Fri, 21 Sep 2018 23:06:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id ABE0D4A463; Fri, 21 Sep 2018 23:06:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LN6gfl027481 for ; Fri, 21 Sep 2018 19:06:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id A09183083329; Fri, 21 Sep 2018 23:06:42 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 6061B3091391; Fri, 21 Sep 2018 23:06:38 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:06:38 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:26 -0500 Message-Id: <1537571127-10143-19-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 18/19] libmultipath: Don't blank intialized paths X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 21 Sep 2018 23:06:44 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP When pathinfo fails for some likely transient reason, it clears the path wwid, but otherwise returns successfully, to keep the path around but not usable until it gets fully initialized. However, if the path has already been initialized, and pathinfo hits a transient error, it shouldn't clear the wwid. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/discovery.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 3e0db7f..33815dc 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1991,9 +1991,9 @@ blank: /* * Recoverable error, for example faulty or offline path */ - memset(pp->wwid, 0, WWID_SIZE); pp->chkrstate = pp->state = PATH_DOWN; - pp->initialized = INIT_FAILED; + if (pp->initialized == INIT_FAILED) + memset(pp->wwid, 0, WWID_SIZE); return PATHINFO_OK; } From patchwork Fri Sep 21 23:05:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10611211 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4DFAC1709 for ; Fri, 21 Sep 2018 23:06:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D4F22D79D for ; Fri, 21 Sep 2018 23:06:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31C892E0C0; Fri, 21 Sep 2018 23:06:48 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C5E972D79D for ; Fri, 21 Sep 2018 23:06:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 73E943DE35; Fri, 21 Sep 2018 23:06:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 45E94308BE75; Fri, 21 Sep 2018 23:06:46 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0B5AD181A139; Fri, 21 Sep 2018 23:06:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8LN6is3027492 for ; Fri, 21 Sep 2018 19:06:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5352083BFC; Fri, 21 Sep 2018 23:06:44 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 1278083BE9; Fri, 21 Sep 2018 23:06:43 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:06:42 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Fri, 21 Sep 2018 18:05:27 -0500 Message-Id: <1537571127-10143-20-git-send-email-bmarzins@redhat.com> In-Reply-To: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> References: <1537571127-10143-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v3 19/19] libmultipath: Fixup updating paths X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 21 Sep 2018 23:06:47 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Commit 582c56cc broke some code paths in uev_update_path. First, it changed the handling of paths that were not fully initialized. uev_update_path was simply setting the wwids for all of these paths. Instead, it should ignore the ones that had not requested a new uevent. These paths are likely down, and are already getting handled by check_path, after it verifies that they have become active. Also, setting the wwid doesn't update all of the other information that may have been missed when the path was initially added. Also, it wasn't possible for pp->wwid_changed to transition back to zero, unless the path's wwid was empty, in which case there was no reason to worry about the wwid change in the first place, since the path hadn't been fully initialized yet. So, even if a path's wwid changed and then changed back to the original value, the path still could not be used. This patch fixes these issues, and also moves the check for paths that have requested a new uevent up in the functions. These paths will get fully reinitialized anyway, so there is no reason to do all the other work first. Fixes: 582c56cc ("libmultipath: uev_update_path: always warn if WWID changed") Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- multipathd/main.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 61ca455..d6d122a 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -1207,6 +1207,15 @@ uev_update_path (struct uevent *uev, struct vectors * vecs) struct multipath *mpp = pp->mpp; char wwid[WWID_SIZE]; + if (pp->initialized == INIT_REQUESTED_UDEV) { + needs_reinit = 1; + goto out; + } + /* Don't deal with other types of failed initialization + * now. check_path will handle it */ + if (!strlen(pp->wwid)) + goto out; + strcpy(wwid, pp->wwid); get_uid(pp, pp->state, uev->udev); @@ -1215,9 +1224,8 @@ uev_update_path (struct uevent *uev, struct vectors * vecs) uev->kernel, wwid, pp->wwid, (disable_changed_wwids ? "disallowing" : "continuing")); - if (disable_changed_wwids && - (strlen(wwid) || pp->wwid_changed)) { - strcpy(pp->wwid, wwid); + strcpy(pp->wwid, wwid); + if (disable_changed_wwids) { if (!pp->wwid_changed) { pp->wwid_changed = 1; pp->tick = 1; @@ -1225,11 +1233,9 @@ uev_update_path (struct uevent *uev, struct vectors * vecs) dm_fail_path(pp->mpp->alias, pp->dev_t); } goto out; - } else if (!disable_changed_wwids) - strcpy(pp->wwid, wwid); - else - pp->wwid_changed = 0; + } } else { + pp->wwid_changed = 0; udev_device_unref(pp->udev); pp->udev = udev_device_ref(uev->udev); conf = get_multipath_config(); @@ -1240,9 +1246,7 @@ uev_update_path (struct uevent *uev, struct vectors * vecs) pthread_cleanup_pop(1); } - if (pp->initialized == INIT_REQUESTED_UDEV) - needs_reinit = 1; - else if (mpp && ro >= 0) { + if (mpp && ro >= 0) { condlog(2, "%s: update path write_protect to '%d' (uevent)", uev->kernel, ro); if (mpp->wait_for_udev)