From: Matt Benjamin Date: Thu, 22 Jan 2009 21:29:06 +0000 (+0000) Subject: DEVEL15-obsd44-pass1-20090123 X-Git-Tag: openafs-devel-1_5_57~3 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=662e220b5eeb02c4a5d771425bd95e41d615682c;p=packages%2Fo%2Fopenafs.git DEVEL15-obsd44-pass1-20090123 LICENSE IPL10 FIXES 123830 first pass at openbsd 4.4 (cherry picked from commit 35a760632da0f15240153cb17ae96e0981e2c8c4) --- diff --git a/src/afs/OBSD/osi_groups.c b/src/afs/OBSD/osi_groups.c index 96335118c..5ccbf779f 100644 --- a/src/afs/OBSD/osi_groups.c +++ b/src/afs/OBSD/osi_groups.c @@ -47,10 +47,12 @@ Afs_xsetgroups(p, args, retval) struct vrequest treq; AFS_STATCNT(afs_xsetgroups); - AFS_GLOCKP(p); + AFS_GLOCK(); + + p = osi_curproc(); code = afs_InitReq(&treq, p->p_rcred); - AFS_GUNLOCKP(p); + AFS_GUNLOCK(); if (code) return code; @@ -61,10 +63,10 @@ Afs_xsetgroups(p, args, retval) */ if (PagInCred(p->p_rcred) == NOPAG) { if (((treq.uid >> 24) & 0xff) == 'A') { - AFS_GLOCKP(p); + AFS_GLOCK(); /* we've already done a setpag, so now we redo it */ AddPag(p, treq.uid, &p->p_rcred); - AFS_GUNLOCKP(p); + AFS_GUNLOCK(); } } return code; diff --git a/src/afs/OBSD/osi_machdep.h b/src/afs/OBSD/osi_machdep.h index a387f3bab..97df3c8ff 100644 --- a/src/afs/OBSD/osi_machdep.h +++ b/src/afs/OBSD/osi_machdep.h @@ -54,8 +54,37 @@ #define AFS_UIOUSER UIO_USERSPACE /* malloc */ -#define AFS_KALLOC(s) afs_nbsd_Alloc(s) -#define AFS_KFREE(p, s) afs_nbsd_Free((p), (s)) +inline void afs_osi_Free(void *buf, size_t asize); +inline void afs_osi_FreeStr(char *x); +extern void *osi_obsd_Alloc(size_t asize, int cansleep); +extern void osi_obsd_Free(void *p, size_t asize); + +#define afs_osi_Alloc_NoSleep(asize) osi_obsd_Alloc((asize), 0) +#define afs_osi_Alloc(asize) osi_obsd_Alloc((asize), 1) +#define afs_osi_FreeStr(s) afs_osi_Free((s), strlen((s)) + 1) +#define afs_osi_Free(buf, asize) osi_obsd_Free((buf), (asize)) + +#ifdef AFS_KALLOC +#undef AFS_KALLOC +#define AFS_KALLOC(s) osi_obsd_Alloc((s), 1 /* cansleep */) +#endif + +#ifdef AFS_KFREE +#undef AFS_KFREE +#define AFS_KFREE(p, s) (osi_obsd_Free((p), (s))) +#endif + +#ifdef AFS_OBSD42_ENV +/* removed, live with it */ +#define BSD_KMALLOC(p, ptype, msize, mtype, mflags) \ + (p) = malloc((msize), (mtype), (mflags)) + +#define BSD_KFREE(p, mflags) \ + free((p), (mflags)) +#else +#define BSD_KMALLOC MALLOC +#define BSD_KFREE KFREE +#endif /* AFS_OBSD42_ENV */ /* proc, cred */ #define AFS_PROC struct proc @@ -92,11 +121,11 @@ /* This is not always in scope yet */ struct vcache; -extern int afs_nbsd_lookupname(char *fnamep, enum uio_seg segflg, +extern int afs_obsd_lookupname(char *fnamep, enum uio_seg segflg, int followlink, struct vnode **compvpp); -extern void afs_nbsd_getnewvnode(struct vcache *tvc); -extern void *afs_nbsd_Alloc(size_t asize); -extern void afs_nbsd_Free(void *p, size_t asize); +extern void afs_obsd_getnewvnode(struct vcache *tvc); +extern void *afs_obsd_Alloc(size_t asize); +extern void afs_obsd_Free(void *p, size_t asize); extern int afs_vget(); #undef gop_lookupname @@ -111,6 +140,49 @@ extern int afs_vget(); #ifdef KERNEL +#ifdef AFS_OBSD44_ENV +/* Revert to classical, BSD locks */ + +extern struct lock afs_global_lock; +extern struct proc *afs_global_owner; + +#ifdef AFS_GLOBAL_SUNLOCK + +#if defined(LOCKDEBUG) + +#define AFS_GLOCK() \ + do { \ + _lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL, __FILE__, __LINE__); \ + } while(0); +#define AFS_GUNLOCK() \ + do { \ + _lockmgr(&afs_global_lock, LK_RELEASE, NULL, __FILE__, __LINE__); \ + } while(0); + +#else + +#define AFS_GLOCK() \ + do { \ + lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL); \ + } while(0); +#define AFS_GUNLOCK() \ + do { \ + lockmgr(&afs_global_lock, LK_RELEASE, NULL); \ + } while(0); +#endif /* LOCKDEBUG */ +#define ISAFS_GLOCK() (lockstatus(&afs_global_lock) == LK_EXCLUSIVE) +#else +extern struct lock afs_global_lock; +#define AFS_GLOCKP(p) +#define AFS_GUNLOCKP(p) +#define AFS_ASSERT_GLOCK() +#define ISAFS_GLOCK() 1 +#endif + +#else +/* I don't see doing locks this way for older kernels, either, + * but, smart folks wrote this + */ #define AFS_GLOCK() AFS_GLOCKP(curproc) #define AFS_GUNLOCK() AFS_GUNLOCKP(curproc) #ifdef AFS_GLOBAL_SUNLOCK @@ -139,6 +211,8 @@ extern struct lock afs_global_lock; #define ISAFS_GLOCK() 1 #endif +#endif /* AFS_OBSD44_ENV */ + #undef SPLVAR #define SPLVAR int splvar #undef NETPRI diff --git a/src/afs/OBSD/osi_misc.c b/src/afs/OBSD/osi_misc.c index 8bbcf559e..4449ca4ff 100644 --- a/src/afs/OBSD/osi_misc.c +++ b/src/afs/OBSD/osi_misc.c @@ -51,6 +51,8 @@ RCSID #include "afs/sysincludes.h" /* Standard vendor system headers */ #include "afs/afsincludes.h" /* Afs-based standard headers */ +#include +#include /* * afs_suser() returns true if the caller is superuser, false otherwise. @@ -74,20 +76,94 @@ afs_osi_suser(void *credp) #endif } +/* + * reworked for netbsd and openbsd at 4.0/4.4 + */ + +#if defined(AFS_OBSD42_ENV) +/* ripped out MALLOC/FREE */ + void * -afs_nbsd_Alloc(size_t asize) +osi_obsd_Alloc(size_t asize, int cansleep) { - void *p; + void *p; + int glocked; + + if (cansleep) { + glocked = ISAFS_GLOCK(); + if (glocked) + AFS_GUNLOCK(); + p = malloc(asize, M_AFSGENERIC, M_WAITOK); + if (glocked) + AFS_GLOCK(); + } else { + p = malloc(asize, M_AFSGENERIC, M_NOWAIT); + } + + return (p); +} +void +osi_obsd_Free(void *p, size_t asize) +{ + free(p, M_AFSGENERIC); +} + +#else +void * +osi_obsd_Alloc(size_t asize, int cansleep) +{ + void *p; + int glocked; + + if (cansleep) { + glocked = ISAFS_GLOCK(); + if (glocked) + AFS_GUNLOCK(); MALLOC(p, void *, asize, M_AFSGENERIC, M_WAITOK); - return p; + if (glocked) + AFS_GLOCK(); + } else { + MALLOC(p, void *, asize, M_AFSGENERIC, M_NOWAIT); + } + + return (p); } void -afs_nbsd_Free(void *p, size_t asize) +osi_obsd_Free(void *p, size_t asize) { - FREE(p, M_AFSGENERIC); + FREE(p, M_AFSGENERIC); } +#endif + +#if 0 /* XXX */ +/* I speculate this usage may be more correct than definitions + * in afs_osi_alloc.c, which I discarded successfully for FreeBSD 7+, + * and am trying to discard for NetBSD 4.x, but until tested, I'm + * not rocking the boat. Matt. + */ + +void +osi_FreeLargeSpace(void *p) +{ + osi_obsd_Free(p, 0); +} + +void +osi_FreeSmallSpace(void *p) +{ + osi_obsd_Free(p, 0); +} + +void * +osi_AllocLargeSpace(size_t size) +{ + AFS_ASSERT_GLOCK(); + AFS_STATCNT(osi_AllocLargeSpace); + return (osi_obsd_Alloc(size, 1)); +} +#endif int afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, retval) diff --git a/src/afs/OBSD/osi_vnodeops.c b/src/afs/OBSD/osi_vnodeops.c index 880fe4532..0ed1b8d8c 100644 --- a/src/afs/OBSD/osi_vnodeops.c +++ b/src/afs/OBSD/osi_vnodeops.c @@ -160,7 +160,11 @@ int afs_nbsd_advlock(void *); /* Global vfs data structures for AFS. */ int (**afs_vnodeop_p) __P((void *)); struct vnodeopv_entry_desc afs_vnodeop_entries[] = { +#ifdef AFS_OBSD44_ENV /* feel free to zero in on this */ + {&vop_default_desc, eopnotsupp}, +#else {&vop_default_desc, vn_default_error}, +#endif {&vop_lookup_desc, afs_nbsd_lookup}, /* lookup */ {&vop_create_desc, afs_nbsd_create}, /* create */ {&vop_mknod_desc, afs_nbsd_mknod}, /* mknod */ @@ -207,11 +211,11 @@ struct vnodeopv_desc afs_vnodeop_opv_desc = #define GETNAME() \ struct componentname *cnp = ap->a_cnp; \ char *name; \ - MALLOC(name, char *, cnp->cn_namelen+1, M_TEMP, M_WAITOK); \ + BSD_KMALLOC(name, char *, cnp->cn_namelen+1, M_TEMP, M_WAITOK); \ bcopy(cnp->cn_nameptr, name, cnp->cn_namelen); \ name[cnp->cn_namelen] = '\0' -#define DROPNAME() FREE(name, M_TEMP) +#define DROPNAME() BSD_KFREE(name, M_TEMP) #ifdef AFS_OBSD36_ENV #define DROPCNP(cnp) pool_put(&namei_pool, (cnp)->cn_pnbuf) @@ -687,10 +691,10 @@ afs_nbsd_rename(void *v) if ((code = vn_lock(fvp, LK_EXCLUSIVE | LK_RETRY, curproc))) goto abortit; - MALLOC(fname, char *, fcnp->cn_namelen + 1, M_TEMP, M_WAITOK); + BSD_KMALLOC(fname, char *, fcnp->cn_namelen + 1, M_TEMP, M_WAITOK); bcopy(fcnp->cn_nameptr, fname, fcnp->cn_namelen); fname[fcnp->cn_namelen] = '\0'; - MALLOC(tname, char *, tcnp->cn_namelen + 1, M_TEMP, M_WAITOK); + BSD_KMALLOC(tname, char *, tcnp->cn_namelen + 1, M_TEMP, M_WAITOK); bcopy(tcnp->cn_nameptr, tname, tcnp->cn_namelen); tname[tcnp->cn_namelen] = '\0'; @@ -702,8 +706,8 @@ afs_nbsd_rename(void *v) AFS_GUNLOCK(); VOP_UNLOCK(fvp, 0, curproc); - FREE(fname, M_TEMP); - FREE(tname, M_TEMP); + BSD_KFREE(fname, M_TEMP); + BSD_KFREE(tname, M_TEMP); if (code) goto abortit; /* XXX */ if (tdvp == tvp) diff --git a/src/afs/afs_osi.h b/src/afs/afs_osi.h index 799caabd8..2b41f7db9 100644 --- a/src/afs/afs_osi.h +++ b/src/afs/afs_osi.h @@ -117,7 +117,9 @@ struct afs_osi_WaitHandle { /* * Alloc declarations. */ +#if !defined(AFS_OBSD44_ENV) #define afs_osi_Alloc_NoSleep afs_osi_Alloc +#endif /* * Vnode related macros diff --git a/src/afs/afs_osi_alloc.c b/src/afs/afs_osi_alloc.c index 6773316df..0dde60896 100644 --- a/src/afs/afs_osi_alloc.c +++ b/src/afs/afs_osi_alloc.c @@ -44,7 +44,7 @@ struct osimem { struct osimem *next; }; - +#if !defined(AFS_OBSD44_ENV) void * afs_osi_Alloc(size_t x) { @@ -124,7 +124,7 @@ afs_osi_FreeStr(char *x) afs_osi_Free(x, strlen(x) + 1); } - +#endif /* free space allocated by AllocLargeSpace. Also called by mclput when freeing * a packet allocated by osi_NetReceive. */ diff --git a/src/afs/afs_prototypes.h b/src/afs/afs_prototypes.h index ea5c04de6..8738de059 100644 --- a/src/afs/afs_prototypes.h +++ b/src/afs/afs_prototypes.h @@ -548,7 +548,9 @@ extern void *afs_osi_Alloc_NoSleep(size_t x); #ifndef afs_osi_Free extern void afs_osi_Free(void *x, size_t asize); #endif +#if !defined(AFS_OBSD44_ENV) extern void afs_osi_FreeStr(char *x); +#endif extern void osi_FreeLargeSpace(void *adata); extern void osi_FreeSmallSpace(void *adata); extern void *osi_AllocLargeSpace(size_t size); diff --git a/src/config/afs_sysnames.h b/src/config/afs_sysnames.h index c8cca9962..09961fd84 100644 --- a/src/config/afs_sysnames.h +++ b/src/config/afs_sysnames.h @@ -245,6 +245,10 @@ #define SYS_NAME_ID_i386_obsd38 2607 #define SYS_NAME_ID_i386_obsd39 2608 #define SYS_NAME_ID_i386_obsd40 2609 +#define SYS_NAME_ID_i386_obsd41 2610 +#define SYS_NAME_ID_i386_obsd42 2611 +#define SYS_NAME_ID_i386_obsd43 2612 +#define SYS_NAME_ID_i386_obsd44 2613 #define SYS_NAME_ID_amd64_linux2 2700 #define SYS_NAME_ID_amd64_linux22 2701 diff --git a/src/rx/rx_kcommon.c b/src/rx/rx_kcommon.c index 1530cbee6..8d174beec 100644 --- a/src/rx/rx_kcommon.c +++ b/src/rx/rx_kcommon.c @@ -1021,10 +1021,12 @@ rxk_NewSocketHost(afs_uint32 ahost, short aport) } nam->m_len = sizeof(myaddr); memcpy(mtod(nam, caddr_t), &myaddr, sizeof(myaddr)); -#ifdef AFS_SGI65_ENV +#if defined(AFS_SGI65_ENV) BHV_PDATA(&bhv) = (void *)newSocket; code = sobind(&bhv, nam); m_freem(nam); +#elif defined(AFS_OBSD44_ENV) + code = sobind(newSocket, nam, osi_curproc()); #else code = sobind(newSocket, nam); #endif diff --git a/src/rx/xdr.h b/src/rx/xdr.h index e41a267cd..6b0873220 100644 --- a/src/rx/xdr.h +++ b/src/rx/xdr.h @@ -96,11 +96,13 @@ #define osi_free afs_osi_Free /* keep here for now, 64 bit issues */ +#ifndef AFS_OBSD44_ENV extern void *afs_osi_Alloc(size_t x); #ifndef afs_osi_Alloc_NoSleep extern void *afs_osi_Alloc_NoSleep(size_t x); #endif extern void afs_osi_Free(void *x, size_t asize); +#endif #endif #ifndef major /* ouch! */ diff --git a/src/rx/xdr_arrayn.c b/src/rx/xdr_arrayn.c index 1b9e06ee2..315b5d4fd 100644 --- a/src/rx/xdr_arrayn.c +++ b/src/rx/xdr_arrayn.c @@ -32,6 +32,11 @@ RCSID ("$Header$"); +#if defined(AFS_OBSD44_ENV) && defined(KERNEL) && !defined(UKERNEL) +/* XXX osi_alloc, please find and fix */ +#include "osi_machdep.h" +#endif + #if !defined(NeXT) /* @@ -44,6 +49,7 @@ RCSID */ #if defined(KERNEL) && !defined(UKERNEL) + #include #ifdef AFS_LINUX20_ENV #include "h/string.h"