Changeset 1362 in MondoRescue
- Timestamp:
- Apr 30, 2007, 12:27:56 AM (18 years ago)
- Location:
- branches/stable
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mondo/src/common/libmondo-stream.c
r1175 r1362 35 35 extern char *g_getfacl; 36 36 extern char *g_getfattr; 37 extern char *MONDO_LOGFILE; 37 38 38 39 /** … … 60 61 61 62 /** 63 * An entry in the tape catalog. 64 */ 65 struct s_tapecat_entry { 66 /** 67 * The type of archive it is (afioball, slice, or something else). 68 */ 69 t_archtype type; 70 71 /** 72 * The filelist number or biggiefile (not slice!) number. 73 */ 74 int number; 75 76 /** 77 * The slice number if it's a biggiefile. 78 */ 79 long aux; 80 81 /** 82 * The tape position at the point this entry was added. 83 */ 84 long long tape_posK; 85 86 /** 87 * The filename of the file cataloged here. 88 */ 89 char *fname; 90 }; 91 92 93 /* 62 94 * The tape catalog that keeps track of files written to tape. 63 */ 64 struct s_tapecatalog *g_tapecatalog; 95 * made of a list of @p s_tapecat_entry. 96 * */ 97 static struct mr_list *g_tapecatalog; 98 99 /* function to free the fname field allocated in te */ 100 static void mr_free_te(void *data) { 101 102 struct s_tapecat_entry *te = NULL; 103 104 te = (struct s_tapecat_entry *)data; 105 mr_free(te->fname); 106 } 65 107 66 108 /* @} - end of globalGroup */ 67 109 68 110 int write_backcatalog_to_tape(struct s_bkpinfo *bkpinfo); 69 70 71 72 111 73 112 … … 138 177 } 139 178 mr_free(blk); 140 mr_free(g_tapecatalog); 179 mr_free_fname(g_tapecatalog); 180 mr_list_free(g_tapecatalog); 141 181 return (retval); 142 182 } … … 159 199 int i = 0; 160 200 char *blk = NULL; 201 struct mr_list_elt *elt = NULL; 202 struct s_tapecat_entry *te = NULL; 161 203 162 204 blk = (char *) mr_malloc(256 * 1024); … … 184 226 paranoid_pclose(g_tape_stream); 185 227 log_it("closeout_tape() -- leaving"); 186 for (i = 0; i < g_tapecatalog->entries; i++) { 228 elt = g_tapecatalog->first; 229 while (elt != NULL) { 230 te = (struct s_tapecat_entry *)elt->data; 187 231 log_it("i=%d type=%s num=%d aux=%ld posK=%lld", i, 188 ( g_tapecatalog->el[i].type ==189 fileset) ? "fileset" : "bigslice",190 g_tapecatalog->el[i].number, g_tapecatalog->el[i].aux,191 g_tapecatalog->el[i].tape_posK);232 (te->type == fileset) ? "fileset" : "bigslice", 233 te->number, te->aux, te->tape_posK); 234 i++; 235 elt = elt->next; 192 236 } 193 237 mr_free(blk); 194 mr_free(g_tapecatalog); 238 mr_free_fname(g_tapecatalog); 239 mr_list_free(g_tapecatalog); 195 240 return (retval); 196 241 } … … 468 513 char *tmpdir = NULL; 469 514 char *old_fname = NULL; 515 struct mr_list_elt *elt = NULL; 516 struct s_tapecat_entry *te = NULL; 470 517 471 518 bufsize_K = (long long) (1024LL * (1 + g_tape_buffer_size_MB)); … … 489 536 mr_free(command); 490 537 491 last = g_tapecatalog->entries- 1;538 last = mr_list_length(g_tapecatalog) - 1; 492 539 if (last <= 0) { 493 540 iamhere("Too early to start deleting from collection."); 494 541 return (0); 495 542 } 496 final_alleged_writeK = g_tapecatalog->el[last].tape_posK; 543 elt = g_tapecatalog->last; 544 te = (struct s_tapecat_entry *)elt->data; 545 final_alleged_writeK = te->tape_posK; 497 546 final_projected_certain_writeK = final_alleged_writeK - bufsize_K; 498 for (curr = last; curr >= 0; curr--) { 499 cposK = g_tapecatalog->el[curr].tape_posK; 547 while (elt != NULL) { 548 te = (struct s_tapecat_entry *)elt->data; 549 cposK = te->tape_posK; 500 550 if (cposK < final_projected_certain_writeK) { 501 551 final_actually_certain_writeK = cposK; 502 552 break; 503 553 } 504 } 505 if (curr < 0) { 554 elt = elt->prev; 555 } 556 if (elt == NULL) { 506 557 iamhere 507 558 ("Not far enough into tape to start deleting old archives from collection."); 508 559 return (0); 509 560 } 510 // log_it( "There are %lld KB (more than %d KB) in my backcatalog", final_alleged_writeK - final_actually_certain_writeK, bufsize_K); 511 512 for (i = curr - 1; i >= 0 && curr - i < 10; i--) { 513 mr_asprintf(&old_fname, "%s/%s", tmpdir, g_tapecatalog->el[i].fname); 561 562 elt = elt->prev; 563 i = 0; 564 while ((elt != NULL) && (i < 10)) { 565 te = (struct s_tapecat_entry *)elt->data; 566 mr_asprintf(&old_fname, "%s/%s", tmpdir, te->fname); 514 567 unlink(old_fname); 515 568 mr_free(old_fname); 569 elt = elt->prev; 570 i++; 516 571 } 517 572 mr_free(tmpdir); … … 585 640 586 641 assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device); 587 g_tapecatalog = mr_malloc(sizeof(struct s_tapecatalog)); 588 g_tapecatalog->entries = 0; 642 mr_list_alloc(g_tapecatalog); 589 643 g_tape_posK = 0; 590 644 if (g_tape_stream) { … … 682 736 /* initialise the catalog */ 683 737 g_current_media_number = 1; 684 g_tapecatalog = mr_malloc(sizeof(struct s_tapecatalog)); 685 g_tapecatalog->entries = 0; 738 mr_list_alloc(g_tapecatalog); 686 739 /* log stuff */ 687 740 log_it("Opening OUT cdstream with the command"); … … 713 766 return (0); 714 767 } 715 g_tapecatalog = mr_malloc(sizeof(struct s_tapecatalog)); 716 g_tapecatalog->entries = 0; 768 mr_list_alloc(g_tapecatalog); 717 769 g_tape_posK = 0; 718 770 … … 1006 1058 char *fn) 1007 1059 { 1008 int last; 1009 char fname[MAX_TAPECAT_FNAME_LEN]; 1010 char *p; 1060 char *fname = NULL; 1061 char *p = NULL; 1062 struct s_tapecat_entry *te = NULL; 1063 struct mr_list_elt *elt = NULL; 1011 1064 1012 1065 p = strrchr(fn, '/'); … … 1016 1069 p = fn; 1017 1070 } 1018 strncpy(fname, p, MAX_TAPECAT_FNAME_LEN); 1019 fname[MAX_TAPECAT_FNAME_LEN] = '\0'; 1020 last = g_tapecatalog->entries; 1021 if (last >= MAX_TAPECATALOG_ENTRIES) { 1022 log_it 1023 ("Warning - can't log #%d in tape catalog - too many entries already", 1024 number); 1025 return (-1); 1026 } 1027 g_tapecatalog->el[last].type = type; 1028 g_tapecatalog->el[last].number = number; 1029 g_tapecatalog->el[last].aux = aux; 1030 g_tapecatalog->el[last].tape_posK = g_tape_posK; 1031 strcpy(g_tapecatalog->el[last].fname, fname); 1032 g_tapecatalog->entries++; 1033 return (last); // returns the index of the record we've jsut added 1071 mr_asprintf(&fname, p); 1072 1073 te = (struct s_tapecat_entry *)mr_malloc(sizeof(struct s_tapecat_entry)); 1074 te->type = type; 1075 te->number = number; 1076 te->aux = aux; 1077 te->tape_posK = g_tape_posK; 1078 /* BERLIOS: Check if this is written womewhere, as it's only a pointer */ 1079 /* BERLIOS: Verify to purge fname correctly */ 1080 te->fname = fname; 1081 1082 /* place the data in a list elt */ 1083 mr_list_alloc_elt(elt, (void *)te, mr_free_te); 1084 mr_list_add_elt_last(elt); 1085 1086 // returns the index of the record we've just added 1087 return (mr_list_length(g_tapecatalog)); 1034 1088 } 1035 1089 … … 1304 1358 int i, last, res = 0; 1305 1359 char *fname = NULL; 1360 struct mr_list_elt *elt = NULL; 1361 struct s_tapecat_entry *te = NULL; 1306 1362 1307 1363 mr_msg(2, "I am now writing back catalog to tape"); 1308 last = g_tapecatalog->entries - 1;1309 for (i = 0; i <= last; i++) {1310 mr_asprintf(&fname, "%s/tmpfs/backcatalog/%s", bkpinfo->tmpdir,1311 g_tapecatalog->el[i].fname);1364 elt = g_tapecatalog->first; 1365 while (elt != NULL) { 1366 te = (struct s_tapecat_entry *) elt->data; 1367 mr_asprintf(&fname, "%s/tmpfs/backcatalog/%s", bkpinfo->tmpdir, te->fname); 1312 1368 if (!does_file_exist(fname)) { 1313 1369 mr_msg(6, "Can't write %s - it doesn't exist.", fname); … … 1328 1384 } 1329 1385 mr_free(fname); 1386 elt = elt->next; 1330 1387 } 1331 1388 mr_msg(2, "Finished writing back catalog to tape"); -
branches/stable/mondo/src/common/mondostructures.h
r1297 r1362 789 789 char fname[MAX_TAPECAT_FNAME_LEN + 1]; 790 790 }; 791 792 /**793 * A tape catalog, made of a list of @p s_tapecat_entry.794 */795 struct s_tapecatalog {796 /**797 * The number of entries in the tape catalog.798 */799 int entries;800 801 /**802 * The entries themselves, all @p entries of them.803 */804 struct s_tapecat_entry el[MAX_TAPECATALOG_ENTRIES];805 }; -
branches/stable/mondo/src/include/my-stuff.h
r1264 r1362 214 214 */ 215 215 #define WELCOME_STRING _("W E L C O M E T O M O N D O R E S C U E") 216 217 /**218 * The maximum length of a filename in the tape catalog.219 */220 #define MAX_TAPECAT_FNAME_LEN 32221 222 /**223 * Compatibility #define to ease the transition to logfile-in-a-variable.224 */225 #define MONDO_LOGFILE "/var/log/mondo-archive.log"226 216 227 217 /**
Note:
See TracChangeset
for help on using the changeset viewer.