Commit a4870492 authored by Max Kellermann's avatar Max Kellermann

storage/nfs: add timeout

parent 68d1abdb
...@@ -4,6 +4,8 @@ ver 0.19.7 (not yet released) ...@@ -4,6 +4,8 @@ ver 0.19.7 (not yet released)
- nfs: fix memory leak on connection failure - nfs: fix memory leak on connection failure
- nfs: fix reconnect after mount failure - nfs: fix reconnect after mount failure
- nfs: implement mount timeout (60 seconds) - nfs: implement mount timeout (60 seconds)
* storage
- nfs: implement I/O timeout (60 seconds)
* playlist * playlist
- don't skip non-existent songs in "listplaylist" - don't skip non-existent songs in "listplaylist"
* fix memory allocator bug on Windows * fix memory allocator bug on Windows
......
...@@ -20,7 +20,9 @@ ...@@ -20,7 +20,9 @@
#include "config.h" #include "config.h"
#include "Blocking.hxx" #include "Blocking.hxx"
#include "Connection.hxx" #include "Connection.hxx"
#include "Domain.hxx"
#include "event/Call.hxx" #include "event/Call.hxx"
#include "util/Error.hxx"
bool bool
BlockingNfsOperation::Run(Error &_error) BlockingNfsOperation::Run(Error &_error)
...@@ -31,7 +33,10 @@ BlockingNfsOperation::Run(Error &_error) ...@@ -31,7 +33,10 @@ BlockingNfsOperation::Run(Error &_error)
[this](){ connection.AddLease(*this); }); [this](){ connection.AddLease(*this); });
/* wait for completion */ /* wait for completion */
LockWaitFinished(); if (!LockWaitFinished()) {
_error.Set(nfs_domain, 0, "Timeout");
return false;
}
/* check for error */ /* check for error */
if (error.IsDefined()) { if (error.IsDefined()) {
......
...@@ -35,6 +35,8 @@ class NfsConnection; ...@@ -35,6 +35,8 @@ class NfsConnection;
* thread, and method Run() waits for completion. * thread, and method Run() waits for completion.
*/ */
class BlockingNfsOperation : protected NfsCallback, NfsLease { class BlockingNfsOperation : protected NfsCallback, NfsLease {
static constexpr unsigned timeout_ms = 60000;
Mutex mutex; Mutex mutex;
Cond cond; Cond cond;
...@@ -52,10 +54,13 @@ public: ...@@ -52,10 +54,13 @@ public:
bool Run(Error &error); bool Run(Error &error);
private: private:
void LockWaitFinished() { bool LockWaitFinished() {
const ScopeLock protect(mutex); const ScopeLock protect(mutex);
while (!finished) while (!finished)
cond.wait(mutex); if (!cond.timed_wait(mutex, timeout_ms))
return false;
return true;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment