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