Skip to content

Commit

Permalink
Make GetBlockSize() use BackupFileSystem
Browse files Browse the repository at this point in the history
Refactor BackupAccountControl, BackupStoreContext and BackupCommands to call
BackupFileSystem to get the block size of the filesystem. It's a start.
  • Loading branch information
qris committed Aug 3, 2017
1 parent c9939f3 commit 1e8dec3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/backupstore/BackupAccountControl.cpp
Expand Up @@ -127,7 +127,7 @@ int BackupStoreAccountControl::SetLimit(const char *SoftLimitStr,
mDiscSetNum, false /* Read/Write */));

// Change the limits
int blocksize = BlockSizeOfDiscSet(mDiscSetNum);
int blocksize = GetBlockSize();
int64_t softlimit = SizeStringToBlocks(SoftLimitStr, blocksize);
int64_t hardlimit = SizeStringToBlocks(HardLimitStr, blocksize);
CheckSoftHardLimits(softlimit, hardlimit);
Expand Down Expand Up @@ -182,7 +182,7 @@ int BackupStoreAccountControl::PrintAccountInfo()
std::auto_ptr<BackupStoreInfo> ap_info(BackupStoreInfo::Load(mAccountID,
mRootDir, mDiscSetNum, true /* ReadOnly */));
BackupStoreInfo& info(*ap_info);
int BlockSize = BlockSizeOfDiscSet(mDiscSetNum);
int BlockSize = GetBlockSize();

// Then print out lots of info
std::cout << FormatUsageLineStart("Account ID", mMachineReadableOutput) <<
Expand Down
9 changes: 9 additions & 0 deletions lib/backupstore/BackupAccountControl.h
Expand Up @@ -29,6 +29,11 @@ class BackupAccountControl
bool mMachineReadableOutput;
std::auto_ptr<BackupFileSystem> mapFileSystem;

virtual int GetBlockSize()
{
return mapFileSystem->GetBlockSize();
}

