[Pvfs2-cvs] commit by mtmoore in pvfs2/src/server: get-value.sm pvfs2-server.h

CVS commit program cvs at parl.clemson.edu
Mon Aug 10 11:30:13 EDT 2009


Update of /projects/cvsroot/pvfs2/src/server
In directory parlweb1:/tmp/cvs-serv10659/pvfs2/src/server

Modified Files:
      Tag: Orange-mtmoore
	get-value.sm pvfs2-server.h 
Log Message:
Merge range query changes and other fixes


Index: get-value.sm
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/server/Attic/get-value.sm,v
diff -p -u -r1.1.2.1 -r1.1.2.2
--- get-value.sm	14 Jul 2009 17:24:52 -0000	1.1.2.1
+++ get-value.sm	10 Aug 2009 15:30:13 -0000	1.1.2.2
@@ -26,9 +26,10 @@
 #include "pint-perf-counter.h"
 #include "dbpf-keyval.h"
 
-#define FAILED_PERMS 100
-#define EMPTY_RESULT 101
-
+#define FAILED_PERMS    100
+#define EMPTY_RESULT    101
+#define TARGET_ASSIGNED 102
+#define MORE_TARGETS    103
 %%
 
 machine pvfs2_get_value_sm
@@ -50,8 +51,8 @@ machine pvfs2_get_value_sm
     state assign_target
     {
         run getvalue_assign_target;
-        EMPTY_RESULT => check_resp;
-        default => perms;
+        TARGET_ASSIGNED => perms;
+        default => final_response;
     }
 
     state perms
@@ -63,10 +64,18 @@ machine pvfs2_get_value_sm
     state check_resp
     {
         run getvalue_check_resp;
-        FAILED_PERMS => setup_resp;
+        FAILED_PERMS => remove_result;
+        MORE_TARGETS => assign_target;
         default => final_response;
     }
 
