1 /*****************************************************************************\
2  *  connection_functions.c - Interface to functions dealing with connections
3  *                           to the database.
4  ******************************************************************************
5  *  Copyright (C) 2010 Lawrence Livermore National Security.
6  *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
7  *  Written by Danny Auble da@llnl.gov, et. al.
8  *  CODE-OCEC-09-009. All rights reserved.
9  *
10  *  This file is part of Slurm, a resource management program.
11  *  For details, see <https://slurm.schedmd.com/>.
12  *  Please also read the included file: DISCLAIMER.
13  *
14  *  Slurm is free software; you can redistribute it and/or modify it under
15  *  the terms of the GNU General Public License as published by the Free
16  *  Software Foundation; either version 2 of the License, or (at your option)
17  *  any later version.
18  *
19  *  In addition, as a special exception, the copyright holders give permission
20  *  to link the code of portions of this program with the OpenSSL library under
21  *  certain conditions as described in each individual source file, and
22  *  distribute linked combinations including the two. You must obey the GNU
23  *  General Public License in all respects for all of the code used other than
24  *  OpenSSL. If you modify file(s) with this exception, you may extend this
25  *  exception to your version of the file(s), but you are not obligated to do
26  *  so. If you do not wish to do so, delete this exception statement from your
27  *  version.  If you delete this exception statement from all source files in
28  *  the program, then also delete it here.
29  *
30  *  Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
31  *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
32  *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
33  *  details.
34  *
35  *  You should have received a copy of the GNU General Public License along
36  *  with Slurm; if not, write to the Free Software Foundation, Inc.,
37  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
38 \*****************************************************************************/
39 
40 #include "slurm/slurm.h"
41 #include "slurm/slurm_errno.h"
42 #include "slurm/slurmdb.h"
43 
44 #include "src/common/slurm_accounting_storage.h"
45 /*
46  * get a new connection to the slurmdb
47  * RET: pointer used to access db
48  */
slurmdb_connection_get(void)49 extern void *slurmdb_connection_get(void)
50 {
51 	char *cluster_name = slurm_get_cluster_name();
52 	void *db_conn = acct_storage_g_get_connection(NULL, 0, NULL,
53 						      1, cluster_name);
54 	xfree(cluster_name);
55 	return db_conn;
56 }
57 
58 /*
59  * get a new connection to the slurmdb
60  * OUT: persist_conn_flags - Flags returned from connection if any see
61  *                           slurm_persist_conn.h.
62  * RET: pointer used to access db
63  */
slurmdb_connection_get2(uint16_t * persist_conn_flags)64 extern void *slurmdb_connection_get2(uint16_t *persist_conn_flags)
65 {
66 	char *cluster_name = slurm_get_cluster_name();
67 	void *db_conn = acct_storage_g_get_connection(NULL, 0,
68 						      persist_conn_flags,
69 						      1, cluster_name);
70 	xfree(cluster_name);
71 	return db_conn;
72 }
73 
74 /*
75  * release connection to the storage unit
76  * IN/OUT: void ** pointer returned from
77  *         slurmdb_connection_get() which will be freed.
78  * RET: SLURM_SUCCESS on success SLURM_ERROR else
79  */
slurmdb_connection_close(void ** db_conn)80 extern int slurmdb_connection_close(void **db_conn)
81 {
82 	return acct_storage_g_close_connection(db_conn);
83 }
84 
85 /*
86  * commit or rollback changes made without closing connection
87  * IN: void * pointer returned from slurmdb_connection_get()
88  * IN: bool - true will commit changes false will rollback
89  * RET: SLURM_SUCCESS on success SLURM_ERROR else
90  */
slurmdb_connection_commit(void * db_conn,bool commit)91 extern int slurmdb_connection_commit(void *db_conn, bool commit)
92 {
93 	return acct_storage_g_commit(db_conn, commit);
94 }
95