From d3ff06683af390a4c2e83b69177e0a2eb76679bc Mon Sep 17 00:00:00 2001 From: czeidler Date: Sun, 22 Jan 2012 17:51:46 +1300 Subject: [PATCH] Use new node monitor fields in the index_server. * remove unnecessary modified query hack --- src/servers/index/Jamfile | 1 - src/servers/index/ModifiedNotifications.cpp | 86 --------------------- src/servers/index/ModifiedNotifications.h | 44 ----------- src/servers/index/VolumeWatcher.cpp | 69 ++++++++++------- src/servers/index/VolumeWatcher.h | 5 +- 5 files changed, 41 insertions(+), 164 deletions(-) delete mode 100644 src/servers/index/ModifiedNotifications.cpp delete mode 100644 src/servers/index/ModifiedNotifications.h diff --git a/src/servers/index/Jamfile b/src/servers/index/Jamfile index ded7a9ac5f..bbe6811c77 100644 --- a/src/servers/index/Jamfile +++ b/src/servers/index/Jamfile @@ -10,7 +10,6 @@ Server index_server : main.cpp IndexServer.cpp IndexServerAddOn.cpp - ModifiedNotifications.cpp VolumeWatcher.cpp # storage diff --git a/src/servers/index/ModifiedNotifications.cpp b/src/servers/index/ModifiedNotifications.cpp deleted file mode 100644 index a2412092cc..0000000000 --- a/src/servers/index/ModifiedNotifications.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2010, Haiku. - * Distributed under the terms of the MIT License. - * - * Authors: - * Clemens Zeidler - */ - -#include "ModifiedNotifications.h" - -#include "fs_query.h" - -#include -#include - -#include "query_private.h" - - -NotifyAllQuery::NotifyAllQuery() - : - fQueryFd(-1) -{ - -} - - -NotifyAllQuery::~NotifyAllQuery() -{ - StopWatching(); -} - - -status_t -NotifyAllQuery::StartWatching(const BVolume& volume, const char* query, - const BMessenger& target) -{ - if (fQueryFd >= 0) - return B_NOT_ALLOWED; - - BMessenger::Private messengerPrivate(const_cast(target)); - port_id port = messengerPrivate.Port(); - long token = (messengerPrivate.IsPreferredTarget() ? -1 - : messengerPrivate.Token()); - - fQueryFd = _kern_open_query(volume.Device(), query, strlen(query), - B_LIVE_QUERY | B_ATTR_CHANGE_NOTIFICATION, port, token); - if (fQueryFd < 0) - return fQueryFd; - return B_OK; -} - - -status_t -NotifyAllQuery::StopWatching() -{ - status_t error = B_OK; - if (fQueryFd >= 0) { - error = _kern_close(fQueryFd); - fQueryFd = -1; - } - return error; -} - - -ModfiedNotifications::~ModfiedNotifications() -{ - StopWatching(); -} - - -status_t -ModfiedNotifications::StartWatching(const BVolume& volume, time_t startTime, - const BMessenger& target) -{ - BString string = "(last_modified>="; - string << startTime; - string << ")"; - return fQuery.StartWatching(volume, string.String(), target); -} - - -status_t -ModfiedNotifications::StopWatching() -{ - return fQuery.StopWatching(); -} diff --git a/src/servers/index/ModifiedNotifications.h b/src/servers/index/ModifiedNotifications.h deleted file mode 100644 index 50cd1b2f8e..0000000000 --- a/src/servers/index/ModifiedNotifications.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2010, Haiku. - * Distributed under the terms of the MIT License. - * - * Authors: - * Clemens Zeidler - */ -#ifndef MODIFIED_NOTIFICATIONS_H -#define MODIFIED_NOTIFICATIONS_H - - -#include -#include -#include - - -class NotifyAllQuery { -public: - NotifyAllQuery(); - ~NotifyAllQuery(); - - status_t StartWatching(const BVolume& volume, - const char* query, - const BMessenger& target); - status_t StopWatching(); -private: - int fQueryFd; -}; - - -class ModfiedNotifications { -public: - ~ModfiedNotifications(); - - status_t StartWatching(const BVolume& volume, - time_t startTime, const BMessenger& target); - status_t StopWatching(); - -private: - NotifyAllQuery fQuery; -}; - - -#endif // MODIFIED_NOTIFICATIONS_H diff --git a/src/servers/index/VolumeWatcher.cpp b/src/servers/index/VolumeWatcher.cpp index 4192c8285a..a945e17c8c 100644 --- a/src/servers/index/VolumeWatcher.cpp +++ b/src/servers/index/VolumeWatcher.cpp @@ -74,6 +74,44 @@ WatchNameHandler::StatChanged(ino_t node, dev_t device, int32 statFields) } +void +WatchNameHandler::MessageReceived(BMessage* msg) +{ + if (msg->what == B_NODE_MONITOR) { + int32 opcode; + if (msg->FindInt32("opcode", &opcode) == B_OK) { + switch (opcode) { + case B_STAT_CHANGED: { + BString name; + entry_ref ref; + ino_t node; + int32 statFields; + msg->FindInt32("fields", &statFields); + if ((statFields & B_STAT_MODIFICATION_TIME) == 0) + break; + msg->FindInt32("device", &ref.device); + msg->FindInt64("node", &node); + msg->FindInt64("directory", &ref.directory); + msg->FindString("name", &name); + + ref.set_name(name); + + BPath path(&ref); + printf("stat changed node %i name %s %s\n", (int)node, + name.String(), path.Path()); + + fVolumeWatcher->fModifiedList.CurrentList()->push_back(ref); + fVolumeWatcher->_NewEntriesArrived(); + + break; + } + } + } + } + NodeMonitorHandler::MessageReceived(msg); +} + + AnalyserDispatcher::AnalyserDispatcher(const char* name) : BLooper(name, B_LOW_PRIORITY), @@ -408,33 +446,6 @@ VolumeWatcher::~VolumeWatcher() } -void -VolumeWatcher::MessageReceived(BMessage *message) -{ - int32 opcode; - switch (message->what) { - case B_QUERY_UPDATE: - message->FindInt32("opcode", &opcode); - if (opcode == B_ATTR_CHANGED || opcode == B_ENTRY_CREATED) { - const char *name; - ino_t directory; - dev_t device; - if ((message->FindString("name", &name) != B_OK) || - (message->FindInt64("directory", &directory) != B_OK) || - (message->FindInt32("device", &device) != B_OK)) - break; - entry_ref ref(device, directory, name); - fModifiedList.CurrentList()->push_back(ref); - _NewEntriesArrived(); - } - break; - - default: - BLooper::MessageReceived(message); - } -} - - bool VolumeWatcher::StartWatching() { @@ -442,9 +453,7 @@ VolumeWatcher::StartWatching() watch_volume(fVolume.Device(), B_WATCH_NAME | B_WATCH_STAT, &fWatchNameHandler); - if (fModfiedNotifications.StartWatching(fVolume.Device(), real_time_clock(), - this) != B_OK) - return false; + // set the time after start watching to not miss anything fVolumeWorker->SetWatchingStart(real_time_clock_usecs()); diff --git a/src/servers/index/VolumeWatcher.h b/src/servers/index/VolumeWatcher.h index dc5e7e1fc4..7131ae3226 100644 --- a/src/servers/index/VolumeWatcher.h +++ b/src/servers/index/VolumeWatcher.h @@ -21,7 +21,6 @@ #include "AnalyserDispatcher.h" #include "CatchUpManager.h" #include "IndexServerAddOn.h" -#include "ModifiedNotifications.h" class VolumeWatcher; @@ -41,6 +40,8 @@ public: ino_t node, dev_t nodeDevice); void StatChanged(ino_t node, dev_t device, int32 statFields); + + void MessageReceived(BMessage* msg); private: VolumeWatcher* fVolumeWatcher; }; @@ -127,7 +128,6 @@ public: VolumeWatcher(const BVolume& volume); ~VolumeWatcher(); - void MessageReceived(BMessage *message); bool StartWatching(); void Stop(); @@ -157,7 +157,6 @@ private: VolumeWorker* fVolumeWorker; CatchUpManager fCatchUpManager; - ModfiedNotifications fModfiedNotifications; };