summaryrefslogtreecommitdiffstats
path: root/sbin/vinum/v.c
diff options
context:
space:
mode:
authorgrog <grog@FreeBSD.org>1999-01-21 00:45:11 +0000
committergrog <grog@FreeBSD.org>1999-01-21 00:45:11 +0000
commit216db4f79fa887ba32a505a17247f046b78b1f2c (patch)
tree049722e836280dfcdf4501d1ea87746697ffe79e /sbin/vinum/v.c
parent295e173f284e3b4b94e3f172bb8b0feac7169c31 (diff)
downloadFreeBSD-src-216db4f79fa887ba32a505a17247f046b78b1f2c.zip
FreeBSD-src-216db4f79fa887ba32a505a17247f046b78b1f2c.tar.gz
Update to reflect major changes in vinum kernel module
Diffstat (limited to 'sbin/vinum/v.c')
-rw-r--r--sbin/vinum/v.c110
1 files changed, 95 insertions, 15 deletions
diff --git a/sbin/vinum/v.c b/sbin/vinum/v.c
index a248b9e..d9a11f2 100644
--- a/sbin/vinum/v.c
+++ b/sbin/vinum/v.c
@@ -36,7 +36,7 @@
*
*/
-/* $Id: v.c,v 1.2 1998/12/28 16:32:39 peter Exp $ */
+/* $Id: v.c,v 1.24 1999/01/17 02:53:38 grog Exp grog $ */
#include <ctype.h>
#include <errno.h>
@@ -57,6 +57,9 @@
#include <sys/wait.h>
#include <readline/history.h>
#include <readline/readline.h>
+#include <sys/linker.h>
+#include <sys/module.h>
+#include <sys/resource.h>
FILE *cf; /* config file handle */
@@ -88,6 +91,8 @@ struct drive drive;
jmp_buf command_fail; /* return on a failed command */
int superdev; /* vinum super device */
+void start_daemon(void);
+
#define ofs(x) ((void *) (& ((struct confdata *) 0)->x)) /* offset of x in struct confdata */
/* create description-file
@@ -112,6 +117,20 @@ int tokens; /* number of tokens */
int
main(int argc, char *argv[])
{
+#if RAID5
+#define VINUMMOD "Vinum"
+#else
+#define VINUMMOD "vinum"
+#endif
+
+ if (modfind(VINUMMOD) < 0) {
+ /* need to load the vinum module */
+ if (kldload(VINUMMOD) < 0 || modfind(VINUMMOD) < 0) {
+ perror("vinum kernel module not available");
+ return 1;
+ }
+ }
+
superdev = open(VINUM_SUPERDEV_NAME, O_RDWR); /* open it */
if (superdev < 0) { /* no go */
@@ -122,6 +141,10 @@ main(int argc, char *argv[])
return 1;
}
}
+ /* Check if the dæmon is running. If not, start it in the
+ * background */
+ start_daemon();
+
if (argc > 1) { /* we have a command on the line */
if (setjmp(command_fail) != 0) /* long jumped out */
return -1;
@@ -156,6 +179,13 @@ main(int argc, char *argv[])
return 0; /* normal completion */
}
+/* stop the hard way */
+void
+vinum_quit(int argc, char *argv[], char *argv0[])
+{
+ exit(0);
+}
+
#define FUNKEY(x) { kw_##x, &vinum_##x } /* create pair "kw_foo", vinum_foo */
struct funkey {
@@ -191,6 +221,10 @@ struct funkey {
FUNKEY(printconfig),
FUNKEY(start),
FUNKEY(stop),
+ FUNKEY(makedev),
+ FUNKEY(help),
+ FUNKEY(quit),
+ FUNKEY(setdaemon),
FUNKEY(resetstats)
};
@@ -348,6 +382,7 @@ make_devices(void)
system("mkdir -p " VINUM_DIR "/drive " /* and make them again */
VINUM_DIR "/plex "
VINUM_DIR "/sd "
+ VINUM_DIR "/rsd "
VINUM_DIR "/vol "
VINUM_DIR "/rvol "
VINUM_RDIR);
@@ -440,10 +475,16 @@ make_devices(void)
if (mknod(filename, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IFBLK, sddev) < 0)
fprintf(stderr, "Can't create %s: %s\n", filename, strerror(errno));
- /* And /dev/vinum/sd/<sd> */
+ /* /dev/vinum/sd/<sd> */
sprintf(filename, VINUM_DIR "/sd/%s", sd.name);
if (mknod(filename, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IFBLK, sddev) < 0)
fprintf(stderr, "Can't create %s: %s\n", filename, strerror(errno));
+
+ /* And /dev/vinum/rsd/<sd> */
+ sprintf(filename, VINUM_DIR "/rsd/%s", sd.name);
+ sddev = VINUMCDEV(volno, plexno, sdno, VINUM_SD_TYPE);
+ if (mknod(filename, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IFCHR, sddev) < 0)
+ fprintf(stderr, "Can't create %s: %s\n", filename, strerror(errno));
}
}
}
@@ -461,6 +502,13 @@ make_devices(void)
}
}
+/* command line interface for the 'makedev' command */
+void
+vinum_makedev(int argc, char *argv[], char *arg0[])
+{
+ make_devices();
+}
+
/* Find the object "name". Return object type at type,
* and the index as the return value.
* If not found, return -1 and invalid_object.
@@ -516,13 +564,13 @@ find_object(const char *name, enum objecttype *type)
return -1;
}
-/* Continue reviving a plex in the background */
+/* Continue reviving a subdisk in the background */
void
-continue_revive(int plexno)
+continue_revive(int sdno)
{
- struct plex plex;
+ struct sd sd;
pid_t pid;
- get_plex_info(&plex, plexno);
+ get_sd_info(&sd, sdno);
#if VINUMDEBUG
if (debug)
@@ -537,27 +585,59 @@ continue_revive(int plexno)
struct vinum_ioctl_msg *message = (struct vinum_ioctl_msg *) &reply;
openlog("vinum", LOG_CONS | LOG_PERROR | LOG_PID, LOG_KERN);
- syslog(LOG_INFO | LOG_KERN, "reviving plex %s", plex.name);
+ syslog(LOG_INFO | LOG_KERN, "reviving %s", sd.name);
for (reply.error = EAGAIN; reply.error == EAGAIN;) {
- message->index = plexno; /* pass plex number */
- message->type = plex_object; /* and type of object */
+ message->index = sdno; /* pass sd number */
+ message->type = sd_object; /* and type of object */
message->state = object_up;
ioctl(superdev, VINUM_SETSTATE, message);
}
if (reply.error) {
syslog(LOG_ERR | LOG_KERN,
- "can't revive plex %s: %s",
- plex.name,
+ "can't revive %s: %s",
+ sd.name,
reply.msg[0] ? reply.msg : strerror(reply.error));
exit(1);
} else {
- get_plex_info(&plex, plexno); /* update the info */
- syslog(LOG_INFO | LOG_KERN, "plex %s is %s", plex.name, plex_state(plex.state));
+ get_sd_info(&sd, sdno); /* update the info */
+ syslog(LOG_INFO | LOG_KERN, "%s is %s", sd.name, sd_state(sd.state));
exit(0);
}
} else if (pid < 0) /* couldn't fork? */
- fprintf(stderr, "Can't continue reviving %s: %s\n", plex.name, strerror(errno));
+ fprintf(stderr, "Can't continue reviving %s: %s\n", sd.name, strerror(errno));
else
- printf("Reviving %s in the background\n", plex.name);
+ printf("Reviving %s in the background\n", sd.name);
+}
+
+/* Check if the daemon is running,
+ * start it if it isn't. The check itself
+ * could take a while, so we do it as a separate
+ * process, which will become the daemon if one isn't
+ * running already */
+void
+start_daemon(void)
+{
+ int pid;
+ int status;
+ int error;
+
+ pid = (int) fork();
+
+ if (pid == 0) { /* We're the child, do the work */
+ error = daemon(0, 0); /* this will fork again, but who's counting? */
+ if (error != 0) {
+ fprintf(stderr, "Can't start daemon: %s (%d)\n", strerror(errno), errno);
+ exit(1);
+ }
+ setproctitle("Vinum daemon"); /* show what we're doing */
+ status = ioctl(superdev, VINUM_FINDDAEMON, NULL);
+ if (status != 0) { /* no daemon, */
+ ioctl(superdev, VINUM_DAEMON, &verbose); /* we should hang here */
+ syslog(LOG_ERR | LOG_KERN, "%s", strerror(errno));
+ exit(1);
+ }
+ exit(0); /* when told to die */
+ } else if (pid < 0) /* couldn't fork */
+ printf("Can't fork to check daemon\n");
}
OpenPOWER on IntegriCloud