Whamcloud - gitweb
- documentation update for MDS recovery
[fs/lustre-release.git] / lustre / mdc / mdc_request.c
index 4ca7ad4..2e18b6d 100644 (file)
 #define DEBUG_SUBSYSTEM S_MDC
 
 #include <linux/lustre_mds.h>
+#include <linux/lustre_lite.h>
 
 #define REQUEST_MINOR 244
 
 extern int mds_queue_req(struct ptlrpc_request *);
 
 int mdc_connect(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
-                ino_t ino, int type, int valid, struct ptlrpc_request **request)
+                struct ll_fid *rootfid, __u64 *last_committed, __u64 *last_rcvd,
+                __u32 *last_xid, struct ptlrpc_request **request)
 {
         struct ptlrpc_request *req;
         struct mds_body *body;
@@ -46,29 +48,38 @@ int mdc_connect(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
                 GOTO(out, rc = -ENOMEM);
 
         body = lustre_msg_buf(req->rq_reqmsg, 0);
-        ll_ino2fid(&body->fid1, ino, 0, type);
-        body->valid = valid;
-
         req->rq_replen = lustre_msg_size(1, &size);
 
+        mds_pack_req_body(req);
         rc = ptlrpc_queue_wait(req);
         rc = ptlrpc_check_status(req, rc);
 
         if (!rc) {
-                mds_unpack_body(req);
+                mds_unpack_rep_body(req);
                 body = lustre_msg_buf(req->rq_repmsg, 0);
-                CDEBUG(D_NET, "mode: %o\n", body->mode);
+                memcpy(rootfid, &body->fid1, sizeof(*rootfid));
+                *last_committed = req->rq_repmsg->last_committed;
+                *last_rcvd = req->rq_repmsg->last_rcvd;
+                *last_xid = body->last_xid;
+
+                CDEBUG(D_NET, "root ino=%ld, last_committed=%Lu, last_rcvd=%Lu,"
+                       " last_xid=%d\n",
+                       (unsigned long)rootfid->id,
+                       (unsigned long long)*last_committed,
+                       (unsigned long long)*last_rcvd,
+                       body->last_xid);
         }
 
         EXIT;
  out:
-        *request = req;
+        ptlrpc_free_req(req); 
         return rc;
 }
 
 
 int mdc_getattr(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
-                ino_t ino, int type, int valid, struct ptlrpc_request **request)
+                ino_t ino, int type, unsigned long valid,
+                struct ptlrpc_request **request)
 {
         struct ptlrpc_request *req;
         struct mds_body *body;
@@ -89,7 +100,7 @@ int mdc_getattr(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
         rc = ptlrpc_check_status(req, rc);
 
         if (!rc) {
-                mds_unpack_body(req);
+                mds_unpack_rep_body(req);
                 body = lustre_msg_buf(req->rq_repmsg, 0);
                 CDEBUG(D_NET, "mode: %o\n", body->mode);
         }
@@ -112,6 +123,7 @@ int mdc_open(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
         if (!req)
                 GOTO(out, rc = -ENOMEM);
 
+        req->rq_flags |= PTL_RPC_FL_RETAIN;
         body = lustre_msg_buf(req->rq_reqmsg, 0);
         ll_ino2fid(&body->fid1, ino, 0, type);
         body->flags = HTON__u32(flags);
@@ -122,7 +134,7 @@ int mdc_open(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
         rc = ptlrpc_check_status(req, rc);
 
         if (!rc) {
-                mds_unpack_body(req);
+                mds_unpack_rep_body(req);
                 body = lustre_msg_buf(req->rq_repmsg, 0);
                 *fh = body->objid;
         }
@@ -148,7 +160,7 @@ int mdc_close(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
         ll_ino2fid(&body->fid1, ino, 0, type);
         body->objid = fh;
 
-        req->rq_replen = lustre_msg_size(1, &size);
+        req->rq_replen = lustre_msg_size(0, NULL);
 
         rc = ptlrpc_queue_wait(req);
         rc = ptlrpc_check_status(req, rc);
@@ -172,7 +184,7 @@ int mdc_readpage(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
 
         niobuf.addr = (__u64) (long) addr;
 
-        CDEBUG(D_INODE, "inode: %ld\n", ino);
+        CDEBUG(D_INODE, "inode: %ld\n", (long)ino);
 
         bulk = ptlrpc_prep_bulk(conn);
         if (bulk == NULL) {
@@ -210,20 +222,19 @@ int mdc_readpage(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
                 GOTO(out, rc);
         }
 
-        mds_unpack_body(req);
+        mds_unpack_rep_body(req);
         EXIT;
 
  out:
         *request = req;
-        if (bulk != NULL)
-                OBD_FREE(bulk, sizeof(*bulk));
+        ptlrpc_free_bulk(bulk);
         return rc;
 }
 
 static int request_ioctl(struct inode *inode, struct file *file,
                          unsigned int cmd, unsigned long arg)
 {
-        int err;
+        int err = 0;
         struct ptlrpc_client cl;
         struct ptlrpc_connection *conn;
         struct ptlrpc_request *request;
@@ -241,9 +252,10 @@ static int request_ioctl(struct inode *inode, struct file *file,
                 RETURN(-EINVAL);
         }
 
-        ptlrpc_init_client(NULL, MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL, &cl);
+        ptlrpc_init_client(NULL, NULL, 
+                           MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL, &cl);
         conn = ptlrpc_uuid_to_connection("mds");
-        if (err) {
+        if (!conn) {
                 CERROR("cannot create client\n");
                 RETURN(-EINVAL);
         }
@@ -262,7 +274,7 @@ static int request_ioctl(struct inode *inode, struct file *file,
                 OBD_ALLOC(buf, PAGE_SIZE);
                 if (!buf) {
                         err = -ENOMEM;
-                        break;
+                        GOTO(out, err);
                 }
                 CERROR("-- readpage 0 for ino %lu\n", arg);
                 err = mdc_readpage(&cl, conn, arg, S_IFDIR, 0, buf, &request);
@@ -310,11 +322,12 @@ static int request_ioctl(struct inode *inode, struct file *file,
         case IOC_REQUEST_OPEN: {
                 __u64 fh, ino;
                 copy_from_user(&ino, (__u64 *)arg, sizeof(ino));
-                CERROR("-- opening ino %llu\n", ino);
+                CERROR("-- opening ino %llu\n", (unsigned long long)ino);
                 err = mdc_open(&cl, conn, ino, S_IFDIR, O_RDONLY, &fh,
                                &request);
                 copy_to_user((__u64 *)arg, &fh, sizeof(fh));
-                CERROR("-- done err %d (fh=%Lu)\n", err, fh);
+                CERROR("-- done err %d (fh=%Lu)\n", err,
+                       (unsigned long long)fh);
 
                 GOTO(out, err);
         }
@@ -328,12 +341,13 @@ static int request_ioctl(struct inode *inode, struct file *file,
         }
 
         default:
-                RETURN(-EINVAL);
+                GOTO(out, err = -EINVAL);
         }
 
  out:
         ptlrpc_free_req(request);
         ptlrpc_put_connection(conn);
+        ptlrpc_cleanup_client(&cl);
 
         RETURN(err);
 }
@@ -364,11 +378,12 @@ MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
 MODULE_DESCRIPTION("Lustre MDS Request Tester v1.0");
 MODULE_LICENSE("GPL");
 
+EXPORT_SYMBOL(mdc_connect);
+EXPORT_SYMBOL(mdc_getattr);
 EXPORT_SYMBOL(mdc_create);
 EXPORT_SYMBOL(mdc_unlink);
 EXPORT_SYMBOL(mdc_rename);
 EXPORT_SYMBOL(mdc_link);
-EXPORT_SYMBOL(mdc_getattr);
 EXPORT_SYMBOL(mdc_readpage);
 EXPORT_SYMBOL(mdc_setattr);
 EXPORT_SYMBOL(mdc_close);