From patchwork Sat Jan 4 22:23:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 3434441 X-Patchwork-Delegate: hal@mellanox.com Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0FB049F295 for ; Sat, 4 Jan 2014 22:24:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E041920158 for ; Sat, 4 Jan 2014 22:24:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A2C6720136 for ; Sat, 4 Jan 2014 22:24:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754545AbaADWXz (ORCPT ); Sat, 4 Jan 2014 17:23:55 -0500 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:33444 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753656AbaADWXy (ORCPT ); Sat, 4 Jan 2014 17:23:54 -0500 Received: from compute1.internal (compute1.nyi.mail.srv.osa [10.202.2.41]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 1FA9C206C8 for ; Sat, 4 Jan 2014 17:23:53 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute1.internal (MEProxy); Sat, 04 Jan 2014 17:23:53 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.fm; h= message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type:content-transfer-encoding; s=mesmtp; bh=G1Lkii9VLv1EZmFHFWxK/IfhFC0=; b=N1Ifr3kVObKWU3eQ/Xe562zE0en5 BGvAlu33rZP0v6YkoWXmIWBfYo3FXmzXgzTobaAJu7D+I1+EioEeq8x/RwkOXTgd +1fvhrKXeALTo8tf23Y079ZPnnXiCBiJawKBmqgTZmN8NlfMMypWkyQNaoMubyBQ IcRY8OZCyDUKFSY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:date:from:mime-version:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding; s=smtpout; bh=G1Lkii9VLv1EZmFHFWxK/I fhFC0=; b=DsoqjFvUlw4LbeU+U/H4n2CbQ4koPHkMfrpOIy8h1fSZii3RjmHoRe UxQBAma4XvFkJl9NqT+zaisxYXBNrPDxnmVxAkYrSUIoiejmpv7QdwAS42VXpY5c yKM2LIpR9hhYVFYMhWEjY5R+k+1Ag/HdKm3qEzF2+pbd4deTmRfFY= X-Sasl-enc: g0oQPB2SnkpYrLpfVg7hny2ttwPWeiiJxOP7ASVE7DQE 1388874232 Received: from [192.168.178.22] (unknown [95.89.87.109]) by mail.messagingengine.com (Postfix) with ESMTPA id 7ED3BC00E7F; Sat, 4 Jan 2014 17:23:52 -0500 (EST) Message-ID: <52C889F7.5050508@fastmail.fm> Date: Sat, 04 Jan 2014 23:23:51 +0100 From: Bernd Schubert User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Hal Rosenstock , "linux-rdma (linux-rdma@vger.kernel.org)" CC: Alex Netes Subject: [PATCH opensm] Parse the the partition config in dry-run mode first References: <52C846F7.6080806@dev.mellanox.co.il> In-Reply-To: <52C846F7.6080806@dev.mellanox.co.il> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hello Hal, thanks for updating the patch! I had it on my todo list during my vacation (still one week left) and didn't have the time to care about it before. What do you think about the patch below on top of your updated patch? (So far I only tested if it compiles at all.) From: Bernd Schubert When the partition config file is parsed, partitions are created for each line. If one of the config lines has an error a default partition is created already by a previous commit, but partitions from previous lines are not cleaned up. Avoid this by doing a dry-run parse first and only if this succeeds actually create new partitions. This still ignores errors from osm_prtn_make_new(), but these errors are rather unlikely (i.e. malloc fails) and not really related to the config file. Signed-off-by: Bernd Schubert --- opensm/osm_prtn_config.c | 47 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/opensm/osm_prtn_config.c b/opensm/osm_prtn_config.c index 9bad7a7..4a2eaab 100644 --- a/opensm/osm_prtn_config.c +++ b/opensm/osm_prtn_config.c @@ -212,7 +212,8 @@ static void __create_mgrp(struct part_conf *conf, struct precreate_mgroup *group } static int partition_create(unsigned lineno, struct part_conf *conf, - char *name, char *id, char *flag, char *flag_val) + char *name, char *id, char *flag, char *flag_val, + boolean_t is_dry_run) { ib_net16_t pkey; @@ -230,6 +231,9 @@ static int partition_create(unsigned lineno, struct part_conf *conf, } else pkey = 0; + if (is_dry_run) + return 0; + conf->p_prtn = osm_prtn_make_new(conf->p_log, conf->p_subn, name, pkey); if (!conf->p_prtn) @@ -601,7 +605,11 @@ static int flush_part_conf(struct part_conf *conf) return 0; } -static int parse_part_conf(struct part_conf *conf, char *str, int lineno) +/** + *@is_dry_run only test if this line is valid + */ +static int parse_part_conf(struct part_conf *conf, char *str, int lineno, + boolean_t is_dry_run) { int ret, len = 0; char *name, *id, *flag, *flval; @@ -659,7 +667,8 @@ static int parse_part_conf(struct part_conf *conf, char *str, int lineno) } if (p != str || (partition_create(lineno, conf, - name, id, flag, flval) < 0)) { + name, id, flag, flval, + is_dry_run) < 0)) { OSM_LOG(conf->p_log, OSM_LOG_ERROR, "PARSE ERROR: line %d: " "bad partition definition\n", lineno); fprintf(stderr, "\nPARSE ERROR: line %d: " @@ -697,10 +706,12 @@ done: } /** + * @is_dry_run test if the config is valid only * @return -1 on error, 0 on success */ -int osm_prtn_config_parse_file(osm_log_t * p_log, osm_subn_t * p_subn, - const char *file_name) +static int _osm_prtn_config_parse_file(osm_log_t * p_log, osm_subn_t * p_subn, + const char *file_name, + boolean_t is_dry_run) { char line[4096]; struct part_conf *conf = NULL; @@ -757,7 +768,7 @@ int osm_prtn_config_parse_file(osm_log_t * p_log, osm_subn_t * p_subn, if (q) *q = '\0'; - len = parse_part_conf(conf, p, lineno); + len = parse_part_conf(conf, p, lineno, is_dry_run); if (len < 0) { is_parse_success = FALSE; break; @@ -779,3 +790,27 @@ int osm_prtn_config_parse_file(osm_log_t * p_log, osm_subn_t * p_subn, else return -1; } + + +/** + * @return -1 on error, 0 on success + */ +int osm_prtn_config_parse_file(osm_log_t * p_log, osm_subn_t * p_subn, + const char *file_name) +{ + boolean_t is_dry_run = TRUE; // dry-run first + int parse_res; + + while (1) { + parse_res =_osm_prtn_config_parse_file(p_log, p_subn, file_name, + is_dry_run); + if (parse_res != 0); + return -1; + + if (!is_dry_run) + return 0; // parse / partition create success + + is_dry_run = FALSE; + } + +}