From 96ec9477e8e47300815282710bfbe4b175574a47 Mon Sep 17 00:00:00 2001
From: braam <braam>
Date: Fri, 18 Jan 2002 06:01:30 +0000
Subject: [PATCH] Fix small typos in ost/osc

---
 lustre/include/linux/obdo.h |   8 +--
 lustre/lib/obd_pack.c       |   1 +
 lustre/mds/Makefile.am      |   2 +
 lustre/obdfs/Makefile.am    |   2 +
 lustre/osc/osc_request.c    | 124 ++++++++++++++++++++++++++++++------
 lustre/ost/ost_handler.c    |  35 ++++++----
 lustre/tests/ostreq.sh      |  14 ++--
 lustre/utils/parser.h       |   2 +-
 8 files changed, 149 insertions(+), 39 deletions(-)

diff --git a/lustre/include/linux/obdo.h b/lustre/include/linux/obdo.h
index c4103548af..a111fd53e7 100644
--- a/lustre/include/linux/obdo.h
+++ b/lustre/include/linux/obdo.h
@@ -89,15 +89,15 @@ static void inline obdfs_to_inode(struct inode *inode, struct obdo *oa)
 #ifdef OPS
 #warning "*** WARNING redefining OPS"
 #else
-#define OPS(sb,op) ((struct obdfs_sb_info *)(& ## sb ## ->u.generic_sbp))->osi_ops->o_ ## op
-#define IOPS(inode,op) ((struct obdfs_sb_info *)(& ## inode->i_sb ## ->u.generic_sbp))->osi_ops->o_ ## op
+#define OPS(sb,op) ((struct obdfs_sb_info *)(& (sb)->u.generic_sbp))->osi_ops->o_ ## op
+#define IOPS(inode,op) ((struct obdfs_sb_info *)(&(inode)->i_sb->u.generic_sbp))->osi_ops->o_ ## op
 #endif
 
 #ifdef ID
 #warning "*** WARNING redefining ID"
 #else
-#define ID(sb) (&((struct obdfs_sb_info *)( & ## sb ## ->u.generic_sbp))->osi_conn)
-#define IID(inode) (&((struct obdfs_sb_info *)( & ## inode->i_sb ## ->u.generic_sbp))->osi_conn)
+#define ID(sb) (&((struct obdfs_sb_info *)( &(sb)->u.generic_sbp))->osi_conn)
+#define IID(inode) (&((struct obdfs_sb_info *)( &(inode)->i_sb->u.generic_sbp))->osi_conn)
 #endif
 
 #define OBDFS_SUPER_MAGIC 0x4711
diff --git a/lustre/lib/obd_pack.c b/lustre/lib/obd_pack.c
index 482826aa57..b0044dabba 100644
--- a/lustre/lib/obd_pack.c
+++ b/lustre/lib/obd_pack.c
@@ -205,3 +205,4 @@ int ost_unpack_rep(char *buf, int len,
 	EXIT;
 	return 0;
 }
+
diff --git a/lustre/mds/Makefile.am b/lustre/mds/Makefile.am
index 4f1864d900..c81056b207 100644
--- a/lustre/mds/Makefile.am
+++ b/lustre/mds/Makefile.am
@@ -3,6 +3,8 @@
 # This code is issued under the GNU General Public License.
 # See the file COPYING in this distribution
 
+DEFS= 
+
 MODULE = mds
 modulefs_DATA = mds.o
 EXTRA_PROGRAMS = mds
diff --git a/lustre/obdfs/Makefile.am b/lustre/obdfs/Makefile.am
index b154c511b3..8470dc1875 100644
--- a/lustre/obdfs/Makefile.am
+++ b/lustre/obdfs/Makefile.am
@@ -3,6 +3,8 @@
 # This code is issued under the GNU General Public License.
 # See the file COPYING in this distribution
 
+DEFS=
+
 MODULE = obdfs
 modulefs_DATA = obdfs.o
 EXTRA_PROGRAMS = obdfs
diff --git a/lustre/osc/osc_request.c b/lustre/osc/osc_request.c
index 94556fb686..e8721f0ae1 100644
--- a/lustre/osc/osc_request.c
+++ b/lustre/osc/osc_request.c
@@ -30,21 +30,18 @@
 #include <linux/lustre_lib.h>
 #include <linux/lustre_idl.h>
 
-extern int ost_queue_req(struct obd_device *obddev, struct ost_request *);
+extern int ost_queue_req(struct obd_device *, struct ost_request *);
 
