From patchwork Sun Jul 10 12:04:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Netes X-Patchwork-Id: 961112 X-Patchwork-Delegate: alexne@voltaire.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6AC4vTW000839 for ; Sun, 10 Jul 2011 12:04:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755874Ab1GJME4 (ORCPT ); Sun, 10 Jul 2011 08:04:56 -0400 Received: from mail.mellanox.co.il ([194.90.237.43]:48762 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755867Ab1GJMEz (ORCPT ); Sun, 10 Jul 2011 08:04:55 -0400 Received: from Internal Mail-Server by MTLPINE2 (envelope-from alexne@mellanox.com) with SMTP; 10 Jul 2011 15:04:48 +0300 Received: from MTRCASDAG01.mtl.com (172.25.0.174) by MTLCAS01.mtl.com (10.0.8.71) with Microsoft SMTP Server (TLS) id 14.1.289.1; Sun, 10 Jul 2011 15:04:48 +0300 Received: from localhost (172.25.5.62) by MTRCASDAG01.mtl.com (172.25.0.174) with Microsoft SMTP Server (TLS) id 14.1.289.1; Sun, 10 Jul 2011 15:04:43 +0300 Date: Sun, 10 Jul 2011 15:04:42 +0300 From: Alex Netes To: , Aleksey Senin Subject: [PATCH] opensm: Add support for PID file Message-ID: <20110710120442.GA11284@localhost.localdomain> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [172.25.5.62] Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Sun, 10 Jul 2011 12:04:57 +0000 (UTC) When OpenSM executed, opensm.pid created by default in /var/run and contains PID of the last executed instance of OpenSM. opensm.pid is used by opensm.init stop, to kill only the last executed instance of OpenSM. Signed-off-by: Aleksey Senin Signed-off-by: Alex Netes --- configure.in | 25 +++++++++++++++++++++++++ include/opensm/osm_base.h | 18 ++++++++++++++++++ include/opensm/osm_subnet.h | 1 + man/opensm.8.in | 5 +++++ opensm/main.c | 16 ++++++++++++++++ opensm/osm_subnet.c | 2 ++ scripts/opensm.init.in | 5 ++++- 7 files changed, 71 insertions(+), 1 deletions(-) diff --git a/configure.in b/configure.in index 7c5eb65..c6f5d53 100644 --- a/configure.in +++ b/configure.in @@ -231,6 +231,31 @@ dnl Checks for headers and libraries OPENIB_APP_OSMV_CHECK_HEADER OPENIB_APP_OSMV_CHECK_LIB +dnl Where to place opensm.pid +piddir=/var/run +dnl make sure the directory exists +if test ! -d $piddir ; then + piddir=`eval echo ${sysconfdir}` + case $piddir in + NONE/*) piddir=`echo $piddir | sed "s~NONE~$ac_default_prefix~"` ;; + esac +fi + +AC_ARG_WITH(pid-dir, + [ --with-pid-dir= define the dir of opensm.pid file (default is /var/run)], + [ + if test -n "$withval" && test "x$withval" != "xno" && \ + test "x${withval}" != "xyes"; then + piddir=$withval + if test ! -d $piddir ; then + AC_MSG_WARN([** no $piddir directory on this system **]) + fi + fi + ] +) +AC_DEFINE_UNQUOTED(OPENSM_PID_DIR, "$piddir", [Specify location of opensm.pid]) +AC_SUBST(piddir) + AC_CONFIG_FILES([man/opensm.8 man/torus-2QoS.8 man/torus-2QoS.conf.5 scripts/opensm.init scripts/redhat-opensm.init scripts/sldd.sh]) dnl Create the following Makefiles diff --git a/include/opensm/osm_base.h b/include/opensm/osm_base.h index c1a52b5..13bfbb0 100644 --- a/include/opensm/osm_base.h +++ b/include/opensm/osm_base.h @@ -318,6 +318,24 @@ BEGIN_C_DECLS #endif /***********/ +/****d* OpenSM: Base/OSM_DEFAULT_PID_FILE +* NAME +* OSM_DEFAULT_PID_FILE +* +* DESCRIPTION +* Specifies the default pid file name +* +* SYNOPSIS +*/ +#if defined(HAVE_DEFAULT_PID_FILE) +#define OSM_DEFAULT_PID_FILE HAVE_DEFAULT_PID_FILE +#elif defined(OPENSM_PID_DIR) +#define OSM_DEFAULT_PID_FILE OPENSM_PID_DIR "/opensm.pid" +#else +#define OSM_DEFAULT_PID_FILE "/var/run/opensm.pid" +#endif +/***********/ + /****d* OpenSM: Base/OSM_DEFAULT_SWEEP_INTERVAL_SECS * NAME * OSM_DEFAULT_SWEEP_INTERVAL_SECS diff --git a/include/opensm/osm_subnet.h b/include/opensm/osm_subnet.h index 6d17c31..9bbbd2f 100644 --- a/include/opensm/osm_subnet.h +++ b/include/opensm/osm_subnet.h @@ -208,6 +208,7 @@ typedef struct osm_subn_opt { char *sa_db_file; boolean_t sa_db_dump; char *torus_conf_file; + char *pid_file; boolean_t do_mesh_analysis; boolean_t exit_on_fatal; boolean_t honor_guid2lid_file; diff --git a/man/opensm.8.in b/man/opensm.8.in index f360739..76096c0 100644 --- a/man/opensm.8.in +++ b/man/opensm.8.in @@ -55,6 +55,7 @@ opensm \- InfiniBand subnet manager and administration (SM/SA) [\-\-consolidate_ipv6_snm_req] [\-\-log_prefix ] [\-\-torus_config ] +[\-\-pid_file ] [\-v(erbose)] [\-V] [\-D ] [\-d(ebug) ] [\-h(elp)] [\-?] @@ -407,6 +408,10 @@ This option defines the file name for the extra configuration information needed for the torus-2QoS routing engine. The default name is \fB\%@OPENSM_CONFIG_DIR@/@TORUS2QOS_CONF_FILE@\fP .TP +\fB\-\-pid_file\fR +Specifies the file that contains the process ID of the opensm daemon. +The default is \fB/var/run/opensm.pid\fP +.TP \fB\-v\fR, \fB\-\-verbose\fR This option increases the log verbosity level. The -v option may be specified multiple times diff --git a/opensm/main.c b/opensm/main.c index 798cb20..30594bf 100644 --- a/opensm/main.c +++ b/opensm/main.c @@ -347,6 +347,9 @@ static void show_usage(void) printf("--consolidate_ipv6_snm_req\n" " Use shared MLID for IPv6 Solicited Node Multicast groups\n" " per MGID scope and P_Key.\n\n"); + printf("--pid_file \n" + " Specifies the file that contains the process ID of the\n" + " opensm daemon.The default is /var/run/opensm.pid\n"); printf("--log_prefix \n" " Prefix to syslog messages from OpenSM.\n\n"); printf("--verbose, -v\n" @@ -638,6 +641,7 @@ int main(int argc, char *argv[]) {"retries", 1, NULL, 8}, {"log_prefix", 1, NULL, 9}, {"torus_config", 1, NULL, 10}, + {"pid_file", 1, NULL, 15}, {NULL, 0, NULL, 0} /* Required at the end of the array */ }; @@ -1047,6 +1051,9 @@ int main(int argc, char *argv[]) SET_STR_OPT(opt.torus_conf_file, optarg); printf("Torus-2QoS config file = %s\n", opt.torus_conf_file); break; + case 15: + SET_STR_OPT(opt.pid_file, optarg); + break; case 'h': case '?': case ':': @@ -1116,6 +1123,14 @@ int main(int argc, char *argv[]) setup_signals(); + FILE *f = fopen(opt.pid_file, "w"); + if (f == NULL) + printf("Couldn't create pid file \"%s\"\n", opt.pid_file); + else { + fprintf(f, "%ld\n", (long) getpid()); + fclose(f); + } + osm_opensm_sweep(&osm); if (run_once_flag == TRUE) { @@ -1147,6 +1162,7 @@ int main(int argc, char *argv[]) } Exit: + unlink(opt.pid_file); osm_opensm_destroy(&osm); complib_exit(); diff --git a/opensm/osm_subnet.c b/opensm/osm_subnet.c index 0b79d3a..3de622e 100644 --- a/opensm/osm_subnet.c +++ b/opensm/osm_subnet.c @@ -404,6 +404,7 @@ static const opt_rec_t opt_tbl[] = { { "no_clients_rereg", OPT_OFFSET(no_clients_rereg), opts_parse_boolean, NULL, 1 }, { "prefix_routes_file", OPT_OFFSET(prefix_routes_file), opts_parse_charp, NULL, 0 }, { "consolidate_ipv6_snm_req", OPT_OFFSET(consolidate_ipv6_snm_req), opts_parse_boolean, NULL, 1 }, + { "pid_file", OPT_OFFSET(pid_file), opts_parse_charp, NULL, 0}, { "lash_start_vl", OPT_OFFSET(lash_start_vl), opts_parse_uint8, NULL, 1 }, { "sm_sl", OPT_OFFSET(sm_sl), opts_parse_uint8, NULL, 1 }, { "log_prefix", OPT_OFFSET(log_prefix), opts_parse_charp, NULL, 1 }, @@ -791,6 +792,7 @@ void osm_subn_set_default_opt(IN osm_subn_opt_t * p_opt) p_opt->no_clients_rereg = FALSE; p_opt->prefix_routes_file = strdup(OSM_DEFAULT_PREFIX_ROUTES_FILE); p_opt->consolidate_ipv6_snm_req = FALSE; + p_opt->pid_file = strdup(OSM_DEFAULT_PID_FILE); p_opt->lash_start_vl = 0; p_opt->sm_sl = OSM_DEFAULT_SL; p_opt->log_prefix = NULL; diff --git a/scripts/opensm.init.in b/scripts/opensm.init.in index 0c84bd3..f8bbfb1 100644 --- a/scripts/opensm.init.in +++ b/scripts/opensm.init.in @@ -42,6 +42,9 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ +piddir=@piddir@ + +PIDFILE=${piddir}/opensm.pid # Source function library. if [[ -s /etc/init.d/functions ]]; then @@ -74,7 +77,7 @@ start () { stop () { echo -n "Shutting down opensm: " - killproc opensm + killproc -p $PIDFILE opensm if [[ $RETVAL -eq 0 ]]; then rm -f /var/lock/subsys/opensm success