~ubuntu-branches/debian/wheezy/zfsutils/wheezy

« back to all changes in this revision

Viewing changes to cddl/contrib/opensolaris/cmd/zpool/zpool_main.c

  • Committer: Package Import Robot
  • Author(s): Robert Millan, Robert Millan
  • Date: 2012-02-04 17:16:40 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120204171640-zkmubmewnswspzku
Tags: 9.0-1
* New upstream release.

[ Robert Millan ]
* zfsutils.cron.daily: Fix to avoid listing children file systems'
  snapshots as candidates for removal.
* zfsutils.cron.daily: Remove verbose output.
* Remove X-Start-Before & X-Stop-After (no longer needed since ZVOL
  subsystem is not started by userland anymore).

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
 
59
59
static int zpool_do_add(int, char **);
60
60
static int zpool_do_remove(int, char **);
 
61
static int zpool_do_labelclear(int, char **);
61
62
 
62
63
static int zpool_do_list(int, char **);
63
64
static int zpool_do_iostat(int, char **);
114
115
        HELP_HISTORY,
115
116
        HELP_IMPORT,
116
117
        HELP_IOSTAT,
 
118
        HELP_LABELCLEAR,
117
119
        HELP_LIST,
118
120
        HELP_OFFLINE,
119
121
        HELP_ONLINE,
150
152
        { "add",        zpool_do_add,           HELP_ADD                },
151
153
        { "remove",     zpool_do_remove,        HELP_REMOVE             },
152
154
        { NULL },
 
155
        { "labelclear", zpool_do_labelclear,    HELP_LABELCLEAR         },
 
156
        { NULL },
153
157
        { "list",       zpool_do_list,          HELP_LIST               },
154
158
        { "iostat",     zpool_do_iostat,        HELP_IOSTAT             },
155
159
        { "status",     zpool_do_status,        HELP_STATUS             },
216
220
        case HELP_IOSTAT:
217
221
                return (gettext("\tiostat [-v] [-T d|u] [pool] ... [interval "
218
222
                    "[count]]\n"));
 
223
        case HELP_LABELCLEAR:
 
224
                return (gettext("\tlabelclear [-f] <vdev>\n"));
219
225
        case HELP_LIST:
220
226
                return (gettext("\tlist [-H] [-o property[,...]] "
221
227
                    "[-T d|u] [pool] ... [interval [count]]\n"));
562
568
}
563
569
 
564
570
/*
 
571
 * zpool labelclear <vdev>
 
572
 *
 
573
 * Verifies that the vdev is not active and zeros out the label information
 
574
 * on the device.
 
575
 */
 
576
int
 
577
zpool_do_labelclear(int argc, char **argv)
 