-
-
-int osc_getattr(struct obd_conn *conn, struct obdo *oa)
+struct ost_request *osc_prep_req(int size, int opcode)
 {
-	struct obd_device *obddev = conn->oc_dev;
 	struct ost_request *request;
-	int rc; 
+	int rc;
+	ENTRY; 
 
-	request = (struct ost_request *)kmalloc(sizeof(*request), 
-						GFP_KERNEL); 
+	request = (struct ost_request *)kmalloc(sizeof(*request), GFP_KERNEL); 
 	if (!request) { 
 		printk("osc_getattr: request allocation out of memory\n");
-		return -ENOMEM;
+		return NULL;
 	}
 
 	rc = ost_pack_req(NULL, 0, NULL, 0, 
@@ -52,25 +49,112 @@ int osc_getattr(struct obd_conn *conn, struct obdo *oa)
 			  &request->rq_reqlen, &request->rq_reqbuf);
 	if (rc) { 
 		printk("llight request: cannot pack request %d\n", rc); 
-		return rc;
+		return NULL;
+	}
+	request->rq_reqhdr->opc = opcode;
+
+	EXIT;
+	return request;
+}
+
+extern int osc_queue_wait(struct obd_conn *conn, struct ost_request *req)
+{
+	struct obd_device *client = conn->oc_dev;
+	struct obd_device *target = client->u.osc.osc_tgt;
+	int rc;
+
+	ENTRY;
+	/* set the connection id */
+	req->rq_req->connid = conn->oc_id;
+
+	CDEBUG(D_INODE, "tgt at %p, conn id %d, opcode %d request at: %p\n", 
+	       &conn->oc_dev->u.osc.osc_tgt->u.ost, 
+	       conn->oc_id, req->rq_reqhdr->opc, req);
+
+	/* XXX fix the race here (wait_for_event?)*/
+	/* hand the packet over to the server */
+	rc =  ost_queue_req(target, req); 
+	if (rc) { 
+		printk("osc_queue_wait: error %d, opcode %d\n", rc, 
+		       req->rq_reqhdr->opc); 
+		return -rc;
+	}
+
+	/* wait for the reply */
+	init_waitqueue_head(&req->rq_wait_for_rep);
+	interruptible_sleep_on(&req->rq_wait_for_rep);
+
+	ost_unpack_rep(req->rq_repbuf, req->rq_replen, &req->rq_rephdr, 
+		       &req->rq_rep); 
+	printk("-->osc_queue_wait: buf %p len %d status %d\n", 
+	       req->rq_repbuf, req->rq_replen, req->rq_rephdr->status); 
+
+	EXIT;
+	return req->rq_rephdr->status;
+}
+
+void osc_free_req(struct ost_request *request)
+{
+	if (request->rq_repbuf)
+		kfree(request->rq_repbuf);
+	kfree(request);
+}
+
+
+int osc_connect(struct obd_conn *conn)
+{
+	struct ost_request *request;
+	int rc; 
+	ENTRY;
+	
+	request = osc_prep_req(sizeof(*request), OST_CONNECT);
+	if (!request) { 
+		printk("osc_connect: cannot pack req!\n"); 
+		return -ENOMEM;
+	}
+
+	rc = osc_queue_wait(conn, request);
+	if (rc) { 
+		EXIT;
+		goto out;
+	}
+      
+	CDEBUG(D_INODE, "received connid %d\n", request->rq_rep->connid); 
+
+	conn->oc_id = request->rq_rep->connid;
+ out:
+	osc_free_req(request);
+	EXIT;
+	return rc;
+}
+
+int osc_getattr(struct obd_conn *conn, struct obdo *oa)
+{
+	struct ost_request *request;
+	int rc; 
+
+	request = osc_prep_req(sizeof(*request), OST_GETATTR);
+	if (!request) { 
+		printk("osc_connect: cannot pack req!\n"); 
+		return -ENOMEM;
 	}
 	
 	memcpy(&request->rq_req->oa, oa, sizeof(*oa));
-	request->rq_reqhdr->opc = OST_GETATTR;
+	request->rq_req->oa.o_valid = ~0;
 	
-	printk("osc_getattr ost tgt at %p\n", &obddev->u.osc.osc_tgt->u.ost);
-	rc = ost_queue_req(obddev->u.osc.osc_tgt, request);
+	rc = osc_queue_wait(conn, request);
 	if (rc) { 
-		printk("ost_gettatr: error in handling %d\n", rc); 
-		return rc;
+		EXIT;
+		goto out;
 	}
 
-	printk("mode: %o\n", request->rq_rep->oa.o_mode); 
+	CDEBUG(D_INODE, "mode: %o\n", request->rq_rep->oa.o_mode); 
 	if (oa) { 
 		memcpy(oa, &request->rq_rep->oa, sizeof(*oa));
 	}
-	kfree(request->rq_repbuf);
-	kfree(request);
+
+ out:
+	osc_free_req(request);
 	return 0;
 }
 
