Re: [Gluster-devel] Translator issue: Change content of iovec

2017-04-03 Thread Vijay Bellur
On Mon, Apr 3, 2017 at 10:38 AM, David Spisla 
wrote:

> Dear GlusterDevels,
>
>
>
> I am coding a translator which is changing the content of the iovec if a
> user wants to read the content of the original file. Imagine you have a
> simple text file with the content „hello“.
>
> If the user wants to read that file, my translator changes the content to
> „I am the new content!!!“. But at the moment my translator is not working
> perfectly.
>
>
>
> Original Content à„hello“
>
> New content à „I am the new content!!!“
>
>
>
> If I read that file I get à „I am “
>
> It seems that there is still the old filesize allocated. I am looking for
> a way to allocate a new size so that my new String will fit into that file.
>
> I tried out several things, but without success. Maybe someone of you has
> an idea. At the moment my translator is on the top of the client stack.
>
>
>
> You find the source attached. I did all changes in à stub_readv_cbk
>
>
>


You would need to modify lookup_cbk in stub.c to indicate the appropriate
meta data attributes for the file being read. Specifically, you would need
to set ia_size in struct iatt.

HTH,
Vijay
___
Gluster-devel mailing list
Gluster-devel@gluster.org
http://lists.gluster.org/mailman/listinfo/gluster-devel

[Gluster-devel] Translator issue: Change content of iovec

2017-04-03 Thread David Spisla
Dear GlusterDevels,

I am coding a translator which is changing the content of the iovec if a user 
wants to read the content of the original file. Imagine you have a simple text 
file with the content "hello".
If the user wants to read that file, my translator changes the content to "I am 
the new content!!!". But at the moment my translator is not working perfectly.

Original Content -->"hello"
New content --> "I am the new content!!!"

If I read that file I get --> "I am "
It seems that there is still the old filesize allocated. I am looking for a way 
to allocate a new size so that my new String will fit into that file.
I tried out several things, but without success. Maybe someone of you has an 
idea. At the moment my translator is on the top of the client stack.

You find the source attached. I did all changes in --> stub_readv_cbk

Regards
David Spisla


/*
   Author: David Spisla
*/
#include 
#include 

#include "glusterfs.h"
#include "xlator.h"
#include "logging.h"
#include "stub-mem-types.h"
#include 
#include 
#include 
/*
 * This is a test xlator to write and read a stub-file
 * and extract informations about the path to
 * the original file. This is just for testing
 * issue, not for production use.
 */



int32_t
stub_readv_cbk (call_frame_t *frame,
 void *cookie,
 xlator_t *this,
 int32_t op_ret,
 int32_t op_errno,
 struct iovec *vector,
 int32_t count,
 struct iatt *stbuf,
 struct iobref *iobref, dict_t *xdata)
{   

struct iovec *new_vec;
struct iobref *new_iobref;
iobref_clear (iobref);
char temp[] = "I am the new content!!!\n";
char *buf0 = "I am the new content!!!\n";  

stbuf->ia_size = sizeof(temp);

new_vec = GF_CALLOC(1, sizeof(temp), gf_stub_mt_iovec);
   
struct iobuf *iobuf = NULL;
iobuf = iobuf_get2(this->ctx->iobuf_pool, sizeof(temp));
iobuf->ptr = buf0;
iobuf->free_ptr = buf0;
new_iobref = iobref_new();
iobref_add(new_iobref, iobuf);

new_vec[0].iov_base = buf0;
new_vec[0].iov_len = sizeof(temp);

 
STACK_UNWIND_STRICT (readv, frame, stbuf->ia_size, op_errno, new_vec, 
count,
 stbuf, new_iobref, xdata);
return 0;
}


int32_t
stub_readv (
call_frame_t *frame,
xlator_t *this,
fd_t * fd,
size_t size,
off_t offset,
uint32_t flags,
dict_t * xdata)
{   


STACK_WIND (frame,
stub_readv_cbk,
FIRST_CHILD(this),
FIRST_CHILD(this)->fops->readv,
fd, size, offset, flags, xdata);
return 0;
}


int32_t
stub_writev (
call_frame_t *frame,
xlator_t *this,
fd_t * fd,
struct iovec * vector,
int32_t count,
off_t off,
uint32_t flags,
struct iobref * iobref,
dict_t * xdata)
{ 

STACK_WIND_TAIL (frame,
 FIRST_CHILD(this), FIRST_CHILD(this)->fops->writev,
 fd, vector, count, off, flags, iobref, xdata);
return 0;
}

int32_t
stub_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno, inode_t * inode,
struct iatt * buf,
dict_t * xdata,
struct iatt * postparent)
{

STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno,
 inode, buf, xdata, postparent);
return 0;
}

int32_t
stub_lookup (
call_frame_t *frame,
xlator_t *this,
loc_t * loc,
dict_t * xdata)
{   

STACK_WIND (frame, stub_lookup_cbk,
 FIRST_CHILD(this), FIRST_CHILD(this)->fops->lookup,
 loc, xdata);
return 0;
}



int32_t
init (xlator_t *this)
{
data_t *data = NULL;

if (!this->parents) {
gf_log (this->name, GF_LOG_WARNING,
"dangling volume. check volfile ");
}

gf_log ("stub", GF_LOG_DEBUG, "stub xlator loaded");
return 0;
}

void
fini (xlator_t *this)
{
this->private = NULL;
return;
}

struct xlator_fops fops = {
.readv= stub_readv,
.writev   = stub_writev,
.lookup   = stub_lookup
};

struct xlator_cbks cbks;

struct volume_options options[] = {
};

/*
   Author: David Spisla
*/


#ifndef __STUB_MEM_TYPES_H__
#define __STUB_MEM_TYPES_H__

#include "mem-types.h"

enum gf_stub_mem_types_ {
gf_stub_mt_data,
gf_stub_mt_iovec,
};

#endif /* __STUB_MEM_TYPES_H__ */





___
Gluster-devel mailing list
Gluster-devel@gluster.org