linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Tejun Heo <tj@kernel.org>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	rusty@rustcorp.com.au, skinsbursky@parallels.com,
	ebiederm@xmission.com, jmorris@namei.org, axboe@kernel.dk
Subject: Re: [PATCHSET] idr: implement idr_alloc() and convert existing users
Date: Sun, 3 Feb 2013 19:15:58 -0500	[thread overview]
Message-ID: <20130204001557.GB24778@fieldses.org> (raw)
In-Reply-To: <20130203170241.GA24778@fieldses.org>

On Sun, Feb 03, 2013 at 12:02:41PM -0500, J. Bruce Fields wrote:
> On Sat, Feb 02, 2013 at 05:20:01PM -0800, Tejun Heo wrote:
> > * Bruce, I couldn't convert nfsd.  Can you please help?  More on it
> >   later.
> ...
> > I converted all in-kernel users except nfsd and staging drivers.  nfsd
> > splits preloading and actual id allocation in a way that per-cpu
> > preloading can't be used.  I couldn't follow the control flow to
> > verify whether the current code is correct either.  I think the best
> > way would be allocating ID upfront without installing the handle and
> > then later using idr_replace() to install the pointer when the ID
> > actually gets used.  Bruce, would something like that be possible?
> 
> Actually, I'm not even sure if that's necessary, we can probably just
> do it all at the start.
> 
> I'll try to have a patch doing that tomorrow.

So, something like this.

--b.

commit 9847160469b40345e1d78a7cbf9536761bb47d91
Author: J. Bruce Fields <bfields@redhat.com>
Date:   Sun Feb 3 12:23:01 2013 -0500

    nfsd4: simplify idr allocation
    
    We don't really need to preallocate at all; just allocate and initialize
    everything at once, but leave the sc_type field initially 0 to prevent
    finding the stateid till it's fully initialized.
    
    Signed-off-by: J. Bruce Fields <bfields@redhat.com>

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 4db46aa..485b1f7 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -261,33 +261,46 @@ static inline int get_new_stid(struct nfs4_stid *stid)
 	return new_stid;
 }
 
-static void init_stid(struct nfs4_stid *stid, struct nfs4_client *cl, unsigned char type)
+static struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, struct
+kmem_cache *slab)
 {
-	stateid_t *s = &stid->sc_stateid;
+	struct idr *stateids = &cl->cl_stateids;
+	static int min_stateid = 0;
+	struct nfs4_stid *stid;
 	int new_id;
 
-	stid->sc_type = type;
+	stid = kmem_cache_alloc(slab, GFP_KERNEL);
+	if (!stid)
+		return NULL;
+
+	if (!idr_pre_get(stateids, GFP_KERNEL))
+		goto out_free;
+	if (idr_get_new_above(stateids, stid, min_stateid, &new_id))
+		goto out_free;
 	stid->sc_client = cl;
-	s->si_opaque.so_clid = cl->cl_clientid;
-	new_id = get_new_stid(stid);
-	s->si_opaque.so_id = (u32)new_id;
+	stid->sc_type = 0;
+	stid->sc_stateid.si_opaque.so_id = new_id;
+	stid->sc_stateid.si_opaque.so_clid = cl->cl_clientid;
 	/* Will be incremented before return to client: */
-	s->si_generation = 0;
-}
+	stid->sc_stateid.si_generation = 0;
 
-static struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, struct kmem_cache *slab)
-{
-	struct idr *stateids = &cl->cl_stateids;
-
-	if (!idr_pre_get(stateids, GFP_KERNEL))
-		return NULL;
 	/*
-	 * Note: if we fail here (or any time between now and the time
-	 * we actually get the new idr), we won't need to undo the idr
-	 * preallocation, since the idr code caps the number of
-	 * preallocated entries.
+	 * It shouldn't be a problem to reuse an opaque stateid value.
+	 * I don't think it is for 4.1.  But with 4.0 I worry that, for
+	 * example, a stray write retransmission could be accepted by
+	 * the server when it should have been rejected.  Therefore,
+	 * adopt a trick from the sctp code to attempt to maximize the
+	 * amount of time until an id is reused, by ensuring they always
+	 * "increase" (mod INT_MAX):
 	 */
-	return kmem_cache_alloc(slab, GFP_KERNEL);
+
+	min_stateid = new_id+1;
+	if (min_stateid == INT_MAX)
+		min_stateid = 0;
+	return stid;
+out_free:
+	kfree(stid);
+	return NULL;
 }
 
 static struct nfs4_ol_stateid * nfs4_alloc_stateid(struct nfs4_client *clp)
@@ -316,7 +329,7 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_ol_stateid *stp, struct sv
 	dp = delegstateid(nfs4_alloc_stid(clp, deleg_slab));
 	if (dp == NULL)
 		return dp;
