- /* My hypothesis is that get_random_bytes, if called from two threads at
- * the same time, will return the same bytes. -phil */
- spin_lock(&random_lock);
- get_random_bytes(&h->h_cookie, sizeof(h->h_cookie));
- spin_unlock(&random_lock);
-
+ /*
+ * This is fast, but simplistic cookie generation algorithm, it will
+ * need a re-do at some point in the future for security.
+ */
+ spin_lock(&handle_base_lock);
+ handle_base += HANDLE_INCR;
+
+ h->h_cookie = handle_base;
+ if (unlikely(handle_base == 0)) {
+ /*
+ * Cookie of zero is "dangerous", because in many places it's
+ * assumed that 0 means "unassigned" handle, not bound to any
+ * object.
+ */
+ CWARN("The universe has been exhausted: cookie wrap-around.\n");
+ handle_base += HANDLE_INCR;
+ }
+ spin_unlock(&handle_base_lock);
+
+ atomic_inc(&handle_count);