Commit cf31acf6 authored by gerd's avatar gerd

Simplifying the impl of get_write_eof


git-svn-id: https://gps.dynxs.de/private/svn/app-plasma/trunk@644 55289a75-7b90-4627-9e07-ffb4263930b2
parent 7660f3f5
......@@ -51,10 +51,6 @@ and block_buffer =
mutable timer : unit Uq_engines.engine option;
mutable eof : int64 option;
(* the minimum eof position because of this written block *)
mutable real_eof : int64;
(* the eof value from inodeinfo, replicated in every block_buffer.
-1 means unknown
*)
mutable mtime : Plasma_rpcapi_aux.time option
(* the minimum mtime because of this written block *)
}
......@@ -123,19 +119,6 @@ let is_complete wbuf block bbuf =
!whole_block
let get_real_eof wbuf inode =
let eof = ref (-1L) in
( try
Hashtbl.iter
(fun (i,_) bbuf ->
if i=inode then (eof := bbuf.real_eof; raise Exit)
)
wbuf.buffers
with Exit -> ()
);
!eof
let count_pieces bbuf =
PieceMap.fold
(fun _ _ n -> n+1)
......@@ -310,19 +293,6 @@ let strmem_zero sm pos len =
(Bigarray.Array1.sub m pos len)
'\000'
let update_real_eof_e wbuf inode bbuf esys =
(* Just in case real_eof is still -1 set it *)
if bbuf.real_eof = (-1L) then
Plasma_client.get_cached_inodeinfo_e wbuf.client inode true
++ (fun ii ->
if bbuf.real_eof = (-1L) then
bbuf.real_eof <- ii.Plasma_rpcapi_aux.eof;
eps_e (`Done ()) esys
)
else
eps_e (`Done ()) esys
let rec write_e wbuf inode filepos data datapos datalen =
let esys = Plasma_client.event_system wbuf.client in
(* We only write up to one block *)
......@@ -358,18 +328,20 @@ let rec write_e wbuf inode filepos data datapos datalen =
let out_of_buffers =
Hashtbl.length wbuf.buffers + need_blocks >= wbuf.max_blocks in
let block_complete =
need_blocks = 1 && datalen1=wbuf.blocksize in
datalen1=wbuf.blocksize in
let in_mem =
need_blocks = 1 &&
Plasma_client.in_buffer wbuf.client inode filepos in
if out_of_buffers || flushing || block_complete || in_mem then (
if out_of_buffers || flushing || block_complete || in_mem || datalen1=0 then (
if block_complete && not flushing then (
let bbuf = Hashtbl.find wbuf.buffers (inode,block) in
stop_timer bbuf;
Hashtbl.remove wbuf.buffers (inode,block);
try
let bbuf = Hashtbl.find wbuf.buffers (inode,block) in
stop_timer bbuf;
Hashtbl.remove wbuf.buffers (inode,block);
with Not_found -> ()
);
Plasma_client.write_e
wbuf.client inode filepos data 0 datalen1
wbuf.client inode filepos data datapos datalen1
)
else (
let now = get_time() in
......@@ -382,7 +354,7 @@ let rec write_e wbuf inode filepos data datapos datalen =
bbuf.pieces <-
PieceMap.add
(filepos,finalpos)
(filepos,finalpos,as_string(strmem_sub data 0 datalen1))
(filepos,finalpos,as_string(strmem_sub data datapos datalen1))
bbuf.pieces;
bbuf.eof <- Some (match bbuf.eof with
| Some eof -> max eof endpos
......@@ -396,12 +368,10 @@ let rec write_e wbuf inode filepos data datapos datalen =
(* If it is complete: submit now *)
if is_complete wbuf block bbuf then
flush_single_e wbuf inode block bbuf
++ (fun () -> update_real_eof_e wbuf inode bbuf esys)
++ (fun () -> eps_e (`Done datalen1) esys)
else (
start_timer wbuf inode block bbuf;
update_real_eof_e wbuf inode bbuf esys
++ (fun () -> eps_e (`Done datalen1) esys)
eps_e (`Done datalen1) esys
)
with
| Not_found ->
......@@ -412,19 +382,15 @@ let rec write_e wbuf inode filepos data datapos datalen =
timer = None;
eof = Some endpos;
mtime = Some now;
real_eof = get_real_eof wbuf inode;
} in
bbuf.pieces <-
PieceMap.add
(filepos,finalpos)
(filepos,finalpos,as_string(strmem_sub data 0 datalen1))
(filepos,finalpos,as_string(strmem_sub data datapos datalen1))
PieceMap.empty;
Hashtbl.add wbuf.buffers (inode,block) bbuf;
update_real_eof_e wbuf inode bbuf esys
++ (fun () ->
start_timer wbuf inode block bbuf;
eps_e (`Done datalen1) esys
)
start_timer wbuf inode block bbuf;
eps_e (`Done datalen1) esys
)
let our_write_eof wbuf inode =
......@@ -434,7 +400,7 @@ let our_write_eof wbuf inode =
match bbuf.eof with
| None -> acc
| Some eof ->
if i=inode then max (max eof bbuf.real_eof) acc else acc
if i=inode then max eof acc else acc
)
wbuf.buffers
(-1L) in
......@@ -444,14 +410,14 @@ let our_write_eof wbuf inode =
let get_write_eof wbuf inode =
try
let eof1 = our_write_eof wbuf inode in
let eof1 = Plasma_client.get_write_eof wbuf.client inode in
let eof2 =
try Plasma_client.get_write_eof wbuf.client inode
with Not_found -> 0L in
try our_write_eof wbuf inode
with Not_found -> eof1 in
max eof1 eof2
with
| Not_found ->
Plasma_client.get_write_eof wbuf.client inode
our_write_eof wbuf inode
let our_write_mtime wbuf inode =
......@@ -475,14 +441,14 @@ let our_write_mtime wbuf inode =
let get_write_mtime wbuf inode =
try
let mtime1 = our_write_mtime wbuf inode in
let mtime1 = Plasma_client.get_write_mtime wbuf.client inode in
let mtime2 =
try Plasma_client.get_write_mtime wbuf.client inode
try our_write_mtime wbuf inode
with Not_found -> mtime1 in
max_time mtime1 mtime2
with
| Not_found ->
Plasma_client.get_write_mtime wbuf.client inode
| Not_found ->
our_write_mtime wbuf inode
let rec read_e ?lazy_validation wbuf inode filepos data datapos datalen =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment