<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 08/07/2013 05:11 AM, Raghavendra G
      wrote:<br>
    </div>
    <blockquote
cite="mid:CADRNtgReSSVeSQKkqYnysJNAV5Pm57OiRxP8fPWBQLLEWUHFsA@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_extra"><br>
          <div class="gmail_quote">On Wed, Aug 7, 2013 at 12:21 AM,
            Raghavendra Bhat <span dir="ltr">&lt;<a
                moz-do-not-send="true" href="mailto:rabhat@redhat.com"
                target="_blank">rabhat@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 class="HOEnZb">
                <div class="h5">On 08/06/2013 05:22 PM, Raghavendra
                  Gowdappa wrote:<br>
                  <blockquote class="gmail_quote" style="margin:0 0 0
                    .8ex;border-left:1px #ccc solid;padding-left:1ex">
                    <br>
                    ----- Original Message -----<br>
                    <blockquote class="gmail_quote" style="margin:0 0 0
                      .8ex;border-left:1px #ccc solid;padding-left:1ex">
                      From: "Raghavendra Bhat" &lt;<a
                        moz-do-not-send="true"
                        href="mailto:rabhat@redhat.com" target="_blank">rabhat@redhat.com</a>&gt;<br>
                      To: <a moz-do-not-send="true"
                        href="mailto:gluster-devel@nongnu.org"
                        target="_blank">gluster-devel@nongnu.org</a><br>
                      Sent: Tuesday, August 6, 2013 1:52:40 PM<br>
                      Subject: [Gluster-devel] handling open fds and
                      graph switches<br>
                      <br>
                      <br>
                      Hi,<br>
                      <br>
                      As of now, there is a problem when following set
                      of operations are<br>
                      performed on a file.<br>
                      <br>
                      open () =&gt; unlink () =&gt; do a graph change
                      (not reconfigure) =&gt; fop on<br>
                      the opened fd (may be write)<br>
                      <br>
                      In the above set of operations, the fop performed
                      on the fd after the<br>
                      graph switch fails with EBADFD (which should not
                      happen). Its because<br>
                      when the file is unlinked (assume there are no
                      other hardlinks for the<br>
                      file), the gfid handle present in the .glusterfs
                      directory of the brick<br>
                      is removed. Now when graph change happens, all fds
                      have to be migrated<br>
                      to the new graph. Before that a nameless lookup
                      will be sent on the gfid<br>
                      (to build the new inode in the new graph). The
                      nameless lookup happens<br>
                      on the gfid handle. But since the gfid handle is
                      removed upon receiving<br>
                      the unlink, nameless lookup fails, thus failing
                      the fd migration to the<br>
                      new graph and the fops on the fd are also failed.<br>
                      <br>
                      A patch has been sent to handle<br>
                      this(<a moz-do-not-send="true"
                        href="http://review.gluster.org/#/c/5428/"
                        target="_blank">http://review.gluster.org/#/c/5428/</a>),
                      where the gfid handle is<br>
                      removed when the last reference to the file is
                      removed (i.e upon getting<br>
                      the unlink, it also checks whether there are any
                      open fds on the inode.<br>
                      If so, then the gfid handle is not removed. Its
                      removed when release on<br>
                      that fd is received). But that approach might lead
                      to gfid handle leaks<br>
                      (what if glusterfsd crashes upon unlinking the
                      last entry? the gfid<br>
                      handle might not have been removed if there are
                      open fds. And now if<br>
                      glusterfsd crashes, then the gfid handle for that
                      file is leaked).<br>
                      <br>
                      Another approach might be to make posix_lookup do
                      a stat on one of the<br>
                      fds present on the inode when it has to build a
                      INODE HANDLE (which<br>
                      happens as part of nameless lookup). The nameless
                      lookup suceeds and the<br>
                      new inode is looked up in the new graph for the
                      client. But after that,<br>
                      there are 2 more issues.<br>
                      <br>
                      1) After successful completion of the nameless
                      lookup, the file has to<br>
                      be opened in the new graph. So a syncop_open is
                      sent on the new graph<br>
                      for the gfid. In posix_open, posix xlator again
                      tries to open the file<br>
                      using the gfid handle. But since the gfid handle
                      is removed, open fails<br>
                      and the file is not opened (thus fd migration
                      fails again.) We can<br>
                      search the list of fds for the inode, find the
                      right fd that the fuse<br>
                      client is trying to migrate and return that fd.
                      But searching the right<br>
                      fd is a hard task. (What if a fuse client has
                      opened 2 fds with same flags?)<br>
                    </blockquote>
                    If there is more than one posix fd (fd opened on
                    backend filesystem) with same flags, its not really
                    an issue. For our purposes it doesn't make any
                    difference. Within glusterfs we'll anyways be using
                    a different fd object (to maintain lock state etc).
                    At the posix level all we need is an fd opened with
                    correct flags. We can dup one of these (posix) fds
                    and associate the duped fd with glusterfs fd object.
                    Please note that returning glfs_fd_object (with a
                    reference) won't work here, since the glusterfs fd
                    object we are migrating might have different lock
                    state than the one having posix fd opened with same
                    flags. We need to dup the posix fd and associate
                    that fd with a new glusterfs fd object.<br>
                  </blockquote>
                </div>
              </div>
              Ok. Will see this method.
              <div class="im"><br>
                <blockquote class="gmail_quote" style="margin:0 0 0
                  .8ex;border-left:1px #ccc solid;padding-left:1ex">
                  <blockquote class="gmail_quote" style="margin:0 0 0
                    .8ex;border-left:1px #ccc solid;padding-left:1ex">
                    2) Another problem is open-behind. Fuse xlator after
                    nameless lookup,<br>
                    sends syncop_open to migrate the fds. Once the
                    syncop_open is complete<br>
                    and fds are migrated, PARENT_DOWN event is sent on
                    the old graph and the<br>
                    client xlator sends release on all the fds (if the
                    previous syncop_open<br>
                    is successful, then its safe to send release from
                    old graph as the new<br>
                    fd would have been migrated to the new graph, with
                    corresponding fd<br>
                    present in the brick). But before that in
                    syncop_open, open-behind might<br>
                    have sent success to the fuse without actually
                    winding the open call to<br>
                    the below xlators. Now fuse gets success for the
                    open, sends PARENT_DOWN<br>
                    to old graph, which sends release on the fd. Thus
                    even though a fd is<br>
                    present from application's point of view, there are
                    no mechanisms to<br>
                    access the file (as the fds and gfid handles have
                    been removed already.)<br>
                  </blockquote>
                  Introduce a key in xdata "force-open" in open fop and
                  if that key is set, make open-behind to not to delay
                  open.<br>
                </blockquote>
              </div>
              But the problem is syncop_open () does not send any
              dictionary (it will be NULL). We can make open-behind<br>
              check whether xdata is NULL and if so, consider that open
              call be generated internally (not from application) and
              wind it to the below xlator.</blockquote>
            <div><br>
            </div>
            <div>Hmm.. I am not too sure whether we can rely on the
              interpretation that xdata being&nbsp; NULL means to force open
              in open-behind. There definitely are/will be other
              use-cases of syncop-open where some might inadvertently
              leave xdata NULL. It always helps in terms of
              understandability, to be explicit on what we want to do.
              Can't you create an xdata in fuse fd migration code and
              pass that down to syncop-open?<br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    Whoever calls syncop_open does not send the xdata as the arugement
    at all. It will be like this.<br>
    ret = syncop_open (new_subvol, &amp;loc, flags, newfd);<br>
    <br>
    The syncop framework itself sends the xdata as NULL while winding
    the call (making syncop framework allocate a new dict before winding
    and send it as an argument also wont work in this case, as fuse wont
    be able to set any new key).<br>
    <blockquote
