From 64cacab28ba7b9692db0b494e2d4399c535bd1ae Mon Sep 17 00:00:00 2001 From: Matt Benjamin Date: Tue, 22 Dec 2009 19:48:02 -0500 Subject: [PATCH] freebsd: track RELENG_8 Fixes to re-enable build and load of kernel module on FreeBSD's RELENG_8. Includes the following changes: Remove cred pointer argument to vop_getattr and vop_setattr. Restore VSUID and VGUID defines, but move to osi_machdep.h. Fixup calls to vinvalbuf, create a macro to avoid too many ifdefs. Revert incorrect definition of gop_lookupname_user. Avoid uninitialized use of 'code' variable in vop_access, and track new a_accmode member name. Remove cred pointer in VFS_STATFS. Avoid including sys/ioctl.h in kernel mode (formerly had no effect, it's now an error). Avoid using an empty file as an object file in shlibafsrpc link. Replace suser() calls with calls to priv_check, using defined OpenAFS privileges (thanks due to Ben Kaduk). Change-Id: I96fc29599a797b975630c8fa5b8b84798b3740a6 Reviewed-on: http://gerrit.openafs.org/1023 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/afs/FBSD/osi_file.c | 8 +++++--- src/afs/FBSD/osi_machdep.h | 34 ++++++++++++++++++++++++++++------ src/afs/FBSD/osi_misc.c | 2 -- src/afs/FBSD/osi_vm.c | 4 ++-- src/afs/FBSD/osi_vnodeops.c | 11 +++++++++-- src/afs/afs_init.c | 2 ++ src/afs/afs_vcache.c | 2 +- src/gtx/curseswindows.c | 2 +- src/shlibafsrpc/Makefile.in | 3 ++- src/util/vice.h | 6 ++++-- 10 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/afs/FBSD/osi_file.c b/src/afs/FBSD/osi_file.c index fdac540c4..94e859181 100644 --- a/src/afs/FBSD/osi_file.c +++ b/src/afs/FBSD/osi_file.c @@ -72,7 +72,7 @@ afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat) AFS_GUNLOCK(); #if defined(AFS_FBSD80_ENV) vn_lock(afile->vnode, LK_EXCLUSIVE | LK_RETRY); - code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curthread); + code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp); VOP_UNLOCK(afile->vnode, 0); #elif defined(AFS_FBSD50_ENV) vn_lock(afile->vnode, LK_EXCLUSIVE | LK_RETRY, curthread); @@ -123,7 +123,7 @@ osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize) AFS_GUNLOCK(); #if defined(AFS_FBSD80_ENV) vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); - code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curthread); + code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp); #elif defined(AFS_FBSD50_ENV) vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread); code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curthread); @@ -136,7 +136,9 @@ osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize) VATTR_NULL(&tvattr); tvattr.va_size = asize; -#if defined(AFS_FBSD50_ENV) +#if defined(AFS_FBSD80_ENV) + code = VOP_SETATTR(vp, &tvattr, afs_osi_credp); +#elif defined(AFS_FBSD50_ENV) code = VOP_SETATTR(vp, &tvattr, afs_osi_credp, curthread); #else code = VOP_SETATTR(vp, &tvattr, afs_osi_credp, curproc); diff --git a/src/afs/FBSD/osi_machdep.h b/src/afs/FBSD/osi_machdep.h index 7086c4ffb..954295a2b 100644 --- a/src/afs/FBSD/osi_machdep.h +++ b/src/afs/FBSD/osi_machdep.h @@ -24,6 +24,10 @@ #if defined(AFS_FBSD50_ENV) #include #endif +#include +#if defined(AFS_FBSD80_ENV) +#include +#endif /* * Time related macros @@ -39,6 +43,9 @@ typedef struct proc afs_proc_t; #define iodone biodone #endif +#define VSUID S_ISUID +#define VSGID S_ISGID + #define osi_vnhold(avc,r) vref(AFSTOV(avc)) #define vType(vc) AFSTOV(vc)->v_type @@ -53,13 +60,19 @@ extern int (**afs_vnodeop_p) (); #endif #define SetAfsVnode(v) /* nothing; done in getnewvnode() */ +#if defined(AFS_FBSD80_ENV) +#define osi_vinvalbuf(vp, flags, slpflag, slptimeo) \ + vinvalbuf((vp), (flags), (slpflag), (slptimeo)) +#else +#define osi_vinvalbuf(vp, flags, slpflag, slptimeo) \ + vinvalbuf((vp), (flags), (curthread), (slpflag), (slptimeo)) +#endif + #undef gop_lookupname #define gop_lookupname osi_lookupname #undef gop_lookupname_user -#define gop_lookupname osi_lookupname_user - -#undef afs_suser +#define gop_lookupname_user osi_lookupname #define afs_strcat(s1, s2) strcat((s1), (s2)) @@ -78,7 +91,18 @@ extern int (**afs_vnodeop_p) (); #endif #define VN_HOLD(vp) VREF(vp) - +#undef afs_suser +#if defined(AFS_FBSD80_ENV) +/* OpenAFS-specific privileges negotiated for FreeBSD, thanks due to + * Ben Kaduk */ +#define osi_suser_client_settings(x) (!priv_check(curthread, PRIV_AFS_ADMIN)) +#define osi_suser_afs_daemon(x) (!priv_check(curthread, PRIV_AFS_DAEMON)) +#define afs_suser(x) (osi_suser_client_settings((x)) && osi_suser_afs_daemon((x))) +#elif defined(AFS_FBSD50_ENV) +#define afs_suser(x) (!suser(curthread)) +#else +#define afs_suser(x) (!suser(curproc)) +#endif #undef osi_getpid #if defined(AFS_FBSD50_ENV) @@ -86,7 +110,6 @@ extern int (**afs_vnodeop_p) (); #define VROOT VV_ROOT #define v_flag v_vflag #define osi_curcred() (curthread->td_ucred) -#define afs_suser(x) (!suser(curthread)) #define osi_getpid() (curthread->td_proc->p_pid) #define simple_lock(x) mtx_lock(x) #define simple_unlock(x) mtx_unlock(x) @@ -99,7 +122,6 @@ extern struct mtx afs_global_mtx; #else /* FBSD50 */ extern struct lock afs_global_lock; #define osi_curcred() (curproc->p_cred->pc_ucred) -#define afs_suser(x) (!suser(curproc)) #define osi_getpid() (curproc->p_pid) #define gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \ vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(aresid), curproc) diff --git a/src/afs/FBSD/osi_misc.c b/src/afs/FBSD/osi_misc.c index 2b6ac4813..0219ff547 100644 --- a/src/afs/FBSD/osi_misc.c +++ b/src/afs/FBSD/osi_misc.c @@ -10,8 +10,6 @@ /* * osi_misc.c * - * Implements: - * afs_suser */ #include diff --git a/src/afs/FBSD/osi_vm.c b/src/afs/FBSD/osi_vm.c index a05222204..804b473d1 100644 --- a/src/afs/FBSD/osi_vm.c +++ b/src/afs/FBSD/osi_vm.c @@ -235,9 +235,9 @@ osi_VM_TryToSmush(struct vcache *avc, afs_ucred_t *acred, int sync) } tries = 5; - code = vinvalbuf(vp, V_SAVE, curthread, PCATCH, 0); + code = osi_vinvalbuf(vp, V_SAVE, PCATCH, 0); while (code && (tries > 0)) { - code = vinvalbuf(vp, V_SAVE, curthread, PCATCH, 0); + code = osi_vinvalbuf(vp, V_SAVE, PCATCH, 0); --tries; } USERPRI; diff --git a/src/afs/FBSD/osi_vnodeops.c b/src/afs/FBSD/osi_vnodeops.c index aff889f8d..442215c61 100644 --- a/src/afs/FBSD/osi_vnodeops.c +++ b/src/afs/FBSD/osi_vnodeops.c @@ -110,7 +110,10 @@ struct vop_vector afs_vnodeops = { .vop_getpages = afs_vop_getpages, .vop_inactive = afs_vop_inactive, .vop_ioctl = afs_vop_ioctl, +#if !defined(AFS_FBSD80_ENV) + /* removed at least temporarily (NFSv4 flux) */ .vop_lease = VOP_NULL, +#endif .vop_link = afs_vop_link, .vop_lookup = afs_vop_lookup, .vop_mkdir = afs_vop_mkdir, @@ -315,7 +318,7 @@ afs_vop_unlock(ap) struct lock *lkp = vp->v_vnlock; #ifdef AFS_FBSD80_ENV - int code; + int code = 0; u_int op; op = ((ap->a_flags) | LK_RELEASE) & LK_TYPE_MASK; int glocked = ISAFS_GLOCK(); @@ -686,7 +689,11 @@ afs_vop_access(ap) { int code; AFS_GLOCK(); +#if defined(AFS_FBSD80_ENV) + code = afs_access(VTOAFS(ap->a_vp), ap->a_accmode, ap->a_cred); +#else code = afs_access(VTOAFS(ap->a_vp), ap->a_mode, ap->a_cred); +#endif AFS_GUNLOCK(); return code; } @@ -1556,7 +1563,7 @@ afs_vop_strategy(ap) { int error; AFS_GLOCK(); - error = afs_ustrategy(ap->a_bp, osi_cred()); + error = afs_ustrategy(ap->a_bp, osi_curcred()); AFS_GUNLOCK(); return error; } diff --git a/src/afs/afs_init.c b/src/afs/afs_init.c index 8eba2e6e7..37f508b02 100644 --- a/src/afs/afs_init.c +++ b/src/afs/afs_init.c @@ -423,6 +423,8 @@ afs_InitCacheInfo(register char *afile) if (afs_cacheVfsp && ((st = *(vfs_statfs(afs_cacheVfsp))),1)) #elif defined(AFS_DARWIN_ENV) if (!VFS_STATFS(filevp->v_mount, &st, current_proc())) +#elif defined(AFS_FBSD80_ENV) + if (!VFS_STATFS(filevp->v_mount, &st)) #elif defined(AFS_FBSD50_ENV) if (!VFS_STATFS(filevp->v_mount, &st, curthread)) #elif defined(AFS_XBSD_ENV) diff --git a/src/afs/afs_vcache.c b/src/afs/afs_vcache.c index edb97da7f..3c5b3ed34 100644 --- a/src/afs/afs_vcache.c +++ b/src/afs/afs_vcache.c @@ -1943,7 +1943,7 @@ afs_GetVCache(register struct VenusFid *afid, struct vrequest *areq, if (glocked) AFS_GLOCK(); } - vinvalbuf(vp, V_SAVE, curthread, PINOD, 0); + vinvalbuf(vp, V_SAVE, PINOD, 0); /* changed late in 8.0-CURRENT */ if (!iheldthelock) VOP_UNLOCK(vp, 0); #elif defined(AFS_FBSD60_ENV) diff --git a/src/gtx/curseswindows.c b/src/gtx/curseswindows.c index a5e59be9a..fba22604e 100644 --- a/src/gtx/curseswindows.c +++ b/src/gtx/curseswindows.c @@ -29,7 +29,7 @@ #endif #include #include -#if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) +#if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD80_ENV) #include #endif #include diff --git a/src/shlibafsrpc/Makefile.in b/src/shlibafsrpc/Makefile.in index 04c240fa8..127a46cdb 100644 --- a/src/shlibafsrpc/Makefile.in +++ b/src/shlibafsrpc/Makefile.in @@ -392,7 +392,8 @@ syscall.o: ${SYS}/syscall.s ${AS} -o syscall.o syscall.i; \ $(RM) -f syscall.ss syscall.i;; \ *fbsd* ) \ - touch syscall.o ;; \ + touch syscall.c ; \ + ${CC} ${CFLAGS} -c syscall.c;; \ *) \ $(PATH_CPP) ${SFLAGS} ${SYS}/syscall.s > syscall.ss; \ as -o syscall.o syscall.ss; \ diff --git a/src/util/vice.h b/src/util/vice.h index 906ab37c8..99dd54f7b 100644 --- a/src/util/vice.h +++ b/src/util/vice.h @@ -11,9 +11,11 @@ #define AFS_VICE_H 1 #include -#ifndef AFS_NT40_ENV +#if !defined(AFS_NT40_ENV) +# if !defined(AFS_FBSD80_ENV) || !defined(KERNEL) || defined(UKERNEL) #include -#endif +#endif /* AFS_FBSD80_ENV */ +#endif /* AFS_NT40_ENV */ #if (defined(__sun) && defined(__SVR4)) || defined(AFS_DFBSD_ENV) || defined(AFS_USR_DFBSD_ENV) # include #endif -- 2.39.5