{
struct pollfd pfd;
- for (;;) {
- if (cb_data->is_finished) {
- break;
- }
+ while (!cb_data->is_finished) {
+
pfd.fd = rpc_get_fd(rpc);
pfd.events = rpc_which_events(rpc);
-
if (poll(&pfd, 1, -1) < 0) {
rpc_set_error(rpc, "Poll failed");
cb_data->status = -EIO;
cb_data->status = -EIO;
break;
}
+ if (rpc_get_fd(rpc) == -1) {
+ rpc_set_error(rpc, "Socket closed\n");
+ break;
+ }
+ }
+}
+
+static void wait_for_nfs_reply(struct nfs_context *nfs, struct sync_cb_data *cb_data)
+{
+ struct pollfd pfd;
+
+ while (!cb_data->is_finished) {
+
+ pfd.fd = nfs_get_fd(nfs);
+ pfd.events = nfs_which_events(nfs);
+ if (poll(&pfd, 1, -1) < 0) {
+ nfs_set_error(nfs, "Poll failed");
+ cb_data->status = -EIO;
+ break;
+ }
+ if (nfs_service(nfs, pfd.revents) < 0) {
+ nfs_set_error(nfs, "nfs_service failed");
+ cb_data->status = -EIO;
+ break;
+ }
+ if (nfs_get_fd(nfs) == -1) {
+ char *server = strdup(nfs_get_server(nfs));
+ char *export = strdup(nfs_get_export(nfs));
+
+ if (nfs_mount(nfs, server, export) != 0) {
+ nfs_set_error(nfs, "Failed to reconnect to nfs server %s", nfs_get_error(nfs));
+ free(server);
+ free(export);
+ break;
+ }
+ free(server);
+ free(export);
+ }
}
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
return -1;
}
- wait_for_reply(nfs_get_rpc_context(nfs), &cb_data);
+ wait_for_nfs_reply(nfs, &cb_data);
return cb_data.status;
}
#include "libnfs-private.h"
#include "slist.h"
+static int rpc_disconnect_requeue(struct rpc_context *rpc);
+
static void set_nonblocking(int fd)
{
unsigned v;
return 0;
}
- if (revents & POLLOUT && rpc->outqueue != NULL) {
- if (rpc_write_to_socket(rpc) != 0) {
- rpc_set_error(rpc, "write to socket failed");
- return -1;
+ if (revents & POLLIN) {
+ if (rpc_read_from_socket(rpc) != 0) {
+ rpc_disconnect_requeue(rpc);
+ return 0;
}
}
- if (revents & POLLIN) {
- if (rpc_read_from_socket(rpc) != 0) {
- rpc_disconnect(rpc, rpc_get_error(rpc));
+ if (revents & POLLOUT && rpc->outqueue != NULL) {
+ if (rpc_write_to_socket(rpc) != 0) {
+ rpc_set_error(rpc, "write to socket failed");
return -1;
}
}
return 0;
}
+/* disconnect but do not error all PDUs, just move pdus in-flight back to the outqueue */
+static int rpc_disconnect_requeue(struct rpc_context *rpc)
+{
+ struct rpc_pdu *pdu;
+
+ if (rpc->fd != -1) {
+ close(rpc->fd);
+ }
+ rpc->fd = -1;
+
+ rpc->is_connected = 0;
+
+ /* socket is closed so we will not get any replies to any commands
+ * in flight. Move them all over from the waitpdu queue back to the out queue
+ */
+ for (pdu=rpc->waitpdu; pdu; pdu=pdu->next) {
+ SLIST_REMOVE(&rpc->waitpdu, pdu);
+ SLIST_ADD(&rpc->outqueue, pdu);
+ }
+
+ return 0;
+}
+
int rpc_bind_udp(struct rpc_context *rpc, char *addr, int port)
{