lib/nfs/Connection: use class NfsClientError
This commit is contained in:
@@ -23,7 +23,6 @@
|
|||||||
#include "Callback.hxx"
|
#include "Callback.hxx"
|
||||||
#include "event/Loop.hxx"
|
#include "event/Loop.hxx"
|
||||||
#include "net/SocketDescriptor.hxx"
|
#include "net/SocketDescriptor.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <nfsc/libnfs.h>
|
#include <nfsc/libnfs.h>
|
||||||
@@ -48,8 +47,7 @@ NfsConnection::CancellableCallback::Stat(nfs_context *ctx,
|
|||||||
|
|
||||||
int result = nfs_stat64_async(ctx, path, Callback, this);
|
int result = nfs_stat64_async(ctx, path, Callback, this);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
throw FormatRuntimeError("nfs_stat64_async() failed: %s",
|
throw NfsClientError(ctx, "nfs_stat64_async() failed");
|
||||||
nfs_get_error(ctx));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
@@ -60,8 +58,7 @@ NfsConnection::CancellableCallback::Lstat(nfs_context *ctx,
|
|||||||
|
|
||||||
int result = nfs_lstat64_async(ctx, path, Callback, this);
|
int result = nfs_lstat64_async(ctx, path, Callback, this);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
throw FormatRuntimeError("nfs_lstat64_async() failed: %s",
|
throw NfsClientError(ctx, "nfs_lstat64_async() failed");
|
||||||
nfs_get_error(ctx));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
@@ -72,8 +69,7 @@ NfsConnection::CancellableCallback::OpenDirectory(nfs_context *ctx,
|
|||||||
|
|
||||||
int result = nfs_opendir_async(ctx, path, Callback, this);
|
int result = nfs_opendir_async(ctx, path, Callback, this);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
throw FormatRuntimeError("nfs_opendir_async() failed: %s",
|
throw NfsClientError(ctx, "nfs_opendir_async() failed");
|
||||||
nfs_get_error(ctx));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
@@ -85,8 +81,7 @@ NfsConnection::CancellableCallback::Open(nfs_context *ctx,
|
|||||||
int result = nfs_open_async(ctx, path, flags,
|
int result = nfs_open_async(ctx, path, flags,
|
||||||
Callback, this);
|
Callback, this);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
throw FormatRuntimeError("nfs_open_async() failed: %s",
|
throw NfsClientError(ctx, "nfs_open_async() failed");
|
||||||
nfs_get_error(ctx));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
@@ -97,8 +92,7 @@ NfsConnection::CancellableCallback::Stat(nfs_context *ctx,
|
|||||||
|
|
||||||
int result = nfs_fstat_async(ctx, fh, Callback, this);
|
int result = nfs_fstat_async(ctx, fh, Callback, this);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
throw FormatRuntimeError("nfs_fstat_async() failed: %s",
|
throw NfsClientError(ctx, "nfs_fstat_async() failed");
|
||||||
nfs_get_error(ctx));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
@@ -109,8 +103,7 @@ NfsConnection::CancellableCallback::Read(nfs_context *ctx, struct nfsfh *fh,
|
|||||||
|
|
||||||
int result = nfs_pread_async(ctx, fh, offset, size, Callback, this);
|
int result = nfs_pread_async(ctx, fh, offset, size, Callback, this);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
throw FormatRuntimeError("nfs_pread_async() failed: %s",
|
throw NfsClientError(ctx, "nfs_pread_async() failed");
|
||||||
nfs_get_error(ctx));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
@@ -150,7 +143,7 @@ NfsConnection::CancellableCallback::Callback(int err, void *data) noexcept
|
|||||||
|
|
||||||
if (err >= 0)
|
if (err >= 0)
|
||||||
cb.OnNfsCallback((unsigned)err, data);
|
cb.OnNfsCallback((unsigned)err, data);
|
||||||
else
|
else
|
||||||
cb.OnNfsError(std::make_exception_ptr(NfsClientError(-err, (const char *)data)));
|
cb.OnNfsError(std::make_exception_ptr(NfsClientError(-err, (const char *)data)));
|
||||||
} else {
|
} else {
|
||||||
if (open) {
|
if (open) {
|
||||||
@@ -512,8 +505,7 @@ NfsConnection::OnSocketReady(unsigned flags) noexcept
|
|||||||
} else if (result < 0) {
|
} else if (result < 0) {
|
||||||
/* the connection has failed */
|
/* the connection has failed */
|
||||||
|
|
||||||
auto e = FormatRuntimeError("NFS connection has failed: %s",
|
auto e = NfsClientError(context, "NFS connection has failed");
|
||||||
nfs_get_error(context));
|
|
||||||
BroadcastError(std::make_exception_ptr(e));
|
BroadcastError(std::make_exception_ptr(e));
|
||||||
|
|
||||||
DestroyContext();
|
DestroyContext();
|
||||||
@@ -522,10 +514,7 @@ NfsConnection::OnSocketReady(unsigned flags) noexcept
|
|||||||
after the connection broke, but autoreconnect was
|
after the connection broke, but autoreconnect was
|
||||||
disabled - nfs_service() returns 0 */
|
disabled - nfs_service() returns 0 */
|
||||||
|
|
||||||
const char *msg = nfs_get_error(context);
|
auto e = NfsClientError(context, "NFS socket disappeared");
|
||||||
if (msg == nullptr)
|
|
||||||
msg = "<unknown>";
|
|
||||||
auto e = FormatRuntimeError("NFS socket disappeared: %s", msg);
|
|
||||||
|
|
||||||
BroadcastError(std::make_exception_ptr(e));
|
BroadcastError(std::make_exception_ptr(e));
|
||||||
|
|
||||||
@@ -556,8 +545,7 @@ NfsConnection::MountCallback(int status, [[maybe_unused]] nfs_context *nfs,
|
|||||||
mount_timeout_event.Cancel();
|
mount_timeout_event.Cancel();
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
auto e = FormatRuntimeError("nfs_mount_async() failed: %s",
|
auto e = NfsClientError(context, "nfs_mount_async() failed");
|
||||||
nfs_get_error(context));
|
|
||||||
postponed_mount_error = std::make_exception_ptr(e);
|
postponed_mount_error = std::make_exception_ptr(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -595,8 +583,7 @@ NfsConnection::MountInternal()
|
|||||||
|
|
||||||
if (nfs_mount_async(context, server.c_str(), export_name.c_str(),
|
if (nfs_mount_async(context, server.c_str(), export_name.c_str(),
|
||||||
MountCallback, this) != 0) {
|
MountCallback, this) != 0) {
|
||||||
auto e = FormatRuntimeError("nfs_mount_async() failed: %s",
|
auto e = NfsClientError(context, "nfs_mount_async() failed");
|
||||||
nfs_get_error(context));
|
|
||||||
nfs_destroy_context(context);
|
nfs_destroy_context(context);
|
||||||
context = nullptr;
|
context = nullptr;
|
||||||
throw e;
|
throw e;
|
||||||
|
Reference in New Issue
Block a user