@@ -104,6 +188,7 @@ static int osc_setup(struct obd_device *obddev, obd_count len,
         return 0;
 } 
 
+
 static int osc_cleanup(struct obd_device * obddev)
 {
         ENTRY;
@@ -122,7 +207,8 @@ static int osc_cleanup(struct obd_device * obddev)
 struct obd_ops osc_obd_ops = { 
 	o_setup:   osc_setup,
 	o_cleanup: osc_cleanup, 
-	o_getattr: osc_getattr
+	o_getattr: osc_getattr,
+	o_connect: osc_connect
 };
 
 static int __init osc_init(void)
diff --git a/lustre/ost/ost_handler.c b/lustre/ost/ost_handler.c
index 122e71c74f..6e87dd046e 100644
--- a/lustre/ost/ost_handler.c
+++ b/lustre/ost/ost_handler.c
@@ -42,7 +42,6 @@ static int ost_queue_req(struct obd_device *obddev, struct ost_request *req)
 	struct ost_request *srv_req; 
 	struct ost_obd *ost = &obddev->u.ost;
 	
-	printk("---> OST at %d %p\n", __LINE__, ost);
 	if (!ost) { 
 		EXIT;
 		return -1;
@@ -53,11 +52,17 @@ static int ost_queue_req(struct obd_device *obddev, struct ost_request *req)
 		EXIT;
 		return -ENOMEM;
 	}
-	memcpy(srv_req, req, sizeof(*req)); 
-	srv_req->rq_reply_handle = req;
+
+	printk("---> OST at %d %p, incoming req %p, srv_req %p\n", 
+	       __LINE__, ost, req, srv_req);
+
+	memset(srv_req, 0, sizeof(*req)); 
+	srv_req->rq_reqbuf = req->rq_reqbuf;
+	srv_req->rq_reqlen    = req->rq_reqlen;
 	srv_req->rq_obd = ost;
-	list_add(&srv_req->rq_list, &ost->ost_reqs); 
+	srv_req->rq_reply_handle = req;
 
+	list_add(&srv_req->rq_list, &ost->ost_reqs); 
 	wake_up(&ost->ost_waitq);
 	return 0;
 }
@@ -69,6 +74,7 @@ int ost_reply(struct obd_device *obddev, struct ost_request *req)
 	struct ost_request *clnt_req = req->rq_reply_handle;
 
 	ENTRY;
+	printk("ost_reply: req %p clnt_req at %p\n", req, clnt_req); 
 
 	/* free the request buffer */
 	kfree(req->rq_reqbuf);
@@ -77,6 +83,11 @@ int ost_reply(struct obd_device *obddev, struct ost_request *req)
 	/* move the reply to the client */ 
 	clnt_req->rq_replen = req->rq_replen;
 	clnt_req->rq_repbuf = req->rq_repbuf;
+
+	printk("---> client req %p repbuf %p len %d status %d\n", 
+	       clnt_req, clnt_req->rq_repbuf, clnt_req->rq_replen, 
+	       req->rq_rephdr->status); 
+
 	req->rq_repbuf = NULL;
 	req->rq_replen = 0;
 	
@@ -140,6 +151,7 @@ static int ost_getattr(struct ost_obd *ost, struct ost_request *req)
 	int rc;
 
 	ENTRY;
+	printk("ost getattr entered\n"); 
 	
 	conn.oc_id = req->rq_req->connid;
 	conn.oc_dev = ost->ost_tgt;
@@ -151,6 +163,7 @@ static int ost_getattr(struct ost_obd *ost, struct ost_request *req)
 		return rc;
 	}
 	req->rq_rep->oa.o_id = req->rq_req->oa.o_id;
+	req->rq_rep->oa.o_valid = req->rq_req->oa.o_valid;
 
 	req->rq_rep->result =ost->ost_tgt->obd_type->typ_ops->o_getattr
 		(&conn, &req->rq_rep->oa); 
@@ -229,8 +242,10 @@ static int ost_connect(struct ost_obd *ost, struct ost_request *req)
 	}
 
 	req->rq_rep->result =ost->ost_tgt->obd_type->typ_ops->o_connect(&conn);
