projects
/
paraslash.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Don't let make write the filename into the output
[paraslash.git]
/
fsck.c
diff --git
a/fsck.c
b/fsck.c
index 391516f30ebeacb82758c1aa4af51bfffa45e0c6..3b605c2d0a65d6260094ba99494009ee8bbfbef8 100644
(file)
--- a/
fsck.c
+++ b/
fsck.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (C) 1997-200
7
Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 1997-200
9
Andre Noll <maan@systemlinux.org>
*
* Licensed under the GPL v2. For licencing details see COPYING.
*/
*
* Licensed under the GPL v2. For licencing details see COPYING.
*/
@@
-19,7
+19,9
@@
static struct fsck_args_info conf;
INIT_FSCK_ERRLISTS;
static struct fsck_args_info conf;
INIT_FSCK_ERRLISTS;
-INIT_STDERR_LOGGING(conf.loglevel_arg);
+
+static int loglevel;
+INIT_STDERR_LOGGING(loglevel);
/* taken from git */
signed char hexval_table[256] = {
/* taken from git */
signed char hexval_table[256] = {
@@
-115,7
+117,7
@@
static int check_index_ranges(struct osl_table *t)
{
int i, j, ret;
{
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++) {
//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++) {
@@
-176,8
+178,8
@@
static int map_index(const struct osl_table_description *desc, struct osl_object
char *filename = index_filename(desc);
int ret;
char *filename = index_filename(desc);
int ret;
- ret = mmap_full_file(filename, O_RDWR,
map
);
- PARA_
INFO
_LOG("mapping index %s: ret: %d, size: %zu\n", filename, ret, map->size);
+ ret = mmap_full_file(filename, O_RDWR,
&map->data, &map->size, NULL
);
+ PARA_
DEBUG
_LOG("mapping index %s: ret: %d, size: %zu\n", filename, ret, map->size);
free(filename);
return ret;
}
free(filename);
return ret;
}
@@
-212,7
+214,7
@@
static int prune_invalid_rows_from_index(struct osl_table *t)
break;
}
}
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
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
+235,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);
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;
/* first count used bytes */
FOR_EACH_MAPPED_COLUMN(i, t, cd) {
loss[i] = t->columns[i].data_map.size;
@@
-434,7
+436,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);
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;
for (i = 0; i < t->num_rows; i++) {
if (row_is_invalid(t, i))
continue;
@@
-474,7
+476,7
@@
static int dummy_compare(const struct osl_object *obj1, const struct osl_object
static unsigned files_pruned;
static unsigned files_pruned;
-int prune_disk_storage_file(const char *path,
const
void *private_data)
+int prune_disk_storage_file(const char *path, void *private_data)
{
HASH_TYPE hash[HASH_SIZE];
unsigned flags = *(unsigned *)private_data;
{
HASH_TYPE hash[HASH_SIZE];
unsigned flags = *(unsigned *)private_data;
@@
-531,10
+533,11
@@
static int prune_disk_storage_files(struct osl_table *t)
int i, ret = 1;
const struct osl_column_description *cd;
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);
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);
+ ret = for_each_file_in_dir(dirname, prune_disk_storage_file,
+ (unsigned *)&t->desc->flags);
free(dirname);
}
if (files_pruned)
free(dirname);
}
if (files_pruned)
@@
-551,7
+554,7
@@
static int check_disk_storage_columns(struct osl_table *t)
const struct osl_column_description *cd;
if (!t->num_disk_storage_columns) {
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;
}
"skipping checks\n", t->desc->name);
return 1;
}
@@
-560,7
+563,7
@@
static int check_disk_storage_columns(struct osl_table *t)
ret = init_rbtrees(t);
if (ret < 0)
return ret;
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;
ret = osl_open_table(&hash_tree_table_desc, &hash_tree_table);
if (ret < 0)
goto out;
@@
-606,7
+609,7
@@
static int fsck_init(struct osl_table_description *desc, struct osl_table **t)
para_munmap(map.data, map.size);
goto out;
}
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));
para_munmap(map.data, map.size);
if (conf.force_given)
ret = map_table(*t, (MAP_TBL_FL_IGNORE_DIRTY));
@@
-621,6
+624,9
@@
out:
static void fsck_cleanup(struct osl_table *t)
{
int i;
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++) {
if (t->desc->column_descriptions) {
struct osl_column_description *cd;
for (i = 0; i < t->desc->num_columns; i++) {
@@
-629,10
+635,8
@@
static void fsck_cleanup(struct osl_table *t)
}
free(t->desc->column_descriptions);
}
}
free(t->desc->column_descriptions);
}
- if (t) {
- free(t->columns);
- free(t);
- }
+ free(t->columns);
+ free(t);
}
}
@@
-751,14
+755,14
@@
static int dump_row(struct osl_table *t, unsigned row_num, const char *row_dir)
if (!t->num_disk_storage_columns)
return 1;
dsnc = t->disk_storage_name_column;
if (!t->num_disk_storage_columns)
return 1;
dsnc = t->disk_storage_name_column;
- ret = get_mapped_object(t, dsnc,
i
, &obj);
+ ret = get_mapped_object(t, dsnc,
row_num
, &obj);
if (ret < 0)
return ret;
hash_object(&obj, hash);
ds_name = disk_storage_name_of_hash(t, hash);
FOR_EACH_DISK_STORAGE_COLUMN(i, t, cd) {
filename = disk_storage_path(t, i, ds_name);
if (ret < 0)
return ret;
hash_object(&obj, hash);
ds_name = disk_storage_name_of_hash(t, hash);
FOR_EACH_DISK_STORAGE_COLUMN(i, t, cd) {
filename = disk_storage_path(t, i, ds_name);
- ret = mmap_full_file(filename, O_RDONLY, &obj);
+ ret = mmap_full_file(filename, O_RDONLY, &obj
.data, &obj.size, NULL
);
free(filename);
if (ret < 0)
goto out;
free(filename);
if (ret < 0)
goto out;
@@
-789,12
+793,12
@@
static int dump_rows(char *dump_dir, struct osl_table *t)
current_dir = make_message("%s/rows_%u-%u", dump_dir, i, i + 999);
PARA_NOTICE_LOG("dumping rows %u - %u\n", i, i + 999);
ret = para_mkdir(current_dir, 0777);
current_dir = make_message("%s/rows_%u-%u", dump_dir, i, i + 999);
PARA_NOTICE_LOG("dumping rows %u - %u\n", i, i + 999);
ret = para_mkdir(current_dir, 0777);
- if (ret < 0)
+ if (ret < 0
&& !is_errno(-ret, EEXIST)
)
goto out;
}
row_dir = make_message("%s/row_%03u", current_dir, i);
ret = para_mkdir(row_dir, 0777);
goto out;
}
row_dir = make_message("%s/row_%03u", current_dir, i);
ret = para_mkdir(row_dir, 0777);
- if (ret < 0) {
+ if (ret < 0
&& !is_errno(-ret, EEXIST)
) {
free(row_dir);
goto out;
}
free(row_dir);
goto out;
}
@@
-813,13
+817,18
@@
static int dump_table(char *dump_dir, struct osl_table_description *desc)
struct osl_table *t = NULL;
int fd, ret = fsck_init(desc, &t);
char *desc_file;
struct osl_table *t = NULL;
int fd, ret = fsck_init(desc, &t);
char *desc_file;
+ char *table_dump_dir = NULL;
if (ret < 0)
goto out;
ret = para_mkdir(dump_dir, 0777);
if (ret < 0)
goto out;
ret = para_mkdir(dump_dir, 0777);
- if (ret < 0)
+ if (ret < 0
&& !is_errno(-ret, EEXIST)
)
goto out;
goto out;
- desc_file = make_message("%s/table_description.c", dump_dir);
+ table_dump_dir = make_message("%s/%s", dump_dir, desc->name);
+ ret = para_mkdir(table_dump_dir, 0777);
+ if (ret < 0 && !is_errno(-ret, EEXIST))
+ goto out;
+ desc_file = make_message("%s/table_description.c", table_dump_dir);
ret = para_open(desc_file, O_WRONLY | O_CREAT | O_EXCL, 0644);
free(desc_file);
if (ret < 0)
ret = para_open(desc_file, O_WRONLY | O_CREAT | O_EXCL, 0644);
free(desc_file);
if (ret < 0)
@@
-829,8
+838,9
@@
static int dump_table(char *dump_dir, struct osl_table_description *desc)
close(fd);
if (ret < 0)
goto out;
close(fd);
if (ret < 0)
goto out;
- ret = dump_rows(dump_dir, t);
+ ret = dump_rows(
table_
dump_dir, t);
out:
out:
+ free(table_dump_dir);
fsck_cleanup(t);
return ret;
}
fsck_cleanup(t);
return ret;
}
@@
-862,7
+872,6
@@
static int fsck(struct osl_table_description *desc)
goto out_unmap;
}
free(lost_bytes);
goto out_unmap;
}
free(lost_bytes);
- PARA_INFO_LOG("success\n");
out_unmap:
unmap_table(t, OSL_MARK_CLEAN);
out:
out_unmap:
unmap_table(t, OSL_MARK_CLEAN);
out:
@@
-879,14
+888,22
@@
static int check_table(char *base_dir, char *table_name)
};
int ret;
};
int ret;
+ PARA_INFO_LOG("checking table %s\n", table_name);
if (!conf.no_fsck_given) {
ret = fsck(&desc);
if (ret < 0)
if (!conf.no_fsck_given) {
ret = fsck(&desc);
if (ret < 0)
-
return re
t;
+
goto ou
t;
}
}
+ ret = 1;
if (!conf.dump_dir_given || !*conf.dump_dir_arg)
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)
}
static int check_all_tables(char *base_dir)
@@
-921,7
+938,15
@@
static int check_all_tables(char *base_dir)
return ret;
}
return ret;
}
-int main(__a_unused int argc, char **argv)
+/**
+ * The praslash database check program.
+ *
+ * \param argc Usual arg count.
+ * \param argv Usual arg vector.
+ *
+ * \return \p EXIT_SUCCESS or \p EXIT_FAILURE.
+ */
+int main(int argc, char **argv)
{
int i, ret;
char *base_dir = NULL;
{
int i, ret;
char *base_dir = NULL;
@@
-932,8
+957,9
@@
int main(__a_unused int argc, char **argv)
goto out;
}
HANDLE_VERSION_FLAG("fsck", conf);
goto out;
}
HANDLE_VERSION_FLAG("fsck", conf);
+ loglevel = get_loglevel_by_name(conf.loglevel_arg);
if (conf.base_dir_given)
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);
else {
char *home = para_homedir();
base_dir = make_message("%s/.paraslash/afs_database", home);
@@
-949,9
+975,15
@@
int main(__a_unused int argc, char **argv)
break;
}
out:
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)
+ );
+ } else
+ PARA_NOTICE_LOG("success\n");
+ if (base_dir)
free(base_dir);
free(base_dir);
- if (ret < 0)
- PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;
}
return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;
}