26 Sep, 2018

1 commit

  • Upon receiving a request for async copy, create a new kthread. If we
    get asynchronous request, make sure to copy the needed arguments/state
    from the stack before starting the copy. Then start the thread and reply
    back to the client indicating copy is asynchronous.

    nfsd_copy_file_range() will copy in a loop over the total number of
    bytes is needed to copy. In case a failure happens in the middle, we
    ignore the error and return how much we copied so far. Once done
    creating a workitem for the callback workqueue and send CB_OFFLOAD with
    the results.

    The lifetime of the copy stateid is bound to the vfs copy. This way we
    don't need to keep the nfsd_net structure for the callback. We could
    keep it around longer so that an OFFLOAD_STATUS that came late would
    still get results, but clients should be able to deal without that.

    We handle OFFLOAD_CANCEL by sending a signal to the copy thread and
    calling kthread_stop.

    A client should cancel any ongoing copies before calling DESTROY_CLIENT;
    if not, we return a CLIENT_BUSY error.

    If the client is destroyed for some other reason (lease expiration, or
    server shutdown), we must clean up any ongoing copies ourselves.

    Signed-off-by: Olga Kornievskaia
    [colin.king@canonical.com: fix leak in error case]
    [bfields@fieldses.org: remove signalling, merge patches]
    Signed-off-by: J. Bruce Fields

    Olga Kornievskaia
     

17 Jun, 2018

1 commit

  • If the client is only renewing state a little sooner than once a lease
    period, then it might not discover the server has restarted till close
    to the end of the grace period, and might run out of time to do the
    actual reclaim.

    Extend the grace period by a second each time we notice there are
    clients still trying to reclaim, up to a limit of another whole lease
    period.

    Signed-off-by: J. Bruce Fields

    J. Bruce Fields
     

28 Nov, 2017

1 commit

  • nfsd_inet[6]addr_event uses nn->nfsd_serv without taking nfsd_mutex,
    which can be changed during execution of notifiers and crash the host.

    Moreover if notifiers were enabled in one net namespace they are enabled
    in all other net namespaces, from creation until destruction.

    This patch allows notifiers to access nn->nfsd_serv only after the
    pointer is correctly initialized and delays cleanup until notifiers are
    no longer in use.

    Signed-off-by: Vasily Averin
    Tested-by: Scott Mayhew
    Signed-off-by: J. Bruce Fields

    Vasily Averin
     

08 Nov, 2017

1 commit

  • do_gettimeofday() is deprecated and we should generally use time64_t
    based functions instead.

    In case of nfsd, all three users of nfssvc_boot only use the initial
    time as a unique token, and are not affected by it overflowing, so they
    are not affected by the y2038 overflow.

    This converts the structure to timespec64 anyway and adds comments
    to all uses, to document that we have thought about it and avoid
    having to look at it again.

    Signed-off-by: Arnd Bergmann
    Signed-off-by: J. Bruce Fields

    Arnd Bergmann
     

18 Nov, 2016

1 commit

  • Make struct pernet_operations::id unsigned.

    There are 2 reasons to do so:

    1)
    This field is really an index into an zero based array and
    thus is unsigned entity. Using negative value is out-of-bound
    access by definition.

    2)
    On x86_64 unsigned 32-bit data which are mixed with pointers
    via array indexing or offsets added or subtracted to pointers
    are preffered to signed 32-bit data.

    "int" being used as an array index needs to be sign-extended
    to 64-bit before being used.

    void f(long *p, int i)
    {
    g(p[i]);
    }

    roughly translates to

    movsx rsi, esi
    mov rdi, [rsi+...]
    call g

    MOVSX is 3 byte instruction which isn't necessary if the variable is
    unsigned because x86_64 is zero extending by default.

    Now, there is net_generic() function which, you guessed it right, uses
    "int" as an array index:

    static inline void *net_generic(const struct net *net, int id)
    {
    ...
    ptr = ng->ptr[id - 1];
    ...
    }

    And this function is used a lot, so those sign extensions add up.

    Patch snipes ~1730 bytes on allyesconfig kernel (without all junk
    messing with code generation):

    add/remove: 0/0 grow/shrink: 70/598 up/down: 396/-2126 (-1730)

    Unfortunately some functions actually grow bigger.
    This is a semmingly random artefact of code generation with register
    allocator being used differently. gcc decides that some variable
    needs to live in new r8+ registers and every access now requires REX
    prefix. Or it is shifted into r12, so [r12+0] addressing mode has to be
    used which is longer than [r8]

    However, overall balance is in negative direction:

    add/remove: 0/0 grow/shrink: 70/598 up/down: 396/-2126 (-1730)
    function old new delta
    nfsd4_lock 3886 3959 +73
    tipc_link_build_proto_msg 1096 1140 +44
    mac80211_hwsim_new_radio 2776 2808 +32
    tipc_mon_rcv 1032 1058 +26
    svcauth_gss_legacy_init 1413 1429 +16
    tipc_bcbase_select_primary 379 392 +13
    nfsd4_exchange_id 1247 1260 +13
    nfsd4_setclientid_confirm 782 793 +11
    ...
    put_client_renew_locked 494 480 -14
    ip_set_sockfn_get 730 716 -14
    geneve_sock_add 829 813 -16
    nfsd4_sequence_done 721 703 -18
    nlmclnt_lookup_host 708 686 -22
    nfsd4_lockt 1085 1063 -22
    nfs_get_client 1077 1050 -27
    tcf_bpf_init 1106 1076 -30
    nfsd4_encode_fattr 5997 5930 -67
    Total: Before=154856051, After=154854321, chg -0.00%

    Signed-off-by: Alexey Dobriyan
    Signed-off-by: David S. Miller

    Alexey Dobriyan
     

