From bf6ae80eeec6afcbee505d22af8e62f60dc1c9a6 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Tue, 30 Oct 2018 01:34:52 -0400 Subject: [PATCH] roots: simplify BeesRoots::transid_max_nocache BeesRoots::transid_max_nocache calls btrfs_get_root_transid() which retrieves the transid of the root of the given Fd. Since the FS_TREE (subvol 5) is the root of the subvol hierarchy, it will always have the highest transid on the filesystem, and we do not need to look at any others. Also fix a bug where we pass BTRFS_FS_TREE_OBJECTID instead of the file descriptor root_fd() to btrfs_get_root_transid(). If BEESHOME is somewhere on the same btrfs filesystem, and there are no leaked FDs at bees startup, then BTRFS_FS_TREE_OBJECTID (5) usually has the same integer value as a valid file descriptor of some object on the filesystem that has a regularly increasing transid value. If Fd 5 happens to be a file in BEESHOME then bees itself drives the transid increments. This, combined with the search of all subvol roots, hides the bug (unless Fd 5 gets closed somehow). Signed-off-by: Zygo Blaxell --- src/bees-roots.cc | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/src/bees-roots.cc b/src/bees-roots.cc index 2e92583..c266e2a 100644 --- a/src/bees-roots.cc +++ b/src/bees-roots.cc @@ -202,38 +202,8 @@ BeesRoots::transid_max_nocache() BEESNOTE("Calculating transid_max (" << rv << " as of root " << root << ")"); BEESTRACE("Calculating transid_max..."); - rv = btrfs_get_root_transid(root); + rv = btrfs_get_root_transid(m_ctx->root_fd()); - // XXX: Do we need any of this? Or is - // m_transid_re.update(btrfs_get_root_transid(BTRFS_FS_TREE_OBJECTID)) good enough? - - BtrfsIoctlSearchKey sk; - sk.tree_id = BTRFS_ROOT_TREE_OBJECTID; - sk.min_type = sk.max_type = BTRFS_ROOT_BACKREF_KEY; - sk.min_objectid = root; - - while (true) { - sk.nr_items = 1024; - sk.do_ioctl(m_ctx->root_fd()); - - if (sk.m_result.empty()) { - break; - } - - for (auto i : sk.m_result) { - sk.next_min(i); - if (i.type == BTRFS_ROOT_BACKREF_KEY) { - if (i.transid > rv) { - BEESLOGDEBUG("transid_max root " << i.objectid << " parent " << i.offset << " transid " << i.transid); - BEESCOUNT(transid_max_miss); - } - root = i.objectid; - } - if (i.transid > rv) { - rv = i.transid; - } - } - } m_transid_re.update(rv); return rv; }