X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=fsck.c;h=60bd27026cd3c962327d6074ec51b202fb7daea0;hp=48fae27d490bf2021f85682616e2503341f5fe83;hb=6d5a56308a3a833b08ae0e3692b794fb6122ea60;hpb=97f53e18953fc2013c0b14f0261ac385e45b0284 diff --git a/fsck.c b/fsck.c index 48fae27d..60bd2702 100644 --- a/fsck.c +++ b/fsck.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1997-2007 Andre Noll + * Copyright (C) 1997-2008 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -115,7 +115,7 @@ static int check_index_ranges(struct osl_table *t) { int i, j, ret; - PARA_NOTICE_LOG("checking for range violations in index\n"); + PARA_INFO_LOG("checking for range violations in index\n"); //PARA_DEBUG_LOG("%d rows. %d columns\n", t->num_rows, t->desc->num_columns); t->num_invalid_rows = 0; for (i = 0; i < t->num_rows; i++) { @@ -177,7 +177,7 @@ static int map_index(const struct osl_table_description *desc, struct osl_object int ret; ret = mmap_full_file(filename, O_RDWR, &map->data, &map->size, NULL); - PARA_INFO_LOG("mapping index %s: ret: %d, size: %zu\n", filename, ret, map->size); + PARA_DEBUG_LOG("mapping index %s: ret: %d, size: %zu\n", filename, ret, map->size); free(filename); return ret; } @@ -212,7 +212,7 @@ static int prune_invalid_rows_from_index(struct osl_table *t) break; } } - PARA_INFO_LOG("unmapping index\n"); + PARA_DEBUG_LOG("unmapping index\n"); para_munmap(t->index_map.data, t->index_map.size); filename = index_filename(t->desc); ret = para_truncate(filename, t->row_index_size @@ -233,7 +233,7 @@ static int check_for_invalid_objects(struct osl_table *t, uint32_t **lost_bytes) const struct osl_column_description *cd; uint32_t *loss = para_malloc(sizeof(uint32_t) * t->desc->num_columns); - PARA_NOTICE_LOG("looking for mapped objects not contained in index\n"); + PARA_INFO_LOG("looking for mapped objects not contained in index\n"); /* first count used bytes */ FOR_EACH_MAPPED_COLUMN(i, t, cd) { loss[i] = t->columns[i].data_map.size; @@ -434,7 +434,7 @@ static int check_disk_storage_presence(struct osl_table *t) if (!t->num_rows) return 1; hashes = para_malloc(t->num_rows * HASH_SIZE); - PARA_NOTICE_LOG("looking for missing disk storage objects\n"); + PARA_INFO_LOG("looking for missing disk storage objects\n"); for (i = 0; i < t->num_rows; i++) { if (row_is_invalid(t, i)) continue; @@ -531,7 +531,7 @@ static int prune_disk_storage_files(struct osl_table *t) int i, ret = 1; const struct osl_column_description *cd; - PARA_NOTICE_LOG("looking for unreferenced disk storage files\n"); + PARA_INFO_LOG("looking for unreferenced disk storage files\n"); FOR_EACH_DISK_STORAGE_COLUMN(i, t, cd) { char *dirname = column_filename(t, i); ret = for_each_file_in_dir(dirname, prune_disk_storage_file, &t->desc->flags); @@ -551,7 +551,7 @@ static int check_disk_storage_columns(struct osl_table *t) const struct osl_column_description *cd; if (!t->num_disk_storage_columns) { - PARA_NOTICE_LOG("no disk storage columns in table '%s', " + PARA_INFO_LOG("no disk storage columns in table '%s', " "skipping checks\n", t->desc->name); return 1; } @@ -560,7 +560,7 @@ static int check_disk_storage_columns(struct osl_table *t) ret = init_rbtrees(t); if (ret < 0) return ret; - PARA_NOTICE_LOG("creating rbtree for disk storage hash values\n"); + PARA_INFO_LOG("creating rbtree for disk storage hash values\n"); ret = osl_open_table(&hash_tree_table_desc, &hash_tree_table); if (ret < 0) goto out; @@ -606,7 +606,7 @@ static int fsck_init(struct osl_table_description *desc, struct osl_table **t) para_munmap(map.data, map.size); goto out; } - PARA_INFO_LOG("unmapping index\n"); + PARA_DEBUG_LOG("unmapping index\n"); para_munmap(map.data, map.size); if (conf.force_given) ret = map_table(*t, (MAP_TBL_FL_IGNORE_DIRTY)); @@ -621,6 +621,9 @@ out: static void fsck_cleanup(struct osl_table *t) { int i; + + if (!t) + return; if (t->desc->column_descriptions) { struct osl_column_description *cd; for (i = 0; i < t->desc->num_columns; i++) { @@ -629,10 +632,8 @@ static void fsck_cleanup(struct osl_table *t) } free(t->desc->column_descriptions); } - if (t) { - free(t->columns); - free(t); - } + free(t->columns); + free(t); } @@ -868,7 +869,6 @@ static int fsck(struct osl_table_description *desc) goto out_unmap; } free(lost_bytes); - PARA_INFO_LOG("success\n"); out_unmap: unmap_table(t, OSL_MARK_CLEAN); out: @@ -885,14 +885,22 @@ static int check_table(char *base_dir, char *table_name) }; int ret; + PARA_INFO_LOG("checking table %s\n", table_name); if (!conf.no_fsck_given) { ret = fsck(&desc); if (ret < 0) - return ret; + goto out; } + ret = 1; if (!conf.dump_dir_given || !*conf.dump_dir_arg) - return 1; - return dump_table(conf.dump_dir_arg, &desc); + goto out; + ret = dump_table(conf.dump_dir_arg, &desc); +out: + if (ret < 0) + PARA_ERROR_LOG("failed to check table %s\n", table_name); + else + PARA_NOTICE_LOG("successfully checked table %s\n", table_name); + return ret; } static int check_all_tables(char *base_dir) @@ -939,7 +947,7 @@ int main(int argc, char **argv) } HANDLE_VERSION_FLAG("fsck", conf); if (conf.base_dir_given) - base_dir = conf.base_dir_arg; + base_dir = para_strdup(conf.base_dir_arg); else { char *home = para_homedir(); base_dir = make_message("%s/.paraslash/afs_database", home); @@ -955,9 +963,18 @@ int main(int argc, char **argv) break; } out: - if (!conf.base_dir_given) + if (ret < 0) { + PARA_ERROR_LOG("%s%s: %s\n", + base_dir? "base_dir: " : "", + base_dir? base_dir : "", + para_strerror(-ret) + ); + if (conf.loglevel_arg > 1) + PARA_EMERG_LOG("re-run with \"--loglevel %d\" to increase verbosity\n", + conf.loglevel_arg - 1); + } else + PARA_NOTICE_LOG("success\n"); + if (base_dir) free(base_dir); - if (ret < 0) - PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); return ret < 0? EXIT_FAILURE : EXIT_SUCCESS; }