LINUX/: ifdef for GFP_NOFS conditionals
[openafs.git] / src / afs / LINUX / osi_alloc.c
index 1c0525f..b586d7b 100644 (file)
 #include <afsconfig.h>
 #include "afs/param.h"
 
-RCSID
-    ("$Header$");
 
 #include "afs/sysincludes.h"
 #include "afsincludes.h"
-#include "h/mm.h"
-#include "h/slab.h"
+#include <linux/mm.h>
+#include <linux/slab.h>
 
 #include "afs_atomlist.h"
 #include "afs_lhash.h"
@@ -51,14 +49,7 @@ unsigned int afs_linux_hash_verify_count = 0;        /* used by hash_verify */
 struct afs_lhash_stat afs_linux_lsb;   /* hash table statistics */
 unsigned int afs_linux_hash_bucket_dist[MAX_BUCKET_LEN];       /* bucket population distribution in our hash table */
 
-#if defined(AFS_LINUX24_ENV)
-#include "h/vmalloc.h"
-#else
-/* externs : can we do this in a better way. Including vmalloc.h causes other
- * problems.*/
-extern void vfree(void *addr);
-extern void *vmalloc(unsigned long size);
-#endif
+#include <linux/vmalloc.h>
 
 /* Allocator support functions (static) */
 
@@ -88,19 +79,18 @@ linux_alloc(unsigned int asize, int drop_glock)
     /*  if we can use kmalloc use it to allocate the required memory. */
     while (!new && max_retry) {
        if (asize <= MAX_KMALLOC_SIZE) {
-           new = (void *)(unsigned long)kmalloc(asize,
-#ifdef GFP_NOFS
-                                                GFP_NOFS
-#else
-                                                GFP_KERNEL
-#endif
-               );
+           new = (void *)(unsigned long)kmalloc(asize, GFP_NOFS);
            if (new)            /* piggy back alloc type */
-               (unsigned long)new |= KM_TYPE;
+               new = (void *)(KM_TYPE | (unsigned long)new);
        } else {
+           osi_Assert(drop_glock || !haveGlock);
+           if (drop_glock && haveGlock)
+               AFS_GUNLOCK();
            new = (void *)vmalloc(asize);
+           if (drop_glock && haveGlock)
+               AFS_GLOCK();
            if (new)            /* piggy back alloc type */
-               (unsigned long)new |= VM_TYPE;
+               new = (void *)(VM_TYPE | (unsigned long)new);
        }
 
        if (!new) {
@@ -143,8 +133,8 @@ linux_free(void *p)
        vfree(MEMADDR(p));
        break;
     default:
-       printf("afs_osi_Free: Asked to free unknown type %d at 0x%x\n",
-              MEMTYPE(p), MEMADDR(p));
+       printf("afs_osi_Free: Asked to free unknown type %d at 0x%lx\n",
+              (int)MEMTYPE(p), (unsigned long)MEMADDR(p));
        break;
     }
 
@@ -194,24 +184,10 @@ hash_verify(size_t index, unsigned key, void *data)
     int memtype;
 
     memtype = MEMTYPE(lmp->chunk);
-#if defined(AFS_SPARC64_LINUX24_ENV) || defined(AFS_I386_UMLINUX20_ENV)
-    if ((memtype == KM_TYPE) && (!VALID_PAGE(virt_to_page(lmp->chunk)))) {
-       printf
-           ("osi_linux_verify_alloced_memory: address 0x%x outside range, index=%d, key=%d\n",
-            lmp->chunk, index, key);
-    }
-#else
-    if ((memtype == KM_TYPE) && (AFS_LINUX_MAP_NR(lmp->chunk) > max_mapnr)) {
-       printf
-           ("osi_linux_verify_alloced_memory: address 0x%x outside range, index=%d, key=%d\n",
-            lmp->chunk, index, key);
-    }
-#endif
-
     if (memtype != KM_TYPE && memtype != VM_TYPE) {
        printf
-           ("osi_linux_verify_alloced_memory: unknown type %d at 0x%x, index=%d\n",
-            memtype, lmp->chunk, index);
+           ("osi_linux_verify_alloced_memory: unknown type %d at 0x%lx, index=%lu\n",
+            (int)memtype, (unsigned long)lmp->chunk, (unsigned long)index);
     }
     afs_linux_hash_verify_count++;
 }
@@ -232,7 +208,7 @@ local_free(void *p, size_t n)
  *    1 - success
  */
 static int
-linux_alloc_init()
+linux_alloc_init(void)
 {
     /* initiate our pool of osi_linux_mem structs */
     al_mem_pool =
@@ -279,7 +255,7 @@ hash_bucket_stat(size_t index, unsigned key, void *data)
 
 /* get_hash_stats() : get hash table statistics */
 static void
-get_hash_stats()
+get_hash_stats(void)
 {
     int i;
 
@@ -295,11 +271,7 @@ get_hash_stats()
 
 /************** Linux memory allocator interface functions **********/
 
-#if defined(AFS_LINUX24_ENV)
 DECLARE_MUTEX(afs_linux_alloc_sem);
-#else
-struct semaphore afs_linux_alloc_sem = MUTEX;
-#endif
 
 void *
 osi_linux_alloc(unsigned int asize, int drop_glock)
@@ -349,9 +321,7 @@ osi_linux_alloc(unsigned int asize, int drop_glock)
 
   free_error:
     if (new) {
-       up(&afs_linux_alloc_sem);
        linux_free(new);
-       down(&afs_linux_alloc_sem);
     }
     new = NULL;
     goto error;
@@ -377,6 +347,7 @@ osi_linux_free(void *addr)
        afs_atomlist_put(al_mem_pool, lmp);     /* return osi_linux_mem struct to pool */
        afs_linux_cur_allocs--;
     } else {
+       BUG();
        printf("osi_linux_free: failed to remove chunk from hashtable\n");
     }