From: Matt Smith Date: Thu, 16 Sep 2010 20:44:04 +0000 (-0500) Subject: Updates to the Cache Manager to include NetBSD5 support X-Git-Tag: upstream/1.8.0_pre1^2~4764 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=18b932f;p=packages%2Fo%2Fopenafs.git Updates to the Cache Manager to include NetBSD5 support LKM currently builds and will mount when forced with the entry point manually defined. Contents of /afs can be discovered, but when listing the directory, the system call will not return. Change-Id: I68ba1897b56613bd4ebbe331eea3140c6a963a7d Reviewed-on: http://gerrit.openafs.org/2767 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- diff --git a/src/afs/NBSD/osi_file.c b/src/afs/NBSD/osi_file.c index 8c93145f3..55a10d770 100644 --- a/src/afs/NBSD/osi_file.c +++ b/src/afs/NBSD/osi_file.c @@ -57,17 +57,21 @@ afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat) struct vattr tvattr; AFS_STATCNT(osi_Stat); - MObtainWriteLock(&afs_xosi, 320); + ObtainWriteLock(&afs_xosi, 320); AFS_GUNLOCK(); +#ifdef AFS_NBSD50_ENV + code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp); +#else code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, osi_curproc()); +#endif AFS_GLOCK(); if (code == 0) { astat->size = afile->size = tvattr.va_size; astat->mtime = tvattr.va_mtime.tv_sec; astat->atime = tvattr.va_atime.tv_sec; } - MReleaseWriteLock(&afs_xosi); + ReleaseWriteLock(&afs_xosi); return code; } @@ -101,18 +105,22 @@ osi_UFSTruncate(struct osi_file *afile, afs_int32 asize) if (code || tstat.size <= asize) return code; - MObtainWriteLock(&afs_xosi, 321); + ObtainWriteLock(&afs_xosi, 321); VATTR_NULL(&tvattr); tvattr.va_size = asize; AFS_GUNLOCK(); VOP_LOCK(afile->vnode, LK_EXCLUSIVE | LK_RETRY); +#ifdef AFS_NBSD50_ENV + code = VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp); +#else code = VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp, osi_curproc()); +#endif VOP_UNLOCK(afile->vnode, 0); AFS_GLOCK(); if (code == 0) afile->size = asize; - MReleaseWriteLock(&afs_xosi); + ReleaseWriteLock(&afs_xosi); return code; } diff --git a/src/afs/NBSD/osi_groups.c b/src/afs/NBSD/osi_groups.c index 307973ae9..492043ae7 100644 --- a/src/afs/NBSD/osi_groups.c +++ b/src/afs/NBSD/osi_groups.c @@ -61,8 +61,11 @@ Afs_xsetgroups(struct proc *p, void *args, int *retval) /* * XXX Does treq.uid == osi_crgetruid(cred)? */ - - code = kauth_cred_setgroups(cred, args, retval, osi_crgetruid(cred)); +#ifdef AFS_NBSD50_ENV + code = kauth_cred_setgroups(cred, args, retval, osi_crgetruid(cred), UIO_SYSSPACE); +#else + code = kauth_cred_setgroups(cred, args, retval, osi_crgetruid(cred)); +#endif /* * Note that if there is a pag already in the new groups we don't * overwrite it with the old pag. diff --git a/src/afs/NBSD/osi_machdep.h b/src/afs/NBSD/osi_machdep.h index 2cd67e891..5b86606e7 100644 --- a/src/afs/NBSD/osi_machdep.h +++ b/src/afs/NBSD/osi_machdep.h @@ -23,11 +23,27 @@ #define AFS_DIRENT 1 #include +#if defined(AFS_NBSD50_ENV) +#include +#include +#include +#include +#endif #include #include #include +#ifndef AFS_NBSD50_ENV +/* Why are we including the rump debugger? */ #include "opt_ddb.h" /* Debugger() */ +#endif + +#if defined(AFS_NBSD50_ENV) +# if !defined(DEF_CADDR_T) +typedef char * caddr_t; +#define DEF_CADDR_T +# endif +#endif #define M_AFSFID (M_TEMP-1) #define M_AFSBUFHDR (M_TEMP-2) @@ -47,17 +63,18 @@ #define v_vfsp v_mount #define VFS_STATFS afs_statvfs +#ifndef AFS_NBSD50_ENV +/* Defined in sys/syscallargs.h */ int sys_ioctl(struct lwp *l, void *v, register_t *retval); +#endif /* vnode */ #define VN_HOLD(vp) (vref(vp)) #define VN_RELE(vp) (vrele(vp)) #define osi_vnhold(avc, r) (VN_HOLD(AFSTOV(avc))) - #define va_nodeid va_fileid -#define vnode_t struct vnode /* syscall */ struct afs_sysargs { @@ -82,8 +99,6 @@ struct afs_sysargs { /* malloc */ inline void * afs_osi_Alloc(size_t asize); inline void * afs_osi_Alloc_NoSleep(size_t asize); -inline void afs_osi_Free(void *buf, size_t asize); -inline void afs_osi_FreeStr(char *x); extern void *osi_nbsd_Alloc(size_t asize, int cansleep); extern void osi_nbsd_Free(void *p, size_t asize); @@ -97,10 +112,12 @@ extern void osi_nbsd_Free(void *p, size_t asize); #define AFS_KFREE(p, s) (osi_nbsd_Free((p), (s))) #endif + /* proc */ typedef struct lwp afs_proc_t; #define osi_curproc() curlwp #define getpid() (osi_curproc())->l_proc->p_pid +#define osi_procname(procname, size) strncpy(procname, curproc->p_comm, size) /* * XXX I'm exporting the internal definition of kauth_cred_t @@ -111,7 +128,37 @@ typedef struct lwp afs_proc_t; #define KAUTH_EXPORT 1 #if defined(KAUTH_EXPORT) /* internal type from kern_auth.c */ -#ifdef AFS_NBSD40_ENV +#if defined(AFS_NBSD50_ENV) +/* + * Credentials. + * + * A subset of this structure is used in kvm(3) (src/lib/libkvm/kvm_proc.c) + * and should be synchronized with this structure when the update is + * relevant. + */ +struct kauth_cred { + /* + * Ensure that the first part of the credential resides in its own + * cache line. Due to sharing there aren't many kauth_creds in a + * typical system, but the reference counts change very often. + * Keeping it seperate from the rest of the data prevents false + * sharing between CPUs. + */ + u_int cr_refcnt; /* reference count */ +#if COHERENCY_UNIT > 4 + uint8_t cr_pad[COHERENCY_UNIT - 4]; +#endif + uid_t cr_uid; /* user id */ + uid_t cr_euid; /* effective user id */ + uid_t cr_svuid; /* saved effective user id */ + gid_t cr_gid; /* group id */ + gid_t cr_egid; /* effective group id */ + gid_t cr_svgid; /* saved effective group id */ + u_int cr_ngroups; /* number of groups */ + gid_t cr_groups[NGROUPS]; /* group memberships */ + specificdata_reference cr_sd; /* specific data */ +}; +#elif defined(AFS_NBSD40_ENV) struct kauth_cred { struct simplelock cr_lock; /* lock on cr_refcnt */ u_int cr_refcnt; /* reference count */ @@ -182,8 +229,24 @@ extern int afs_vget(); #ifdef KERNEL #ifdef AFS_GLOBAL_SUNLOCK -extern struct lock afs_global_lock; +#if defined(AFS_NBSD50_ENV) +extern kmutex_t afs_global_mtx; +#define AFS_GLOCK() \ + do { \ + mutex_enter(&afs_global_mtx); \ + } while (0) +#define AFS_GUNLOCK() \ + do { \ + mutex_exit(&afs_global_mtx); \ + } while (0) +#define ISAFS_GLOCK() (mutex_owned(&afs_global_mtx)) +#define osi_InitGlock() \ + do { \ + mutex_init(&afs_global_mtx, MUTEX_DEFAULT, IPL_NONE); \ + } while (0) +#else /* !50 */ +extern struct lock afs_global_lock; #if defined(LOCKDEBUG) #define AFS_GLOCK() \ do { \ @@ -203,14 +266,15 @@ extern struct lock afs_global_lock; lockmgr(&afs_global_lock, LK_RELEASE, NULL); \ } while(0); #endif /* LOCKDEBUG */ -#define ISAFS_GLOCK() (lockstatus(&afs_global_lock) == LK_EXCLUSIVE) +#endif /* !50 */ #else +#define ISAFS_GLOCK() (lockstatus(&afs_global_lock) == LK_EXCLUSIVE) extern struct lock afs_global_lock; #define AFS_GLOCKP(p) #define AFS_GUNLOCKP(p) #define AFS_ASSERT_GLOCK() #define ISAFS_GLOCK() 1 -#endif +#endif /* !AFS_GLOBAL_SUNLOCK */ #undef SPLVAR #define SPLVAR int splvar @@ -240,4 +304,5 @@ extern int (**afs_vnodeop_p) (); #define IsAfsVnode(v) ((v)->v_op == afs_vnodeop_p) #define SetAfsVnode(v) /* nothing; done in getnewvnode() */ + #endif /* _OSI_MACHDEP_H_ */ diff --git a/src/afs/NBSD/osi_misc.c b/src/afs/NBSD/osi_misc.c index 50ed09988..845aa97dc 100644 --- a/src/afs/NBSD/osi_misc.c +++ b/src/afs/NBSD/osi_misc.c @@ -65,9 +65,20 @@ int afs_osi_suser(void *credp) { int code; +/* + * lwp->l_acflag is gone in NBSD50. It was "Accounting" stuff. + * lwp->l_ru is what is listed as "accounting information" now, so this + * may or may not work... + */ +#ifdef AFS_NBSD50_ENV + code = kauth_authorize_generic(credp, + KAUTH_GENERIC_ISSUSER, + &curlwp->l_ru); +#else code = kauth_authorize_generic(credp, KAUTH_GENERIC_ISSUSER, &curlwp->l_acflag); +#endif return (code == 0); } @@ -158,6 +169,8 @@ osi_AllocSmallSpace(size_t size) #endif /* Space undef */ +#endif /* Space undef */ + int afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, retval) long *retval; @@ -166,8 +179,6 @@ afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, retval) return EINVAL; } -#endif /* Space undef */ - int afs_syscall_iopen(dev, inode, usrmod, retval) long *retval; diff --git a/src/afs/NBSD/osi_vcache.c b/src/afs/NBSD/osi_vcache.c index 6dca058f5..f7a544e9a 100644 --- a/src/afs/NBSD/osi_vcache.c +++ b/src/afs/NBSD/osi_vcache.c @@ -52,15 +52,19 @@ void osi_AttachVnode(struct vcache *avc, int seq) { ReleaseWriteLock(&afs_xvcache); AFS_GUNLOCK(); - afs_obsd_getnewvnode(avc); /* includes one refcount */ + afs_nbsd_getnewvnode(avc); /* includes one refcount */ AFS_GLOCK(); ObtainWriteLock(&afs_xvcache,337); +#ifdef AFS_NBSD50_ENV + mutex_init(&avc->rwlock, MUTEX_DEFAULT, IPL_NONE); +#else lockinit(&avc->rwlock, PINOD, "vcache", 0, 0); +#endif } void osi_PostPopulateVCache(struct vcache *avc) { AFSTOV(avc)->v_mount = afs_globalVFS; - vSetType(vc, VREG); + vSetType(avc, VREG); } diff --git a/src/afs/NBSD/osi_vfsops.c b/src/afs/NBSD/osi_vfsops.c index 922b1d591..d257d71a5 100644 --- a/src/afs/NBSD/osi_vfsops.c +++ b/src/afs/NBSD/osi_vfsops.c @@ -100,6 +100,9 @@ NONINFRINGEMENT. #include #include +#include + +extern unsigned long long afs_debug; #if 0 /* from /usr/src/sys/kern/vfs_subr.c */ @@ -158,6 +161,9 @@ static const struct vnodeopv_desc *afs_vnodeopv_descs[] = { struct vfsops afs_vfsops = { AFS_MOUNT_AFS, +#ifdef AFS_NBSD50_ENV + 0, /* vfs_min_mount_data */ +#endif afs_mount, afs_start, afs_unmount, @@ -172,8 +178,14 @@ struct vfsops afs_vfsops = { afs_reinit, afs_done, (int (*) (void)) eopnotsupp, /* mountroot */ - (int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp, + (int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp, /* vfs_snapshot */ vfs_stdextattrctl, +#ifdef AFS_NBSD50_ENV + (int (*)(struct mount *, int)) eopnotsupp, /* vfs_suspendctl */ + (int (*)(struct mount *)) eopnotsupp, /* vfs_renamelock_enter */ + (void *) eopnotsupp, /* vfs_renamelock_exit */ + (int (*)(struct vnode*, int)) eopnotsupp, /* vfs_fsync */ +#endif afs_vnodeopv_descs, 0, /* vfs_refcount */ { NULL, NULL }, @@ -197,7 +209,15 @@ afs_nbsd_lookupname(char *fnamep, enum uio_seg segflg, int followlink, */ /* XXX LOCKLEAF ? */ niflag = followlink ? FOLLOW : NOFOLLOW; + /* + * NBSD50 seems to have stopped caring about the curproc of things. + * mattjsm + */ +#ifdef AFS_NBSD50_ENV + NDINIT(&nd, LOOKUP, niflag, segflg, fnamep); +#else NDINIT(&nd, LOOKUP, niflag, segflg, fnamep, osi_curproc()); +#endif if ((error = namei(&nd))) return error; *compvpp = nd.ni_vp; @@ -249,10 +269,12 @@ afs_mount(struct mount *mp, const char *path, void *data, } AFS_GLOCK(); +#ifdef AFS_DISCON_ENV /* initialize the vcache entries before we start using them */ /* XXX find a better place for this if possible */ init_vcache_entries(); +#endif afs_globalVFS = mp; mp->mnt_stat.f_bsize = 8192; mp->mnt_stat.f_frsize = 8192; @@ -285,7 +307,9 @@ afs_unmount(struct mount *mp, int mntflags, struct lwp *l) extern int sys_ioctl(), sys_setgroups(); AFS_STATCNT(afs_unmount); +#ifdef AFS_DISCON_ENV give_up_cbs(); +#endif if (afs_globalVFS == NULL) { printf("afs already unmounted\n"); return 0; @@ -348,7 +372,12 @@ afs_root(struct mount *mp, struct vnode **vpp) afs_globalVp = tvp; VREF(AFSTOV(afs_globalVp)); } +/* v_flag no longer exists... mattjsm */ +#ifdef AFS_NBSD50_ENV + AFSTOV(tvp)->v_vflag |= VV_ROOT; +#else AFSTOV(tvp)->v_flag |= VROOT; +#endif afs_globalVFS = mp; *vpp = AFSTOV(tvp); } else @@ -401,8 +430,10 @@ int afs_sync(struct mount *mp, int waitfor, kauth_cred_t cred, struct lwp *l) { AFS_STATCNT(afs_sync); +#if defined(AFS_DISCON_ENV) /* Can't do this in OpenBSD 2.7, it faults when called from apm_suspend() */ store_dirty_vcaches(); +#endif return 0; } @@ -454,18 +485,17 @@ afs_vfs_load(struct lkm_table *lkmtp, int cmd) if (memname[M_AFSBUFFER] == NULL) memname[M_AFSBUFFER] = afsbfrmem; #endif - lkmid = lkmtp->id; - - if (sysent[AFS_SYSCALL].sy_call != sys_nosys) { - printf("LKM afs_vfs_load(): AFS3 syscall %d already used\n", - AFS_SYSCALL); - /* return EEXIST; */ + lkmid = lkmtp->id; + if (sysent[AFS_SYSCALL].sy_call != sys_nosys) { + printf("LKM afs_vfs_load(): AFS3 syscall %d already used\n", + AFS_SYSCALL); + /* return EEXIST; */ } old_sysent = sysent[AFS_SYSCALL]; sysent[AFS_SYSCALL] = afs_sysent; - printf("OpenAFS lkm loaded\n"); + printf("OpenAFS lkm loaded id: %d\n", lkmid); return (0); } @@ -512,5 +542,10 @@ libafs_lkmentry(struct lkm_table *lkmtp, int cmd, int ver) return EINVAL; } } + +#if DEBUG + afs_debug = AFSDEB_VNLAYER; +#endif + DISPATCH(lkmtp, cmd, ver, afs_vfs_load, afs_vfs_unload, lkm_nofunc); } diff --git a/src/afs/NBSD/osi_vnodeops.c b/src/afs/NBSD/osi_vnodeops.c index 56c42a327..c8a0edf39 100644 --- a/src/afs/NBSD/osi_vnodeops.c +++ b/src/afs/NBSD/osi_vnodeops.c @@ -98,8 +98,6 @@ NONINFRINGEMENT. #include #include "afs/param.h" - - #include "afs/sysincludes.h" /* Standard vendor system headers */ #include "afs/afsincludes.h" /* Afs-based standard headers */ #include "afs/afs_stats.h" /* statistics */ @@ -234,6 +232,15 @@ struct vnodeopv_desc afs_vnodeop_opv_desc = /* toss "stale" pages by shrinking the vnode uobj to a 0-length * region (see uvm_vnp_setsize in uvm_vnode.c) */ +#ifdef AFS_NBSD50_ENV +#define VNP_UNCACHE(vp) \ + do { \ + struct uvm_object *uobj = &vp->v_uobj; \ + mutex_enter(&uobj->vmobjlock); \ + VOP_PUTPAGES( (struct vnode *) uobj, 0 /* offlo */, 0 /* offhi */, PGO_FREE | PGO_SYNCIO); \ + mutex_exit(&uobj->vmobjlock); \ + } while(0); +#else #define VNP_UNCACHE(vp) \ do { \ struct uvm_object *uobj = &vp->v_uobj; \ @@ -241,6 +248,7 @@ struct vnodeopv_desc afs_vnodeop_opv_desc = VOP_PUTPAGES( (struct vnode *) uobj, 0 /* offlo */, 0 /* offhi */, PGO_FREE | PGO_SYNCIO); \ simple_unlock(&uobj->vmobjlock); \ } while(0); +#endif /* psuedo-vnop, wherein we learn that obsd and nbsd disagree * about vnode refcounting */ @@ -251,15 +259,25 @@ afs_nbsd_getnewvnode(struct vcache *tvc) /* no vnodes available, force an alloc (limits be damned)! */ desiredvnodes++; } - afs_warn("afs_nbsd_getnewvnode: vp %lx refs %d (soon to be 1)\n", tvc->v, - tvc->v->v_usecount); + printf("afs_nbsd_getnewvnode: vp %p refs %d\n", tvc->v, + tvc->v->v_usecount); +#ifdef AFS_NBSD50_ENV + mutex_enter(&tvc->v->v_interlock); +#else simple_lock(&tvc->v->v_interlock); +#endif tvc->v->v_data = (void *)tvc; +#if 0 tvc->v->v_usecount = 1; /* !locked, and vref w/v_usecount < 1 panics */ +#endif +#ifdef AFS_NBSD50_ENV + mutex_exit(&tvc->v->v_interlock); +#else simple_unlock(&tvc->v->v_interlock); +#endif } -int afs_debug; +unsigned long long afs_debug; int afs_nbsd_lookup(void *v) @@ -276,33 +294,44 @@ afs_nbsd_lookup(void *v) int flags = ap->a_cnp->cn_flags; int lockparent; /* 1 => lockparent flag is set */ - afs_warn("afs_nbsd_lookup enter\n"); + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_lookup enter ap %p\n", ap); GETNAME(); lockparent = flags & LOCKPARENT; if (ap->a_dvp->v_type != VDIR) { - *ap->a_vpp = NULL; - DROPNAME(); - return ENOTDIR; + *ap->a_vpp = NULL; + DROPNAME(); + return ENOTDIR; } dvp = ap->a_dvp; +/* +* v_flag was broke up into 3 separate flags. v_vflag is the +* substitute when referencing V_ROOT (which was also renamed) +* +* mattjsm +*/ +#ifdef AFS_NBSD50_ENV + if (afs_debug & AFSDEB_VNLAYER && !(dvp->v_vflag & VV_ROOT)) +#else if (afs_debug & AFSDEB_VNLAYER && !(dvp->v_flag & VROOT)) - printf("nbsd_lookup dvp %p flags %x name %s cnt %d\n", dvp, flags, - name, dvp->v_usecount); +#endif + printf("nbsd_lookup dvp %p flags %x name %s v_usecnt %d\n", dvp, flags, + name, dvp->v_usecount); AFS_GLOCK(); code = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred); AFS_GUNLOCK(); if (code) { - if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME) - && (flags & ISLASTCN) && code == ENOENT) - code = EJUSTRETURN; - if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN)) - cnp->cn_flags |= SAVENAME; - DROPNAME(); - *ap->a_vpp = NULL; - return (code); + if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME) + && (flags & ISLASTCN) && code == ENOENT) + code = EJUSTRETURN; + if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN)) + cnp->cn_flags |= SAVENAME; + DROPNAME(); + *ap->a_vpp = NULL; + return (code); } - vp = AFSTOV(vcp); /* always get a node if no error */ + vp = AFSTOV(vcp); /* always get a node if no error */ /* * The parent directory comes in locked. We unlock it on return @@ -311,39 +340,50 @@ afs_nbsd_lookup(void *v) */ if (vp == dvp) { - /* they're the same; afs_lookup() already ref'ed the leaf. - * It came in locked, so we don't need to ref OR lock it */ - if (afs_debug & AFSDEB_VNLAYER) - printf("ref'ed %p as .\n", dvp); + /* they're the same; afs_lookup() already ref'ed the leaf. + * It came in locked, so we don't need to ref OR lock it */ + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_lookup: ref'ed %p as .\n", dvp); } else { - if (!lockparent || !(flags & ISLASTCN)) { - VOP_UNLOCK(dvp, 0); /* done with parent. */ - } - - simple_lock(&vp->v_interlock); - vp->v_usecount = (vp->v_usecount < 1) ? 1 : (vp->v_usecount+1); - simple_unlock(&vp->v_interlock); - if (!VOP_ISLOCKED(vp)) { - vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); - afs_warn("h2\n"); - /* vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); *//* always return the child locked */ - } else { - afs_warn("lookup: vp %lx is locked\n", vp); - } - afs_warn("lookup: after islocked\n"); - if (afs_debug & AFSDEB_VNLAYER) - printf("locked ret %p from lookup\n", vp); + if (!lockparent || !(flags & ISLASTCN)) { + VOP_UNLOCK(dvp, 0); /* done with parent. */ + } + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_lookup dvp %p flags %x name %s v_usecnt %d\n", + dvp, flags, name, dvp->v_usecount); + + /* XXXX hacked here, recheck OBSD and bundled--NBSD has + * removed PDIRUNLOCK, so we must at least accommodate that + * change. M.*/ + if (!VOP_ISLOCKED(vp)) { + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_lookup: omitting to always return child locked\n"); + /* vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); *//* always return the child locked */ + } else { + if (afs_debug & AFSDEB_VNLAYER) + printf("lookup: vp %p is locked\n", vp); + } + if (afs_debug & AFSDEB_VNLAYER) + printf("locked ret %p from lookup\n", vp); } *ap->a_vpp = vp; if (((cnp->cn_nameiop == RENAME && (flags & ISLASTCN)) - || (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN)))) - cnp->cn_flags |= SAVENAME; + || (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN)))) + cnp->cn_flags |= SAVENAME; DROPNAME(); +#ifdef AFS_NBSD50_ENV + if (afs_debug & AFSDEB_VNLAYER && !(dvp->v_vflag & VV_ROOT)) +#else if (afs_debug & AFSDEB_VNLAYER && !(dvp->v_flag & VROOT)) - printf("nbsd_lookup done dvp %p cnt %d\n", dvp, dvp->v_usecount); - return code; +#endif + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_lookup done ap %p dvp %p cnt %d\n", ap, dvp, + dvp->v_usecount); + return (code); } int @@ -401,9 +441,16 @@ afs_nbsd_mknod(void *v) * struct componentname *a_cnp; * struct vattr *a_vap; * } */ *ap = v; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_mknod: enter ap %p\n", ap); + DROPCNP(ap->a_cnp); vput(ap->a_dvp); return (ENODEV); + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_mknod: exit ap %p\n", ap); } int @@ -416,16 +463,24 @@ afs_nbsd_open(void *v) * struct lwp *a_l; * } */ *ap = v; int code; - struct vcache *vc = VTOAFS(ap->a_vp); + struct vnode *vp = ap->a_vp; + struct vcache *vc = VTOAFS(vp); + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_open: enter vp %p vc %p\n", vp, vc); AFS_GLOCK(); code = afs_open(&vc, ap->a_mode, ap->a_cred); #ifdef DIAGNOSTIC if (AFSTOV(vc) != ap->a_vp) - panic("AFS open changed vnode!"); + panic("nbsd_open: AFS open changed vnode!"); #endif AFS_GUNLOCK(); - return code; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_open: exit vp %p vc %p\n", vp, vc); + + return (code); } int @@ -438,11 +493,20 @@ afs_nbsd_close(void *v) * struct lwp *a_l; * } */ *ap = v; int code; + struct vnode *vp = ap->a_vp; + struct vcache *vc = VTOAFS(vp); + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_close: enter vp %p vc %p\n", vp, vc); AFS_GLOCK(); code = afs_close(VTOAFS(ap->a_vp), ap->a_fflag, ap->a_cred); AFS_GUNLOCK(); - return code; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_close: exit vp %p vc %p\n", vp, vc); + + return (code); } int @@ -455,11 +519,20 @@ afs_nbsd_access(void *v) * struct lwp *a_l; * } */ *ap = v; int code; + struct vnode *vp = ap->a_vp; + struct vcache *vc = VTOAFS(vp); + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_access: enter vp %p vc %p mode %d\n", vp, vc, ap->a_mode); AFS_GLOCK(); code = afs_access(VTOAFS(ap->a_vp), ap->a_mode, ap->a_cred); AFS_GUNLOCK(); - return code; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_access: exit vp %p vc %p mode %d\n", vp, vc, ap->a_mode); + + return (code); } int @@ -472,11 +545,22 @@ afs_nbsd_getattr(void *v) * struct lwp *a_l; * } */ *ap = v; int code; + struct vnode *vp = ap->a_vp; + struct vcache *vc = VTOAFS(vp); + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_getattr: enter vp %p vc %p acred %p\n", vp, vc, + ap->a_cred); AFS_GLOCK(); code = afs_getattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred); AFS_GUNLOCK(); - return code; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_getattr: exit vp %p vc %p acred %p\n", vp, vc, + ap->a_cred); + + return (code); } int @@ -490,10 +574,17 @@ afs_nbsd_setattr(void *v) * } */ *ap = v; int code; + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_setattr: enter %p\n", ap); + AFS_GLOCK(); code = afs_setattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred); AFS_GUNLOCK(); - return code; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_setattr: exit %p\n", ap); + + return (code); } int @@ -507,12 +598,19 @@ afs_nbsd_read(void *v) * } */ *ap = v; int code; + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_read enter %p", ap); + AFS_GLOCK(); code = - afs_read(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, (daddr_t) 0, NULL, + afs_read(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, (daddr_t) 0, NULL, 0); AFS_GUNLOCK(); - return code; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_read exit %p", ap); + + return (code); } int @@ -526,6 +624,9 @@ afs_nbsd_write(void *v) * } */ *ap = v; int code; + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_write enter %p", ap); + #if 1 /* all pages are really "stale?" */ VNP_UNCACHE(ap->a_vp); @@ -534,9 +635,13 @@ afs_nbsd_write(void *v) #endif AFS_GLOCK(); code = - afs_write(VTOAFS(ap->a_vp), ap->a_uio, ap->a_ioflag, ap->a_cred, 0); + afs_write(VTOAFS(ap->a_vp), ap->a_uio, ap->a_ioflag, ap->a_cred, 0); AFS_GUNLOCK(); - return code; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_write exit %p", ap); + + return (code); } int @@ -552,20 +657,27 @@ afs_nbsd_ioctl(void *v) * } */ *ap = v; int code; + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_ioctl: enter %p\n", ap); + /* in case we ever get in here... */ AFS_STATCNT(afs_ioctl); AFS_GLOCK(); if (((ap->a_command >> 8) & 0xff) == 'V') - /* This is a VICEIOCTL call */ + /* This is a VICEIOCTL call */ code = HandleIoctl(VTOAFS(ap->a_vp), ap->a_command, - (struct afs_ioctl *)ap->a_data); + (struct afs_ioctl *)ap->a_data); else - /* No-op call; just return. */ - code = ENOTTY; + /* No-op call; just return. */ + code = ENOTTY; AFS_GUNLOCK(); - return code; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_ioctl: exit %p\n", ap); + + return (code); } int @@ -586,6 +698,9 @@ afs_nbsd_fsync(void *v) struct vnode *vp = ap->a_vp; int code, wait; + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_fsync: enter %p\n", ap); + wait = (ap->a_flags & FSYNC_WAIT) != 0; AFS_GLOCK(); @@ -593,7 +708,10 @@ afs_nbsd_fsync(void *v) code = afs_fsync(VTOAFS(vp), ap->a_cred); AFS_GUNLOCK(); - return code; + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_fsync: exit %p\n", ap); + + return (code); } int @@ -608,6 +726,9 @@ afs_nbsd_remove(void *v) struct vnode *vp = ap->a_vp; struct vnode *dvp = ap->a_dvp; + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_remove: enter %p\n", ap); + GETNAME(); AFS_GLOCK(); code = afs_remove(VTOAFS(dvp), name, cnp->cn_cred); @@ -619,7 +740,11 @@ afs_nbsd_remove(void *v) vput(dvp); DROPCNP(cnp); DROPNAME(); - return code; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_remove: exit %p\n", ap); + + return (code); } int @@ -634,20 +759,23 @@ afs_nbsd_link(void *v) struct vnode *dvp = ap->a_dvp; struct vnode *vp = ap->a_vp; + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_link: enter %p\n", ap); + GETNAME(); if (dvp->v_mount != vp->v_mount) { - VOP_ABORTOP(vp, cnp); - code = EXDEV; - goto out; + VOP_ABORTOP(vp, cnp); + code = EXDEV; + goto out; } if (vp->v_type == VDIR) { - VOP_ABORTOP(vp, cnp); - code = EISDIR; - goto out; + VOP_ABORTOP(vp, cnp); + code = EISDIR; + goto out; } if ((code = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY))) { - VOP_ABORTOP(dvp, cnp); - goto out; + VOP_ABORTOP(dvp, cnp); + goto out; } AFS_GLOCK(); @@ -655,12 +783,16 @@ afs_nbsd_link(void *v) AFS_GUNLOCK(); DROPCNP(cnp); if (dvp != vp) - VOP_UNLOCK(vp, 0); + VOP_UNLOCK(vp, 0); out: vput(dvp); DROPNAME(); - return code; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_link: exit %p\n", ap); + + return (code); } int @@ -684,24 +816,27 @@ afs_nbsd_rename(void *v) struct vnode *fvp = ap->a_fvp; struct vnode *fdvp = ap->a_fdvp; + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_rename: enter %p\n", ap); + /* * Check for cross-device rename. */ if ((fvp->v_mount != tdvp->v_mount) - || (tvp && (fvp->v_mount != tvp->v_mount))) { - code = EXDEV; - abortit: - VOP_ABORTOP(tdvp, tcnp); /* XXX, why not in NFS? */ - if (tdvp == tvp) - vrele(tdvp); - else - vput(tdvp); - if (tvp) - vput(tvp); - VOP_ABORTOP(fdvp, fcnp); /* XXX, why not in NFS? */ - vrele(fdvp); - vrele(fvp); - return (code); + || (tvp && (fvp->v_mount != tvp->v_mount))) { + code = EXDEV; + abortit: + VOP_ABORTOP(tdvp, tcnp); /* XXX, why not in NFS? */ + if (tdvp == tvp) + vrele(tdvp); + else + vput(tdvp); + if (tvp) + vput(tvp); + VOP_ABORTOP(fdvp, fcnp); /* XXX, why not in NFS? */ + vrele(fdvp); + vrele(fvp); + goto out; } /* * if fvp == tvp, we're just removing one name of a pair of @@ -709,30 +844,31 @@ afs_nbsd_rename(void *v) ( (pinched from NetBSD 1.0's ufs_rename()) */ if (fvp == tvp) { - if (fvp->v_type == VDIR) { - code = EINVAL; - goto abortit; - } - - /* Release destination completely. */ - VOP_ABORTOP(tdvp, tcnp); - vput(tdvp); - vput(tvp); - - /* Delete source. */ - vrele(fdvp); - vrele(fvp); - fcnp->cn_flags &= ~MODMASK; - fcnp->cn_flags |= LOCKPARENT | LOCKLEAF; - if ((fcnp->cn_flags & SAVESTART) == 0) - panic("afs_rename: lost from startdir"); - fcnp->cn_nameiop = DELETE; - (void)relookup(fdvp, &fvp, fcnp); - return (VOP_REMOVE(fdvp, fvp, fcnp)); + if (fvp->v_type == VDIR) { + code = EINVAL; + goto abortit; + } + + /* Release destination completely. */ + VOP_ABORTOP(tdvp, tcnp); + vput(tdvp); + vput(tvp); + + /* Delete source. */ + vrele(fdvp); + vrele(fvp); + fcnp->cn_flags &= ~MODMASK; + fcnp->cn_flags |= LOCKPARENT | LOCKLEAF; + if ((fcnp->cn_flags & SAVESTART) == 0) + panic("afs_rename: lost from startdir"); + fcnp->cn_nameiop = DELETE; + (void)relookup(fdvp, &fvp, fcnp); + code = VOP_REMOVE(fdvp, fvp, fcnp); + goto out; } if ((code = vn_lock(fvp, LK_EXCLUSIVE | LK_RETRY))) - goto abortit; + goto abortit; /* XXX GETNAME() ? */ MALLOC(fname, char *, fcnp->cn_namelen + 1, M_TEMP, M_WAITOK); @@ -742,28 +878,32 @@ afs_nbsd_rename(void *v) bcopy(tcnp->cn_nameptr, tname, tcnp->cn_namelen); tname[tcnp->cn_namelen] = '\0'; - AFS_GLOCK(); /* XXX use "from" or "to" creds? NFS uses "to" creds */ code = - afs_rename(VTOAFS(fdvp), fname, VTOAFS(tdvp), tname, - tcnp->cn_cred); + afs_rename(VTOAFS(fdvp), fname, VTOAFS(tdvp), tname, + tcnp->cn_cred); AFS_GUNLOCK(); VOP_UNLOCK(fvp, 0); FREE(fname, M_TEMP); FREE(tname, M_TEMP); if (code) - goto abortit; /* XXX */ + goto abortit; /* XXX */ if (tdvp == tvp) - vrele(tdvp); + vrele(tdvp); else - vput(tdvp); + vput(tdvp); if (tvp) - vput(tvp); + vput(tvp); vrele(fdvp); vrele(fvp); - return code; + + out: + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_rename: exit %p\n", ap); + + return (code); } int @@ -780,29 +920,37 @@ afs_nbsd_mkdir(void *v) int code; struct vcache *vcp; + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_mkdir: enter %p\n", ap); + GETNAME(); #ifdef DIAGNOSTIC if ((cnp->cn_flags & HASBUF) == 0) - panic("afs_nbsd_mkdir: no name"); + panic("afs_nbsd_mkdir: no name"); #endif AFS_GLOCK(); code = afs_mkdir(VTOAFS(dvp), name, vap, &vcp, cnp->cn_cred); AFS_GUNLOCK(); if (code) { - VOP_ABORTOP(dvp, cnp); - vput(dvp); - DROPNAME(); - return (code); + VOP_ABORTOP(dvp, cnp); + vput(dvp); + DROPNAME(); + goto out; } if (vcp) { - *ap->a_vpp = AFSTOV(vcp); - vn_lock(AFSTOV(vcp), LK_EXCLUSIVE | LK_RETRY); + *ap->a_vpp = AFSTOV(vcp); + vn_lock(AFSTOV(vcp), LK_EXCLUSIVE | LK_RETRY); } else - *ap->a_vpp = 0; + *ap->a_vpp = 0; DROPCNP(cnp); DROPNAME(); vput(dvp); - return code; + + out: + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_mkdir: exit %p\n", ap); + + return (code); } int @@ -817,13 +965,17 @@ afs_nbsd_rmdir(void *v) struct vnode *vp = ap->a_vp; struct vnode *dvp = ap->a_dvp; + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_rmdir: enter %p", ap); + GETNAME(); if (dvp == vp) { - vrele(dvp); - vput(vp); - DROPCNP(cnp); - DROPNAME(); - return (EINVAL); + vrele(dvp); + vput(vp); + DROPCNP(cnp); + DROPNAME(); + code = EINVAL; + goto out; } AFS_GLOCK(); @@ -832,7 +984,12 @@ afs_nbsd_rmdir(void *v) DROPNAME(); vput(dvp); vput(vp); - return code; + + out: + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_rmdir: exit %p\n", ap); + + return (code); } int @@ -849,6 +1006,9 @@ afs_nbsd_symlink(void *v) int code; /* NFS ignores a_vpp; so do we. */ + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_symlink: enter %p\n", ap); + GETNAME(); AFS_GLOCK(); code = @@ -858,7 +1018,86 @@ afs_nbsd_symlink(void *v) DROPCNP(cnp); DROPNAME(); vput(dvp); - return code; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_symlink: exit %p\n", ap); + + return (code); +} + +int +nbsd_fake_readdir(struct vnode *vp, struct vcache *vc, struct uio *auio, + kauth_cred_t acred, int *a_eofflag, int *a_ncookies, + u_long **a_cookies) +{ + static int ino = 2; + afs_int32 code, maxb; + struct dirent *dp; + maxb = auio->uio_resid; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_fake_readdir: enter vp %p vc %p acred %p auio %p " + "uio_offset %d uio_resid %d\n", + vp, vc, acred, auio, (int) auio->uio_offset, + (int) auio->uio_resid); + + /* 1. simply returning 0 had good behavior (/afs is empty) */ + +/* +(gdb) p *auio +$5 = {uio_iov = 0xcbd0ec90, uio_iovcnt = 1, uio_offset = 0, uio_resid = 4096, + uio_rw = UIO_READ, uio_vmspace = 0xcbe8beec} +*/ + /* ok. we don't know about cookies, so since auio->uio_resid is 4096, + * what we can legitimately do is move as many appropriately aligned + * NetBSD dirent records into uio_iov[0] as will fit in the total size + * of 4KB. We do not need to zero-fill anything. This does not + * terminate the directly listing. If we return 0, VFS will re-enter + * nbsd_readdir to continue reading--to termiate the iteration, we must + * return a non-zero value from nbsd_readdir. VOP_READDIR(9) appears to + * suggest that enumeration is terminated by setting a_eofflag = 1, + * but as noted there this -can- only be done if VFS passed a value for + * a_eofflag--apparently, this is to do with NFS. Setting the eof is + * correct but insufficient. */ + + /* 2. next, let's move ONE entry in by hand--due to termination + * rules, this will actually create file_1 .. file_99 and many + * unecessary nbsd_readdir invocations. The solution to this is to + * make proper use of auio->uio_offset and auio->uio_resid, together + * when accounting bytes moved each invocation, allowing VFS to + * invoke nbsd_readdir at successive offsets until we have consumed + * all entries in all chunks of the vnode being read--setting a_eofflag + * when this is done. + */ + + /* this isn't thread safe--we would in fact use incoming offset + * to select the offset of the next AFS dirent, read it, then take + * its values for (modulo volume) inode number and name */ + if (auio->uio_offset == 0) + ino = 2; + + dp = (struct dirent *) kmem_zalloc(sizeof(struct dirent), KM_SLEEP); + dp->d_ino = ino; + dp->d_type = DT_REG; + sprintf(dp->d_name, "file_%d", ino); + dp->d_namlen = strlen(dp->d_name); + dp->d_reclen = _DIRENT_SIZE(dp); /* comp reclen from d_namlen and align */ + printf("nbsd_fake_readdir: add dirent %s\n", dp->d_name); + code = uiomove(dp, dp->d_reclen, auio); + if (code) + printf("nbsd_fake_readdir: uiomove FAILED\n"); + kmem_free(dp, sizeof(struct dirent)); + ++ino; + + /* terminate enumeration */ + if (!code) + if (ino > 100) { + code = EINVAL; + if(a_eofflag) + *a_eofflag = 1; + } + + return (code); } int @@ -873,20 +1112,30 @@ afs_nbsd_readdir(void *v) * u_long **a_cookies; * } */ *ap = v; int code; + struct vnode *vp = ap->a_vp; + struct vcache *vc = VTOAFS(vp); + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_readdir: enter vp %p vc %p acred %p auio %p\n", vp, vc, + ap->a_cred, ap->a_uio); AFS_GLOCK(); #ifdef AFS_HAVE_COOKIES printf("readdir %p cookies %p ncookies %d\n", ap->a_vp, ap->a_cookies, - ap->a_ncookies); + ap->a_ncookies); code = - afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, ap->a_eofflag, + afs_readdir(vc, ap->a_uio, ap->a_cred, ap->a_eofflag, ap->a_ncookies, ap->a_cookies); #else code = - afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, ap->a_eofflag); + afs_readdir(vc, ap->a_uio, ap->a_cred, ap->a_eofflag); #endif AFS_GUNLOCK(); - return code; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_readdir: exit %p eofflag %d\n", ap, *ap->a_eofflag); + + return (code); } int @@ -899,10 +1148,17 @@ afs_nbsd_readlink(void *v) * } */ *ap = v; int code; + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_readlink: enter %p\n", ap); + AFS_GLOCK(); code = afs_readlink(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred); AFS_GUNLOCK(); - return code; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_readlink: exit %p\n", ap); + + return (code); } extern int prtactive; @@ -919,17 +1175,28 @@ afs_nbsd_inactive(void *v) AFS_STATCNT(afs_inactive); + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_inactive: enter %p\n", ap); + if (prtactive && vp->v_usecount != 0) - vprint("afs_nbsd_inactive(): pushing active", vp); + vprint("afs_nbsd_inactive: pushing active", vp); if (!haveGlock) - AFS_GLOCK(); + AFS_GLOCK(); afs_InactiveVCache(vc, 0); /* decrs ref counts */ if (!haveGlock) - AFS_GUNLOCK(); + AFS_GUNLOCK(); +#ifdef AFS_NBSD50_ENV + mutex_init(&vc->rwlock, MUTEX_DEFAULT, IPL_NONE); +#else lockinit(&vc->rwlock, PINOD, "vcache", 0, 0); - return 0; +#endif + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_inactive: exit %p\n", ap); + + return (0); } int @@ -944,26 +1211,41 @@ afs_nbsd_reclaim(void *v) int haveGlock = ISAFS_GLOCK(); int haveVlock = CheckLock(&afs_xvcache); + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_reclaim: enter %p\n", ap); + #if 0 printf("reclaim usecount %d\n", vp->v_usecount); /* OK, there are no internal vrefCounts, so there shouldn't * be any more refs here. */ vp->v_data = NULL; /* remove from vnode */ avc->v = NULL; /* also drop the ptr to vnode */ - return 0; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_reclaim: exit %p\n", ap); + + return (0); #else if (!haveGlock) - AFS_GLOCK(); + AFS_GLOCK(); if (!haveVlock) - ObtainWriteLock(&afs_xvcache, 901); + ObtainWriteLock(&afs_xvcache, 901); +#ifndef AFS_DISCON_ENV + code = afs_FlushVCache(avc, &slept); /* tosses our stuff from vnode */ +#else /* reclaim the vnode and the in-memory vcache, but keep the on-disk vcache */ code = afs_FlushVCache(avc, &slept); +#endif if (!haveVlock) - ReleaseWriteLock(&afs_xvcache); + ReleaseWriteLock(&afs_xvcache); if (!haveGlock) - AFS_GUNLOCK(); + AFS_GUNLOCK(); + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_reclaim: exit %p\n", ap); + return code; -#endif +#endif /* 0 */ } int @@ -974,8 +1256,19 @@ afs_nbsd_lock(void *v) * int a_flags; * struct lwp *a_l; * } */ *ap = v; + int code; + struct vnode *vp = ap->a_vp; + int flags = ap->a_flags; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_lock: enter vp %p flags %d\n", vp, flags); - return (genfs_lock(v)); + code = genfs_lock(v); + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_lock: exit vp %p flags %d\n\n", vp, flags); + + return (code); } int @@ -986,10 +1279,43 @@ afs_nbsd_unlock(void *v) * int a_flags; * struct lwp *a_l; * } */ *ap = v; + int code; + struct vnode *vp = ap->a_vp; + int flags = ap->a_flags; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_unlock: enter vp %p flags %d\n", vp, flags); + + code = genfs_unlock(v); + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_unlock: exit vp %p flags %d\n", vp, flags); + + return (code); +} + +int +afs_nbsd_islocked(void *v) +{ + struct vop_islocked_args /* { + * struct vnode *a_vp; + * } */ *ap = v; + + int code; + struct vnode *vp = ap->a_vp; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_islocked: enter vp %p flags %d\n", vp); - return (genfs_unlock(v)); + code = genfs_islocked(v); + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_islocked: exit vp %p flags %d\n", vp); + + return (code); } + int afs_nbsd_bmap(void *v) { @@ -1004,21 +1330,25 @@ afs_nbsd_bmap(void *v) AFS_STATCNT(afs_bmap); + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_bmap: enter %p\n", ap); + /* borrowed from DARWIN--why notyet? */ - if (ap->a_bnp) { - *ap->a_bnp = ap->a_bn * (PAGE_SIZE / DEV_BSIZE); - } - if (ap->a_vpp) { - *ap->a_vpp = ap->a_vp; - } + if (ap->a_bnp) + *ap->a_bnp = ap->a_bn * (PAGE_SIZE / DEV_BSIZE); + if (ap->a_vpp) + *ap->a_vpp = ap->a_vp; if (ap->a_runp != NULL) - *ap->a_runp = 0; + *ap->a_runp = 0; #ifdef notyet if (ap->a_runb != NULL) - *ap->a_runb = 0; + *ap->a_runb = 0; #endif - return 0; + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_bmap: exit %p\n", ap); + + return (0); } int @@ -1037,26 +1367,46 @@ afs_nbsd_strategy(void *v) AFS_STATCNT(afs_strategy); + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_strategy: enter %p\n", ap); + tuio.afsio_iov = tiovec; tuio.afsio_iovcnt = 1; tuio.afsio_resid = len; +/* + * b_un was removed in NBSD50...there's no true substitute for the + * b_addr that was in it, but b_blkno is the closest. + * mattjsm + */ +#ifdef AFS_NBSD50_ENV + tiovec[0].iov_base = abp->b_blkno; +#else tiovec[0].iov_base = abp->b_un.b_addr; +#endif tiovec[0].iov_len = len; UIO_SETUP_SYSSPACE(&tuio); AFS_GLOCK(); if ((abp->b_flags & B_READ) == B_READ) { - code = afs_rdwr(tvc, &tuio, UIO_READ, 0, credp); - if (code == 0 && tuio.afsio_resid > 0) - bzero(abp->b_un.b_addr + len - tuio.afsio_resid, - tuio.afsio_resid); - } else - code = afs_rdwr(tvc, &tuio, UIO_WRITE, 0, credp); + code = afs_rdwr(tvc, &tuio, UIO_READ, 0, credp); + if (code == 0 && tuio.afsio_resid > 0) +#ifdef AFS_NBSD50_ENV + bzero(abp->b_blkno + len - tuio.afsio_resid, +#else + bzero(abp->b_un.b_addr + len - tuio.afsio_resid, +#endif + tuio.afsio_resid); + } else + code = afs_rdwr(tvc, &tuio, UIO_WRITE, 0, credp); AFS_GUNLOCK(); ReleaseWriteLock(&tvc->lock); AFS_RELE(AFSTOV(tvc)); - return code; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_strategy: exit %p\n", ap); + + return (code); } int @@ -1071,18 +1421,13 @@ afs_nbsd_print(void *v) printf("tag %d, fid: %d.%x.%x.%x, ", vp->v_tag, vc->f.fid.Cell, (int)vc->f.fid.Fid.Volume, (int)vc->f.fid.Fid.Vnode, (int)vc->f.fid.Fid.Unique); +#ifdef AFS_NBSD50_ENV + mutex_owned(&vc->rwlock); +#else lockmgr_printinfo(&vc->rwlock); +#endif printf("\n"); - return 0; -} - -int -afs_nbsd_islocked(void *v) -{ - struct vop_islocked_args /* { - * struct vnode *a_vp; - * } */ *ap = v; - return (genfs_islocked(v)); + return (0); } /* @@ -1096,30 +1441,43 @@ afs_nbsd_pathconf(void *v) * int a_name; * int *a_retval; * } */ *ap = v; + int code = 0; + AFS_STATCNT(afs_cntl); + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_pathconf: enter %p\n", ap); + switch (ap->a_name) { case _PC_LINK_MAX: - *ap->a_retval = LINK_MAX; - break; + *ap->a_retval = LINK_MAX; + break; case _PC_NAME_MAX: - *ap->a_retval = NAME_MAX; - break; + *ap->a_retval = NAME_MAX; + break; case _PC_PATH_MAX: - *ap->a_retval = PATH_MAX; - break; + *ap->a_retval = PATH_MAX; + break; case _PC_CHOWN_RESTRICTED: - *ap->a_retval = 1; - break; + *ap->a_retval = 1; + break; case _PC_NO_TRUNC: - *ap->a_retval = 1; - break; + *ap->a_retval = 1; + break; case _PC_PIPE_BUF: - return EINVAL; - break; + code = EINVAL; + goto out; + break; default: - return EINVAL; + code = EINVAL; + goto out; } - return 0; + +out: + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_pathconf: exit %p\n", ap); + + return (0); } extern int @@ -1141,10 +1499,17 @@ afs_nbsd_advlock(void *v) * } */ *ap = v; int code; + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_pathconf: enter %p\n", ap); + AFS_GLOCK(); code = - afs_lockctl(VTOAFS(ap->a_vp), ap->a_fl, ap->a_op, osi_curcred(), - (int)ap->a_id); + afs_lockctl(VTOAFS(ap->a_vp), ap->a_fl, ap->a_op, osi_curcred(), + (int)ap->a_id); AFS_GUNLOCK(); - return code; + + if (afs_debug & AFSDEB_VNLAYER) + printf("nbsd_pathconf: exit %p\n", ap); + + return (code); } diff --git a/src/afs/VNOPS/afs_vnop_attrs.c b/src/afs/VNOPS/afs_vnop_attrs.c index b3931e546..6aebeaa7c 100644 --- a/src/afs/VNOPS/afs_vnop_attrs.c +++ b/src/afs/VNOPS/afs_vnop_attrs.c @@ -299,8 +299,10 @@ afs_getattr(OSI_VC_DECL(avc), struct vattr *attrs, afs_ucred_t *acred) } #else if ( -#ifdef AFS_DARWIN_ENV +#if defined(AFS_DARWIN_ENV) vnode_isvroot(AFSTOV(avc)) +#elif defined(AFS_NBSD50_ENV) + AFSTOV(avc)->v_vflag & VV_ROOT #else AFSTOV(avc)->v_flag & VROOT #endif diff --git a/src/afs/VNOPS/afs_vnop_readdir.c b/src/afs/VNOPS/afs_vnop_readdir.c index 1c494bd9a..b39423953 100644 --- a/src/afs/VNOPS/afs_vnop_readdir.c +++ b/src/afs/VNOPS/afs_vnop_readdir.c @@ -503,13 +503,27 @@ afs_readdir_move(struct DirEntry *de, struct vcache *vc, struct uio *auio, #if defined(AFS_NBSD40_ENV) { struct dirent *dp; - dp = (struct dirent *) pool_get(&ufs_direct_pool, PR_WAITOK); - dp->d_ino = (Volume << 16) + ntohl(Vnode); - FIXUPSTUPIDINODE(dp->d_ino); - dp->d_reclen = rlen; - strcpy(dp->d_name, de->name); - AFS_UIOMOVE((char*) dp, sizeof(struct dirent), UIO_READ, auio, code); - pool_put(&ufs_direct_pool, dp); + dp = (struct dirent *) +#if defined(AFS_NBSD50_ENV) + osi_AllocLargeSpace(AFS_LRALLOCSIZ); +#else + pool_get(&ufs_direct_pool, PR_WAITOK); +#endif + memset(dp, 0, sizeof(struct dirent)); + dp->d_ino = (Volume << 16) + ntohl(Vnode); + FIXUPSTUPIDINODE(dp->d_ino); + dp->d_namlen = slen; + dp->d_type = afs_readdir_type(vc, de); + strcpy(dp->d_name, de->name); + dp->d_reclen = _DIRENT_SIZE(dp) /* rlen */; + afs_warn("afs_readdir_move %s type %d slen %d rlen %d act. rlen %d\n", + dp->d_name, dp->d_type, slen, rlen, _DIRENT_SIZE(dp)); + AFS_UIOMOVE((char*) dp, sizeof(struct dirent), UIO_READ, auio, code); +#if defined(AFS_NBSD50_ENV) + osi_FreeLargeSpace((char *)dp); +#else + pool_put(&ufs_direct_pool, dp); +#endif } #else AFS_UIOMOVE((char *) &sdirEntry, sizeof(sdirEntry), UIO_READ, auio, code); diff --git a/src/afs/VNOPS/afs_vnop_strategy.c b/src/afs/VNOPS/afs_vnop_strategy.c index eed0e136a..44532f287 100644 --- a/src/afs/VNOPS/afs_vnop_strategy.c +++ b/src/afs/VNOPS/afs_vnop_strategy.c @@ -190,7 +190,7 @@ int afs_ustrategy(struct buf *abp) #if defined (AFS_XBSD_ENV) if (code) { abp->b_error = code; -#if !defined(AFS_FBSD_ENV) +#if !defined(AFS_FBSD_ENV) && !defined(AFS_NBSD50_ENV) abp->b_flags |= B_ERROR; #endif } diff --git a/src/afs/afs.h b/src/afs/afs.h index f1285bc0c..08a2e7600 100644 --- a/src/afs/afs.h +++ b/src/afs/afs.h @@ -807,7 +807,9 @@ struct vcache { struct lock__bsd__ rwlock; #endif #ifdef AFS_XBSD_ENV -#if !defined(AFS_DFBSD_ENV) +# if defined(AFS_NBSD50_ENV) + struct krwlock rwlock; +# elif !defined(AFS_DFBSD_ENV) struct lock rwlock; #endif #endif diff --git a/src/afs/afs_call.c b/src/afs/afs_call.c index 909fb5c46..7bade4fdf 100644 --- a/src/afs/afs_call.c +++ b/src/afs/afs_call.c @@ -214,7 +214,6 @@ afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5, int code; struct afsd_thread_info info; thread_t thread; - if (parm == AFSOP_START_RXCALLBACK) { if (afs_CB_Running) return; @@ -581,7 +580,7 @@ afs_syscall_call(long parm, long parm2, long parm3, #endif /* !RXK_LISTENER_ENV */ { #ifdef RXK_LISTENER_ENV - while (afs_RX_Running != 2) + while (afs_RX_Running != 2) afs_osi_Sleep(&afs_RX_Running); #else /* !RXK_LISTENER_ENV */ afs_initState = AFSOP_START_AFS; diff --git a/src/afs/afs_daemons.c b/src/afs/afs_daemons.c index 81f9c5c14..fb89d44fb 100644 --- a/src/afs/afs_daemons.c +++ b/src/afs/afs_daemons.c @@ -181,6 +181,26 @@ afs_Daemon(void) if (afs_nfsexporter) afs_FlushActiveVcaches(0); /* flush NFS writes */ afs_FlushVCBs(1); /* flush queued callbacks */ + +#if defined(AFS_NBSD50_ENV) + /* XXXX */ + { + int c1, c2; + c1 = ISAFS_GLOCK(); /* this thread owns the GLOCK */ + if (!c1) { + c2 = mutex_tryenter(&afs_global_mtx); /* not held either */ + if (c2) + AFS_GUNLOCK(); + } + else + c2 = 0; + printf("afs_daemons periodic glock check: curthread owns glock %s; " + "glock held somewhere %s\n", + c1 ? "true" : "false", + c2 ? "true" : "false"); + } +#endif + afs_MaybeWakeupTruncateDaemon(); /* free cache space if have too */ rx_CheckPackets(); /* Does RX need more packets? */ diff --git a/src/afs/afs_osi.c b/src/afs/afs_osi.c index 4cece9823..d2fafff07 100644 --- a/src/afs/afs_osi.c +++ b/src/afs/afs_osi.c @@ -54,8 +54,12 @@ struct lock__bsd__ afs_global_lock; #endif #if defined(AFS_XBSD_ENV) && !defined(AFS_FBSD_ENV) +# if defined(AFS_NBSD50_ENV) +struct kmutex afs_global_mtx; +# else struct lock afs_global_lock; afs_proc_t *afs_global_owner; +# endif #elif defined(AFS_FBSD_ENV) struct mtx afs_global_mtx; struct thread *afs_global_owner; @@ -163,6 +167,8 @@ afs_osi_Invisible(void) #elif defined(AFS_DARWIN_ENV) /* maybe call init_process instead? */ current_proc()->p_flag |= P_SYSTEM; +#elif defined(AFS_NBSD50_ENV) + /* XXX in netbsd a system thread is more than invisible */ #elif defined(AFS_XBSD_ENV) curproc->p_flag |= P_SYSTEM; #elif defined(AFS_SGI_ENV) @@ -181,6 +187,8 @@ afs_osi_Visible(void) #elif defined(AFS_DARWIN_ENV) /* maybe call init_process instead? */ current_proc()->p_flag &= ~P_SYSTEM; +#elif defined(AFS_NBSD50_ENV) + /* XXX in netbsd a system thread is more than invisible */ #elif defined(AFS_XBSD_ENV) curproc->p_flag &= ~P_SYSTEM; #endif diff --git a/src/afs/afs_osi.h b/src/afs/afs_osi.h index b5e3b8f3a..5d0bdc925 100644 --- a/src/afs/afs_osi.h +++ b/src/afs/afs_osi.h @@ -37,6 +37,13 @@ struct xfs_inode_info { #include "h/mm.h" #endif +#if defined(AFS_NBSD50_ENV) +# if !defined(DEF_CADDR_T) +typedef char * caddr_t; +#define DEF_CADDR_T +# endif +#endif + /* this is just a dummy type decl, we're really using struct sockets here */ struct osi_socket { @@ -368,7 +375,7 @@ typedef struct timeval osi_timeval_t; uio_setrw((UIO),(RW)); \ CODE = uiomove((SRC),(LEN),(UIO)); \ } while(0) -#elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) +#elif defined(AFS_DARWIN_ENV) || (defined(AFS_XBSD_ENV) && !defined(AFS_NBSD40_ENV)) #define AFS_UIOMOVE(SRC,LEN,RW,UIO,CODE) \ do { \ (UIO)->uio_rw = (RW); \ diff --git a/src/afs/afs_osi_alloc.c b/src/afs/afs_osi_alloc.c index 676d523eb..6855afa62 100644 --- a/src/afs/afs_osi_alloc.c +++ b/src/afs/afs_osi_alloc.c @@ -40,7 +40,7 @@ struct osimem { struct osimem *next; }; -#if !defined(AFS_NBSD_ENV) +#if !defined(AFS_NBSD_ENV) || defined(AFS_NBSD50_ENV) void * afs_osi_Alloc(size_t x) { @@ -218,7 +218,7 @@ osi_AllocSmallSpace(size_t size) return (char *)tp; } -#endif /* !AFS_NBSD_ENV */ +#endif /* !AFS_NBSD_ENV && !defined(AFS_NBSD50_ENV) */ void shutdown_osinet(void) diff --git a/src/afs/afs_syscall.c b/src/afs/afs_syscall.c index 42989a127..9eb70f7e7 100644 --- a/src/afs/afs_syscall.c +++ b/src/afs/afs_syscall.c @@ -784,10 +784,11 @@ Afs_syscall() iparams.param2, iparams.param3, iparams.param4, rvp, CRED()); #elif defined(AFS_NBSD40_ENV) - - code = afs_syscall_create(SCARG(uap, parm1), SCARG(uap, parm2), - SCARG(uap, parm3), SCARG(uap, parm4), - retval); + code = + afs_syscall_icreate(SCARG(uap, parm1), SCARG(uap, parm2), + iparams.param1, iparams.param2, iparams.param3, + iparams.param4, retval + ); #else code = afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1, diff --git a/src/afs/sysincludes.h b/src/afs/sysincludes.h index 916d02a30..35e523d0f 100644 --- a/src/afs/sysincludes.h +++ b/src/afs/sysincludes.h @@ -52,6 +52,9 @@ # include #elif defined(AFS_NBSD40_ENV) +# ifdef AFS_NBSD50_ENV +# include +# endif # include # include # include /* may define MOUNT_AFS */ diff --git a/src/afsd/afsd.c b/src/afsd/afsd.c index 712318fbf..84bbf0a03 100644 --- a/src/afsd/afsd.c +++ b/src/afsd/afsd.c @@ -1932,7 +1932,7 @@ afsd_run(void) int vFilesFound; /*How many data cache files were found in sweep */ int currVFile; /*Current AFS cache file number passed in */ - /* + /* * Pull out all the configuration info for the workstation's AFS cache and * the cellular community we're willing to let our users see. */ @@ -2170,7 +2170,7 @@ afsd_run(void) if (code > 0) { if (enable_rxbind) code = code | 0x80000000; - afsd_call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf); + afsd_call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf); } else printf("ADVISEADDR: Error in specifying interface addresses:%s\n", reason); @@ -2222,7 +2222,6 @@ afsd_run(void) printf("%s: Forking AFSDB lookup handler.\n", rn); afsd_fork(0, afsdb_thread, NULL); } - code = afsd_call_syscall(AFSOP_BASIC_INIT, 1); if (code) { printf("%s: Error %d in basic initialization.\n", rn, code); @@ -2247,7 +2246,7 @@ afsd_run(void) cparams.setTimeFlag = cacheSetTime; cparams.memCacheFlag = cacheFlags; cparams.dynamic_vcaches = afsd_dynamic_vcaches; - afsd_call_syscall(AFSOP_CACHEINIT, &cparams); + afsd_call_syscall(AFSOP_CACHEINIT, &cparams); /* do it before we init the cache inodes */ if (enable_splitcache) { @@ -2306,7 +2305,7 @@ afsd_run(void) if (afsd_debug) printf("%s: Calling AFSOP_CELLINFO: cell info file is '%s'\n", rn, fullpn_CellInfoFile); - afsd_call_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile); + afsd_call_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile); if (rxmaxmtu) { if (afsd_verbose) @@ -2455,7 +2454,7 @@ afsd_run(void) if (afsd_debug) printf("%s: Calling AFSOP_GO with cacheSetTime = %d\n", rn, cacheSetTime); - afsd_call_syscall(AFSOP_GO, cacheSetTime); + afsd_call_syscall(AFSOP_GO, cacheSetTime); /* * At this point, we have finished passing the kernel all the info diff --git a/src/afsd/afsd_kernel.c b/src/afsd/afsd_kernel.c index c5c457ed8..35f3eaa1f 100644 --- a/src/afsd/afsd_kernel.c +++ b/src/afsd/afsd_kernel.c @@ -225,7 +225,7 @@ afsd_call_syscall(long param1, long param2, long param3, long param4, long param error=syscall_data.retval; } # else /* AFS_DARWIN80_ENV */ - error = + error = syscall(AFS_SYSCALL, AFSCALL_CALL, param1, param2, param3, param4, param5, param6, param7); # endif /* !AFS_DARWIN80_ENV */ diff --git a/src/config/param.nbsd50.h b/src/config/param.nbsd50.h index 35e515512..59458b896 100644 --- a/src/config/param.nbsd50.h +++ b/src/config/param.nbsd50.h @@ -11,10 +11,27 @@ #define AFS_MOUNT_AFS "afs" /* The name of the filesystem type. */ #define AFS_SYSCALL 210 + +#ifdef AFS_KALLOC +#undef AFS_KALLOC +#endif +#define AFS_KALLOC(s) (osi_nbsd_Alloc((s), 1 /* cansleep */)) + +#ifdef AFS_KFREE +#undef AFS_KFREE +#endif +#define AFS_KFREE(p, s) (osi_nbsd_Free((p), (s))) + +#if 0 +/* including this file before sysincludes.h is canonical, but + * NBSD40's mount.h defines MOUNT_AFS */ + #ifndef MOUNT_AFS #define MOUNT_AFS AFS_MOUNT_AFS #endif +#endif /* 0 */ + #define AFS_XBSD_ENV 1 /* {Free,Open,Net}BSD */ #define AFS_NBSD_ENV 1 @@ -48,10 +65,7 @@ #define ICHG 0x0040 #define IMOD 0x0080 -#define IN_LOCK(ip) lockmgr(&ip->i_lock, LK_EXCLUSIVE, \ - NULL, curproc) -#define IN_UNLOCK(ip) lockmgr(&ip->i_lock, LK_RELEASE, \ - NULL, curproc) +#define RXK_LISTENER_ENV 1 #include @@ -61,10 +75,10 @@ #define AFS_GCPAGS 0 /* if nonzero, garbage collect PAGs */ #define AFS_USE_GETTIMEOFDAY 1 /* use gettimeofday to implement rx clock */ +#define AFS_GLOBAL_SUNLOCK 1 /* Extra kernel definitions (from kdefs file) */ -#ifdef _KERNEL -#define AFS_GLOBAL_SUNLOCK 1 +#ifdef _KERNEL_DEPRECATED #define AFS_VFS34 1 /* What is VFS34??? */ #define AFS_SHORTGID 1 /* are group id's short? */ #define afsio_iov uio_iov @@ -85,7 +99,6 @@ #define va_nodeid va_fileid #define vfs_vnodecovered mnt_vnodecovered #define direct dirent -#define vnode_t struct vnode #ifndef MUTEX_DEFAULT #define MUTEX_DEFAULT 0 @@ -113,7 +126,7 @@ enum vcexcl { NONEXCL, EXCL }; #endif /* KERNEL */ #endif /* ! ASSEMBLER & ! __LANGUAGE_ASSEMBLY__ && !defined(IGNORE_STDS_H) */ -#endif /* _KERNEL */ +#endif /* _KERNEL_DEPRECATED */ #else /* !defined(UKERNEL) */ @@ -145,7 +158,7 @@ enum vcexcl { NONEXCL, EXCL }; #define CMSERVERPREF #endif -#if !defined(ASSEMBLER) && !defined(__LANGUAGE_ASSEMBLY__) && !defined(IGNORE_STDS_H) +#if !defined(ASSEMBLER) && !defined(__LANGUAGE_ASSEMBLY__) && !defined(IGNORE_STDS_H) && !defined() #include #include #include diff --git a/src/config/stds.h b/src/config/stds.h index 55350a743..be6d8334e 100644 --- a/src/config/stds.h +++ b/src/config/stds.h @@ -313,7 +313,7 @@ typedef struct afsUUID afsUUID; #elif defined(AFS_SGI_ENV) || defined(AFS_USR_SGI_ENV) #define static_inline static #define hdr_static_inline(x) x -#elif defined(AFS_NBSD_ENV) +#elif defined(AFS_NBSD_ENV) && !defined(AFS_NBSD50_ENV) #define static_inline static __inline __attribute__((always_inline)) #define hdr_static_inline(x) static __inline __attribute__((always_inline)) x #else diff --git a/src/fsint/afsaux.c b/src/fsint/afsaux.c index 19c984122..82f60ee8a 100644 --- a/src/fsint/afsaux.c +++ b/src/fsint/afsaux.c @@ -17,6 +17,9 @@ #include "afsincludes.h" #include "rx/xdr.h" #else /* defined(UKERNEL) */ +#if defined(AFS_NBSD50_ENV) +#include "afs/afs_osi.h" +#endif #if defined(AFS_OSF_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) #include "afs/sysincludes.h" #include "afsincludes.h" diff --git a/src/libafs/MakefileProto.NBSD.in b/src/libafs/MakefileProto.NBSD.in index e9005d685..3375c1574 100644 --- a/src/libafs/MakefileProto.NBSD.in +++ b/src/libafs/MakefileProto.NBSD.in @@ -35,14 +35,17 @@ AFS_OS_NONFSOBJS = \ # System specific build commands and flags KSRC = @BSD_KERNEL_PATH@ KBLD = @BSD_KERNEL_BUILD@ -KARCHFLAGS = -march=pentiumpro -mtune=pentiumpro -mtune=pentiumpro +KARCHFLAGS = -Di386 -march=pentiumpro -mtune=pentiumpro KOPTFLAGS = -D_KERNEL -DLKM -D_LKM -DDEBUG -DLOCKDEBUG KDEFS=-Wall -ansi -nostdinc -I/usr/include \ ${KARCHFLAGS} ${KOPTFLAGS} \ -ffreestanding -Wno-pointer-sign -Wno-strict-aliasing \ + + -std=gnu99 \ + -I${KSRC} -I${KSRC}/sys \ -I${KBLD} -I../afs -DBUG = -O2 +DBUG = -O2 -g3 DEFINES= -DAFSDEBUG -DKERNEL -DAFS -DVICE -DNFS -DUFS -DINET -DQUOTA -DGETMOUNT OPTF=${OPT} OPTF2=${OPT2} @@ -75,6 +78,9 @@ setup: -ln -fs ${KSRC}/ufs/ufs ufs -ln -fs ${KSRC}/sys h -ln -fs ${KSRC}/vm vm + -ln -fs ${KSRC}/arch/x86/include/via_padlock.h /usr/include/x86/via_padlock.h + -ln -fs ${KSRC}/arch/x86/include/cpufunc.h /usr/include/x86/cpufunc.h + -ln -fs ${KSRC}/arch/x86/include/pic.h /usr/include/machine/pic.h -touch $(KOBJ)/sec_net.h @@ -88,14 +94,15 @@ INST_LIBAFSNONFS = ${DESTDIR}${afskerneldir}/${LIBAFSNONFS} DEST_LIBAFS = ${DEST}/root.client/bin/${LIBAFS} DEST_LIBAFSNONFS = ${DEST}/root.client/bin/${LIBAFSNONFS} - + # libafs: $(LIBAFS) $(LIBAFSNONFS) libafs: $(LIBAFSNONFS) # install_libafs: $(INST_LIBAFS) $(INST_LIBAFSNONFS) -install_libafs: $(INST_LIBAFSNONFS) +#install_libafs: $(INST_LIBAFSNONFS) +install_libafs: # dest_libafs: $(DEST_LIBAFS) $(DEST_LIBAFSNONFS) dest_libafs: $(DEST_LIBAFSNONFS) - + libafs: echo WARNING: No kernel module for ${SYS_NAME} @@ -108,7 +115,7 @@ dest_libafs: # for now, just skip it #${LIBAFS}: $(AFSAOBJS) $(AFSNFSOBJS) -# $(LD) -r -o ${LIBAFS} ${AFSAOBJS} ${AFSNFSOBJS} +# $(LD) -r -z muldefs -o ${LIBAFS} ${AFSAOBJS} ${AFSNFSOBJS} ${LIBAFSNONFS}: $(AFSAOBJS) $(AFSNONFSOBJS) - $(LD) -r -o ${LIBAFSNONFS} ${AFSAOBJS} ${AFSNONFSOBJS} + $(LD) -r -z muldefs -o ${LIBAFSNONFS} ${AFSAOBJS} ${AFSNONFSOBJS} diff --git a/src/rx/NBSD/rx_kmutex.h b/src/rx/NBSD/rx_kmutex.h index dd429605d..dc75f2a07 100644 --- a/src/rx/NBSD/rx_kmutex.h +++ b/src/rx/NBSD/rx_kmutex.h @@ -25,7 +25,11 @@ #ifndef _RX_KMUTEX_H_ #define _RX_KMUTEX_H_ +#ifdef AFS_NBSD50_ENV +#include +#else #include +#endif /* You can't have AFS_GLOBAL_SUNLOCK and not RX_ENABLE_LOCKS */ #define RX_ENABLE_LOCKS 1 @@ -76,10 +80,43 @@ typedef int afs_kcondvar_t; typedef struct { - struct lock lock; +#ifdef AFS_NBSD50_ENV + struct kmutex mtx; +#else + struct lock lock; +#endif struct lwp *owner; } afs_kmutex_t; +#ifdef AFS_NBSD50_ENV +#define MUTEX_INIT(a,b,c,d) \ + do { \ + mutex_init(&(a)->mtx, (c), IPL_NONE); \ + } while(0); + +#define MUTEX_DESTROY(a) \ + do { \ + mutex_destroy(&(a)->mtx); \ + } while(0); + +#define MUTEX_ENTER(a) \ + do { \ + mutex_enter(&(a)->mtx); \ + } while(0); + +#define MUTEX_TRYENTER(a) \ + ( mutex_tryenter(&(a)->mtx) ) + +#define MUTEX_EXIT(a) \ + do { \ + mutex_exit(&(a)->mtx); \ + } while(0); + +#define MUTEX_ISMINE(a) \ + ( mutex_owned(&(a)->mtx) ) + +#else /* AFS_NBSD50_ENV */ + #define MUTEX_INIT(a,b,c,d) \ do { \ lockinit(&(a)->lock, PSOCK, "afs rx mutex", 0, 0); \ @@ -89,7 +126,6 @@ typedef struct { do { \ (a)->owner = (struct lwp *)-1; \ } while(0); - #if defined(LOCKDEBUG) #define MUTEX_ENTER(a) \ do { \ @@ -122,10 +158,13 @@ typedef struct { (a)->owner = 0; \ lockmgr(&(a)->lock, LK_RELEASE, 0); \ } while(0); -#endif /* LOCKDEBUG */ +#endif /* LOCKDEBUG */ + #define MUTEX_ISMINE(a) \ (lockstatus(a) == LK_EXCLUSIVE) #define MUTEX_LOCKED(a) \ (lockstatus(a) == LK_EXCLUSIVE) +#endif /* AFS_NBSD50_ENV */ + #endif /* _RX_KMUTEX_H_ */ diff --git a/src/rx/rx_kcommon.c b/src/rx/rx_kcommon.c index bd452a7b2..e2e823c27 100644 --- a/src/rx/rx_kcommon.c +++ b/src/rx/rx_kcommon.c @@ -112,7 +112,7 @@ rxi_GetHostUDPSocket(u_int host, u_short port) sockp = (osi_socket *)rxk_NewSocketHost(host, port); if (sockp == (osi_socket *)0) return OSI_NULLSOCKET; - rxk_AddPort(port, (char *)sockp); + rxk_AddPort(port, (char *)sockp); return (osi_socket) sockp; } @@ -870,6 +870,8 @@ rxk_NewSocketHost(afs_uint32 ahost, short aport) afs_osi_credp, curthread); #elif defined(AFS_DARWIN80_ENV) code = sock_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, NULL, NULL, &newSocket); +#elif defined(AFS_NBSD50_ENV) + code = socreate(AF_INET, &newSocket, SOCK_DGRAM, 0, osi_curproc(), NULL); #elif defined(AFS_NBSD40_ENV) code = socreate(AF_INET, &newSocket, SOCK_DGRAM, 0, osi_curproc()); #else diff --git a/src/rx/rx_packet.c b/src/rx/rx_packet.c index c5ba1621b..f9411c531 100644 --- a/src/rx/rx_packet.c +++ b/src/rx/rx_packet.c @@ -30,7 +30,7 @@ #ifndef AFS_LINUX20_ENV #include "h/systm.h" #endif -#if defined(AFS_SGI_ENV) || defined(AFS_HPUX110_ENV) +#if defined(AFS_SGI_ENV) || defined(AFS_HPUX110_ENV) || defined(AFS_NBSD50_ENV) #include "afs/sysincludes.h" #endif #if defined(AFS_OBSD_ENV) diff --git a/src/rx/xdr.h b/src/rx/xdr.h index 0ad3e34bb..d23e6106c 100644 --- a/src/rx/xdr.h +++ b/src/rx/xdr.h @@ -55,6 +55,13 @@ #endif /* !TRUE */ #define __dontcare__ -1 +#if defined(AFS_NBSD50_ENV) +# if !defined(DEF_CADDR_T) +typedef char * caddr_t; +#define DEF_CADDR_T +# endif +#endif + #ifndef mem_alloc #define mem_alloc(bsize) malloc(bsize) #endif diff --git a/src/util/softsig.c b/src/util/softsig.c index dd3db45c4..6fe861ea1 100644 --- a/src/util/softsig.c +++ b/src/util/softsig.c @@ -72,7 +72,7 @@ softsig_thread(void *arg) while (1) { void (*h) (int); -#if !defined(AFS_DARWIN_ENV) && !defined(AFS_NBSD_ENV) +#if !defined(AFS_DARWIN_ENV) && (!defined(AFS_NBSD_ENV) || defined(AFS_NBSD50_ENV)) int sigw; #endif