Whamcloud - gitweb
- new xml format, generated by lmc
[fs/lustre-release.git] / lustre / ptlrpc / client.c
index 288d43f..983b071 100644 (file)
  *
  */
 
-#define EXPORT_SYMTAB
-
 #define DEBUG_SUBSYSTEM S_RPC
 
+#include <linux/obd_support.h>
+#include <linux/obd_class.h>
+#include <linux/lustre_lib.h>
 #include <linux/lustre_ha.h>
 
 void ptlrpc_init_client(struct recovd_obd *recovd, 
@@ -64,8 +65,10 @@ struct ptlrpc_connection *ptlrpc_uuid_to_connection(char *uuid)
         }
 
         c = ptlrpc_get_connection(&peer);
-        if (c)
+        if (c) { 
+                memcpy(c->c_remote_uuid, uuid, sizeof(c->c_remote_uuid));
                 c->c_epoch++;
+        }
 
         return c;
 }
@@ -87,65 +90,66 @@ void ptlrpc_readdress_connection(struct ptlrpc_connection *conn, char *uuid)
 
 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk(struct ptlrpc_connection *conn)
 {
-        struct ptlrpc_bulk_desc *bulk;
+        struct ptlrpc_bulk_desc *desc;
 
-        OBD_ALLOC(bulk, sizeof(*bulk));
-        if (bulk != NULL) {
-                bulk->b_connection = ptlrpc_connection_addref(conn);
-                init_waitqueue_head(&bulk->b_waitq);
-                INIT_LIST_HEAD(&bulk->b_page_list);
+        OBD_ALLOC(desc, sizeof(*desc));
+        if (desc != NULL) {
+                desc->b_connection = ptlrpc_connection_addref(conn);
+                atomic_set(&desc->b_refcount, 1);
+                init_waitqueue_head(&desc->b_waitq);
+                INIT_LIST_HEAD(&desc->b_page_list);
+                ptl_set_inv_handle(&desc->b_md_h);
+                ptl_set_inv_handle(&desc->b_me_h);
         }
 
-        return bulk;
+        return desc;
 }
 
 struct ptlrpc_bulk_page *ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc)
 {
-        struct ptlrpc_bulk_page *page;
-
-        OBD_ALLOC(page, sizeof(*page));
-        if (page != NULL) {
-                page->b_desc = desc;
-                ptl_set_inv_handle(&page->b_md_h);
-                ptl_set_inv_handle(&page->b_me_h);
-                list_add(&page->b_link, &desc->b_page_list);
+        struct ptlrpc_bulk_page *bulk;
+
+        OBD_ALLOC(bulk, sizeof(*bulk));
+        if (bulk != NULL) {
+                bulk->b_desc = desc;
+                list_add_tail(&bulk->b_link, &desc->b_page_list);
                 desc->b_page_count++;
         }
-        return page;
+        return bulk;
 }
 
-void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk)
+void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *desc)
 {
         struct list_head *tmp, *next;
         ENTRY;
-        if (bulk == NULL) {
+        if (desc == NULL) {
                 EXIT;
                 return;
         }
 
-        list_for_each_safe(tmp, next, &bulk->b_page_list) {
-                struct ptlrpc_bulk_page *page;
-                page = list_entry(tmp, struct ptlrpc_bulk_page, b_link);
-                ptlrpc_free_bulk_page(page);
+        list_for_each_safe(tmp, next, &desc->b_page_list) {
+                struct ptlrpc_bulk_page *bulk;
+                bulk = list_entry(tmp, struct ptlrpc_bulk_page, b_link);
+                ptlrpc_free_bulk_page(bulk);
         }
 
-        ptlrpc_put_connection(bulk->b_connection);
+        ptlrpc_put_connection(desc->b_connection);
 
-        OBD_FREE(bulk, sizeof(*bulk));
+        OBD_FREE(desc, sizeof(*desc));
         EXIT;
 }
 
-void ptlrpc_free_bulk_page(struct ptlrpc_bulk_page *page)
+void ptlrpc_free_bulk_page(struct ptlrpc_bulk_page *bulk)
 {
         ENTRY;
-        if (page == NULL) {
+        if (bulk == NULL) {
                 EXIT;
                 return;
         }
 
-        list_del(&page->b_link);
-        page->b_desc->b_page_count--;
-        OBD_FREE(page, sizeof(*page));
+        list_del(&bulk->b_link);
+        bulk->b_desc->b_page_count--;
+        OBD_FREE(bulk, sizeof(*bulk));
         EXIT;
 }
 
@@ -168,30 +172,52 @@ struct ptlrpc_request *ptlrpc_prep_req(struct ptlrpc_client *cl,
                              &request->rq_reqlen, &request->rq_reqmsg);
         if (rc) {
                 CERROR("cannot pack request %d\n", rc);
+                OBD_FREE(request, sizeof(*request));
                 RETURN(NULL);
         }
 
+        request->rq_level = LUSTRE_CONN_FULL;
         request->rq_type = PTL_RPC_TYPE_REQUEST;
+        request->rq_client = cl;
         request->rq_connection = ptlrpc_connection_addref(conn);
 
-        request->rq_reqmsg->conn = (__u64)(unsigned long)conn->c_remote_conn;
-        request->rq_reqmsg->token = conn->c_remote_token;
-        request->rq_reqmsg->opc = HTON__u32(opcode);
-        request->rq_reqmsg->type = HTON__u32(PTL_RPC_MSG_REQUEST);
         INIT_LIST_HEAD(&request->rq_list);
-
+        INIT_LIST_HEAD(&request->rq_multi);
         /* this will be dec()d once in req_finished, once in free_committed */
         atomic_set(&request->rq_refcount, 2);
 
         spin_lock(&conn->c_lock);
-        request->rq_reqmsg->xid = HTON__u32(++conn->c_xid_out);
-        request->rq_xid = conn->c_xid_out;
+        request->rq_xid = HTON__u32(++conn->c_xid_out);
         spin_unlock(&conn->c_lock);
 
-        request->rq_client = cl;
+        request->rq_reqmsg->magic = PTLRPC_MSG_MAGIC; 
+        request->rq_reqmsg->version = PTLRPC_MSG_VERSION;
+        request->rq_reqmsg->opc = HTON__u32(opcode);
+        request->rq_reqmsg->type = HTON__u32(PTL_RPC_MSG_REQUEST);
 
         RETURN(request);
 }
+struct ptlrpc_request *ptlrpc_prep_req2(struct lustre_handle *conn, 
+                                       int opcode, int count, int *lengths,
+                                       char **bufs)
+{
+        struct client_obd *clobd; 
+        struct ptlrpc_request *req;
+        struct obd_export *export;
+
+        export = class_conn2export(conn);
+        if (!export) { 
+                LBUG();
+                CERROR("NOT connected\n"); 
+                return NULL;
+        }
+
+        clobd = &export->exp_obd->u.cli;
+        req = ptlrpc_prep_req(clobd->cl_client, clobd->cl_conn, 
+                              opcode, count, lengths, bufs);
+        ptlrpc_hdl2req(req, &clobd->cl_exporth);
+        return req;
+}
 
 void ptlrpc_req_finished(struct ptlrpc_request *request)
 {
@@ -210,8 +236,11 @@ void ptlrpc_req_finished(struct ptlrpc_request *request)
 
 void ptlrpc_free_req(struct ptlrpc_request *request)
 {
-        if (request == NULL)
+        ENTRY;
+        if (request == NULL) {
+                EXIT;
                 return;
+        }
 
         if (request->rq_repmsg != NULL)
                 OBD_FREE(request->rq_repmsg, request->rq_replen);
@@ -225,8 +254,9 @@ void ptlrpc_free_req(struct ptlrpc_request *request)
         }
 
         ptlrpc_put_connection(request->rq_connection);
-
+        list_del(&request->rq_multi);
         OBD_FREE(request, sizeof(*request));
+        EXIT;
 }
 
 static int ptlrpc_check_reply(struct ptlrpc_request *req)
@@ -240,6 +270,11 @@ static int ptlrpc_check_reply(struct ptlrpc_request *req)
         }
 
         if (req->rq_flags & PTL_RPC_FL_RESEND) { 
+                if (l_killable_pending(current)) {
+                        CERROR("-- INTR --\n");
+                        req->rq_flags |= PTL_RPC_FL_INTR;
+                        GOTO(out, rc = 1);
+                }
                 CERROR("-- RESEND --\n");
                 GOTO(out, rc = 1);
         }
@@ -249,35 +284,34 @@ static int ptlrpc_check_reply(struct ptlrpc_request *req)
                 GOTO(out, rc = 1);
         }
 
