Annotation of freem/src/tp_check.c, revision 1.6
1.1 snw 1: /*
1.6 ! snw 2: * $Id: tp_check.c,v 1.5 2025/04/09 19:52:02 snw Exp $
1.3 snw 3: * TP global checkpointing code
1.1 snw 4: *
5: *
1.2 snw 6: * Author: Serena Willis <snw@coherent-logic.com>
1.1 snw 7: * Copyright (C) 1998 MUG Deutschland
1.3 snw 8: * Copyright (C) 2022, 2025 Coherent Logic Development LLC
1.1 snw 9: *
10: *
11: * This file is part of FreeM.
12: *
13: * FreeM is free software: you can redistribute it and/or modify
14: * it under the terms of the GNU Affero Public License as published by
15: * the Free Software Foundation, either version 3 of the License, or
16: * (at your option) any later version.
17: *
18: * FreeM is distributed in the hope that it will be useful,
19: * but WITHOUT ANY WARRANTY; without even the implied warranty of
20: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21: * GNU Affero Public License for more details.
22: *
23: * You should have received a copy of the GNU Affero Public License
24: * along with FreeM. If not, see <https://www.gnu.org/licenses/>.
25: *
1.4 snw 26: * $Log: tp_check.c,v $
1.6 ! snw 27: * Revision 1.5 2025/04/09 19:52:02 snw
! 28: * Eliminate as many warnings as possible while building with -Wall
! 29: *
1.5 snw 30: * Revision 1.4 2025/03/22 18:43:54 snw
31: * Make STRLEN 255 chars and add BIGSTR macro for larger buffers
32: *
1.4 snw 33: * Revision 1.3 2025/03/09 19:50:47 snw
34: * Second phase of REUSE compliance and header reformat
35: *
1.3 snw 36: *
37: * SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC
38: * SPDX-License-Identifier: AGPL-3.0-or-later
1.1 snw 39: **/
40:
41: #include <stdlib.h>
42: #include <string.h>
43: #include <unistd.h>
44: #include "tp_check.h"
45: #include "mpsdef.h"
46: #include "transact.h"
47: #include "journal.h"
48: #include "fs.h"
49:
50: short frm_global_exists(char *, char *, char *);
51:
52: cptab *cptab_head[TP_MAX_NEST];
53:
54: cptab *cptab_insert(int tlevel, char *global)
55: {
56: cptab *t;
57: short g_exists;
58: char *gc_ns;
59: char *gc_pth;
60:
61: gc_ns = (char *) malloc (STRLEN * sizeof (char));
62: NULLPTRCHK(gc_ns,"cptab_insert");
63:
1.4 snw 64: gc_pth = (char *) malloc (PATHLEN * sizeof (char));
1.1 snw 65: NULLPTRCHK(gc_pth,"cptab_insert");
66:
67: for (t = cptab_head[tlevel]; t != NULL; t = t->next) {
68:
69: if ((strcmp (t->global, global) == 0) && (t->mode > CP_UNUSED)) {
70: /* found match */
71: return t;
72: }
73:
74: }
75:
76: /* insert */
77: t = (cptab *) malloc (sizeof (cptab));
78: NULLPTRCHK(t,"cptab_insert");
79:
80: t->global = (char *) malloc (sizeof (char) * (strlen (global) + 1));
81: NULLPTRCHK(t->global,"cptab_insert");
82:
83: strcpy (t->global, global);
84:
85: g_exists = frm_global_exists (gc_ns, gc_pth, global);
86:
87: t->file = (char *) malloc (sizeof (char) * (strlen (gc_pth)));
88: NULLPTRCHK(t->file,"cptab_insert");
89:
1.4 snw 90: t->cp_file = (char *) malloc (sizeof (char) * PATHLEN);
1.1 snw 91: NULLPTRCHK(t->cp_file,"cptab_insert");
92:
93: strcpy (t->file, gc_pth);
94: stcnv_m2c (t->file);
95:
1.6 ! snw 96: snprintf (t->cp_file, PATHLEN - 1, "%s.%d.%d.chk", t->file, pid, tp_level);
1.1 snw 97:
98: free (gc_ns);
99: free (gc_pth);
100:
101: if (!g_exists) {
102: t->mode = CP_REMOVE;
103: }
104: else {
105: t->mode = CP_RESTORE;
106: }
107:
108: t->next = cptab_head[tlevel];
109: cptab_head[tlevel] = t;
110:
111: return t;
112: }
113:
114: short cptab_precommit(int tlevel)
115: {
116: cptab *t;
117: /*char *cmd;*/
118: char *pctmp;
119: int rc;
120:
121: /*
122: cmd = (char *) malloc (STRLEN * sizeof (char));
123: NULLPTRCHK(cmd,"cptab_precommit");
124: */
125:
126: pctmp = (char *) malloc (STRLEN * sizeof (char));
127: NULLPTRCHK(pctmp,"cptab_precommit");
128:
129: for (t = cptab_head[tlevel]; t != NULL; t = t->next) {
130:
131: if (t->mode == CP_RESTORE) {
132:
133: /*
134: snprintf (cmd, STRLEN - 1, "/bin/cp %s %s", t->file, t->cp_file);
135: rc = system (cmd);
136: */
137:
138: rc = cp (t->cp_file, t->file);
139:
140: if (rc != 0) {
141:
142: strcpy (pctmp, t->file);
143: stcnv_c2m (pctmp);
144:
145: jnl_ent_write (JNLA_CHECKPOINT_FAIL, " \201", pctmp);
146:
147: /*free (cmd);*/
148: free (pctmp);
149:
150: return FALSE;
151:
152: }
153: else {
154:
155: strcpy (pctmp, t->file);
156: stcnv_c2m (pctmp);
157:
158: jnl_ent_write (JNLA_CHECKPOINT_OK, " \201", pctmp);
159:
160: }
161:
162: }
163:
164: }
165:
166: /*free (cmd);*/
167: free (pctmp);
168:
169: return TRUE;
170: }
171:
172: void cptab_postcommit(int tlevel)
173: {
174: cptab *t;
175: /*char *cmd;*/
176:
177: /*
178: cmd = (char *) malloc (STRLEN * sizeof (char));
179: NULLPTRCHK(cmd,"cptab_postcommit");
180: */
181:
182: for (t = cptab_head[tlevel]; t != NULL; t = t->next) {
183:
184: if (t->mode == CP_RESTORE) {
185: /*
186: snprintf (cmd, STRLEN - 1, "/bin/rm -f '%s'", t->cp_file);
187: rc = system (cmd);
188: */
189: unlink (t->cp_file);
190: }
191:
192: }
193:
194: cptab_head[tlevel] = NULL;
195: }
196:
197: short cptab_rollback(int tlevel)
198: {
199: cptab *t;
200: /*char *cmd;*/
201: int rc;
202:
203: /*
204: cmd = (char *) malloc (STRLEN * sizeof (char));
205: NULLPTRCHK(cmd,"cptab_rollback");
206: */
207:
208: for (t = cptab_head[tlevel]; t != NULL; t = t->next) {
209:
210: switch (t->mode) {
211:
212: case CP_REMOVE:
213: unlink (t->file);
214: /*
215: snprintf (cmd, STRLEN - 1, "/bin/rm -f '%s'", t->file);
216: rc = system (cmd);
217: */
218: break;
219:
220: case CP_RESTORE:
221: /*
222: snprintf (cmd, STRLEN - 1, "/bin/cp '%s' '%s'", t->cp_file, t->file);
223: rc = system (cmd);
224: */
1.6 ! snw 225: /* TODO: support OS/2 */
1.1 snw 226: rc = cp (t->file, t->cp_file);
227:
228: if (rc != 0) {
229: cptab_head[tlevel] = NULL;
230: /*free (cmd);*/
231: return FALSE;
232: }
233:
234: /*
235: snprintf (cmd, STRLEN - 1, "/bin/rm -f %s", t->cp_file);
236: rc = system (cmd);
237: */
238:
239: unlink (t->cp_file);
240: if (rc != 0) {
241: cptab_head[tlevel] = NULL;
242: /*free (cmd);*/
243: return FALSE;
244: }
245:
246: break;
247:
248:
249: }
250:
251: }
252:
253: cptab_head[tlevel] = NULL;
254:
255: return TRUE;
256:
257: }
258:
259: void cptab_dump(int tlevel)
260: {
261: cptab *gt;
262: char cp_mode[15];
263:
264: printf ("\n Global database checkpoints:\n");
265:
266: printf ("\n %-30s%-20s%s\n", "GLOBAL", "MODE", "FILES");
267: printf (" %-30s%-20s%s\n", "------", "----", "-----");
268:
269: for (gt = cptab_head[tlevel]; gt != NULL; gt = gt->next) {
270:
271: switch (gt->mode) {
272:
273: case CP_UNUSED:
274: strcpy (cp_mode, "CP_UNUSED");
275: break;
276:
277: case CP_REMOVE:
278: strcpy (cp_mode, "CP_REMOVE");
279: break;
280:
281: case CP_RESTORE:
282: strcpy (cp_mode, "CP_RESTORE");
283: break;
284:
285: }
286:
287: if (gt->mode > CP_UNUSED) {
288: printf (" %-30s%-20sIN: %s\n", gt->global, cp_mode, gt->file);
289: }
290: else {
291: printf (" N/A\n");
292: }
293:
294: if (gt->mode == CP_RESTORE) {
295: printf (" %-30s%-20sOUT: %s\n", "", "", gt->cp_file);
296: }
297:
298: }
299: }
300:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>