UBIFS: align inode data to eight
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Thu, 24 Jul 2008 11:52:45 +0000 (14:52 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Mon, 25 May 2009 14:08:52 +0000 (17:08 +0300)
UBIFS aligns node lengths to 8, so budgeting has to do the
same. Well, direntry, inode, and page budgets are already
aligned, but not inode data budget (e.g., data in special
devices or symlinks). Do this for inode data as well.
Also, add corresponding debugging checks.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
fs/ubifs/budget.c
fs/ubifs/dir.c
fs/ubifs/file.c
fs/ubifs/ubifs.h
fs/ubifs/xattr.c

index c18caf0..e94f5de 100644 (file)
@@ -554,6 +554,8 @@ int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req)
        ubifs_assert(req->new_ino_d <= UBIFS_MAX_INO_DATA);
        ubifs_assert(req->dirtied_ino <= 4);
        ubifs_assert(req->dirtied_ino_d <= UBIFS_MAX_INO_DATA * 4);
+       ubifs_assert(!(req->new_ino_d & 7));
+       ubifs_assert(!(req->dirtied_ino_d & 7));
 
        data_growth = calc_data_growth(c, req);
        dd_growth = calc_dd_growth(c, req);
@@ -641,6 +643,8 @@ void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req)
        ubifs_assert(req->new_ino_d <= UBIFS_MAX_INO_DATA);
        ubifs_assert(req->dirtied_ino <= 4);
        ubifs_assert(req->dirtied_ino_d <= UBIFS_MAX_INO_DATA * 4);
+       ubifs_assert(!(req->new_ino_d & 7));
+       ubifs_assert(!(req->dirtied_ino_d & 7));
        if (!req->recalculate) {
                ubifs_assert(req->idx_growth >= 0);
                ubifs_assert(req->data_growth >= 0);
@@ -668,7 +672,11 @@ void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req)
 
        ubifs_assert(c->budg_idx_growth >= 0);
        ubifs_assert(c->budg_data_growth >= 0);
+       ubifs_assert(c->budg_dd_growth >= 0);
        ubifs_assert(c->min_idx_lebs < c->main_lebs);
+       ubifs_assert(!(c->budg_idx_growth & 7));
+       ubifs_assert(!(c->budg_data_growth & 7));
+       ubifs_assert(!(c->budg_dd_growth & 7));
        spin_unlock(&c->space_lock);
 }
 
@@ -710,7 +718,7 @@ void ubifs_release_dirty_inode_budget(struct ubifs_info *c,
        struct ubifs_budget_req req;
 
        memset(&req, 0, sizeof(struct ubifs_budget_req));
-       req.dd_growth = c->inode_budget + ui->data_len;
+       req.dd_growth = c->inode_budget + ALIGN(ui->data_len, 8);
        ubifs_release_budget(c, &req);
 }
 
index 320f89a..e1827d7 100644 (file)
@@ -520,7 +520,7 @@ static int ubifs_link(struct dentry *old_dentry, struct inode *dir,
        struct ubifs_inode *dir_ui = ubifs_inode(dir);
        int err, sz_change = CALC_DENT_SIZE(dentry->d_name.len);
        struct ubifs_budget_req req = { .new_dent = 1, .dirtied_ino = 2,
-                                       .dirtied_ino_d = ui->data_len };
+                               .dirtied_ino_d = ALIGN(ui->data_len, 8) };
 
        /*
         * Budget request settings: new direntry, changing the target inode,
@@ -783,7 +783,8 @@ static int ubifs_mknod(struct inode *dir, struct dentry *dentry,
        int sz_change = CALC_DENT_SIZE(dentry->d_name.len);
        int err, devlen = 0;
        struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
-                                       .new_ino_d = devlen, .dirtied_ino = 1 };
+                                       .new_ino_d = ALIGN(devlen, 8),
+                                       .dirtied_ino = 1 };
 
        /*
         * Budget request settings: new inode, new direntry and changing parent
@@ -857,7 +858,8 @@ static int ubifs_symlink(struct inode *dir, struct dentry *dentry,
        int err, len = strlen(symname);
        int sz_change = CALC_DENT_SIZE(dentry->d_name.len);
        struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
-                                       .new_ino_d = len, .dirtied_ino = 1 };
+                                       .new_ino_d = ALIGN(len, 8),
+                                       .dirtied_ino = 1 };
 
        /*
         * Budget request settings: new inode, new direntry and changing parent
@@ -1006,7 +1008,7 @@ static int ubifs_rename(struct inode *old_dir, struct dentry *old_dentry,
        struct ubifs_budget_req req = { .new_dent = 1, .mod_dent = 1,
                                        .dirtied_ino = 3 };
        struct ubifs_budget_req ino_req = { .dirtied_ino = 1,
-                               .dirtied_ino_d = old_inode_ui->data_len };
+                       .dirtied_ino_d = ALIGN(old_inode_ui->data_len, 8) };
        struct timespec time;
 
        /*
index 72b78d4..8f49268 100644 (file)
@@ -899,7 +899,7 @@ static int do_setattr(struct ubifs_info *c, struct inode *inode,
        loff_t new_size = attr->ia_size;
        struct ubifs_inode *ui = ubifs_inode(inode);
        struct ubifs_budget_req req = { .dirtied_ino = 1,
-                                       .dirtied_ino_d = ui->data_len };
+                               .dirtied_ino_d = ALIGN(ui->data_len, 8) };
 
        err = ubifs_budget_space(c, &req);
        if (err)
@@ -1061,7 +1061,7 @@ static int update_mctime(struct ubifs_info *c, struct inode *inode)
        if (mctime_update_needed(inode, &now)) {
                int err, release;
                struct ubifs_budget_req req = { .dirtied_ino = 1,
-                                               .dirtied_ino_d = ui->data_len };
+                               .dirtied_ino_d = ALIGN(ui->data_len, 8) };
 
                err = ubifs_budget_space(c, &req);
                if (err)
index 990ecd1..89aba17 100644 (file)
@@ -809,6 +809,10 @@ struct ubifs_compressor {
  * An inode may contain 4KiB of data at max., thus the widths of @new_ino_d
  * is 13 bits, and @dirtied_ino_d - 15, because up to 4 inodes may be made
  * dirty by the re-name operation.
+ *
+ * Note, UBIFS aligns node lengths to 8-bytes boundary, so the requester has to
+ * make sure the amount of inode data which contribute to @new_ino_d and
+ * @dirtied_ino_d fields are aligned.
  */
 struct ubifs_budget_req {
 #ifdef UBIFS_COMPAT_USE_OLD_PREPARE_WRITE
index 1388a07..39e831d 100644 (file)
@@ -103,8 +103,8 @@ static int create_xattr(struct ubifs_info *c, struct inode *host,
        struct inode *inode;
        struct ubifs_inode *ui, *host_ui = ubifs_inode(host);
        struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
-                                       .new_ino_d = size, .dirtied_ino = 1,
-                                       .dirtied_ino_d = host_ui->data_len};
+                               .new_ino_d = size, .dirtied_ino = 1,
+                               .dirtied_ino_d = ALIGN(host_ui->data_len, 8)};
 
        if (host_ui->xattr_cnt >= MAX_XATTRS_PER_INODE)
                return -ENOSPC;