Allow symlink creation to be disabled from command line or mdadm.conf

This commit is contained in:
Neil Brown 2006-08-11 18:00:05 +10:00
parent 0a6e1c6743
commit 38098016ca
8 changed files with 75 additions and 7 deletions

View File

@ -1,3 +1,8 @@
Changes Priot to this release
- When creating devices in /dev/md/ create matching symlinks
from /dev. e.g. /dev/md0 -> /dev/md/0.
Allow this to be disabled in mdadm.conf or on command line.
Changes Prior to 2.5.3 release Changes Prior to 2.5.3 release
- Document v0.91 superblocks in md.4 - Document v0.91 superblocks in md.4
- Make GPL explicit in man pages. - Make GPL explicit in man pages.

View File

@ -139,6 +139,7 @@ struct option long_options[] = {
{"re-add", 0, 0, ReAdd}, {"re-add", 0, 0, ReAdd},
{"homehost", 1, 0, HomeHost}, {"homehost", 1, 0, HomeHost},
{"auto-update-homehost", 0, 0, AutoHomeHost}, {"auto-update-homehost", 0, 0, AutoHomeHost},
{"symlinks", 1, 0, Symlinks},
/* For assemble */ /* For assemble */
{"uuid", 1, 0, 'u'}, {"uuid", 1, 0, 'u'},

View File

@ -255,6 +255,7 @@ mddev_dev_t load_partitions(void)
} }
struct createinfo createinfo = { struct createinfo createinfo = {
.symlinks = 1,
#ifdef DEBIAN #ifdef DEBIAN
.gid = 6, /* disk */ .gid = 6, /* disk */
.mode = 0660, .mode = 0660,
@ -364,8 +365,11 @@ static void createline(char *line)
if (!createinfo.supertype) if (!createinfo.supertype)
fprintf(stderr, Name ": metadata format %s unknown, ignoring\n", fprintf(stderr, Name ": metadata format %s unknown, ignoring\n",
w+9); w+9);
} else if (strncasecmp(w, "symlinks=yes", 12) == 0)
} else { createinfo.symlinks = 1;
else if (strncasecmp(w, "symlinks=no", 11) == 0)
createinfo.symlinks = 0;
else {
fprintf(stderr, Name ": unrecognised word on CREATE line: %s\n", fprintf(stderr, Name ": unrecognised word on CREATE line: %s\n",
w); w);
} }

22
mdadm.8
View File

@ -594,6 +594,28 @@ number will be considered unused if there is no active array for that
number, and there is no entry in /dev for that number and with a number, and there is no entry in /dev for that number and with a
non-standard name. non-standard name.
.TP
.BR --symlink = no
Normally when
.B --auto
causes
.I mdadm
to create devices in
.B /dev/md/
it will also create symlinks from
.B /dev/
with names starting with
.B md
or
.BR md_ .
Use
.B --symlink=no
to suppress this, or
.B --symlink=yes
to enforce this even if it is suppressing
.IR mdadm.conf .
.SH For assemble: .SH For assemble:
.TP .TP

20
mdadm.c
View File

