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

CVS commit program cvs at parl.clemson.edu
Tue Dec 16 10:54:26 EST 2008


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

Modified Files:
	dbpf-bstream-direct.c dbpf.h 
Log Message:
minor reorganization; on resize of directio bstream, perform truncate after
updating attr rather than before


Index: dbpf-bstream-direct.c
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/src/io/trove/trove-dbpf/dbpf-bstream-direct.c,v
diff -p -u -r1.9 -r1.10
--- dbpf-bstream-direct.c	11 Dec 2008 19:45:18 -0000	1.9
+++ dbpf-bstream-direct.c	16 Dec 2008 15:54:26 -0000	1.10
@@ -148,7 +148,7 @@ int dbpf_aligned_block_put(void *ptr);
 int dbpf_aligned_blocks_finalize(void);
 #endif
 
-static int dbpf_dspace_setattr_op_svc_free_wrapper(struct dbpf_op *op_p);
+static int dbpf_dspace_setattr_op_svc_and_resize(struct dbpf_op *op_p);
 
 /**
  * Perform an write in direct mode (no buffering).
@@ -1085,22 +1085,48 @@ static int dbpf_bstream_direct_write_lis
     return DBPF_OP_CONTINUE;
 }
 
-/* dbpf_dspace_setattr_op_svc_free_wrapper()
+/* dbpf_dspace_setattr_op_svc_and_resize()
  *
- * Wrapper around the dbpf_dspace_setattr_op_svc() function.  This allows
- * internal callsers of setattr to have a hook to use for freeing an
- * internally allocated ds attributes structure.
+ * Wrapper around the dbpf_dspace_setattr_op_svc() function that also
+ * resizes underlying bstream file
  *
- * preserves return code ov dbpf_dspace_setattr_op_svc()
+ * preserves return code of dbpf_dspace_setattr_op_svc()
  */
-static int dbpf_dspace_setattr_op_svc_free_wrapper(struct dbpf_op *op_p)
+static int dbpf_dspace_setattr_op_svc_and_resize(struct dbpf_op *op_p)
 {
     int ret;
+    struct open_cache_ref open_ref;
+    TROVE_size tmp_size;
     
     ret = dbpf_dspace_setattr_op_svc(op_p);
+    tmp_size = op_p->u.d_setattr.attr_p->u.datafile.b_size;
+
     free(op_p->u.d_setattr.attr_p);
 
-    return(ret);
+    if(ret != DBPF_OP_COMPLETE)
+    {
+        return(ret);
+    }
+
+    /* truncate file after attributes are set */
+    ret = dbpf_open_cache_get(
+        op_p->coll_p->coll_id, op_p->handle,
+        DBPF_FD_DIRECT_WRITE,
+        &open_ref);
+    if(ret < 0)
+    {
+        return ret;
+    }
+
+    ret = DBPF_RESIZE(open_ref.fd, tmp_size);
+    if(ret < 0)
+    {
+        return(ret);
+    }
+
+    dbpf_open_cache_put(&open_ref);
+
+    return(DBPF_OP_COMPLETE);
 }
 
 static int dbpf_bstream_direct_resize_op_svc(struct dbpf_op *op_p)
@@ -1117,27 +1143,16 @@ static int dbpf_bstream_direct_resize_op
     ret = dbpf_dspace_attr_get(op_p->coll_p, ref, &attr);
     if(ret != 0)
     {
-        dbpf_open_cache_put(&op_p->u.b_resize.open_ref);
         return ret;
     }
 
-    ret = ftruncate(op_p->u.b_resize.open_ref.fd, op_p->u.b_resize.size);
-    if(ret == -1)
-    {
-        ret = -trove_errno_to_trove_error(errno);
-        dbpf_open_cache_put(&op_p->u.b_resize.open_ref);
-        return ret;
-    }
-
-    dbpf_open_cache_put(&op_p->u.b_resize.open_ref);
-
     attr.u.datafile.b_size = op_p->u.b_resize.size;
 
     dbpf_queued_op_init(q_op_p,
                         DSPACE_SETATTR,
                         ref.handle,
                         op_p->coll_p,
-                        dbpf_dspace_setattr_op_svc_free_wrapper,
+                        dbpf_dspace_setattr_op_svc_and_resize,
                         q_op_p->op.user_ptr,
                         TROVE_SYNC,
                         q_op_p->op.context_id);
@@ -1170,7 +1185,6 @@ int dbpf_bstream_direct_resize(TROVE_col
 {
     dbpf_queued_op_t *q_op_p = NULL;
     struct dbpf_collection *coll_p = NULL;
-    int ret;
 
     coll_p = dbpf_collection_find_registered(coll_id);
     if (coll_p == NULL)
@@ -1195,16 +1209,6 @@ int dbpf_bstream_direct_resize(TROVE_col
                         context_id);
 
     /* initialize the op-specific members */
-    ret = dbpf_open_cache_get(
-        coll_id, handle,
-        DBPF_FD_DIRECT_WRITE,
-        &q_op_p->op.u.b_resize.open_ref);
-    if(ret < 0)
-    {
-        dbpf_queued_op_free(q_op_p);
-        return ret;
-    }
-
     q_op_p->op.u.b_resize.size = *inout_size_p;
     q_op_p->op.u.b_resize.queued_op_ptr = q_op_p;
     *out_op_id_p = dbpf_queued_op_queue(q_op_p);

Index: dbpf.h
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/src/io/trove/trove-dbpf/dbpf.h,v
diff -p -u -r1.91 -r1.92
--- dbpf.h	11 Dec 2008 19:45:18 -0000	1.91
+++ dbpf.h	16 Dec 2008 15:54:26 -0000	1.92
@@ -379,7 +379,6 @@ struct dbpf_bstream_resize_op
     TROVE_size size;
     /* vtag? */
     void *queued_op_ptr;
-    struct open_cache_ref open_ref;
 };
 
 /* Used to maintain state of partial processing of a listio operation



More information about the Pvfs2-cvs mailing list