Deleted Added
full compact
gvinum.c (150044) gvinum.c (152616)
1/*
1/*
2 * Copyright (c) 2004 Lukas Ertl
2 * Copyright (c) 2004 Lukas Ertl, 2005 Chris Jones
3 * All rights reserved.
4 *
3 * All rights reserved.
4 *
5 * Portions of this software were developed for the FreeBSD Project
6 * by Chris Jones thanks to the support of Google's Summer of Code
7 * program and mentoring by Lukas Ertl.
8 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.

--- 5 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.

--- 5 unchanged lines hidden (view full) ---

22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
26 * $FreeBSD: head/sbin/gvinum/gvinum.c 150044 2005-09-12 14:31:49Z le $
30 * $FreeBSD: head/sbin/gvinum/gvinum.c 152616 2005-11-19 20:26:52Z le $
27 */
28
29#include <sys/param.h>
30#include <sys/linker.h>
31#include <sys/lock.h>
32#include <sys/module.h>
33#include <sys/mutex.h>
34#include <sys/queue.h>

--- 13 unchanged lines hidden (view full) ---

48#include <readline/history.h>
49#include <unistd.h>
50
51#include "gvinum.h"
52
53void gvinum_create(int, char **);
54void gvinum_help(void);
55void gvinum_list(int, char **);
31 */
32
33#include <sys/param.h>
34#include <sys/linker.h>
35#include <sys/lock.h>
36#include <sys/module.h>
37#include <sys/mutex.h>
38#include <sys/queue.h>

--- 13 unchanged lines hidden (view full) ---

52#include <readline/history.h>
53#include <unistd.h>
54
55#include "gvinum.h"
56
57void gvinum_create(int, char **);
58void gvinum_help(void);
59void gvinum_list(int, char **);
60void gvinum_move(int, char **);
56void gvinum_parityop(int, char **, int);
57void gvinum_printconfig(int, char **);
61void gvinum_parityop(int, char **, int);
62void gvinum_printconfig(int, char **);
63void gvinum_rename(int, char **);
58void gvinum_rm(int, char **);
59void gvinum_saveconfig(void);
60void gvinum_setstate(int, char **);
61void gvinum_start(int, char **);
62void gvinum_stop(int, char **);
63void parseline(int, char **);
64void printconfig(FILE *, char *);
65

--- 249 unchanged lines hidden (view full) ---

