View | Details | Raw Unified | Return to bug 244465 | Differences between
and this patch

Collapse All | Expand All

(-)cddl/contrib/opensolaris/cmd/zfs/zfs_main.c (-10 / +55 lines)
Lines 298-304 Link Here
298
	case HELP_SHARE:
298
	case HELP_SHARE:
299
		return (gettext("\tshare <-a | filesystem>\n"));
299
		return (gettext("\tshare <-a | filesystem>\n"));
300
	case HELP_SNAPSHOT:
300
	case HELP_SNAPSHOT:
301
		return (gettext("\tsnapshot|snap [-r] [-o property=value] ... "
301
		return (gettext("\tsnapshot|snap [-r] [-o property=value] [-m minfree] ... "
302
		    "<filesystem|volume>@<snap> ...\n"));
302
		    "<filesystem|volume>@<snap> ...\n"));
303
	case HELP_UNMOUNT:
303
	case HELP_UNMOUNT:
304
		return (gettext("\tunmount|umount [-f] "
304
		return (gettext("\tunmount|umount [-f] "
Lines 3677-3682 Link Here
3677
	nvlist_t *sd_nvl;
3677
	nvlist_t *sd_nvl;
3678
	boolean_t sd_recursive;
3678
	boolean_t sd_recursive;
3679
	const char *sd_snapname;
3679
	const char *sd_snapname;
3680
  	uint64_t min_avail;
3680
} snap_cbdata_t;
3681
} snap_cbdata_t;
3681
3682
3682
static int
3683
static int
Lines 3686-3704 Link Here
3686
	char *name;
3687
	char *name;
3687
	int rv = 0;
3688
	int rv = 0;
3688
	int error;
3689
	int error;
3690
	uint64_t avail;
3689
3691
3692
	
3690
	if (sd->sd_recursive &&
3693
	if (sd->sd_recursive &&
3691
	    zfs_prop_get_int(zhp, ZFS_PROP_INCONSISTENT) != 0) {
3694
	    zfs_prop_get_int(zhp, ZFS_PROP_INCONSISTENT) != 0) {
3692
		zfs_close(zhp);
3695
		zfs_close(zhp);
3693
		return (0);
3696
		return (0);
3694
	}
3697
	}
3695
3698
3696
	error = asprintf(&name, "%s@%s", zfs_get_name(zhp), sd->sd_snapname);
3699
	if (!sd->min_avail ||
3697
	if (error == -1)
3700
	    (avail = zfs_prop_get_int(zhp, ZFS_PROP_AVAILABLE)) >= sd->min_avail) {
3698
		nomem();
3701
	  
3699
	fnvlist_add_boolean(sd->sd_nvl, name);
3702
	  error = asprintf(&name, "%s@%s", zfs_get_name(zhp), sd->sd_snapname);
3700
	free(name);
3703
	  if (error == -1)
3701
3704
	    nomem();
3705
	  fnvlist_add_boolean(sd->sd_nvl, name);
3706
	  free(name);
3707
	  
3708
	} else {
3709
	  fprintf(stderr, "%s@%s: Skipping snapshot - avail too low (%llu < %llu)\n",
3710
		  zfs_get_name(zhp), sd->sd_snapname, avail, sd->min_avail);
3711
	}
3712
	
3702
	if (sd->sd_recursive)
3713
	if (sd->sd_recursive)
3703
		rv = zfs_iter_filesystems(zhp, zfs_snapshot_cb, sd);
3714
		rv = zfs_iter_filesystems(zhp, zfs_snapshot_cb, sd);
3704
	zfs_close(zhp);
3715
	zfs_close(zhp);
Lines 3719-3737 Link Here
3719
	nvlist_t *props;
3730
	nvlist_t *props;
3720
	snap_cbdata_t sd = { 0 };
3731
	snap_cbdata_t sd = { 0 };
3721
	boolean_t multiple_snaps = B_FALSE;
3732
	boolean_t multiple_snaps = B_FALSE;
3722
3733
	char pfx;
3734
	
3723
	if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0)
3735
	if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0)
3724
		nomem();
3736
		nomem();
3725
	if (nvlist_alloc(&sd.sd_nvl, NV_UNIQUE_NAME, 0) != 0)
3737
	if (nvlist_alloc(&sd.sd_nvl, NV_UNIQUE_NAME, 0) != 0)
3726
		nomem();
3738
		nomem();
3727
3739
3740
	sd.min_avail = 0;
3741
	
3728
	/* check options */
3742
	/* check options */
3729
	while ((c = getopt(argc, argv, "ro:")) != -1) {
3743
	while ((c = getopt(argc, argv, "ro:m:")) != -1) {
3730
		switch (c) {
3744
		switch (c) {
3731
		case 'o':
3745
		case 'o':
3732
			if (parseprop(props, optarg) != 0)
3746
			if (parseprop(props, optarg) != 0)
3733
				return (1);
3747
				return (1);
3734
			break;
3748
			break;
3749
		case 'm':
3750
		  pfx = 0;
3751
		  if (!optarg || sscanf(optarg, "%lld%c", &sd.min_avail, &pfx) < 1) {
3752
		    (void) fprintf(stderr, "invalid minfree '%s'", optarg);
3753
		    goto usage;
3754
		  }
3755
3756
		  switch (toupper(pfx)) {
3757
		  case 'K':
3758
		    sd.min_avail *= 1000;
3759
		    break;
3760
3761
		  case 'M':
3762
		    sd.min_avail *= 1000000;
3763
		    break;
3764
3765
		  case 'G':
3766
		    sd.min_avail *= 1000000000;
3767
		    break;
3768
3769
		  case 'T':
3770
		    sd.min_avail *= 1000000000000;
3771
		    break;
3772
3773
		  default:
3774
		    (void) fprintf(stderr, "invalid minfree '%s'", optarg);
3775
		    goto usage;
3776
		  }
3777
		  break;
3735
		case 'r':
3778
		case 'r':
3736
			sd.sd_recursive = B_TRUE;
3779
			sd.sd_recursive = B_TRUE;
3737
			multiple_snaps = B_TRUE;
3780
			multiple_snaps = B_TRUE;
Lines 3771-3777 Link Here
3771
			goto usage;
3814
			goto usage;
3772
	}
3815
	}
3773
3816
3774
	ret = zfs_snapshot_nvl(g_zfs, sd.sd_nvl, props);
3817
	if (!nvlist_empty(sd.sd_nvl))
3818
	  ret = zfs_snapshot_nvl(g_zfs, sd.sd_nvl, props);
3819
	
3775
	nvlist_free(sd.sd_nvl);
3820
	nvlist_free(sd.sd_nvl);
3776
	nvlist_free(props);
3821
	nvlist_free(props);
3777
	if (ret != 0 && multiple_snaps)
3822
	if (ret != 0 && multiple_snaps)

Return to bug 244465