Whamcloud - gitweb
Lproc-snmp code drop
[fs/lustre-release.git] / lustre / ost / ost_handler.c
index 22a98a9..9282752 100644 (file)
 #include <linux/lustre_net.h>
 #include <linux/lustre_dlm.h>
 #include <linux/init.h>
+#include <linux/lprocfs_status.h>
+
+extern lprocfs_vars_t status_var_nm_1[];
+extern lprocfs_vars_t status_class_var[];
 
 static int ost_destroy(struct ptlrpc_request *req)
 {
@@ -70,6 +74,7 @@ static int ost_getattr(struct ptlrpc_request *req)
                 RETURN(rc);
 
         repbody = lustre_msg_buf(req->rq_repmsg, 0);
+        /* FIXME: unpack only valid fields instead of memcpy, endianness */
         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
         req->rq_status = obd_getattr(conn, &repbody->oa, NULL);
         RETURN(0);
@@ -79,24 +84,24 @@ static int ost_statfs(struct ptlrpc_request *req)
 {
         struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg;
         struct obd_statfs *osfs;
-        struct statfs sfs;
         int rc, size = sizeof(*osfs);
         ENTRY;
 
-        rc = obd_statfs(conn, &sfs);
-        if (rc) {
-                CERROR("ost: statfs failed: rc %d\n", rc);
-                req->rq_status = rc;
-                RETURN(rc);
-        }
-
         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
         if (rc)
                 RETURN(rc);
 
         osfs = lustre_msg_buf(req->rq_repmsg, 0);
         memset(osfs, 0, size);
-        obd_statfs_pack(osfs, &sfs);
+
+        rc = obd_statfs(conn, osfs);
+        if (rc) {
+                CERROR("ost: statfs failed: rc %d\n", rc);
+                req->rq_status = rc;
+                RETURN(rc);
+        }
+        obd_statfs_pack(osfs, osfs);
+
         RETURN(0);
 }
 
@@ -114,6 +119,7 @@ static int ost_open(struct ptlrpc_request *req)
                 RETURN(rc);
 
         repbody = lustre_msg_buf(req->rq_repmsg, 0);
+        /* FIXME: unpack only valid fields instead of memcpy, endianness */
         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
         req->rq_status = obd_open(conn, &repbody->oa, NULL);
         RETURN(0);
@@ -133,6 +139,7 @@ static int ost_close(struct ptlrpc_request *req)
                 RETURN(rc);
 
         repbody = lustre_msg_buf(req->rq_repmsg, 0);
+        /* FIXME: unpack only valid fields instead of memcpy, endianness */
         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
         req->rq_status = obd_close(conn, &repbody->oa, NULL);
         RETURN(0);
@@ -152,6 +159,7 @@ static int ost_create(struct ptlrpc_request *req)
                 RETURN(rc);
 
         repbody = lustre_msg_buf(req->rq_repmsg, 0);
+        /* FIXME: unpack only valid fields instead of memcpy, endianness */
         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
         req->rq_status = obd_create(conn, &repbody->oa, NULL);
         RETURN(0);
@@ -166,14 +174,19 @@ static int ost_punch(struct ptlrpc_request *req)
 
         body = lustre_msg_buf(req->rq_reqmsg, 0);
 
+        if ((NTOH__u32(body->oa.o_valid) & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))!=
+            (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
+                RETURN(-EINVAL);
+
         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
         if (rc)
                 RETURN(rc);
 
         repbody = lustre_msg_buf(req->rq_repmsg, 0);
+        /* FIXME: unpack only valid fields instead of memcpy, endianness */
         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
-        req->rq_status = obd_punch(conn, &repbody->oa, NULL, 
-                                   repbody->oa.o_blocks, repbody->oa.o_size);
+        req->rq_status = obd_punch(conn, &repbody->oa, NULL,
+                                   repbody->oa.o_size, repbody->oa.o_blocks);
         RETURN(0);
 }
 
@@ -191,6 +204,7 @@ static int ost_setattr(struct ptlrpc_request *req)
                 RETURN(rc);
 
         repbody = lustre_msg_buf(req->rq_repmsg, 0);
+        /* FIXME: unpack only valid fields instead of memcpy, endianness */
         memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
         req->rq_status = obd_setattr(conn, &repbody->oa, NULL);
         RETURN(0);
@@ -201,7 +215,7 @@ static int ost_bulk_timeout(void *data)
         struct ptlrpc_bulk_desc *desc = data;
 
         ENTRY;
-        CERROR("(not yet) starting recovery of client %p\n", desc->b_client);
+        CERROR("(not yet) starting recovery of client %p\n", desc->bd_client);
         RETURN(1);
 }
 
@@ -256,16 +270,16 @@ static int ost_brw_read(struct ptlrpc_request *req)
         desc = ptlrpc_prep_bulk(req->rq_connection);
         if (desc == NULL)
                 GOTO(out_local, rc = -ENOMEM);
-        desc->b_portal = OST_BULK_PORTAL;
+        desc->bd_portal = OST_BULK_PORTAL;
 
         for (i = 0; i < niocount; i++) {
                 struct ptlrpc_bulk_page *bulk = ptlrpc_prep_bulk_page(desc);
 
                 if (bulk == NULL)
                         GOTO(out_bulk, rc = -ENOMEM);
-                bulk->b_xid = remote_nb[i].xid;
-                bulk->b_buf = local_nb[i].addr;
-                bulk->b_buflen = remote_nb[i].len;
+                bulk->bp_xid = remote_nb[i].xid;
+                bulk->bp_buf = local_nb[i].addr;
+                bulk->bp_buflen = remote_nb[i].len;
         }
 
         rc = ptlrpc_send_bulk(desc);
@@ -273,7 +287,7 @@ static int ost_brw_read(struct ptlrpc_request *req)
                 GOTO(out_bulk, rc);
 
         lwi = LWI_TIMEOUT(obd_timeout * HZ, ost_bulk_timeout, desc);
-        rc = l_wait_event(desc->b_waitq, desc->b_flags &PTL_BULK_FL_SENT, &lwi);
+        rc = l_wait_event(desc->bd_waitq, desc->bd_flags &PTL_BULK_FL_SENT, &lwi);
         if (rc) {
                 LASSERT(rc == -ETIMEDOUT);
                 GOTO(out_bulk, rc);
@@ -289,9 +303,13 @@ out_bulk:
 out_local:
         OBD_FREE(local_nb, sizeof(*local_nb) * niocount);
 out:
-        if (rc)
+        if (rc) {
+                /* It's a lot of work to delay allocating the reply, and a lot
+                 * less work to just free it here. */
+                OBD_FREE(req->rq_repmsg, req->rq_replen);
+                req->rq_repmsg = NULL;
                 ptlrpc_error(req->rq_svc, req);
-        else
+        else
                 ptlrpc_reply(req->rq_svc, req);
         RETURN(rc);
 }
@@ -355,10 +373,10 @@ static int ost_brw_write(struct ptlrpc_request *req)
         desc = ptlrpc_prep_bulk(req->rq_connection);
         if (desc == NULL)
                 GOTO(fail_preprw, rc = -ENOMEM);
-        desc->b_cb = NULL;
-        desc->b_portal = OSC_BULK_PORTAL;
-        desc->b_desc_private = desc_priv;
-        memcpy(&(desc->b_conn), &conn, sizeof(conn));
+        desc->bd_cb = NULL;
+        desc->bd_portal = OSC_BULK_PORTAL;
+        desc->bd_desc_private = desc_priv;
+        memcpy(&(desc->bd_conn), &conn, sizeof(conn));
 
         srv = req->rq_obd->u.ost.ost_service;
         spin_lock(&srv->srv_lock);
@@ -372,18 +390,18 @@ static int ost_brw_write(struct ptlrpc_request *req)
                 if (bulk == NULL)
                         GOTO(fail_bulk, rc = -ENOMEM);
 
-                bulk->b_xid = xid;              /* single xid for all pages */
+                bulk->bp_xid = xid;              /* single xid for all pages */
 
-                bulk->b_buf = lnb->addr;
-                bulk->b_page = lnb->page;
-                bulk->b_flags = lnb->flags;
-                bulk->b_dentry = lnb->dentry;
-                bulk->b_buflen = lnb->len;
-                bulk->b_cb = NULL;
+                bulk->bp_buf = lnb->addr;
+                bulk->bp_page = lnb->page;
+                bulk->bp_flags = lnb->flags;
+                bulk->bp_dentry = lnb->dentry;
+                bulk->bp_buflen = lnb->len;
+                bulk->bp_cb = NULL;
 
                 /* this advances remote_nb */
                 ost_pack_niobuf((void **)&remote_nb, lnb->offset, lnb->len, 0,
-                                bulk->b_xid);
+                                bulk->bp_xid);
         }
 
         rc = ptlrpc_register_bulk(desc);
@@ -394,7 +412,8 @@ static int ost_brw_write(struct ptlrpc_request *req)
         ptlrpc_reply(req->rq_svc, req);
 
         lwi = LWI_TIMEOUT(obd_timeout * HZ, ost_bulk_timeout, desc);
