return ret;
 }
 
+static int ocfs2_remove_rightmost_empty_extent(struct ocfs2_super *osb,
+                               struct ocfs2_extent_tree *et,
+                               struct ocfs2_path *path,
+                               struct ocfs2_cached_dealloc_ctxt *dealloc)
+{
+       handle_t *handle;
+       int ret;
+       int credits = path->p_tree_depth * 2 + 1;
+
+       handle = ocfs2_start_trans(osb, credits);
+       if (IS_ERR(handle)) {
+               ret = PTR_ERR(handle);
+               mlog_errno(ret);
+               return ret;
+       }
+
+       ret = ocfs2_remove_rightmost_path(handle, et, path, dealloc);
+       if (ret)
+               mlog_errno(ret);
+
+       ocfs2_commit_trans(osb, handle);
+       return ret;
+}
+
 /*
  * Left rotation of btree records.
  *
                 * to check it up here before changing the tree.
                */
                if (root_el->l_tree_depth && rec->e_int_clusters == 0) {
-                       ocfs2_error(inode->i_sb, "Inode %lu has an empty "
+                       mlog(ML_ERROR, "Inode %lu has an empty "
                                    "extent record, depth %u\n", inode->i_ino,
                                    le16_to_cpu(root_el->l_tree_depth));
-                       status = -EROFS;
-                       goto bail;
+                       status = ocfs2_remove_rightmost_empty_extent(osb,
+                                       &et, path, &dealloc);
+                       if (status) {
+                               mlog_errno(status);
+                               goto bail;
+                       }
+
+                       ocfs2_reinit_path(path, 1);
+                       goto start;
+               } else {
+                       trunc_cpos = le32_to_cpu(rec->e_cpos);
+                       trunc_len = 0;
+                       blkno = 0;
                }
-               trunc_cpos = le32_to_cpu(rec->e_cpos);
-               trunc_len = 0;
-               blkno = 0;
        } else if (le32_to_cpu(rec->e_cpos) >= new_highest_cpos) {
                /*
                 * Truncate entire record.