+    state remove_result
+    {
+      run getvalue_remove_result;
+      MORE_TARGETS => assign_target;
+      default => final_response;
+    }
+
     state final_response
     {
         jump pvfs2_final_response_sm;
@@ -89,46 +98,76 @@ machine pvfs2_get_value_sm
 static PINT_sm_action getvalue_setup_resp(
         struct PINT_smcb *smcb, job_status_s *js_p)
 {
-    int ret=0;
+    int ret=0, i=0;
     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
-    gossip_debug(GOSSIP_GETVALUE_DEBUG, "[GETVALUE]: getvalue_setup_resp: "
-                 "enter\n");
 
     js_p->error_code = 0;
-
     ret = job_req_sched_post(s_op->op, s_op->target_fs_id, s_op->target_handle,
                              s_op->access_type, s_op->sched_policy,
                              smcb, 0, js_p, 
                              &(s_op->scheduled_id), server_job_context);
     PINT_perf_count(PINT_server_pc, PINT_PERF_REQSCHED, 1, PINT_PERF_ADD);
 
-    if( (s_op->u.getvalue.key.buffer = malloc( PVFS_NAME_MAX )) == 0 )
+    /* allocate buffer for all keyval buffers (attr and val) */
+    if( (s_op->u.getvalue.buffer = malloc( s_op->req->u.getvalue.count * 2 * 
+                                           PVFS_NAME_MAX )) == 0 )
+    {
+        js_p->error_code = -PVFS_ENOMEM;
+        return SM_ACTION_COMPLETE;
+    }
+    memset(s_op->u.getvalue.buffer, 0, 
+      s_op->req->u.getvalue.count * 2 * PVFS_NAME_MAX);
+
+    /* copy req values to state structs */
+    s_op->u.getvalue.count = s_op->req->u.getvalue.count;
+    s_op->u.getvalue.original_count = s_op->req->u.getvalue.count;
+    s_op->u.getvalue.match_count = 0;
+    s_op->u.getvalue.target_i = 0;
+
+    /* initialize response structs and buffers */
+    s_op->resp.u.getvalue.token = TROVE_ITERATE_END;
+    s_op->resp.u.getvalue.count = 0;
+    s_op->resp.u.getvalue.match_count = 0;
+
+    if( (s_op->resp.u.getvalue.dirent = 
+        malloc( s_op->u.getvalue.original_count * sizeof(PVFS_dirent)) ) == 0 ) 
+    {
+        js_p->error_code = -PVFS_ENOMEM;
+        return SM_ACTION_COMPLETE;
+    }
+    memset(s_op->resp.u.getvalue.dirent, 0, s_op->u.getvalue.original_count * 
+      sizeof(PVFS_dirent));
+
+    if( (s_op->resp.u.getvalue.key = 
+        malloc(s_op->u.getvalue.original_count*sizeof(PVFS_ds_keyval)) ) == 0 ) 
     {
-        return TROVE_ENOMEM;
+        js_p->error_code = -PVFS_ENOMEM;
+        return SM_ACTION_COMPLETE;
     }
-    memset(s_op->u.getvalue.key.buffer, 0, PVFS_NAME_MAX);
-    s_op->u.getvalue.key.buffer_sz = PVFS_NAME_MAX;
-    s_op->u.getvalue.key.read_sz = s_op->req->u.getvalue.key.read_sz;
-    memcpy(s_op->u.getvalue.key.buffer, s_op->req->u.getvalue.key.buffer, 
-           s_op->req->u.getvalue.key.buffer_sz);
+    memset(s_op->resp.u.getvalue.key, 0, s_op->u.getvalue.original_count * 
+      sizeof(PVFS_ds_keyval));
 
-    if( (s_op->u.getvalue.val.buffer = 
-        malloc(s_op->req->u.getvalue.val.buffer_sz) ) == 0 ) 
+    if( (s_op->resp.u.getvalue.val = 
+        malloc(s_op->u.getvalue.original_count*sizeof(PVFS_ds_keyval)) ) == 0 ) 
     {
-        return TROVE_ENOMEM;
+        js_p->error_code = -PVFS_ENOMEM;
+        return SM_ACTION_COMPLETE;
     }
-    memset(s_op->u.getvalue.val.buffer, 0, s_op->req->u.getvalue.val.buffer_sz);
-    s_op->u.getvalue.val.buffer_sz = s_op->req->u.getvalue.val.buffer_sz;
-    s_op->u.getvalue.val.read_sz = s_op->req->u.getvalue.val.read_sz;
-    memcpy(s_op->u.getvalue.val.buffer, s_op->req->u.getvalue.val.buffer, 
-           s_op->req->u.getvalue.val.buffer_sz);
+    memset(s_op->resp.u.getvalue.val, 0, s_op->u.getvalue.original_count * 
+      sizeof(PVFS_ds_keyval));
 
-    s_op->u.getvalue.token = s_op->req->u.getvalue.token;
 
-    memset(&(s_op->u.getvalue.dirent), 0, sizeof(PVFS_dirent));
+    /* point individual keyval buffers into s_op->u big buffer */
+    for( i = 0; i < s_op->u.getvalue.original_count; i++ )
+    {
+        s_op->resp.u.getvalue.key[i].buffer = s_op->u.getvalue.buffer + 
+            (2 * i * PVFS_NAME_MAX); 
+        s_op->resp.u.getvalue.key[i].buffer_sz = PVFS_NAME_MAX;
 
-    gossip_debug(GOSSIP_GETVALUE_DEBUG, "[GETVALUE]: getvalue_setup_resp: "
-                 "exit\n");
+        s_op->resp.u.getvalue.val[i].buffer = s_op->u.getvalue.buffer + 
+            ((2 * i * PVFS_NAME_MAX) + PVFS_NAME_MAX);
+        s_op->resp.u.getvalue.val[i].buffer_sz = PVFS_NAME_MAX;
+    }
     return SM_ACTION_COMPLETE;
 }
 
@@ -144,23 +183,24 @@ static PINT_sm_action getvalue_read_valu
 
     js_p->error_code = 0;
 
-    gossip_debug(GOSSIP_GETVALUE_DEBUG, "[GETVALUE]: getvalue_read_value: "
-                 "enter, fs_id: %d, dirent: %p, key: %p, val: %p, "
-                 "key.buffer: %s, key.buffer_sz: %d, val.buffer: %s\n",
-                 s_op->req->u.getvalue.fs_id,
-                 &(s_op->u.getvalue.dirent),
-                 &(s_op->u.getvalue.key),
-                 &(s_op->u.getvalue.val),
-                 (char *)s_op->u.getvalue.key.buffer,
-                 s_op->u.getvalue.key.buffer_sz,
-                 (char *)s_op->u.getvalue.val.buffer);
+    gossip_debug(GOSSIP_GETVALUE_DEBUG, 
+                 "[GETVALUE]: getvalue_read_value: enter, token: %llu, "
+                 "key buf_sz: %d, val buf_sz: %d\n",
+                 llu(s_op->req->u.getvalue.token), 
+                 s_op->req->u.getvalue.key.buffer_sz,
+                 s_op->req->u.getvalue.val.buffer_sz);
 
     ret = job_trove_keyval_read_value(
         s_op->req->u.getvalue.fs_id,
-        s_op->u.getvalue.token,
-        &(s_op->u.getvalue.dirent),
-        &(s_op->u.getvalue.key),
-        &(s_op->u.getvalue.val),
+        s_op->req->u.getvalue.token,
+        s_op->req->u.getvalue.query_type,
+        &(s_op->req->u.getvalue.key),
+        &(s_op->req->u.getvalue.val),
+        s_op->resp.u.getvalue.dirent,
+        s_op->resp.u.getvalue.key,
+        s_op->resp.u.getvalue.val,
+        &(s_op->u.getvalue.count),
+        &(s_op->u.getvalue.match_count),
         0,
         NULL,
         smcb,
@@ -171,6 +211,7 @@ static PINT_sm_action getvalue_read_valu
 
     gossip_debug(GOSSIP_GETVALUE_DEBUG, 
                  "[GETVALUE]: getvalue_read_value: exit\n");
+
     return ret;
 }
 
@@ -179,23 +220,41 @@ static PINT_sm_action getvalue_assign_ta
 {
     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
 
-    s_op->target_handle = s_op->u.getvalue.dirent.handle;
-    s_op->target_fs_id = s_op->req->u.getvalue.fs_id;
-    s_op->resp.u.getvalue.token = js_p->position;
-    s_op->req->u.getvalue.token = js_p->position;
-
     js_p->error_code = 0;
-    if( (js_p->position == TROVE_ITERATE_END) && 
-        (s_op->u.getvalue.key.buffer_sz == 0) )
-    {
-        gossip_debug(GOSSIP_GETVALUE_DEBUG, 
-                     "[GETVALUE]: TROVE_ITERATE_END, returning EMPTY_RESULT\n");
-        js_p->error_code = EMPTY_RESULT;
-    }
 
+    /* only store position after first time in state (if count is non-zero 
+     * we'll be back */
+    if( s_op->resp.u.getvalue.count == 0 )
+    {
+        s_op->resp.u.getvalue.count = s_op->u.getvalue.count;
+        s_op->resp.u.getvalue.match_count = 
+            ( s_op->u.getvalue.match_count > s_op->u.getvalue.count) ? 
+            ( s_op->u.getvalue.count ) : ( s_op->u.getvalue.match_count );
+        s_op->resp.u.getvalue.token = js_p->position;
+    }
+
+    if( s_op->u.getvalue.count == 0 )
+    {   /* no records found, no targets to set */
+        s_op->resp.u.getvalue.token = TROVE_ITERATE_END;
+        return SM_ACTION_COMPLETE;
+    }
+
+    assert( s_op->u.getvalue.target_i < s_op->u.getvalue.count );
+    gossip_debug(GOSSIP_GETVALUE_DEBUG,
+                 "[GETVALUE]: assign_target: target_i: %d, count: %d, "
+                 "token: %llu\n",
+                 s_op->u.getvalue.target_i, s_op->u.getvalue.count,
+                 s_op->resp.u.getvalue.token);
+
+    s_op->target_handle = 
+        s_op->resp.u.getvalue.dirent[ s_op->u.getvalue.target_i ].handle;
+    s_op->target_fs_id = s_op->req->u.getvalue.fs_id;
+
+    js_p->error_code = TARGET_ASSIGNED;
     return SM_ACTION_COMPLETE;
 }
 
+
 /* getvalue_check_resp()
  */
 static PINT_sm_action getvalue_check_resp(
@@ -203,57 +262,99 @@ static PINT_sm_action getvalue_check_res
 {
     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
 
-    gossip_debug(GOSSIP_GETVALUE_DEBUG, 
-                 "[GETVALUE]: getvalue_check_resp: enter: token: %llu, "
-                 "handle: %llu, path: %s, key: %s, value: %s\n", 
-                 s_op->req->u.getvalue.token, 
-                 s_op->u.getvalue.dirent.handle,
-                 s_op->u.getvalue.dirent.d_name,
-                 (char *)s_op->u.getvalue.key.buffer+sizeof(TROVE_handle), 
-                 (char *)s_op->u.getvalue.val.buffer);
-
-    if( js_p->error_code == EMPTY_RESULT )
-    {
-        gossip_debug(GOSSIP_GETVALUE_DEBUG, "[GETVALUE]: empty result\n");
-        memset(s_op->resp.u.getvalue.key.buffer, 0, 
-            s_op->u.getvalue.key.buffer_sz);
-        memset(s_op->resp.u.getvalue.val.buffer, 0, 
-            s_op->u.getvalue.val.buffer_sz);
-        memset(&(s_op->resp.u.getvalue.dirent), 0, sizeof(PVFS_dirent));
-        js_p->error_code = 0;
+    if( js_p->error_code != 0 )
+    {
+        gossip_debug(GOSSIP_GETVALUE_DEBUG, 
+                     "[GETVALUE]: Failed permission check on %llu, error: %d\n",
+                     llu(s_op->target_handle), js_p->error_code);
+        js_p->error_code =  FAILED_PERMS; 
     }
-    else if( js_p->error_code != 0 )
+    else
     {
-        js_p->error_code =  FAILED_PERMS;
+        /* if next result is, change error code to say so */
+        if( ++s_op->u.getvalue.target_i < s_op->u.getvalue.count )
+        {
+            js_p->error_code = MORE_TARGETS;
+        }
+        else
+        {
+            js_p->error_code = 0;
+        }
+    }
+    return SM_ACTION_COMPLETE;
+}
+
+static PINT_sm_action getvalue_remove_result(
+        struct PINT_smcb *smcb, job_status_s *js_p)
+{
+    int i = 0;
+    struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
+
+    gossip_debug(GOSSIP_DBPF_KEYVAL_DEBUG,
+                 "[DBPF KEYVAL]: remove_result enter target_i: %u, "
+                 "count: %u\n", s_op->u.getvalue.target_i,
+                 s_op->u.getvalue.count);
+    /* squish result array (key, val, dirent) to remove result with failed
+     * permission check. key, val, dirent are whole array malloc'd,
+     * buffers for key and val are one large malloc too so no leaks with
+     * memory copies. this is not cheap but the best I could figur' */
+    for( i = (s_op->u.getvalue.target_i+1); i < s_op->u.getvalue.count; i++)
+    {
+        gossip_debug(GOSSIP_GETVALUE_DEBUG,
+                     "\t[GETVALUE]: i: %d, replacing %llu(%s|%s) with "
+                     "%llu(%s|%s)\n", i, 
+                     llu(s_op->resp.u.getvalue.dirent[i-1].handle),
+                     (char *)(s_op->resp.u.getvalue.key[i-1].buffer+sizeof(PVFS_handle)),
+                     (char *)s_op->resp.u.getvalue.val[i-1].buffer,
+                     llu(s_op->resp.u.getvalue.dirent[i].handle),
+                     (char *)(s_op->resp.u.getvalue.key[i].buffer+sizeof(PVFS_handle)),
+                     (char *)s_op->resp.u.getvalue.val[i].buffer);
+        memcpy( &(s_op->resp.u.getvalue.key[i-1]), 
+                &(s_op->resp.u.getvalue.key[i]), sizeof(PVFS_ds_keyval) );
+        memcpy( &(s_op->resp.u.getvalue.val[i-1]), 
+                &(s_op->resp.u.getvalue.val[i]), sizeof(PVFS_ds_keyval) );
+        memcpy( &(s_op->resp.u.getvalue.dirent[i-1]), 
+                &(s_op->resp.u.getvalue.dirent[i]), sizeof(PVFS_dirent) );
+    }
+
+    /* zero out last item in array we just shifted (or are removing) */
+    assert( (i-1) < s_op->u.getvalue.original_count );
+    memset( &(s_op->resp.u.getvalue.key [ i-1 ]), 0,
+            sizeof( PVFS_ds_keyval ) );
+    memset( &(s_op->resp.u.getvalue.val [ i-1 ]), 0,
+            sizeof( PVFS_ds_keyval ) );
+    memset( &(s_op->resp.u.getvalue.dirent [ i-1 ]), 0,
+            sizeof( PVFS_dirent ) );
+
+    /* match count should never be less than 0 */
+    if( s_op->u.getvalue.match_count > 0 )
+    {
+        s_op->u.getvalue.match_count--;
+    }
+
+    if( s_op->u.getvalue.count == 1 )
+    {   /* removing last record */
+        s_op->u.getvalue.count = 0;
+        s_op->resp.u.getvalue.token = TROVE_ITERATE_END;
     }
     else
     {
-        /* point malloc'd buffer to response structs */
-        s_op->resp.u.getvalue.key.read_sz = s_op->u.getvalue.key.buffer_sz;
-        s_op->resp.u.getvalue.key.buffer_sz = s_op->u.getvalue.key.buffer_sz;
-        s_op->resp.u.getvalue.key.buffer = s_op->u.getvalue.key.buffer;
-    
-        s_op->resp.u.getvalue.val.read_sz = s_op->u.getvalue.val.buffer_sz;
-        s_op->resp.u.getvalue.val.buffer_sz = s_op->u.getvalue.val.buffer_sz;
-        s_op->resp.u.getvalue.val.buffer = s_op->u.getvalue.val.buffer;
-    
-        memcpy(&(s_op->resp.u.getvalue.dirent), &(s_op->u.getvalue.dirent), 
-            sizeof(PVFS_dirent));
-        gossip_debug(GOSSIP_GETVALUE_DEBUG, 
-                     "[GETVALUE]: RESPONSE: token: %llu, path: %s (%llu), "
-                     "key: %s, value: %s\n",
-                     s_op->resp.u.getvalue.token,
-                     s_op->resp.u.getvalue.dirent.d_name,
-                     llu(s_op->resp.u.getvalue.dirent.handle),
-                     (char *)
-                     s_op->resp.u.getvalue.key.buffer+sizeof(TROVE_handle),
-                     (char *)s_op->resp.u.getvalue.val.buffer);
-    
-        gossip_debug(GOSSIP_GETVALUE_DEBUG, 
-                     "[GETVALUE]: getvalue_check_resp: exit, token: %llu\n",
-                     s_op->resp.u.getvalue.token);
-        js_p->error_code = 0;
+        s_op->u.getvalue.count--;
+    }
+
+    js_p->error_code = 0;
+    if( s_op->u.getvalue.target_i < s_op->u.getvalue.count )
+    {
+        js_p->error_code = MORE_TARGETS;
     }
+
+    s_op->resp.u.getvalue.count = s_op->u.getvalue.count;
+    s_op->resp.u.getvalue.match_count = s_op->u.getvalue.match_count;
+
+    gossip_debug(GOSSIP_GETVALUE_DEBUG,
+                 "[GETVALUE]: remove_result exit, target_i: %d, "
+                 "count: %d\n", s_op->u.getvalue.target_i,
+                 s_op->resp.u.getvalue.count);
     return SM_ACTION_COMPLETE;
 }
 
@@ -265,14 +366,10 @@ static PINT_sm_action getvalue_cleanup(
 {
     struct PINT_server_op *s_op = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);
 
-    gossip_debug(GOSSIP_GETVALUE_DEBUG, 
-                 "[GETVALUE]: getvalue_cleanup: enter\n");
-
-    free(s_op->u.getvalue.key.buffer);
-    free(s_op->u.getvalue.val.buffer);
-
-    gossip_debug(GOSSIP_GETVALUE_DEBUG, 
-                 "[GETVALUE]: getvalue_cleanup: exit\n");
+    free(s_op->u.getvalue.buffer);
+    free(s_op->resp.u.getvalue.dirent);
+    free(s_op->resp.u.getvalue.key);
+    free(s_op->resp.u.getvalue.val);
     return(server_state_machine_complete(smcb));
 }
 

Index: pvfs2-server.h
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/server/pvfs2-server.h,v
diff -p -u -r1.155.10.2.6.1 -r1.155.10.2.6.2
--- pvfs2-server.h	14 Jul 2009 17:19:44 -0000	1.155.10.2.6.1
+++ pvfs2-server.h	10 Aug 2009 15:30:13 -0000	1.155.10.2.6.2
@@ -540,10 +540,11 @@ struct PINT_server_listattr_op
 
 struct PINT_server_getvalue_op
 {
-    TROVE_ds_position token;
-    PVFS_dirent dirent;
-    PVFS_ds_keyval key;
-    PVFS_ds_keyval val;
+    void *buffer;
+    uint32_t match_count;
+    uint32_t count;
+    uint32_t original_count;
+    uint32_t target_i;
 };
 
 /* this is used in both set_eattr, get_eattr and list_eattr */



More information about the Pvfs2-cvs mailing list