mirror of
				https://git.proxmox.com/git/mirror_zfs.git
				synced 2025-10-26 18:05:04 +03:00 
			
		
		
		
	zfs get -p only outputs 3 columns if "clones" property is empty
get_clones_string currently returns an empty string for filesystem snapshots which have no clones. This breaks parsable `zfs get` output as only three columns are output, instead of 4. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Matt Fiddaman <github@m.fiddaman.uk> Co-authored-by: matt <matt@fiddaman.net> Closes #11837
This commit is contained in:
		
							parent
							
								
									71a3487a89
								
							
						
					
					
						commit
						1bb4b5a5ae
					
				| @ -32,6 +32,7 @@ | |||||||
|  * Copyright 2017-2018 RackTop Systems. |  * Copyright 2017-2018 RackTop Systems. | ||||||
|  * Copyright (c) 2019 Datto Inc. |  * Copyright (c) 2019 Datto Inc. | ||||||
|  * Copyright (c) 2019, loli10K <ezomori.nozomu@gmail.com> |  * Copyright (c) 2019, loli10K <ezomori.nozomu@gmail.com> | ||||||
|  |  * Copyright (c) 2021 Matt Fiddaman | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include <ctype.h> | #include <ctype.h> | ||||||
| @ -2385,7 +2386,7 @@ get_clones_string(zfs_handle_t *zhp, char *propbuf, size_t proplen) | |||||||
| 	nvpair_t *pair; | 	nvpair_t *pair; | ||||||
| 
 | 
 | ||||||
| 	value = zfs_get_clones_nvl(zhp); | 	value = zfs_get_clones_nvl(zhp); | ||||||
| 	if (value == NULL) | 	if (value == NULL || nvlist_empty(value)) | ||||||
| 		return (-1); | 		return (-1); | ||||||
| 
 | 
 | ||||||
| 	propbuf[0] = '\0'; | 	propbuf[0] = '\0'; | ||||||
|  | |||||||
| @ -27,6 +27,7 @@ | |||||||
| 
 | 
 | ||||||
| # | # | ||||||
| # Copyright (c) 2016 by Delphix. All rights reserved. | # Copyright (c) 2016 by Delphix. All rights reserved. | ||||||
|  | # Copyright (c) 2021 Matt Fiddaman | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| . $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib | . $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib | ||||||
| @ -72,7 +73,8 @@ typeset all_props=("${zfs_props[@]}" \ | |||||||
|     "${zfs_props_os[@]}" \ |     "${zfs_props_os[@]}" \ | ||||||
|     "${userquota_props[@]}") |     "${userquota_props[@]}") | ||||||
| typeset dataset=($TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ | typeset dataset=($TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ | ||||||
| 	$TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP) | 	$TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP | ||||||
|  | 	$TESTPOOL/$TESTFS@$TESTSNAP1 $TESTPOOL/$TESTCLONE) | ||||||
| 
 | 
 | ||||||
