From: Andre Noll Date: Sat, 15 Sep 2007 14:01:20 +0000 (+0200) Subject: Rename osl index entry stuff. X-Git-Tag: v0.3.0~403 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=a3b43ea4ccc39b56ec4de003f83836b75905afe2;p=paraslash.git Rename osl index entry stuff. struct osl_table: index_entry_size -> row_index_size get_index_entry_start -> get_row_index get_index_entry -> get_cell_index update_index_entry -> update_cell_index --- diff --git a/osl.c b/osl.c index b75b3bc3..1587b04c 100644 --- a/osl.c +++ b/osl.c @@ -526,8 +526,8 @@ int init_table_structure(const struct osl_table_description *desc, break; case OSL_MAPPED_STORAGE: t->num_mapped_columns++; - col->index_offset = t->index_entry_size; - t->index_entry_size += 8; + col->index_offset = t->row_index_size; + t->row_index_size += 8; break; case OSL_NO_STORAGE: col->volatile_num = t->num_volatile_columns; @@ -551,7 +551,7 @@ int init_table_structure(const struct osl_table_description *desc, if (!t->num_rbtrees) goto err; /* success */ - PARA_DEBUG_LOG("OK. Index entry size: %u\n", t->index_entry_size); + PARA_DEBUG_LOG("OK. Index entry size: %u\n", t->row_index_size); ret = init_column_descriptions(t); if (ret < 0) goto err; @@ -955,16 +955,16 @@ int get_mapped_object(const struct osl_table *t, unsigned col_num, struct osl_column *col = &t->columns[col_num]; uint32_t offset; char *header; - char *index_entry; + char *cell_index; int ret; if (t->num_rows <= row_num) return -E_BAD_ID; - ret = get_index_entry(t, row_num, col_num, &index_entry); + ret = get_cell_index(t, row_num, col_num, &cell_index); if (ret < 0) return ret; - offset = read_u32(index_entry); - obj->size = read_u32(index_entry + 4) - 1; + offset = read_u32(cell_index); + obj->size = read_u32(cell_index + 4) - 1; header = col->data_map.data + offset; obj->data = header + 1; if (read_u8(header) == 0xff) { @@ -1195,13 +1195,13 @@ int osl_close_table(struct osl_table *t, enum osl_close_flags flags) */ int row_is_invalid(struct osl_table *t, uint32_t row_num) { - char *index_entry; - int i, ret = get_index_entry_start(t, row_num, &index_entry); + char *row_index; + int i, ret = get_row_index(t, row_num, &row_index); if (ret < 0) return ret; - for (i = 0; i < t->index_entry_size; i++) { - if ((unsigned char)index_entry[i] != 0xff) + for (i = 0; i < t->row_index_size; i++) { + if ((unsigned char)row_index[i] != 0xff) return 0; } PARA_INFO_LOG("row %d is invalid\n", row_num); @@ -1221,14 +1221,13 @@ int row_is_invalid(struct osl_table *t, uint32_t row_num) */ int mark_row_invalid(struct osl_table *t, uint32_t row_num) { - char *index_entry; - int i, ret = get_index_entry_start(t, row_num, &index_entry); + char *row_index; + int ret = get_row_index(t, row_num, &row_index); - PARA_INFO_LOG("marking row %d as invalid\n", row_num); if (ret < 0) return ret; - for (i = 0; i < t->index_entry_size; i++) - index_entry[i] = 0xff; + PARA_INFO_LOG("marking row %d as invalid\n", row_num); + memset(row_index, 0xff, t->row_index_size); return 1; } @@ -1371,7 +1370,7 @@ static int append_map_file(const struct osl_table *t, unsigned col_num, return ret; } -static int append_index_entry(const struct osl_table *t, char *new_index_entry) +static int append_row_index(const struct osl_table *t, char *row_index) { char *filename; int ret; @@ -1379,9 +1378,8 @@ static int append_index_entry(const struct osl_table *t, char *new_index_entry) if (!t->num_mapped_columns) return 1; filename = index_filename(t->desc); -// PARA_DEBUG_LOG("appending %u bytes\n", t->index_entry_size); - ret = append_file(filename, NULL, 0, new_index_entry, - t->index_entry_size, NULL); + ret = append_file(filename, NULL, 0, row_index, + t->row_index_size, NULL); free(filename); return ret; } @@ -1479,7 +1477,7 @@ int osl_add_and_get_row(struct osl_table *t, struct osl_object *objects, int i, ret; char *ds_name = NULL; struct rb_node **rb_parents = NULL, ***rb_links = NULL; - char *new_index_entry = NULL; + char *new_row_index = NULL; struct osl_object *volatile_objs = NULL; const struct osl_column_description *cd; @@ -1488,7 +1486,7 @@ int osl_add_and_get_row(struct osl_table *t, struct osl_object *objects, rb_parents = para_malloc(t->num_rbtrees * sizeof(struct rn_node*)); rb_links = para_malloc(t->num_rbtrees * sizeof(struct rn_node**)); if (t->num_mapped_columns) - new_index_entry = para_malloc(t->index_entry_size); + new_row_index = para_malloc(t->row_index_size); /* pass 1: sanity checks */ // PARA_DEBUG_LOG("sanity tests: %p:%p\n", objects[0].data, // objects[1].data); @@ -1539,7 +1537,7 @@ int osl_add_and_get_row(struct osl_table *t, struct osl_object *objects, ret = append_map_file(t, i, objects + i, &new_size); if (ret < 0) goto rollback; - update_index_entry(new_index_entry, col, new_size, + update_cell_index(new_row_index, col, new_size, objects[i].size); continue; } @@ -1548,13 +1546,13 @@ int osl_add_and_get_row(struct osl_table *t, struct osl_object *objects, if (ret < 0) goto rollback; } - ret = append_index_entry(t, new_index_entry); + ret = append_row_index(t, new_row_index); if (ret < 0) goto rollback; ret = map_table(t, MAP_TBL_FL_VERIFY_INDEX); if (ret < 0) { /* truncate index and rollback changes */ char *filename = index_filename(t->desc); - para_truncate(filename, t->index_entry_size); + para_truncate(filename, t->row_index_size); free(filename); goto rollback; } @@ -1588,7 +1586,7 @@ rollback: /* rollback all changes made, ignore further errors */ /* ignore error and return previous error value */ map_table(t, MAP_TBL_FL_VERIFY_INDEX); out: - free(new_index_entry); + free(new_row_index); free(ds_name); free(rb_parents); free(rb_links); @@ -1971,8 +1969,8 @@ int osl_update_object(struct osl_table *t, const struct osl_row *r, memcpy(old_obj.data, obj->data, cd->data_size); else { /* TODO: if the size doesn't change, use old space */ uint32_t new_data_map_size; - char *index_entry; - ret = get_index_entry_start(t, r->id, &index_entry); + char *row_index; + ret = get_row_index(t, r->id, &row_index); if (ret < 0) return ret; ret = mark_mapped_object_invalid(t, r->id, col_num); @@ -1986,7 +1984,7 @@ int osl_update_object(struct osl_table *t, const struct osl_row *r, ret = map_column(t, col_num); if (ret < 0) return ret; - update_index_entry(index_entry, col, new_data_map_size, + update_cell_index(row_index, col, new_data_map_size, obj->size); } } diff --git a/osl_core.h b/osl_core.h index 295351fe..16a6775b 100644 --- a/osl_core.h +++ b/osl_core.h @@ -60,7 +60,7 @@ struct osl_table { */ unsigned disk_storage_name_column; /** The number of bytes of an index entry of a row. */ - unsigned index_entry_size; + unsigned row_index_size; /** Pointer to the internal representation of the columns. */ struct osl_column *columns; }; @@ -204,7 +204,7 @@ _static_inline_ size_t index_column_description_size(const char *name) _static_inline_ unsigned table_num_rows(const struct osl_table *t) { return (t->index_map.size - t->index_header_size) - / t->index_entry_size; + / t->row_index_size; } /** @@ -243,22 +243,22 @@ _static_inline_ char *column_filename(const struct osl_table *t, unsigned col_nu * * \param t Pointer to a table which has been mapped. * \param row_num The number of the row whose index entry should be retrieved. - * \param index_entry Result is returned here. + * \param row_index Result pointer. * * \return Positive on success, \p -E_INDEX_CORRUPTION otherwise. * - * \sa get_index_entry(). + * \sa get_cell_index(). */ -_static_inline_ int get_index_entry_start(const struct osl_table *t, uint32_t row_num, - char **index_entry) +_static_inline_ int get_row_index(const struct osl_table *t, uint32_t row_num, + char **row_index) { uint32_t index_offset; - index_offset = t->index_header_size + t->index_entry_size * row_num; + index_offset = t->index_header_size + t->row_index_size * row_num; if (index_offset + 8 > t->index_map.size) { - *index_entry = NULL; + *row_index = NULL; return -E_INDEX_CORRUPTION; } - *index_entry = (char *)(t->index_map.data) + index_offset; + *row_index = (char *)(t->index_map.data) + index_offset; return 1; } @@ -268,26 +268,26 @@ _static_inline_ int get_index_entry_start(const struct osl_table *t, uint32_t ro * \param t Pointer to a table which has been mapped. * \param row_num The number of the row whose index entry should be retrieved. * \param col_num The number of the column whose index entry should be retrieved. - * \param index_entry Result pointer. + * \param cell_index Result pointer. * * \return Positive on success, \p -E_INDEX_CORRUPTION otherwise. * - * \sa get_index_entry_start(). + * \sa get_row_index(). */ -_static_inline_ int get_index_entry(const struct osl_table *t, uint32_t row_num, - uint32_t col_num, char **index_entry) +_static_inline_ int get_cell_index(const struct osl_table *t, uint32_t row_num, + uint32_t col_num, char **cell_index) { - int ret = get_index_entry_start(t, row_num, index_entry); + int ret = get_row_index(t, row_num, cell_index); if (ret < 0) return ret; - *index_entry += t->columns[col_num].index_offset; + *cell_index += t->columns[col_num].index_offset; return ret; } /** * Change an index entry of a column after object was added. * - * \param index_entry_start This determines the row. + * \param row_index Pointer to the index of the row to update. * \param col Pointer to the column. * \param map_size The new size of the data file. * \param object_size The size of the object just appended to the data file. @@ -295,13 +295,13 @@ _static_inline_ int get_index_entry(const struct osl_table *t, uint32_t row_num, * This is called right after an object was appended to the data file for a * mapped column. * - * \sa get_index_entry_start(). + * \sa get_row_index(). */ -_static_inline_ void update_index_entry(char *index_entry_start, struct osl_column *col, +_static_inline_ void update_cell_index(char *row_index, struct osl_column *col, uint32_t map_size, uint32_t object_size) { - write_u32(index_entry_start + col->index_offset, map_size - object_size - 1); - write_u32(index_entry_start + col->index_offset + 4, object_size + 1); + write_u32(row_index + col->index_offset, map_size - object_size - 1); + write_u32(row_index + col->index_offset + 4, object_size + 1); } /**