578
{
 
579
        char *vdev, *name;
 
580
        int c, fd = -1, ret = 0;
 
581
        pool_state_t state;
 
582
        boolean_t inuse = B_FALSE;
 
583
        boolean_t force = B_FALSE;
 
584
 
 
585
        /* check options */
 
586
        while ((c = getopt(argc, argv, "f")) != -1) {
 
587
                switch (c) {
 
588
                case 'f':
 
589
                        force = B_TRUE;
 
590
                        break;
 
591
                default:
 
592
                        (void) fprintf(stderr, gettext("invalid option '%c'\n"),
 
593
                            optopt);
 
594
                        usage(B_FALSE);
 
595
                }
 
596
        }
 
597
 
 
598
        argc -= optind;
 
599
        argv += optind;
 
600
 
 
601
        /* get vdev name */
 
602
        if (argc < 1) {
 
603
                (void) fprintf(stderr, gettext("missing vdev device name\n"));
 
604
                usage(B_FALSE);
 
605
        }
 
606
 
 
607
        vdev = argv[0];
 
608
        if ((fd = open(vdev, O_RDWR)) < 0) {
 
609
                (void) fprintf(stderr, gettext("Unable to open %s\n"), vdev);
 
610
                return (B_FALSE);
 
611
        }
 
612
 
 
613
        name = NULL;
 
614
        if (zpool_in_use(g_zfs, fd, &state, &name, &inuse) != 0) {
 
615
                if (force)
 
616
                        goto wipe_label;
 
617
                
 
618
                (void) fprintf(stderr,
 
619
                    gettext("Unable to determine pool state for %s\n"
 
620
                    "Use -f to force the clearing any label data\n"), vdev);
 
621
 
 
622
                return (1);
 
623
        }
 
624
 
 
625
        if (inuse) {
 
626
                switch (state) {
 
627
                default:
 
628
                case POOL_STATE_ACTIVE:
 
629
                case POOL_STATE_SPARE:
 
630
                case POOL_STATE_L2CACHE:
 
631
                        (void) fprintf(stderr,
 
632
gettext("labelclear operation failed.\n"
 
633
        "\tVdev %s is a member (%s), of pool \"%s\".\n"
 
634
        "\tTo remove label information from this device, export or destroy\n"
 
635
        "\tthe pool, or remove %s from the configuration of this pool\n"
 
636
        "\tand retry the labelclear operation\n"),
 
637
                            vdev, zpool_pool_state_to_name(state), name, vdev);
 
638
                        ret = 1;
 
639
                        goto errout;
 
640
 
 
641
                case POOL_STATE_EXPORTED:
 
642
                        if (force)
 
643
                                break;
 
644
 
 
645
                        (void) fprintf(stderr,
 
646
gettext("labelclear operation failed.\n"
 
647
        "\tVdev %s is a member of the exported pool \"%s\".\n"
 
648
        "\tUse \"zpool labelclear -f %s\" to force the removal of label\n"
 
649
        "\tinformation.\n"),
 
650
                            vdev, name, vdev);
 
651
                        ret = 1;
 
652
                        goto errout;
 
653
 
 
654
                case POOL_STATE_POTENTIALLY_ACTIVE:
 
655
                        if (force)
 
656
                                break;
 
657
 
 
658
                        (void) fprintf(stderr,
 
659
gettext("labelclear operation failed.\n"
 
660
        "\tVdev %s is a member of the pool \"%s\".\n"
 
661
        "\tThis pool is unknown to this system, but may be active on\n"
 
662
        "\tanother system. Use \'zpool labelclear -f %s\' to force the\n"
 
663
        "\tremoval of label information.\n"),
 
664
                            vdev, name, vdev);
 
665
                        ret = 1;
 
666
                        goto errout;
 
667
 
 
668
                case POOL_STATE_DESTROYED:
 
669
                        /* inuse should never be set for a destoryed pool... */
 
670
                        break;
 
671
                }
 
672
        }
 
673
 
 
674
wipe_label:
 
675
        if (zpool_clear_label(fd) != 0) {
 
676
                (void) fprintf(stderr,
 
677
                    gettext("Label clear failed on vdev %s\n"), vdev);
 
678
                ret = 1;
 
679
        }
 
680
 
 
681
errout:
 
682
        close(fd);
 
683
        if (name != NULL)
 
684
                free(name);
 
685
 
 
686
        return (ret);
 
687
}
 
688
 
 
689
/*
565
690
 * zpool create [-fn] [-o property=value] ...
566
691
 *              [-O file-system-property=value] ...
567
692
 *              [-R root] [-m mountpoint] <pool> <dev> ...
1053
1178
        char *vname;
1054
1179
        uint64_t notpresent;
1055
1180
        spare_cbdata_t cb;
1056
 
        char *state;
 
1181
        const char *state;
1057
1182
 
1058
1183
        if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
1059
1184
            &child, &children) != 0)
1085
1210
        }
1086
1211
 
1087
1212
        if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
1088
 
            &notpresent) == 0) {
 
1213
            &notpresent) == 0 ||
 
1214
            vs->vs_state <= VDEV_STATE_CANT_OPEN) {
1089
1215
                char *path;
1090
 
                verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0);
1091
 
                (void) printf("  was %s", path);
 
1216
                if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0)
 
1217
                        (void) printf("  was %s", path);
1092
1218
        } else if (vs->vs_aux != 0) {
1093
1219
                (void) printf("  ");
1094
1220