summaryrefslogtreecommitdiff
path: root/cmd_migrate.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2019-10-04 16:25:58 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2019-10-04 16:26:48 -0400
commit62f5e4fa67dde8255fa18a06d5354cdca02b6fc7 (patch)
tree1819ccb1adf6d449d7b4e7958e344ad963700f7b /cmd_migrate.c
parentb540b170c9c277ffc5bdaf6b05e21c30f142dfc9 (diff)
Update bcachefs sources to ce9293e9d0 bcachefs: Factor out fs-common.c
Diffstat (limited to 'cmd_migrate.c')
-rw-r--r--cmd_migrate.c50
1 files changed, 17 insertions, 33 deletions
diff --git a/cmd_migrate.c b/cmd_migrate.c
index 7d6af443..7d15a08e 100644
--- a/cmd_migrate.c
+++ b/cmd_migrate.c
@@ -30,7 +30,7 @@
#include "libbcachefs/btree_update.h"
#include "libbcachefs/buckets.h"
#include "libbcachefs/dirent.h"
-#include "libbcachefs/fs.h"
+#include "libbcachefs/fs-common.h"
#include "libbcachefs/inode.h"
#include "libbcachefs/io.h"
#include "libbcachefs/replicas.h"
@@ -38,6 +38,9 @@
#include "libbcachefs/super.h"
#include "libbcachefs/xattr.h"
+/* XXX cut and pasted from fsck.c */
+#define QSTR(n) { { { .len = strlen(n) } }, .name = n }
+
static char *dev_t_to_path(dev_t dev)
{
char link[PATH_MAX], *p;
@@ -123,39 +126,21 @@ static void update_inode(struct bch_fs *c,
ret = bch2_btree_insert(c, BTREE_ID_INODES, &packed.inode.k_i,
NULL, NULL, 0);
if (ret)
- die("error creating file: %s", strerror(-ret));
-}
-
-static void create_dirent(struct bch_fs *c,
- struct bch_inode_unpacked *parent,
- const char *name, u64 inum, mode_t mode)
-{
- struct bch_hash_info parent_hash_info = bch2_hash_info_init(c, parent);
- struct qstr qname = { { { .len = strlen(name), } }, .name = name };
-
- int ret = bch2_dirent_create(c, parent->bi_inum, &parent_hash_info,
- mode_to_type(mode), &qname,
- inum, NULL, BCH_HASH_SET_MUST_CREATE);
- if (ret)
- die("error creating file: %s", strerror(-ret));
-
- if (S_ISDIR(mode))
- parent->bi_nlink++;
+ die("error updating inode: %s", strerror(-ret));
}
static void create_link(struct bch_fs *c,
struct bch_inode_unpacked *parent,
const char *name, u64 inum, mode_t mode)
{
+ struct qstr qstr = QSTR(name);
struct bch_inode_unpacked inode;
- int ret = bch2_inode_find_by_inum(c, inum, &inode);
- if (ret)
- die("error looking up hardlink: %s", strerror(-ret));
- inode.bi_nlink++;
- update_inode(c, &inode);
-
- create_dirent(c, parent, name, inum, mode);
+ int ret = bch2_trans_do(c, NULL, BTREE_INSERT_ATOMIC,
+ bch2_link_trans(&trans, parent->bi_inum,
+ inum, &inode, &qstr));
+ if (ret)
+ die("error creating hardlink: %s", strerror(-ret));
}
static struct bch_inode_unpacked create_file(struct bch_fs *c,
@@ -164,18 +149,17 @@ static struct bch_inode_unpacked create_file(struct bch_fs *c,
uid_t uid, gid_t gid,
mode_t mode, dev_t rdev)
{
+ struct qstr qstr = QSTR(name);
struct bch_inode_unpacked new_inode;
- int ret;
-
- bch2_inode_init(c, &new_inode, uid, gid, mode, rdev, parent);
- ret = bch2_inode_create(c, &new_inode, BLOCKDEV_INODE_MAX, 0,
- &c->unused_inode_hint);
+ int ret = bch2_trans_do(c, NULL, BTREE_INSERT_ATOMIC,
+ bch2_create_trans(&trans,
+ parent->bi_inum, parent,
+ &new_inode, &qstr,
+ uid, gid, mode, rdev, NULL, NULL));
if (ret)
die("error creating file: %s", strerror(-ret));
- create_dirent(c, parent, name, new_inode.bi_inum, mode);
-
return new_inode;
}