[Pvfs2-cvs] commit by slang in pvfs2/src/io/trove/trove-dbpf: dbpf-bstream-direct.c

CVS commit program cvs at parl.clemson.edu
Thu Aug 21 16:06:16 EDT 2008


Update of /projects/cvsroot/pvfs2/src/io/trove/trove-dbpf
In directory parlweb1:/tmp/cvs-serv30908/src/io/trove/trove-dbpf

Modified Files:
      Tag: directio-branch
	dbpf-bstream-direct.c 
Log Message:
lock the size update to prevent RMW conflicts.


Index: dbpf-bstream-direct.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/io/trove/trove-dbpf/Attic/dbpf-bstream-direct.c,v
diff -p -u -r1.1.2.4 -r1.1.2.5
--- dbpf-bstream-direct.c	5 Aug 2008 15:08:10 -0000	1.1.2.4
+++ dbpf-bstream-direct.c	21 Aug 2008 20:06:15 -0000	1.1.2.5
@@ -33,6 +33,8 @@
 #include "pint-context.h"
 #include "pint-op.h"
 
+static gen_mutex_t dbpf_update_size_lock = GEN_MUTEX_INITIALIZER;
+
 typedef struct
 {
     char *buffer;
@@ -737,6 +739,7 @@ static int dbpf_bstream_direct_write_op_
     struct dbpf_bstream_rw_list_op *rw_op;
     dbpf_queued_op_t *qop_p;
     int eor = -1;
+    int sync_required = 0;
 
     rw_op = (struct dbpf_bstream_rw_list_op *)ptr;
     qop_p = (dbpf_queued_op_t *)rw_op->queued_op_ptr;
@@ -744,12 +747,6 @@ static int dbpf_bstream_direct_write_op_
     ref.fs_id = qop_p->op.coll_p->coll_id;
     ref.handle = qop_p->op.handle;
 
-    ret = dbpf_dspace_attr_get(qop_p->op.coll_p, ref, &attr);
-    if(ret != 0)
-    {
-        return ret;
-    }
-
     ret = dbpf_bstream_get_extents(
         rw_op->mem_offset_array,
         rw_op->mem_size_array,
@@ -785,6 +782,12 @@ static int dbpf_bstream_direct_write_op_
         return ret;
     }
 
+    ret = dbpf_dspace_attr_get(qop_p->op.coll_p, ref, &attr);
+    if(ret != 0)
+    {
+        return ret;
+    }
+
     *rw_op->out_size_p = 0;
     for(i = 0; i < extent_count; ++ i)
     {
@@ -810,20 +813,43 @@ static int dbpf_bstream_direct_write_op_
     if(eor > attr.u.datafile.b_size)
     {
         int outcount;
-        /* set the size of the file */
-        attr.u.datafile.b_size = eor;
-        /* We want to hit the coalesce path, so we queue up the setattr */
-        dbpf_queued_op_init(qop_p,
-                            DSPACE_SETATTR,
-                            ref.handle,
-                            qop_p->op.coll_p,
-                            dbpf_dspace_setattr_op_svc,
-                            qop_p->op.user_ptr,
-                            TROVE_SYNC,
-                            qop_p->op.context_id);
-        dbpf_dspace_attr_set(qop_p->op.coll_p, ref, &attr);
-        ret = dbpf_sync_coalesce(qop_p, 0, &outcount);
-        return PINT_MGMT_OP_CONTINUE;
+
+        gen_mutex_lock(&dbpf_update_size_lock);
+        ret = dbpf_dspace_attr_get(qop_p->op.coll_p, ref, &attr);
+        if(ret != 0)
+        {
+            gen_mutex_unlock(&dbpf_update_size_lock);
+            return ret;
+        }
+
+        if(eor > attr.u.datafile.b_size)
+        {
+            /* set the size of the file */
+            attr.u.datafile.b_size = eor;
+            ret = dbpf_dspace_attr_set(qop_p->op.coll_p, ref, &attr);
+            if(ret != 0)
+            {
+                gen_mutex_unlock(&dbpf_update_size_lock);
+                return ret;
+            }
+            sync_required = 1;
+        }
+        gen_mutex_unlock(&dbpf_update_size_lock);
+
+        if(sync_required == 1)
+        {
+            /* We want to hit the coalesce path, so we queue up the setattr */
+            dbpf_queued_op_init(qop_p,
+                                DSPACE_SETATTR,
+                                ref.handle,
+                                qop_p->op.coll_p,
+                                dbpf_dspace_setattr_op_svc,
+                                qop_p->op.user_ptr,
+                                TROVE_SYNC,
+                                qop_p->op.context_id);
+            ret = dbpf_sync_coalesce(qop_p, 0, &outcount);
+            return PINT_MGMT_OP_CONTINUE;
+        }
     }
 
     return PINT_MGMT_OP_COMPLETED;



More information about the Pvfs2-cvs mailing list