1. 20 2月, 2023 4 次提交
  2. 10 12月, 2022 1 次提交
  3. 29 11月, 2022 1 次提交
  4. 27 9月, 2022 3 次提交
    • C
      SUNRPC: Parametrize how much of argsize should be zeroed · 103cc1fa
      Chuck Lever 提交于
      Currently, SUNRPC clears the whole of .pc_argsize before processing
      each incoming RPC transaction. Add an extra parameter to struct
      svc_procedure to enable upper layers to reduce the amount of each
      operation's argument structure that is zeroed by SUNRPC.
      
      The size of struct nfsd4_compoundargs, in particular, is a lot to
      clear on each incoming RPC Call. A subsequent patch will cut this
      down to something closer to what NFSv2 and NFSv3 uses.
      
      This patch should cause no behavior changes.
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      103cc1fa
    • C
      SUNRPC: Fix svcxdr_init_encode's buflen calculation · 1242a87d
      Chuck Lever 提交于
      Commit 2825a7f9 ("nfsd4: allow encoding across page boundaries")
      added an explicit computation of the remaining length in the rq_res
      XDR buffer.
      
      The computation appears to suffer from an "off-by-one" bug. Because
      buflen is too large by one page, XDR encoding can run off the end of
      the send buffer by eventually trying to use the struct page address
      in rq_page_end, which always contains NULL.
      
      Fixes: bddfdbcd ("NFSD: Extract the svcxdr_init_encode() helper")
      Reviewed-by: NJeff Layton <jlayton@kernel.org>
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      1242a87d
    • C
      SUNRPC: Fix svcxdr_init_decode's end-of-buffer calculation · 90bfc37b
      Chuck Lever 提交于
      Ensure that stream-based argument decoding can't go past the actual
      end of the receive buffer. xdr_init_decode's calculation of the
      value of xdr->end over-estimates the end of the buffer because the
      Linux kernel RPC server code does not remove the size of the RPC
      header from rqstp->rq_arg before calling the upper layer's
      dispatcher.
      
      The server-side still uses the svc_getnl() macros to decode the
      RPC call header. These macros reduce the length of the head iov
      but do not update the total length of the message in the buffer
      (buf->len).
      
      A proper fix for this would be to replace the use of svc_getnl() and
      friends in the RPC header decoder, but that would be a large and
      invasive change that would be difficult to backport.
      
      Fixes: 5191955d ("SUNRPC: Prepare for xdr_stream-style decoding on the server-side")
      Reviewed-by: NJeff Layton <jlayton@kernel.org>
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      90bfc37b
  5. 20 5月, 2022 2 次提交
  6. 07 4月, 2022 1 次提交
    • C
      SUNRPC: Fix NFSD's request deferral on RDMA transports · 773f91b2
      Chuck Lever 提交于
      Trond Myklebust reports an NFSD crash in svc_rdma_sendto(). Further
      investigation shows that the crash occurred while NFSD was handling
      a deferred request.
      
      This patch addresses two inter-related issues that prevent request
      deferral from working correctly for RPC/RDMA requests:
      
      1. Prevent the crash by ensuring that the original
         svc_rqst::rq_xprt_ctxt value is available when the request is
         revisited. Otherwise svc_rdma_sendto() does not have a Receive
         context available with which to construct its reply.
      
      2. Possibly since before commit 71641d99 ("svcrdma: Properly
         compute .len and .buflen for received RPC Calls"),
         svc_rdma_recvfrom() did not include the transport header in the
         returned xdr_buf. There should have been no need for svc_defer()
         and friends to save and restore that header, as of that commit.
         This issue is addressed in a backport-friendly way by simply
         having svc_rdma_recvfrom() set rq_xprt_hlen to zero
         unconditionally, just as svc_tcp_recvfrom() does. This enables
         svc_deferred_recv() to correctly reconstruct an RPC message
         received via RPC/RDMA.
      Reported-by: NTrond Myklebust <trondmy@hammerspace.com>
      Link: https://lore.kernel.org/linux-nfs/82662b7190f26fb304eb0ab1bb04279072439d4e.camel@hammerspace.com/Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      Cc: <stable@vger.kernel.org>
      773f91b2
  7. 28 2月, 2022 5 次提交
  8. 14 12月, 2021 7 次提交
    • N
      lockd: use svc_set_num_threads() for thread start and stop · 6b044fba
      NeilBrown 提交于
      svc_set_num_threads() does everything that lockd_start_svc() does, except
      set sv_maxconn.  It also (when passed 0) finds the threads and
      stops them with kthread_stop().
      
      So move the setting for sv_maxconn, and use svc_set_num_thread()
      
      We now don't need nlmsvc_task.
      
      Now that we use svc_set_num_threads() it makes sense to set svo_module.
      This request that the thread exists with module_put_and_exit().
      Also fix the documentation for svo_module to make this explicit.
      
      svc_prepare_thread is now only used where it is defined, so it can be
      made static.
      Signed-off-by: NNeilBrown <neilb@suse.de>
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      6b044fba
    • N
      SUNRPC: move the pool_map definitions (back) into svc.c · cf0e124e
      NeilBrown 提交于
      These definitions are not used outside of svc.c, and there is no
      evidence that they ever have been.  So move them into svc.c
      and make the declarations 'static'.
      Signed-off-by: NNeilBrown <neilb@suse.de>
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      cf0e124e
    • N
      SUNRPC: discard svo_setup and rename svc_set_num_threads_sync() · 3ebdbe52
      NeilBrown 提交于
      The ->svo_setup callback serves no purpose.  It is always called from
      within the same module that chooses which callback is needed.  So
      discard it and call the relevant function directly.
      
      Now that svc_set_num_threads() is no longer used remove it and rename
      svc_set_num_threads_sync() to remove the "_sync" suffix.
      Signed-off-by: NNeilBrown <neilb@suse.de>
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      3ebdbe52
    • N
      NFSD: Make it possible to use svc_set_num_threads_sync · 3409e4f1
      NeilBrown 提交于
      nfsd cannot currently use svc_set_num_threads_sync.  It instead
      uses svc_set_num_threads which does *not* wait for threads to all
      exit, and has a separate mechanism (nfsd_shutdown_complete) to wait
      for completion.
      
      The reason that nfsd is unlike other services is that nfsd threads can
      exit separately from svc_set_num_threads being called - they die on
      receipt of SIGKILL.  Also, when the last thread exits, the service must
      be shut down (sockets closed).
      
      For this, the nfsd_mutex needs to be taken, and as that mutex needs to
      be held while svc_set_num_threads is called, the one cannot wait for
      the other.
      
      This patch changes the nfsd thread so that it can drop the ref on the
      service without blocking on nfsd_mutex, so that svc_set_num_threads_sync
      can be used:
       - if it can drop a non-last reference, it does that.  This does not
         trigger shutdown and does not require a mutex.  This will likely
         happen for all but the last thread signalled, and for all threads
         being shut down by nfsd_shutdown_threads()
       - if it can get the mutex without blocking (trylock), it does that
         and then drops the reference.  This will likely happen for the
         last thread killed by SIGKILL
       - Otherwise there might be an unrelated task holding the mutex,
         possibly in another network namespace, or nfsd_shutdown_threads()
         might be just about to get a reference on the service, after which
         we can drop ours safely.
         We cannot conveniently get wakeup notifications on these events,
         and we are unlikely to need to, so we sleep briefly and check again.
      
      With this we can discard nfsd_shutdown_complete and
      nfsd_complete_shutdown(), and switch to svc_set_num_threads_sync.
      Signed-off-by: NNeilBrown <neilb@suse.de>
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      3409e4f1
    • N
      SUNRPC: stop using ->sv_nrthreads as a refcount · ec52361d
      NeilBrown 提交于
      The use of sv_nrthreads as a general refcount results in clumsy code, as
      is seen by various comments needed to explain the situation.
      
      This patch introduces a 'struct kref' and uses that for reference
      counting, leaving sv_nrthreads to be a pure count of threads.  The kref
      is managed particularly in svc_get() and svc_put(), and also nfsd_put();
      
      svc_destroy() now takes a pointer to the embedded kref, rather than to
      the serv.
      
      nfsd allows the svc_serv to exist with ->sv_nrhtreads being zero.  This
      happens when a transport is created before the first thread is started.
      To support this, a 'keep_active' flag is introduced which holds a ref on
      the svc_serv.  This is set when any listening socket is successfully
      added (unless there are running threads), and cleared when the number of
      threads is set.  So when the last thread exits, the nfs_serv will be
      destroyed.
      The use of 'keep_active' replaces previous code which checked if there
      were any permanent sockets.
      
      We no longer clear ->rq_server when nfsd() exits.  This was done
      to prevent svc_exit_thread() from calling svc_destroy().
      Instead we take an extra reference to the svc_serv to prevent
      svc_destroy() from being called.
      Signed-off-by: NNeilBrown <neilb@suse.de>
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      ec52361d
    • N
      SUNRPC/NFSD: clean up get/put functions. · 8c62d127
      NeilBrown 提交于
      svc_destroy() is poorly named - it doesn't necessarily destroy the svc,
      it might just reduce the ref count.
      nfsd_destroy() is poorly named for the same reason.
      
      This patch:
       - removes the refcount functionality from svc_destroy(), moving it to
         a new svc_put().  Almost all previous callers of svc_destroy() now
         call svc_put().
       - renames nfsd_destroy() to nfsd_put() and improves the code, using
         the new svc_destroy() rather than svc_put()
       - removes a few comments that explain the important for balanced
         get/put calls.  This should be obvious.
      
      The only non-trivial part of this is that svc_destroy() would call
      svc_sock_update() on a non-final decrement.  It can no longer do that,
      and svc_put() isn't really a good place of it.  This call is now made
      from svc_exit_thread() which seems like a good place.  This makes the
      call *before* sv_nrthreads is decremented rather than after.  This
      is not particularly important as the call just sets a flag which
      causes sv_nrthreads set be checked later.  A subsequent patch will
      improve the ordering.
      Signed-off-by: NNeilBrown <neilb@suse.de>
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      8c62d127
    • N
      SUNRPC: change svc_get() to return the svc. · df5e49c8
      NeilBrown 提交于
      It is common for 'get' functions to return the object that was 'got',
      and there are a couple of places where users of svc_get() would be a
      little simpler if svc_get() did that.
      
      Make it so.
      Signed-off-by: NNeilBrown <neilb@suse.de>
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      df5e49c8
  9. 13 10月, 2021 4 次提交
  10. 12 10月, 2021 1 次提交
  11. 03 10月, 2021 1 次提交
  12. 17 8月, 2021 2 次提交
  13. 11 8月, 2021 2 次提交
  14. 22 3月, 2021 1 次提交
    • C
      NFSD: Extract the svcxdr_init_encode() helper · bddfdbcd
      Chuck Lever 提交于
      NFSD initializes an encode xdr_stream only after the RPC layer has
      already inserted the RPC Reply header. Thus it behaves differently
      than xdr_init_encode does, which assumes the passed-in xdr_buf is
      entirely devoid of content.
      
      nfs4proc.c has this server-side stream initialization helper, but
      it is visible only to the NFSv4 code. Move this helper to a place
      that can be accessed by NFSv2 and NFSv3 server XDR functions.
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      bddfdbcd
  15. 25 1月, 2021 1 次提交
  16. 01 12月, 2020 2 次提交
    • C
      SUNRPC: Prepare for xdr_stream-style decoding on the server-side · 5191955d
      Chuck Lever 提交于
      A "permanent" struct xdr_stream is allocated in struct svc_rqst so
      that it is usable by all server-side decoders. A per-rqst scratch
      buffer is also allocated to handle decoding XDR data items that
      cross page boundaries.
      
      To demonstrate how it will be used, add the first call site for the
      new svcxdr_init_decode() API.
      
      As an additional part of the overall conversion, add symbolic
      constants for successful and failed XDR operations. Returning "0" is
      overloaded. Sometimes it means something failed, but sometimes it
      means success. To make it more clear when XDR decoding functions
      succeed or fail, introduce symbolic constants.
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      5191955d
    • C
      SUNRPC: Rename svc_encode_read_payload() · 03493bca
      Chuck Lever 提交于
      Clean up: "result payload" is a less confusing name for these
      payloads. "READ payload" reflects only the NFS usage.
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      03493bca
  17. 21 5月, 2020 1 次提交
    • C
      SUNRPC: Refactor svc_recvfrom() · ca07eda3
      Chuck Lever 提交于
      This function is not currently "generic" so remove the documenting
      comment and rename it appropriately. Its internals are converted to
      use bio_vecs for reading from the transport socket.
      
      In existing typical sunrpc uses of bio_vecs, the bio_vec array is
      allocated dynamically. Here, instead, an array of bio_vecs is added
      to svc_rqst. The lifetime of this array can be greater than one call
      to xpo_recvfrom():
      
      - Multiple calls to xpo_recvfrom() might be needed to read an RPC
        message completely.
      
      - At some later point, rq_arg.bvecs will point to this array and it
        will carry the received message into svc_process().
      
      I also expect that a future optimization will remove either the
      rq_vec or rq_pages array in favor of rq_bvec, thus conserving the
      size of struct svc_rqst.
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      ca07eda3
  18. 09 5月, 2020 1 次提交
    • J
      nfsd: clients don't need to break their own delegations · 28df3d15
      J. Bruce Fields 提交于
      We currently revoke read delegations on any write open or any operation
      that modifies file data or metadata (including rename, link, and
      unlink).  But if the delegation in question is the only read delegation
      and is held by the client performing the operation, that's not really
      necessary.
      
      It's not always possible to prevent this in the NFSv4.0 case, because
      there's not always a way to determine which client an NFSv4.0 delegation
      came from.  (In theory we could try to guess this from the transport
      layer, e.g., by assuming all traffic on a given TCP connection comes
      from the same client.  But that's not really correct.)
      
      In the NFSv4.1 case the session layer always tells us the client.
      
      This patch should remove such self-conflicts in all cases where we can
      reliably determine the client from the compound.
      
      To do that we need to track "who" is performing a given (possibly
      lease-breaking) file operation.  We're doing that by storing the
      information in the svc_rqst and using kthread_data() to map the current
      task back to a svc_rqst.
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      28df3d15