+        if (req->rq_flags & PTL_RPC_FL_TIMEOUT && l_killable_pending(current)) {
+                req->rq_flags |= PTL_RPC_FL_INTR;
+                GOTO(out, rc = 1);
+        }
 
-        if (CURRENT_TIME - req->rq_time >= req->rq_timeout) {
-                CERROR("-- REQ TIMEOUT --\n");
+        if (req->rq_timeout &&
+            (CURRENT_TIME - req->rq_time >= req->rq_timeout)) {
+                CERROR("-- REQ TIMEOUT ON CONNID %d XID %Ld --\n",
+                       req->rq_connid, (unsigned long long)req->rq_xid);
                 /* clear the timeout */
                 req->rq_timeout = 0;
                 req->rq_connection->c_level = LUSTRE_CONN_RECOVD;
                 req->rq_flags |= PTL_RPC_FL_TIMEOUT;
                 if (req->rq_client && req->rq_client->cli_recovd)
                         recovd_cli_fail(req->rq_client);
-                if (req->rq_level < LUSTRE_CONN_FULL)
-                        rc = -ETIMEDOUT;
-                else 
+                if (req->rq_level < LUSTRE_CONN_FULL) {
+                        rc = 1;
+                } else if (l_killable_pending(current)) {
+                        req->rq_flags |= PTL_RPC_FL_INTR;
+                        rc = 1;
+                } else {
                         rc = 0;
-
+                }
                 GOTO(out, rc);
         }
 
-        if (req->rq_timeout) { 
-                schedule_timeout(req->rq_timeout * HZ);
-        }
-
-        if (sigismember(&(current->pending.signal), SIGKILL) ||
-            sigismember(&(current->pending.signal), SIGTERM) ||
-            sigismember(&(current->pending.signal), SIGINT)) {
-                req->rq_flags |= PTL_RPC_FL_INTR;
-                GOTO(out, rc = 1);
-        }
-
  out:
+        CDEBUG(D_NET, "req = %p, rc = %d\n", req, rc);
         return rc;
 }
 
