|
@@ -100,10 +100,11 @@ static int sub_alloc(struct idr *idp, void *ptr, int *starting_id)
|
|
int n, m, sh;
|
|
int n, m, sh;
|
|
struct idr_layer *p, *new;
|
|
struct idr_layer *p, *new;
|
|
struct idr_layer *pa[MAX_LEVEL];
|
|
struct idr_layer *pa[MAX_LEVEL];
|
|
- int l, id;
|
|
|
|
|
|
+ int l, id, oid;
|
|
long bm;
|
|
long bm;
|
|
|
|
|
|
id = *starting_id;
|
|
id = *starting_id;
|
|
|
|
+ restart:
|
|
p = idp->top;
|
|
p = idp->top;
|
|
l = idp->layers;
|
|
l = idp->layers;
|
|
pa[l--] = NULL;
|
|
pa[l--] = NULL;
|
|
@@ -117,12 +118,23 @@ static int sub_alloc(struct idr *idp, void *ptr, int *starting_id)
|
|
if (m == IDR_SIZE) {
|
|
if (m == IDR_SIZE) {
|
|
/* no space available go back to previous layer. */
|
|
/* no space available go back to previous layer. */
|
|
l++;
|
|
l++;
|
|
|
|
+ oid = id;
|
|
id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1;
|
|
id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1;
|
|
|
|
+
|
|
|
|
+ /* if already at the top layer, we need to grow */
|
|
if (!(p = pa[l])) {
|
|
if (!(p = pa[l])) {
|
|
*starting_id = id;
|
|
*starting_id = id;
|
|
return -2;
|
|
return -2;
|
|
}
|
|
}
|
|
- continue;
|
|
|
|
|
|
+
|
|
|
|
+ /* If we need to go up one layer, continue the
|
|
|
|
+ * loop; otherwise, restart from the top.
|
|
|
|
+ */
|
|
|
|
+ sh = IDR_BITS * (l + 1);
|
|
|
|
+ if (oid >> sh == id >> sh)
|
|
|
|
+ continue;
|
|
|
|
+ else
|
|
|
|
+ goto restart;
|
|
}
|
|
}
|
|
if (m != n) {
|
|
if (m != n) {
|
|
sh = IDR_BITS*l;
|
|
sh = IDR_BITS*l;
|