From ab4bb26a0aeac99a7ea5aa9fdd93d379bf3c054d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 14 Dec 2014 15:20:40 +0100 Subject: lib/nfs/Connection: make in_service and in_event debug-only flags --- src/lib/nfs/Connection.hxx | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/lib/nfs/Connection.hxx') diff --git a/src/lib/nfs/Connection.hxx b/src/lib/nfs/Connection.hxx index aebafd4d3..e63782931 100644 --- a/src/lib/nfs/Connection.hxx +++ b/src/lib/nfs/Connection.hxx @@ -111,6 +111,7 @@ class NfsConnection : SocketMonitor, DeferredMonitor { Error postponed_mount_error; +#ifndef NDEBUG /** * True when nfs_service() is being called. */ @@ -121,6 +122,7 @@ class NfsConnection : SocketMonitor, DeferredMonitor { * event updates are omitted. */ bool in_event; +#endif bool mount_finished; -- cgit v1.2.3 From 7fa1a84ec37ba6e891d2eb9d557cf3ddfb902023 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 14 Dec 2014 15:38:09 +0100 Subject: lib/nfs/Connection: move code to method InternalClose() --- src/lib/nfs/Connection.hxx | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/lib/nfs/Connection.hxx') diff --git a/src/lib/nfs/Connection.hxx b/src/lib/nfs/Connection.hxx index e63782931..93bb4e236 100644 --- a/src/lib/nfs/Connection.hxx +++ b/src/lib/nfs/Connection.hxx @@ -186,6 +186,11 @@ protected: private: void DestroyContext(); + /** + * Wrapper for nfs_close_async(). + */ + void InternalClose(struct nfsfh *fh); + /** * Invoke nfs_close_async() after nfs_service() returns. */ -- cgit v1.2.3 From 80f2ba7fca533de38575bdaf737ea89284ed2b7b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 14 Dec 2014 15:45:10 +0100 Subject: lib/nfs/Connection: move code to Service() --- src/lib/nfs/Connection.hxx | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/lib/nfs/Connection.hxx') diff --git a/src/lib/nfs/Connection.hxx b/src/lib/nfs/Connection.hxx index 93bb4e236..3d872eb3a 100644 --- a/src/lib/nfs/Connection.hxx +++ b/src/lib/nfs/Connection.hxx @@ -207,6 +207,11 @@ private: void ScheduleSocket(); + /** + * Wrapper for nfs_service(). + */ + int Service(unsigned flags); + /* virtual methods from SocketMonitor */ virtual bool OnSocketReady(unsigned flags) override; -- cgit v1.2.3 From a543627abd19f321ddd4259e222e6437e8312417 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 14 Dec 2014 15:56:53 +0100 Subject: lib/nfs/Connection: fix memory leak (and assertion failure) nfs_destroy_context() will invoke all pending callbacks with err==-EINTR. In CancellableCallback::Callback(), this will invoke NfsConnection::DeferClose(), which however is only designed to be called from nfs_service(). In non-debug mode, this will leak memory because nfs_close_async() is never called. Workaround: before nfs_destroy_context(), invoke nfs_close_async() on all pending file handles. --- src/lib/nfs/Connection.hxx | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/lib/nfs/Connection.hxx') diff --git a/src/lib/nfs/Connection.hxx b/src/lib/nfs/Connection.hxx index 3d872eb3a..e47ba404b 100644 --- a/src/lib/nfs/Connection.hxx +++ b/src/lib/nfs/Connection.hxx @@ -84,6 +84,13 @@ class NfsConnection : SocketMonitor, DeferredMonitor { */ void CancelAndScheduleClose(struct nfsfh *fh); + /** + * Called by NfsConnection::DestroyContext() right + * before nfs_destroy_context(). This object is given + * a chance to prepare for the latter. + */ + void PrepareDestroyContext(); + private: static void Callback(int err, struct nfs_context *nfs, void *data, void *private_data); -- cgit v1.2.3 From 7fa91ec175452823e04dba199bc48df12d3a64f0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 14 Dec 2014 15:31:49 +0100 Subject: lib/nfs/Connection: add debug flag "in_destroy" --- src/lib/nfs/Connection.hxx | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/lib/nfs/Connection.hxx') diff --git a/src/lib/nfs/Connection.hxx b/src/lib/nfs/Connection.hxx index e47ba404b..310ccdc44 100644 --- a/src/lib/nfs/Connection.hxx +++ b/src/lib/nfs/Connection.hxx @@ -129,6 +129,11 @@ class NfsConnection : SocketMonitor, DeferredMonitor { * event updates are omitted. */ bool in_event; + + /** + * True when DestroyContext() is being called. + */ + bool in_destroy; #endif bool mount_finished; -- cgit v1.2.3 From 82da364b8b9c6073e4af58cddc85357674a1a2e5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 14 Dec 2014 23:27:57 +0100 Subject: lib/nfs/Connection: implement mount timeout --- src/lib/nfs/Connection.hxx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/lib/nfs/Connection.hxx') diff --git a/src/lib/nfs/Connection.hxx b/src/lib/nfs/Connection.hxx index 310ccdc44..3969a7e8f 100644 --- a/src/lib/nfs/Connection.hxx +++ b/src/lib/nfs/Connection.hxx @@ -23,6 +23,7 @@ #include "Lease.hxx" #include "Cancellable.hxx" #include "event/SocketMonitor.hxx" +#include "event/TimeoutMonitor.hxx" #include "event/DeferredMonitor.hxx" #include "util/Error.hxx" @@ -40,7 +41,7 @@ class NfsCallback; /** * An asynchronous connection to a NFS server. */ -class NfsConnection : SocketMonitor, DeferredMonitor { +class NfsConnection : SocketMonitor, TimeoutMonitor, DeferredMonitor { class CancellableCallback : public CancellablePointer { NfsConnection &connection; @@ -142,7 +143,8 @@ public: gcc_nonnull_all NfsConnection(EventLoop &_loop, const char *_server, const char *_export_name) - :SocketMonitor(_loop), DeferredMonitor(_loop), + :SocketMonitor(_loop), TimeoutMonitor(_loop), + DeferredMonitor(_loop), server(_server), export_name(_export_name), context(nullptr) {} @@ -227,6 +229,9 @@ private: /* virtual methods from SocketMonitor */ virtual bool OnSocketReady(unsigned flags) override; + /* virtual methods from TimeoutMonitor */ + void OnTimeout() final; + /* virtual methods from DeferredMonitor */ virtual void RunDeferred() override; }; -- cgit v1.2.3