@@ -306,8 +340,12 @@ int ptlrpc_check_status(struct ptlrpc_request *req, int err)
         }
 
         if (req->rq_repmsg->status != 0) {
-                CERROR("req->rq_repmsg->status is %d\n",
-                       req->rq_repmsg->status);
+                if (req->rq_repmsg->status < 0)
+                        CERROR("req->rq_repmsg->status is %d\n",
+                               req->rq_repmsg->status);
+                else
+                        CDEBUG(D_INFO, "req->rq_repmsg->status is %d\n",
+                               req->rq_repmsg->status);
                 /* XXX: translate this error from net to host */
                 RETURN(req->rq_repmsg->status);
         }
@@ -348,11 +386,10 @@ void ptlrpc_free_committed(struct ptlrpc_client *cli)
                                req->rq_xid);
                         continue;
                 }
-                        
-                /* not yet committed */ 
-                if (!req->rq_transno ||
-                    req->rq_transno > cli->cli_last_committed)
-                        break; 
+
+                /* not yet committed */
+                if (req->rq_transno > cli->cli_last_committed)
+                        break;
 
                 CDEBUG(D_INFO, "Marking request %Ld as committed ("
                        "transno=%Lu, last_committed=%Lu\n", 
@@ -405,7 +442,7 @@ void ptlrpc_continue_req(struct ptlrpc_request *req)
         ENTRY;
         CDEBUG(D_INODE, "continue delayed request %Ld opc %d\n", 
                req->rq_xid, req->rq_reqmsg->opc); 
-        wake_up_interruptible(&req->rq_wait_for_rep); 
+        wake_up(&req->rq_wait_for_rep); 
         EXIT;
 }
 
@@ -418,7 +455,7 @@ void ptlrpc_resend_req(struct ptlrpc_request *req)
         req->rq_level = LUSTRE_CONN_RECOVD;
         req->rq_flags |= PTL_RPC_FL_RESEND;
         req->rq_flags &= ~PTL_RPC_FL_TIMEOUT;
-        wake_up_interruptible(&req->rq_wait_for_rep);
+        wake_up(&req->rq_wait_for_rep);
         EXIT;
 }
 
@@ -430,29 +467,30 @@ void ptlrpc_restart_req(struct ptlrpc_request *req)
         req->rq_status = -ERESTARTSYS;
         req->rq_flags |= PTL_RPC_FL_RECOVERY;
         req->rq_flags &= ~PTL_RPC_FL_TIMEOUT;