-        rc = l_wait_event(desc->b_waitq, desc->b_flags & PTL_BULK_FL_RCVD, &lwi);
+        rc = l_wait_event(desc->bd_waitq, desc->bd_flags & PTL_BULK_FL_RCVD,
+                          &lwi);
         if (rc) {
                 if (rc != -ETIMEDOUT)
                         LBUG();
@@ -402,16 +421,18 @@ static int ost_brw_write(struct ptlrpc_request *req)
         }
 
         rc = obd_commitrw(cmd, conn, objcount, tmp1, niocount, local_nb,
-                          desc->b_desc_private);
+                          desc->bd_desc_private);
         ptlrpc_free_bulk(desc);
         EXIT;
 out_free:
         OBD_FREE(local_nb, niocount * sizeof(*local_nb));
 out:
         if (!reply_sent) {
-                if (rc)
+                if (rc) {
+                        OBD_FREE(req->rq_repmsg, req->rq_replen);
+                        req->rq_repmsg = NULL;
                         ptlrpc_error(req->rq_svc, req);
-                else
+                else
                         ptlrpc_reply(req->rq_svc, req);
         }
         return rc;
@@ -434,12 +455,6 @@ static int ost_handle(struct ptlrpc_request *req)
                 GOTO(out, rc);
         }
 
-        if (req->rq_reqmsg->type != PTL_RPC_MSG_REQUEST) {
-                CERROR("lustre_ost: wrong packet type sent %d\n",
-                       req->rq_reqmsg->type);
-                GOTO(out, rc = -EINVAL);
-        }
-
         if (req->rq_reqmsg->opc != OST_CONNECT &&
             req->rq_export == NULL) {
                 CERROR("lustre_ost: operation %d on unconnected OST\n",
@@ -596,15 +611,16 @@ static int ost_setup(struct obd_device *obddev, obd_count len, void *buf)
                 GOTO(error_dec, err = -EINVAL);
         }
 
-        err = obd_connect(&ost->ost_conn, tgt, NULL);
+        err = obd_connect(&ost->ost_conn, tgt, NULL, NULL, NULL);
         if (err) {
                 CERROR("fail to connect to device %d\n", data->ioc_dev);
                 GOTO(error_dec, err = -EINVAL);
         }
 
-        ost->ost_service = ptlrpc_init_svc(64 * 1024, OST_REQUEST_PORTAL,
-                                           OSC_REPLY_PORTAL, "self",ost_handle, 
-                                           "ost");
+        ost->ost_service = ptlrpc_init_svc(OST_NEVENTS, OST_NBUFS,
+                                           OST_BUFSIZE, OST_MAXREQSIZE,
+                                           OST_REQUEST_PORTAL, OSC_REPLY_PORTAL, 
+                                           "self", ost_handle, "ost");
         if (!ost->ost_service) {
                 CERROR("failed to start service\n");
                 GOTO(error_disc, err = -EINVAL);
@@ -620,9 +636,6 @@ static int ost_setup(struct obd_device *obddev, obd_count len, void *buf)
                 }
         }
 
-        ptlrpc_init_client(LDLM_REQUEST_PORTAL, LDLM_REPLY_PORTAL,
-                           "ost_ldlm_client", &obddev->obd_ldlm_client);
-
         RETURN(0);
 
 error_disc:
@@ -656,21 +669,50 @@ static int ost_cleanup(struct obd_device * obddev)
         MOD_DEC_USE_COUNT;
         RETURN(0);
 }
+int ost_attach(struct obd_device *dev, 
+                   obd_count len, void *data)
+{
+        /*  lprocfs_reg_dev(dev, (lprocfs_group_t*)lprocfs_ptlrpc_nm,
+                        sizeof(struct lprofiler_ptlrpc));
+        */
+        lprocfs_reg_obd(dev, (lprocfs_vars_t*)status_var_nm_1, (void*)dev);
+        return 0; 
+}
+
+int ost_detach(struct obd_device *dev)
+{
+        /* lprocfs_dereg_dev(dev); */
+        lprocfs_dereg_obd(dev);
+        return 0;
+
+}
+
+
 
 /* use obd ops to offer management infrastructure */
 static struct obd_ops ost_obd_ops = {
+        o_attach:      ost_attach,
+        o_detach:      ost_detach,
         o_setup:       ost_setup,
         o_cleanup:     ost_cleanup,
 };
 
 static int __init ost_init(void)
 {
-        class_register_type(&ost_obd_ops, LUSTRE_OST_NAME);
+        int rc;
+
+        rc = class_register_type(&ost_obd_ops,
+                                 (lprocfs_vars_t*)status_class_var, 
+                                 LUSTRE_OST_NAME);
+        if (rc) RETURN(rc);
+
         return 0;
+
 }
 
 static void __exit ost_exit(void)
 {
+        
         class_unregister_type(LUSTRE_OST_NAME);
 }