* `open_clear`: The open FD cache was cleared to avoid keeping file descriptors open too long.
* `open_fail_enoent`: A file could not be opened because it no longer exists (i.e. it was deleted or renamed during the lookup/resolve operations).
- * `open_fail_error`: A file could not be opened for other reasons (e.g. IO error, permission denied, out of resources).
+ * `open_fail_error`: A file could not be opened for other reasons (e.g. IO error, permission denied, out of resources). The open throws if no other path to the inode opens.
* `open_file`: A file was successfully opened. This counts only the `open()` system call, not other reasons why the opened FD might not be usable.
* `open_hit`: A file was successfully opened and the FD was acceptable.
* `open_ino_ms`: Total time spent executing the `open()` system call.
* `open_lookup_empty`: No paths were found for the inode in the `INO_PATHS` ioctl.
* `open_lookup_enoent`: The `INO_PATHS` ioctl returned ENOENT.
- * `open_lookup_error`: The `INO_PATHS` ioctl returned a different error.
+ * `open_lookup_error`: The `INO_PATHS` ioctl returned a different error. The open throws.
* `open_lookup_ok`: The `INO_PATHS` ioctl successfully returned a list of one or more filenames.
* `open_no_path`: All attempts to open a file by `(root, inode)` pair failed.
* `open_no_root`: An attempt to open a file by `(root, inode)` pair failed because the `root` could not be opened.
* `open_root_ms`: Total time spent opening subvol root FDs.
- * `open_wrong_dev`: A FD returned by `open()` did not match the device belonging to the filesystem subvol.
+ * `open_wrong_dev`: A FD returned by `open()` did not match the device belonging to the filesystem subvol. The open throws.
* `open_wrong_flags`: A FD returned by `open()` had incompatible flags (`NODATASUM` / `NODATACOW`).
- * `open_wrong_ino`: A FD returned by `open()` did not match the expected inode (i.e. the file was renamed or replaced during the lookup/resolve operations).
- * `open_wrong_root`: A FD returned by `open()` did not match the expected subvol ID (i.e. `root`).
+ * `open_wrong_ino`: A FD returned by `open()` did not match the expected inode (i.e. the file was renamed or replaced during the lookup/resolve operations). The open throws.
+ * `open_wrong_root`: A FD returned by `open()` did not match the expected subvol ID (i.e. `root`). The open throws.
pairbackward
------------
* `root_found`: A root FD was successfully opened.
* `root_notfound`: A root FD could not be opened because all candidate paths could not be opened, or there were no paths available.
* `root_ok`: A root FD was opened and its correctness verified.
- * `root_open_fail`: A root FD `open()` attempt returned an error.
+ * `root_open_fail`: A root FD `open()` attempt returned an error. Any error but ENOENT throws.
* `root_parent_open_fail`: A recursive call to open the parent of a subvol failed.
* `root_parent_open_ok`: A recursive call to open the parent of a subvol succeeded.
* `root_parent_open_try`: A recursive call to open the parent of a subvol was attempted.
* `root_parent_path_empty`: No path could be found to connect a parent root FD to its child.
- * `root_parent_path_fail`: The `INO_PATH` ioctl failed to find a name for a child subvol relative to its parent.
- * `root_parent_path_open_fail`: The `open()` call in a recursive call to open the parent of a subvol returned an error.
+ * `root_parent_path_fail`: The `INO_PATH` ioctl failed to find a name for a child subvol relative to its parent. Any error but ENOENT throws.
+ * `root_parent_path_open_fail`: The `open()` call in a recursive call to open the parent of a subvol returned an error. Any error but ENOENT throws.
* `root_workaround_btrfs_send`: A subvol was determined to be read-only and disabled to implement the btrfs send workaround.
scan
BEESTRACE("dirid " << dirid << " root " << rootid << " INO_PATH");
BtrfsIoctlInoPathArgs ino(dirid);
if (!ino.do_ioctl_nothrow(parent_fd)) {
- BEESLOGDEBUG("dirid " << dirid
- << " inode path lookup failed in parent_fd "
- << name_fd(parent_fd) << ": " << strerror(errno));
+ const auto e = errno;
BEESCOUNT(root_parent_path_fail);
+ if (e != ENOENT) {
+ THROW_ERRNO_VALUE(e, "dirid " << dirid
+ << " inode path lookup in parent_fd " << name_fd(parent_fd));
+ }
return Fd();
}
if (ino.m_paths.empty()) {
parent_fd
);
if (!parent_fd) {
- BEESLOGDEBUG("no parent_fd from dirid " << dirid
- << " in parent_rootid " << parent_rootid);
+ const auto e = errno;
BEESCOUNT(root_parent_path_open_fail);
+ if (e != ENOENT) {
+ THROW_ERRNO_VALUE(e, "open dirid " << dirid
+ << " path " << dir_path << " in parent_rootid " << parent_rootid);
+ }
return Fd();
}
dir_and_name = dir_path + "/" + name;
Fd rv(bees_openat(parent_fd, name.c_str(), FLAGS_OPEN_DIR),
dir_and_name, parent_root_fd);
if (!rv) {
- BEESLOGDEBUG("open failed for name " << name << " in parent_fd "
- << name_fd(parent_fd) << ": " << strerror(errno));
+ const auto e = errno;
BEESCOUNT(root_open_fail);
+ if (e != ENOENT) {
+ THROW_ERRNO_VALUE(e, "open root " << rootid << " name " << name
+ << " in parent_fd " << name_fd(parent_fd));
+ }
return rv;
}
BEESCOUNT(root_found);
BEESTRACE("looking up ino " << ino);
BtrfsIoctlInoPathArgs ipa(ino);
if (!ipa.do_ioctl_nothrow(root_fd)) {
- if (errno == ENOENT) {
- BEESCOUNT(open_lookup_enoent);
- } else {
- BEESLOGINFO("Lookup root " << root << " ino " << ino
- << " failed: " << strerror(errno));
+ const auto e = errno;
+ if (e != ENOENT) {
BEESCOUNT(open_lookup_error);
+ THROW_ERRNO_VALUE(e, "lookup root " << root << " ino " << ino);
}
+ BEESCOUNT(open_lookup_enoent);
return Fd();
}
BEESTRACE("searching paths for root " << root << " ino " << ino);
Fd rv;
+ int open_errno = 0;
+ string open_errno_path;
if (ipa.m_paths.empty()) {
BEESCOUNT(open_lookup_empty);
}
rv = Fd(bees_openat(root_fd, file_path.c_str(), FLAGS_OPEN_FILE),
file_path, root_fd);
if (!rv) {
- if (errno == ENOENT) {
- BEESCOUNT(open_fail_enoent);
- } else {
- BEESLOGWARN("Could not open path '" << file_path << "' at root "
- << root << " " << name_fd(root_fd) << ": "
- << strerror(errno));
+ const auto e = errno;
+ if (e != ENOENT) {
+ // Another hardlink may still open, so try the rest
+ // before throwing.
BEESCOUNT(open_fail_error);
+ if (!open_errno) {
+ open_errno = e;
+ open_errno_path = file_path;
+ }
+ } else {
+ BEESCOUNT(open_fail_enoent);
}
continue;
}
Stat file_stat(rv);
if (file_stat.st_ino != ino) {
- BEESLOGWARN("Opening " << name_fd(root_fd) << "/" << file_path
+ BEESCOUNT(open_wrong_ino);
+ THROW_ERROR(runtime_error, "opening " << name_fd(root_fd) << "/" << file_path
<< " found wrong inode " << file_stat.st_ino
<< " instead of " << ino);
- rv = Fd();
- BEESCOUNT(open_wrong_ino);
- break;
}
auto file_root = btrfs_get_root_id(rv);
if (file_root != root) {
- BEESLOGWARN("Opening " << name_fd(root_fd) << "/" << file_path
- << " found wrong root " << file_root << " instead of " << root);
- rv = Fd();
BEESCOUNT(open_wrong_root);
- break;
+ THROW_ERROR(runtime_error, "opening " << name_fd(root_fd) << "/" << file_path
+ << " found wrong root " << file_root << " instead of " << root);
}
Stat root_stat(root_fd);
if (root_stat.st_dev != file_stat.st_dev) {
- BEESLOGWARN("Opening root " << name_fd(root_fd) << " path "
+ BEESCOUNT(open_wrong_dev);
+ THROW_ERROR(runtime_error, "opening root " << name_fd(root_fd) << " path "
<< file_path << " found path st_dev " << file_stat.st_dev
<< " but root st_dev is " << root_stat.st_dev);
- rv = Fd();
- BEESCOUNT(open_wrong_dev);
- break;
}
BEESCOUNT(open_hit);
}
BEESCOUNT(open_no_path);
+ if (open_errno) {
+ THROW_ERRNO_VALUE(open_errno, "open path '" << open_errno_path << "' at root "
+ << root << " " << name_fd(root_fd));
+ }
return Fd();
}