Annotation of freem/src/tp_check.c, revision 1.4
1.1 snw 1: /*
1.4 ! snw 2: * $Id: tp_check.c,v 1.3 2025/03/09 19:50:47 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 $
! 27: * Revision 1.3 2025/03/09 19:50:47 snw
! 28: * Second phase of REUSE compliance and header reformat
! 29: *
1.3 snw 30: *
31: * SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC
32: * SPDX-License-Identifier: AGPL-3.0-or-later
1.1 snw 33: **/
34:
35: #include <stdlib.h>
36: #include <string.h>
37: #include <unistd.h>
38: #include "tp_check.h"
39: #include "mpsdef.h"
40: #include "transact.h"
41: #include "journal.h"
42: #include "fs.h"
43:
44: short frm_global_exists(char *, char *, char *);
45:
46: cptab *cptab_head[TP_MAX_NEST];
47:
48: cptab *cptab_insert(int tlevel, char *global)
49: {
50: cptab *t;
51: char mode;
52:
53: short g_exists;
54:
55: char *gc_ns;
56: char *gc_pth;
57:
58: gc_ns = (char *) malloc (STRLEN * sizeof (char));
59: NULLPTRCHK(gc_ns,"cptab_insert");
60:
1.4 ! snw 61: gc_pth = (char *) malloc (PATHLEN * sizeof (char));
1.1 snw 62: NULLPTRCHK(gc_pth,"cptab_insert");
63:
64: for (t = cptab_head[tlevel]; t != NULL; t = t->next) {
65:
66: if ((strcmp (t->global, global) == 0) && (t->mode > CP_UNUSED)) {
67: /* found match */
68: return t;
69: }
70:
71: }
72:
73: /* insert */
74: t = (cptab *) malloc (sizeof (cptab));
75: NULLPTRCHK(t,"cptab_insert");
76:
77: t->global = (char *) malloc (sizeof (char) * (strlen (global) + 1));
78: NULLPTRCHK(t->global,"cptab_insert");
79:
80: strcpy (t->global, global);
81:
82: g_exists = frm_global_exists (gc_ns, gc_pth, global);
83:
84: t->file = (char *) malloc (sizeof (char) * (strlen (gc_pth)));
85: NULLPTRCHK(t->file,"cptab_insert");
86:
1.4 ! snw 87: t->cp_file = (char *) malloc (sizeof (char) * PATHLEN);
1.1 snw 88: NULLPTRCHK(t->cp_file,"cptab_insert");
89:
90: strcpy (t->file, gc_pth);
91: stcnv_m2c (t->file);
92:
1.4 ! snw 93: snprintf (t->cp_file, PATHLEN, "%s.%d.%d.chk", t->file, pid, tp_level);
1.1 snw 94:
95: free (gc_ns);
96: free (gc_pth);
97:
98: if (!g_exists) {
99: t->mode = CP_REMOVE;
100: }
101: else {
102: t->mode = CP_RESTORE;
103: }
104:
105: t->next = cptab_head[tlevel];
106: cptab_head[tlevel] = t;
107:
108: return t;
109: }
110:
111: short cptab_precommit(int tlevel)
112: {
113: cptab *t;
114: /*char *cmd;*/
115: char *pctmp;
116: int rc;
117:
118: /*
119: cmd = (char *) malloc (STRLEN * sizeof (char));
120: NULLPTRCHK(cmd,"cptab_precommit");
121: */
122:
123: pctmp = (char *) malloc (STRLEN * sizeof (char));
124: NULLPTRCHK(pctmp,"cptab_precommit");
125:
126: for (t = cptab_head[tlevel]; t != NULL; t = t->next) {
127:
128: if (t->mode == CP_RESTORE) {
129:
130: /*
131: snprintf (cmd, STRLEN - 1, "/bin/cp %s %s", t->file, t->cp_file);
132: rc = system (cmd);
133: */
134:
135: rc = cp (t->cp_file, t->file);
136:
137: if (rc != 0) {
138:
139: strcpy (pctmp, t->file);
140: stcnv_c2m (pctmp);
141:
142: jnl_ent_write (JNLA_CHECKPOINT_FAIL, " \201", pctmp);
143:
144: /*free (cmd);*/
145: free (pctmp);
146:
147: return FALSE;
148:
149: }
150: else {
151:
152: strcpy (pctmp, t->file);
153: stcnv_c2m (pctmp);
154:
155: jnl_ent_write (JNLA_CHECKPOINT_OK, " \201", pctmp);
156:
157: }
158:
159: }
160:
161: }
162:
163: /*free (cmd);*/
164: free (pctmp);
165:
166: return TRUE;
167: }
168:
169: void cptab_postcommit(int tlevel)
170: {
171: cptab *t;
172: /*char *cmd;*/
173: int rc;
174:
175: /*
176: cmd = (char *) malloc (STRLEN * sizeof (char));
177: NULLPTRCHK(cmd,"cptab_postcommit");
178: */
179:
180: for (t = cptab_head[tlevel]; t != NULL; t = t->next) {
181:
182: if (t->mode == CP_RESTORE) {
183: /*
184: snprintf (cmd, STRLEN - 1, "/bin/rm -f '%s'", t->cp_file);
185: rc = system (cmd);
186: */
187: unlink (t->cp_file);
188: }
189:
190: }
191:
192: cptab_head[tlevel] = NULL;
193: }
194:
195: short cptab_rollback(int tlevel)
196: {
197: cptab *t;
198: /*char *cmd;*/
199: int rc;
200:
201: /*
202: cmd = (char *) malloc (STRLEN * sizeof (char));
203: NULLPTRCHK(cmd,"cptab_rollback");
204: */
205:
206: for (t = cptab_head[tlevel]; t != NULL; t = t->next) {
207:
208: switch (t->mode) {
209:
210: case CP_REMOVE:
211: unlink (t->file);
212: /*
213: snprintf (cmd, STRLEN - 1, "/bin/rm -f '%s'", t->file);
214: rc = system (cmd);
215: */
216: break;
217:
218: case CP_RESTORE:
219: /*
220: snprintf (cmd, STRLEN - 1, "/bin/cp '%s' '%s'", t->cp_file, t->file);
221: rc = system (cmd);
222: */
223: rc = cp (t->file, t->cp_file);
224:
225: if (rc != 0) {
226: cptab_head[tlevel] = NULL;
227: /*free (cmd);*/
228: return FALSE;
229: }
230:
231: /*
232: snprintf (cmd, STRLEN - 1, "/bin/rm -f %s", t->cp_file);
233: rc = system (cmd);
234: */
235:
236: unlink (t->cp_file);
237: if (rc != 0) {
238: cptab_head[tlevel] = NULL;
239: /*free (cmd);*/
240: return FALSE;
241: }
242:
243: break;
244:
245:
246: }
247:
248: }
249:
250: cptab_head[tlevel] = NULL;
251:
252: return TRUE;
253:
254: }
255:
256: void cptab_dump(int tlevel)
257: {
258: cptab *gt;
259: char cp_mode[15];
260:
261: printf ("\n Global database checkpoints:\n");
262:
263: printf ("\n %-30s%-20s%s\n", "GLOBAL", "MODE", "FILES");
264: printf (" %-30s%-20s%s\n", "------", "----", "-----");
265:
266: for (gt = cptab_head[tlevel]; gt != NULL; gt = gt->next) {
267:
268: switch (gt->mode) {
269:
270: case CP_UNUSED:
271: strcpy (cp_mode, "CP_UNUSED");
272: break;
273:
274: case CP_REMOVE:
275: strcpy (cp_mode, "CP_REMOVE");
276: break;
277:
278: case CP_RESTORE:
279: strcpy (cp_mode, "CP_RESTORE");
280: break;
281:
282: }
283:
284: if (gt->mode > CP_UNUSED) {
285: printf (" %-30s%-20sIN: %s\n", gt->global, cp_mode, gt->file);
286: }
287: else {
288: printf (" N/A\n");
289: }
290:
291: if (gt->mode == CP_RESTORE) {
292: printf (" %-30s%-20sOUT: %s\n", "", "", gt->cp_file);
293: }
294:
295: }
296: }
297:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>