obsd44-pass1-20090123
authorMatt Benjamin <matt@linuxbox.com>
Thu, 22 Jan 2009 21:28:29 +0000 (21:28 +0000)
committerDerrick Brashear <shadow@dementia.org>
Thu, 22 Jan 2009 21:28:29 +0000 (21:28 +0000)
LICENSE IPL10
FIXES 123830

first pass at openbsd 4.4

src/afs/OBSD/osi_groups.c
src/afs/OBSD/osi_machdep.h
src/afs/OBSD/osi_misc.c
src/afs/OBSD/osi_vnodeops.c
src/afs/afs_osi.h
src/afs/afs_prototypes.h
src/config/afs_sysnames.h
src/rx/rx_kcommon.c
src/rx/xdr.h
src/rx/xdr_arrayn.c

index 9633511..5ccbf77 100644 (file)
@@ -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;
index 576facf..933f03c 100644 (file)
 #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 @@ extern time_t osi_Time();
 /* 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
index 8bbcf55..4449ca4 100644 (file)
@@ -51,6 +51,8 @@ RCSID
 
 #include "afs/sysincludes.h"   /* Standard vendor system headers */
 #include "afs/afsincludes.h"   /* Afs-based standard headers */
+#include <sys/types.h>
+#include <sys/malloc.h>
 
 /*
  * 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)
index 92279d2..e01b1bf 100644 (file)
@@ -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)
index 799caab..2b41f7d 100644 (file)
@@ -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
index 0758771..6a5a9d0 100644 (file)
@@ -549,7 +549,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);
index 6ebd42f..287bf92 100644 (file)
 #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
index 1530cbe..8d174be 100644 (file)
@@ -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
index e41a267..6b08732 100644 (file)
 #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! */
index 1b9e06e..0860afe 100644 (file)
 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 <sys/param.h>
 #ifdef AFS_LINUX20_ENV
 #include "h/string.h"