<div dir="ltr">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).<div><br></div><div>-Amar</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 10, 2018 at 6:36 PM, Xavi Hernandez <span dir="ltr"><<a href="mailto:jahernan@redhat.com" target="_blank">jahernan@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi David,<br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Wed, Jan 10, 2018 at 1:42 PM, David Spisla <span dir="ltr"><<a href="mailto:david.spisla@iternity.com" target="_blank">david.spisla@iternity.com</a>></span> wrote: </span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="DE" link="blue" vlink="purple"><div class="m_6675101335138961521m_-7521787277578374138WordSection1"><div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt"><div><span class=""><div><div class="m_6675101335138961521h5"><div><div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm"><div><div><div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt"><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-left:30.0pt;margin-right:0cm">
<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-left:30.0pt;margin-right:0cm">
<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-left:30.0pt;margin-right:0cm">
<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-left:30.0pt;margin-right:0cm">
<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-left:30.0pt;margin-right:0cm">
<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-left:30.0pt;margin-right:0cm">
<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""><u></u> <u></u></span></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></span><div>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif">Xavi<u></u><u></u></span></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></i></b><b><i>. 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></p></div></div></div></div></div></blockquote><div><br></div><div>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.</div><div><br></div><div>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).</div><div><br></div><div>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.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Xavi</div></font></span></div></div></div>
<br>______________________________<wbr>_________________<br>
Gluster-devel mailing list<br>
<a href="mailto:Gluster-devel@gluster.org">Gluster-devel@gluster.org</a><br>
<a href="http://lists.gluster.org/mailman/listinfo/gluster-devel" rel="noreferrer" target="_blank">http://lists.gluster.org/<wbr>mailman/listinfo/gluster-devel</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Amar Tumballi (amarts)<br></div></div></div></div></div>
</div>