Re: Can function arguments be modified ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Mar 9, 2012 at 12:18 AM, Xavier Hernandez <xhernandez@xxxxxxxxxx> wrote:
> Hello,
>
> I've a doubt about the way in which arguments received from upper or lower
> translators should be handled in case they need to be modified.
>
> Simple arguments are passed by value and there is no problem, but all other
> data types are passed by reference (dict_t *, fd_t *, inode_t *, struct iatt
> *, ...). I know that for fd_t and inode_t the way to go is to attach context
> structures to them associated to my translator without modifying anything,
> but for dict_t and other structures I may need to make changes before
> continuing. For example, I need to add some keys into a dict before calling
> lower translators and I need to remove some keys before propagating response
> to upper translators. I also need to modify some fields from an struct iatt.
>
> The question is what is the policy used for gluster development ? are
> translators allowed to modify arguments received from upper layers ? are
> translators allowed to modify arguments received from callbacks before
> propagating them ?
>
> My translator can have multiple subvolumes, so if they are allowed to modify
> the parameters I send to them, I need to send a different copy to each one.
> Otherwise they can interfere with each other. On the other hand, if they are
> not allowed to modify my arguments, but I need to modify what I receive, I
> would need to make a copy before.
>
> The same happens with arguments received from a callback. If translators can
> modify them, it's supposed that they can't access data after propagating it
> upper into the chain, otherwise they could see unknown or inconsistent data.
> If they aren't allowed to modify data, then a copy must be done before
> making any change.
>
> Making copies is always safe but if it's unnecessary, it's a waste of time
> and a loss of resources and throughput.
>
> What is the correct behaviour ?
>
> Thank you very much for your help
>
> Xavi

There is a no rule written on stone here. It is good practice to make
copies. Note that for things like iatt structure, you need not
"allocate" and "free" from the heap. Most of the time you can copy to
a structure on the stack, modify and return that. You will see that
for parameters which get modified in the callback (typically
aggregated from multiple subvolumes), most translators have a
"modified" copy inside frame->local.

Avati



[Index of Archives]     [Gluster Users]     [Ceph Users]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux