linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@redhat.com>
To: Olga Kornievskaia <aglo@umich.edu>
Cc: Olga Kornievskaia <kolga@netapp.com>,
	linux-nfs <linux-nfs@vger.kernel.org>
Subject: Re: [PATCH v6 08/10] NFSD handle OFFLOAD_CANCEL op
Date: Fri, 16 Feb 2018 13:10:36 -0500	[thread overview]
Message-ID: <20180216181035.GA2623@parsley.fieldses.org> (raw)
In-Reply-To: <CAN-5tyFugGyOj0HXjOOzRsPz5HR=X45AJNa9W7YrM9Uo77riFg@mail.gmail.com>

On Fri, Feb 16, 2018 at 12:28:19PM -0500, Olga Kornievskaia wrote:
> On Tue, Oct 24, 2017 at 1:47 PM, Olga Kornievskaia <kolga@netapp.com> wrote:
> > Upon receiving OFFLOAD_CANCEL search the list of copy stateids,
> > if found then set the SIGPENDING signal so that do_splice stops
> > copying and also send kthread_stop to the copy thread to stop
> > and wait for it. Take a reference on the copy from the
> > offload_cancel thread so that it won't go away while we are
> > trying to process it. Server won't be sending CB_OFFLOAD to the
> > client since it received a cancel.
> >
> > Signed-off-by: Olga Kornievskaia <kolga@netapp.com>
> > ---
> >  fs/nfsd/nfs4proc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
> >  fs/nfsd/xdr4.h     |  1 +
> >  2 files changed, 45 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
> > index 6876080..3b0bb54 100644
> > --- a/fs/nfsd/nfs4proc.c
> > +++ b/fs/nfsd/nfs4proc.c
> > @@ -1097,6 +1097,14 @@ static int fill_in_write_vector(struct kvec *vec, struct nfsd4_write *write)
> >  out:
> >         return status;
> >  }
> > +
> > +static void nfs4_put_copy(struct nfsd4_copy *copy)
> > +{
> > +       if (!atomic_dec_and_test(&copy->refcount))
> > +               return;
> > +       kfree(copy);
> > +}
> > +
> >  static void nfsd4_cb_offload_release(struct nfsd4_callback *cb)
> >  {
> >         struct nfsd4_copy *copy = container_of(cb, struct nfsd4_copy, cp_cb);
> > @@ -1134,6 +1142,8 @@ static int _nfsd_copy_file_range(struct nfsd4_copy *copy)
> >         u64 dst_pos = copy->cp_dst_pos;
> >
> >         do {
> > +               if (signalled() || kthread_should_stop())
> > +                       return -1;
> >                 bytes_copied = nfsd_copy_file_range(copy->fh_src, src_pos,
> >                                 copy->fh_dst, dst_pos, bytes_total);
> >                 if (bytes_copied <= 0)
> > @@ -1152,11 +1162,16 @@ static int nfsd4_do_copy(struct nfsd4_copy *copy, bool sync)
> >         ssize_t bytes;
> >
> >         bytes = _nfsd_copy_file_range(copy);
> > +       if (signalled() || kthread_should_stop()) {
> > +               status = -1;
> > +               goto cleanup;
> > +       }
> >         if (bytes < 0 && !copy->cp_res.wr_bytes_written)
> >                 status = nfserrno(bytes);
> >         else
> >                 status = nfsd4_init_copy_res(copy, sync);
> >
> > +cleanup:
> >         fput(copy->fh_src);
> >         fput(copy->fh_dst);
> >         return status;
> > @@ -1194,7 +1209,7 @@ static void cleanup_async_copy(struct nfsd4_copy *copy)
> >         list_del(&copy->copies);
> >         spin_unlock(&copy->cp_clp->async_lock);
> >         atomic_dec(&copy->cp_clp->cl_refcount);
> > -       kfree(copy);
> > +       nfs4_put_copy(copy);
> >  }
> >
> >  static int nfsd4_do_async_copy(void *data)
> > @@ -1203,6 +1218,9 @@ static int nfsd4_do_async_copy(void *data)
> >         struct nfsd4_copy *cb_copy;
> >
> >         copy->nfserr = nfsd4_do_copy(copy, 0);
> > +       if (signalled() || kthread_should_stop())
> > +               goto out;
> > +
> >         cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
> >         if (!cb_copy)
> >                 goto out;
> > @@ -1259,6 +1277,7 @@ static int nfsd4_do_async_copy(void *data)
> >                 memcpy(&copy->cp_res.cb_stateid, &copy->cps->cp_stateid,
> >                         sizeof(copy->cps->cp_stateid));
> >                 dup_copy_fields(copy, async_copy);
> > +               atomic_set(&async_copy->refcount, 1);
> >                 spin_lock(&async_copy->cp_clp->async_lock);
> >                 list_add(&async_copy->copies,
> >                                 &async_copy->cp_clp->async_copies);
> > @@ -1285,7 +1304,30 @@ static int nfsd4_do_async_copy(void *data)
> >                      struct nfsd4_compound_state *cstate,
> >                      union nfsd4_op_u *u)
> >  {
> > -       return 0;
> > +       struct nfsd4_offload_status *os = &u->offload_status;
> > +       __be32 status = 0;
> > +       struct nfsd4_copy *copy;
> > +       bool found = false;
> > +       struct nfs4_client *clp = cstate->clp;
> > +
> > +       spin_lock(&clp->async_lock);
> > +       list_for_each_entry(copy, &clp->async_copies, copies) {
> > +               if (memcmp(&copy->cps->cp_stateid, &os->stateid,
> > +                               NFS4_STATEID_SIZE))
> > +                       continue;
> > +               found = true;
> > +               atomic_inc(&copy->refcount);
> > +               break;
> > +       }
> > +       spin_unlock(&clp->async_lock);
> > +       if (found) {
> > +               set_tsk_thread_flag(copy->copy_task, TIF_SIGPENDING);
> > +               kthread_stop(copy->copy_task);
> > +               nfs4_put_copy(copy);
> > +       } else
> > +               status = nfserr_bad_stateid;
> > +
> > +       return status;
> >  }
> >
> >  static __be32
> > diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
> > index 27bac6a..3127b58 100644
> > --- a/fs/nfsd/xdr4.h
> > +++ b/fs/nfsd/xdr4.h
> > @@ -540,6 +540,7 @@ struct nfsd4_copy {
> >
> >         struct list_head        copies;
> >         struct task_struct      *copy_task;
> > +       atomic_t                refcount;
> 
> Hi Bruce,
> 
> Is the code moving away from using atomic_t and using refcount_t
> instead. Should I be changing this as well?

Yeah, that would be a good idea, thanks.

--b.

  reply	other threads:[~2018-02-16 18:10 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-24 17:47 [PATCH v6 00/10] NFSD support for asynchronous COPY Olga Kornievskaia
2017-10-24 17:47 ` [PATCH v6 01/10] NFSD CB_OFFLOAD xdr Olga Kornievskaia
2018-01-25 16:43   ` J. Bruce Fields
2018-01-26 15:16     ` Olga Kornievskaia
2017-10-24 17:47 ` [PATCH v6 02/10] NFSD OFFLOAD_STATUS xdr Olga Kornievskaia
2017-10-24 17:47 ` [PATCH v6 03/10] NFSD OFFLOAD_CANCEL xdr Olga Kornievskaia
2017-10-24 17:47 ` [PATCH v6 04/10] NFSD xdr callback stateid in async COPY reply Olga Kornievskaia
2017-10-24 17:47 ` [PATCH v6 05/10] NFSD first draft of async copy Olga Kornievskaia
2018-01-25 22:04   ` J. Bruce Fields
2018-01-26 15:17     ` Olga Kornievskaia
2018-02-15 19:59     ` Olga Kornievskaia
2018-02-15 20:06       ` J. Bruce Fields
2018-01-25 22:29   ` J. Bruce Fields
2018-01-26 15:17     ` Olga Kornievskaia
2018-01-26 21:34   ` J. Bruce Fields
2018-02-02 19:50     ` Olga Kornievskaia
2018-02-02 19:55       ` J. Bruce Fields
2017-10-24 17:47 ` [PATCH v6 06/10] NFSD return nfs4_stid in nfs4_preprocess_stateid_op Olga Kornievskaia
2017-10-24 17:47 ` [PATCH v6 07/10] NFSD create new stateid for async copy Olga Kornievskaia
2018-01-26 21:37   ` J. Bruce Fields
2018-01-26 21:59   ` J. Bruce Fields
2018-02-02 20:45     ` Olga Kornievskaia
2018-02-02 21:45       ` J. Bruce Fields
2018-02-15 22:18         ` Olga Kornievskaia
2018-02-16  1:43           ` J. Bruce Fields
2018-02-16 16:06             ` Olga Kornievskaia
2018-02-16 18:12               ` J. Bruce Fields
2018-02-16 20:53                 ` Olga Kornievskaia
2018-02-20 18:48                   ` J. Bruce Fields
2018-03-06 17:15                     ` Olga Kornievskaia
2018-03-06 19:33                       ` J. Bruce Fields
2017-10-24 17:47 ` [PATCH v6 08/10] NFSD handle OFFLOAD_CANCEL op Olga Kornievskaia
2018-02-16 17:28   ` Olga Kornievskaia
2018-02-16 18:10     ` J. Bruce Fields [this message]
2017-10-24 17:47 ` [PATCH v6 09/10] NFSD support OFFLOAD_STATUS Olga Kornievskaia
2017-10-24 17:47 ` [PATCH v6 10/10] NFSD stop queued async copies on client shutdown Olga Kornievskaia
2018-01-25 22:22   ` J. Bruce Fields
2018-01-26 15:17     ` Olga Kornievskaia
2017-11-03 19:57 ` [PATCH v6 00/10] NFSD support for asynchronous COPY Olga Kornievskaia
2017-11-10 15:01   ` Olga Kornievskaia
2017-11-14  0:48     ` J. Bruce Fields
2017-11-28 20:28       ` Olga Kornievskaia
2017-11-30 20:18         ` J. Bruce Fields
2017-11-30 23:03           ` Olga Kornievskaia
2017-12-04 21:32             ` J. Bruce Fields
     [not found]               ` <CAN-5tyEVSwBmPMtUBJYDdLi7FK2MNMGuDQrrsvp776zD3Jcw0w@mail.gmail.com>
2018-01-22 16:51                 ` Olga Kornievskaia
2018-01-25 22:33                   ` J. Bruce Fields
2018-01-26 15:16                     ` Olga Kornievskaia

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180216181035.GA2623@parsley.fieldses.org \
    --to=bfields@redhat.com \
    --cc=aglo@umich.edu \
    --cc=kolga@netapp.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).