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.
This commit is contained in:
Adrien Destugues
2019-10-08 19:56:39 +02:00
parent 5bfbdf0dc8
commit 4337c7582c
2 changed files with 20 additions and 15 deletions
@@ -581,19 +581,19 @@ ExtentAllocator::Initialize()
status_t status = _LoadExtentTree(BTRFS_BLOCKGROUP_FLAG_DATA); status_t status = _LoadExtentTree(BTRFS_BLOCKGROUP_FLAG_DATA);
if (status != B_OK) { if (status != B_OK) {
ERROR("ExtentAllocator:: could not load exent tree (data)\n"); ERROR("ExtentAllocator:: could not load extent tree (data)\n");
return status; return status;
} }
status = _LoadExtentTree(BTRFS_BLOCKGROUP_FLAG_SYSTEM); status = _LoadExtentTree(BTRFS_BLOCKGROUP_FLAG_SYSTEM);
if (status != B_OK) { if (status != B_OK) {
ERROR("ExtentAllocator:: could not load exent tree (system)\n"); ERROR("ExtentAllocator:: could not load extent tree (system)\n");
return status; return status;
} }
status = _LoadExtentTree(BTRFS_BLOCKGROUP_FLAG_METADATA); status = _LoadExtentTree(BTRFS_BLOCKGROUP_FLAG_METADATA);
if (status != B_OK) { if (status != B_OK) {
ERROR("ExtentAllocator:: could not load exent tree (metadata)\n"); ERROR("ExtentAllocator:: could not load extent tree (metadata)\n");
return status; return status;
} }
@@ -431,19 +431,24 @@ Volume::Mount(const char* deviceName, uint32 flags)
TRACE("Volume::Mount() Find larget inode id % " B_PRIu64 "\n", TRACE("Volume::Mount() Find larget inode id % " B_PRIu64 "\n",
fLargestInodeID); fLargestInodeID);
// Initialize Journal if ((flags & B_MOUNT_READ_ONLY) != 0) {
fJournal = new(std::nothrow) Journal(this); fJournal = NULL;
if (fJournal == NULL) fExtentAllocator = NULL;
return B_NO_MEMORY; } else {
// Initialize Journal
fJournal = new(std::nothrow) Journal(this);
if (fJournal == NULL)
return B_NO_MEMORY;
// Initialize ExtentAllocator; // Initialize ExtentAllocator;
fExtentAllocator = new(std::nothrow) ExtentAllocator(this); fExtentAllocator = new(std::nothrow) ExtentAllocator(this);
if (fExtentAllocator == NULL) if (fExtentAllocator == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
status = fExtentAllocator->Initialize(); status = fExtentAllocator->Initialize();
if (status != B_OK) { if (status != B_OK) {
ERROR("could not initalize extent allocator!\n"); ERROR("could not initalize extent allocator!\n");
return status; return status;
}
} }
// ready // ready