Linux CM: Use kernel allocator directly for events
[openafs.git] / src / afs / LINUX / osi_sleep.c
index 3a9cda9..31b5149 100644 (file)
 #include <afsconfig.h>
 #include "afs/param.h"
 
-RCSID
-    ("$Header$");
 
 #include "afs/sysincludes.h"   /* Standard vendor system headers */
 #include "afsincludes.h"       /* Afs-based standard headers */
 #include "afs/afs_stats.h"     /* afs statistics */
-
-static int osi_TimedSleep(char *event, afs_int32 ams, int aintok);
+#include "osi_compat.h"
 
 static char waitV, dummyV;
 
@@ -59,7 +56,7 @@ afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok)
 
     do {
        AFS_ASSERT_GLOCK();
-       code = osi_TimedSleep(&waitV, ams, 1);
+       code = afs_osi_TimedSleep(&waitV, ams, 1);
        if (code)
            break;
        if (ahandle && (ahandle->proc == (caddr_t) 0)) {
@@ -80,11 +77,7 @@ typedef struct afs_event {
     int seq;                   /* Sequence number: this is incremented
                                 * by wakeup calls; wait will not return until
                                 * it changes */
-#if defined(AFS_LINUX24_ENV)
     wait_queue_head_t cond;
-#else
-    struct wait_queue *cond;
-#endif
 } afs_event_t;
 
 #define HASHSIZE 128
@@ -92,6 +85,20 @@ afs_event_t *afs_evhasht[HASHSIZE];  /* Hash table for events */
 #define afs_evhash(event)      (afs_uint32) ((((long)event)>>2) & (HASHSIZE-1));
 int afs_evhashcnt = 0;
 
+void
+osi_event_shutdown(void)
+{
+   int i;
+
+   for (i=0;i<HASHSIZE;i++) {
+       while (afs_evhasht[i] != NULL) {
+           afs_event_t *tmp = afs_evhasht[i];
+           afs_evhasht[i] = tmp->next;
+           kfree(tmp);
+       }
+   }
+}
+
 /* Get and initialize event structure corresponding to lwp event (i.e. address)
  * */
 static afs_event_t *
@@ -126,10 +133,7 @@ afs_getevent(char *event)
  *     address.
  *
  * Locks:
- *     Called with GLOCK held. However the function might drop
- *     GLOCK when it calls osi_AllocSmallSpace for allocating
- *     a new event (In Linux, the allocator drops GLOCK to avoid
- *     a deadlock).
+ *     Called with GLOCK held.
  */
 
 static void
@@ -140,18 +144,12 @@ afs_addevent(char *event)
 
     AFS_ASSERT_GLOCK();
     hashcode = afs_evhash(event);
-    newp = osi_linux_alloc(sizeof(afs_event_t), 0);
+    newp = kzalloc(sizeof(afs_event_t), GFP_NOFS);
     afs_evhashcnt++;
     newp->next = afs_evhasht[hashcode];
     afs_evhasht[hashcode] = newp;
-#if defined(AFS_LINUX24_ENV)
     init_waitqueue_head(&newp->cond);
-#else
-    init_waitqueue(&newp->cond);
-#endif
-    newp->seq = 0;
     newp->event = &dummyV;     /* Dummy address for new events */
-    newp->refcount = 0;
 }
 
 #ifndef set_current_state
@@ -192,22 +190,8 @@ afs_osi_SleepSig(void *event)
        AFS_ASSERT_GLOCK();
        AFS_GUNLOCK();
        schedule();
-#ifdef AFS_LINUX26_ENV
-#ifdef CONFIG_PM
-       if (
-#ifdef PF_FREEZE
-           current->flags & PF_FREEZE
-#else
-           !current->todo
-#endif
-           )
-#ifdef LINUX_REFRIGERATOR_TAKES_PF_FREEZE
-           refrigerator(PF_FREEZE);
-#else
-           refrigerator();
-#endif
-#endif
-#endif
+       afs_try_to_freeze();
+
        AFS_GLOCK();
        if (signal_pending(current)) {
            retval = EINTR;
@@ -247,7 +231,7 @@ afs_osi_Sleep(void *event)
     SIG_UNLOCK(current);
 }
 
-/* osi_TimedSleep
+/* afs_osi_TimedSleep
  * 
  * Arguments:
  * event - event to sleep on
@@ -257,8 +241,8 @@ afs_osi_Sleep(void *event)
  * Returns 0 if timeout, EINTR if signalled, and EGAIN if it might
  * have raced.
  */
-static int
-osi_TimedSleep(char *event, afs_int32 ams, int aintok)
+int
+afs_osi_TimedSleep(void *event, afs_int32 ams, int aintok)
 {
     int code = 0;
     long ticks = (ams * HZ / 1000) + 1;
@@ -281,27 +265,12 @@ osi_TimedSleep(char *event, afs_int32 ams, int aintok)
      * from artifically increasing. */
     AFS_GUNLOCK();
 
-    if (aintok) {
-       if (schedule_timeout(ticks))
+    if (schedule_timeout(ticks)) {
+       if (aintok)
            code = EINTR;
-    } else
-       schedule_timeout(ticks);
-#ifdef AFS_LINUX26_ENV
-#ifdef CONFIG_PM
-    if (
-#ifdef PF_FREEZE
-           current->flags & PF_FREEZE
-#else
-           !current->todo
-#endif
-           )
-#ifdef LINUX_REFRIGERATOR_TAKES_PF_FREEZE
-       refrigerator(PF_FREEZE);
-#else
-       refrigerator();
-#endif
-#endif
-#endif
+    }
+
+    afs_try_to_freeze();
 
     AFS_GLOCK();
     remove_wait_queue(&evp->cond, &wait);