[Gluster-devel] Simulating some kind of "virtual file"

David Spisla david.spisla at iternity.com
Thu Jan 11 10:45:57 UTC 2018


Hello Xavi,

Von: Xavi Hernandez [mailto:jahernan at redhat.com]
Gesendet: Donnerstag, 11. Januar 2018 10:51
An: David Spisla <david.spisla at iternity.com>
Cc: Amar Tumballi <atumball at redhat.com>; gluster-devel at gluster.org
Betreff: Re: [Gluster-devel] Simulating some kind of "virtual file"

Hi David,

On Wed, Jan 10, 2018 at 3:24 PM, David Spisla <david.spisla at iternity.com<mailto:david.spisla at iternity.com>> wrote:
Hello Amar, Xavi

Von: Amar Tumballi [mailto:atumball at redhat.com<mailto:atumball at redhat.com>]
Gesendet: Mittwoch, 10. Januar 2018 14:16
An: Xavi Hernandez <jahernan at redhat.com<mailto:jahernan at redhat.com>>; David Spisla <david.spisla at iternity.com<mailto:david.spisla at iternity.com>>
Cc: gluster-devel at gluster.org<mailto:gluster-devel at gluster.org>
Betreff: Re: [Gluster-devel] Simulating some kind of "virtual file"

Check the files in $mountpoint/.meta/ directory. These are all virtual. And meta xlator gives a very good idea about how to handle virtual files (and directories).

-Amar
[David Spisla] Sounds good. Thank you

On Wed, Jan 10, 2018 at 6:36 PM, Xavi Hernandez <jahernan at redhat.com<mailto:jahernan at redhat.com>> wrote:
Hi David,

On Wed, Jan 10, 2018 at 1:42 PM, David Spisla <david.spisla at iternity.com<mailto:david.spisla at iternity.com>> wrote:
[David Spisla] I tried this:
char *new_path = malloc(1+len_path-5);
memcpy(new_path, loc->path, len_path-5);
new_path[strlen(new_path)] = '\0';
loc->name = new_path + (len_path - len_name);

First of all, you should always use memory allocation functions from gluster. This includes GF_MALLOC(), gf_strdup(), gf_asprintf() and several other variants. You can look at libglusterfs/src/mem-pool.h to see all available options.

The second problem I see is that memcpy() doesn't write a terminating null character, so when you compute strlen() afterwards, it will return invalid length, or even try to access invalid memory, causing a crash.

You should do something like this (assuming both loc->path and loc->name are not NULL and skipping many necessary checks):

len_path = strlen(loc->path);
len_name = strlen(loc->name);
new_path = GF_MALLOC(len_path - 4, gf_common_mt_char);
memcpy(new_path, loc->path, len_path - 5);
new_path[len_path - 5] = 0;
loc->name = new_path + len_path - len_name;

This should work fine.

Xavi
[David Spisla] Yes, this worls fine. Thank you 😊. By the way, is there a way inside gluster xlator to get access to xattr or attr of a file. In the lookup function there is only the struct loc, but I am missing there the files gfid. It seems to be null always. I could use syncop_getxattr() with the parameter loc, but the gfid is missing. Can I get the gfid if I have only loc->path and loc-> name? It is like a conversion from files path to files gfid.

One of the main purposes of the 'lookup' fop is to resolve a given path to an existing gfid, so you won't find any gfid in the lookup request (unless it's a revalidate request). You need to look at the response (cbk) of the lookup to get the real gfid. If the request succeeds, you can find the gfid in buf->ia_gfid of the lookup callback.

Other fops that receive a loc_t structure are normally called after a successful lookup, so loc->gfid and/or loc->inode->gfid should be set (unfortunately there isn't an homogeneous management of loc_t structures by xlators, so not always both fields are set).

You can also request additional xattrs in the lookup request by adding them to the xdata dictionary. Their values will be returned in the xdata argument of the lookup callback.

Xavi
[David Spisla] Ok, so there is no chance to get that gfid in an initial lookup.
In the request, no. Only revalidate lookups will include the gfid, but the initial one will only contain a path. You need to look at the answer (in the cbk of lookup) to determine the gfid.
Another problem seems to be that there is no loc parameter in lookup_cbk function. I have the buf->gfid and inode, but there is no loc with the path and name oft he file.
In this case, you need to save the path (or the entire loc if you prefer) when you receive the lookup request and pass it to the cbk to be used there. To do so you need to create a data structure that needs to be allocated and filled when the lookup request is received. Then you can pass this structure to the cbk in two ways (basically):

1. Attach it to frame->local. You can access it later from cbk using frame->local.

2. Pass it as a "cookie" in STACK_WIND_COOKIE(). You can access it from cbk using the 'cookie' argument.
[David Spisla] Yes, first I tried to store it as loc_t* in an additional variable in read_only_priv_t. This also worked, but your solution  seems to be more cleaner. It is better to use the existing infrastructure.
I prefer using solution 1. Doing frame->local = loc in lookup and get it in callback via loc_t *temp_loc = (loc_t *)frame->local. Before checking if frame->local != NULL
I want to use syncop_getxattr but I have no loc as parameter. Can I get a loc struct with the gfid?
You can manually construct a loc using the inode, gfid and path information you have. However it's not a good idea to do so from a lookup request. Inodes are not fully initialized until they reach the highest xlator (this means FUSE/NFS/gfapi for clients, and protocol/server for servers). Trying to use a partially initialized inode in a request may cause troubles on other xlators.
[David Spisla] Well, I copied it from buf->ia_gfid to temp_loc->gfid. At the moment it seems to be working. Now I can use syncop_getxattr in the callback function

If you only need to request some xattrs, the good way to do it is making use of the 'xdata' argument of the lookup request.

You can add the xattrs you need using:

dict_set_uint32(xdata, "<xattr name>", 0);

The value is not important here. The data type (uint32) is not critical (in theory any could work, at least for now), but you should use the same data type that you expect to receive to be more consistent.

This way, on the 'xdata' argument of the lookup cbk, you will receive the value of that xattr. You can read it using:

dict_get_<data type>(xdata, "<xattr name>", &value);

In 'value' you will get the current value of the requested xattr (if it exists).

Xavi
[David Spisla] This would be another option. Maybe I try this later.

Regards
David

David

_______________________________________________
Gluster-devel mailing list
Gluster-devel at gluster.org<mailto:Gluster-devel at gluster.org>
http://lists.gluster.org/mailman/listinfo/gluster-devel



--
Amar Tumballi (amarts)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gluster.org/pipermail/gluster-devel/attachments/20180111/211ccbca/attachment-0001.html>


More information about the Gluster-devel mailing list