1 /* commands.c: vinum interface program, main commands */
3 * Copyright (c) 1997, 1998
4 * Nan Yang Computer Services Limited. All rights reserved.
6 * Written by Greg Lehey
8 * This software is distributed under the so-called ``Berkeley
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Company nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * This software is provided ``as is'', and any express or implied
24 * warranties, including, but not limited to, the implied warranties of
25 * merchantability and fitness for a particular purpose are disclaimed.
26 * In no event shall the company or contributors be liable for any
27 * direct, indirect, incidental, special, exemplary, or consequential
28 * damages (including, but not limited to, procurement of substitute
29 * goods or services; loss of use, data, or profits; or business
30 * interruption) however caused and on any theory of liability, whether
31 * in contract, strict liability, or tort (including negligence or
32 * otherwise) arising in any way out of the use of this software, even if
33 * advised of the possibility of such damage.
35 * $Id: commands.c,v 1.14 2000/11/14 20:01:23 grog Exp grog $
36 * $FreeBSD: src/sbin/vinum/commands.c,v 1.31.2.6 2003/06/06 05:13:29 grog Exp $
37 * $DragonFly: src/sbin/vinum/commands.c,v 1.10 2008/06/05 18:06:31 swildner Exp $
40 #define _KERNEL_STRUCTURES
54 #include <sys/ioctl.h>
55 #include <dev/raid/vinum/vinumhdr.h>
56 #include <dev/raid/vinum/request.h>
58 #include <sys/types.h>
59 #include <sys/linker.h>
60 #include <sys/module.h>
62 #include <readline/readline.h>
65 static void dorename(struct vinum_rename_msg
*msg
, const char *oldname
, const char *name
, int maxlen
);
68 vinum_create(int argc
, char *argv
[], char *arg0
[])
71 FILE *dfd
; /* file descriptor for the config file */
72 char buffer
[BUFSIZE
]; /* read config file in here */
73 char commandline
[BUFSIZE
]; /* issue command from here */
74 struct _ioctl_reply
*reply
;
75 int ioctltype
; /* for ioctl call */
76 char tempfile
[PATH_MAX
]; /* name of temp file for direct editing */
77 char *file
; /* file to read */
78 FILE *tf
; /* temp file */
80 if (argc
== 0) { /* no args, */
81 char *editor
; /* editor to start */
84 editor
= getenv("EDITOR");
86 editor
= "/usr/bin/vi";
87 sprintf(tempfile
, "/var/tmp/" VINUMMOD
".create.%d", getpid()); /* create a temp file */
88 tf
= fopen(tempfile
, "w"); /* open it */
90 fprintf(stderr
, "Can't open %s: %s\n", argv
[0], strerror(errno
));
93 printconfig(tf
, "# "); /* and put the current config it */
95 sprintf(commandline
, "%s %s", editor
, tempfile
); /* create an edit command */
96 status
= system(commandline
); /* do it */
98 fprintf(stderr
, "Can't edit config: status %d\n", status
);
102 } else if (argc
== 1)
105 fprintf(stderr
, "Expecting 1 parameter, not %d\n", argc
);
108 reply
= (struct _ioctl_reply
*) &buffer
;
109 dfd
= fopen(file
, "r");
110 if (dfd
== NULL
) { /* no go */
111 fprintf(stderr
, "Can't open %s: %s\n", file
, strerror(errno
));
114 if (ioctl(superdev
, VINUM_STARTCONFIG
, &force
)) { /* can't get config? */
115 printf("Can't configure: %s (%d)\n", strerror(errno
), errno
);
118 file_line
= 0; /* start with line 1 */
119 /* Parse the configuration, and add it to the global configuration */
120 for (;;) { /* love this style(9) */
123 configline
= fgets(buffer
, BUFSIZE
, dfd
);
125 if (configline
== NULL
) {
127 perror("Can't read config file");
131 fprintf(hist
, "%s", buffer
);
132 file_line
++; /* count the lines */
134 printf("%4d: %s", file_line
, buffer
);
135 strcpy(commandline
, buffer
); /* make a copy */
136 ioctl(superdev
, VINUM_CREATE
, buffer
);
137 if (reply
->error
!= 0) { /* error in config */
138 if (!vflag
) /* print this line anyway */
139 printf("%4d: %s", file_line
, commandline
);
140 fprintf(stdout
, "** %d %s: %s\n",
143 strerror(reply
->error
));
146 * XXX at the moment, we reset the config
147 * lock on error, so try to get it again.
148 * If we fail, don't cry again.
150 if (ioctl(superdev
, VINUM_STARTCONFIG
, &force
)) /* can't get config? */
154 fclose(dfd
); /* done with the config file */
155 ioctltype
= 0; /* saveconfig after update */
156 error
= ioctl(superdev
, VINUM_SAVECONFIG
, &ioctltype
); /* save the config to disk */
158 perror("Can't save Vinum config");
161 checkupdates(); /* make sure we're updating */
164 /* Read vinum config from a disk */
166 vinum_read(int argc
, char *argv
[], char *arg0
[])
169 char buffer
[BUFSIZE
]; /* read config file in here */
170 struct _ioctl_reply
*reply
;
173 reply
= (struct _ioctl_reply
*) &buffer
;
174 if (argc
< 1) { /* wrong arg count */
175 fprintf(stderr
, "Usage: read drive [drive ...]\n");
178 strcpy(buffer
, "read ");
179 for (i
= 0; i
< argc
; i
++) { /* each drive name */
180 strcat(buffer
, argv
[i
]);
184 if (ioctl(superdev
, VINUM_STARTCONFIG
, &force
)) { /* can't get config? */
185 fprintf(stderr
, "Can't configure: %s (%d)\n", strerror(errno
), errno
);
188 ioctl(superdev
, VINUM_CREATE
, &buffer
);
189 if (reply
->error
!= 0) { /* error in config */
190 fprintf(stdout
, "** %s: %s\n", reply
->msg
, strerror(reply
->error
));
191 error
= ioctl(superdev
, VINUM_RELEASECONFIG
, NULL
); /* save the config to disk */
193 perror("Can't save Vinum config");
195 error
= ioctl(superdev
, VINUM_RELEASECONFIG
, NULL
); /* save the config to disk */
197 perror("Can't save Vinum config");
200 checkupdates(); /* make sure we're updating */
205 vinum_debug(int argc
, char *argv
[], char *arg0
[])
207 struct debuginfo info
;
210 info
.param
= atoi(argv
[0]);
214 sleep(2); /* give a chance to leave the window */
216 ioctl(superdev
, VINUM_DEBUG
, (caddr_t
) & info
);
221 vinum_modify(int argc
, char *argv
[], char *arg0
[])
223 fprintf(stderr
, "Modify command is currently not implemented\n");
224 checkupdates(); /* make sure we're updating */
228 vinum_set(int argc
, char *argv
[], char *arg0
[])
230 fprintf(stderr
, "set is not implemented yet\n");
234 vinum_rm(int argc
, char *argv
[], char *arg0
[])
237 struct _ioctl_reply reply
;
238 struct vinum_ioctl_msg
*message
= (struct vinum_ioctl_msg
*) &reply
;
240 if (argc
== 0) /* start everything */
241 fprintf(stderr
, "Usage: rm object [object...]\n");
242 else { /* start specified objects */
244 enum objecttype type
;
246 for (index
= 0; index
< argc
; index
++) {
247 object
= find_object(argv
[index
], &type
); /* look for it */
248 if (type
== invalid_object
)
249 fprintf(stderr
, "Can't find object: %s\n", argv
[index
]);
251 message
->index
= object
; /* pass object number */
252 message
->type
= type
; /* and type of object */
253 message
->force
= force
; /* do we want to force the operation? */
254 message
->recurse
= recurse
; /* do we want to remove subordinates? */
255 ioctl(superdev
, VINUM_REMOVE
, message
);
256 if (reply
.error
!= 0) {
258 "Can't remove %s: %s (%d)\n",
260 reply
.msg
[0] ? reply
.msg
: strerror(reply
.error
),
263 fprintf(stderr
, "%s removed\n", argv
[index
]);
266 checkupdates(); /* make sure we're updating */
271 vinum_resetconfig(int argc
, char *argv
[], char *arg0
[])
276 if (! isatty (STDIN_FILENO
)) {
277 fprintf (stderr
, "Please enter this command from a tty device\n");
280 printf(" WARNING! This command will completely wipe out your vinum configuration.\n"
281 " All data will be lost. If you really want to do this, enter the text\n\n"
284 fgets(reply
, sizeof(reply
), stdin
);
285 if (strcmp(reply
, "NO FUTURE\n")) /* changed his mind */
286 printf("\n No change\n");
288 error
= ioctl(superdev
, VINUM_RESETCONFIG
, NULL
); /* trash config on disk */
291 fprintf(stderr
, "Can't reset configuration: objects are in use\n");
293 perror("Can't find vinum config");
295 make_devices(); /* recreate the /dev/vinum hierarchy */
296 printf("\b Vinum configuration obliterated\n");
297 start_daemon(); /* then restart the daemon */
300 checkupdates(); /* make sure we're updating */
303 /* Initialize subdisks */
305 vinum_init(int argc
, char *argv
[], char *arg0
[])
307 if (argc
> 0) { /* initialize plexes */
310 enum objecttype type
; /* type returned */
313 fflush(hist
); /* don't let all the kids do it. */
314 for (objindex
= 0; objindex
< argc
; objindex
++) {
315 objno
= find_object(argv
[objindex
], &type
); /* find the object */
317 printf("Can't find %s\n", argv
[objindex
]);
325 initplex(objno
, argv
[objindex
]);
329 initsd(objno
, dowait
);
333 printf("Can't initialize %s: wrong object type\n", argv
[objindex
]);
339 checkupdates(); /* make sure we're updating */
345 printf("Initializing volumes is not implemented yet\n");
349 initplex(int plexno
, char *name
)
352 int plexfh
= 0; /* file handle for plex */
354 char filename
[MAXPATHLEN
]; /* create a file name here */
356 /* Variables for use by children */
357 int failed
= 0; /* set if a child dies badly */
359 sprintf(filename
, VINUM_DIR
"/plex/%s", name
);
360 if ((plexfh
= open(filename
, O_RDWR
, S_IRWXU
)) < 0) { /* got a plex, open it */
362 * We don't actually write anything to the
363 * plex. We open it to ensure that nobody
364 * else tries to open it while we initialize
367 fprintf(stderr
, "can't open plex %s: %s\n", filename
, strerror(errno
));
371 pid
= fork(); /* into the background with you */
372 if (pid
!= 0) { /* I'm the parent, or we failed */
373 if (pid
< 0) /* failure */
374 printf("Couldn't fork: %s", strerror(errno
));
375 close(plexfh
); /* we don't need this any more */
380 * If we get here, we're either the first-level
381 * child (if we're not waiting) or we're going
384 for (sdno
= 0; sdno
< plex
.subdisks
; sdno
++) { /* initialize each subdisk */
385 get_plex_sd_info(&sd
, plexno
, sdno
);
388 /* Now wait for them to complete */
392 if (((int) pid
== -1)
393 && (errno
== ECHILD
)) /* all gone */
395 if (WEXITSTATUS(status
) != 0) { /* oh, oh */
396 printf("child %d exited with status 0x%x\n", pid
, WEXITSTATUS(status
));
402 message
->index
= plexno
; /* pass object number */
403 message
->type
= plex_object
; /* and type of object */
404 message
->state
= object_up
;
405 message
->force
= 1; /* insist */
406 ioctl(superdev
, VINUM_SETSTATE
, message
);
408 syslog(LOG_INFO
| LOG_KERN
, "plex %s initialized", plex
.name
);
410 syslog(LOG_ERR
| LOG_KERN
, "couldn't initialize plex %s, %d processes died",
413 if (dowait
== 0) /* we're the waiting child, */
414 exit(0); /* we've done our dash */
417 /* Initialize a subdisk. */
419 initsd(int sdno
, int dowait
)
422 struct _ioctl_reply reply
;
423 struct vinum_ioctl_msg
*message
= (struct vinum_ioctl_msg
*) &reply
;
424 char filename
[MAXPATHLEN
]; /* create a file name here */
426 /* Variables for use by children */
427 int sdfh
; /* and for subdisk */
428 int initsize
; /* actual size to write */
429 int64_t sdsize
; /* size of subdisk */
432 pid
= fork(); /* into the background with you */
433 if (pid
> 0) /* I'm the parent */
435 else if (pid
< 0) { /* failure */
436 printf("couldn't fork for subdisk %d: %s", sdno
, strerror(errno
));
440 if (SSize
!= 0) { /* specified a size for init */
442 SSize
<<= DEV_BSHIFT
;
443 initsize
= min(SSize
, MAXPLEXINITSIZE
);
445 initsize
= PLEXINITSIZE
;
446 openlog("vinum", LOG_CONS
| LOG_PERROR
| LOG_PID
, LOG_KERN
);
447 get_sd_info(&sd
, sdno
);
448 sdsize
= sd
.sectors
* DEV_BSIZE
; /* size of subdisk in bytes */
449 sprintf(filename
, VINUM_DIR
"/sd/%s", sd
.name
);
450 setproctitle("initializing %s", filename
); /* show what we're doing */
451 syslog(LOG_INFO
| LOG_KERN
, "initializing subdisk %s", filename
);
452 if ((sdfh
= open(filename
, O_RDWR
, S_IRWXU
)) < 0) { /* no go */
453 syslog(LOG_ERR
| LOG_KERN
,
454 "can't open subdisk %s: %s",
459 /* Set the subdisk in initializing state */
460 message
->index
= sd
.sdno
; /* pass object number */
461 message
->type
= sd_object
; /* and type of object */
462 message
->state
= object_initializing
;
463 message
->verify
= vflag
; /* verify what we write? */
464 message
->force
= 1; /* insist */
465 ioctl(superdev
, VINUM_SETSTATE
, message
);
466 if ((SSize
> 0) /* specified a size for init */
468 SSize
<<= DEV_BSHIFT
;
471 "Can't initialize %s: %s (%d)\n",
473 strerror(reply
.error
),
478 if (interval
) /* pause between copies */
479 usleep(interval
* 1000);
480 message
->index
= sd
.sdno
; /* pass object number */
481 message
->type
= sd_object
; /* and type of object */
482 message
->state
= object_up
;
483 message
->verify
= vflag
; /* verify what we write? */
484 message
->blocksize
= SSize
;
485 ioctl(superdev
, VINUM_SETSTATE
, message
);
487 while (reply
.error
== EAGAIN
); /* until we're done */
490 "Can't initialize %s: %s (%d)\n",
492 strerror(reply
.error
),
494 get_sd_info(&sd
, sdno
);
495 if (sd
.state
!= sd_up
)
496 /* Set the subdisk down */
497 message
->index
= sd
.sdno
; /* pass object number */
498 message
->type
= sd_object
; /* and type of object */
499 message
->state
= object_down
;
500 message
->verify
= vflag
; /* verify what we write? */
501 message
->force
= 1; /* insist */
502 ioctl(superdev
, VINUM_SETSTATE
, message
);
505 printf("subdisk %s initialized\n", filename
);
511 vinum_start(int argc
, char *argv
[], char *arg0
[])
514 struct _ioctl_reply reply
;
515 struct vinum_ioctl_msg
*message
= (struct vinum_ioctl_msg
*) &reply
;
517 if (argc
== 0) { /* start everything */
518 int devs
= getnumdevs();
519 struct statinfo statinfo
;
521 char *enamelist
; /* end of name list */
523 char **token
; /* list of tokens */
524 int tokens
; /* and their number */
526 bzero(&statinfo
, sizeof(struct statinfo
));
527 statinfo
.dinfo
= malloc(devs
* sizeof(struct statinfo
));
528 namelist
= malloc(devs
* (DEVSTAT_NAME_LEN
+ 8));
529 token
= malloc((devs
+ 1) * sizeof(char *));
530 if ((statinfo
.dinfo
== NULL
) || (namelist
== NULL
) || (token
== NULL
)) {
531 fprintf(stderr
, "Can't allocate memory for drive list\n");
534 bzero(statinfo
.dinfo
, sizeof(struct devinfo
));
536 tokens
= 0; /* no tokens yet */
537 if (getdevs(&statinfo
) < 0) { /* find out what devices we have */
538 perror("Can't get device list");
541 namelist
[0] = '\0'; /* start with empty namelist */
542 enamelist
= namelist
; /* point to the end of the list */
544 for (i
= 0; i
< devs
; i
++) {
545 struct devstat
*stat
= &statinfo
.dinfo
->devices
[i
];
547 if ((((stat
->device_type
& DEVSTAT_TYPE_MASK
) == DEVSTAT_TYPE_DIRECT
) /* disk device */
548 || ((stat
->device_type
& DEVSTAT_TYPE_MASK
) == DEVSTAT_TYPE_STORARRAY
)) /* storage array */
549 &&((stat
->device_type
& DEVSTAT_TYPE_IF_MASK
) != DEVSTAT_TYPE_IF_OTHER
) /* and not md */
550 &&((stat
->device_type
& DEVSTAT_TYPE_PASS
) == 0) /* and not passthrough */
551 &&((stat
->device_name
[0] != '\0'))) { /* and it has a name */
552 sprintf(enamelist
, "%s%s%d", _PATH_DEV
, stat
->device_name
, stat
->unit_number
);
553 token
[tokens
] = enamelist
; /* point to it */
554 tokens
++; /* one more token */
555 enamelist
= &enamelist
[strlen(enamelist
) + 1]; /* and start beyond the end */
558 free(statinfo
.dinfo
); /* don't need the list any more */
559 vinum_read(tokens
, token
, &token
[0]); /* start the system */
562 list_defective_objects(); /* and list anything that's down */
563 } else { /* start specified objects */
565 enum objecttype type
;
567 for (index
= 0; index
< argc
; index
++) {
568 object
= find_object(argv
[index
], &type
); /* look for it */
569 if (type
== invalid_object
)
570 fprintf(stderr
, "Can't find object: %s\n", argv
[index
]);
572 int doit
= 0; /* set to 1 if we pass our tests */
575 if (drive
.state
== drive_up
) /* already up */
576 fprintf(stderr
, "%s is already up\n", drive
.label
.name
);
582 if (sd
.state
== sd_up
) /* already up */
583 fprintf(stderr
, "%s is already up\n", sd
.name
);
589 if (plex
.state
== plex_up
) /* already up */
590 fprintf(stderr
, "%s is already up\n", plex
.name
);
595 * First, see if we can bring it up
596 * just by asking. This might happen
597 * if somebody has used setupstate on
598 * the subdisks. If we don't do this,
599 * we'll return success, but the plex
600 * won't have changed state. Note
601 * that we don't check for errors
604 message
->index
= plex
.plexno
; /* pass object number */
605 message
->type
= plex_object
; /* it's a plex */
606 message
->state
= object_up
;
607 message
->force
= 0; /* don't force it */
608 ioctl(superdev
, VINUM_SETSTATE
, message
);
609 for (sdno
= 0; sdno
< plex
.subdisks
; sdno
++) {
610 get_plex_sd_info(&sd
, object
, sdno
);
611 if ((sd
.state
>= sd_empty
)
612 && (sd
.state
<= sd_reviving
)) { /* candidate for start */
613 message
->index
= sd
.sdno
; /* pass object number */
614 message
->type
= sd_object
; /* it's a subdisk */
615 message
->state
= object_up
;
616 message
->force
= force
; /* don't force it, use a larger hammer */
619 * We don't do any checking here.
620 * The kernel module has a better
621 * understanding of these things,
624 if (SSize
!= 0) { /* specified a size for init */
626 SSize
<<= DEV_BSHIFT
;
627 message
->blocksize
= SSize
;
629 message
->blocksize
= DEFAULT_REVIVE_BLOCKSIZE
;
630 ioctl(superdev
, VINUM_SETSTATE
, message
);
631 if (reply
.error
!= 0) {
632 if (reply
.error
== EAGAIN
) /* we're reviving */
633 continue_revive(sd
.sdno
);
636 "Can't start %s: %s (%d)\n",
638 reply
.msg
[0] ? reply
.msg
: strerror(reply
.error
),
642 vinum_lsi(sd
.sdno
, 0);
649 if (vol
.state
== volume_up
) /* already up */
650 fprintf(stderr
, "%s is already up\n", vol
.name
);
660 message
->index
= object
; /* pass object number */
661 message
->type
= type
; /* and type of object */
662 message
->state
= object_up
;
663 message
->force
= force
; /* don't force it, use a larger hammer */
666 * We don't do any checking here.
667 * The kernel module has a better
668 * understanding of these things,
671 if (SSize
!= 0) { /* specified a size for init or revive */
673 SSize
<<= DEV_BSHIFT
;
674 message
->blocksize
= SSize
;
676 message
->blocksize
= 0;
677 ioctl(superdev
, VINUM_SETSTATE
, message
);
678 if (reply
.error
!= 0) {
679 if ((reply
.error
== EAGAIN
) /* we're reviving */
680 &&(type
== sd_object
))
681 continue_revive(object
);
684 "Can't start %s: %s (%d)\n",
686 reply
.msg
[0] ? reply
.msg
: strerror(reply
.error
),
690 vinum_li(object
, type
);
695 checkupdates(); /* make sure we're updating */
699 vinum_stop(int argc
, char *argv
[], char *arg0
[])
702 struct _ioctl_reply reply
;
703 struct vinum_ioctl_msg
*message
= (struct vinum_ioctl_msg
*) &reply
;
705 if (checkupdates() && (!force
)) /* not updating? */
707 message
->force
= force
; /* should we force the transition? */
708 if (argc
== 0) { /* stop vinum */
709 int fileid
= 0; /* ID of Vinum kld */
711 close(superdev
); /* we can't stop if we have vinum open */
712 sleep(1); /* wait for the daemon to let go */
713 fileid
= kldfind(VINUMMOD
);
714 if ((fileid
< 0) /* no go */
715 ||(kldunload(fileid
) < 0))
716 perror("Can't unload " VINUMMOD
);
718 fprintf(stderr
, VINUMMOD
" unloaded\n");
722 /* If we got here, the stop failed. Reopen the superdevice. */
723 superdev
= open(VINUM_SUPERDEV_NAME
, O_RDWR
); /* reopen vinum superdevice */
725 perror("Can't reopen Vinum superdevice");
728 } else { /* stop specified objects */
730 enum objecttype type
;
732 for (i
= 0; i
< argc
; i
++) {
733 object
= find_object(argv
[i
], &type
); /* look for it */
734 if (type
== invalid_object
)
735 fprintf(stderr
, "Can't find object: %s\n", argv
[i
]);
737 message
->index
= object
; /* pass object number */
738 message
->type
= type
; /* and type of object */
739 message
->state
= object_down
;
740 ioctl(superdev
, VINUM_SETSTATE
, message
);
741 if (reply
.error
!= 0)
743 "Can't stop %s: %s (%d)\n",
745 reply
.msg
[0] ? reply
.msg
: strerror(reply
.error
),
748 vinum_li(object
, type
);
755 vinum_label(int argc
, char *argv
[], char *arg0
[])
758 struct _ioctl_reply reply
;
759 int *message
= (int *) &reply
;
761 if (argc
== 0) /* start everything */
762 fprintf(stderr
, "label: please specify one or more volume names\n");
763 else { /* start specified objects */
765 enum objecttype type
;
767 for (i
= 0; i
< argc
; i
++) {
768 object
= find_object(argv
[i
], &type
); /* look for it */
769 if (type
== invalid_object
)
770 fprintf(stderr
, "Can't find object: %s\n", argv
[i
]);
771 else if (type
!= volume_object
) /* it exists, but it isn't a volume */
772 fprintf(stderr
, "%s is not a volume\n", argv
[i
]);
774 message
[0] = object
; /* pass object number */
775 ioctl(superdev
, VINUM_LABEL
, message
);
776 if (reply
.error
!= 0)
778 "Can't label %s: %s (%d)\n",
780 reply
.msg
[0] ? reply
.msg
: strerror(reply
.error
),
783 vinum_li(object
, type
);
787 checkupdates(); /* not updating? */
791 reset_volume_stats(int volno
, int recurse
)
793 struct vinum_ioctl_msg msg
;
794 struct _ioctl_reply
*reply
= (struct _ioctl_reply
*) &msg
;
797 msg
.type
= volume_object
;
798 /* XXX get these numbers right if we ever
799 * actually return errors */
800 if (ioctl(superdev
, VINUM_RESETSTATS
, &msg
) < 0) {
801 fprintf(stderr
, "Can't reset stats for volume %d: %s\n", volno
, reply
->msg
);
802 longjmp(command_fail
, -1);
803 } else if (recurse
) {
807 get_volume_info(&vol
, volno
);
808 for (plexno
= 0; plexno
< vol
.plexes
; plexno
++)
809 reset_plex_stats(vol
.plex
[plexno
], recurse
);
814 reset_plex_stats(int plexno
, int recurse
)
816 struct vinum_ioctl_msg msg
;
817 struct _ioctl_reply
*reply
= (struct _ioctl_reply
*) &msg
;
820 msg
.type
= plex_object
;
821 /* XXX get these numbers right if we ever
822 * actually return errors */
823 if (ioctl(superdev
, VINUM_RESETSTATS
, &msg
) < 0) {
824 fprintf(stderr
, "Can't reset stats for plex %d: %s\n", plexno
, reply
->msg
);
825 longjmp(command_fail
, -1);
826 } else if (recurse
) {
831 get_plex_info(&plex
, plexno
);
832 for (sdno
= 0; sdno
< plex
.subdisks
; sdno
++) {
833 get_plex_sd_info(&sd
, plex
.plexno
, sdno
);
834 reset_sd_stats(sd
.sdno
, recurse
);
840 reset_sd_stats(int sdno
, int recurse
)
842 struct vinum_ioctl_msg msg
;
843 struct _ioctl_reply
*reply
= (struct _ioctl_reply
*) &msg
;
846 msg
.type
= sd_object
;
847 /* XXX get these numbers right if we ever
848 * actually return errors */
849 if (ioctl(superdev
, VINUM_RESETSTATS
, &msg
) < 0) {
850 fprintf(stderr
, "Can't reset stats for subdisk %d: %s\n", sdno
, reply
->msg
);
851 longjmp(command_fail
, -1);
852 } else if (recurse
) {
853 get_sd_info(&sd
, sdno
); /* get the info */
854 reset_drive_stats(sd
.driveno
); /* and clear the drive */
859 reset_drive_stats(int driveno
)
861 struct vinum_ioctl_msg msg
;
862 struct _ioctl_reply
*reply
= (struct _ioctl_reply
*) &msg
;
865 msg
.type
= drive_object
;
866 /* XXX get these numbers right if we ever
867 * actually return errors */
868 if (ioctl(superdev
, VINUM_RESETSTATS
, &msg
) < 0) {
869 fprintf(stderr
, "Can't reset stats for drive %d: %s\n", driveno
, reply
->msg
);
870 longjmp(command_fail
, -1);
875 vinum_resetstats(int argc
, char *argv
[], char *argv0
[])
879 enum objecttype type
;
881 if (ioctl(superdev
, VINUM_GETCONFIG
, &vinum_conf
) < 0) {
882 perror("Can't get vinum config");
886 for (objno
= 0; objno
< vinum_conf
.volumes_allocated
; objno
++)
887 reset_volume_stats(objno
, 1); /* clear everything recursively */
889 for (i
= 0; i
< argc
; i
++) {
890 objno
= find_object(argv
[i
], &type
);
891 if (objno
>= 0) { /* not invalid */
894 reset_drive_stats(objno
);
898 reset_sd_stats(objno
, recurse
);
902 reset_plex_stats(objno
, recurse
);
906 reset_volume_stats(objno
, recurse
);
909 case invalid_object
: /* can't get this */
917 /* Attach a subdisk to a plex, or a plex to a volume.
918 * attach subdisk plex [offset] [rename]
919 * attach plex volume [rename]
922 vinum_attach(int argc
, char *argv
[], char *argv0
[])
925 enum objecttype supertype
;
926 struct vinum_ioctl_msg msg
;
927 struct _ioctl_reply
*reply
= (struct _ioctl_reply
*) &msg
;
928 const char *objname
= argv
[0];
929 const char *supername
= argv
[1];
932 char oldname
[MAXNAME
+ 8];
933 char newname
[MAXNAME
+ 8];
934 int rename
= 0; /* set if we want to rename the object */
939 "Usage: \tattach <subdisk> <plex> [rename] [<plexoffset>]\n"
940 "\tattach <plex> <volume> [rename]\n");
943 if (ioctl(superdev
, VINUM_GETCONFIG
, &vinum_conf
) < 0) {
944 perror("Can't get vinum config");
947 msg
.index
= find_object(objname
, &msg
.type
); /* find the object to attach */
948 msg
.otherobject
= find_object(supername
, &supertype
); /* and the object to attach to */
949 msg
.force
= force
; /* did we specify the use of force? */
950 msg
.recurse
= recurse
;
951 msg
.offset
= -1; /* and no offset */
953 for (i
= 2; i
< argc
; i
++) {
954 if (!strcmp(argv
[i
], "rename")) {
956 msg
.rename
= 1; /* do renaming */
957 } else if (!isdigit(argv
[i
][0])) { /* not an offset */
958 fprintf(stderr
, "Unknown attribute: %s\n", supername
);
961 msg
.offset
= sizespec(argv
[i
]);
966 find_object(argv
[1], &supertype
);
967 if (supertype
!= plex_object
) { /* huh? */
968 fprintf(stderr
, "%s can only be attached to a plex\n", objname
);
971 if ((plex
.organization
!= plex_concat
) /* not a cat plex, */
973 fprintf(stderr
, "Can't attach subdisks to a %s plex\n", plex_org(plex
.organization
));
976 sdno
= msg
.index
; /* note the subdisk number for later */
980 find_object(argv
[1], &supertype
);
981 if (supertype
!= volume_object
) { /* huh? */
982 fprintf(stderr
, "%s can only be attached to a volume\n", objname
);
989 fprintf(stderr
, "Can only attach subdisks and plexes\n");
993 fprintf(stderr
, "%s is not a Vinum object\n", objname
);
997 ioctl(superdev
, VINUM_ATTACH
, &msg
);
998 if (reply
->error
!= 0) {
999 if (reply
->error
== EAGAIN
) /* reviving */
1000 continue_revive(sdno
); /* continue the revive */
1003 "Can't attach %s to %s: %s (%d)\n",
1006 reply
->msg
[0] ? reply
->msg
: strerror(reply
->error
),
1014 /* we've overwritten msg with the
1015 * ioctl reply, start again */
1016 msg
.index
= find_object(objname
, &msg
.type
); /* find the object to rename */
1019 get_sd_info(&sd
, msg
.index
);
1020 get_plex_info(&plex
, sd
.plexno
);
1021 for (sdno
= 0; sdno
< plex
.subdisks
; sdno
++) {
1022 if (plex
.sdnos
[sdno
] == msg
.index
) /* found our subdisk */
1025 sprintf(newname
, "%s.s%d", plex
.name
, sdno
);
1026 sprintf(oldname
, "%s", sd
.name
);
1027 vinum_rename_2(oldname
, newname
);
1031 get_plex_info(&plex
, msg
.index
);
1032 get_volume_info(&vol
, plex
.volno
);
1033 for (plexno
= 0; plexno
< vol
.plexes
; plexno
++) {
1034 if (vol
.plex
[plexno
] == msg
.index
) /* found our subdisk */
1037 sprintf(newname
, "%s.p%d", vol
.name
, plexno
);
1038 sprintf(oldname
, "%s", plex
.name
);
1039 vinum_rename_2(oldname
, newname
); /* this may recurse */
1042 default: /* can't get here */
1046 checkupdates(); /* make sure we're updating */
1049 /* Detach a subdisk from a plex, or a plex from a volume.
1050 * detach subdisk plex [rename]
1051 * detach plex volume [rename]
1054 vinum_detach(int argc
, char *argv
[], char *argv0
[])
1056 struct vinum_ioctl_msg msg
;
1057 struct _ioctl_reply
*reply
= (struct _ioctl_reply
*) &msg
;
1062 "Usage: \tdetach <subdisk> [rename]\n"
1063 "\tdetach <plex> [rename]\n");
1066 if (ioctl(superdev
, VINUM_GETCONFIG
, &vinum_conf
) < 0) {
1067 perror("Can't get vinum config");
1070 msg
.index
= find_object(argv
[0], &msg
.type
); /* find the object to detach */
1071 msg
.force
= force
; /* did we specify the use of force? */
1072 msg
.rename
= 0; /* don't specify new name */
1073 msg
.recurse
= recurse
; /* but recurse if we have to */
1075 /* XXX are we going to keep this?
1076 * Don't document it yet, since the
1077 * kernel side of things doesn't
1080 if (!strcmp(argv
[1], "rename"))
1081 msg
.rename
= 1; /* do renaming */
1083 fprintf(stderr
, "Unknown attribute: %s\n", argv
[1]);
1087 if ((msg
.type
!= sd_object
)
1088 && (msg
.type
!= plex_object
)) {
1089 fprintf(stderr
, "Can only detach subdisks and plexes\n");
1092 ioctl(superdev
, VINUM_DETACH
, &msg
);
1093 if (reply
->error
!= 0)
1095 "Can't detach %s: %s (%d)\n",
1097 reply
->msg
[0] ? reply
->msg
: strerror(reply
->error
),
1099 checkupdates(); /* make sure we're updating */
1103 dorename(struct vinum_rename_msg
*msg
, const char *oldname
, const char *name
, int maxlen
)
1105 struct _ioctl_reply
*reply
= (struct _ioctl_reply
*) msg
;
1107 if (strlen(name
) > maxlen
) {
1108 fprintf(stderr
, "%s is too long\n", name
);
1111 strcpy(msg
->newname
, name
);
1112 ioctl(superdev
, VINUM_RENAME
, msg
);
1113 if (reply
->error
!= 0)
1115 "Can't rename %s to %s: %s (%d)\n",
1118 reply
->msg
[0] ? reply
->msg
: strerror(reply
->error
),
1122 /* Rename an object:
1123 * rename <object> "newname"
1126 vinum_rename_2(char *oldname
, char *newname
)
1128 struct vinum_rename_msg msg
;
1132 msg
.index
= find_object(oldname
, &msg
.type
); /* find the object to rename */
1133 msg
.recurse
= recurse
;
1135 /* Ugh. Determine how long the name may be */
1138 dorename(&msg
, oldname
, newname
, MAXDRIVENAME
);
1142 dorename(&msg
, oldname
, newname
, MAXSDNAME
);
1147 dorename(&msg
, oldname
, newname
, MAXPLEXNAME
);
1151 get_plex_info(&plex
, plexno
); /* find out who we are */
1152 msg
.type
= sd_object
;
1153 for (sdno
= 0; sdno
< plex
.subdisks
; sdno
++) {
1154 char sdname
[MAXPLEXNAME
+ 8];
1156 get_plex_sd_info(&sd
, plex
.plexno
, sdno
); /* get info about the subdisk */
1157 sprintf(sdname
, "%s.s%d", newname
, sdno
);
1158 msg
.index
= sd
.sdno
; /* number of the subdisk */
1159 dorename(&msg
, sd
.name
, sdname
, MAXSDNAME
);
1166 dorename(&msg
, oldname
, newname
, MAXVOLNAME
);
1171 get_volume_info(&vol
, volno
); /* find out who we are */
1172 for (plexno
= 0; plexno
< vol
.plexes
; plexno
++) {
1173 char plexname
[MAXVOLNAME
+ 8];
1175 msg
.type
= plex_object
;
1176 sprintf(plexname
, "%s.p%d", newname
, plexno
);
1177 msg
.index
= vol
.plex
[plexno
]; /* number of the plex */
1178 dorename(&msg
, plex
.name
, plexname
, MAXPLEXNAME
);
1179 get_plex_info(&plex
, vol
.plex
[plexno
]); /* find out who we are */
1180 msg
.type
= sd_object
;
1181 for (sdno
= 0; sdno
< plex
.subdisks
; sdno
++) {
1182 char sdname
[MAXPLEXNAME
+ 8];
1184 get_plex_sd_info(&sd
, plex
.plexno
, sdno
); /* get info about the subdisk */
1185 sprintf(sdname
, "%s.s%d", plexname
, sdno
);
1186 msg
.index
= sd
.sdno
; /* number of the subdisk */
1187 dorename(&msg
, sd
.name
, sdname
, MAXSDNAME
);
1194 fprintf(stderr
, "%s is not a Vinum object\n", oldname
);
1200 vinum_rename(int argc
, char *argv
[], char *argv0
[])
1203 fprintf(stderr
, "Usage: \trename <object> <new name>\n");
1206 if (ioctl(superdev
, VINUM_GETCONFIG
, &vinum_conf
) < 0) {
1207 perror("Can't get vinum config");
1210 vinum_rename_2(argv
[0], argv
[1]);
1211 checkupdates(); /* make sure we're updating */
1217 * mv <dest> <src> ...
1220 vinum_mv(int argc
, char *argv
[], char *argv0
[])
1222 int i
; /* loop index */
1225 enum objecttype srct
;
1226 enum objecttype destt
;
1228 struct _ioctl_reply reply
;
1229 struct vinum_ioctl_msg
*msg
= (struct vinum_ioctl_msg
*) &reply
;
1232 fprintf(stderr
, "Usage: \tmove <dest> <src> ...\n");
1235 /* Get current config */
1236 if (ioctl(superdev
, VINUM_GETCONFIG
, &vinum_conf
) < 0) {
1237 perror("Cannot get vinum config\n");
1240 /* Get our destination */
1241 destobj
= find_object(argv
[0], &destt
);
1242 if (destobj
== -1) {
1243 fprintf(stderr
, "Can't find %s\n", argv
[0]);
1246 /* Verify that the target is a drive */
1247 if (destt
!= drive_object
) {
1248 fprintf(stderr
, "%s is not a drive\n", argv
[0]);
1251 for (i
= 1; i
< argc
; i
++) { /* for all the sources */
1252 srcobj
= find_object(argv
[i
], &srct
);
1254 fprintf(stderr
, "Can't find %s\n", argv
[i
]);
1257 msg
->index
= destobj
;
1258 switch (srct
) { /* Handle the source object */
1259 case drive_object
: /* Move all subdisks on the drive to dst. */
1260 get_drive_info(&drive
, srcobj
); /* get info on drive */
1261 for (sdno
= 0; sdno
< vinum_conf
.subdisks_allocated
; ++sdno
) {
1262 get_sd_info(&sd
, sdno
);
1263 if (sd
.driveno
== srcobj
) {
1264 msg
->index
= destobj
;
1265 msg
->otherobject
= sd
.sdno
;
1266 if (ioctl(superdev
, VINUM_MOVE
, msg
) < 0)
1268 "Can't move %s (part of %s) to %s: %s (%d)\n",
1272 strerror(reply
.error
),
1279 msg
->otherobject
= srcobj
;
1280 if (ioctl(superdev
, VINUM_MOVE
, msg
) < 0)
1282 "Can't move %s to %s: %s (%d)\n",
1285 strerror(reply
.error
),
1290 get_plex_info(&plex
, srcobj
);
1291 for (sdno
= 0; sdno
< plex
.subdisks
; ++sdno
) {
1292 get_plex_sd_info(&sd
, plex
.plexno
, sdno
);
1293 msg
->index
= destobj
;
1294 msg
->otherobject
= sd
.sdno
;
1295 if (ioctl(superdev
, VINUM_MOVE
, msg
) < 0)
1297 "Can't move %s (part of %s) to %s: %s (%d)\n",
1301 strerror(reply
.error
),
1307 case invalid_object
:
1309 fprintf(stderr
, "Can't move %s (inappropriate object).\n", argv
[i
]);
1314 "Can't move %s to %s: %s (%d)\n",
1317 strerror(reply
.error
),
1320 checkupdates(); /* make sure we're updating */
1324 * Replace objects. Not implemented, may never be.
1327 vinum_replace(int argc
, char *argv
[], char *argv0
[])
1329 fprintf(stderr
, "'replace' not implemented yet. Use 'move' instead\n");
1332 /* Primitive help function */
1334 vinum_help(int argc
, char *argv
[], char *argv0
[])
1339 "create [-f description-file]\n"
1340 " Create a volume as described in description-file\n"
1341 "attach plex volume [rename]\n"
1342 "attach subdisk plex [offset] [rename]\n"
1343 " Attach a plex to a volume, or a subdisk to a plex.\n"
1345 " Cause the volume manager to enter the kernel debugger.\n"
1347 " Set debugging flags.\n"
1348 "detach [plex | subdisk]\n"
1349 " Detach a plex or subdisk from the volume or plex to which it is\n"
1352 " List information about volume manager state.\n"
1353 "init [-v] [-w] plex\n"
1354 " Initialize a plex by writing zeroes to all its subdisks.\n"
1356 " Create a volume label\n"
1357 "list [-r] [-s] [-v] [-V] [volume | plex | subdisk]\n"
1358 " List information about specified objects\n"
1359 "l [-r] [-s] [-v] [-V] [volume | plex | subdisk]\n"
1360 " List information about specified objects (alternative to\n"
1362 "ld [-r] [-s] [-v] [-V] [volume]\n"
1363 " List information about drives\n"
1364 "ls [-r] [-s] [-v] [-V] [subdisk]\n"
1365 " List information about subdisks\n"
1366 "lp [-r] [-s] [-v] [-V] [plex]\n"
1367 " List information about plexes\n"
1368 "lv [-r] [-s] [-v] [-V] [volume]\n"
1369 " List information about volumes\n"
1370 "printconfig [file]\n"
1371 " Write a copy of the current configuration to file.\n"
1373 " Remake the device nodes in " _PATH_DEV
"vinum.\n"
1374 "move drive [subdisk | plex | drive]\n"
1375 " Move the subdisks of the specified object(s) to drive.\n"
1377 " Exit the vinum program when running in interactive mode. Nor-\n"
1378 " mally this would be done by entering the EOF character.\n"
1379 "read disk [disk...]\n"
1380 " Read the vinum configuration from the specified disks.\n"
1381 "rename [-r] [drive | subdisk | plex | volume] newname\n"
1382 " Change the name of the specified object.\n"
1384 " Reset the complete vinum configuration.\n"
1385 "resetstats [-r] [volume | plex | subdisk]\n"
1386 " Reset statistisc counters for the specified objects, or for all\n"
1387 " objects if none are specified.\n"
1388 "rm [-f] [-r] volume | plex | subdisk\n"
1389 " Remove an object\n"
1391 " Save vinum configuration to disk.\n"
1392 "setdaemon [value]\n"
1393 " Set daemon configuration.\n"
1395 " Read configuration from all vinum drives.\n"
1396 "start [volume | plex | subdisk]\n"
1397 " Allow the system to access the objects\n"
1398 "stop [-f] [volume | plex | subdisk]\n"
1399 " Terminate access to the objects, or stop vinum if no parameters\n"
1405 /* Set daemon options.
1406 * XXX quick and dirty: use a bitmap, which requires
1407 * knowing which bit does what. FIXME */
1409 vinum_setdaemon(int argc
, char *argv
[], char *argv0
[])
1415 if (ioctl(superdev
, VINUM_GETDAEMON
, &options
) < 0)
1416 fprintf(stderr
, "Can't get daemon options: %s (%d)\n", strerror(errno
), errno
);
1418 printf("Options mask: %d\n", options
);
1422 options
= atoi(argv
[0]);
1423 if (ioctl(superdev
, VINUM_SETDAEMON
, &options
) < 0)
1424 fprintf(stderr
, "Can't set daemon options: %s (%d)\n", strerror(errno
), errno
);
1428 fprintf(stderr
, "Usage: \tsetdaemon [<bitmask>]\n");
1430 checkupdates(); /* make sure we're updating */
1438 if (ioctl(superdev
, VINUM_GETDAEMON
, &options
) < 0)
1439 fprintf(stderr
, "Can't get daemon options: %s (%d)\n", strerror(errno
), errno
);
1440 if (options
& daemon_noupdate
) {
1441 fprintf(stderr
, "*** Warning: configuration updates are disabled. ***\n");
1447 /* Save config info */
1449 vinum_saveconfig(int argc
, char *argv
[], char *argv0
[])
1454 printf("Usage: saveconfig\n");
1457 ioctltype
= 1; /* user saveconfig */
1458 if (ioctl(superdev
, VINUM_SAVECONFIG
, &ioctltype
) < 0)
1459 fprintf(stderr
, "Can't save configuration: %s (%d)\n", strerror(errno
), errno
);
1460 checkupdates(); /* make sure we're updating */
1464 * Create a volume name for the quick and dirty
1465 * commands. It will be of the form "vinum#",
1466 * where # is a small positive number.
1471 int v
; /* volume number */
1472 static char volumename
[MAXVOLNAME
]; /* name to create */
1473 enum objecttype type
;
1475 objectname
= volumename
; /* point to it */
1477 sprintf(objectname
, "vinum%d", v
); /* create the name */
1478 if (find_object(objectname
, &type
) == -1) /* does it exist? */
1479 return; /* no, it's ours */
1484 * Create a drive for the quick and dirty
1485 * commands. The name will be of the form
1486 * vinumdrive#, where # is a small positive
1487 * number. Return the name of the drive.
1490 create_drive(char *devicename
)
1492 int d
; /* volume number */
1493 static char drivename
[MAXDRIVENAME
]; /* name to create */
1494 enum objecttype type
;
1495 struct _ioctl_reply
*reply
;
1498 * We're never likely to get anything
1499 * like 10000 drives. The only reason for
1500 * this limit is to stop the thing
1501 * looping if we have a bug somewhere.
1503 for (d
= 0; d
< 100000; d
++) { /* look for a free drive number */
1504 sprintf(drivename
, "vinumdrive%d", d
); /* create the name */
1505 if (find_object(drivename
, &type
) == -1) { /* does it exist? */
1506 char command
[MAXDRIVENAME
* 2];
1508 sprintf(command
, "drive %s device %s", drivename
, devicename
); /* create a create command */
1510 printf("drive %s device %s\n", drivename
, devicename
); /* create a create command */
1511 ioctl(superdev
, VINUM_CREATE
, command
);
1512 reply
= (struct _ioctl_reply
*) &command
;
1513 if (reply
->error
!= 0) { /* error in config */
1516 "Can't create drive %s, device %s: %s\n",
1522 "Can't create drive %s, device %s: %s (%d)\n",
1525 strerror(reply
->error
),
1527 longjmp(command_fail
, -1); /* give up */
1529 find_object(drivename
, &type
);
1530 return &drive
; /* return the name of the drive */
1533 fprintf(stderr
, "Can't generate a drive name\n");
1539 * Create a volume with a single concatenated plex from
1540 * as much space as we can get on the specified drives.
1541 * If the drives aren't Vinum drives, make them so.
1544 vinum_concat(int argc
, char *argv
[], char *argv0
[])
1546 int o
; /* object number */
1547 char buffer
[BUFSIZE
];
1548 struct drive
*drive
; /* drive we're currently looking at */
1549 struct _ioctl_reply
*reply
;
1552 enum objecttype type
;
1554 reply
= (struct _ioctl_reply
*) &buffer
;
1555 if (ioctl(superdev
, VINUM_STARTCONFIG
, &force
)) { /* can't get config? */
1556 printf("Can't configure: %s (%d)\n", strerror(errno
), errno
);
1559 if (!objectname
) /* we need a name for our object */
1561 sprintf(buffer
, "volume %s", objectname
);
1563 printf("volume %s\n", objectname
);
1564 ioctl(superdev
, VINUM_CREATE
, buffer
); /* create the volume */
1565 if (reply
->error
!= 0) { /* error in config */
1568 "Can't create volume %s: %s\n",
1573 "Can't create volume %s: %s (%d)\n",
1575 strerror(reply
->error
),
1577 longjmp(command_fail
, -1); /* give up */
1579 sprintf(buffer
, "plex name %s.p0 org concat", objectname
);
1581 printf(" plex name %s.p0 org concat\n", objectname
);
1582 ioctl(superdev
, VINUM_CREATE
, buffer
);
1583 if (reply
->error
!= 0) { /* error in config */
1586 "Can't create plex %s.p0: %s\n",
1591 "Can't create plex %s.p0: %s (%d)\n",
1593 strerror(reply
->error
),
1595 longjmp(command_fail
, -1); /* give up */
1597 for (o
= 0; o
< argc
; o
++) {
1598 if ((drive
= find_drive_by_devname(argv
[o
])) == NULL
) /* doesn't exist */
1599 drive
= create_drive(argv
[o
]); /* create it */
1600 sprintf(buffer
, "sd name %s.p0.s%d drive %s size 0", objectname
, o
, drive
->label
.name
);
1602 printf(" sd name %s.p0.s%d drive %s size 0\n", objectname
, o
, drive
->label
.name
);
1603 ioctl(superdev
, VINUM_CREATE
, buffer
);
1604 if (reply
->error
!= 0) { /* error in config */
1607 "Can't create subdisk %s.p0.s%d: %s\n",
1613 "Can't create subdisk %s.p0.s%d: %s (%d)\n",
1616 strerror(reply
->error
),
1618 longjmp(command_fail
, -1); /* give up */
1622 /* done, save the config */
1623 ioctltype
= 0; /* saveconfig after update */
1624 error
= ioctl(superdev
, VINUM_SAVECONFIG
, &ioctltype
); /* save the config to disk */
1626 perror("Can't save Vinum config");
1627 find_object(objectname
, &type
); /* find the index of the volume */
1628 make_vol_dev(vol
.volno
, 1); /* and create the devices */
1630 vflag
--; /* XXX don't give too much detail */
1631 find_object(objectname
, &type
); /* point to the volume */
1632 vinum_lvi(vol
.volno
, 1); /* and print info about it */
1638 * Create a volume with a single striped plex from
1639 * as much space as we can get on the specified drives.
1640 * If the drives aren't Vinum drives, make them so.
1643 vinum_stripe(int argc
, char *argv
[], char *argv0
[])
1645 int o
; /* object number */
1646 char buffer
[BUFSIZE
];
1647 struct drive
*drive
; /* drive we're currently looking at */
1648 struct _ioctl_reply
*reply
;
1651 enum objecttype type
;
1653 int fe
; /* freelist entry index */
1655 struct drive_freelist freelist
;
1656 struct ferq
{ /* request to pass to ioctl */
1661 u_int64_t bigchunk
; /* biggest chunk in freelist */
1664 reply
= (struct _ioctl_reply
*) &buffer
;
1667 * First, check our drives.
1670 fprintf(stderr
, "You need at least two drives to create a striped plex\n");
1673 if (ioctl(superdev
, VINUM_STARTCONFIG
, &force
)) { /* can't get config? */
1674 printf("Can't configure: %s (%d)\n", strerror(errno
), errno
);
1677 if (!objectname
) /* we need a name for our object */
1679 for (o
= 0; o
< argc
; o
++) {
1680 if ((drive
= find_drive_by_devname(argv
[o
])) == NULL
) /* doesn't exist */
1681 drive
= create_drive(argv
[o
]); /* create it */
1682 /* Now find the largest chunk available on the drive */
1683 bigchunk
= 0; /* ain't found nothin' yet */
1684 for (fe
= 0; fe
< drive
->freelist_entries
; fe
++) {
1685 freeunion
.ferq
.driveno
= drive
->driveno
;
1686 freeunion
.ferq
.fe
= fe
;
1687 if (ioctl(superdev
, VINUM_GETFREELIST
, &freeunion
.freelist
) < 0) {
1689 "Can't get free list element %d: %s\n",
1692 longjmp(command_fail
, -1);
1694 bigchunk
= bigchunk
> freeunion
.freelist
.sectors
? bigchunk
: freeunion
.freelist
.sectors
; /* max it */
1696 maxsize
= min(maxsize
, bigchunk
); /* this is as much as we can do */
1699 /* Now create the volume */
1700 sprintf(buffer
, "volume %s", objectname
);
1702 printf("volume %s\n", objectname
);
1703 ioctl(superdev
, VINUM_CREATE
, buffer
); /* create the volume */
1704 if (reply
->error
!= 0) { /* error in config */
1707 "Can't create volume %s: %s\n",
1712 "Can't create volume %s: %s (%d)\n",
1714 strerror(reply
->error
),
1716 longjmp(command_fail
, -1); /* give up */
1718 sprintf(buffer
, "plex name %s.p0 org striped 256k", objectname
);
1720 printf(" plex name %s.p0 org striped 256k\n", objectname
);
1721 ioctl(superdev
, VINUM_CREATE
, buffer
);
1722 if (reply
->error
!= 0) { /* error in config */
1725 "Can't create plex %s.p0: %s\n",
1730 "Can't create plex %s.p0: %s (%d)\n",
1732 strerror(reply
->error
),
1734 longjmp(command_fail
, -1); /* give up */
1736 for (o
= 0; o
< argc
; o
++) {
1737 drive
= find_drive_by_devname(argv
[o
]); /* we know it exists... */
1739 "sd name %s.p0.s%d drive %s size %lldb",
1743 (long long) maxsize
);
1745 printf(" sd name %s.p0.s%d drive %s size %lldb\n",
1749 (long long) maxsize
);
1750 ioctl(superdev
, VINUM_CREATE
, buffer
);
1751 if (reply
->error
!= 0) { /* error in config */
1754 "Can't create subdisk %s.p0.s%d: %s\n",
1760 "Can't create subdisk %s.p0.s%d: %s (%d)\n",
1763 strerror(reply
->error
),
1765 longjmp(command_fail
, -1); /* give up */
1769 /* done, save the config */
1770 ioctltype
= 0; /* saveconfig after update */
1771 error
= ioctl(superdev
, VINUM_SAVECONFIG
, &ioctltype
); /* save the config to disk */
1773 perror("Can't save Vinum config");
1774 find_object(objectname
, &type
); /* find the index of the volume */
1775 make_vol_dev(vol
.volno
, 1); /* and create the devices */
1777 vflag
--; /* XXX don't give too much detail */
1778 find_object(objectname
, &type
); /* point to the volume */
1779 vinum_lvi(vol
.volno
, 1); /* and print info about it */
1784 * Create a volume with a single RAID-4 plex from
1785 * as much space as we can get on the specified drives.
1786 * If the drives aren't Vinum drives, make them so.
1789 vinum_raid4(int argc
, char *argv
[], char *argv0
[])
1791 int o
; /* object number */
1792 char buffer
[BUFSIZE
];
1793 struct drive
*drive
; /* drive we're currently looking at */
1794 struct _ioctl_reply
*reply
;
1797 enum objecttype type
;
1799 int fe
; /* freelist entry index */
1801 struct drive_freelist freelist
;
1802 struct ferq
{ /* request to pass to ioctl */
1807 u_int64_t bigchunk
; /* biggest chunk in freelist */
1810 reply
= (struct _ioctl_reply
*) &buffer
;
1813 * First, check our drives.
1816 fprintf(stderr
, "You need at least three drives to create a RAID-4 plex\n");
1819 if (ioctl(superdev
, VINUM_STARTCONFIG
, &force
)) { /* can't get config? */
1820 printf("Can't configure: %s (%d)\n", strerror(errno
), errno
);
1823 if (!objectname
) /* we need a name for our object */
1825 for (o
= 0; o
< argc
; o
++) {
1826 if ((drive
= find_drive_by_devname(argv
[o
])) == NULL
) /* doesn't exist */
1827 drive
= create_drive(argv
[o
]); /* create it */
1828 /* Now find the largest chunk available on the drive */
1829 bigchunk
= 0; /* ain't found nothin' yet */
1830 for (fe
= 0; fe
< drive
->freelist_entries
; fe
++) {
1831 freeunion
.ferq
.driveno
= drive
->driveno
;
1832 freeunion
.ferq
.fe
= fe
;
1833 if (ioctl(superdev
, VINUM_GETFREELIST
, &freeunion
.freelist
) < 0) {
1835 "Can't get free list element %d: %s\n",
1838 longjmp(command_fail
, -1);
1840 bigchunk
= bigchunk
> freeunion
.freelist
.sectors
? bigchunk
: freeunion
.freelist
.sectors
; /* max it */
1842 maxsize
= min(maxsize
, bigchunk
); /* this is as much as we can do */
1845 /* Now create the volume */
1846 sprintf(buffer
, "volume %s", objectname
);
1848 printf("volume %s\n", objectname
);
1849 ioctl(superdev
, VINUM_CREATE
, buffer
); /* create the volume */
1850 if (reply
->error
!= 0) { /* error in config */
1853 "Can't create volume %s: %s\n",
1858 "Can't create volume %s: %s (%d)\n",
1860 strerror(reply
->error
),
1862 longjmp(command_fail
, -1); /* give up */
1864 sprintf(buffer
, "plex name %s.p0 org raid4 256k", objectname
);
1866 printf(" plex name %s.p0 org raid4 256k\n", objectname
);
1867 ioctl(superdev
, VINUM_CREATE
, buffer
);
1868 if (reply
->error
!= 0) { /* error in config */
1871 "Can't create plex %s.p0: %s\n",
1876 "Can't create plex %s.p0: %s (%d)\n",
1878 strerror(reply
->error
),
1880 longjmp(command_fail
, -1); /* give up */
1882 for (o
= 0; o
< argc
; o
++) {
1883 drive
= find_drive_by_devname(argv
[o
]); /* we know it exists... */
1885 "sd name %s.p0.s%d drive %s size %lldb",
1889 (long long) maxsize
);
1891 printf(" sd name %s.p0.s%d drive %s size %lldb\n",
1895 (long long) maxsize
);
1896 ioctl(superdev
, VINUM_CREATE
, buffer
);
1897 if (reply
->error
!= 0) { /* error in config */
1900 "Can't create subdisk %s.p0.s%d: %s\n",
1906 "Can't create subdisk %s.p0.s%d: %s (%d)\n",
1909 strerror(reply
->error
),
1911 longjmp(command_fail
, -1); /* give up */
1915 /* done, save the config */
1916 ioctltype
= 0; /* saveconfig after update */
1917 error
= ioctl(superdev
, VINUM_SAVECONFIG
, &ioctltype
); /* save the config to disk */
1919 perror("Can't save Vinum config");
1920 find_object(objectname
, &type
); /* find the index of the volume */
1921 make_vol_dev(vol
.volno
, 1); /* and create the devices */
1923 vflag
--; /* XXX don't give too much detail */
1924 find_object(objectname
, &type
); /* point to the volume */
1925 vinum_lvi(vol
.volno
, 1); /* and print info about it */
1930 * Create a volume with a single RAID-4 plex from
1931 * as much space as we can get on the specified drives.
1932 * If the drives aren't Vinum drives, make them so.
1935 vinum_raid5(int argc
, char *argv
[], char *argv0
[])
1937 int o
; /* object number */
1938 char buffer
[BUFSIZE
];
1939 struct drive
*drive
; /* drive we're currently looking at */
1940 struct _ioctl_reply
*reply
;
1943 enum objecttype type
;
1945 int fe
; /* freelist entry index */
1947 struct drive_freelist freelist
;
1948 struct ferq
{ /* request to pass to ioctl */
1953 u_int64_t bigchunk
; /* biggest chunk in freelist */
1956 reply
= (struct _ioctl_reply
*) &buffer
;
1959 * First, check our drives.
1962 fprintf(stderr
, "You need at least three drives to create a RAID-5 plex\n");
1965 if (ioctl(superdev
, VINUM_STARTCONFIG
, &force
)) { /* can't get config? */
1966 printf("Can't configure: %s (%d)\n", strerror(errno
), errno
);
1969 if (!objectname
) /* we need a name for our object */
1971 for (o
= 0; o
< argc
; o
++) {
1972 if ((drive
= find_drive_by_devname(argv
[o
])) == NULL
) /* doesn't exist */
1973 drive
= create_drive(argv
[o
]); /* create it */
1974 /* Now find the largest chunk available on the drive */
1975 bigchunk
= 0; /* ain't found nothin' yet */
1976 for (fe
= 0; fe
< drive
->freelist_entries
; fe
++) {
1977 freeunion
.ferq
.driveno
= drive
->driveno
;
1978 freeunion
.ferq
.fe
= fe
;
1979 if (ioctl(superdev
, VINUM_GETFREELIST
, &freeunion
.freelist
) < 0) {
1981 "Can't get free list element %d: %s\n",
1984 longjmp(command_fail
, -1);
1986 bigchunk
= bigchunk
> freeunion
.freelist
.sectors
? bigchunk
: freeunion
.freelist
.sectors
; /* max it */
1988 maxsize
= min(maxsize
, bigchunk
); /* this is as much as we can do */
1991 /* Now create the volume */
1992 sprintf(buffer
, "volume %s", objectname
);
1994 printf("volume %s\n", objectname
);
1995 ioctl(superdev
, VINUM_CREATE
, buffer
); /* create the volume */
1996 if (reply
->error
!= 0) { /* error in config */
1999 "Can't create volume %s: %s\n",
2004 "Can't create volume %s: %s (%d)\n",
2006 strerror(reply
->error
),
2008 longjmp(command_fail
, -1); /* give up */
2010 sprintf(buffer
, "plex name %s.p0 org raid5 256k", objectname
);
2012 printf(" plex name %s.p0 org raid5 256k\n", objectname
);
2013 ioctl(superdev
, VINUM_CREATE
, buffer
);
2014 if (reply
->error
!= 0) { /* error in config */
2017 "Can't create plex %s.p0: %s\n",
2022 "Can't create plex %s.p0: %s (%d)\n",
2024 strerror(reply
->error
),
2026 longjmp(command_fail
, -1); /* give up */
2028 for (o
= 0; o
< argc
; o
++) {
2029 drive
= find_drive_by_devname(argv
[o
]); /* we know it exists... */
2031 "sd name %s.p0.s%d drive %s size %lldb",
2035 (long long) maxsize
);
2037 printf(" sd name %s.p0.s%d drive %s size %lldb\n",
2041 (long long) maxsize
);
2042 ioctl(superdev
, VINUM_CREATE
, buffer
);
2043 if (reply
->error
!= 0) { /* error in config */
2046 "Can't create subdisk %s.p0.s%d: %s\n",
2052 "Can't create subdisk %s.p0.s%d: %s (%d)\n",
2055 strerror(reply
->error
),
2057 longjmp(command_fail
, -1); /* give up */
2061 /* done, save the config */
2062 ioctltype
= 0; /* saveconfig after update */
2063 error
= ioctl(superdev
, VINUM_SAVECONFIG
, &ioctltype
); /* save the config to disk */
2065 perror("Can't save Vinum config");
2066 find_object(objectname
, &type
); /* find the index of the volume */
2067 make_vol_dev(vol
.volno
, 1); /* and create the devices */
2069 vflag
--; /* XXX don't give too much detail */
2070 find_object(objectname
, &type
); /* point to the volume */
2071 vinum_lvi(vol
.volno
, 1); /* and print info about it */
2076 * Create a volume with a two plexes from as much space
2077 * as we can get on the specified drives. If the
2078 * drives aren't Vinum drives, make them so.
2080 * The number of drives must be even, and at least 4
2081 * for a striped plex. Specify striped plexes with the
2082 * -s flag; otherwise they will be concatenated. It's
2083 * possible that the two plexes may differ in length.
2086 vinum_mirror(int argc
, char *argv
[], char *argv0
[])
2088 int o
; /* object number */
2089 int p
; /* plex number */
2090 char buffer
[BUFSIZE
];
2091 struct drive
*drive
; /* drive we're currently looking at */
2092 struct _ioctl_reply
*reply
;
2095 enum objecttype type
;
2096 off_t maxsize
[2]; /* maximum subdisk size for striped plexes */
2097 int fe
; /* freelist entry index */
2099 struct drive_freelist freelist
;
2100 struct ferq
{ /* request to pass to ioctl */
2105 u_int64_t bigchunk
; /* biggest chunk in freelist */
2107 if (sflag
) /* striped, */
2108 maxsize
[0] = maxsize
[1] = QUAD_MAX
; /* we need to calculate sd size */
2110 maxsize
[0] = maxsize
[1] = 0; /* let the kernel routines do it */
2112 reply
= (struct _ioctl_reply
*) &buffer
;
2115 * First, check our drives.
2118 fprintf(stderr
, "You need an even number of drives to create a mirrored volume\n");
2121 if (sflag
&& (argc
< 4)) {
2122 fprintf(stderr
, "You need at least 4 drives to create a mirrored, striped volume\n");
2125 if (ioctl(superdev
, VINUM_STARTCONFIG
, &force
)) { /* can't get config? */
2126 printf("Can't configure: %s (%d)\n", strerror(errno
), errno
);
2129 if (!objectname
) /* we need a name for our object */
2131 for (o
= 0; o
< argc
; o
++) {
2132 if ((drive
= find_drive_by_devname(argv
[o
])) == NULL
) /* doesn't exist */
2133 drive
= create_drive(argv
[o
]); /* create it */
2134 if (sflag
) { /* striping, */
2135 /* Find the largest chunk available on the drive */
2136 bigchunk
= 0; /* ain't found nothin' yet */
2137 for (fe
= 0; fe
< drive
->freelist_entries
; fe
++) {
2138 freeunion
.ferq
.driveno
= drive
->driveno
;
2139 freeunion
.ferq
.fe
= fe
;
2140 if (ioctl(superdev
, VINUM_GETFREELIST
, &freeunion
.freelist
) < 0) {
2142 "Can't get free list element %d: %s\n",
2145 longjmp(command_fail
, -1);
2147 bigchunk
= bigchunk
> freeunion
.freelist
.sectors
? bigchunk
: freeunion
.freelist
.sectors
; /* max it */
2149 maxsize
[o
& 1] = min(maxsize
[o
& 1], bigchunk
); /* get the maximum size of a subdisk */
2153 /* Now create the volume */
2154 sprintf(buffer
, "volume %s setupstate", objectname
);
2156 printf("volume %s setupstate\n", objectname
);
2157 ioctl(superdev
, VINUM_CREATE
, buffer
); /* create the volume */
2158 if (reply
->error
!= 0) { /* error in config */
2161 "Can't create volume %s: %s\n",
2166 "Can't create volume %s: %s (%d)\n",
2168 strerror(reply
->error
),
2170 longjmp(command_fail
, -1); /* give up */
2172 for (p
= 0; p
< 2; p
++) { /* create each plex */
2174 sprintf(buffer
, "plex name %s.p%d org striped 256k", objectname
, p
);
2176 printf(" plex name %s.p%d org striped 256k\n", objectname
, p
);
2177 } else { /* concat */
2178 sprintf(buffer
, "plex name %s.p%d org concat", objectname
, p
);
2180 printf(" plex name %s.p%d org concat\n", objectname
, p
);
2182 ioctl(superdev
, VINUM_CREATE
, buffer
);
2183 if (reply
->error
!= 0) { /* error in config */
2186 "Can't create plex %s.p%d: %s\n",
2192 "Can't create plex %s.p%d: %s (%d)\n",
2195 strerror(reply
->error
),
2197 longjmp(command_fail
, -1); /* give up */
2199 /* Now look at the subdisks */
2200 for (o
= p
; o
< argc
; o
+= 2) { /* every second one */
2201 drive
= find_drive_by_devname(argv
[o
]); /* we know it exists... */
2203 "sd name %s.p%d.s%d drive %s size %lldb",
2208 (long long) maxsize
[p
]);
2210 printf(" sd name %s.p%d.s%d drive %s size %lldb\n",
2215 (long long) maxsize
[p
]);
2216 ioctl(superdev
, VINUM_CREATE
, buffer
);
2217 if (reply
->error
!= 0) { /* error in config */
2220 "Can't create subdisk %s.p%d.s%d: %s\n",
2227 "Can't create subdisk %s.p%d.s%d: %s (%d)\n",
2231 strerror(reply
->error
),
2233 longjmp(command_fail
, -1); /* give up */
2238 /* done, save the config */
2239 ioctltype
= 0; /* saveconfig after update */
2240 error
= ioctl(superdev
, VINUM_SAVECONFIG
, &ioctltype
); /* save the config to disk */
2242 perror("Can't save Vinum config");
2243 find_object(objectname
, &type
); /* find the index of the volume */
2244 make_vol_dev(vol
.volno
, 1); /* and create the devices */
2246 vflag
--; /* XXX don't give too much detail */
2247 sflag
= 0; /* no stats, please */
2248 find_object(objectname
, &type
); /* point to the volume */
2249 vinum_lvi(vol
.volno
, 1); /* and print info about it */
2254 vinum_readpol(int argc
, char *argv
[], char *argv0
[])
2257 struct _ioctl_reply reply
;
2258 struct vinum_ioctl_msg
*message
= (struct vinum_ioctl_msg
*) &reply
;
2259 enum objecttype type
;
2264 if (argc
== 0) { /* start everything */
2265 fprintf(stderr
, "Usage: readpol <volume> <plex>|round\n");
2268 object
= find_object(argv
[1], &type
); /* look for it */
2269 if (type
!= volume_object
) {
2270 fprintf(stderr
, "%s is not a volume\n", argv
[1]);
2273 get_volume_info(&vol
, object
);
2274 if (strcmp(argv
[2], "round")) { /* not 'round' */
2275 object
= find_object(argv
[2], &type
); /* look for it */
2276 if (type
!= plex_object
) {
2277 fprintf(stderr
, "%s is not a plex\n", argv
[2]);
2280 get_plex_info(&plex
, object
);
2281 plexno
= plex
.plexno
;
2286 message
->index
= vol
.volno
;
2287 message
->otherobject
= plexno
;
2288 if (ioctl(superdev
, VINUM_READPOL
, message
) < 0)
2289 fprintf(stderr
, "Can't set read policy: %s (%d)\n", strerror(errno
), errno
);
2291 vinum_lpi(plexno
, recurse
);
2295 * Brute force set state function. Don't look at
2296 * any dependencies, just do it.
2299 vinum_setstate(int argc
, char *argv
[], char *argv0
[])
2302 struct _ioctl_reply reply
;
2303 struct vinum_ioctl_msg
*message
= (struct vinum_ioctl_msg
*) &reply
;
2305 enum objecttype type
;
2308 for (index
= 1; index
< argc
; index
++) {
2309 object
= find_object(argv
[index
], &type
); /* look for it */
2310 if (type
== invalid_object
)
2311 fprintf(stderr
, "Can't find object: %s\n", argv
[index
]);
2313 int doit
= 0; /* set to 1 if we pass our tests */
2316 state
= DriveState(argv
[0]); /* get the state */
2317 if (drive
.state
== state
) /* already in that state */
2318 fprintf(stderr
, "%s is already %s\n", drive
.label
.name
, argv
[0]);
2324 state
= SdState(argv
[0]); /* get the state */
2325 if (sd
.state
== state
) /* already in that state */
2326 fprintf(stderr
, "%s is already %s\n", sd
.name
, argv
[0]);
2332 state
= PlexState(argv
[0]); /* get the state */
2333 if (plex
.state
== state
) /* already in that state */
2334 fprintf(stderr
, "%s is already %s\n", plex
.name
, argv
[0]);
2340 state
= VolState(argv
[0]); /* get the state */
2341 if (vol
.state
== state
) /* already in that state */
2342 fprintf(stderr
, "%s is already %s\n", vol
.name
, argv
[0]);
2348 state
= 0; /* to keep the compiler happy */
2352 fprintf(stderr
, "Invalid state for object: %s\n", argv
[0]);
2354 message
->index
= object
; /* pass object number */
2355 message
->type
= type
; /* and type of object */
2356 message
->state
= state
;
2357 message
->force
= force
; /* don't force it, use a larger hammer */
2358 ioctl(superdev
, VINUM_SETSTATE_FORCE
, message
);
2359 if (reply
.error
!= 0)
2361 "Can't start %s: %s (%d)\n",
2363 reply
.msg
[0] ? reply
.msg
: strerror(reply
.error
),
2366 vinum_li(object
, type
);
2373 vinum_checkparity(int argc
, char *argv
[], char *argv0
[])
2375 Verbose
= vflag
; /* accept -v for verbose */
2376 if (argc
== 0) /* no parameters? */
2377 fprintf(stderr
, "Usage: checkparity object [object...]\n");
2379 parityops(argc
, argv
, checkparity
);
2383 vinum_rebuildparity(int argc
, char *argv
[], char *argv0
[])
2385 if (argc
== 0) /* no parameters? */
2386 fprintf(stderr
, "Usage: rebuildparity object [object...]\n");
2388 parityops(argc
, argv
, vflag
? rebuildandcheckparity
: rebuildparity
);
2392 * Common code for rebuildparity and checkparity.
2393 * We bend the meanings of some flags here:
2395 * -v: Report incorrect parity on rebuild.
2396 * -V: Show running count of position being checked.
2397 * -f: Start from beginning of the plex.
2400 parityops(int argc
, char *argv
[], enum parityop op
)
2404 struct _ioctl_reply reply
;
2405 struct vinum_ioctl_msg
*message
= (struct vinum_ioctl_msg
*) &reply
;
2407 enum objecttype type
;
2411 if (op
== checkparity
)
2415 for (index
= 0; index
< argc
; index
++) {
2416 object
= find_object(argv
[index
], &type
); /* look for it */
2417 if (type
!= plex_object
)
2418 fprintf(stderr
, "%s is not a plex\n", argv
[index
]);
2420 get_plex_info(&plex
, object
);
2421 if (!isparity((&plex
)))
2422 fprintf(stderr
, "%s is not a RAID-4 or RAID-5 plex\n", argv
[index
]);
2425 message
->index
= object
; /* pass object number */
2426 message
->type
= type
; /* and type of object */
2427 message
->op
= op
; /* what to do */
2429 message
->offset
= 0; /* start at the beginning */
2431 message
->offset
= plex
.checkblock
; /* continue where we left off */
2432 force
= 0; /* don't reset after the first time */
2433 ioctl(superdev
, VINUM_PARITYOP
, message
);
2434 get_plex_info(&plex
, object
);
2436 block
= (plex
.checkblock
<< DEV_BSHIFT
) * (plex
.subdisks
- 1);
2438 printf("\r%s at %s (%d%%) ",
2440 roughlength(block
, 1),
2441 ((int) (block
* 100 / plex
.length
) >> DEV_BSHIFT
));
2442 if ((reply
.error
== EAGAIN
)
2443 && (reply
.msg
[0])) /* got a comment back */
2444 fputs(reply
.msg
, stderr
); /* show it */
2448 while (reply
.error
== EAGAIN
);
2449 if (reply
.error
!= 0) {
2451 fputs(reply
.msg
, stderr
);
2456 strerror(reply
.error
));
2457 } else if (Verbose
) {
2458 if (op
== checkparity
)
2459 fprintf(stderr
, "%s has correct parity\n", argv
[index
]);
2461 fprintf(stderr
, "Rebuilt parity on %s\n", argv
[index
]);
2468 /* Local Variables: */
2469 /* fill-column: 50 */