@ -75,6 +75,7 @@ int main(int argc, char *argv[])
int force = 0; int force = 0;
int test = 0; int test = 0;
int assume_clean = 0; int assume_clean = 0;
char *symlinks = NULL;
/* autof indicates whether and how to create device node. /* autof indicates whether and how to create device node.
* bottom 3 bits are style. Rest (when shifted) are number of parts * bottom 3 bits are style. Rest (when shifted) are number of parts
* 0 - unset * 0 - unset
@ -499,6 +500,12 @@ int main(int argc, char *argv[])
autof = parse_auto(optarg, "--auto flag", 0); autof = parse_auto(optarg, "--auto flag", 0);
continue; continue;
case O(CREATE,Symlinks):
case O(BUILD,Symlinks):
case O(ASSEMBLE,Symlinks): /* auto creation of symlinks in /dev to /dev/md */
symlinks = optarg;
continue;
case O(BUILD,'f'): /* force honouring '-n 1' */ case O(BUILD,'f'): /* force honouring '-n 1' */
case O(GROW,'f'): /* ditto */ case O(GROW,'f'): /* ditto */
case O(CREATE,'f'): /* force honouring of device list */ case O(CREATE,'f'): /* force honouring of device list */
@ -858,6 +865,19 @@ int main(int argc, char *argv[])
fputs(Usage, stderr); fputs(Usage, stderr);
exit(2); exit(2);
} }
if (symlinks) {
struct createinfo *ci = conf_get_create_info();
if (strcasecmp(symlinks, "yes") == 0)
ci->symlinks = 1;
else if (strcasecmp(symlinks, "no") == 0)
ci->symlinks = 0;
else {
fprintf(stderr, Name ": option --symlinks must be 'no' or 'yes'\n");
exit(2);
}
}
/* Ok, got the option parsing out of the way /* Ok, got the option parsing out of the way
* hopefully it's mostly right but there might be some stuff * hopefully it's mostly right but there might be some stuff
* missing * missing

View File

@ -273,6 +273,20 @@ missing device entries should be created.
The name of the metadata format to use if none is explicitly given. The name of the metadata format to use if none is explicitly given.
This can be useful to impose a system-wide default of version-1 superblocks. This can be useful to impose a system-wide default of version-1 superblocks.
.TP
.B symlinks=no
Normally when creating devices in
.B /dev/md/
.I mdadm
will create a matching symlink from
.B /dev/
with a name starting
.B md
or
.BR md_ .
Give
.B symlinked=no
to suppress this symlink creation.
.RE .RE

View File

@ -132,6 +132,7 @@ struct createinfo {
int gid; int gid;
int autof; int autof;
int mode; int mode;
int symlinks;
struct supertype *supertype; struct supertype *supertype;
}; };
@ -167,6 +168,7 @@ enum special_options {
BackupFile, BackupFile,
HomeHost, HomeHost,
AutoHomeHost, AutoHomeHost,
Symlinks,
}; };
/* structures read from config file */ /* structures read from config file */

View File

@ -48,7 +48,7 @@ void make_dev_symlink(char *dev)
} }
void make_parts(char *dev, int cnt) void make_parts(char *dev, int cnt, int symlinks)
{ {
/* make 'cnt' partition devices for 'dev' /* make 'cnt' partition devices for 'dev'
* We use the major/minor from dev and add 1..cnt * We use the major/minor from dev and add 1..cnt
@ -88,7 +88,7 @@ void make_parts(char *dev, int cnt)
perror("chown"); perror("chown");
if (chmod(name, stb2.st_mode & 07777)) if (chmod(name, stb2.st_mode & 07777))
perror("chmod"); perror("chmod");
if (strncmp(name, "/dev/md/", 8) == 0) if (symlinks && strncmp(name, "/dev/md/", 8) == 0)
make_dev_symlink(name); make_dev_symlink(name);
stat(name, &stb2); stat(name, &stb2);
add_dev(name, &stb2, 0, NULL); add_dev(name, &stb2, 0, NULL);
@ -192,7 +192,7 @@ int open_mddev(char *dev, int autof)
return -1; return -1;
} else { } else {
if (major != MD_MAJOR && parts > 0) if (major != MD_MAJOR && parts > 0)
make_parts(dev, parts); make_parts(dev, parts, ci->symlinks);
return mdfd; return mdfd;
} }
} }
@ -279,10 +279,10 @@ int open_mddev(char *dev, int autof)
} }
stat(dev, &stb); stat(dev, &stb);
add_dev(dev, &stb, 0, NULL); add_dev(dev, &stb, 0, NULL);
if (strncmp(dev, "/dev/md/", 8) == 0) if (ci->symlinks && strncmp(dev, "/dev/md/", 8) == 0)
make_dev_symlink(dev); make_dev_symlink(dev);
if (major != MD_MAJOR) if (major != MD_MAJOR)
make_parts(dev,parts); make_parts(dev,parts, ci->symlinks);
} }
} }
mdfd = open(dev, O_RDWR, 0); mdfd = open(dev, O_RDWR, 0);