Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2171607yba; Thu, 25 Apr 2019 11:49:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqyK/6rtxLvJx1Om3Q2vCNmgJ0XwXloLTYnHXvNQti+Agx19dAnMbuCIPtfT1dM9B9vLjS3e X-Received: by 2002:a65:5148:: with SMTP id g8mr3831375pgq.168.1556218142857; Thu, 25 Apr 2019 11:49:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556218142; cv=none; d=google.com; s=arc-20160816; b=r8IBDtdIzGaiT8AMR0hUo6NnBj3pIjioXefPiAVeHvrTQoN1+Gq/FaNTOO7Dw83dGn iOW/Qo3x4xM5EprFzfNat5V/zmC1Hsr2Tdv4n2GvAEcc2G+a8JIl3kqa5Q8+TPk61eVu WODTLss0PCb0jiQY0vFBanqWX5DUg/+00Ev/1mYma6cnb9koEoWmWfdJdR/wV7IYSWsA wgF6LNv6ZxYqCunvE7fphFCFtEcJ6rVav9fYa9l61GAJ5lTOcyZIIoQ5wlaSLDrLv448 Go+r7TmJFTgoBkemro9hONLOoJYHL3uCJ3xXfglm/vDaMJSa2e0MTFrYtVpMVKBjl9B5 6uRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=ldpRpgCWBKKVSKykR5KEInYM/UNI+DvkAvjxNm2Zw14=; b=zvqSlg3e7tAjThnIuOUSBQmyncem0LfqXffw8WEGNZ0Y9Nexs1NN1DhDaTSy2A03YM zO2ukcvpKITwu/7i09yJLYRkrRrrF1CIOJSQYEiYROo3glBp+STzml0XpTvNLZxjspQh EcPBZEN7aM/IlLOw+OJEy0RI4sJeRQ8e9RWSKpdFYAdNWJ3jCFWEaL6sJz+SOueXcA6h KJ3QlQ6EhdpiEfvLZRP+yh+O/zzQHRWOY9f4pR0UmdUAHMV/xJIoq/Ruxm69Yx4P5zLP 9SpAcFc2qEUdXGklCED5/Vjq8XSvJZXTLniPRn3CcufRC1zDV/6WfNQDyk1U+Wbi7x5k lWVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e3si23347578pfn.164.2019.04.25.11.48.39; Thu, 25 Apr 2019 11:49:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730231AbfDYSFD (ORCPT + 99 others); Thu, 25 Apr 2019 14:05:03 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:44904 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730225AbfDYSFD (ORCPT ); Thu, 25 Apr 2019 14:05:03 -0400 Received: by mail-qt1-f193.google.com with SMTP id s10so1093292qtc.11 for ; Thu, 25 Apr 2019 11:05:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=ldpRpgCWBKKVSKykR5KEInYM/UNI+DvkAvjxNm2Zw14=; b=UTCC9CXONfRbhRI+QHdGMIgETON+MV6NoFnq3Bf8Ww68kDXZ2DskOP6veFvvWNT9Tp wDTYOQ4xvF/4v3eCPR3Wb4x4Dszhx7oVDzFNnLbVvzFEqDUMeP6Jd+8Sk2NFVxkqqRcC VOnZt1ZREGI21Ewl0PSSxEzM4nWbz7viYSrkEkn/4pFRhX2Kge7KmlNiHFII/RatZ/8/ hVaqmlu9Bpo1F3GPwQrH2j7ns38m4QLGmMq+RduWe6Z+cLjYscTkFxNVQAC4Qz4CRPUy YfYlq/N7+C8r/tl+t4v8RxM6rva1suNYgSl7TM/XVhlw4ekdF8liHona6c7B5mywPGYw FlEA== X-Gm-Message-State: APjAAAWwgAAtf0J6/M2tUc8XYfKg4vdMUw3w7elf3ZS3i15O8KbM5YAc TuWzpOX9mp6sfSkRpA3F+2U9OA== X-Received: by 2002:a0c:fe69:: with SMTP id b9mr6896606qvv.11.1556215501674; Thu, 25 Apr 2019 11:05:01 -0700 (PDT) Received: from tleilax.poochiereds.net (cpe-2606-A000-1100-202A-0-0-0-83B.dyn6.twc.com. [2606:a000:1100:202a::83b]) by smtp.gmail.com with ESMTPSA id w58sm10649429qtw.93.2019.04.25.11.05.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Apr 2019 11:05:01 -0700 (PDT) Message-ID: Subject: Re: [PATCH 08/10] nfsd4: add file to display list of client's opens From: Jeff Layton To: "J. Bruce Fields" , linux-nfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, abe@purdue.edu, lsof-l@lists.purdue.edu, util-linux@vger.kernel.org Date: Thu, 25 Apr 2019 14:04:59 -0400 In-Reply-To: <1556201060-7947-9-git-send-email-bfields@redhat.com> References: <1556201060-7947-1-git-send-email-bfields@redhat.com> <1556201060-7947-9-git-send-email-bfields@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5 (3.30.5-1.fc29) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Thu, 2019-04-25 at 10:04 -0400, J. Bruce Fields wrote: > From: "J. Bruce Fields" > > Add a nfsd/clients/#/opens file to list some information about all the > opens held by the given client. > > Signed-off-by: J. Bruce Fields > --- > fs/nfsd/nfs4state.c | 100 +++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 98 insertions(+), 2 deletions(-) > > diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c > index 928705fc8ff5..829d1e5440d3 100644 > --- a/fs/nfsd/nfs4state.c > +++ b/fs/nfsd/nfs4state.c > @@ -684,7 +684,8 @@ struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, struct kmem_cache *sla > > idr_preload(GFP_KERNEL); > spin_lock(&cl->cl_lock); > - new_id = idr_alloc_cyclic(&cl->cl_stateids, stid, 0, 0, GFP_NOWAIT); > + /* Reserving 0 for start of file in nfsdfs "opens" file: */ > + new_id = idr_alloc_cyclic(&cl->cl_stateids, stid, 1, 0, GFP_NOWAIT); > spin_unlock(&cl->cl_lock); > idr_preload_end(); > if (new_id < 0) > @@ -2223,9 +2224,104 @@ static const struct file_operations client_info_fops = { > .release = single_release, > }; > > +static void *opens_start(struct seq_file *s, loff_t *pos) > + __acquires(&clp->cl_lock) > +{ > + struct nfs4_client *clp = s->private; > + unsigned long id = *pos; > + void *ret; > + > + spin_lock(&clp->cl_lock); > + ret = idr_get_next_ul(&clp->cl_stateids, &id); > + *pos = id; > + return ret; > +} > + > +static void *opens_next(struct seq_file *s, void *v, loff_t *pos) > +{ > + struct nfs4_client *clp = s->private; > + unsigned long id = *pos; > + void *ret; > + > + id = *pos; > + id++; > + ret = idr_get_next_ul(&clp->cl_stateids, &id); > + *pos = id; > + return ret; > +} > + > +static void opens_stop(struct seq_file *s, void *v) > + __releases(&clp->cl_lock) > +{ > + struct nfs4_client *clp = s->private; > + > + spin_unlock(&clp->cl_lock); > +} > + > +static int opens_show(struct seq_file *s, void *v) > +{ > + struct nfs4_stid *st = v; > + struct nfs4_ol_stateid *os; > + u64 stateid; > + > + if (st->sc_type != NFS4_OPEN_STID) > + return 0; /* XXX: or SEQ_SKIP? */ > + os = openlockstateid(st); > + /* XXX: get info about file, etc., here */ > + > + memcpy(&stateid, &st->sc_stateid, sizeof(stateid)); > + seq_printf(s, "stateid: %llx\n", stateid); > + return 0; > +} More bikeshedding: should we have a "states" file instead of an "opens" file and print a different set of output for each stateid type? > + > +static struct seq_operations opens_seq_ops = { > + .start = opens_start, > + .next = opens_next, > + .stop = opens_stop, > + .show = opens_show > +}; > + > +static int client_opens_open(struct inode *inode, struct file *file) > +{ > + struct nfsdfs_client *nc; > + struct seq_file *s; > + struct nfs4_client *clp; > + int ret; > + > + nc = get_nfsdfs_client(inode); > + if (!nc) > + return -ENXIO; > + clp = container_of(nc, struct nfs4_client, cl_nfsdfs); > + > + ret = seq_open(file, &opens_seq_ops); > + if (ret) > + return ret; > + s = file->private_data; > + s->private = clp; > + return 0; > +} > + > +static int client_opens_release(struct inode *inode, struct file *file) > +{ > + struct seq_file *m = file->private_data; > + struct nfs4_client *clp = m->private; > + > + /* XXX: alternatively, we could get/drop in seq start/stop */ > + drop_client(clp); > + return 0; > +} > + > +static const struct file_operations client_opens_fops = { > + .open = client_opens_open, > + .read = seq_read, > + .llseek = seq_lseek, > + .release = client_opens_release, > +}; > + > static const struct tree_descr client_files[] = { > [0] = {"info", &client_info_fops, S_IRUSR}, > - [1] = {""}, > + [1] = {"open", &client_opens_fops, S_IRUSR}, > + [2] = {""}, > }; > > static struct nfs4_client *create_client(struct xdr_netobj name, -- Jeff Layton