using namespace crucible;
using namespace std;
+// Definitions for the static block-size members declared in bees.h.
+// Initialised by BeesContext::set_root_fd() from BTRFS_IOC_FS_INFO.
+uint32_t BeesContext::s_sectorsize = 0;
+uint32_t BeesContext::s_clone_alignment = 0;
+
void
BeesContext::set_reporter(shared_ptr<BeesReporter> reporter)
{
}
m_root_fd = fd;
+ // Populate filesystem-wide block-size constants from BTRFS_IOC_FS_INFO.
+ // These are static (single-instance daemon) and become the source of
+ // truth for new code in place of the hardcoded BLOCK_SIZE_CLONE /
+ // BLOCK_SIZE_SUMS constants. Must run before any other subsystem can
+ // observe them — set_root_fd is the earliest point where m_root_fd is
+ // usable, and runs before BeesConfig parsing or hash table init.
+ {
+ BEESTRACE("fetching BTRFS_IOC_FS_INFO for sectorsize / clone_alignment");
+ BtrfsIoctlFsInfoArgs fsi;
+ fsi.do_ioctl(m_root_fd);
+ s_sectorsize = fsi.sectorsize;
+ s_clone_alignment = fsi.clone_alignment;
+ THROW_CHECK1(runtime_error, s_sectorsize, s_sectorsize > 0);
+ THROW_CHECK1(runtime_error, s_clone_alignment, s_clone_alignment > 0);
+ BEESLOGINFO("filesystem sectorsize " << s_sectorsize
+ << ", clone_alignment " << s_clone_alignment);
+ }
+
// 65536 is big enough for two max-sized extents.
// Need enough total space in the cache for the maximum number of active threads.
m_resolve_cache.max_size(65536);
/// Required alignment for the FIDEDUPERANGE (FILE_EXTENT_SAME) ioctl source and
/// destination offsets. Should match the filesystem's clone_alignment, but is
/// currently hardcoded to 4096.
-/// FIXME: should read this from /sys/fs/btrfs/<FS-UUID>/clone_alignment
+///
+/// Soft-deprecated for new code: use @ref BeesContext::s_clone_alignment instead,
+/// which is populated from BTRFS_IOC_FS_INFO at startup and reflects the kernel's
+/// authoritative value. This constant is kept because some existing call sites
+/// rely on it being a compile-time value (template parameters, fixed-size arrays).
+/// Do not introduce new uses; existing uses can migrate incrementally.
const off_t BLOCK_SIZE_CLONE = 4096;
/// Granularity at which blocks are hashed for deduplication. Must be a multiple
* @c shared_ptr<BeesContext>.
*/
class BeesContext : public enable_shared_from_this<BeesContext> {
+public:
+ /// Filesystem sectorsize, in bytes (from BTRFS_IOC_FS_INFO).
+ /// Populated once by set_root_fd(); static because the daemon manages
+ /// exactly one filesystem. Use this in new code in place of the
+ /// hardcoded BLOCK_SIZE_SUMS / BLOCK_SIZE_CLONE constants where the
+ /// kernel value is the source of truth (alignment checks, EOF tail
+ /// computation, etc.). Existing constants remain for places that
+ /// still need a compile-time value (template parameters, array sizes).
+ static uint32_t s_sectorsize;
+
+ /// Filesystem clone-alignment, in bytes (from BTRFS_IOC_FS_INFO).
+ /// On modern btrfs this equals sectorsize, but the two are surfaced
+ /// separately by the kernel. Use this for EXTENT_SAME alignment
+ /// checks; use s_sectorsize for I/O / read alignment.
+ static uint32_t s_clone_alignment;
+
+private:
Fd m_home_fd; ///< FD to the bees home directory (contains state files).
shared_ptr<BeesConfig> m_config;