BFS: Use the shared QueryParser.

Ideally should have no functional changes from the old one.

Change-Id: Id557d8fb069603221887447597ef0ffce5de07a6
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7705
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Axel Dörfler <[email protected]>
This commit is contained in:
Augustin Cavalier
2024-06-24 19:40:08 +00:00
committed by waddlesplash
parent 7da55c7296
commit 0a44afc6bf
6 changed files with 295 additions and 1424 deletions
+3 -1
View File
@@ -337,7 +337,7 @@ private:
class NodeGetter : public CachedBlock { class NodeGetter : public CachedBlock {
public: public:
NodeGetter(Volume* volume) NodeGetter(Volume* volume = NULL)
: :
CachedBlock(volume) CachedBlock(volume)
{ {
@@ -349,6 +349,8 @@ public:
status_t SetTo(const Inode* inode) status_t SetTo(const Inode* inode)
{ {
Unset();
fVolume = inode->GetVolume();
return CachedBlock::SetTo(fVolume->VnodeToBlock(inode->ID())); return CachedBlock::SetTo(fVolume->VnodeToBlock(inode->ID()));
} }
File diff suppressed because it is too large Load Diff
+29 -51
View File
@@ -1,5 +1,6 @@
/* /*
* Copyright 2001-2008, Axel Dörfler, [email protected]. * Copyright 2001-2008, Axel Dörfler, [email protected].
* Copyright 2024, Haiku, Inc. All rights reserved.
* This file may be used under the terms of the MIT License. * This file may be used under the terms of the MIT License.
*/ */
#ifndef QUERY_H #ifndef QUERY_H
@@ -10,70 +11,47 @@
#include "Index.h" #include "Index.h"
class Volume; namespace QueryParser {
class Term; template<typename QueryPolicy> class Query;
class Equation;
class TreeIterator;
class Query;
class Expression {
public:
Expression(char* expr);
~Expression();
status_t InitCheck();
const char* Position() const { return fPosition; }
Term* Root() const { return fTerm; }
protected:
Term* ParseOr(char** expr);
Term* ParseAnd(char** expr);
Term* ParseEquation(char** expr);
bool IsOperator(char** expr, char op);
private:
Expression(const Expression& other);
Expression& operator=(const Expression& other);
// no implementation
char* fPosition;
Term* fTerm;
}; };
class Query : public SinglyLinkedListLinkImpl<Query> { class Volume;
class Query : public DoublyLinkedListLinkImpl<Query> {
public: public:
Query(Volume* volume, Expression* expression,
uint32 flags);
~Query(); ~Query();
status_t Rewind(); static status_t Create(Volume* volume, const char* queryString,
status_t GetNextEntry(struct dirent* , size_t size); uint32 flags, port_id port, uint32 token,
Query*& _query);
void SetLiveMode(port_id port, int32 token); status_t Rewind();
void LiveUpdate(Inode* inode, const char* attribute, status_t GetNextEntry(struct dirent* entry, size_t size);
int32 type, const uint8* oldKey,
size_t oldLength, const uint8* newKey, void LiveUpdate(Inode* inode,
size_t newLength); const char* attribute, int32 type,
void LiveUpdateRenameMove(Inode* inode, const void* oldKey, size_t oldLength,
const void* newKey, size_t newLength);
void LiveUpdateRenameMove(Inode* node,
ino_t oldDirectoryID, const char* oldName, ino_t oldDirectoryID, const char* oldName,
size_t oldLength, ino_t newDirectoryID, size_t oldLength, ino_t newDirectoryID,
const char* newName, size_t newLength); const char* newName, size_t newLength);
private:
struct QueryPolicy;
friend struct QueryPolicy;
typedef QueryParser::Query<QueryPolicy> QueryImpl;
Expression* GetExpression() const { return fExpression; } private:
Query(Volume* volume);
status_t _Init(const char* queryString, uint32 flags,
port_id port, uint32 token);
private: private:
Volume* fVolume; Volume* fVolume;
Expression* fExpression; QueryImpl* fImpl;
Equation* fCurrent;
TreeIterator* fIterator;
Index fIndex;
Stack<Equation*> fStack;
uint32 fFlags;
port_id fPort;
int32 fToken;
}; };
#endif // QUERY_H #endif // QUERY_H
@@ -413,7 +413,7 @@ Volume::UpdateLiveQueries(Inode* inode, const char* attribute, int32 type,
{ {
MutexLocker _(fQueryLock); MutexLocker _(fQueryLock);
SinglyLinkedList<Query>::Iterator iterator = fQueries.GetIterator(); DoublyLinkedList<Query>::Iterator iterator = fQueries.GetIterator();
while (iterator.HasNext()) { while (iterator.HasNext()) {
Query* query = iterator.Next(); Query* query = iterator.Next();
query->LiveUpdate(inode, attribute, type, oldKey, oldLength, newKey, query->LiveUpdate(inode, attribute, type, oldKey, oldLength, newKey,
@@ -431,7 +431,7 @@ Volume::UpdateLiveQueriesRenameMove(Inode* inode, ino_t oldDirectoryID,
size_t oldLength = strlen(oldName); size_t oldLength = strlen(oldName);
size_t newLength = strlen(newName); size_t newLength = strlen(newName);
SinglyLinkedList<Query>::Iterator iterator = fQueries.GetIterator(); DoublyLinkedList<Query>::Iterator iterator = fQueries.GetIterator();
while (iterator.HasNext()) { while (iterator.HasNext()) {
Query* query = iterator.Next(); Query* query = iterator.Next();
query->LiveUpdateRenameMove(inode, oldDirectoryID, oldName, oldLength, query->LiveUpdateRenameMove(inode, oldDirectoryID, oldName, oldLength,
+1 -1
View File
@@ -173,7 +173,7 @@ protected:
vint32 fDirtyCachedBlocks; vint32 fDirtyCachedBlocks;
mutex fQueryLock; mutex fQueryLock;
SinglyLinkedList<Query> fQueries; DoublyLinkedList<Query> fQueries;
uint32 fFlags; uint32 fFlags;
@@ -2268,26 +2268,10 @@ bfs_open_query(fs_volume* _volume, const char* queryString, uint32 flags,
Volume* volume = (Volume*)_volume->private_volume; Volume* volume = (Volume*)_volume->private_volume;
Expression* expression = new(std::nothrow) Expression((char*)queryString); Query* query;
if (expression == NULL) status_t error = Query::Create(volume, queryString, flags, port, token, query);
RETURN_ERROR(B_NO_MEMORY); if (error != B_OK)
return error;
if (expression->InitCheck() < B_OK) {
INFORM(("Could not parse query \"%s\", stopped at: \"%s\"\n",
queryString, expression->Position()));
delete expression;
RETURN_ERROR(B_BAD_VALUE);
}
Query* query = new(std::nothrow) Query(volume, expression, flags);
if (query == NULL) {
delete expression;
RETURN_ERROR(B_NO_MEMORY);
}
if (flags & B_LIVE_QUERY)
query->SetLiveMode(port, token);
*_cookie = (void*)query; *_cookie = (void*)query;
@@ -2309,9 +2293,7 @@ bfs_free_query_cookie(fs_volume* _volume, void* cookie)
FUNCTION(); FUNCTION();
Query* query = (Query*)cookie; Query* query = (Query*)cookie;
Expression* expression = query->GetExpression();
delete query; delete query;
delete expression;
return B_OK; return B_OK;
} }