public:
BackupAccountControl(const Configuration& config,
bool machineReadableOutput = false)
Expand Down Expand Up @@ -58,6 +63,10 @@ class BackupStoreAccountControl : public BackupAccountControl
mAccountID(AccountID),
mDiscSetNum(0)
{ }
virtual int GetBlockSize()
{
return BlockSizeOfDiscSet(mDiscSetNum);
}
int BlockSizeOfDiscSet(int discSetNum);
bool OpenAccount(NamedLock* pLock);
int SetLimit(const char *SoftLimitStr,
Expand Down
12 changes: 2 additions & 10 deletions lib/backupstore/BackupCommands.cpp
Expand Up @@ -957,10 +957,6 @@ std::auto_ptr<BackupProtocolMessage> BackupProtocolGetAccountUsage::DoCommand(Ba
// Get store info from context
const BackupStoreInfo &rinfo(rContext.GetBackupStoreInfo());

// Find block size
RaidFileController &rcontroller(RaidFileController::GetController());
RaidFileDiscSet &rdiscSet(rcontroller.GetDiscSet(rinfo.GetDiscSetNumber()));

// Return info
return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolAccountUsage(
rinfo.GetBlocksUsed(),
Expand All @@ -969,7 +965,7 @@ std::auto_ptr<BackupProtocolMessage> BackupProtocolGetAccountUsage::DoCommand(Ba
rinfo.GetBlocksInDirectories(),
rinfo.GetBlocksSoftLimit(),
rinfo.GetBlocksHardLimit(),
rdiscSet.GetBlockSize()
rContext.GetBlockSize()
));
}

Expand Down Expand Up @@ -1007,18 +1003,14 @@ std::auto_ptr<BackupProtocolMessage> BackupProtocolGetAccountUsage2::DoCommand(
// Get store info from context
const BackupStoreInfo &info(rContext.GetBackupStoreInfo());

// Find block size
RaidFileController &rcontroller(RaidFileController::GetController());
RaidFileDiscSet &rdiscSet(rcontroller.GetDiscSet(info.GetDiscSetNumber()));

// Return info
BackupProtocolAccountUsage2* usage = new BackupProtocolAccountUsage2();
std::auto_ptr<BackupProtocolMessage> reply(usage);
#define COPY(name) usage->Set ## name (info.Get ## name ())
COPY(AccountName);
usage->SetAccountEnabled(info.IsAccountEnabled());
COPY(ClientStoreMarker);
usage->SetBlockSize(rdiscSet.GetBlockSize());
usage->SetBlockSize(rContext.GetBlockSize());
COPY(LastObjectIDUsed);
COPY(BlocksUsed);
COPY(BlocksInCurrentFiles);
Expand Down
15 changes: 15 additions & 0 deletions lib/backupstore/BackupStoreContext.cpp
Expand Up @@ -70,6 +70,7 @@ BackupStoreContext::BackupStoreContext(int32_t ClientID,
mStoreDiscSet(-1),
mReadOnly(true),
mSaveStoreInfoDelay(STORE_INFO_SAVE_DELAY),
mpFileSystem(NULL),
mpTestHook(NULL)
// If you change the initialisers, be sure to update
// BackupStoreContext::CleanUp as well!
Expand Down Expand Up @@ -188,6 +189,20 @@ bool BackupStoreContext::AttemptToGetWriteLock()
}


void BackupStoreContext::SetClientHasAccount(const std::string &rStoreRoot,
int StoreDiscSet)
{
// Check that the BackupStoreContext hasn't already been initialised, or already
// created its own BackupFileSystem.
ASSERT(!mpFileSystem);
mClientHasAccount = true;
mapOwnFileSystem.reset(
new RaidBackupFileSystem(mClientID, rStoreRoot, StoreDiscSet));
mpFileSystem = mapOwnFileSystem.get();
mAccountRootDir = rStoreRoot;
mStoreDiscSet = StoreDiscSet;
}

// --------------------------------------------------------------------------
//
// Function
Expand Down
15 changes: 14 additions & 1 deletion lib/backupstore/BackupStoreContext.h
Expand Up @@ -16,6 +16,7 @@

#include "autogen_BackupProtocol.h"
#include "autogen_BackupStoreException.h"
#include "BackupFileSystem.h"
#include "BackupStoreInfo.h"
#include "BackupStoreRefCountDatabase.h"
#include "NamedLock.h"
Expand Down Expand Up @@ -95,7 +96,7 @@ class BackupStoreContext
}
}

void SetClientHasAccount(const std::string &rStoreRoot, int StoreDiscSet) {mClientHasAccount = true; mAccountRootDir = rStoreRoot; mStoreDiscSet = StoreDiscSet;}
void SetClientHasAccount(const std::string &rStoreRoot, int StoreDiscSet);
bool GetClientHasAccount() const {return mClientHasAccount;}
const std::string &GetAccountRoot() const {return mAccountRootDir;}
int GetStoreDiscSet() const {return mStoreDiscSet;}
Expand Down Expand Up @@ -185,6 +186,7 @@ class BackupStoreContext
// Info
int32_t GetClientID() const {return mClientID;}
const std::string& GetConnectionDetails() { return mConnectionDetails; }
virtual int GetBlockSize() { return mpFileSystem->GetBlockSize(); }

private:
void MakeObjectFilename(int64_t ObjectID, std::string &rOutput, bool EnsureDirectoryExists = false);
Expand All @@ -211,6 +213,17 @@ class BackupStoreContext
// Store info
std::auto_ptr<BackupStoreInfo> mapStoreInfo;

// mapOwnFileSystem is initialised when we created our own BackupFileSystem,
// using the old constructor. It ensures that the BackupFileSystem is deleted
// when this BackupStoreContext is destroyed. TODO: stop using that old
// constructor, and remove this member.
std::auto_ptr<BackupFileSystem> mapOwnFileSystem;

// mpFileSystem is always initialised when SetClientHasAccount() has been called,
// whether or not we created it ourselves, and all internal functions use this
// member instead of mapOwnFileSystem.
BackupFileSystem* mpFileSystem;

// Non-const version for internal use:
BackupStoreInfo& GetBackupStoreInfoInternal() const
{
Expand Down

0 comments on commit 1e8dec3

Please sign in to comment.