From patchwork Thu Nov 5 15:58:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 56067 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp487325lbr; Thu, 5 Nov 2015 07:59:01 -0800 (PST) X-Received: by 10.107.135.204 with SMTP id r73mr10406492ioi.164.1446739141520; Thu, 05 Nov 2015 07:59:01 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id p78si7044588iop.65.2015.11.05.07.58.31; Thu, 05 Nov 2015 07:59:01 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: by lists.linaro.org (Postfix, from userid 109) id A5C8B61A2E; Thu, 5 Nov 2015 15:58:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id DA9B86195C; Thu, 5 Nov 2015 15:58:29 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 42E3261970; Thu, 5 Nov 2015 15:58:28 +0000 (UTC) Received: from mail-lf0-f54.google.com (mail-lf0-f54.google.com [209.85.215.54]) by lists.linaro.org (Postfix) with ESMTPS id 0914E61101 for ; Thu, 5 Nov 2015 15:58:27 +0000 (UTC) Received: by lfgh9 with SMTP id h9so59543514lfg.1 for ; Thu, 05 Nov 2015 07:58:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=bN5A6WiG561KK2n56gcKaLfXklUPH/kpWHBRVX6O9AA=; b=AGknyGZKx1iWr+kuKy0vybP3y1wAQP6klpniUEOQiXSF0LPxewp6ianmswpjDf2ada v/+PTrexBS3EKIPuUiZ0S62f9n//547LTCFd7CDwxqL1loo6nORUrPgiz7rlUH5uQxhm fw5FfQIqpXhhV6hPMASzueYqpxJ1HF9I6Un0bWA+xJETcoT4sZT0h0hQ+86zdmfvq/0d m9zn/h9AqXlP+o0TijBNnI2tfmdsQHJHT/BmmAgF+0dHSUxx7FvUGyRIk8V8teKKz/I4 yijJhwPXWUc+fEN8rMP2rvSYJG6+HcB+KfbqIOiBXfX02ByiboTgGrKMTxOhQYoD4vkE 0CDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=bN5A6WiG561KK2n56gcKaLfXklUPH/kpWHBRVX6O9AA=; b=e9QXIdB2cRaVRe5jXGHE+auwYQD4+8INcj1gKeCscoTrMi8jVs55wCXTsVvqFH6Yb0 E5DNP1juUKzId6BOd8m0l/UzHkVsf8b4qW0gfxTEuHfyDEoq9EpvVEKSm0uy0e+C1sN0 K6dW8jPSf2O6nsG1VrrSSbSaeYOSI5HYI5DlLaSZPiT55RiQAsd3CrMLqAgnzVqOJt2M /omMR4LE//NGvp3MDTndzEXuXokepjcCUmCVcSKyox24c7K86sVj3E8a7uB7u524/r/t +bfOnrzHmBrx2hvUblQX/hiIJdueJtJSRMr43Hc1WbbZvD+gAeN+zMWeWEcBh7jqzSAn 2gqg== X-Gm-Message-State: ALoCoQln0i6xeZCQQD+sRjaWdA8eKc0X4jvTmava959oHXUBshyruQ96SNOtBqvc5NpuUKmOvWLL X-Received: by 10.25.79.14 with SMTP id d14mr2334647lfb.40.1446739105818; Thu, 05 Nov 2015 07:58:25 -0800 (PST) Received: from localhost.localdomain (ppp91-76-161-180.pppoe.mtu-net.ru. [91.76.161.180]) by smtp.gmail.com with ESMTPSA id ys17sm1047921lbb.11.2015.11.05.07.58.24 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Nov 2015 07:58:25 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 5 Nov 2015 18:58:17 +0300 Message-Id: <1446739097-29843-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Subject: [lng-odp] [PATCHv2] linux-generic: check return codes in odp_pktio_term_global X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" According to API odp_pktio_close() can be called only for stopped pktio. So in odp_pktio_term_global try to stop it first then call close. Also check all returns codes. https://bugs.linaro.org/show_bug.cgi?id=1854 Signed-off-by: Maxim Uvarov --- v2: lock pktio for stop and close in odp_pktio_term_global() (Nicolases note) platform/linux-generic/odp_packet_io.c | 119 ++++++++++++++++++++++----------- 1 file changed, 79 insertions(+), 40 deletions(-) diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 1246bff..c3bc6a0 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -84,33 +84,6 @@ int odp_pktio_init_global(void) return 0; } -int odp_pktio_term_global(void) -{ - pktio_entry_t *pktio_entry; - int ret = 0; - int id; - int pktio_if; - - for (id = 1; id <= ODP_CONFIG_PKTIO_ENTRIES; ++id) { - pktio_entry = &pktio_tbl->entries[id - 1]; - odp_pktio_close(pktio_entry->s.handle); - odp_queue_destroy(pktio_entry->s.outq_default); - } - - for (pktio_if = 0; pktio_if_ops[pktio_if]; ++pktio_if) { - if (pktio_if_ops[pktio_if]->term) - if (pktio_if_ops[pktio_if]->term()) - ODP_ERR("failed to terminate pktio type %d", - pktio_if); - } - - ret = odp_shm_free(odp_shm_lookup("odp_pktio_entries")); - if (ret < 0) - ODP_ERR("shm free failed for odp_pktio_entries"); - - return ret; -} - int odp_pktio_init_local(void) { return 0; @@ -284,10 +257,22 @@ odp_pktio_t odp_pktio_open(const char *dev, odp_pool_t pool, return id; } +static int _pktio_close(pktio_entry_t *entry) +{ + int ret; + + ret = entry->s.ops->close(entry); + if (ret) + return -1; + + set_free(entry); + return 0; +} + int odp_pktio_close(odp_pktio_t id) { pktio_entry_t *entry; - int res = -1; + int res; entry = get_pktio_entry(id); if (entry == NULL) @@ -295,14 +280,12 @@ int odp_pktio_close(odp_pktio_t id) lock_entry(entry); if (!is_free(entry)) { - res = entry->s.ops->close(entry); - res |= free_pktio_entry(id); + res = _pktio_close(entry); + if (res) + ODP_ABORT("unable to close pktio\n"); } unlock_entry(entry); - if (res != 0) - return -1; - return 0; } @@ -325,20 +308,29 @@ int odp_pktio_start(odp_pktio_t id) return res; } -int odp_pktio_stop(odp_pktio_t id) +static int _pktio_stop(pktio_entry_t *entry) { - pktio_entry_t *entry; int res = 0; - entry = get_pktio_entry(id); - if (!entry) - return -1; - - lock_entry(entry); if (entry->s.ops->stop) res = entry->s.ops->stop(entry); if (!res) entry->s.state = STATE_STOP; + + return res; +} + +int odp_pktio_stop(odp_pktio_t id) +{ + pktio_entry_t *entry; + int res; + + entry = get_pktio_entry(id); + if (!entry) + return -1; + + lock_entry(entry); + res = _pktio_stop(entry); unlock_entry(entry); return res; @@ -822,3 +814,50 @@ void odp_pktio_param_init(odp_pktio_param_t *params) { memset(params, 0, sizeof(odp_pktio_param_t)); } + +int odp_pktio_term_global(void) +{ + int ret; + int id; + int pktio_if; + + for (id = 0; id < ODP_CONFIG_PKTIO_ENTRIES; ++id) { + pktio_entry_t *pktio_entry; + + pktio_entry = &pktio_tbl->entries[id]; + + ret = odp_queue_destroy(pktio_entry->s.outq_default); + if (ret) + ODP_ABORT("unable to destroy outq %s\n", + pktio_entry->s.name); + + if (is_free(pktio_entry)) + continue; + + lock_entry(pktio_entry); + if (pktio_entry->s.state != STATE_STOP) { + ret = _pktio_stop(pktio_entry); + if (ret) + ODP_ABORT("unable to stop pktio %s\n", + pktio_entry->s.name); + } + ret = _pktio_close(pktio_entry); + if (ret) + ODP_ABORT("unable to close pktio %s\n", + pktio_entry->s.name); + unlock_entry(pktio_entry); + } + + for (pktio_if = 0; pktio_if_ops[pktio_if]; ++pktio_if) { + if (pktio_if_ops[pktio_if]->term) + if (pktio_if_ops[pktio_if]->term()) + ODP_ABORT("failed to terminate pktio type %d", + pktio_if); + } + + ret = odp_shm_free(odp_shm_lookup("odp_pktio_entries")); + if (ret != 0) + ODP_ERR("shm free failed for odp_pktio_entries"); + + return ret; +}