Changeset 1362


Ignore:
Timestamp:
Apr 30, 2007, 12:27:56 AM (12 years ago)
Author:
bruno
Message:
  • 2.2.3 announce
  • In stable, replacement of a big structure for g_tapecatalog by a chained list (idea of M. Loiseleur). This removes some fixed allocations and should allow for easier debug for tape env.
Location:
branches/stable
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/common/libmondo-stream.c

    r1175 r1362  
    3535extern char *g_getfacl;
    3636extern char *g_getfattr;
     37extern char *MONDO_LOGFILE;
    3738
    3839/**
     
    6061
    6162/**
     63 * An entry in the tape catalog.
     64 */
     65struct 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/*
    6294 * 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 * */
     97static struct mr_list *g_tapecatalog;
     98
     99/* function to free the fname field allocated in te */
     100static 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}
    65107
    66108/* @} - end of globalGroup */
    67109
    68110int write_backcatalog_to_tape(struct s_bkpinfo *bkpinfo);
    69 
    70 
    71 
    72111
    73112
     
    138177    }
    139178    mr_free(blk);
    140     mr_free(g_tapecatalog);
     179    mr_free_fname(g_tapecatalog);
     180    mr_list_free(g_tapecatalog);
    141181    return (retval);
    142182}
     
    159199    int i = 0;
    160200    char *blk = NULL;
     201    struct mr_list_elt *elt = NULL;
     202    struct s_tapecat_entry *te = NULL;
    161203
    162204    blk = (char *) mr_malloc(256 * 1024);
     
    184226    paranoid_pclose(g_tape_stream);
    185227    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;
    187231        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;
    192236    }
    193237    mr_free(blk);
    194     mr_free(g_tapecatalog);
     238    mr_free_fname(g_tapecatalog);
     239    mr_list_free(g_tapecatalog);
    195240    return (retval);
    196241}
     
    468513    char *tmpdir = NULL;
    469514    char *old_fname = NULL;
     515    struct mr_list_elt *elt = NULL;
     516    struct s_tapecat_entry *te = NULL;
    470517
    471518    bufsize_K = (long long) (1024LL * (1 + g_tape_buffer_size_MB));
     
    489536    mr_free(command);
    490537
    491     last = g_tapecatalog->entries - 1;
     538    last = mr_list_length(g_tapecatalog) - 1;
    492539    if (last <= 0) {
    493540        iamhere("Too early to start deleting from collection.");
    494541        return (0);
    495542    }
    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;
    497546    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;
    500550        if (cposK < final_projected_certain_writeK) {
    501551            final_actually_certain_writeK = cposK;
    502552            break;
    503553        }
    504     }
    505     if (curr < 0) {
     554        elt = elt->prev;
     555    }
     556    if (elt == NULL) {
    506557        iamhere
    507558            ("Not far enough into tape to start deleting old archives from collection.");
    508559        return (0);
    509560    }
    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);
    514567        unlink(old_fname);
    515568        mr_free(old_fname);
     569        elt = elt->prev;
     570        i++;
    516571    }
    517572    mr_free(tmpdir);
     
    585640
    586641    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);
    589643    g_tape_posK = 0;
    590644    if (g_tape_stream) {
     
    682736    /*  initialise the catalog */
    683737    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);
    686739    /* log stuff */
    687740    log_it("Opening OUT cdstream with the command");
     
    713766        return (0);
    714767    }
    715     g_tapecatalog = mr_malloc(sizeof(struct s_tapecatalog));
    716     g_tapecatalog->entries = 0;
     768    mr_list_alloc(g_tapecatalog);
    717769    g_tape_posK = 0;
    718770
     
    10061058                             char *fn)
    10071059{
    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;
    10111064
    10121065    p = strrchr(fn, '/');
     
    10161069        p = fn;
    10171070    }
    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));
    10341088}
    10351089
     
    13041358    int i, last, res = 0;
    13051359    char *fname = NULL;
     1360    struct mr_list_elt *elt = NULL;
     1361    struct s_tapecat_entry *te = NULL;
    13061362
    13071363    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);
    13121368        if (!does_file_exist(fname)) {
    13131369            mr_msg(6, "Can't write %s - it doesn't exist.", fname);
     
    13281384        }
    13291385        mr_free(fname);
     1386        elt = elt->next;
    13301387    }
    13311388    mr_msg(2, "Finished writing back catalog to tape");
  • branches/stable/mondo/src/common/mondostructures.h

    r1297 r1362  
    789789    char fname[MAX_TAPECAT_FNAME_LEN + 1];
    790790};
    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  
    214214 */
    215215#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 32
    221 
    222 /**
    223  * Compatibility #define to ease the transition to logfile-in-a-variable.
    224  */
    225 #define MONDO_LOGFILE    "/var/log/mondo-archive.log"
    226216
    227217/**
Note: See TracChangeset for help on using the changeset viewer.