Support nameing of version-1 arrays.

--name is recognised in --create and --assemble
name= is recognised in config file.

Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au>
This commit is contained in:
Neil Brown 2005-08-09 05:23:20 +00:00
parent dfd4d8ee42
commit 947fd4ddb5
17 changed files with 114 additions and 22 deletions

View File

@ -116,6 +116,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
unsigned int num_devs;
mddev_dev_t tmpdev;
struct mdinfo info;
struct mddev_ident_s ident2;
vers = md_get_version(mdfd);
if (vers <= 0) {
@ -214,7 +215,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
devname);
close(dfd);
} else {
tst->ss->getinfo_super(&info, super);
tst->ss->getinfo_super(&info, &ident2, super);
close(dfd);
}
@ -225,6 +226,13 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
devname);
continue;
}
if (ident->name[0] &&
(!super || strncmp(ident2.name, ident->name, 32)!=0)) {
if (inargv || verbose)
fprintf(stderr, Name ": %s has wrong name.\n",
devname);
continue;
}
if (ident->super_minor != UnSet &&
(!super || ident->super_minor != info.array.md_minor)) {
if (inargv || verbose)
@ -344,7 +352,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
return 1;
}
st->ss->getinfo_super(&info, first_super);
st->ss->getinfo_super(&info, &ident2, first_super);
/* now we have some devices that might be suitable.
* I wonder how many
@ -461,7 +469,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
fprintf(stderr, Name ": No suitable drives found for %s\n", mddev);
return 1;
}
st->ss->getinfo_super(&info, super);
st->ss->getinfo_super(&info, &ident2, super);
for (i=0; i<bestcnt; i++) {
int j = best[i];
unsigned int desired_state;

View File

@ -2,6 +2,8 @@ Changes Prior to this release
- Support assembling from byte-swapped superblocks
metadata type "0.swap" and --update=byteorder
- write-mostly and write-behind support for raid1.
- Support --name= and 'name=' config entry for identifying
arrays be name.
Changes Prior to 2.0-devel-3 release
- Assorted fixes for multiple bugs...

View File

@ -33,6 +33,7 @@
int Create(struct supertype *st, char *mddev, int mdfd,
int chunk, int level, int layout, unsigned long size, int raiddisks, int sparedisks,
char *name,
int subdevs, mddev_dev_t devlist,
int runstop, int verbose, int force,
char *bitmap_file, int bitmap_chunk, int write_behind, int delay)
@ -343,7 +344,7 @@ int Create(struct supertype *st, char *mddev, int mdfd,
array.chunk_size = chunk*1024;
if (!st->ss->init_super(st, &super, &array))
if (!st->ss->init_super(st, &super, &array, name))
return 1;
if (bitmap_file && strcmp(bitmap_file, "internal")==0) {

View File

@ -112,7 +112,8 @@ int Detail(char *dev, int brief, int test)
if (fd2 >=0 && st &&
st->ss->load_super(st, fd2, &super, NULL) == 0) {
struct mdinfo info;
st->ss->getinfo_super(&info, super);
struct mddev_ident_s ident;
st->ss->getinfo_super(&info, &ident, super);
if (info.array.ctime != array.ctime ||
info.array.level != array.level) {
free(super);

View File

@ -62,6 +62,7 @@ int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust, struct su
void *super;
struct supertype *st;
struct mdinfo info;
struct mddev_ident_s ident;
void *devs;
struct array *next;
int spares;
@ -108,9 +109,9 @@ int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust, struct su
ap->spares = 0;
ap->st = st;
arrays = ap;
st->ss->getinfo_super(&ap->info, super);
st->ss->getinfo_super(&ap->info, &ap->ident, super);
} else {
st->ss->getinfo_super(&ap->info, super);
st->ss->getinfo_super(&ap->info, &ap->ident, super);
free(super);
}
if (!(ap->info.disk.state & MD_DISK_SYNC))

2
Kill.c
View File

@ -63,7 +63,7 @@ int Kill(char *dev, int force)
mdu_array_info_t info;
info.major_version = -1; /* zero superblock */
free(super);
st->ss->init_super(st, &super, &info);
st->ss->init_super(st, &super, &info, "");
if (st->ss->store_super(st, fd, super)) {
fprintf(stderr, Name ": Could not zero superblock on %s\n",
dev);

View File

@ -42,6 +42,7 @@ int Query(char *dev)
int ioctlerr;
int superror, superrno;
struct mdinfo info;
struct mddev_ident_s ident;
mdu_array_info_t array;
void *super;
struct supertype *st = NULL;
@ -104,7 +105,7 @@ int Query(char *dev)
close(fd);
if (superror == 0) {
/* array might be active... */
st->ss->getinfo_super(&info, super);
st->ss->getinfo_super(&info, &ident, super);
if (st->ss->major == 0) {
mddev = get_md_name(info.array.md_minor);
disc.number = info.disk.number;

View File

@ -137,6 +137,7 @@ struct option long_options[] = {
/* For assemble */
{"uuid", 1, 0, 'u'},
{"super-minor",1,0, 'm'},
{"name", 1, 0, 'N'},
{"config", 1, 0, 'c'},
{"scan", 0, 0, 's'},
{"force", 0, 0, 'f'},
@ -236,6 +237,7 @@ char OptionHelp[] =
" --bitmap-chunk= : chunksize of bitmap in bitmap file (Kilobytes)\n"
" --delay= -d : seconds between bitmap updates\n"
" --write-behind= : number of simultaneous write-behind requests to allow (requires bitmap)\n"
" --name= -N : Textual name for array - max 32 characters\n"
"\n"
" For assemble:\n"
" --bitmap= -b : File to find bitmap information in\n"
@ -243,6 +245,7 @@ char OptionHelp[] =
" have this uuid are excluded\n"
" --super-minor= -m : minor number to look for in super-block when\n"
" choosing devices to use.\n"
" --name= -N : Array name to look for in super-block.\n"
" --config= -c : config file\n"
" --scan -s : scan config file for missing information\n"
" --force -f : Assemble the array even if some superblocks appear out-of-date\n"
@ -307,6 +310,7 @@ char Help_create[] =
" --run -R : insist of running the array even if not all\n"
" : devices are present or some look odd.\n"
" --readonly -o : start the array readonly - not supported yet.\n"
" --name= -N : Textual name for array - max 32 characters\n"
" --bitmap-chunk= : bitmap chunksize in Kilobytes.\n"
" --delay= -d : bitmap update delay in seconds.\n"
"\n"
@ -371,6 +375,7 @@ char Help_assemble[] =
" have this uuid are excluded\n"
" --super-minor= -m : minor number to look for in super-block when\n"
" choosing devices to use.\n"
" --name= -N : Array name to look for in super-block.\n"
" --config= -c : config file\n"
" --scan -s : scan config file for missing information\n"
" --run -R : Try to start the array even if not enough devices\n"

View File

@ -277,6 +277,7 @@ void arrayline(char *line)
mis.next = NULL;
mis.st = NULL;
mis.bitmap_fd = -1;
mis.name[0] = 0;
for (w=dl_next(line); w!=line; w=dl_next(w)) {
if (w[0] == '/') {
@ -307,6 +308,15 @@ void arrayline(char *line)
mis.super_minor = UnSet;
}
}
} else if (strncasecmp(w, "name=", 5)==0) {
if (mis.name[0])
fprintf(stderr, Name ": only specify name once, %s ignored.\n",
w);
else if (strlen(w+5) > 32)
fprintf(stderr, Name ": name too long, ignoring %s\n", w);
else
strcpy(mis.name, w+5);
} else if (strncasecmp(w, "devices=", 8 ) == 0 ) {
if (mis.devices)
fprintf(stderr, Name ": only specify devices once (use a comma separated list). %s ignored\n",
@ -375,7 +385,7 @@ void arrayline(char *line)
}
if (mis.devname == NULL)
fprintf(stderr, Name ": ARRAY line with no device\n");
else if (mis.uuid_set == 0 && mis.devices == NULL && mis.super_minor == UnSet)
else if (mis.uuid_set == 0 && mis.devices == NULL && mis.super_minor == UnSet && mis.name[0] == 0)
fprintf(stderr, Name ": ARRAY line %s has no identity information.\n", mis.devname);
else {
mi = malloc(sizeof(*mi));

13
mdadm.8
View File

@ -431,6 +431,14 @@ that the array pre-existed and is known to be clean. This is only
really useful for Building RAID1 array. Only use this if you really
know what you are doing. This is currently only supported for --build.
.TP
.BR -N ", " --name=
Set a
.B name
for the array. This is currently only effective when creating an
array with a version-1 superblock. The name is a simple textual
string that can be used to identify array components when assembling.
.TP
.BR -R ", " --run
Insist that
@ -517,6 +525,11 @@ e.g. when assembling
.M --super-minor=dev
will look for super blocks with a minor number of 0.
.TP
.BR -N ", " --name=
Specify the name of the array to assemble. This must be the name
that was specified when creating the array.
.TP
.BR -f ", " --force
Assemble the array even if some superblocks appear out-of-date

20
mdadm.c
View File

@ -107,6 +107,7 @@ int main(int argc, char *argv[])
ident.autof = 0;
ident.st = NULL;
ident.bitmap_fd = -1;
ident.name[0] = 0;
while ((option_index = -1) ,
(opt=getopt_long(argc, argv,
@ -526,6 +527,21 @@ int main(int argc, char *argv[])
}
continue;
case O(CREATE,'N'):
case O(ASSEMBLE,'N'):
if (ident.name[0]) {
fprintf(stderr, Name ": name cannot be set twice. "
"Second value %s.\n", optarg);
exit(2);
}
if (strlen(optarg) > 32) {
fprintf(stderr, Name ": name '%s' is too long, 32 chars max.\n",
optarg);
exit(2);
}
strcpy(ident.name, optarg);
continue;
case O(ASSEMBLE,'m'): /* super-minor for array */
if (ident.super_minor != UnSet) {
fprintf(stderr, Name ": super-minor cannot be set twice. "
@ -852,7 +868,7 @@ int main(int argc, char *argv[])
break;
case ASSEMBLE:
if (devs_found == 1 && ident.uuid_set == 0 &&
ident.super_minor == UnSet && !scan ) {
ident.super_minor == UnSet && ident.name[0] == 0 && !scan ) {
/* Only a device has been given, so get details from config file */
mddev_ident_t array_ident = conf_get_ident(configfile, devlist->devname);
if (array_ident == NULL) {
@ -972,7 +988,7 @@ int main(int argc, char *argv[])
}
rv = Create(ss, devlist->devname, mdfd, chunk, level, layout, size<0 ? 0 : size,
raiddisks, sparedisks,
raiddisks, sparedisks, ident.name,
devs_found-1, devlist->next, runstop, verbose, force,
bitmap_file, bitmap_chunk, write_behind, delay);
break;

View File

@ -90,6 +90,13 @@ The value should be a 128 bit uuid in hexadecimal, with punctuation
interspersed if desired. This must match the uuid stored in the
superblock.
.TP
.B name=
The value should be a simple textual name as was given to
.I mdadm
when the array was created. This must match the name stored in the
superblock on a device for that device to be included in the array.
Not all superblock-formats support names.
.TP
.B super-minor=
The value is an integer which indicates the minor number that was
stored in the superblock when the array was created. When an array is

View File

@ -112,6 +112,7 @@ typedef struct mddev_ident_s {
int uuid_set;
int uuid[4];
char name[33];
unsigned int super_minor;
@ -177,10 +178,10 @@ extern struct superswitch {
void (*detail_super)(void *sbv);
void (*brief_detail_super)(void *sbv);
void (*uuid_from_super)(int uuid[4], void *sbv);
void (*getinfo_super)(struct mdinfo *info, void *sbv);
void (*getinfo_super)(struct mdinfo *info, mddev_ident_t ident, void *sbv);
int (*update_super)(struct mdinfo *info, void *sbv, char *update, char *devname, int verbose);
__u64 (*event_super)(void *sbv);
int (*init_super)(struct supertype *st, void **sbp, mdu_array_info_t *info);
int (*init_super)(struct supertype *st, void **sbp, mdu_array_info_t *info, char *name);
void (*add_to_super)(void *sbv, mdu_disk_info_t *dinfo);
int (*store_super)(struct supertype *st, int fd, void *sbv);
int (*write_init_super)(struct supertype *st, void *sbv, mdu_disk_info_t *dinfo, char *devname);
@ -244,6 +245,7 @@ extern int Build(char *mddev, int mdfd, int chunk, int level, int layout,
extern int Create(struct supertype *st, char *mddev, int mdfd,
int chunk, int level, int layout, unsigned long size, int raiddisks, int sparedisks,
char *name,
int subdevs, mddev_dev_t devlist,
int runstop, int verbose, int force,
char *bitmap_file, int bitmap_chunk, int write_behind, int delay);

View File

@ -223,7 +223,7 @@ static void uuid_from_super0(int uuid[4], void * sbv)
}
}
static void getinfo_super0(struct mdinfo *info, void *sbv)
static void getinfo_super0(struct mdinfo *info, mddev_ident_t ident, void *sbv)
{
mdp_super_t *sb = sbv;
int working = 0;
@ -246,7 +246,8 @@ static void getinfo_super0(struct mdinfo *info, void *sbv)
info->events = md_event(sb);
uuid_from_super0(info->uuid, sbv);
ident->name[0] = 0;
/* work_disks is calculated rather than read directly */
for (i=0; i < MD_SB_DISKS; i++)
if ((sb->disks[i].state & (1<<MD_DISK_SYNC)) &&
@ -365,7 +366,7 @@ static __u64 event_super0(void *sbv)
static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info)
static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info, char *ignored_name)
{
mdp_super_t *sb = malloc(MD_SB_BYTES + sizeof(bitmap_super_t));
int spares;

View File

@ -230,6 +230,8 @@ static void brief_examine_super1(void *sbv)
printf("%02x", sb->set_uuid[i]);
if ((i&3)==0 && i != 0) printf(":");
}
if (sb->set_name[0])
printf(" name=%.32s", sb->set_name);
printf("\n");
}
@ -238,6 +240,7 @@ static void detail_super1(void *sbv)
struct mdp_superblock_1 *sb = sbv;
int i;
printf(" Name : %.32s\n", sb->set_name);
printf(" UUID : ");
for (i=0; i<16; i++) {
printf("%02x", sb->set_uuid[i]);
@ -251,6 +254,8 @@ static void brief_detail_super1(void *sbv)
struct mdp_superblock_1 *sb = sbv;
int i;
if (sb->set_name[0])
printf(" name=%.32s", sb->set_name);
printf(" UUID=");
for (i=0; i<16; i++) {
printf("%02x", sb->set_uuid[i]);
@ -269,7 +274,7 @@ static void uuid_from_super1(int uuid[4], void * sbv)
cuuid[i] = super->set_uuid[i];
}
static void getinfo_super1(struct mdinfo *info, void *sbv)
static void getinfo_super1(struct mdinfo *info, mddev_ident_t ident, void *sbv)
{
struct mdp_superblock_1 *sb = sbv;
int working = 0;
@ -309,6 +314,9 @@ static void getinfo_super1(struct mdinfo *info, void *sbv)
memcpy(info->uuid, sb->set_uuid, 16);
strncpy(ident->name, sb->set_name, 32);
ident->name[32] = 0;
for (i=0; i< __le32_to_cpu(sb->max_dev); i++) {
role = __le16_to_cpu(sb->dev_roles[i]);
if (/*role == 0xFFFF || */role < info->array.raid_disks)
@ -375,7 +383,7 @@ static __u64 event_super1(void *sbv)
return __le64_to_cpu(sb->events);
}
static int init_super1(struct supertype *st, void **sbp, mdu_array_info_t *info)
static int init_super1(struct supertype *st, void **sbp, mdu_array_info_t *info, char *name)
{
struct mdp_superblock_1 *sb = malloc(1024);
int spares;
@ -402,7 +410,8 @@ static int init_super1(struct supertype *st, void **sbp, mdu_array_info_t *info)
*(__u32*)(sb->set_uuid+8) = random();
*(__u32*)(sb->set_uuid+12) = random();
/* FIXME name */
memset(sb->set_name, 0, 32);
strcpy(sb->set_name, name);
sb->ctime = __cpu_to_le64((unsigned long long)time(0));
sb->level = __cpu_to_le32(info->level);

13
tests/06name Normal file
View File

@ -0,0 +1,13 @@
set -x
# create an array with a name
$mdadm -CR $md0 -l0 -n2 --metadata=1 --name="Fred" $dev0 $dev1
$mdadm -E $dev0 | grep 'Name : Fred$' > /dev/null || exit 1
$mdadm -D $md0 | grep 'Name : Fred$' > /dev/null || exit 1
$mdadm -S $md0
$mdadm -A $md0 --name="Fred" $devlist
$mdadm -Db $md0
$mdadm -S $md0

6
util.c
View File

@ -227,6 +227,7 @@ int check_raid(int fd, char *name)
{
void *super;
struct mdinfo info;
struct mddev_ident_s ident;
time_t crtime;
struct supertype *st = guess_super(fd);
@ -235,7 +236,7 @@ int check_raid(int fd, char *name)
/* Looks like a raid array .. */
fprintf(stderr, Name ": %s appears to be part of a raid array:\n",
name);
st->ss->getinfo_super(&info, super);
st->ss->getinfo_super(&info, &ident, super);
free(super);
crtime = info.array.ctime;
fprintf(stderr, " level=%d devices=%d ctime=%s",
@ -607,7 +608,8 @@ struct supertype *guess_super(int fd)
rv = ss->load_super(st, fd, &sbp, NULL);
if (rv == 0) {
struct mdinfo info;
ss->getinfo_super(&info, sbp);
struct mddev_ident_s ident;
ss->getinfo_super(&info, &ident, sbp);
if (bestsuper == -1 ||
besttime < info.array.ctime) {
bestsuper = i;