Whamcloud - gitweb
branch: b_new_cmd
authorericm <ericm>
Wed, 11 Oct 2006 18:07:30 +0000 (18:07 +0000)
committerericm <ericm>
Wed, 11 Oct 2006 18:07:30 +0000 (18:07 +0000)
hack version of b11058.

lustre/include/lustre_sec.h
lustre/mdc/mdc_locks.c
lustre/ptlrpc/sec.c
lustre/ptlrpc/sec_null.c
lustre/ptlrpc/sec_plain.c

index e316eae..3246b24 100644 (file)
@@ -302,6 +302,11 @@ struct ptlrpc_sec_cops {
                                                 int lustre_msg_size);
         void                    (*free_repbuf) (struct ptlrpc_sec *sec,
                                                 struct ptlrpc_request *req);
+        int                     (*enlarge_reqbuf)
+                                               (struct ptlrpc_sec *sec,
+                                                struct ptlrpc_request *req,
+                                                int segment, int newsize,
+                                                int move_data);
 };
 
 struct ptlrpc_sec_sops {
@@ -444,9 +449,11 @@ int sptlrpc_ctx_display(struct ptlrpc_cli_ctx *ctx, char *buf, int bufsize);
 int sptlrpc_cli_wrap_request(struct ptlrpc_request *req);
 int sptlrpc_cli_unwrap_reply(struct ptlrpc_request *req);
 int sptlrpc_cli_alloc_reqbuf(struct ptlrpc_request *req, int msgsize);
-int sptlrpc_cli_alloc_repbuf(struct ptlrpc_request *req, int msgsize);
 void sptlrpc_cli_free_reqbuf(struct ptlrpc_request *req);
+int sptlrpc_cli_alloc_repbuf(struct ptlrpc_request *req, int msgsize);
 void sptlrpc_cli_free_repbuf(struct ptlrpc_request *req);
+int sptlrpc_cli_enlarge_reqbuf(struct ptlrpc_request *req,
+                               int segment, int newsize, int movedata);
 void sptlrpc_request_out_callback(struct ptlrpc_request *req);
 
 /*
index 92ca530..b12266d 100644 (file)
@@ -235,38 +235,13 @@ static int round_up(int val)
 static void mdc_realloc_openmsg(struct ptlrpc_request *req,
                                 struct mdt_body *body, int size[9])
 {
-        int new_size, old_size;
-        struct lustre_msg *new_msg;
+        int     rc;
 
-        LBUG(); // ericm
-        /* save old size */
-        old_size = lustre_msg_size(lustre_request_magic(req), 9, size);
-
-        size[DLM_INTENT_REC_OFF + 4] = body->eadatasize;
-        new_size = lustre_msg_size(lustre_request_magic(req), 9, size);
-        OBD_ALLOC(new_msg, new_size);
-        if (new_msg != NULL) {
-                struct lustre_msg *old_msg = req->rq_reqmsg;
-
-                DEBUG_REQ(D_INFO, req, "Replace reqmsg for larger EA %u\n",
-                          body->eadatasize);
-
-                CDEBUG(D_INFO, "Copy old msg of size %d to new allocated msg "
-                       "of size %d\n", old_size, new_size);
-                
-                memcpy(new_msg, old_msg, old_size);
-                lustre_msg_set_buflen(new_msg, DLM_INTENT_REC_OFF + 4,
-                                      body->eadatasize);
-
-                spin_lock(&req->rq_lock);
-                req->rq_reqmsg = new_msg;
-                req->rq_reqlen = new_size;
-                spin_unlock(&req->rq_lock);
-
-                OBD_FREE(old_msg, old_size);
-        } else {
-                CERROR("Can't allocate new msg, size %d\n",
-                       new_size);
+        rc = sptlrpc_cli_enlarge_reqbuf(req, DLM_INTENT_REC_OFF + 4,
+                                        body->eadatasize, 0);
+        if (rc) {
+                CERROR("Can't enlarge segment %d size to %d\n",
+                       DLM_INTENT_REC_OFF + 4, body->eadatasize);
                 body->valid &= ~OBD_MD_FLEASIZE;
                 body->eadatasize = 0;
         }
index b2b1a34..1f1d615 100644 (file)
@@ -1322,6 +1322,28 @@ void sptlrpc_cli_free_reqbuf(struct ptlrpc_request *req)
         policy->sp_cops->free_reqbuf(ctx->cc_sec, req);
 }
 
+int sptlrpc_cli_enlarge_reqbuf(struct ptlrpc_request *req,
+                               int segment, int newsize, int movedata)
+{
+        struct ptlrpc_cli_ctx    *ctx = req->rq_cli_ctx;
+        struct ptlrpc_sec_policy *policy;
+        struct lustre_msg        *msg = req->rq_reqmsg;
+
+        LASSERT(ctx);
+        LASSERT(msg);
+        LASSERT(msg->lm_bufcount > segment);
+        LASSERT(msg->lm_buflens[segment] <= newsize);
+
+        if (msg->lm_buflens[segment] == newsize)
+                return 0;
+
+        policy = ctx->cc_sec->ps_policy;
+        LASSERT(policy->sp_cops->enlarge_reqbuf);
+        return policy->sp_cops->enlarge_reqbuf(ctx->cc_sec, req,
+                                               segment, newsize, movedata);
+}
+EXPORT_SYMBOL(sptlrpc_cli_enlarge_reqbuf);
+
 int sptlrpc_cli_alloc_repbuf(struct ptlrpc_request *req, int msgsize)
 {
         struct ptlrpc_cli_ctx *ctx = req->rq_cli_ctx;
index dc1c622..38bca6f 100644 (file)
@@ -158,6 +158,43 @@ void null_free_repbuf(struct ptlrpc_sec *sec,
 }
 
 static
+int null_enlarge_reqbuf(struct ptlrpc_sec *sec,
+                        struct ptlrpc_request *req,
+                        int segment, int newsize, int move_data)
+{
+        struct lustre_msg      *oldmsg = req->rq_reqbuf, *newmsg;
+        int                     oldsize, new_msgsize;
+
+        LASSERT(req->rq_reqbuf);
+        LASSERT(req->rq_reqbuf == req->rq_reqmsg);
+        LASSERT(!move_data); // XXX
+
+        oldsize = oldmsg->lm_buflens[segment];
+        oldmsg->lm_buflens[segment] = newsize;
+
+        new_msgsize = lustre_msg_size(oldmsg->lm_magic,
+                                      oldmsg->lm_bufcount, oldmsg->lm_buflens);
+
+        /* FIXME need move data!!! */
+        if (req->rq_pool) {
+                req->rq_reqlen = new_msgsize;
+        } else {
+                OBD_ALLOC(newmsg, new_msgsize);
+                if (newmsg == NULL) {
+                        oldmsg->lm_buflens[segment] = oldsize;
+                        return -ENOMEM;
+                }
+                memcpy(newmsg, oldmsg, req->rq_reqlen);
+
+                OBD_FREE(req->rq_reqbuf, req->rq_reqbuf_len);
+                req->rq_reqbuf = req->rq_reqmsg = newmsg;
+                req->rq_reqbuf_len = req->rq_reqlen = new_msgsize;
+        }
+
+        return 0;
+}
+
+static
 int null_accept(struct ptlrpc_request *req)
 {
         LASSERT(SEC_FLAVOR_POLICY(req->rq_sec_flavor) == SPTLRPC_POLICY_NULL);
@@ -238,6 +275,7 @@ static struct ptlrpc_sec_cops null_sec_cops = {
         .alloc_repbuf           = null_alloc_repbuf,
         .free_reqbuf            = null_free_reqbuf,
         .free_repbuf            = null_free_repbuf,
+        .enlarge_reqbuf         = null_enlarge_reqbuf,
 };
 
 static struct ptlrpc_sec_sops null_sec_sops = {
index 7eeaf14..53abfba 100644 (file)
@@ -258,6 +258,15 @@ void plain_free_repbuf(struct ptlrpc_sec *sec,
 }
 
 static
+int plain_enlarge_reqbuf(struct ptlrpc_sec *sec,
+                         struct ptlrpc_request *req,
+                         int segment, int newsize, int move_data)
+{
+        LBUG();
+        return 0;
+}
+
+static
 int plain_accept(struct ptlrpc_request *req)
 {
         struct lustre_msg *msg = req->rq_reqbuf;
@@ -425,6 +434,7 @@ static struct ptlrpc_sec_cops plain_sec_cops = {
         .alloc_repbuf           = plain_alloc_repbuf,
         .free_reqbuf            = plain_free_reqbuf,
         .free_repbuf            = plain_free_repbuf,
+        .enlarge_reqbuf         = plain_enlarge_reqbuf,
 };
 
 static struct ptlrpc_sec_sops plain_sec_sops = {