From 4337c7582c835720d18511deb8390774eb96ec60 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Tue, 8 Oct 2019 19:56:39 +0200 Subject: [PATCH] btrfs: do not create Journal and ExtentAllocator for read-only They are not needed, and the ExtentAllocator seems to currently fail on an empty volume I created for testing. --- .../file_systems/btrfs/ExtentAllocator.cpp | 6 ++-- .../kernel/file_systems/btrfs/Volume.cpp | 29 +++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/add-ons/kernel/file_systems/btrfs/ExtentAllocator.cpp b/src/add-ons/kernel/file_systems/btrfs/ExtentAllocator.cpp index a677700378..cbffe1af72 100644 --- a/src/add-ons/kernel/file_systems/btrfs/ExtentAllocator.cpp +++ b/src/add-ons/kernel/file_systems/btrfs/ExtentAllocator.cpp @@ -581,19 +581,19 @@ ExtentAllocator::Initialize() status_t status = _LoadExtentTree(BTRFS_BLOCKGROUP_FLAG_DATA); if (status != B_OK) { - ERROR("ExtentAllocator:: could not load exent tree (data)\n"); + ERROR("ExtentAllocator:: could not load extent tree (data)\n"); return status; } status = _LoadExtentTree(BTRFS_BLOCKGROUP_FLAG_SYSTEM); if (status != B_OK) { - ERROR("ExtentAllocator:: could not load exent tree (system)\n"); + ERROR("ExtentAllocator:: could not load extent tree (system)\n"); return status; } status = _LoadExtentTree(BTRFS_BLOCKGROUP_FLAG_METADATA); if (status != B_OK) { - ERROR("ExtentAllocator:: could not load exent tree (metadata)\n"); + ERROR("ExtentAllocator:: could not load extent tree (metadata)\n"); return status; } diff --git a/src/add-ons/kernel/file_systems/btrfs/Volume.cpp b/src/add-ons/kernel/file_systems/btrfs/Volume.cpp index c1bfbaf331..ff4f227bce 100644 --- a/src/add-ons/kernel/file_systems/btrfs/Volume.cpp +++ b/src/add-ons/kernel/file_systems/btrfs/Volume.cpp @@ -431,19 +431,24 @@ Volume::Mount(const char* deviceName, uint32 flags) TRACE("Volume::Mount() Find larget inode id % " B_PRIu64 "\n", fLargestInodeID); - // Initialize Journal - fJournal = new(std::nothrow) Journal(this); - if (fJournal == NULL) - return B_NO_MEMORY; + if ((flags & B_MOUNT_READ_ONLY) != 0) { + fJournal = NULL; + fExtentAllocator = NULL; + } else { + // Initialize Journal + fJournal = new(std::nothrow) Journal(this); + if (fJournal == NULL) + return B_NO_MEMORY; - // Initialize ExtentAllocator; - fExtentAllocator = new(std::nothrow) ExtentAllocator(this); - if (fExtentAllocator == NULL) - return B_NO_MEMORY; - status = fExtentAllocator->Initialize(); - if (status != B_OK) { - ERROR("could not initalize extent allocator!\n"); - return status; + // Initialize ExtentAllocator; + fExtentAllocator = new(std::nothrow) ExtentAllocator(this); + if (fExtentAllocator == NULL) + return B_NO_MEMORY; + status = fExtentAllocator->Initialize(); + if (status != B_OK) { + ERROR("could not initalize extent allocator!\n"); + return status; + } } // ready