Project

General

Profile

Bug #5484 ยป zfs-zpool-upgrade.patch

Steven Hartland, 2014-12-26 04:50 AM

View differences:

cddl/contrib/opensolaris/cmd/zpool/zpool_main.c (working copy)
4490 4490
}
4491 4491

  
4492 4492
typedef struct upgrade_cbdata {
4493
	int	cb_first;
4494
	char	cb_poolname[ZPOOL_MAXNAMELEN];
4495
	int	cb_argc;
4496
	uint64_t cb_version;
4497
	char	**cb_argv;
4493
	boolean_t	cb_first;
4494
	boolean_t	cb_unavail;
4495
	char		cb_poolname[ZPOOL_MAXNAMELEN];
4496
	int		cb_argc;
4497
	uint64_t	cb_version;
4498
	char		**cb_argv;
4498 4499
} upgrade_cbdata_t;
4499 4500

  
4500 4501
#ifdef __FreeBSD__
......
4610 4611
	boolean_t printnl = B_FALSE;
4611 4612
	int ret;
4612 4613

  
4614
	if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) {
4615
		(void) fprintf(stderr, gettext("cannot upgrade '%s': pool is "
4616
		    "currently unavailable.\n\n"), zpool_get_name(zhp));
4617
		cbp->cb_unavail = B_TRUE;
4618
		/* Allow iteration to continue. */
4619
		return (0);
4620
	}
4621

  
4613 4622
	config = zpool_get_config(zhp, NULL);
4614 4623
	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
4615 4624
	    &version) == 0);
......
4671 4680
}
4672 4681

  
4673 4682
static int
4683
upgrade_list_unavail(zpool_handle_t *zhp, void *arg)
4684
{
4685
	upgrade_cbdata_t *cbp = arg;
4686

  
4687
	if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) {
4688
		if (cbp->cb_first) {
4689
			(void) fprintf(stderr, gettext("The following pools "
4690
			    "are unavailable and cannot be upgraded as this "
4691
			    "time.\n\n"));
4692
			(void) fprintf(stderr, gettext("POOL\n"));
4693
			(void) fprintf(stderr, gettext("------------\n"));
4694
			cbp->cb_first = B_FALSE;
4695
		}
4696
		(void) printf(gettext("%s\n"), zpool_get_name(zhp));
4697
		cbp->cb_unavail = B_TRUE;
4698
	}
4699
	return (0);
4700
}
4701

  
4702
static int
4674 4703
upgrade_list_older_cb(zpool_handle_t *zhp, void *arg)
4675 4704
{
4676 4705
	upgrade_cbdata_t *cbp = arg;
4677 4706
	nvlist_t *config;
4678 4707
	uint64_t version;
4679 4708

  
4709
	if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) {
4710
		/*
4711
		 * This will have been reported by upgrade_list_unavail so
4712
		 * just allow iteration to continue.
4713
		 */
4714
		cbp->cb_unavail = B_TRUE;
4715
		return (0);
4716
	}
4717

  
4680 4718
	config = zpool_get_config(zhp, NULL);
4681 4719
	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
4682 4720
	    &version) == 0);
......
4710 4748
	nvlist_t *config;
4711 4749
	uint64_t version;
4712 4750

  
4751
	if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) {
4752
		/*
4753
		 * This will have been reported by upgrade_list_unavail so
4754
		 * just allow iteration to continue.
4755
		 */
4756
		cbp->cb_unavail = B_TRUE;
4757
		return (0);
4758
	}
4759

  
4713 4760
	config = zpool_get_config(zhp, NULL);
4714 4761
	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
4715 4762
	    &version) == 0);
......
4763 4810
	uint64_t cur_version;
4764 4811
	int ret;
4765 4812

  
4813
	if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) {
4814
		(void) fprintf(stderr, gettext("cannot upgrade '%s': pool is "
4815
		    "is currently unavailable.\n\n"), zpool_get_name(zhp));
4816
		cbp->cb_unavail = B_TRUE;
4817
		return (1);
4818
	}
