]> git.tue.mpg.de Git - paraslash.git/commitdiff
osl.c: Fix a bug in osl_update_object().
authorAndre Noll <maan@systemlinux.org>
Sat, 15 Sep 2007 13:12:59 +0000 (15:12 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 15 Sep 2007 13:12:59 +0000 (15:12 +0200)
In case a mapped column is being updated, we have to unmap the
thing before appending to the data file.

osl.c

diff --git a/osl.c b/osl.c
index a71f93c3243153d20504eae0fed91a88141145ff..8b89b3cbcdb993486ec468ce6df4e87b1afba5cb 100644 (file)
--- a/osl.c
+++ b/osl.c
@@ -806,6 +806,17 @@ static void mark_table_clean(struct osl_table *t)
        write_u8(buf, read_u8(buf) & 0xfe);
 }
 
+static void unmap_column(struct osl_table *t, unsigned col_num)
+{
+       struct osl_object map = t->columns[col_num].data_map;
+       int ret;
+       if (!map.data)
+               return;
+       ret = para_munmap(map.data, map.size);
+       assert(ret > 0);
+       map.data = NULL;
+}
+
 /**
  * Unmap all mapped files of an osl table.
  *
@@ -836,18 +847,30 @@ int unmap_table(struct osl_table *t, enum osl_close_flags flags)
        t->index_map.data = NULL;
        if (!t->num_rows)
                return 1;
-       FOR_EACH_MAPPED_COLUMN(i, t, cd) {
-               struct osl_object map = t->columns[i].data_map;
-               if (!map.data)
-                       continue;
-               ret = para_munmap(map.data, map.size);
-               if (ret < 0)
-                       return ret;
-               map.data = NULL;
-       }
+       FOR_EACH_MAPPED_COLUMN(i, t, cd)
+               unmap_column(t, i);
        return 1;
 }
 
+static int map_column(struct osl_table *t, unsigned col_num)
+{
+       struct stat statbuf;
+       char *filename = column_filename(t, col_num);
+       int ret = -E_STAT;
+       if (stat(filename, &statbuf) < 0) {
+               free(filename);
+               return ret;
+       }
+       if (!(S_IFREG & statbuf.st_mode)) {
+               free(filename);
+               return ret;
+       }
+       ret = mmap_full_file(filename, O_RDWR,
+               &t->columns[col_num].data_map);
+       free(filename);
+       return ret;
+}
+
 /**
  * Map the index file and all columns of type \p OSL_MAPPED_STORAGE into memory.
  *
@@ -894,20 +917,7 @@ int map_table(struct osl_table *t, enum map_table_flags flags)
                return num_rows;
        /* map data files */
        FOR_EACH_MAPPED_COLUMN(i, t, cd) {
-               struct stat statbuf;
-               filename = column_filename(t, i);
-               ret = -E_STAT;
-               if (stat(filename, &statbuf) < 0) {
-                       free(filename);
-                       goto err;
-               }
-               if (!(S_IFREG & statbuf.st_mode)) {
-                       free(filename);
-                       goto err;
-               }
-               ret = mmap_full_file(filename, O_RDWR,
-                       &t->columns[i].data_map);
-               free(filename);
+               ret = map_column(t, i);
                if (ret < 0)
                        goto err;
        }
@@ -1967,8 +1977,12 @@ int osl_update_object(struct osl_table *t, const struct osl_row *r,
                        ret = mark_mapped_object_invalid(t, r->id, col_num);
                        if (ret < 0)
                                return ret;
+                       unmap_column(t, col_num);
                        ret = append_map_file(t, col_num, obj,
                                &new_data_map_size);
+                       if (ret < 0)
+                               return ret;
+                       ret = map_column(t, col_num);
                        if (ret < 0)
                                return ret;
                        update_index_entry(index_entry, col, new_data_map_size,