25 Oct, 2016

1 commit

  • Bruce was hitting some lockdep warnings in testing, showing that we
    could hit a deadlock with the new CB_NOTIFY_LOCK handling, involving a
    rather complex situation involving four different spinlocks.

    The crux of the matter is that we end up taking the nn->client_lock in
    the lm_notify handler. The simplest fix is to just declare a new
    per-nfsd_net spinlock to protect the new CB_NOTIFY_LOCK structures.

    Signed-off-by: Jeff Layton
    Signed-off-by: J. Bruce Fields

    Jeff Layton
     

27 Sep, 2016

1 commit

  • It's possible for a client to call in on a lock that is blocked for a
    long time, but discontinue polling for it. A malicious client could
    even set a lock on a file, and then spam the server with failing lock
    requests from different lockowners that pile up in a DoS attack.

    Add the blocked lock structures to a per-net namespace LRU when hashing
    them, and timestamp them. If the lock request is not revisited after a
    lease period, we'll drop it under the assumption that the client is no
    longer interested.

    This also gives us a mechanism to clean up these objects at server
    shutdown time as well.

    Signed-off-by: Jeff Layton
    Signed-off-by: J. Bruce Fields

    Jeff Layton
     

24 Nov, 2015

1 commit


11 Aug, 2015

1 commit

  • If using clientid_counter, it seems possible that gen_confirm could
    generate the same verifier for the same client in some situations.

    Add a new counter for client confirm verifier to make sure gen_confirm
    generates a different verifier on each call for the same clientid.

    Signed-off-by: Kinglong Mee
    Reviewed-by: Jeff Layton
    Signed-off-by: J. Bruce Fields

    Kinglong Mee
     

06 Aug, 2014

1 commit


05 Aug, 2014

1 commit

  • The clid counter is a global counter currently. Move it to be a per-net
    property so that it can be properly protected by the nn->client_lock
    instead of relying on the client_mutex.

    The verifier generator is also potentially racy if there are two
    simultaneous callers. Generate the verifier when we generate the clid
    value, so it's also created under the client_lock. With this, there's
    no need to keep two counters as they'd always be in sync anyway, so
    just use the clientid_counter for both.

    As Trond points out, what would be best is to eventually move this
    code to use IDR instead of the hash tables. That would also help ensure
    uniqueness, but that's probably best done as a separate project.

    Signed-off-by: Jeff Layton
    Signed-off-by: J. Bruce Fields

    Jeff Layton
     

01 Aug, 2014

1 commit


10 Jul, 2014

1 commit


09 Jul, 2014

1 commit

  • Currently, the maximum number of connections that nfsd will allow
    is based on the number of threads spawned. While this is fine for a
    default, there really isn't a clear relationship between the two.

    The number of threads corresponds to the number of concurrent requests
    that we want to allow the server to process at any given time. The
    connection limit corresponds to the maximum number of clients that we
    want to allow the server to handle. These are two entirely different
    quantities.

    Break the dependency on increasing threads in order to allow for more
    connections, by adding a new per-net parameter that can be set to a
    non-zero value. The default is still to base it on the number of threads,
    so there should be no behavior change for anyone who doesn't use it.

    Cc: Trond Myklebust
    Signed-off-by: Jeff Layton
    Signed-off-by: J. Bruce Fields

    Jeff Layton
     

04 Jan, 2014

1 commit


05 Apr, 2013

1 commit


11 Dec, 2012