-	init_stid(&dp->dl_stid, clp, NFS4_DELEG_STID);
+	dp->dl_stid.sc_type = NFS4_DELEG_STID;
 	/*
 	 * delegation seqid's are never incremented.  The 4.1 special
 	 * meaning of seqid 0 isn't meaningful, really, but let's avoid
@@ -337,13 +350,21 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_ol_stateid *stp, struct sv
 	return dp;
 }
 
+void free_stid(struct nfs4_stid *s, struct kmem_cache *slab)
+{
+	struct idr *stateids = &s->sc_client->cl_stateids;
+
+	idr_remove(stateids, s->sc_stateid.si_opaque.so_id);
+	kmem_cache_free(slab, s);
+}
+
 void
 nfs4_put_delegation(struct nfs4_delegation *dp)
 {
 	if (atomic_dec_and_test(&dp->dl_count)) {
 		dprintk("NFSD: freeing dp %p\n",dp);
 		put_nfs4_file(dp->dl_file);
-		kmem_cache_free(deleg_slab, dp);
+		free_stid(&dp->dl_stid, deleg_slab);
 		num_delegations--;
 	}
 }
@@ -360,9 +381,7 @@ static void nfs4_put_deleg_lease(struct nfs4_file *fp)
 
 static void unhash_stid(struct nfs4_stid *s)
 {
-	struct idr *stateids = &s->sc_client->cl_stateids;
-
-	idr_remove(stateids, s->sc_stateid.si_opaque.so_id);
+	s->sc_type = 0;
 }
 
 /* Called under the state lock. */
@@ -519,7 +538,7 @@ static void close_generic_stateid(struct nfs4_ol_stateid *stp)
 
 static void free_generic_stateid(struct nfs4_ol_stateid *stp)
 {
-	kmem_cache_free(stateid_slab, stp);
+	free_stid(&stp->st_stid, stateid_slab);
 }
 
 static void release_lock_stateid(struct nfs4_ol_stateid *stp)
@@ -1258,7 +1277,12 @@ static void gen_confirm(struct nfs4_client *clp)
 
 static struct nfs4_stid *find_stateid(struct nfs4_client *cl, stateid_t *t)
 {
-	return idr_find(&cl->cl_stateids, t->si_opaque.so_id);
+	struct nfs4_stid *ret;
+
+	ret = idr_find(&cl->cl_stateids, t->si_opaque.so_id);
+	if (!ret || !ret->sc_type)
+		return NULL;
+	return ret;
 }
 
 static struct nfs4_stid *find_stateid_by_type(struct nfs4_client *cl, stateid_t *t, char typemask)
@@ -2444,9 +2468,8 @@ alloc_init_open_stateowner(unsigned int strhashval, struct nfs4_client *clp, str
 
 static void init_open_stateid(struct nfs4_ol_stateid *stp, struct nfs4_file *fp, struct nfsd4_open *open) {
 	struct nfs4_openowner *oo = open->op_openowner;
-	struct nfs4_client *clp = oo->oo_owner.so_client;
 
-	init_stid(&stp->st_stid, clp, NFS4_OPEN_STID);
+	stp->st_stid.sc_type = NFS4_OPEN_STID;
 	INIT_LIST_HEAD(&stp->st_lockowners);
 	list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids);
 	list_add(&stp->st_perfile, &fp->fi_stateids);
@@ -4032,7 +4055,7 @@ alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp, struct
 	stp = nfs4_alloc_stateid(clp);
 	if (stp == NULL)
 		return NULL;
-	init_stid(&stp->st_stid, clp, NFS4_LOCK_STID);
+	stp->st_stid.sc_type = NFS4_LOCK_STID;
 	list_add(&stp->st_perfile, &fp->fi_stateids);
 	list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids);
 	stp->st_stateowner = &lo->lo_owner;

  reply	other threads:[~2013-02-04  0:16 UTC|newest]

