From 4235a0786c7756f63d70130afc85690dc7812e43 Mon Sep 17 00:00:00 2001 From: Bob Beck Date: Tue, 15 Dec 2009 15:53:49 +0000 Subject: Make sillyrename not so damn silly. The kindergarten algorithm here for picking a name meant that more than 58 sillys in a directory and we fail with EINVAL, resulting in strange problems for nfs which in turn causes pain and stress in building, and PTSD in nfs and vfs hackers. Has bit us in the butt since the vienna f2k7 hackathon. good suggestions from deraadt@ guenther@ and otto@ ok deraadt@,oga@,blambert@,krw@,guenther@, and a "very special ok" tedu@ Oh god, I'm an nfs hacker.. --- sys/nfs/nfs_vnops.c | 27 ++++++++++++--------------- sys/nfs/nfsnode.h | 4 ++-- 2 files changed, 14 insertions(+), 17 deletions(-) (limited to 'sys') diff --git a/sys/nfs/nfs_vnops.c b/sys/nfs/nfs_vnops.c index 849f6ef5217..0b9fada31f5 100644 --- a/sys/nfs/nfs_vnops.c +++ b/sys/nfs/nfs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs_vnops.c,v 1.126 2009/12/10 16:41:45 beck Exp $ */ +/* $OpenBSD: nfs_vnops.c,v 1.127 2009/12/15 15:53:48 beck Exp $ */ /* $NetBSD: nfs_vnops.c,v 1.62.4.1 1996/07/08 20:26:52 jtc Exp $ */ /* @@ -186,7 +186,6 @@ extern struct nfsstats nfsstats; extern nfstype nfsv3_type[9]; int nfs_numasync = 0; - void nfs_cache_enter(struct vnode *dvp, struct vnode *vp, struct componentname *cnp) { @@ -2519,21 +2518,19 @@ nfs_sillyrename(struct vnode *dvp, struct vnode *vp, struct componentname *cnp) goto bad; } - /* Fudge together a funny name */ - sp->s_namlen = snprintf(sp->s_name, sizeof sp->s_name, - ".nfsA%05x4.4", cnp->cn_proc->p_pid); - if (sp->s_namlen > sizeof sp->s_name) - sp->s_namlen = strlen(sp->s_name); - /* Try lookitups until we get one that isn't there */ - while (nfs_lookitup(dvp, sp->s_name, sp->s_namlen, sp->s_cred, - cnp->cn_proc, NULL) == 0) { - sp->s_name[4]++; - if (sp->s_name[4] > 'z') { - error = EINVAL; - goto bad; - } + while (1) { + /* Fudge together a funny name */ + sp->s_namlen = snprintf(sp->s_name, sizeof sp->s_name, + ".nfs%08X%08X", arc4random(), arc4random()); + if (sp->s_namlen > sizeof sp->s_name) + sp->s_namlen = strlen(sp->s_name); + + if (nfs_lookitup(dvp, sp->s_name, sp->s_namlen, sp->s_cred, + cnp->cn_proc, NULL)) + break; } + error = nfs_renameit(dvp, cnp, sp); if (error) goto bad; diff --git a/sys/nfs/nfsnode.h b/sys/nfs/nfsnode.h index 85d411c9ba5..ee09b388e85 100644 --- a/sys/nfs/nfsnode.h +++ b/sys/nfs/nfsnode.h @@ -1,4 +1,4 @@ -/* $OpenBSD: nfsnode.h,v 1.38 2009/09/02 18:20:54 thib Exp $ */ +/* $OpenBSD: nfsnode.h,v 1.39 2009/12/15 15:53:48 beck Exp $ */ /* $NetBSD: nfsnode.h,v 1.16 1996/02/18 11:54:04 fvdl Exp $ */ /* @@ -53,7 +53,7 @@ struct sillyrename { struct ucred *s_cred; struct vnode *s_dvp; long s_namlen; - char s_name[20]; + char s_name[24]; }; /* -- cgit v1.2.3