4 commits

  • This patch makes main step in NFSd containerisation.

    There could be different approaches to how to make NFSd able to handle
    incoming RPC request from different network namespaces. The two main
    options are:

    1) Share NFSd kthreads betwween all network namespaces.
    2) Create separated pool of threads for each namespace.

    While first approach looks more flexible, second one is simpler and
    non-racy. This patch implements the second option.

    To make it possible to allocate separate pools of threads, we have to
    make it possible to allocate separate NFSd service structures per net.

    Signed-off-by: Stanislav Kinsbursky
    Signed-off-by: J. Bruce Fields

    Stanislav Kinsbursky
     
  • This is simple: an NFSd service can be started at different times in
    different network environments. So, its "boot time" has to be assigned
    per net.

    Signed-off-by: Stanislav Kinsbursky
    Signed-off-by: J. Bruce Fields

    Stanislav Kinsbursky
     
  • This patch introduces introduces per-net "nfsd_net_up" boolean flag, which has
    the same purpose as general "nfsd_up" flag - skip init or shutdown of per-net
    resources in case of they are inited on shutted down respectively.

    Signed-off-by: Stanislav Kinsbursky
    Signed-off-by: J. Bruce Fields

    Stanislav Kinsbursky
     
  • Pointer to client tracking operations - client_tracking_ops - have to be
    containerized, because different environment can support different trackers
    (for example, legacy tracker currently is not suported in container).

    Signed-off-by: Stanislav Kinsbursky
    Signed-off-by: J. Bruce Fields

    Stanislav Kinsbursky
     

03 Dec, 2012

1 commit

  • I added in a generic for-each loop that takes a pass over the client_lru
    list for the current net namespace and calls some function. The next few
    patches will update other operations to use this function as well. A value
    of 0 still means "forget everything that is found".

    Signed-off-by: Bryan Schumaker
    Signed-off-by: J. Bruce Fields

    Bryan Schumaker
     

28 Nov, 2012

5 commits


15 Nov, 2012

11 commits

  • This patch moves laundromat_work to nfsd per-net context, thus allowing to run
    multiple laundries.

    Signed-off-by: Stanislav Kinsbursky
    Signed-off-by: J. Bruce Fields

    Stanislav Kinsbursky
     
  • This list holds nfs4 clients (open) stateowner queue for last close replay,
    which are network namespace aware. So let's make this list per network
    namespace too.

    Signed-off-by: Stanislav Kinsbursky
    Signed-off-by: J. Bruce Fields

    Stanislav Kinsbursky
     
  • This list holds nfs4 clients queue for lease renewal, which are network
    namespace aware. So let's make this list per network namespace too.

    Signed-off-by: Stanislav Kinsbursky
    Signed-off-by: J. Bruce Fields

    Stanislav Kinsbursky
     
  • This hash holds established sessions state and closely associated with
    nfs4_clients info, which are network namespace aware. So let's make it
    allocated per network namespace too.

    Note: this hash can be allocated in per-net operations. But it looks
    better to allocate it on nfsd state start and thus don't waste resources
    if server is not running.

    Signed-off-by: Stanislav Kinsbursky
    Signed-off-by: J. Bruce Fields

    Stanislav Kinsbursky
     
  • This hash holds file lock owners and closely associated with nfs4_clients info,
    which are network namespace aware. So let's make it allocated per network
    namespace too.

    Note: this hash can be allocated in per-net operations. But it looks
    better to allocate it on nfsd state start and thus don't waste resources
    if server is not running.

    Signed-off-by: Stanislav Kinsbursky
    Signed-off-by: J. Bruce Fields

    Stanislav Kinsbursky
     
  • This hash holds open owner state and closely associated with nfs4_clients
    info, which are network namespace aware. So let's make it allocated per
    network namespace too.

    Note: this hash can be allocated in per-net operations. But it looks
    better to allocate it on nfsd state start and thus don't waste resources
    if server is not running.

    Signed-off-by: Stanislav Kinsbursky
    Signed-off-by: J. Bruce Fields

    Stanislav Kinsbursky
     
  • This hash holds nfs4_clients info, which are network namespace aware.
    So let's make it allocated per network namespace.

    Signed-off-by: Stanislav Kinsbursky
    Signed-off-by: J. Bruce Fields

    Stanislav Kinsbursky
     
  • This hash holds nfs4_clients info, which are network namespace aware.
    So let's make it allocated per network namespace.

    Note: this hash can be allocated in per-net operations. But it looks
    better to allocate it on nfsd state start and thus don't waste resources
    if server is not running.

    Signed-off-by: Stanislav Kinsbursky
    Signed-off-by: J. Bruce Fields

    Stanislav Kinsbursky
     
  • This tree holds nfs4_clients info, which are network namespace aware.
    So let's make it per network namespace.

    Signed-off-by: Stanislav Kinsbursky
    Signed-off-by: J. Bruce Fields

    Stanislav Kinsbursky
     
  • This hash holds nfs4_clients info, which are network namespace aware.
    So let's make it allocated per network namespace.

    Note: this hash can be allocated in per-net operations. But it looks
    better to allocate it on nfsd state start and thus don't waste resources
    if server is not running.

    Signed-off-by: Stanislav Kinsbursky
    Signed-off-by: J. Bruce Fields

    Stanislav Kinsbursky
     
  • This hash holds nfs4_clients info, which are network namespace aware.
    So let's make it allocated per network namespace.

    Note: this hash is used only by legacy tracker. So let's allocate hash in
    tracker init.

    Signed-off-by: Stanislav Kinsbursky
    Signed-off-by: J. Bruce Fields

    Stanislav Kinsbursky
     

28 Jul, 2012

3 commits