4819

  
4766 4820
	if (strcmp("log", zpool_get_name(zhp)) == 0) {
4767 4821
		(void) printf(gettext("'log' is now a reserved word\n"
4768 4822
		    "Pool 'log' must be renamed using export and import"
4769
		    " to upgrade.\n"));
4823
		    " to upgrade.\n\n"));
4770 4824
		return (1);
4771 4825
	}
4772 4826

  
......
4810 4864
#endif	/* __FreeBSD __*/
4811 4865
		} else if (cur_version == SPA_VERSION) {
4812 4866
			(void) printf(gettext("Pool '%s' already has all "
4813
			    "supported features enabled.\n"),
4867
			    "supported features enabled.\n\n"),
4814 4868
			    zpool_get_name(zhp));
4815 4869
		}
4816 4870
	}
......
4967 5021
		ret = zpool_iter(g_zfs, upgrade_cb, &cb);
4968 5022
		if (ret == 0 && cb.cb_first) {
4969 5023
			if (cb.cb_version == SPA_VERSION) {
4970
				(void) printf(gettext("All pools are already "
4971
				    "formatted using feature flags.\n\n"));
4972
				(void) printf(gettext("Every feature flags "
5024
				(void) printf(gettext("All %spools are already "
5025
				    "formatted using feature flags.\n\n"),
5026
				    cb.cb_unavail ? gettext("available ") : "");
5027
				(void) printf(gettext("Every %sfeature flags "
4973 5028
				    "pool already has all supported features "
4974
				    "enabled.\n"));
5029
				    "enabled.\n"),
5030
				    cb.cb_unavail ? gettext("available ") : "");
4975 5031
			} else {
4976 5032
				(void) printf(gettext("All pools are already "
4977 5033
				    "formatted with version %llu or higher.\n"),
......
4980 5036
		}
4981 5037
	} else if (argc == 0) {
4982 5038
		cb.cb_first = B_TRUE;
5039
		ret = zpool_iter(g_zfs, upgrade_list_unavail, &cb);
5040
		assert(ret == 0);
5041

  
5042
		if (!cb.cb_first) {
5043
			(void) fprintf(stderr, "\n");
5044
		}
5045

  
5046
		cb.cb_first = B_TRUE;
4983 5047
		ret = zpool_iter(g_zfs, upgrade_list_older_cb, &cb);
4984 5048
		assert(ret == 0);
4985 5049

  
4986 5050
		if (cb.cb_first) {
4987
			(void) printf(gettext("All pools are formatted "
4988
			    "using feature flags.\n\n"));
5051
			(void) printf(gettext("All %spools are formatted using "
5052
			    "feature flags.\n\n"), cb.cb_unavail ?
5053
			    gettext("available ") : "");
4989 5054
		} else {
4990 5055
			(void) printf(gettext("\nUse 'zpool upgrade -v' "
4991 5056
			    "for a list of available legacy versions.\n"));
......
4996 5061
		assert(ret == 0);
4997 5062

  
4998 5063
		if (cb.cb_first) {
4999
			(void) printf(gettext("Every feature flags pool has "
5000
			    "all supported features enabled.\n"));
5064
			(void) printf(gettext("Every %sfeature flags pool has "
5065
			    "all supported features enabled.\n"),
5066
			    cb.cb_unavail ? gettext("available ") : "");
5001 5067
		} else {
5002 5068
			(void) printf(gettext("\n"));
5003 5069
		}
5004 5070
	} else {
5005
		ret = for_each_pool(argc, argv, B_FALSE, NULL,
5071
		ret = for_each_pool(argc, argv, B_TRUE, NULL,
5006 5072
		    upgrade_one, &cb);
5007 5073
	}
5008 5074

  
    (1-1/1)