From 638cab1445079b522f4c99f02eb7eba4d5819aae Mon Sep 17 00:00:00 2001 From: Ryan Zezeski Date: Sat, 4 Nov 2017 15:00:22 -0600 Subject: [PATCH] 8765 dladm tries setting persistent prop on temporary link Reviewed by: Jerry Jelinek Reviewed by: Sebastian Wiedenroth Reviewed by: Toomas Soome Approved by: Gordon Ross --- usr/src/lib/libdladm/common/linkprop.c | 44 +++-- usr/src/pkg/manifests/system-test-utiltest.mf | 2 + usr/src/test/util-tests/runfiles/default.run | 2 + usr/src/test/util-tests/tests/dladm/Makefile | 6 +- .../test/util-tests/tests/dladm/set-linkprop.ksh | 208 +++++++++++++++++++++ 5 files changed, 247 insertions(+), 15 deletions(-) create mode 100644 usr/src/test/util-tests/tests/dladm/set-linkprop.ksh diff --git a/usr/src/lib/libdladm/common/linkprop.c b/usr/src/lib/libdladm/common/linkprop.c index 342584b488..0684971453 100644 --- a/usr/src/lib/libdladm/common/linkprop.c +++ b/usr/src/lib/libdladm/common/linkprop.c @@ -20,7 +20,7 @@ */ /* * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2016 Joyent, Inc. + * Copyright 2017 Joyent, Inc. * Copyright 2015 Garrett D'Amore */ @@ -881,7 +881,8 @@ static dladm_status_t i_dladm_set_single_prop(dladm_handle_t, datalink_id_t, datalink_class_t, uint32_t, prop_desc_t *, char **, uint_t, uint_t); static dladm_status_t i_dladm_set_linkprop(dladm_handle_t, datalink_id_t, - const char *, char **, uint_t, uint_t); + const char *, char **, uint_t, uint_t, + datalink_class_t, uint32_t); static dladm_status_t i_dladm_getset_defval(dladm_handle_t, prop_desc_t *, datalink_id_t, datalink_media_t, uint_t); @@ -1013,19 +1014,13 @@ done: static dladm_status_t i_dladm_set_linkprop(dladm_handle_t handle, datalink_id_t linkid, - const char *prop_name, char **prop_val, uint_t val_cnt, uint_t flags) + const char *prop_name, char **prop_val, uint_t val_cnt, uint_t flags, + datalink_class_t class, uint32_t media) { int i; boolean_t found = B_FALSE; - datalink_class_t class; - uint32_t media; dladm_status_t status = DLADM_STATUS_OK; - status = dladm_datalink_id2info(handle, linkid, NULL, &class, &media, - NULL, 0); - if (status != DLADM_STATUS_OK) - return (status); - for (i = 0; i < DLADM_MAX_PROPS; i++) { prop_desc_t *pdp = &prop_table[i]; dladm_status_t s; @@ -1041,6 +1036,19 @@ i_dladm_set_linkprop(dladm_handle_t handle, datalink_id_t linkid, status = s; break; } else { + /* + * Some consumers of this function pass a + * prop_name of NULL to indicate that all + * properties should reset to their default + * value. Some properties don't support a + * default value and will return NOTSUP -- for + * the purpose of resetting property values we + * treat it the same as success. We need the + * separate status variable 's' so that we can + * record any failed calls in 'status' and + * continue resetting the rest of the + * properties. + */ if (s != DLADM_STATUS_OK && s != DLADM_STATUS_NOTSUP) status = s; @@ -1066,6 +1074,9 @@ dladm_set_linkprop(dladm_handle_t handle, datalink_id_t linkid, const char *prop_name, char **prop_val, uint_t val_cnt, uint_t flags) { dladm_status_t status = DLADM_STATUS_OK; + datalink_class_t class; + uint32_t media; + uint32_t link_flags; if ((linkid == DATALINK_INVALID_LINKID) || (flags == 0) || (prop_val == NULL && val_cnt > 0) || @@ -1078,12 +1089,21 @@ dladm_set_linkprop(dladm_handle_t handle, datalink_id_t linkid, * Check for valid link property against the flags passed * and set the link property when active flag is passed. */ + status = dladm_datalink_id2info(handle, linkid, &link_flags, &class, + &media, NULL, 0); + if (status != DLADM_STATUS_OK) + return (status); status = i_dladm_set_linkprop(handle, linkid, prop_name, prop_val, - val_cnt, flags); + val_cnt, flags, class, media); if (status != DLADM_STATUS_OK) return (status); - if (flags & DLADM_OPT_PERSIST) { + /* + * Write an entry to the persistent configuration database if + * and only if the user has requested the property to be + * persistent and the link is a persistent link. + */ + if ((flags & DLADM_OPT_PERSIST) && (link_flags & DLMGMT_PERSIST)) { status = i_dladm_set_linkprop_db(handle, linkid, prop_name, prop_val, val_cnt); diff --git a/usr/src/pkg/manifests/system-test-utiltest.mf b/usr/src/pkg/manifests/system-test-utiltest.mf index a8cab5ba5c..4532004df2 100644 --- a/usr/src/pkg/manifests/system-test-utiltest.mf +++ b/usr/src/pkg/manifests/system-test-utiltest.mf @@ -12,6 +12,7 @@ # # Copyright (c) 2012 by Delphix. All rights reserved. # Copyright 2014, OmniTI Computer Consulting, Inc. All rights reserved. +# Copyright 2017 Joyent, Inc. # set name=pkg.fmri value=pkg:/system/test/utiltest@$(PKGVERS) @@ -163,6 +164,7 @@ file path=opt/util-tests/tests/libnvpair_json/json_06_nested mode=0555 file path=opt/util-tests/tests/libnvpair_json/json_07_nested_arrays mode=0555 file path=opt/util-tests/tests/libnvpair_json/json_common mode=0555 file path=opt/util-tests/tests/printf_test mode=0555 +file path=opt/util-tests/tests/set-linkprop mode=0555 file path=opt/util-tests/tests/xargs_test mode=0555 license lic_CDDL license=lic_CDDL depend fmri=system/library/iconv/utf-8 type=require diff --git a/usr/src/test/util-tests/runfiles/default.run b/usr/src/test/util-tests/runfiles/default.run index 3f7498e23b..39b244e60e 100644 --- a/usr/src/test/util-tests/runfiles/default.run +++ b/usr/src/test/util-tests/runfiles/default.run @@ -12,6 +12,7 @@ # # Copyright (c) 2012 by Delphix. All rights reserved. # Copyright 2014 Garrett D'Amore +# Copyright 2017 Joyent, Inc. # [DEFAULT] @@ -24,6 +25,7 @@ outputdir = /var/tmp/test_results [/opt/util-tests/tests/printf_test] [/opt/util-tests/tests/allowed-ips] +[/opt/util-tests/tests/set-linkprop] [/opt/util-tests/tests/xargs_test] diff --git a/usr/src/test/util-tests/tests/dladm/Makefile b/usr/src/test/util-tests/tests/dladm/Makefile index df3997656c..e37ae56072 100644 --- a/usr/src/test/util-tests/tests/dladm/Makefile +++ b/usr/src/test/util-tests/tests/dladm/Makefile @@ -10,18 +10,18 @@ # # -# Copyright (c) 2014 Joyent, Inc. All rights reserved. +# Copyright 2017 Joyent, Inc. # include $(SRC)/cmd/Makefile.cmd include $(SRC)/test/Makefile.com ROOTOPTPKG = $(ROOT)/opt/util-tests/tests -PROG = allowed-ips +PROG = allowed-ips set-linkprop ROOTPROG = $(PROG:%=$(ROOTOPTPKG)/%) -all: +all: install: $(ROOTPROG) diff --git a/usr/src/test/util-tests/tests/dladm/set-linkprop.ksh b/usr/src/test/util-tests/tests/dladm/set-linkprop.ksh new file mode 100644 index 0000000000..37e318fe34 --- /dev/null +++ b/usr/src/test/util-tests/tests/dladm/set-linkprop.ksh @@ -0,0 +1,208 @@ +#!/bin/ksh +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2017 Joyent, Inc. +# + +# +# The purpose of this test is to verify that set-linkprop performs as +# it should -- both on persistent and temporary links. +# + +vm_arg0="$(basename $0)" +vm_stub="teststub$$" +vm_pvnic="test_pvnic$$" +vm_tvnic="test_tvnic$$" + +DL_FILE=/etc/dladm/datalink.conf + +fatal() +{ + typeset msg="$*" + [[ -z "$msg" ]] && msg="failed" + echo "TEST_FAIL: $vm_arg0: $msg" >&2 + + # Try to clean up just in case + dladm delete-vnic $vm_pvnic 2>/dev/null + dladm delete-vnic $vm_tvnic 2>/dev/null + dladm delete-etherstub $vm_stub 2>/dev/null + exit 1 +} + +delete_stub() +{ + dladm delete-etherstub $vm_stub || fatal \ + "failed to delete stub $vm_stub" +} + +create_stub() +{ + dladm create-etherstub $vm_stub || fatal \ + "failed to create stub" +} + +create_vnic() +{ + typeset dev=$1 + typeset flags=$2 + + dladm create-vnic $flags -l $vm_stub $dev 2>/dev/null || fatal \ + "failed to create vnic: $dev" +} + +delete_vnic() +{ + typeset dev=$1 + + dladm delete-vnic $dev || fatal "failed to delete vnic: $dev" +} + +# +# Validate the property is reported by dladm. +# +validate_prop() +{ + typeset dev=$1 + typeset prop=$2 + typeset val=$3 + typeset oval + + [[ -z "$dev" ]] && fatal "missing required device" + [[ -z "$prop" ]] && fatal "missing required prop" + [[ -z "$val" ]] && fatal "missing required val" + oval=$(dladm show-linkprop -c -o value -p $prop $dev | tr -d ' ') + [[ $? -eq 0 ]] || fatal "failed to get $prop for $dev" + [[ "$val" == "$oval" ]] || fatal \ + "$prop mismatch on $dev: expected $val, got $oval" +} + +# +# Validate the property is persistent. +# +validate_pprop() +{ + typeset dev=$1 + typeset prop=$2 + typeset val=$3 + typeset oval + + [[ -z "$dev" ]] && fatal "missing required device" + [[ -z "$prop" ]] && fatal "missing required prop" + [[ -z "$val" ]] && fatal "missing required val" + + oval=$(awk "/^$dev/ { print \$2 }" $DL_FILE | \ + awk -F, "BEGIN { RS=\";\"; } /^$prop/ { print \$2; }") + + [[ $? -eq 0 ]] || fatal "failed to get persistent $prop for $dev" + [[ "$val" == "$oval" ]] || fatal \ + "persistent $prop mismatch on $dev: expected $val, got $oval" +} + +# +# Validate the the property is not persistent. +# +validate_not_pprop() +{ + typeset dev=$1 + typeset prop=$2 + + [[ -z "$dev" ]] && fatal "missing required device" + [[ -z "$prop" ]] && fatal "missing required prop" + + oval=$(awk "/^$dev/ { print \$2 }" $DL_FILE | \ + awk -F, "BEGIN { RS=\";\"; } /^$prop/ { print \$2; }") + + [[ $? -eq 0 ]] || fatal "failed to search $DL_FILE" + + [[ -z "$oval" ]] || fatal \ + "found persistent $prop for $dev but didn't expect to" + +} + +set_prop_pass() +{ + typeset dev=$1 + typeset flags=$2 + typeset prop=$3 + typeset val=$4 + typeset msg="failed to set prop $prop on $dev" + + [[ "$#" -ne 4 ]] && fatal "set_prop_pass() requires 4 args" + [[ -z "$dev" ]] && fatal "missing required device" + [[ -z "$prop" ]] && fatal "missing required prop" + [[ -z "$val" ]] && fatal "missing required val" + + if [ -n "$flags" ]; then + typeset msg="failed to set temp prop $prop on $dev" + fi + + dladm set-linkprop $flags -p $prop=$val $dev || fatal $msg +} + +test_pass() +{ + [[ -f $DL_FILE ]] || fatal "datalink file does not exist: $DL_FILE" + + create_stub + + # + # Test setting persistent and temp properties on a persistent + # link. + # + create_vnic $vm_pvnic + + set_prop_pass $vm_pvnic "-t" maxbw 89 + validate_prop $vm_pvnic maxbw 89 + validate_not_pprop $vm_pvnic maxbw 89 + set_prop_pass $vm_pvnic "-t" priority medium + validate_prop $vm_pvnic priority medium + validate_not_pprop $vm_pvnic priority medium + + set_prop_pass $vm_pvnic "" maxbw 99 + validate_prop $vm_pvnic maxbw 99 + validate_pprop $vm_pvnic maxbw 99 + set_prop_pass $vm_pvnic "" priority low + validate_prop $vm_pvnic priority low + validate_pprop $vm_pvnic priority low + + delete_vnic $vm_pvnic + + # + # Test setting persistent and temp properties on a temp link. + # A "persistent" property on a temp link is really just a temp + # property. But setting a property on a temp link, without + # passing -t, should still work and report success to the + # user. + # + create_vnic $vm_tvnic "-t" + + set_prop_pass $vm_tvnic "-t" maxbw 89 + validate_prop $vm_tvnic maxbw 89 + validate_not_pprop $vm_tvnic maxbw 89 + set_prop_pass $vm_tvnic "-t" priority medium + validate_prop $vm_tvnic priority medium + validate_not_pprop $vm_tvnic priority medium + + set_prop_pass $vm_tvnic "" maxbw 99 + validate_prop $vm_tvnic maxbw 99 + validate_not_pprop $vm_tvnic maxbw 99 + set_prop_pass $vm_tvnic "" priority low + validate_prop $vm_tvnic priority low + validate_not_pprop $vm_tvnic priority low + + delete_vnic $vm_tvnic + + delete_stub +} + +test_pass -- 2.11.4.GIT