-        wake_up_interruptible(&req->rq_wait_for_rep);
+        wake_up(&req->rq_wait_for_rep);
         EXIT;
 }
 
 int ptlrpc_queue_wait(struct ptlrpc_request *req)
 {
-        int rc = 0;
+        int rc = 0, timeout;
         struct ptlrpc_client *cli = req->rq_client;
         ENTRY;
 
         init_waitqueue_head(&req->rq_wait_for_rep);
-        CERROR("subsys: %s req %Ld opc %d level %d, conn level %d\n", 
+        CDEBUG(D_NET, "subsys: %s req %Ld opc %d level %d, conn level %d\n",
                cli->cli_name, req->rq_xid, req->rq_reqmsg->opc, req->rq_level,
                req->rq_connection->c_level);
 
         /* XXX probably both an import and connection level are needed */
         if (req->rq_level > req->rq_connection->c_level) { 
-                CERROR("process %d waiting for recovery\n", current->pid);
+                CERROR("process %d waiting for recovery (%d > %d)\n", 
+                       current->pid, req->rq_level, req->rq_connection->c_level);
                 spin_lock(&cli->cli_lock);
                 list_del_init(&req->rq_list);
                 list_add(&req->rq_list, cli->cli_delayed_head.prev); 
                 spin_unlock(&cli->cli_lock);
-                wait_event_interruptible
+                l_wait_event_killable
                         (req->rq_wait_for_rep, 
                          req->rq_level <= req->rq_connection->c_level);
                 spin_lock(&cli->cli_lock);
@@ -462,7 +500,7 @@ int ptlrpc_queue_wait(struct ptlrpc_request *req)
         }
  resend:
         req->rq_time = CURRENT_TIME;
-        req->rq_timeout = 30;
+        req->rq_timeout = 100;
         rc = ptl_send_rpc(req);
         if (rc) {
                 CERROR("error %d, opcode %d\n", rc, req->rq_reqmsg->opc);
@@ -475,12 +513,17 @@ int ptlrpc_queue_wait(struct ptlrpc_request *req)
 
         spin_lock(&cli->cli_lock);
         list_del_init(&req->rq_list);
-        list_add(&req->rq_list, cli->cli_sending_head.prev);
+        list_add_tail(&req->rq_list, &cli->cli_sending_head);
         spin_unlock(&cli->cli_lock);
 
         CDEBUG(D_OTHER, "-- sleeping\n");
-        wait_event_interruptible(req->rq_wait_for_rep, 
-                                 ptlrpc_check_reply(req));
+        /*
+         * req->rq_timeout gets reset in the timeout case, and
+         * l_wait_event_timeout is a macro, so save the timeout value here.
+         */
+        timeout = req->rq_timeout * HZ;
+        l_wait_event_timeout(req->rq_wait_for_rep, ptlrpc_check_reply(req),
+                             timeout);
         CDEBUG(D_OTHER, "-- done\n");
 
         if (req->rq_flags & PTL_RPC_FL_RESEND) {
@@ -495,16 +538,18 @@ int ptlrpc_queue_wait(struct ptlrpc_request *req)
                 GOTO(out, rc = -EINTR);
         }
 
-        if (! (req->rq_flags & PTL_RPC_FL_REPLIED)) {
+        if (req->rq_flags & PTL_RPC_FL_TIMEOUT)
+                GOTO(out, rc = -ETIMEDOUT);
+
+        if (!(req->rq_flags & PTL_RPC_FL_REPLIED))
                 GOTO(out, rc = req->rq_status);
-        }
 
         rc = lustre_unpack_msg(req->rq_repmsg, req->rq_replen);
         if (rc) {
                 CERROR("unpack_rep failed: %d\n", rc);
                 GOTO(out, rc);
         }
-        CDEBUG(D_NET, "got rep %d\n", req->rq_repmsg->xid);
+        CDEBUG(D_NET, "got rep %Ld\n", req->rq_xid);
         if (req->rq_repmsg->status == 0)
                 CDEBUG(D_NET, "--> buf %p len %d status %d\n", req->rq_repmsg,
                        req->rq_replen, req->rq_repmsg->status);
@@ -527,12 +572,12 @@ int ptlrpc_replay_req(struct ptlrpc_request *req)
         ENTRY;
 
         init_waitqueue_head(&req->rq_wait_for_rep);
-        CERROR("req %Ld opc %d level %d, conn level %d\n", 
+        CDEBUG(D_NET, "req %Ld opc %d level %d, conn level %d\n",
                req->rq_xid, req->rq_reqmsg->opc, req->rq_level,
                req->rq_connection->c_level);
 
         req->rq_time = CURRENT_TIME;
-        req->rq_timeout = 3;
+        req->rq_timeout = 100;
         rc = ptl_send_rpc(req);
         if (rc) {
                 CERROR("error %d, opcode %d\n", rc, req->rq_reqmsg->opc);
@@ -542,8 +587,7 @@ int ptlrpc_replay_req(struct ptlrpc_request *req)
         }
 
         CDEBUG(D_OTHER, "-- sleeping\n");
-        wait_event_interruptible(req->rq_wait_for_rep, 
-                                 ptlrpc_check_reply(req));
+        l_wait_event_killable(req->rq_wait_for_rep, ptlrpc_check_reply(req));
         CDEBUG(D_OTHER, "-- done\n");
 
         up(&cli->cli_rpc_sem);
@@ -561,7 +605,7 @@ int ptlrpc_replay_req(struct ptlrpc_request *req)
                 GOTO(out, rc);
         }
 
-        CDEBUG(D_NET, "got rep %d\n", req->rq_repmsg->xid);
+        CDEBUG(D_NET, "got rep %Ld\n", req->rq_xid);
         if (req->rq_repmsg->status == 0)
                 CDEBUG(D_NET, "--> buf %p len %d status %d\n", req->rq_repmsg,
                        req->rq_replen, req->rq_repmsg->status);