315 gctl_free(req);
316 gvinum_list(0, NULL);
317}
318
319void
320gvinum_help(void)
321{
322 printf("COMMANDS\n"
64void gvinum_rm(int, char **);
65void gvinum_saveconfig(void);
66void gvinum_setstate(int, char **);
67void gvinum_start(int, char **);
68void gvinum_stop(int, char **);
69void parseline(int, char **);
70void printconfig(FILE *, char *);
71

--- 249 unchanged lines hidden (view full) ---

321 gctl_free(req);
322 gvinum_list(0, NULL);
323}
324
325void
326gvinum_help(void)
327{
328 printf("COMMANDS\n"
323 "attach plex volume [rename]\n"
324 "attach subdisk plex [offset] [rename]\n"
325 " Attach a plex to a volume, or a subdisk to a plex.\n"
326 "checkparity plex [-f] [-v]\n"
327 " Check the parity blocks of a RAID-4 or RAID-5 plex.\n"
328 "concat [-f] [-n name] [-v] drives\n"
329 " Create a concatenated volume from the specified drives.\n"
330 "create [-f] description-file\n"
331 " Create a volume as described in description-file.\n"
332 "detach [-f] [plex | subdisk]\n"
333 " Detach a plex or subdisk from the volume or plex to"
334 "which it is\n"
335 " attached.\n"
336 "dumpconfig [drive ...]\n"
337 " List the configuration information stored on the"
338 " specified\n"
339 " drives, or all drives in the system if no drive names"
340 " are speci-\n"
341 " fied.\n"
342 "info [-v] [-V]\n"
343 " List information about volume manager state.\n"
344 "init [-S size] [-w] plex | subdisk\n"
345 " Initialize the contents of a subdisk or all the subdisks"
346 " of a\n"
347 " plex to all zeros.\n"
348 "label volume\n"
349 " Create a volume label.\n"
350 "l | list [-r] [-s] [-v] [-V] [volume | plex | subdisk]\n"
329 "checkparity [-f] plex\n"
330 " Check the parity blocks of a RAID-5 plex.\n"
331 "create description-file\n"
332 " Create as per description-file or open editor.\n"
333 "l | list [-r] [-v] [-V] [volume | plex | subdisk]\n"
351 " List information about specified objects.\n"
334 " List information about specified objects.\n"
352 "ld [-r] [-s] [-v] [-V] [volume]\n"
335 "ld [-r] [-v] [-V] [volume]\n"
353 " List information about drives.\n"
336 " List information about drives.\n"
354 "ls [-r] [-s] [-v] [-V] [subdisk]\n"
337 "ls [-r] [-v] [-V] [subdisk]\n"
355 " List information about subdisks.\n"
338 " List information about subdisks.\n"
356 "lp [-r] [-s] [-v] [-V] [plex]\n"
339 "lp [-r] [-v] [-V] [plex]\n"
357 " List information about plexes.\n"
340 " List information about plexes.\n"
358 "lv [-r] [-s] [-v] [-V] [volume]\n"
341 "lv [-r] [-v] [-V] [volume]\n"
359 " List information about volumes.\n"
342 " List information about volumes.\n"
360 "mirror [-f] [-n name] [-s] [-v] drives\n"
361 " Create a mirrored volume from the specified drives.\n"
362 "move | mv -f drive object ...\n"
363 " Move the object(s) to the specified drive.\n"
343 "move | mv -f drive object ...\n"
344 " Move the object(s) to the specified drive.\n"
364 "printconfig [file]\n"
365 " Write a copy of the current configuration to file.\n"
366 "quit Exit the vinum program when running in interactive mode."
367 " Nor-\n"
368 " mally this would be done by entering the EOF character.\n"
369 "rename [-r] [drive | subdisk | plex | volume] newname\n"
370 " Change the name of the specified object.\n"
345 "quit Exit the vinum program when running in interactive mode."
346 " Nor-\n"
347 " mally this would be done by entering the EOF character.\n"
348 "rename [-r] [drive | subdisk | plex | volume] newname\n"
349 " Change the name of the specified object.\n"
371 "rebuildparity plex [-f] [-v] [-V]\n"
372 " Rebuild the parity blocks of a RAID-4 or RAID-5 plex.\n"
373 "resetconfig\n"
374 " Reset the complete vinum configuration.\n"
375 "rm [-f] [-r] volume | plex | subdisk\n"
350 "rebuildparity plex [-f]\n"
351 " Rebuild the parity blocks of a RAID-5 plex.\n"
352 "rm [-r] volume | plex | subdisk | drive\n"
376 " Remove an object.\n"
377 "saveconfig\n"
378 " Save vinum configuration to disk after configuration"
379 " failures.\n"
353 " Remove an object.\n"
354 "saveconfig\n"
355 " Save vinum configuration to disk after configuration"
356 " failures.\n"
380 "setstate state [volume | plex | subdisk | drive]\n"
357 "setstate [-f] state [volume | plex | subdisk | drive]\n"
381 " Set state without influencing other objects, for"
382 " diagnostic pur-\n"
383 " poses only.\n"
358 " Set state without influencing other objects, for"
359 " diagnostic pur-\n"
360 " poses only.\n"
384 "start [-i interval] [-S size] [-w] volume | plex | subdisk\n"
361 "start [-S size] volume | plex | subdisk\n"
385 " Allow the system to access the objects.\n"
362 " Allow the system to access the objects.\n"
386 "stop [-f] [volume | plex | subdisk]\n"
387 " Terminate access to the objects, or stop vinum if no"
388 " parameters\n"
389 " are specified.\n"
390 "stripe [-f] [-n name] [-v] drives\n"
391 " Create a striped volume from the specified drives.\n"
392 );
393
394 return;
395}
396
397void
398gvinum_setstate(int argc, char **argv)
399{

--- 109 unchanged lines hidden (view full) ---

509 return;
510 }
511
512 printf("%s", config);
513 gctl_free(req);
514 return;
515}
516
363 );
364
365 return;
366}
367
368void
369gvinum_setstate(int argc, char **argv)
370{

--- 109 unchanged lines hidden (view full) ---

480 return;
481 }
482
483 printf("%s", config);
484 gctl_free(req);
485 return;
486}
487
488/* Note that move is currently of form '[-r] target object [...]' */
517void
489void
490gvinum_move(int argc, char **argv)
491{
492 struct gctl_req *req;
493 const char *errstr;
494 char buf[20];
495 int flags, i, j;
496
497 flags = 0;
498 if (argc) {
499 optreset = 1;
500 optind = 1;
501 while ((j = getopt(argc, argv, "f")) != -1) {
502 switch (j) {
503 case 'f':
504 flags |= GV_FLAG_F;
505 break;
506 case '?':
507 default:
508 return;
509 }
510 }
511 argc -= optind;
512 argv += optind;
513 }
514
515 switch (argc) {
516 case 0:
517 warnx("no destination or object(s) to move specified");
518 return;
519 case 1:
520 warnx("no object(s) to move specified");
521 return;
522 default:
523 break;
524 }
525
526 req = gctl_get_handle();
527 gctl_ro_param(req, "class", -1, "VINUM");
528 gctl_ro_param(req, "verb", -1, "move");
529 gctl_ro_param(req, "argc", sizeof(int), &argc);
530 gctl_ro_param(req, "flags", sizeof(int), &flags);
531 gctl_ro_param(req, "destination", -1, argv[0]);
532 for (i = 1; i < argc; i++) {
533 snprintf(buf, sizeof(buf), "argv%d", i);
534 gctl_ro_param(req, buf, -1, argv[i]);
535 }
536 errstr = gctl_issue(req);
537 if (errstr != NULL)
538 warnx("can't move object(s): %s", errstr);
539 gctl_free(req);
540 return;
541}
542
543void
518gvinum_printconfig(int argc, char **argv)
519{
520 printconfig(stdout, "");
521}
522
523void
524gvinum_parityop(int argc, char **argv, int rebuild)
525{

--- 73 unchanged lines hidden (view full) ---

599 if (rebuild)
600 printf("Rebuilt parity on %s\n", argv[0]);
601 else
602 printf("%s has correct parity\n", argv[0]);
603 }
604}
605
606void
544gvinum_printconfig(int argc, char **argv)
545{
546 printconfig(stdout, "");
547}
548
549void
550gvinum_parityop(int argc, char **argv, int rebuild)
551{

--- 73 unchanged lines hidden (view full) ---

625 if (rebuild)
626 printf("Rebuilt parity on %s\n", argv[0]);
627 else
628 printf("%s has correct parity\n", argv[0]);
629 }
630}
631
632void
633gvinum_rename(int argc, char **argv)
634{
635 struct gctl_req *req;
636 const char *errstr;
637 int flags, j;
638
639 flags = 0;
640
641 if (argc) {
642 optreset = 1;
643 optind = 1;
644 while ((j = getopt(argc, argv, "r")) != -1) {
645 switch (j) {
646 case 'r':
647 flags |= GV_FLAG_R;
648 break;
649 case '?':
650 default:
651 return;
652 }
653 }
654 argc -= optind;
655 argv += optind;
656 }
657
658 switch (argc) {
659 case 0:
660 warnx("no object to rename specified");
661 return;
662 case 1:
663 warnx("no new name specified");
664 return;
665 case 2:
666 break;
667 default:
668 warnx("more than one new name specified");
669 return;
670 }
671
672 req = gctl_get_handle();
673 gctl_ro_param(req, "class", -1, "VINUM");
674 gctl_ro_param(req, "verb", -1, "rename");
675 gctl_ro_param(req, "flags", sizeof(int), &flags);
676 gctl_ro_param(req, "object", -1, argv[0]);
677 gctl_ro_param(req, "newname", -1, argv[1]);
678 errstr = gctl_issue(req);
679 if (errstr != NULL)
680 warnx("can't rename object: %s", errstr);
681 gctl_free(req);
682 return;
683}
684
685void
607gvinum_rm(int argc, char **argv)
608{
609 struct gctl_req *req;
610 int flags, i, j;
611 const char *errstr;
612 char buf[20], *cmd;
613
614 cmd = argv[0];

--- 139 unchanged lines hidden (view full) ---

754 else if (!strcmp(argv[0], "ld"))
755 gvinum_list(argc, argv);
756 else if (!strcmp(argv[0], "lp"))
757 gvinum_list(argc, argv);
758 else if (!strcmp(argv[0], "ls"))
759 gvinum_list(argc, argv);
760 else if (!strcmp(argv[0], "lv"))
761 gvinum_list(argc, argv);
686gvinum_rm(int argc, char **argv)
687{
688 struct gctl_req *req;
689 int flags, i, j;
690 const char *errstr;
691 char buf[20], *cmd;
692
693 cmd = argv[0];

--- 139 unchanged lines hidden (view full) ---

833 else if (!strcmp(argv[0], "ld"))
834 gvinum_list(argc, argv);
835 else if (!strcmp(argv[0], "lp"))
836 gvinum_list(argc, argv);
837 else if (!strcmp(argv[0], "ls"))
838 gvinum_list(argc, argv);
839 else if (!strcmp(argv[0], "lv"))
840 gvinum_list(argc, argv);
841 else if (!strcmp(argv[0], "move"))
842 gvinum_move(argc, argv);
843 else if (!strcmp(argv[0], "mv"))
844 gvinum_move(argc, argv);
762 else if (!strcmp(argv[0], "printconfig"))
763 gvinum_printconfig(argc, argv);
845 else if (!strcmp(argv[0], "printconfig"))
846 gvinum_printconfig(argc, argv);
847 else if (!strcmp(argv[0], "rename"))
848 gvinum_rename(argc, argv);
764 else if (!strcmp(argv[0], "rm"))
765 gvinum_rm(argc, argv);
766 else if (!strcmp(argv[0], "saveconfig"))
767 gvinum_saveconfig();
768 else if (!strcmp(argv[0], "setstate"))
769 gvinum_setstate(argc, argv);
770 else if (!strcmp(argv[0], "start"))
771 gvinum_start(argc, argv);

--- 50 unchanged lines hidden ---
849 else if (!strcmp(argv[0], "rm"))
850 gvinum_rm(argc, argv);
851 else if (!strcmp(argv[0], "saveconfig"))
852 gvinum_saveconfig();
853 else if (!strcmp(argv[0], "setstate"))
854 gvinum_setstate(argc, argv);
855 else if (!strcmp(argv[0], "start"))
856 gvinum_start(argc, argv);

--- 50 unchanged lines hidden ---