20 #ifndef MPD_NFS_CONNECTION_HXX
21 #define MPD_NFS_CONNECTION_HXX
30 #include <forward_list>
58 struct nfsfh *close_fh;
61 explicit CancellableCallback(
NfsCallback &_callback,
65 connection(_connection),
66 open(_open), close_fh(
nullptr) {}
68 void Stat(nfs_context *context,
const char *path);
70 void Open(nfs_context *context,
const char *path,
int flags);
71 void Stat(nfs_context *context,
struct nfsfh *fh);
72 void Read(nfs_context *context,
struct nfsfh *fh,
73 uint64_t offset,
size_t size);
79 void CancelAndScheduleClose(
struct nfsfh *fh);
86 void PrepareDestroyContext();
89 static void Callback(
int err,
struct nfs_context *nfs,
90 void *data,
void *private_data);
91 void Callback(
int err,
void *data);
94 std::string server, export_name;
98 typedef std::list<NfsLease *> LeaseList;
99 LeaseList new_leases, active_leases;
102 CallbackList callbacks;
111 std::forward_list<struct nfsfh *> deferred_close;
113 std::exception_ptr postponed_mount_error;
138 const char *_server,
const char *_export_name) noexcept
141 server(_server), export_name(_export_name),
151 return server.c_str();
156 return export_name.c_str();
189 void Read(
struct nfsfh *fh, uint64_t offset,
size_t size,
194 void Close(
struct nfsfh *fh);
201 void DestroyContext();
206 void InternalClose(
struct nfsfh *fh);
211 void DeferClose(
struct nfsfh *fh);
213 void MountInternal();
214 void BroadcastMountSuccess();
215 void BroadcastMountError(std::exception_ptr &&
e);
216 void BroadcastError(std::exception_ptr &&
e);
218 static void MountCallback(
int status, nfs_context *nfs,
void *data,
220 void MountCallback(
int status, nfs_context *nfs,
void *data);
222 void ScheduleSocket();
227 int Service(
unsigned flags);
230 virtual bool OnSocketReady(
unsigned flags)
override;
233 void OnTimeout() final;
236 virtual
void RunDeferred() override;
gcc_pure const char * GetExportName() const noexcept
gcc_pure const char * GetServer() const noexcept
EventLoop & GetEventLoop() noexcept
void CloseDirectory(struct nfsdir *dir)
SocketMonitor(EventLoop &_loop)
This class monitors a timeout.
void OpenDirectory(const char *path, NfsCallback &callback)
~NfsConnection()
Must be run from EventLoop's thread.
const struct nfsdirent * ReadDirectory(struct nfsdir *dir)
An event loop that polls for events on file/socket descriptors.
Defer execution of an event into an EventLoop.
void RemoveLease(NfsLease &lease)
gcc_nonnull_all NfsConnection(EventLoop &_loop, const char *_server, const char *_export_name) noexcept
void Open(const char *path, int flags, NfsCallback &callback)
Throws std::runtime_error on error.
Monitor events on a socket.
An asynchronous connection to a NFS server.
EventLoop & GetEventLoop()
DeferredMonitor(EventLoop &_loop)
Callbacks for an asynchronous libnfs operation.
void Read(struct nfsfh *fh, uint64_t offset, size_t size, NfsCallback &callback)
Throws std::runtime_error on error.
TimeoutMonitor(EventLoop &_loop)
void CancelAndClose(struct nfsfh *fh, NfsCallback &callback)
void Stat(const char *path, NfsCallback &callback)
void AddLease(NfsLease &lease)
Ensure that the connection is established.
virtual void OnNfsConnectionError(std::exception_ptr &&e)=0