<div dir="ltr">Hi David,<br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 10, 2018 at 3:24 PM, David Spisla <span dir="ltr"><<a href="mailto:david.spisla@iternity.com" target="_blank">david.spisla@iternity.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div lang="DE">
<div class="gmail-m_-4752732996295814472WordSection1">
<p class="MsoNormal"><span>Hello Amar, Xavi<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0cm 0cm 0cm 4pt">
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0cm 0cm">
<p class="MsoNormal"><b>Von:</b> Amar Tumballi [mailto:<a href="mailto:atumball@redhat.com" target="_blank">atumball@redhat.com</a>] <br>
<b>Gesendet:</b> Mittwoch, 10. Januar 2018 14:16<br>
<b>An:</b> Xavi Hernandez <<a href="mailto:jahernan@redhat.com" target="_blank">jahernan@redhat.com</a>>; David Spisla <<a href="mailto:david.spisla@iternity.com" target="_blank">david.spisla@iternity.com</a>><span class="gmail-"><br>
<b>Cc:</b> <a href="mailto:gluster-devel@gluster.org" target="_blank">gluster-devel@gluster.org</a><br>
<b>Betreff:</b> Re: [Gluster-devel] Simulating some kind of "virtual file"<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">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).<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">-Amar<u></u><u></u></p>
<p class="MsoNormal"><b><i>[David Spisla] Sounds good. Thank you</i></b><u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div><span class="gmail-">
<p class="MsoNormal">On Wed, Jan 10, 2018 at 6:36 PM, Xavi Hernandez <<a href="mailto:jahernan@redhat.com" target="_blank">jahernan@redhat.com</a>> wrote:<u></u><u></u></p>
</span><blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm">
<div>
<p class="MsoNormal">Hi David,<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div><span class="gmail-">
<p class="MsoNormal">On Wed, Jan 10, 2018 at 1:42 PM, David Spisla <<a href="mailto:david.spisla@iternity.com" target="_blank">david.spisla@iternity.com</a>> wrote: <u></u><u></u></p>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0cm 0cm 0cm 4pt">
<div>
<div>
<div>
<div>
<div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin:5pt 0cm 5pt 4.8pt">
<div>
<div>
<div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0cm 0cm 0cm 4pt">
<div>
<div>
<div>
<div>
<p class="MsoNormal"><b><i>[David Spisla] I tried this:</i></b><u></u><u></u></p>
<p class="MsoNormal"><i>char *new_path = malloc(1+len_path-5);</i><u></u><u></u></p>
<p class="MsoNormal"><i>memcpy(new_path, loc->path, len_path-5);</i><u></u><u></u></p>
<p class="MsoNormal"><i>new_path[strlen(new_path)] = '\0';</i><u></u><u></u></p>
<p class="MsoNormal"><i>loc->name = new_path + (len_path - len_name);</i><u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">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.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">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.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">You should do something like this (assuming both loc->path and loc->name are not NULL and skipping many necessary checks):<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
</div>
<blockquote style="margin:5pt 0cm 5pt 30pt">
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">len_path = strlen(loc->path);</span><u></u><u></u></p>
</div>
</div>
</div>
</blockquote>
<blockquote style="margin:5pt 0cm 5pt 30pt">
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">len_name = strlen(loc->name);</span><u></u><u></u></p>
</div>
</div>
</div>
</blockquote>
<blockquote style="margin:5pt 0cm 5pt 30pt">
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">new_path = GF_MALLOC(len_path - 4, gf_common_mt_char);</span><u></u><u></u></p>
</div>
</div>
</div>
</blockquote>
<blockquote style="margin:5pt 0cm 5pt 30pt">
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">memcpy(new_path, loc->path, len_path - 5);</span><u></u><u></u></p>
</div>
</div>
</div>
</blockquote>
<blockquote style="margin:5pt 0cm 5pt 30pt">
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">new_path[len_path - 5] = 0;</span><u></u><u></u></p>
</div>
</div>
</div>
</blockquote>
<blockquote style="margin:5pt 0cm 5pt 30pt">
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">loc->name = new_path + len_path - len_name;</span><u></u><u></u></p>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New""> </span><u></u><u></u></p>
</div>
<p class="MsoNormal"><span style="font-family:Arial,sans-serif">This should work fine.</span><u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Arial,sans-serif">Xavi</span><u></u><u></u></p>
<p class="MsoNormal"><b><i>[David Spisla] Yes, this worls fine. Thank you
</i></b><b><i><span style="font-family:"Segoe UI Emoji",sans-serif">😊</span>. 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.</i></b><u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">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.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">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).<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">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.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:rgb(136,136,136)"><u></u> <u></u></span></p>
</div>
</span><div>
<p class="MsoNormal"><span style="color:rgb(136,136,136)">Xavi<u></u><u></u></span></p>
<p class="MsoNormal"><b><i>[David Spisla] Ok, so there is no chance to get that gfid in an initial lookup.</i></b></p></div></div></div></div></blockquote></div></div></div></div></div></blockquote><div>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.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="DE"><div class="gmail-m_-4752732996295814472WordSection1"><div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0cm 0cm 0cm 4pt"><div><div><blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm"><div><div><div><div><p class="MsoNormal"><b><i> Another problem seems to be that there is no loc parameter in lookup_cbk function. </i></b><b><i>I have the buf->gfid and inode, but there is no loc with the path and name oft he file.</i></b></p></div></div></div></div></blockquote></div></div></div></div></div></blockquote><div>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):</div><div><br></div><div>1. Attach it to frame->local. You can access it later from cbk using frame->local.</div><div><br></div><div>2. Pass it as a "cookie" in STACK_WIND_COOKIE(). You can access it from cbk using the 'cookie' argument.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="DE"><div class="gmail-m_-4752732996295814472WordSection1"><div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0cm 0cm 0cm 4pt"><div><div><blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm"><div><div><div><div><p class="MsoNormal"><b><i>I want to use syncop_getxattr but I have no loc as parameter. Can I get a loc struct with the gfid?</i></b></p></div></div></div></div></blockquote></div></div></div></div></div></blockquote><div>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.</div><div><br></div><div>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.</div><div><br></div><div>You can add the xattrs you need using:</div><div><br></div></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace">dict_set_uint32(xdata, "<xattr name>", 0);</font></div></div></div></blockquote><div><br></div>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.<div><br></div><div>This way, on the 'xdata' argument of the lookup cbk, you will receive the value of that xattr. You can read it using:</div><div><br></div><div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font face="monospace, monospace">dict_get_<data type>(xdata, "<xattr name>", &value);</font></div></blockquote><div><br></div>In 'value' you will get the current value of the requested xattr (if it exists).</div><div><br></div><div>Xavi<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="DE"><div class="gmail-m_-4752732996295814472WordSection1"><div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0cm 0cm 0cm 4pt"><div><div><blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm"><div><div><div><div><p class="MsoNormal"><b><i><u></u><u></u></i></b></p>
<p class="MsoNormal"><b><i><u></u> <u></u></i></b></p>
<p class="MsoNormal"><b><i>David </i></b><u></u><u></u></p>
</div>
</div>
</div>
</div><span class="gmail-">
<p class="MsoNormal"><br>
______________________________<wbr>_________________<br>
Gluster-devel mailing list<br>
<a href="mailto:Gluster-devel@gluster.org" target="_blank">Gluster-devel@gluster.org</a><br>
<a href="http://lists.gluster.org/mailman/listinfo/gluster-devel" target="_blank">http://lists.gluster.org/<wbr>mailman/listinfo/gluster-devel</a><u></u><u></u></p>
</span></blockquote>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal">-- <u></u><u></u></p>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">Amar Tumballi (amarts)<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote></div><br></div></div></div>