<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Sep 30, 2013 at 3:40 AM, Shyamsundar Ranganathan <span dir="ltr">&lt;<a href="mailto:srangana@redhat.com" target="_blank">srangana@redhat.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div>Avati, Amar,<br><br>Amar, Anand S and myself had a discussion on this comment and here is an answer to your queries the way I see it. Let me know if I am missing something here.<br>
<br>(this is not a NFS Ganesha requirement, FYI. As Ganesha will only do a single lookup or preserve a single object handle per filesystem object in its cache)<br><br>Currently a glfs_object is an opaque pointer to an object (it is a _handle_ to the object). The object itself contains a ref&#39;d inode, which is the actual pointer to the object.<br>
<br>1) The similarity and differences of object handles to fds<br><br>The intention of multiple object handles is in lines with multiple fd&#39;s per file, an application using the library is free to lookup (and/or create (and its equivalents)) and acquire as many object handles as it wants for a particular object, and can hence determine the lifetime of each such object in its view. So in essence one thread can have an object handle to perform, say attribute related operations, whereas another thread has the same object looked up to perform IO.<br>
</div></div></div></blockquote><div><br></div><div>So do you mean a glfs_object is meant to be a *per-operation* handle? If one thread wants to perform a chmod() and another thread wants to perform chown() and both attempt to resolve the same name and end up getting different handles, then both of them unref the glfs_handle right after their operation?</div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div>Where the object handles depart from the notion of fds is when an unlink is performed. As POSIX defines that open fds are still _open_ for activities on the file, the life of an fd and the actual object that it points to is till the fd is closed. In the case of object handles though, the moment any handle is used to unlink the object (which BTW is done using the parent object handle and the name of the child), all handles pointing to the object are still valid pointers, but operations on then will result in ENOENT, as the actual object has since been unlinked and removed by the underlying filesystem.<br>
</div></div></div></blockquote><div><br></div><div>Not always. If the file had hardlinks the handle should still be valid. And if there were no hardlinks and you unlinked the last link, further operations must return ESTALE. ENOENT is when a &quot;basename&quot; does not resolve to a handle (in entry operations) - for e.g when you try to unlink the same entry a second time. Whereas ESTALE is when a presented handle does not exist - for e.g when you try to operate (read, chmod) a handle which got deleted.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div>The departure from fds is considered valid in my perspective, as the handle points to an object, which has since been removed, and so there is no semantics here that needs it to be preserved for further operations as there is a reference to it held.<br>
</div></div></div></blockquote><div><br></div><div>The departure is only in the behavior of unlinked files. That is orthogonal to whether you want to return separate handles each time a component is looked up. I fail to see how the &quot;departure from fd behavior&quot; justifies creating new glfs_object per lookup?</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div>So in essence for each time an object handle is returned by the API, it has to be closed for its life to end. Additionally if the object that it points to is removed from the underlying system, the handle is pointing to an entry that does not exist any longer and returns ENOENT on operations using the same.<br>
<br>2) The issue/benefit of having the same object handle irrespective of looking it up multiple times<br><br>If we have an 1-1 relationship of object handles (i.e struct glfs_object) to inodes, then the caller gets the same pointer to the handle. Hence having multiple handles as per the caller, boils down to giving out ref counted glfs_object(s) for the same inode.<br>
<br>Other than the memory footprint, this will still not make the object live past it&#39;s unlink time. The pointer handed out will be still valid till the last ref count is removed (i.e the object handle closed), at which point the object handle can be destroyed.<br>
</div></div></div></blockquote><div><br></div><div>If I understand what you say above correctly, you intend to solve the problem of &quot;unlinked files must return error&quot; at your API layer? That&#39;s wrong. The right way is to ref-count glfs_object and return them precisely because you should NOT make the decision about the end of life of an inode at that layer. A hardlink may have been created by another client and the glfs_object may therefore be still be valid.</div>
<div><br></div><div>You are also returning separate glfs_object for different hardlinks of a file. Does that mean glfs_object is representing a dentry? or a per-operation reference to an inode?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div>So again, as many handles were handed out for the same inode, they have to be closed, etc.<br><br>3) Graph switches<br><br>In the case of graph switches, handles that are used in operations post the switch, get refreshed with an inode from the new graph, if we have an N:1 object to inode relationship.<br>
<br>In the case of 1:1 this is done once, but is there some multi thread safety that needs to be in place? I think this is already in place from the glfs_resolve_inode implementation as suggested earlier, but good to check.<br>
<br>4) Renames<br><br>In the case of renames, the inode remains the same, hence all handed out object handles still are valid and will operate on the right object per se.<br><br>5) unlinks and recreation of the same _named_ object in the background<br>
<br>Example being, application gets an handle for an object, say named &quot;a.txt&quot;, and in the background (or via another application/client) this is deleted and recreated.<br><br>This will return ENOENT as the GFID would have changed for the previously held object to the new one, even though the names are the same. This seems like the right behaviour, and does not change in the case of a 1:1 of an N:1 object handle to inode mapping.<br>
<br>So bottom line, I see the object handles like an fd with the noted difference above. Having them in a 1:1 relationship or as a N:1 relationship does not seem to be an issue from what I understand, what am I missing here?<br>
</div></div></div></blockquote><div><br></div><div>The issue is this. From what I understand, the usage of glfs_object in the FSAL is not like a per-operation handle, but something stored long term (many minutes, hours, days) in the per-inode context of the NFS Ganesha layer. Now NFS Ganesha may be doing the &quot;right thing&quot; by not re-looking up an already looked up name and therefore avoiding a leak (I&#39;m not so sure, it still needs to verify every so often if the mapping is still valid). From NFS Ganesha&#39;s point of view the handle is changing on every lookup.</div>
<div><br></div><div>Now consider what happens in case of READDIRPLUS. A list of names and handles are returned to the client. The list of names can possibly include names which were previously looked up as well. Both are supposed to represent the same &quot;gfid&quot;, but here will be returning new glfs_objects. When a client performs an operation on a GFID, on which glfs_object will the operation be performed at the gfapi layer? This part seems very ambiguous and not clear.</div>
<div><br></div><div>What would really help is if you can tell what a glfs_object is supposed to represent? - an on disk inode (i.e GFID)? an in memory per-graph inode (i.e inode_t)? A dentry? A per-operation handle to an on disk inode? A per-operation handle to an in memory per-graph inode? A per operation handle to a dentry? In the current form, it does not seem to fit any of the these categories.</div>
<div><br></div><div><br></div><div>Avati</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif">
<div>Shyam</div><div><br></div><div><br></div><hr><blockquote style="padding-left:5px;font-size:12pt;font-style:normal;margin-left:5px;font-family:Helvetica,Arial,sans-serif;text-decoration:none;font-weight:normal;border-left:2px solid #1010ff">
<div class="im"><b>From: </b>&quot;Anand Avati&quot; &lt;<a href="mailto:avati@gluster.org" target="_blank">avati@gluster.org</a>&gt;<br><b>To: </b>&quot;Shyamsundar Ranganathan&quot; &lt;<a href="mailto:srangana@redhat.com" target="_blank">srangana@redhat.com</a>&gt;<br>
<b>Cc: </b>&quot;Gluster Devel&quot; &lt;<a href="mailto:gluster-devel@nongnu.org" target="_blank">gluster-devel@nongnu.org</a>&gt;<br></div><b>Sent: </b>Monday, September 30, 2013 10:35:05 AM<div><div class="h5"><br><b>Subject: </b>Re: RFC/Review: libgfapi object handle based extensions<br>
<div><br></div><div dir="ltr">I see a pretty core issue - lifecycle management of &#39;struct glfs_object&#39;. What is the structure representing? When is it created? When is it destroyed? How does it relate to inode_t?<div>
<br></div><div>
Looks like for every lookup() we are creating a new glfs_object, even if the looked up inode was already looked up before (in the cache) and had a glfs_object created for it in the recent past.</div><div><br></div><div>We need a stronger relationship between the two with a clearer relationship. It is probably necessary for a glfs_object to represent mulitple inode_t&#39;s at different points in time depending on graph switches, but for a given inode_t we need only one glfs_object. We definitely must NOT have a new glfs_object per lookup call.</div>

<div><br></div><div>Avati</div><div><br><div class="gmail_extra"><div class="gmail_quote">On Thu, Sep 19, 2013 at 5:13 AM, Shyamsundar Ranganathan <span dir="ltr">&lt;<a href="mailto:srangana@redhat.com" target="_blank">srangana@redhat.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Avati,<br>
<br>
Please find the updated patch set for review at gerrit.<br>
<a href="http://review.gluster.org/#/c/5936/" target="_blank">http://review.gluster.org/#/c/5936/</a><br>
<br>
Changes made to address the points (1) (2) and (3) below. By the usage of the suggested glfs_resolve_inode approach.<br>
<br>
I have not yet changes glfs_h_unlink to use the glfs_resolve_at. (more on this a little later).<br>
<br>
So currently, the review request is for all APIs other than,<br>
glfs_h_unlink, glfs_h_extract_gfid, glfs_h_create_from_gfid<br>
<br>
glfs_resolve_at: Using this function the terminal name will be a force look up anyway (as force_lookup will be passed as 1 based on !next_component). We need to avoid this _extra_ lookup in the unlink case, which is why all the inode_grep(s) etc. were added to the glfs_h_lookup in the first place.<br>


<br>
Having said the above, we should still leverage glfs_resolve_at anyway, as there seem to be other corner cases where the resolved inode and subvol maybe from different graphs. So I think I want to modify glfs_resolve_at to make a conditional force_lookup, based on iatt being NULL or not. IOW, change the call to glfs_resolve_component with the conditional as, (reval || (!next_component &amp;&amp; iatt)). So that callers that do not want the iatt filled, can skip the syncop_lookup.<br>


<br>
Request comments on the glfs_resolve_at proposal.<br>
<br>
Shyam.<br>
<div><br>
----- Original Message -----<br>
<br>
&gt; From: &quot;Anand Avati&quot; &lt;<a href="mailto:avati@gluster.org" target="_blank">avati@gluster.org</a>&gt;<br>
</div>&gt; To: &quot;Shyamsundar Ranganathan&quot; &lt;<a href="mailto:srangana@redhat.com" target="_blank">srangana@redhat.com</a>&gt;<br>
&gt; Cc: &quot;Gluster Devel&quot; &lt;<a href="mailto:gluster-devel@nongnu.org" target="_blank">gluster-devel@nongnu.org</a>&gt;<br>
&gt; Sent: Wednesday, September 18, 2013 11:39:27 AM<br>
&gt; Subject: Re: RFC/Review: libgfapi object handle based extensions<br>
<div><div><br>
&gt; Minor comments are made in gerrit. Here is a larger (more important) comment<br>
&gt; for which email is probably more convenient.<br>
<br>
&gt; There is a problem in the general pattern of the fops, for example<br>
&gt; glfs_h_setattrs() (and others too)<br>
<br>
&gt; 1. glfs_validate_inode() has the assumption that object-&gt;inode deref is a<br>
&gt; guarded operation, but here we are doing an unguarded deref in the paramter<br>
&gt; glfs_resolve_base().<br>
<br>
&gt; 2. A more important issue, glfs_active_subvol() and glfs_validate_inode() are<br>
&gt; not atomic. glfs_active_subvol() can return an xlator from one graph, but by<br>
&gt; the time glfs_validate_inode() is called, a graph switch could have happened<br>
&gt; and inode can get resolved to a different graph. And in syncop_XXXXXX() we<br>
&gt; end up calling on graph1 with inode belonging to graph2.<br>
<br>
&gt; 3. ESTALE_RETRY is a fundamentally wrong thing to do with handle based<br>
&gt; operations. The ESTALE_RETRY macro exists for path based FOPs where the<br>
&gt; resolved handle could have turned stale by the time we perform the FOP<br>
&gt; (where resolution and FOP are non-atomic). Over here, the handle is<br>
&gt; predetermined, and it does not make sense to retry on ESTALE (notice that FD<br>
&gt; based fops in glfs-fops.c also do not have ESTALE_RETRY for this same<br>
&gt; reason)<br>
<br>
&gt; I think the pattern should be similar to FD based fops which specifically<br>
&gt; address both the above problems. Here&#39;s an outline:<br>
<br>
&gt; glfs_h_XXXX(struct glfs *fs, glfs_object *object, ...)<br>
&gt; {<br>
&gt; xlator_t *subvol = NULL;<br>
&gt; inode_t *inode = NULL;<br>
<br>
&gt; __glfs_entry_fs (fs);<br>
<br>
&gt; subvol = glfs_active_subvol (fs);<br>
&gt; if (!subvol) { errno = EIO; ... goto out; }<br>
<br>
&gt; inode = glfs_resolve_inode (fs, object, subvol);<br>
&gt; if (!inode) { errno = ESTALE; ... goto out; }<br>
<br>
&gt; loc.inode = inode;<br>
&gt; ret = syncop_XXXX(subvol, &amp;loc, ...);<br>
<br>
&gt; }<br>
<br>
&gt; Notice the signature of glfs_resolve_inode(). What it does: given a<br>
&gt; glfs_object, and a subvol, it returns an inode_t which is resolved on that<br>
&gt; subvol. This way the syncop_XXX() is performed with matching subvol and<br>
&gt; inode. Also it returns the inode pointer so that no unsafe object-&gt;inode<br>
&gt; deref is done by the caller. Again, this is the same pattern followed by the<br>
&gt; fd based fops already.<br>
<br>
&gt; Also, as mentioned in one of the comments, please consider using<br>
&gt; glfs_resolve_at() and avoiding manual construction of loc_t.<br>
<br>
&gt; Thanks,<br>
&gt; Avati<br>
</div></div></blockquote></div><br></div></div></div>
</div></div></blockquote><div><br></div></div></div></blockquote></div><br></div></div>