cite="mid:CADRNtgReSSVeSQKkqYnysJNAV5Pm57OiRxP8fPWBQLLEWUHFsA@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div>
              <br>
            </div>
            <blockquote class="gmail_quote" style="margin:0pt 0pt 0pt
              0.8ex;border-left:1px solid
              rgb(204,204,204);padding-left:1ex">
              <div class="HOEnZb">
                <div class="h5"><br>
                  <br>
                  <blockquote class="gmail_quote" style="margin:0 0 0
                    .8ex;border-left:1px #ccc solid;padding-left:1ex">
                    <br>
                    <blockquote class="gmail_quote" style="margin:0 0 0
                      .8ex;border-left:1px #ccc solid;padding-left:1ex">
                      Please provide feedback on the above issues.<br>
                      <br>
                      <br>
                      Regards,<br>
                      Raghavendra Bhat<br>
                      <br>
                      <br>
                      _______________________________________________<br>
                      Gluster-devel mailing list<br>
                      <a moz-do-not-send="true"
                        href="mailto:Gluster-devel@nongnu.org"
                        target="_blank">Gluster-devel@nongnu.org</a><br>
                      <a moz-do-not-send="true"
                        href="https://lists.nongnu.org/mailman/listinfo/gluster-devel"
                        target="_blank">https://lists.nongnu.org/mailman/listinfo/gluster-devel</a><br>
                      <br>
                    </blockquote>
                  </blockquote>
                  <br>
                  <br>
                  _______________________________________________<br>
                  Gluster-devel mailing list<br>
                  <a moz-do-not-send="true"
                    href="mailto:Gluster-devel@nongnu.org"
                    target="_blank">Gluster-devel@nongnu.org</a><br>
                  <a moz-do-not-send="true"
                    href="https://lists.nongnu.org/mailman/listinfo/gluster-devel"
                    target="_blank">https://lists.nongnu.org/mailman/listinfo/gluster-devel</a><br>
                </div>
              </div>
            </blockquote>
          </div>
          <br>
          <br clear="all">
          <br>
          -- <br>
          Raghavendra G<br>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>