Thread overview: 128+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-03  1:20 [PATCHSET] idr: implement idr_alloc() and convert existing users Tejun Heo
2013-02-03  1:20 ` [PATCH 01/62] idr: cosmetic updates to struct / initializer definitions Tejun Heo
2013-02-03  1:20 ` [PATCH 02/62] idr: relocate idr_for_each_entry() and reorganize id[r|a]_get_new() Tejun Heo
2013-02-03  1:20 ` [PATCH 03/62] idr: remove _idr_rc_to_errno() hack Tejun Heo
2013-02-03  1:20 ` [PATCH 04/62] idr: refactor idr_get_new_above() Tejun Heo
2013-02-03  1:20 ` [PATCH 05/62] idr: implement idr_preload[_end]() and idr_alloc() Tejun Heo
2013-02-04 18:32   ` [PATCH v2 " Tejun Heo
2013-02-03  1:20 ` [PATCH 06/62] block: fix synchronization and limit check in blk_alloc_devt() Tejun Heo
2013-02-06 11:00   ` Jens Axboe
2013-02-03  1:20 ` [PATCH 07/62] block: convert to idr_alloc() Tejun Heo
2013-02-04 13:10   ` Jens Axboe
2013-02-03  1:20 ` [PATCH 08/62] block/loop: " Tejun Heo
2013-02-04 13:11   ` Jens Axboe
2013-02-03  1:20 ` [PATCH 09/62] atm/nicstar: " Tejun Heo
2013-02-04 14:04   ` chas williams - CONTRACTOR
2013-02-04 17:06     ` Tejun Heo
2013-02-04 18:06       ` chas williams - CONTRACTOR
2013-02-04 18:37   ` [PATCH v3 " Tejun Heo
2013-02-03  1:20 ` [PATCH 10/62] drbd: " Tejun Heo
2013-02-03  1:20 ` [PATCH 11/62] dca: " Tejun Heo
2013-02-03  1:20 ` [PATCH 12/62] dmaengine: " Tejun Heo
2013-02-03  1:20 ` [PATCH 13/62] firewire: " Tejun Heo
2013-02-03 11:03   ` Stefan Richter
2013-02-03 11:18     ` Stefan Richter
2013-02-04 16:57   ` [PATCH 12.5/62] firewire: add minor number range check to fw_device_init() Tejun Heo
2013-02-04 18:15     ` Stefan Richter
2013-02-04 16:58   ` [PATCH v2 13/62] firewire: convert to idr_alloc() Tejun Heo
2013-02-04 18:16     ` Stefan Richter
2013-02-03  1:20 ` [PATCH 14/62] gpio: " Tejun Heo
2013-02-04 20:40   ` Linus Walleij
2013-02-03  1:20 ` [PATCH 15/62] drm: " Tejun Heo
2013-02-03  1:20 ` [PATCH 16/62] drm/exynos: " Tejun Heo
2013-02-03  1:20 ` [PATCH 17/62] drm/i915: " Tejun Heo
2013-02-04 14:53   ` Daniel Vetter
2013-02-03  1:20 ` [PATCH 18/62] drm/sis: " Tejun Heo
2013-02-03  1:20 ` [PATCH 19/62] drm/via: " Tejun Heo
2013-02-03  1:20 ` [PATCH 20/62] drm/vmwgfx: " Tejun Heo
2013-02-03  1:20 ` [PATCH 21/62] i2c: " Tejun Heo
2013-02-03  1:20 ` [PATCH 22/62] infiniband/core: " Tejun Heo
2013-02-04 16:43   ` [PATCH v2 " Tejun Heo
2013-02-05  0:07     ` Hefty, Sean
2013-02-03  1:20 ` [PATCH 23/62] infiniband/amso1100: " Tejun Heo
2013-02-03 14:36   ` Steve Wise
2013-02-03  1:20 ` [PATCH 24/62] infiniband/cxgb3: " Tejun Heo
2013-02-03 14:37   ` Steve Wise
2013-02-03  1:20 ` [PATCH 25/62] infiniband/cxgb4: " Tejun Heo
2013-02-03 14:18   ` Steve Wise
2013-02-03 14:28     ` Tejun Heo
2013-02-04 15:32   ` Steve Wise
2013-02-03  1:20 ` [PATCH 26/62] infiniband/ehca: " Tejun Heo
2013-02-03  1:20 ` [PATCH 27/62] infiniband/ipath: " Tejun Heo
2013-02-04 16:15   ` Marciniszyn, Mike
2013-02-04 16:18     ` Tejun Heo
2013-02-03  1:20 ` [PATCH 28/62] infiniband/mlx4: " Tejun Heo
2013-02-03  1:20 ` [PATCH 29/62] infiniband/ocrdma: " Tejun Heo
2013-02-03  1:20 ` [PATCH 30/62] infiniband/qib: " Tejun Heo
2013-02-03  1:20 ` [PATCH 31/62] dm: " Tejun Heo
2013-02-03  1:20 ` [PATCH 32/62] memstick: " Tejun Heo
2013-02-03  1:20 ` [PATCH 33/62] mfd: " Tejun Heo
2013-02-03 22:32   ` Samuel Ortiz
2013-02-03  1:20 ` [PATCH 34/62] misc/c2port: " Tejun Heo
2013-02-03  1:20 ` [PATCH 35/62] misc/tifm_core: " Tejun Heo
2013-02-03  1:20 ` [PATCH 36/62] mmc: " Tejun Heo
2013-02-03  1:20 ` [PATCH 37/62] mtd: " Tejun Heo
2013-02-04 13:09   ` Ezequiel Garcia
2013-02-03  1:20 ` [PATCH 38/62] i2c: " Tejun Heo
2013-02-03  1:25   ` [PATCH UPDATED 38/62] macvtap: " Tejun Heo
2013-02-03  1:20 ` [PATCH 39/62] ppp: " Tejun Heo
2013-02-03  1:20 ` [PATCH 40/62] power: " Tejun Heo
2013-02-03  3:46   ` Anton Vorontsov
2013-02-03  1:20 ` [PATCH 41/62] pps: " Tejun Heo
2013-02-03  1:20 ` [PATCH 42/62] remoteproc: " Tejun Heo
2013-02-03  1:20 ` [PATCH 43/62] rpmsg: " Tejun Heo
2013-02-03  1:20 ` [PATCH 44/62] scsi/bfa: " Tejun Heo
2013-02-03  1:20 ` [PATCH 45/62] scsi: " Tejun Heo
2013-02-03  1:20 ` [PATCH 46/62] target/iscsi: " Tejun Heo
2013-02-03  1:20 ` [PATCH 47/62] scsi/lpfc: " Tejun Heo
2013-02-11 22:46   ` James Smart
2013-02-03  1:20 ` [PATCH 48/62] thermal: " Tejun Heo
2013-02-03  1:20 ` [PATCH 49/62] uio: " Tejun Heo
2013-02-03  7:05   ` Greg Kroah-Hartman
2013-02-03  1:20 ` [PATCH 50/62] vfio: " Tejun Heo
2013-02-04 16:06   ` Alex Williamson
2013-02-04 16:48   ` [PATCH v2 " Tejun Heo
2013-02-03  1:20 ` [PATCH 51/62] dlm: " Tejun Heo
2013-02-03  1:20 ` [PATCH 52/62] inotify: " Tejun Heo
2013-02-03  1:20 ` [PATCH 53/62] ocfs2: " Tejun Heo
2013-02-03  1:20 ` [PATCH 54/62] ipc: " Tejun Heo
2013-02-03  1:20 ` [PATCH 55/62] cgroup: " Tejun Heo
2013-02-04  2:49   ` Li Zefan
2013-02-03  1:20 ` [PATCH 56/62] events: " Tejun Heo
2013-02-03  1:20 ` [PATCH 57/62] posix-timers: " Tejun Heo
2013-02-03  1:20 ` [PATCH 58/62] net/9p: " Tejun Heo
2013-02-03  1:21 ` [PATCH 59/62] mac80211: " Tejun Heo
2013-02-04 17:40   ` Johannes Berg
2013-02-04 17:42     ` Tejun Heo
2013-02-03  1:21 ` [PATCH 60/62] sctp: " Tejun Heo
2013-02-03 16:55   ` Neil Horman
2013-02-04 16:22   ` Vlad Yasevich
2013-02-04 16:37     ` Tejun Heo
2013-02-04 16:42   ` [PATCH v2 " Tejun Heo
2013-02-05 15:22     ` Neil Horman
2013-02-03  1:21 ` [PATCH 61/62] nfs4client: " Tejun Heo
2013-02-03  1:21 ` [PATCH 62/62] idr: deprecate idr_pre_get() and idr_get_new[_above]() Tejun Heo
2013-02-03 13:41 ` [PATCHSET] idr: implement idr_alloc() and convert existing users Eric W. Biederman
2013-02-03 14:13   ` Tejun Heo
2013-02-03 15:24     ` Eric W. Biederman
2013-02-03 15:47       ` Tejun Heo
2013-02-03 17:02 ` J. Bruce Fields
2013-02-04  0:15   ` J. Bruce Fields [this message]
2013-02-04 17:10     ` Tejun Heo
2013-02-04 17:11       ` Tejun Heo
2013-02-04 18:15         ` J. Bruce Fields
2013-03-21 14:06         ` J. Bruce Fields
2013-03-21 18:35           ` Tejun Heo
2013-03-26 15:19             ` Jeff Layton
2013-03-26 15:26               ` Tejun Heo
2013-03-26 16:30                 ` J. Bruce Fields
2013-03-26 16:33                   ` Tejun Heo
2013-03-26 16:36                     ` Tejun Heo
2013-03-26 16:52                       ` Jeff Layton
2013-02-04 17:16       ` J. Bruce Fields
2013-02-04 19:17 ` Tejun Heo
2013-02-04 19:54   ` Marciniszyn, Mike
2013-02-04 21:42     ` Tejun Heo
2013-02-04 22:25       ` Marciniszyn, Mike
2013-02-04 20:08   ` Marciniszyn, Mike
2013-02-04 21:43     ` Tejun Heo

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=20130204001557.GB24778@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=ebiederm@xmission.com \
    --cc=jmorris@namei.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=skinsbursky@parallels.com \
    --cc=tj@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).