Add must_be_container helper.

This checks a block device to see if it could be a container, and
in particular cannot be a member device.

Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
NeilBrown 2010-11-22 20:58:06 +11:00
parent 88cef9b3e6
commit 3a3716107b
4 changed files with 17 additions and 6 deletions

View File

@ -76,11 +76,10 @@ int Examine(struct mddev_dev *devlist, int brief, int export, int scan,
err = 1;
}
else {
unsigned long long size;
int container = 0;
if (forcest)
st = dup_super(forcest);
else if (get_dev_size(fd, NULL, &size) == 0 || size == 0) {
else if (must_be_container(fd)) {
/* might be a container */
st = super_by_fd(fd, NULL);
container = 1;

View File

@ -103,7 +103,6 @@ int Incremental(char *devname, int verbose, int runstop,
char *name_to_use;
mdu_array_info_t ainf;
struct dev_policy *policy = NULL;
unsigned long long size;
struct createinfo *ci = conf_get_create_info();
@ -127,9 +126,7 @@ int Incremental(char *devname, int verbose, int runstop,
return rv;
}
/* If the device is a container, we do something very different */
if (get_dev_size(dfd, devname, &size) == 0)
goto out;
if (size == 0) {
if (must_be_container(dfd)) {
if (!st)
st = super_by_fd(dfd, NULL);
if (st)

View File

@ -739,6 +739,7 @@ static inline struct supertype *guess_super(int fd) {
}
extern struct supertype *dup_super(struct supertype *st);
extern int get_dev_size(int fd, char *dname, unsigned long long *sizep);
extern int must_be_container(int fd);
extern void get_one_disk(int mdfd, mdu_array_info_t *ainf,
mdu_disk_info_t *disk);
void wait_for(char *dev, int fd);

14
util.c
View File

@ -1189,6 +1189,20 @@ int get_dev_size(int fd, char *dname, unsigned long long *sizep)
return 1;
}
/* Return true if this can only be a container, not a member device.
* i.e. is and md device and size is zero
*/
int must_be_container(int fd)
{
unsigned long long size;
if (md_get_version(fd) < 0)
return 0;
if (get_dev_size(fd, NULL, &size) == 0)
return 1;
if (size == 0)
return 1;
return 0;
}
/* Sets endofpart parameter to the last block used by the last GPT partition on the device.
* Returns: 1 if successful