From 63152c1b330f75842644c82d925fa8dcd37fe233 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Mon, 5 May 2008 21:55:36 +1000 Subject: Unify code into find_free_devnum. Two places have code to find a free md device number. Make this a subroutine. --- Incremental.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'Incremental.c') diff --git a/Incremental.c b/Incremental.c index 4c6a2a7..b54c4fc 100644 --- a/Incremental.c +++ b/Incremental.c @@ -246,20 +246,15 @@ int Incremental(char *devname, int verbose, int runstop, if (devnum < 0) { /* Haven't found anything yet, choose something free */ - /* There is similar code in mdopen.c - should unify */ - for (devnum = 127 ; devnum != 128 ; - devnum = devnum ? devnum-1 : (1<<22)-1) { - if (mddev_busy(use_partitions ? - (-1-devnum) : devnum)) - break; - } - if (devnum == 128) { + devnum = find_free_devnum(use_partitions); + + if (devnum == NoMdDev) { fprintf(stderr, Name ": No spare md devices!!\n"); return 2; } - } - devnum = use_partitions ? (-1-devnum) : devnum; + } else + devnum = use_partitions ? (-1-devnum) : devnum; } mdfd = open_mddev_devnum(match ? match->devname : NULL, devnum, -- cgit