[Gluster-devel] Can function arguments be modified ?

Jeff Darcy jdarcy at redhat.com
Sun Mar 11 14:19:32 UTC 2012

On 03/10/2012 03:34 PM, Anand Avati wrote:
> 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.

Object-lifecycle management in GlusterFS can be a bit tricky.  The two most
common patterns I see are that dict_t and similar structures will be
*dereferenced* either when the originator's (i.e. FUSE or protocol/server)
STACK_WIND returns or when the callback completes.  Thus, you can usually
ensure their continued existence by doing a dict_ref (or data_ref if you really
only care about a single value).  IIRC, DHT already does this for some layout
xattrs that it aggregates across subvolumes.  In most cases, though, Avati is
correct: good practice would be to make a copy.

More information about the Gluster-devel mailing list