Commit 98ad3db4 authored by gerd's avatar gerd

more diagnostics to catch mmap errors


git-svn-id: https://gps.dynxs.de/private/svn/app-plasma/[email protected] 55289a75-7b90-4627-9e07-ffb4263930b2
parent 4fe5656b
......@@ -41,25 +41,54 @@ let proc_read conf (slot, block, pos, len) =
let store = current_dn_store() in
let shm = current_dn_shm() in
let (mem,mpos) = Dn_shm.slot shm slot in
Dn_store.read_block store block pos mem mpos len
try
Dn_store.read_block store block pos mem mpos len
with
| error ->
Netlog.logf `Err
"proc_read: exception %s for block=%Ld pos=%d len=%d"
(Netexn.to_string error) block pos len;
raise (Rpc.Rpc_server Rpc.System_err)
let proc_read_shm conf (shm_obj, block, pos, len) =
if shm_obj.Rpcapi_aux.shm_length < len then
failwith "proc_read_shm: shm object too small";
if shm_obj.Rpcapi_aux.shm_offset < 0L then
failwith "proc_read_shm: negative shm offset";
let mem_fd =
Netsys_posix.shm_open
shm_obj.Rpcapi_aux.shm_path [Netsys_posix.SHM_O_RDWR] 0 in
(* Fail immediately if shm is not large enough. Otherwise we would run
into race conditions when map_file tried to enlarge the shm file
*)
let mem =
try
Bigarray.Array1.map_file
mem_fd ~pos:shm_obj.Rpcapi_aux.shm_offset
Bigarray.char Bigarray.c_layout
true shm_obj.Rpcapi_aux.shm_length
let mem_eof = Unix.LargeFile.lseek mem_fd 0L Unix.SEEK_END in
if Int64.sub mem_eof (Int64.of_int shm_obj.Rpcapi_aux.shm_length) <
shm_obj.Rpcapi_aux.shm_offset
then
failwith "proc_read_shm: shm object is smaller than announced";
let mem =
Bigarray.Array1.map_file
mem_fd ~pos:shm_obj.Rpcapi_aux.shm_offset
Bigarray.char Bigarray.c_layout
true shm_obj.Rpcapi_aux.shm_length in
Unix.close mem_fd;
mem
with error -> Unix.close mem_fd; raise error in
Unix.close mem_fd;
let store = current_dn_store() in
Dn_store.read_block store block pos mem 0 len;
Netsys_mem.memory_unmap_file mem
try
Dn_store.read_block store block pos mem 0 len;
Netsys_mem.memory_unmap_file mem
with
| error ->
Netlog.logf `Err
"proc_read_shm: exception %s for block=%Ld pos=%d len=%d \
shm_offset=%Ld shm_length=%d"
(Netexn.to_string error) block pos len shm_obj.Rpcapi_aux.shm_offset
shm_obj.Rpcapi_aux.shm_length;
raise (Rpc.Rpc_server Rpc.System_err)
let proc_write conf (slot, block) =
(** Implementation of the [write] RPC: Do the write, and take the write
......@@ -68,24 +97,50 @@ let proc_write conf (slot, block) =
let store = current_dn_store() in
let shm = current_dn_shm() in
let (mem,mpos) = Dn_shm.slot shm slot in
Dn_store.write_block store block mem mpos
try
Dn_store.write_block store block mem mpos
with
| error ->
Netlog.logf `Err
"proc_write: exception %s for block=%Ld"
(Netexn.to_string error) block;
raise (Rpc.Rpc_server Rpc.System_err)
let proc_write_shm conf (shm_obj, block) =
let store = current_dn_store() in
if shm_obj.Rpcapi_aux.shm_length < Dn_store.get_blocksize store then
failwith "proc_write_shm: shm object too small";
if shm_obj.Rpcapi_aux.shm_offset < 0L then
failwith "proc_write_shm: negative shm offset";
let mem_fd =
Netsys_posix.shm_open
shm_obj.Rpcapi_aux.shm_path [Netsys_posix.SHM_O_RDWR] 0 in
let mem =
try
Bigarray.Array1.map_file
mem_fd ~pos:shm_obj.Rpcapi_aux.shm_offset
Bigarray.char Bigarray.c_layout
true shm_obj.Rpcapi_aux.shm_length
let mem_eof = Unix.LargeFile.lseek mem_fd 0L Unix.SEEK_END in
if Int64.sub mem_eof (Int64.of_int shm_obj.Rpcapi_aux.shm_length) <
shm_obj.Rpcapi_aux.shm_offset
then
failwith "proc_write_shm: shm object is smaller than announced";
let mem =
Bigarray.Array1.map_file
mem_fd ~pos:shm_obj.Rpcapi_aux.shm_offset
Bigarray.char Bigarray.c_layout
true shm_obj.Rpcapi_aux.shm_length in
Unix.close mem_fd;
mem
with error -> Unix.close mem_fd; raise error in
Unix.close mem_fd;
Dn_store.write_block store block mem 0
try
Dn_store.write_block store block mem 0;
Netsys_mem.memory_unmap_file mem
with
| error ->
Netlog.logf `Err
"proc_write_shm: exception %s for block=%Ld \
shm_offset=%Ld shm_length=%d"
(Netexn.to_string error) block shm_obj.Rpcapi_aux.shm_offset
shm_obj.Rpcapi_aux.shm_length;
raise (Rpc.Rpc_server Rpc.System_err)
let create_dn_client conn =
let esys = Unixqueue.create_unix_event_system() in
......
......@@ -85,6 +85,8 @@ let read_file c name index len : record_reader =
let bufs =
try
Netsys_posix.shm_unlink buf_name;
Netlog.logf `Debug "read_file (pid %d): truncate fd=%Ld eof=%d"
(Unix.getpid()) (Netsys.int64_of_file_descr buf_fd) buf_dim;
Unix.ftruncate buf_fd buf_dim;
Bigarray.Array1.map_file
buf_fd Bigarray.char Bigarray.c_layout true buf_dim
......@@ -372,6 +374,8 @@ let write_file c name =
let bufs =
try
Netsys_posix.shm_unlink buf_name;
Netlog.logf `Debug "write_file (pid %d): truncate fd=%Ld eof=%d"
(Unix.getpid()) (Netsys.int64_of_file_descr buf_fd) buf_len;
Unix.ftruncate buf_fd buf_len;
Bigarray.Array1.map_file
buf_fd Bigarray.char Bigarray.c_layout true buf_len
......
......@@ -2354,10 +2354,13 @@ let rec get_shm_buf shm blocksize =
Netsys_posix.shm_open shm.shm_opath [Netsys_posix.SHM_O_RDWR] 0 in
let idx = shm.shm_blocks in
shm.shm_blocks <- idx + 1;
let pos = Int64.of_int (idx * blocksize) in
Netlog.logf `Debug
"get_shm_buf (pid %d): pos=%Ld blocksize=%d"
(Unix.getpid()) pos blocksize;
let m =
Bigarray.Array1.map_file
fd ~pos:(Int64.of_int (idx * blocksize))
Bigarray.char Bigarray.c_layout true blocksize in
fd ~pos Bigarray.char Bigarray.c_layout true blocksize in
Unix.close fd;
m, idx
......@@ -2417,6 +2420,8 @@ let rec request_shm_e c dc (supp : dn_shm_support) (h,p) =
let copy_in_e c inode pos fd len topo =
(* TODO: check pos, len *)
if pos < 0L || len < 0L then invalid_arg "Plasma_client.copy_in_e";
let get_info_e mc tid =
(** Get information: inodeinfo *)
(Util.rpc_engine mc Fsys.V1.get_inodeinfo'async (tid,inode))
......@@ -2827,6 +2832,8 @@ let copy_in c inode pos fd len topo = sync (copy_in_e c inode pos fd len) topo
let copy_out_e c inode pos fd len =
(* TODO: check pos, len *)
if pos < 0L || len < 0L then invalid_arg "Plasma_client.copy_out_e";
let get_info_e mc tid =
(** Get information: inodeinfo *)
Util.rpc_engine mc Fsys.V1.get_inodeinfo'async (tid,inode)
......@@ -3050,8 +3057,12 @@ let copy_out_e c inode pos fd len =
let fd_eof =
Unix.LargeFile.lseek fd 0L Unix.SEEK_END in
if fd_pos > Int64.sub fd_eof len then
Unix.LargeFile.ftruncate fd (Int64.add fd_pos len);
if fd_pos > Int64.sub fd_eof len then (
let new_eof = Int64.add fd_pos len in
Netlog.logf `Debug "copy_out (pid %d): truncate fd=%Ld new_eof=%Ld"
(Unix.getpid()) (Netsys.int64_of_file_descr fd) new_eof;
Unix.LargeFile.ftruncate fd new_eof
);
with_nn_session_e c
(fun mc ->
......
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