From 8409b6bf63eaf30a34fe5e8e844a86c6b6d0da83 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Mon, 26 Jan 2004 21:38:28 +0000
Subject: [PATCH] #define SLURM version information in slurm.h Export version
 info via new API

---
 NEWS                               | 10 ++++++++++
 acinclude.m4                       |  8 ++++----
 doc/man/Makefile.am                |  1 +
 doc/man/man3/slurm_api_version.3   |  1 +
 doc/man/man3/slurm_free_ctl_conf.3 | 25 ++++++++++++++++++++++---
 slurm/slurm.h.in                   | 28 ++++++++++++++++++++++++++++
 src/api/config_info.c              | 11 +++++++++++
 src/scontrol/scontrol.c            |  7 +++++++
 8 files changed, 84 insertions(+), 7 deletions(-)
 create mode 100644 doc/man/man3/slurm_api_version.3

diff --git a/NEWS b/NEWS
index efafa602879..6c9e56d81ac 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,16 @@ documents those changes that are of interest to users and admins.
  -- Updates to node pinging for large numbers of unresponsive nodes 
  -- Explicitly set default action for SIGTERM (action on Thunder was 
     to ignore SIGTERM)
+ -- Sinfo "--exact" option only applies to fields actually displayed
+ -- Partition processor count not correctly computed for heterogeneous 
+    clusters with FastSchedule=0 configuration
+ -- Only return DOWN nodes to service if the reason for them being in 
+    that state is non-responsiveness and "ReturnToService=1" configuration
+ -- Partition processor count now correctly computed for heterogeneous 
+    clusters with FastSchedule configured off
+ -- Only return DOWN nodes to service if the reason for them being in 
+    that state is non-responsiveness and ReturnToService configured on
+ -- New macros and function to export SLURM version number
 
 * Changes in SLURM 0.3.0.0-pre5
 ===============================
diff --git a/acinclude.m4 b/acinclude.m4
index 3d6f6742e66..6fbf93b15c7 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -139,12 +139,12 @@ else
    SLURM_VERSION="$MAJOR.$MINOR.$MICRO"
    test $RELEASE = "1" || SLURM_VERSION="$SLURM_VERSION-$SLURM_RELEASE"
 fi
-AC_DEFINE_UNQUOTED(SLURM_MAJOR, "$MAJOR", 
+AC_DEFINE_UNQUOTED(SLURM_MAJOR, $MAJOR, 
                    [Define the project's major version.])
-AC_DEFINE_UNQUOTED(SLURM_MINOR, "$MINOR",
-                   [Define the project's minor version.])
-AC_DEFINE_UNQUOTED(SLURM_MICRO, "$MICRO",
+AC_DEFINE_UNQUOTED(SLURM_MINOR, $MINOR,
                    [Define the project's minor version.])
+AC_DEFINE_UNQUOTED(SLURM_MICRO, $MICRO,
+                   [Define the project's micro version.])
 AC_DEFINE_UNQUOTED(RELEASE, "$RELEASE", [Define the project's release.])
 AC_DEFINE_UNQUOTED(SLURM_VERSION, "$SLURM_VERSION",
                    [Define the project's version string.])
diff --git a/doc/man/Makefile.am b/doc/man/Makefile.am
index 0a83195940f..dcd95fbfd5a 100644
--- a/doc/man/Makefile.am
+++ b/doc/man/Makefile.am
@@ -14,6 +14,7 @@ man3_MANS = man3/hostlist_create.3 \
 	man3/hostlist_shift.3 \
 	man3/slurm_allocate_resources.3 \
 	man3/slurm_allocate_resources_and_run.3 \
+	man3/slurm_api_version.3 \
 	man3/slurm_complete_job.3 \
 	man3/slurm_complete_job_step.3 \
 	man3/slurm_confirm_allocation.3 \
diff --git a/doc/man/man3/slurm_api_version.3 b/doc/man/man3/slurm_api_version.3
new file mode 100644
index 00000000000..a267130db6e
--- /dev/null
+++ b/doc/man/man3/slurm_api_version.3
@@ -0,0 +1 @@
+.so man3/slurm_free_ctl_conf.3
diff --git a/doc/man/man3/slurm_free_ctl_conf.3 b/doc/man/man3/slurm_free_ctl_conf.3
index cddf4aad87a..a68dee0286e 100644
--- a/doc/man/man3/slurm_free_ctl_conf.3
+++ b/doc/man/man3/slurm_free_ctl_conf.3
@@ -1,4 +1,4 @@
-.TH "Slurm API" "3" "September 2003" "Morris Jette" "Slurm informational calls"
+.TH "Slurm API" "3" "January 2004" "Morris Jette" "Slurm informational calls"
 .SH "NAME"
 slurm_free_ctl_conf, slurm_load_ctl_conf, 
 slurm_print_ctl_conf\- Slurm information reporting functions
@@ -7,6 +7,8 @@ slurm_print_ctl_conf\- Slurm information reporting functions
 #include <stdio.h>
 .br
 #include <slurm/slurm.h>
+.LP
+long \fBslurm_api_version\fR ();
 .LP 
 void \fBslurm_free_ctl_conf\fR (
 .br 
@@ -50,6 +52,8 @@ greater than the last time changes where made to that information, new informati
 is not returned.  Otherwise all the configuration. job, node, or partition records 
 are returned.
 .SH "DESCRIPTION"
+.LP
+\fBslurm_api_version\fR Return the SLURM API version number.
 .LP 
 \fBslurm_free_ctl_conf\fR Release the storage generated by the 
 \fBslurm_load_ctl_conf\fR function.
@@ -61,8 +65,9 @@ Slurm configuration records.
 \fBslurm_load_ctl_conf\fR function.
 .SH "RETURN VALUE"
 .LP
-On success, zero is returned. On error, -1 is returned, and Slurm error code
-is set appropriately.
+For \fBslurm_api_version\fR the SLURM API version number is returned. 
+All other functions return zero on success and -1 on error with the 
+SLURM error code set appropriately.
 .SH "ERRORS"
 .LP
 \fBSLURM_NO_CHANGE_IN_DATA\fR Data has not changed since \fBupdate_time\fR.
@@ -84,6 +89,20 @@ int main (int argc, char *argv[])
 {
 .br
 	slurm_ctl_conf_info_msg_t * conf_info_msg_ptr = NULL;
+.br
+	long version = slurm_api_version;
+.LP
+	/* We can use the SLURM version number to determine how 
+.br
+	 * API should be used */
+.br
+	printf("slurm_api_version: %ld, %ld.%ld.%ld\\n", version,
+.br
+		SLURM_VERSION_MAJOR(version),
+.br
+		SLURM_VERSION_MINOR(version),
+.br
+		SLURM_VERSION_MICRO(version));
 .LP
 	/* get and print some configuration information */
 .br
diff --git a/slurm/slurm.h.in b/slurm/slurm.h.in
index 5d3c9c068a4..de970272f78 100644
--- a/slurm/slurm.h.in
+++ b/slurm/slurm.h.in
@@ -92,6 +92,26 @@ BEGIN_C_DECLS
    typedef struct switch_jobinfo *switch_jobinfo_t;	/* opaque data type */
 #endif
 
+/*****************************************************************************\
+ *      DEFINITIONS FOR VERSION MANAGEMENT
+\*****************************************************************************/
+
+#ifndef SLURM_MAJOR
+/* Define the project's major version. */
+#undef SLURM_MAJOR
+
+/* Define the project's minor version. */
+#undef SLURM_MINOR
+
+/* Define the project's micro version. */
+#undef SLURM_MICRO
+#endif
+
+#define SLURM_VERSION_NUM(a,b,c) (((a) << 16) + ((b) << 8) + (c))
+#define SLURM_VERSION_MAJOR(a)   (((a) >> 16) & 0xff)
+#define SLURM_VERSION_MINOR(a)   (((a) >>  8) & 0xff)
+#define SLURM_VERSION_MICRO(a)    ((a)        & 0xff)
+
 /*****************************************************************************\
  *	DEFINITIONS FOR INPUT VALUES
 \*****************************************************************************/
@@ -607,6 +627,14 @@ extern int slurm_complete_job_step PARAMS((
  *	SLURM CONTROL CONFIGURATION READ/PRINT/UPDATE FUNCTIONS
 \*****************************************************************************/
 
+/*
+ * slurm_api_version - Return a single number reflecting the SLURM API's 
+ *	version number. Use the macros SLURM_VERSION_NUM, SLURM_VERSION_MAJOR, 
+ *	SLURM_VERSION_MINOR, and SLURM_VERSION_MICRO to work with this value
+ * RET API's version number
+ */
+extern long slurm_api_version PARAMS((void));
+
 /*
  * make_time_str - convert time_t to string with "month/date hour:min:sec" 
  * IN time - a time stamp
diff --git a/src/api/config_info.c b/src/api/config_info.c
index ab991af97fd..2a0b50d9fb5 100644
--- a/src/api/config_info.c
+++ b/src/api/config_info.c
@@ -37,6 +37,17 @@
 #include "src/api/job_info.h"
 #include "src/common/slurm_protocol_api.h"
 
+/*
+ * slurm_api_version - Return a single number reflecting the SLURM API's 
+ *      version number. Use the macros SLURM_VERSION_NUM, SLURM_VERSION_MAJOR, 
+ *      SLURM_VERSION_MINOR, and SLURM_VERSION_MICRO to work with this value
+ * RET API's version number
+ */
+extern long slurm_api_version (void)
+{
+	return (long) SLURM_VERSION_NUM(SLURM_MAJOR, SLURM_MINOR, SLURM_MICRO);
+}
+
 /*
  * slurm_print_ctl_conf - output the contents of slurm control configuration 
  *	message as loaded using slurm_load_ctl_conf
diff --git a/src/scontrol/scontrol.c b/src/scontrol/scontrol.c
index bf1ae659b21..35a1a1f1306 100644
--- a/src/scontrol/scontrol.c
+++ b/src/scontrol/scontrol.c
@@ -182,6 +182,13 @@ main (int argc, char *argv[])
 static void _print_version(void)
 {
 	printf("%s %s\n", PACKAGE, SLURM_VERSION);
+	if (quiet_flag == -1) {
+		long version = slurm_api_version();
+		printf("slurm_api_version: %ld, %ld.%ld.%ld\n", version,
+			SLURM_VERSION_MAJOR(version), 
+			SLURM_VERSION_MINOR(version),
+			SLURM_VERSION_MICRO(version));
+	}
 }
 
 
-- 
GitLab