From patchwork Thu Dec 7 18:48:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10100853 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.web.codeaurora.org (Postfix) with ESMTP id 82A546056F for ; Thu, 7 Dec 2017 18:49:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75E9D28521 for ; Thu, 7 Dec 2017 18:49:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6AB472853C; Thu, 7 Dec 2017 18:49: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=-6.9 required=2.0 tests=BAYES_00,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 E4AB528535 for ; Thu, 7 Dec 2017 18:49:34 +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 2B76E61D20; Thu, 7 Dec 2017 18:49: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 0C1A569285; Thu, 7 Dec 2017 18:49: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 DBC7C180474D; Thu, 7 Dec 2017 18:49:33 +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 vB7InQjf026227 for ; Thu, 7 Dec 2017 13:49:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4D28A6EE54; Thu, 7 Dec 2017 18:49:26 +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 0EBE66EE5A; Thu, 7 Dec 2017 18:49:24 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Thu, 07 Dec 2017 12:49:24 -0600 From: "Benjamin Marzinski" To: device-mapper development Date: Thu, 7 Dec 2017 12:48:59 -0600 Message-Id: <1512672546-12785-6-git-send-email-bmarzins@redhat.com> In-Reply-To: <1512672546-12785-1-git-send-email-bmarzins@redhat.com> References: <1512672546-12785-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 05/12] multipathd: move helper functions to libmultipath 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.39]); Thu, 07 Dec 2017 18:49:34 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP This commit simply moves sync_map_state() and update_map() from multipathd/main.c to libmultipath/structs_vec.c, to enable future changes. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- libmultipath/structs_vec.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++ libmultipath/structs_vec.h | 2 ++ multipathd/main.c | 72 -------------------------------------------- multipathd/main.h | 1 - 4 files changed, 76 insertions(+), 73 deletions(-) diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c index 22be8e0..eddeeaf 100644 --- a/libmultipath/structs_vec.c +++ b/libmultipath/structs_vec.c @@ -16,6 +16,8 @@ #include "propsel.h" #include "discovery.h" #include "prio.h" +#include "configure.h" +#include "libdevmapper.h" /* * creates or updates mpp->paths reading mpp->pg @@ -415,6 +417,78 @@ out: return 1; } +void +sync_map_state(struct multipath *mpp) +{ + struct pathgroup *pgp; + struct path *pp; + unsigned int i, j; + + if (!mpp->pg) + return; + + vector_foreach_slot (mpp->pg, pgp, i){ + vector_foreach_slot (pgp->paths, pp, j){ + if (pp->state == PATH_UNCHECKED || + pp->state == PATH_WILD || + pp->state == PATH_DELAYED) + continue; + if (mpp->ghost_delay_tick > 0) + continue; + if ((pp->dmstate == PSTATE_FAILED || + pp->dmstate == PSTATE_UNDEF) && + (pp->state == PATH_UP || pp->state == PATH_GHOST)) + dm_reinstate_path(mpp->alias, pp->dev_t); + else if ((pp->dmstate == PSTATE_ACTIVE || + pp->dmstate == PSTATE_UNDEF) && + (pp->state == PATH_DOWN || + pp->state == PATH_SHAKY)) + dm_fail_path(mpp->alias, pp->dev_t); + } + } +} + +int +update_map (struct multipath *mpp, struct vectors *vecs) +{ + int retries = 3; + char params[PARAMS_SIZE] = {0}; + +retry: + condlog(4, "%s: updating new map", mpp->alias); + if (adopt_paths(vecs->pathvec, mpp)) { + condlog(0, "%s: failed to adopt paths for new map update", + mpp->alias); + retries = -1; + goto fail; + } + verify_paths(mpp, vecs); + mpp->flush_on_last_del = FLUSH_UNDEF; + mpp->action = ACT_RELOAD; + + if (setup_map(mpp, params, PARAMS_SIZE)) { + condlog(0, "%s: failed to setup new map in update", mpp->alias); + retries = -1; + goto fail; + } + if (domap(mpp, params, 1) <= 0 && retries-- > 0) { + condlog(0, "%s: map_udate sleep", mpp->alias); + sleep(1); + goto retry; + } + dm_lib_release(); + +fail: + if (setup_multipath(vecs, mpp)) + return 1; + + sync_map_state(mpp); + + if (retries < 0) + condlog(0, "%s: failed reload in new map update", mpp->alias); + return 0; +} + struct multipath *add_map_without_path (struct vectors *vecs, char *alias) { struct multipath * mpp = alloc_multipath(); diff --git a/libmultipath/structs_vec.h b/libmultipath/structs_vec.h index 46f30af..54444e0 100644 --- a/libmultipath/structs_vec.h +++ b/libmultipath/structs_vec.h @@ -30,6 +30,8 @@ void remove_map_and_stop_waiter (struct multipath * mpp, struct vectors * vecs, void remove_maps (struct vectors * vecs); void remove_maps_and_stop_waiters (struct vectors * vecs); +void sync_map_state (struct multipath *); +int update_map (struct multipath *mpp, struct vectors *vecs); struct multipath * add_map_without_path (struct vectors * vecs, char * alias); struct multipath * add_map_with_path (struct vectors * vecs, struct path * pp, int add_vec); diff --git a/multipathd/main.c b/multipathd/main.c index 25f1f52..93506ea 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -338,37 +338,6 @@ coalesce_maps(struct vectors *vecs, vector nmpv) return 0; } -void -sync_map_state(struct multipath *mpp) -{ - struct pathgroup *pgp; - struct path *pp; - unsigned int i, j; - - if (!mpp->pg) - return; - - vector_foreach_slot (mpp->pg, pgp, i){ - vector_foreach_slot (pgp->paths, pp, j){ - if (pp->state == PATH_UNCHECKED || - pp->state == PATH_WILD || - pp->state == PATH_DELAYED) - continue; - if (mpp->ghost_delay_tick > 0) - continue; - if ((pp->dmstate == PSTATE_FAILED || - pp->dmstate == PSTATE_UNDEF) && - (pp->state == PATH_UP || pp->state == PATH_GHOST)) - dm_reinstate_path(mpp->alias, pp->dev_t); - else if ((pp->dmstate == PSTATE_ACTIVE || - pp->dmstate == PSTATE_UNDEF) && - (pp->state == PATH_DOWN || - pp->state == PATH_SHAKY)) - dm_fail_path(mpp->alias, pp->dev_t); - } - } -} - static void sync_maps_state(vector mpvec) { @@ -416,47 +385,6 @@ flush_map(struct multipath * mpp, struct vectors * vecs, int nopaths) return 0; } -int -update_map (struct multipath *mpp, struct vectors *vecs) -{ - int retries = 3; - char params[PARAMS_SIZE] = {0}; - -retry: - condlog(4, "%s: updating new map", mpp->alias); - if (adopt_paths(vecs->pathvec, mpp)) { - condlog(0, "%s: failed to adopt paths for new map update", - mpp->alias); - retries = -1; - goto fail; - } - verify_paths(mpp, vecs); - mpp->flush_on_last_del = FLUSH_UNDEF; - mpp->action = ACT_RELOAD; - - if (setup_map(mpp, params, PARAMS_SIZE)) { - condlog(0, "%s: failed to setup new map in update", mpp->alias); - retries = -1; - goto fail; - } - if (domap(mpp, params, 1) <= 0 && retries-- > 0) { - condlog(0, "%s: map_udate sleep", mpp->alias); - sleep(1); - goto retry; - } - dm_lib_release(); - -fail: - if (setup_multipath(vecs, mpp)) - return 1; - - sync_map_state(mpp); - - if (retries < 0) - condlog(0, "%s: failed reload in new map update", mpp->alias); - return 0; -} - static int uev_add_map (struct uevent * uev, struct vectors * vecs) { diff --git a/multipathd/main.h b/multipathd/main.h index 094b04f..ededdab 100644 --- a/multipathd/main.h +++ b/multipathd/main.h @@ -26,7 +26,6 @@ int ev_add_path (struct path *, struct vectors *, int); int ev_remove_path (struct path *, struct vectors *, int); int ev_add_map (char *, char *, struct vectors *); int ev_remove_map (char *, char *, int, struct vectors *); -void sync_map_state (struct multipath *); int set_config_state(enum daemon_status); void * mpath_alloc_prin_response(int prin_sa); int prin_do_scsi_ioctl(char *, int rq_servact, struct prin_resp * resp,