1*5a1d355fSStephan Aßmus // VolumeManager.h 2*5a1d355fSStephan Aßmus 3*5a1d355fSStephan Aßmus #ifndef NET_FS_VOLUME_MANAGER_H 4*5a1d355fSStephan Aßmus #define NET_FS_VOLUME_MANAGER_H 5*5a1d355fSStephan Aßmus 6*5a1d355fSStephan Aßmus #include <AutoLocker.h> 7*5a1d355fSStephan Aßmus #include <Entry.h> 8*5a1d355fSStephan Aßmus #include <Locker.h> 9*5a1d355fSStephan Aßmus #include <util/DoublyLinkedList.h> 10*5a1d355fSStephan Aßmus 11*5a1d355fSStephan Aßmus #include "BlockingQueue.h" 12*5a1d355fSStephan Aßmus #include "NodeMonitor.h" 13*5a1d355fSStephan Aßmus #include "NodeMonitoringEvent.h" 14*5a1d355fSStephan Aßmus 15*5a1d355fSStephan Aßmus class ClientVolume; 16*5a1d355fSStephan Aßmus class Directory; 17*5a1d355fSStephan Aßmus class Entry; 18*5a1d355fSStephan Aßmus class Node; 19*5a1d355fSStephan Aßmus class Path; 20*5a1d355fSStephan Aßmus class QueryHandle; 21*5a1d355fSStephan Aßmus class QueryDomain; 22*5a1d355fSStephan Aßmus class Volume; 23*5a1d355fSStephan Aßmus 24*5a1d355fSStephan Aßmus // VolumeManager 25*5a1d355fSStephan Aßmus class VolumeManager : private NodeMonitorListener { 26*5a1d355fSStephan Aßmus private: 27*5a1d355fSStephan Aßmus VolumeManager(); 28*5a1d355fSStephan Aßmus ~VolumeManager(); 29*5a1d355fSStephan Aßmus 30*5a1d355fSStephan Aßmus status_t Init(); 31*5a1d355fSStephan Aßmus 32*5a1d355fSStephan Aßmus public: 33*5a1d355fSStephan Aßmus static status_t CreateDefault(); 34*5a1d355fSStephan Aßmus static void DeleteDefault(); 35*5a1d355fSStephan Aßmus static VolumeManager* GetDefault(); 36*5a1d355fSStephan Aßmus 37*5a1d355fSStephan Aßmus bool Lock(); 38*5a1d355fSStephan Aßmus void Unlock(); 39*5a1d355fSStephan Aßmus 40*5a1d355fSStephan Aßmus int64 GetRevision() const; 41*5a1d355fSStephan Aßmus 42*5a1d355fSStephan Aßmus Volume* GetVolume(dev_t volumeID, bool add = false); 43*5a1d355fSStephan Aßmus Volume* GetRootVolume() const; 44*5a1d355fSStephan Aßmus 45*5a1d355fSStephan Aßmus status_t AddClientVolume(ClientVolume* clientVolume); 46*5a1d355fSStephan Aßmus void RemoveClientVolume(ClientVolume* clientVolume); 47*5a1d355fSStephan Aßmus 48*5a1d355fSStephan Aßmus status_t AddNode(Node* node); 49*5a1d355fSStephan Aßmus void RemoveNode(Node* node); 50*5a1d355fSStephan Aßmus Node* GetNode(dev_t volumeID, ino_t nodeID); 51*5a1d355fSStephan Aßmus status_t LoadNode(const struct stat& st, Node** node); 52*5a1d355fSStephan Aßmus 53*5a1d355fSStephan Aßmus Directory* GetDirectory(dev_t volumeID, ino_t nodeID); 54*5a1d355fSStephan Aßmus Directory* GetRootDirectory() const; 55*5a1d355fSStephan Aßmus Directory* GetParentDirectory(Directory* directory); 56*5a1d355fSStephan Aßmus status_t LoadDirectory(dev_t volumeID, ino_t directoryID, 57*5a1d355fSStephan Aßmus Directory** directory); 58*5a1d355fSStephan Aßmus 59*5a1d355fSStephan Aßmus status_t AddEntry(Entry* entry); 60*5a1d355fSStephan Aßmus void RemoveEntry(Entry* entry); 61*5a1d355fSStephan Aßmus void DeleteEntry(Entry* entry, bool keepNode); 62*5a1d355fSStephan Aßmus Entry* GetEntry(dev_t volumeID, ino_t directoryID, 63*5a1d355fSStephan Aßmus const char* name); 64*5a1d355fSStephan Aßmus Entry* GetEntry(const entry_ref& ref); 65*5a1d355fSStephan Aßmus status_t LoadEntry(dev_t volumeID, ino_t directoryID, 66*5a1d355fSStephan Aßmus const char* name, bool loadDir, 67*5a1d355fSStephan Aßmus Entry** entry); 68*5a1d355fSStephan Aßmus 69*5a1d355fSStephan Aßmus status_t OpenQuery(QueryDomain* queryDomain, 70*5a1d355fSStephan Aßmus const char* queryString, uint32 flags, 71*5a1d355fSStephan Aßmus port_id remotePort, int32 remoteToken, 72*5a1d355fSStephan Aßmus QueryHandle** handle); 73*5a1d355fSStephan Aßmus 74*5a1d355fSStephan Aßmus status_t CompletePathToRoot(Directory* directory); 75*5a1d355fSStephan Aßmus 76*5a1d355fSStephan Aßmus status_t GetPath(Entry* entry, Path* path); 77*5a1d355fSStephan Aßmus status_t GetPath(Node* node, Path* path); 78*5a1d355fSStephan Aßmus 79*5a1d355fSStephan Aßmus bool DirectoryContains(Directory* directory, 80*5a1d355fSStephan Aßmus Entry* entry); 81*5a1d355fSStephan Aßmus bool DirectoryContains(Directory* directory, 82*5a1d355fSStephan Aßmus Directory* descendant, bool reflexive); 83*5a1d355fSStephan Aßmus bool DirectoryContains(Directory* directory, 84*5a1d355fSStephan Aßmus Node* descendant, bool reflexive); 85*5a1d355fSStephan Aßmus 86*5a1d355fSStephan Aßmus private: 87*5a1d355fSStephan Aßmus virtual void ProcessNodeMonitoringEvent( 88*5a1d355fSStephan Aßmus NodeMonitoringEvent* event); 89*5a1d355fSStephan Aßmus 90*5a1d355fSStephan Aßmus status_t _AddVolume(dev_t volumeID, 91*5a1d355fSStephan Aßmus Volume** volume = NULL); 92*5a1d355fSStephan Aßmus 93*5a1d355fSStephan Aßmus void _EntryCreated(EntryCreatedEvent* event); 94*5a1d355fSStephan Aßmus void _EntryRemoved(EntryRemovedEvent* event, 95*5a1d355fSStephan Aßmus bool keepNode); 96*5a1d355fSStephan Aßmus void _EntryMoved(EntryMovedEvent* event); 97*5a1d355fSStephan Aßmus void _NodeStatChanged(StatChangedEvent* event); 98*5a1d355fSStephan Aßmus void _NodeAttributeChanged( 99*5a1d355fSStephan Aßmus AttributeChangedEvent* event); 100*5a1d355fSStephan Aßmus void _VolumeMounted(VolumeMountedEvent* event); 101*5a1d355fSStephan Aßmus void _VolumeUnmounted(VolumeUnmountedEvent* event); 102*5a1d355fSStephan Aßmus 103*5a1d355fSStephan Aßmus void _QueryEntryCreated(EntryCreatedEvent* event); 104*5a1d355fSStephan Aßmus void _QueryEntryRemoved(EntryRemovedEvent* event); 105*5a1d355fSStephan Aßmus void _QueryEntryMoved(EntryMovedEvent* event); 106*5a1d355fSStephan Aßmus 107*5a1d355fSStephan Aßmus bool _IsRecentEvent( 108*5a1d355fSStephan Aßmus NodeMonitoringEvent* event) const; 109*5a1d355fSStephan Aßmus 110*5a1d355fSStephan Aßmus status_t _GenerateEntryCreatedEvent(const entry_ref& ref, 111*5a1d355fSStephan Aßmus bigtime_t time, 112*5a1d355fSStephan Aßmus EntryCreatedEvent** event = NULL); 113*5a1d355fSStephan Aßmus status_t _GenerateEntryRemovedEvent(Entry* entry, 114*5a1d355fSStephan Aßmus bigtime_t time, 115*5a1d355fSStephan Aßmus EntryRemovedEvent** event = NULL); 116*5a1d355fSStephan Aßmus 117*5a1d355fSStephan Aßmus void _CheckVolumeRootMoved(EntryMovedEvent* event); 118*5a1d355fSStephan Aßmus 119*5a1d355fSStephan Aßmus static int32 _NodeMonitoringProcessorEntry(void* data); 120*5a1d355fSStephan Aßmus int32 _NodeMonitoringProcessor(); 121*5a1d355fSStephan Aßmus 122*5a1d355fSStephan Aßmus private: 123*5a1d355fSStephan Aßmus class QueryHandler; 124*5a1d355fSStephan Aßmus struct VolumeMap; 125*5a1d355fSStephan Aßmus struct ClientVolumeMap; 126*5a1d355fSStephan Aßmus typedef BlockingQueue<NodeMonitoringEvent> NodeMonitoringEventQueue; 127*5a1d355fSStephan Aßmus typedef DoublyLinkedList<NodeMonitoringEvent> 128*5a1d355fSStephan Aßmus NodeMonitoringEventList; 129*5a1d355fSStephan Aßmus struct EntryCreatedEventMap; 130*5a1d355fSStephan Aßmus struct EntryRemovedEventMap; 131*5a1d355fSStephan Aßmus struct EntryMovedEventMap; 132*5a1d355fSStephan Aßmus struct NodeStatChangedEventMap; 133*5a1d355fSStephan Aßmus struct NodeAttributeChangedEventMap; 134*5a1d355fSStephan Aßmus 135*5a1d355fSStephan Aßmus BLocker fLock; 136*5a1d355fSStephan Aßmus VolumeMap* fVolumes; 137*5a1d355fSStephan Aßmus Volume* fRootVolume; 138*5a1d355fSStephan Aßmus ClientVolumeMap* fClientVolumes; 139*5a1d355fSStephan Aßmus NodeMonitor* fNodeMonitor; 140*5a1d355fSStephan Aßmus thread_id fNodeMonitoringProcessor; 141*5a1d355fSStephan Aßmus NodeMonitoringEventQueue fNodeMonitoringEvents; 142*5a1d355fSStephan Aßmus NodeMonitoringEventList fRecentNodeMonitoringEvents; 143*5a1d355fSStephan Aßmus EntryCreatedEventMap* fEntryCreatedEvents; 144*5a1d355fSStephan Aßmus EntryRemovedEventMap* fEntryRemovedEvents; 145*5a1d355fSStephan Aßmus EntryMovedEventMap* fEntryMovedEvents; 146*5a1d355fSStephan Aßmus NodeStatChangedEventMap* fNodeStatChangedEvents; 147*5a1d355fSStephan Aßmus NodeAttributeChangedEventMap* fNodeAttributeChangedEvents; 148*5a1d355fSStephan Aßmus int64 fRevision; 149*5a1d355fSStephan Aßmus bool fTerminating; 150*5a1d355fSStephan Aßmus 151*5a1d355fSStephan Aßmus static VolumeManager* sManager; 152*5a1d355fSStephan Aßmus }; 153*5a1d355fSStephan Aßmus 154*5a1d355fSStephan Aßmus // VolumeManagerLocker 155*5a1d355fSStephan Aßmus struct VolumeManagerLocker : AutoLocker<VolumeManager> { VolumeManagerLockerVolumeManagerLocker156*5a1d355fSStephan Aßmus VolumeManagerLocker() 157*5a1d355fSStephan Aßmus : AutoLocker<VolumeManager>(VolumeManager::GetDefault()) 158*5a1d355fSStephan Aßmus { 159*5a1d355fSStephan Aßmus } 160*5a1d355fSStephan Aßmus }; 161*5a1d355fSStephan Aßmus 162*5a1d355fSStephan Aßmus #endif // NET_FS_VOLUME_MANAGER_H 163