115 static int reserve_space(
struct ubifs_info *
c,
int jhead,
int len)
126 squeeze = (jhead ==
BASEHD);
171 dbg_jnl(
"GC couldn't make a free LEB for jhead %s",
174 dbg_jnl(
"retry (%d)", retries);
192 dbg_jnl(
"return LEB %d back, already have LEB %d:%d",
194 err = ubifs_return_leb(c, lnum);
230 err1 = ubifs_return_leb(c, lnum);
231 if (err1 && err == -
EAGAIN)
255 static int write_node(
struct ubifs_info *c,
int jhead,
void *
node,
int len,
256 int *lnum,
int *offs)
265 dbg_jnl(
"jhead %s, LEB %d:%d, len %d",
286 static int write_head(
struct ubifs_info *c,
int jhead,
void *
buf,
int len,
287 int *lnum,
int *offs,
int sync)
296 dbg_jnl(
"jhead %s, LEB %d:%d, len %d",
323 static int make_reservation(
struct ubifs_info *c,
int jhead,
int len)
325 int err, cmt_retries = 0, nospc_retries = 0;
329 err = reserve_space(c, jhead, len);
341 if (nospc_retries++ < 2) {
361 if (cmt_retries > 128) {
369 }
else if (cmt_retries > 32)
370 ubifs_warn(
"too many space allocation re-tries (%d)",
373 dbg_jnl(
"-EAGAIN, commit and retry (retried %d times)",
383 ubifs_err(
"cannot reserve %d bytes in jhead %d, error %d",
406 static inline void release_head(
struct ubifs_info *c,
int jhead)
418 static void finish_reservation(
struct ubifs_info *c)
427 static int get_dent_type(
int mode)
464 ino_key_init_flash(c, &ino->
key, inode->
i_ino);
483 zero_ino_node_unused(ino);
489 if (!last_reference) {
542 const struct qstr *nm,
const struct inode *inode,
543 int deletion,
int xent)
545 int err,
dlen, ilen, len, lnum, ino_offs, dent_offs;
546 int aligned_dlen, aligned_ilen, sync =
IS_DIRSYNC(dir);
547 int last_reference = !!(deletion && inode->
i_nlink == 0);
554 dbg_jnl(
"ino %lu, dent '%.*s', data len %d in dir ino %lu",
568 if (!last_reference) {
573 aligned_dlen =
ALIGN(dlen, 8);
574 aligned_ilen =
ALIGN(ilen, 8);
581 err = make_reservation(c,
BASEHD, len);
587 dent_key_init(c, &dent_key, dir->
i_ino, nm);
590 xent_key_init(c, &dent_key, dir->
i_ino, nm);
593 key_write(c, &dent_key, dent->
key);
598 dent->
name[nm->len] =
'\0';
599 zero_dent_node_unused(dent);
602 ino = (
void *)dent + aligned_dlen;
603 pack_inode(c, ino, inode, 0);
604 ino = (
void *)ino + aligned_ilen;
605 pack_inode(c, ino, dir, 1);
607 if (last_reference) {
616 err = write_head(c,
BASEHD, dent, len, &lnum, &dent_offs, sync);
632 err = ubifs_add_dirt(c, lnum, dlen);
644 ino_key_init(c, &ino_key, inode->
i_ino);
645 ino_offs = dent_offs + aligned_dlen;
650 ino_key_init(c, &ino_key, dir->
i_ino);
651 ino_offs += aligned_ilen;
652 err =
ubifs_tnc_add(c, &ino_key, lnum, ino_offs, UBIFS_INO_NODE_SZ);
656 finish_reservation(c);
660 mark_inode_clean(c, ui);
661 mark_inode_clean(c, dir_ui);
665 finish_reservation(c);
677 finish_reservation(c);
700 dbg_jnlk(key,
"ino %lu, blk %u, len %d, key ",
701 (
unsigned long)key_inum(c, key), key_block(c, key), len);
719 key_write(c, key, &data->
key);
721 zero_data_node_unused(data);
733 dlen = UBIFS_DATA_NODE_SZ +
out_len;
737 err = make_reservation(c,
DATAHD, dlen);
741 err = write_node(c,
DATAHD, data, dlen, &lnum, &offs);
751 finish_reservation(c);
762 finish_reservation(c);
793 if (!last_reference) {
802 err = make_reservation(c,
BASEHD, len);
806 pack_inode(c, ino, inode, 1);
807 err = write_head(c,
BASEHD, ino, len, &lnum, &offs, sync);
815 if (last_reference) {
820 err = ubifs_add_dirt(c, lnum, len);
824 ino_key_init(c, &key, inode->
i_ino);
830 finish_reservation(c);
841 finish_reservation(c);
921 const struct dentry *old_dentry,
922 const struct inode *new_dir,
923 const struct dentry *new_dentry,
int sync)
928 int err, dlen1, dlen2, ilen, lnum,
offs, len;
929 const struct inode *old_inode = old_dentry->
d_inode;
932 int last_reference = !!(new_inode && new_inode->
i_nlink == 0);
933 int move = (old_dir != new_dir);
936 dbg_jnl(
"dent '%.*s' in dir ino %lu to dent '%.*s' in dir ino %lu",
952 ilen += new_ui->data_len;
956 aligned_dlen1 =
ALIGN(dlen1, 8);
957 aligned_dlen2 =
ALIGN(dlen2, 8);
958 len = aligned_dlen1 + aligned_dlen2 +
ALIGN(ilen, 8) +
ALIGN(plen, 8);
959 if (old_dir != new_dir)
966 err = make_reservation(c,
BASEHD, len);
972 dent_key_init_flash(c, &dent->
key, new_dir->
i_ino, &new_dentry->
d_name);
974 dent->
type = get_dent_type(old_inode->
i_mode);
978 zero_dent_node_unused(dent);
982 dent2 = (
void *)dent + aligned_dlen1;
984 dent_key_init_flash(c, &dent2->
key, old_dir->
i_ino,
991 zero_dent_node_unused(dent2);
994 p = (
void *)dent2 + aligned_dlen2;
996 pack_inode(c, p, new_inode, 0);
1001 pack_inode(c, p, old_dir, 1);
1003 pack_inode(c, p, old_dir, 0);
1004 p +=
ALIGN(plen, 8);
1005 pack_inode(c, p, new_dir, 1);
1008 if (last_reference) {
1014 new_ui->del_cmtno = c->
cmt_no;
1017 err = write_head(c,
BASEHD, dent, len, &lnum, &offs, sync);
1031 dent_key_init(c, &key, new_dir->
i_ino, &new_dentry->
d_name);
1036 err = ubifs_add_dirt(c, lnum, dlen2);
1040 dent_key_init(c, &key, old_dir->
i_ino, &old_dentry->
d_name);
1045 offs += aligned_dlen1 + aligned_dlen2;
1047 ino_key_init(c, &key, new_inode->
i_ino);
1051 offs +=
ALIGN(ilen, 8);
1054 ino_key_init(c, &key, old_dir->
i_ino);
1059 if (old_dir != new_dir) {
1060 offs +=
ALIGN(plen, 8);
1061 ino_key_init(c, &key, new_dir->
i_ino);
1067 finish_reservation(c);
1069 mark_inode_clean(c, new_ui);
1070 spin_lock(&new_ui->ui_lock);
1071 new_ui->synced_i_size = new_ui->ui_size;
1072 spin_unlock(&new_ui->ui_lock);
1087 finish_reservation(c);
1154 dbg_jnl(
"ino %lu, size %lld -> %lld",
1155 (
unsigned long)inum, old_size, new_size);
1171 zero_trun_node_unused(trun);
1178 data_key_init(c, &key, inum, blk);
1180 err = ubifs_tnc_lookup(c, &key, dn);
1192 err = recomp_data_node(dn, &dlen);
1199 zero_data_node_unused(dn);
1208 err = make_reservation(c,
BASEHD, len);
1212 pack_inode(c, ino, inode, 0);
1217 err = write_head(c,
BASEHD, ino, len, &lnum, &offs, sync);
1231 ino_key_init(c, &key, inum);
1232 err =
ubifs_tnc_add(c, &key, lnum, offs, UBIFS_INO_NODE_SZ);
1242 data_key_init(c, &key, inum, blk);
1246 data_key_init(c, &to_key, inum, blk);
1252 finish_reservation(c);
1256 mark_inode_clean(c, ui);
1264 finish_reservation(c);
1284 const struct inode *inode,
const struct qstr *nm)
1286 int err, xlen, hlen, len, lnum, xent_offs, aligned_xlen;
1293 dbg_jnl(
"host %lu, xattr ino %lu, name '%s', data len %d",
1304 aligned_xlen =
ALIGN(xlen, 8);
1313 err = make_reservation(c,
BASEHD, len);
1320 xent_key_init(c, &xent_key, host->
i_ino, nm);
1321 key_write(c, &xent_key, xent->
key);
1326 xent->
name[nm->len] =
'\0';
1327 zero_dent_node_unused(xent);
1330 ino = (
void *)xent + aligned_xlen;
1331 pack_inode(c, ino, inode, 0);
1333 pack_inode(c, ino, host, 1);
1335 err = write_head(c,
BASEHD, xent, len, &lnum, &xent_offs, sync);
1347 err = ubifs_add_dirt(c, lnum, xlen);
1355 lowest_ino_key(c, &key1, inode->
i_ino);
1356 highest_ino_key(c, &key2, inode->
i_ino);
1365 ino_key_init(c, &key1, host->
i_ino);
1366 err =
ubifs_tnc_add(c, &key1, lnum, xent_offs + len - hlen, hlen);
1370 finish_reservation(c);
1373 spin_unlock(&host_ui->
ui_lock);
1374 mark_inode_clean(c, host_ui);
1379 finish_reservation(c);
1397 const struct inode *
host)
1399 int err, len1, len2, aligned_len, aligned_len1, lnum,
offs;
1412 aligned_len1 =
ALIGN(len1, 8);
1413 aligned_len = aligned_len1 +
ALIGN(len2, 8);
1420 err = make_reservation(c,
BASEHD, aligned_len);
1424 pack_inode(c, ino, host, 0);
1425 pack_inode(c, (
void *)ino + aligned_len1, inode, 1);
1427 err = write_head(c,
BASEHD, ino, aligned_len, &lnum, &offs, 0);
1428 if (!sync && !err) {
1438 ino_key_init(c, &key, host->
i_ino);
1443 ino_key_init(c, &key, inode->
i_ino);
1444 err =
ubifs_tnc_add(c, &key, lnum, offs + aligned_len1, len2);
1448 finish_reservation(c);
1451 spin_unlock(&host_ui->
ui_lock);
1452 mark_inode_clean(c, host_ui);
1458 finish_reservation(c);