From e38eb1a586813c71d8f3eeffd0a8781e4dcdbe96 Mon Sep 17 00:00:00 2001 From: Sam Liddicott Date: Wed, 12 Nov 2008 08:35:33 +0000 Subject: [PATCH] Return remote cache name for out-of-process sync mechanism --- source4/librpc/idl/proxy.idl | 1 + source4/ntvfs/proxy/lib/cache/cache.c | 4 +-- source4/ntvfs/proxy/vfs_proxy.c | 46 +++++++++++++++++++++++++++-------- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/source4/librpc/idl/proxy.idl b/source4/librpc/idl/proxy.idl index 321c3c864ee..641db73769c 100644 --- a/source4/librpc/idl/proxy.idl +++ b/source4/librpc/idl/proxy.idl @@ -18,6 +18,7 @@ interface rpcproxy [in,out] uint8 flags, /* read_for_execute, zlib, md5 etc */ [in] [switch_is(flags & PROXY_USE_CACHE)] digest_ digest, [out] uint32 nread, + [out] sws cache_name, [out] [switch_is(flags)] Read_data response ); diff --git a/source4/ntvfs/proxy/lib/cache/cache.c b/source4/ntvfs/proxy/lib/cache/cache.c index 2e7a17f66cd..06024a617a3 100644 --- a/source4/ntvfs/proxy/lib/cache/cache.c +++ b/source4/ntvfs/proxy/lib/cache/cache.c @@ -124,13 +124,13 @@ void cache_beopen(struct cache_file_entry *cache) { void cache_reopen(struct cache_file_entry *cache) { cache_close(cache); - cache->fd=open(cache->pathname,O_RDWR | O_CREAT,S_IRWXU); + cache->fd=open(cache->pathname,O_RDWR | O_CREAT,S_IRWXU | S_IROTH | S_IXOTH); } void cache_create(struct cache_file_entry *cache, int readahead_window) { if (cache->status != CACHE_NONE && cache->fd<0) { - mkpath(cache->context->root, cache->context->prefix, S_IRWXU); + mkpath(cache->context->root, cache->context->prefix, S_IRWXU | S_IROTH | S_IXOTH); cache->pathname=talloc_asprintf(cache, "%s/%s", cache->context->root, cache->cache_name); diff --git a/source4/ntvfs/proxy/vfs_proxy.c b/source4/ntvfs/proxy/vfs_proxy.c index 51faf08b31f..91b02a7b4e4 100644 --- a/source4/ntvfs/proxy/vfs_proxy.c +++ b/source4/ntvfs/proxy/vfs_proxy.c @@ -2465,6 +2465,7 @@ NTSTATUS proxy_validate_complete(struct proxy_validate_parts_parts *parts) { NTSTATUS status; struct proxy_Read* r=parts->r; + struct proxy_file *f=parts->f; DEBUG(5,("%s: %d/%d bytes \n\n\n\n",__LOCATION__,r->out.nread,r->in.maxcnt)); @@ -2486,16 +2487,23 @@ NTSTATUS proxy_validate_complete(struct proxy_validate_parts_parts *parts) (memcmp(parts->digest, r->in.digest.digest, sizeof(parts->digest))==0)) { r->out.flags = PROXY_USE_CACHE | PROXY_VALIDATE; DEBUG(5,("======= VALIDATED FINE \n\n\n")); - } else if (r->in.flags & PROXY_USE_ZLIB) { - ssize_t size = r->out.response.generic.count; - DEBUG(5,("======= VALIDATED WRONG; compress size %d \n\n\n",size)); - if (compress_block(r->out.response.generic.data, &size) ) { - r->out.flags|=PROXY_USE_ZLIB; - r->out.response.compress.count=size; - r->out.response.compress.data=r->out.response.generic.data; - DEBUG(3,("%s: Compressed from %d to %d = %d%%\n", - __LOCATION__,r->out.nread,size,size*100/r->out.nread)); + } else { + if (r->in.flags & PROXY_USE_ZLIB) { + ssize_t size = r->out.response.generic.count; + DEBUG(5,("======= VALIDATED WRONG; compress size %d \n\n\n",size)); + if (compress_block(r->out.response.generic.data, &size) ) { + r->out.flags|=PROXY_USE_ZLIB; + r->out.response.compress.count=size; + r->out.response.compress.data=r->out.response.generic.data; + DEBUG(3,("%s: Compressed from %d to %d = %d%%\n", + __LOCATION__,r->out.nread,size,size*100/r->out.nread)); + } } + /* return cache filename as a ghastly hack for now */ + r->out.cache_name.s=f->cache->cache_name; + r->out.cache_name.count=strlen(r->out.cache_name.s)+1; + DEBUG(5,("%s: writing cache name: %s\n",__LOCATION__, f->cache->cache_name)); + /* todo: what about tiny files, buffer to small, don't validate tiny files <1K */ } /* assert: this must only be true if we are in a callback */ @@ -2536,6 +2544,11 @@ NTSTATUS async_proxy_validate_parts(struct async_info *async, void* io1, void* i /* log this data in r->out.generic.data */ /* Find memcpy window, copy data from the io_frag to the io */ + /* Also write validate to cache */ + if (f && f->cache) { + cache_save(f->cache, io_frag->generic.out.data, io_frag->generic.out.nread, io_frag->generic.in.offset); + } + /* extent is the last byte we (don't) read for this frag */ ssize_t extent = io_frag->generic.in.offset + io_frag->generic.out.nread; /* start_offset is the file offset we first care about */ @@ -2862,9 +2875,10 @@ static NTSTATUS proxy_read(struct ntvfs_module_context *ntvfs, if (f->oplock) { DEBUG(5,("%s: *** faking bulkd read\n\n",__LOCATION__)); r=talloc_zero(io_frag, struct proxy_Read); - r->in.flags |= PROXY_VALIDATE | PROXY_USE_CACHE | PROXY_USE_ZLIB; + r->in.flags |= PROXY_VALIDATE | PROXY_USE_CACHE;//| PROXY_USE_ZLIB; io_frag->generic.in.maxcnt = MIN(f->metadata->info_data.size, private->cache_validatesize); r->in.mincnt=io_frag->generic.in.maxcnt; + r->in.mincnt=io_frag->generic.in.mincnt; } /* not enough in cache to make it worthwhile anymore */ DEBUG(5,("VALIDATE DOWNGRADE 1, no more on this file: frag length %zu, offset %llu, cache=%x len=%lld\n", @@ -5161,6 +5175,7 @@ NTSTATUS async_proxy_smb_raw_read_rpc(struct async_info *async, union smb_read* io =talloc_get_type_abort(io1, union smb_read); struct proxy_Read* r=talloc_get_type_abort(io2, struct proxy_Read); struct proxy_file *f = async->f; + struct proxy_private *private=async->proxy; DEBUG(5,("\n>>\n%s() rpc status: %s\n",__FUNCTION__, get_friendly_nt_error_msg(status))); @@ -5235,6 +5250,17 @@ NTSTATUS async_proxy_smb_raw_read_rpc(struct async_info *async, //Assert(r->out.nread == r->out.generic.out.count); memcpy(io->generic.out.data, r->out.response.generic.data, io->generic.out.nread); } + if (r->out.cache_name.s && f && f->cache) { + int result; + setenv("WAFS_CACHE_REMOTE_NAME",r->out.cache_name.s,1); + setenv("WAFS_CACHE_LOCAL_NAME",f->cache->cache_name,1); + setenv("WAFS_REMOTE_SERVER",private->remote_server,1); + DEBUG(5,("%s running cache transfer command: %s\n",__LOCATION__,getenv("WAFS_CACHE_REMOTE_NAME"))); + result=system(getenv("WAFS_CACHE_TRANSFER")); + DEBUG(5,("%s cache transfer command result %d\n",__LOCATION__,result)); + // now set cache to make whole local file valud + cache_validated(f->cache, cache_len(f->cache)); + } return status; } -- 2.11.4.GIT