lib/util: fallback to any id in idr_get_new_random()
authorStefan Metzmacher <metze@samba.org>
Sat, 28 Mar 2009 22:29:23 +0000 (23:29 +0100)
committerStefan Metzmacher <metze@samba.org>
Wed, 1 Apr 2009 14:41:15 +0000 (16:41 +0200)
metze

lib/util/idtree.c

index c8a8b6346ad8414c9e1f3c8cbbd58bef46af182f..0af93a229d3ede3755ccd02491ba071050e4cd8a 100644 (file)
@@ -372,12 +372,16 @@ _PUBLIC_ int idr_get_new_random(struct idr_context *idp, void *ptr, int limit)
 
        /* first try a random starting point in the whole range, and if that fails,
           then start randomly in the bottom half of the range. This can only
-          fail if the range is over half full */
+          fail if the range is over half full, and finally fallback to any
+          free id */
        id = idr_get_new_above(idp, ptr, 1+(generate_random() % limit), limit);
        if (id == -1) {
                id = idr_get_new_above(idp, ptr, 1+(generate_random()%(limit/2)), limit);
        }
-       
+       if (id == -1) {
+               id = idr_get_new_above(idp, ptr, 1, limit);
+       }
+
        return id;
 }