-	req->rq_rep->connid = conn.oc_id;
 
+	printk("ost_connect: rep buffer %p, id %d\n", req->rq_repbuf, 
+	       conn.oc_id);
+	req->rq_rep->connid = conn.oc_id;
 	EXIT;
 	return 0;
 }
@@ -296,9 +311,9 @@ int ost_handle(struct obd_device *obddev, struct ost_request *req)
 	struct ost_req_hdr *hdr;
 
 	ENTRY;
+	printk("ost_handle: req at %p\n", req); 
 
 	hdr = (struct ost_req_hdr *)req->rq_reqbuf;
-
 	if (NTOH__u32(hdr->type) != OST_TYPE_REQ) {
 		printk("lustre_ost: wrong packet type sent %d\n",
 		       NTOH__u32(hdr->type));
@@ -318,6 +333,7 @@ int ost_handle(struct obd_device *obddev, struct ost_request *req)
 
 	case OST_CONNECT:
 		CDEBUG(D_INODE, "connect\n");
+		printk("----> connect \n"); 
 		rc = ost_connect(ost, req);
 		break;
 	case OST_DISCONNECT:
@@ -350,6 +366,7 @@ int ost_handle(struct obd_device *obddev, struct ost_request *req)
 	}
 
 out:
+	req->rq_rephdr->status = rc;
 	if (rc) { 
 		printk("ost: processing error %d\n", rc);
 		ost_error(obddev, req);
@@ -475,7 +492,7 @@ static int ost_setup(struct obd_device *obddev, obd_count len,
 	}
 
         tgt = &obd_dev[data->ioc_dev];
-	
+	ost->ost_tgt = tgt;
         if ( ! (tgt->obd_flags & OBD_ATTACHED) || 
              ! (tgt->obd_flags & OBD_SET_UP) ){
                 printk("device not attached or not set up (%d)\n", 
@@ -492,17 +509,13 @@ static int ost_setup(struct obd_device *obddev, obd_count len,
 		return -EINVAL;
 	}
 
-	printk("---> OST at %d %p\n", __LINE__, ost);
 	INIT_LIST_HEAD(&ost->ost_reqs);
 	ost->ost_thread = NULL;
 	ost->ost_flags = 0;
 
-	printk("---> %d\n", __LINE__);
 	spin_lock_init(&obddev->u.ost.fo_lock);
 
-	printk("---> %d\n", __LINE__);
 	ost_start_srv_thread(obddev);
-	printk("---> %d\n", __LINE__);
 
         MOD_INC_USE_COUNT;
         EXIT; 
diff --git a/lustre/tests/ostreq.sh b/lustre/tests/ostreq.sh
index 84d0924545..634f4436b1 100644
--- a/lustre/tests/ostreq.sh
+++ b/lustre/tests/ostreq.sh
@@ -3,15 +3,18 @@
 R=/r
 
 insmod /lib/modules/2.4.17/kernel/drivers/block/loop.o
+insmod $R/usr/src/obd/class/obdclass.o 
+insmod $R/usr/src/obd/ext2obd/obdext2.o
+insmod $R/usr/src/obd/ost/ost.o
+insmod $R/usr/src/obd/osc/osc.o
+
 dd if=/dev/zero of=/tmp/fs bs=1024 count=10000
 mke2fs -F /tmp/fs
 losetup /dev/loop/0 /tmp/fs
 
+echo 4095 > /proc/sys/obd/debug
+echo 4095 > /proc/sys/obd/trace
 
-insmod $R/usr/src/obd/class/obdclass.o 
-insmod $R/usr/src/obd/ext2obd/obdext2.o
-insmod $R/usr/src/obd/ost/ost.o
-insmod $R/usr/src/obd/osc/osc.o
 mknod /dev/obd c 10 241
 
 $R/usr/src/obd/utils/obdctl <<EOF
@@ -21,6 +24,9 @@ setup /dev/loop/0
 device 1
 attach ost
 setup 0
+device 2
+attach osc
+setup 1
 quit
 EOF
 
diff --git a/lustre/utils/parser.h b/lustre/utils/parser.h
index a35ab753bc..6bb252ff9d 100644
--- a/lustre/utils/parser.h
+++ b/lustre/utils/parser.h
@@ -52,4 +52,4 @@ char *Parser_strarg(char *inp, const char *prompt, const char *deft,
 int Parser_arg2int(const char *inp, long *result, int base);
 
 
-#endif _PARSER_H_
+#endif
-- 
GitLab