| typeset bookmark_props=(creation) | typeset bookmark_props=(creation) | ||||||
| typeset bookmark=($TESTPOOL/$TESTFS#$TESTBKMARK $TESTPOOL/$TESTVOL#$TESTBKMARK) | typeset bookmark=($TESTPOOL/$TESTFS#$TESTBKMARK $TESTPOOL/$TESTVOL#$TESTBKMARK) | ||||||
| @ -102,6 +104,7 @@ function check_return_value | |||||||
| 
 | 
 | ||||||
| 			if [[ $item == $p ]]; then | 			if [[ $item == $p ]]; then | ||||||
| 				((found += 1)) | 				((found += 1)) | ||||||
|  | 				cols=$(echo $line | awk '{print NF}') | ||||||
| 				break | 				break | ||||||
| 			fi | 			fi | ||||||
| 		done < $TESTDIR/$TESTFILE0 | 		done < $TESTDIR/$TESTFILE0 | ||||||
| @ -109,6 +112,9 @@ function check_return_value | |||||||
| 		if ((found == 0)); then | 		if ((found == 0)); then | ||||||
| 			log_fail "'zfs get $opt $props $dst' return " \ | 			log_fail "'zfs get $opt $props $dst' return " \ | ||||||
| 			    "error message.'$p' haven't been found." | 			    "error message.'$p' haven't been found." | ||||||
|  | 		elif [[ "$opt" == "-p" ]] && ((cols != 4)); then | ||||||
|  | 			log_fail "'zfs get $opt $props $dst' returned " \ | ||||||
|  | 			    "$cols columns instead of 4." | ||||||
| 		fi | 		fi | ||||||
| 	done | 	done | ||||||
| 
 | 
 | ||||||
| @ -123,6 +129,10 @@ log_onexit cleanup | |||||||
| create_snapshot $TESTPOOL/$TESTFS $TESTSNAP | create_snapshot $TESTPOOL/$TESTFS $TESTSNAP | ||||||
| create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP | create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP | ||||||
| 
 | 
 | ||||||
|  | # Create second snapshot and clone it | ||||||
|  | create_snapshot $TESTPOOL/$TESTFS $TESTSNAP1 | ||||||
|  | create_clone $TESTPOOL/$TESTFS@$TESTSNAP1 $TESTPOOL/$TESTCLONE | ||||||
|  | 
 | ||||||
| # Create filesystem and volume's bookmark | # Create filesystem and volume's bookmark | ||||||
| create_bookmark $TESTPOOL/$TESTFS $TESTSNAP $TESTBKMARK | create_bookmark $TESTPOOL/$TESTFS $TESTSNAP $TESTBKMARK | ||||||
| create_bookmark $TESTPOOL/$TESTVOL $TESTSNAP $TESTBKMARK | create_bookmark $TESTPOOL/$TESTVOL $TESTSNAP $TESTBKMARK | ||||||
|  | |||||||
| @ -26,6 +26,7 @@ | |||||||
| 
 | 
 | ||||||
| # | # | ||||||
| # Copyright (c) 2016 by Delphix. All rights reserved. | # Copyright (c) 2016 by Delphix. All rights reserved. | ||||||
|  | # Copyright (c) 2021 Matt Fiddaman | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| . $STF_SUITE/include/libtest.shlib | . $STF_SUITE/include/libtest.shlib | ||||||
| @ -87,8 +88,8 @@ function gen_option_str # $elements $prefix $separator $counter | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| # | # | ||||||
| # Cleanup the volume snapshot, filesystem snapshot, volume bookmark, and | # Cleanup the volume snapshot, filesystem snapshots, clone, volume bookmark, | ||||||
| # filesystem bookmark that were created for this test case. | # and filesystem bookmark that were created for this test case. | ||||||
| # | # | ||||||
| function cleanup | function cleanup | ||||||
| { | { | ||||||
| @ -97,6 +98,11 @@ function cleanup | |||||||
| 	datasetexists $TESTPOOL/$TESTFS@$TESTSNAP && \ | 	datasetexists $TESTPOOL/$TESTFS@$TESTSNAP && \ | ||||||
| 		destroy_snapshot $TESTPOOL/$TESTFS@$TESTSNAP | 		destroy_snapshot $TESTPOOL/$TESTFS@$TESTSNAP | ||||||
| 
 | 
 | ||||||
|  | 	datasetexists $TESTPOOL/$TESTCLONE && \ | ||||||
|  | 		destroy_clone $TESTPOOL/$TESTCLONE | ||||||
|  | 	datasetexists $TESTPOOL/$TESTFS@$TESTSNAP1 && \ | ||||||
|  | 		destroy_snapshot $TESTPOOL/$TESTFS@$TESTSNAP1 | ||||||
|  | 
 | ||||||
| 	bkmarkexists $TESTPOOL/$TESTVOL#$TESTBKMARK && \ | 	bkmarkexists $TESTPOOL/$TESTVOL#$TESTBKMARK && \ | ||||||
| 		destroy_bookmark $TESTPOOL/$TESTVOL#$TESTBKMARK | 		destroy_bookmark $TESTPOOL/$TESTVOL#$TESTBKMARK | ||||||
| 	bkmarkexists $TESTPOOL/$TESTFS#$TESTBKMARK && \ | 	bkmarkexists $TESTPOOL/$TESTFS#$TESTBKMARK && \ | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 matt-fidd
						matt-fidd