Print this page
OS-2031 fmtopo -P flag does not appear to set properties

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/fm/fmtopo/common/fmtopo.c
          +++ new/usr/src/cmd/fm/fmtopo/common/fmtopo.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
       24 + * Copyright (c) 2013, Joyent, Inc. All rights reserved.
  24   25   */
  25   26  
  26   27  
  27   28  #include <sys/fm/protocol.h>
  28   29  #include <fm/libtopo.h>
  29   30  #include <ctype.h>
  30   31  #include <fnmatch.h>
  31   32  #include <limits.h>
  32   33  #include <strings.h>
  33   34  #include <stdio.h>
↓ open down ↓ 556 lines elided ↑ open up ↑
 590  591                  if (match && !all)
 591  592                          return;
 592  593          }
 593  594  }
 594  595  
 595  596  static void
 596  597  set_prop(topo_hdl_t *thp, tnode_t *node, nvlist_t *fmri, struct prop_args *pp)
 597  598  {
 598  599          int ret, err = 0;
 599  600          topo_type_t type;
 600      -        nvlist_t *nvl, *f = NULL;
      601 +        nvlist_t *nvl = NULL;
 601  602          char *end;
 602  603  
 603  604          if (pp->prop == NULL || pp->type == NULL || pp->value == NULL)
 604      -                return;
      605 +                goto out;
 605  606  
 606  607          if ((type = str2type(pp->type)) == TOPO_TYPE_INVALID) {
 607  608                  (void) fprintf(stderr, "%s: invalid property type %s for %s\n",
 608  609                      g_pname, pp->type, pp->prop);
 609      -                return;
      610 +                goto out;
 610  611          }
 611  612  
 612  613          if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) {
 613  614                  (void) fprintf(stderr, "%s: nvlist allocation failed for "
 614  615                      "%s=%s:%s\n", g_pname, pp->prop, pp->type, pp->value);
 615      -                return;
      616 +                goto out;
 616  617          }
 617  618          ret = nvlist_add_string(nvl, TOPO_PROP_VAL_NAME, pp->prop);
 618  619          ret |= nvlist_add_uint32(nvl, TOPO_PROP_VAL_TYPE, type);
 619  620          if (ret != 0) {
 620  621                  (void) fprintf(stderr, "%s: invalid property type %s for %s\n",
 621  622                      g_pname, pp->type, pp->prop);
 622      -                nvlist_free(nvl);
 623      -                return;
      623 +                goto out;
 624  624          }
 625  625  
 626  626          errno = 0;
 627  627          switch (type) {
 628  628                  case TOPO_TYPE_INT32:
 629  629                  {
 630  630                          int32_t val;
 631  631  
 632  632                          val = strtol(pp->value, &end, 0);
 633  633                          if (errno == ERANGE) {
↓ open down ↓ 40 lines elided ↑ open up ↑
 674  674                          break;
 675  675                  }
 676  676                  case TOPO_TYPE_STRING:
 677  677                  {
 678  678                          ret = nvlist_add_string(nvl, TOPO_PROP_VAL_VAL,
 679  679                              pp->value);
 680  680                          break;
 681  681                  }
 682  682                  case TOPO_TYPE_FMRI:
 683  683                  {
 684      -                        if ((ret = topo_fmri_str2nvl(thp, pp->value, &f, &err))
 685      -                            < 0)
      684 +                        nvlist_t *val = NULL;
      685 +
      686 +                        if ((ret = topo_fmri_str2nvl(thp, pp->value, &val,
      687 +                            &err)) < 0)
 686  688                                  break;
 687  689  
 688  690                          if ((ret = nvlist_add_nvlist(nvl, TOPO_PROP_VAL_VAL,
 689      -                            f)) != 0)
      691 +                            val)) != 0)
 690  692                                  err = ETOPO_PROP_NVL;
      693 +
      694 +                        nvlist_free(val);
 691  695                          break;
 692  696                  }
 693  697                  default:
 694  698                          ret = -1;
 695  699          }
 696  700  
 697  701          if (ret != 0) {
 698  702                  (void) fprintf(stderr, "%s: unable to set property value for "
 699  703                      "%s: %s\n", g_pname, pp->prop,  topo_strerror(err));
 700      -                nvlist_free(nvl);
 701      -                return;
      704 +                goto out;
 702  705          }
 703  706  
 704  707          if (node != NULL) {
 705      -                if (topo_prop_setprop(node, pp->group, nvl, TOPO_PROP_MUTABLE,
 706      -                    f, &ret) < 0) {
      708 +                if ((ret = topo_prop_setprop(node, pp->group, nvl,
      709 +                    TOPO_PROP_MUTABLE, nvl, &err)) < 0) {
 707  710                          (void) fprintf(stderr, "%s: unable to set property "
 708  711                              "value for " "%s=%s:%s: %s\n", g_pname, pp->prop,
 709      -                            pp->type, pp->value, topo_strerror(ret));
 710      -                        nvlist_free(nvl);
 711      -                        nvlist_free(f);
 712      -                        return;
      712 +                            pp->type, pp->value, topo_strerror(err));
      713 +                        goto out;
 713  714                  }
 714  715          } else {
 715      -                if (topo_fmri_setprop(thp, fmri,  pp->group, nvl,
 716      -                    TOPO_PROP_MUTABLE, f, &ret) < 0) {
      716 +                if ((ret = topo_fmri_setprop(thp, fmri,  pp->group, nvl,
      717 +                    TOPO_PROP_MUTABLE, nvl, &err)) < 0) {
 717  718                          (void) fprintf(stderr, "%s: unable to set property "
 718  719                              "value for " "%s=%s:%s: %s\n", g_pname, pp->prop,
 719      -                            pp->type, pp->value, topo_strerror(ret));
 720      -                        nvlist_free(nvl);
 721      -                        nvlist_free(f);
 722      -                        return;
      720 +                            pp->type, pp->value, topo_strerror(err));
      721 +                        goto out;
 723  722                  }
 724  723          }
 725  724  
 726  725          nvlist_free(nvl);
      726 +        nvl = NULL;
 727  727  
 728  728          /*
 729  729           * Now, get the property back for printing
 730  730           */
 731  731          if (node != NULL) {
 732      -                if (topo_prop_getprop(node, pp->group, pp->prop, f, &nvl,
 733      -                    &err) < 0) {
      732 +                if ((ret = topo_prop_getprop(node, pp->group, pp->prop, NULL,
      733 +                    &nvl, &err)) < 0) {
 734  734                          (void) fprintf(stderr, "%s: failed to get %s.%s: %s\n",
 735  735                              g_pname, pp->group, pp->prop, topo_strerror(err));
 736      -                        nvlist_free(f);
 737      -                        return;
      736 +                        goto out;
 738  737                  }
 739  738          } else {
 740      -                if (topo_fmri_getprop(thp, fmri, pp->group, pp->prop,
 741      -                    f, &nvl, &err) < 0) {
      739 +                if ((ret = topo_fmri_getprop(thp, fmri, pp->group, pp->prop,
      740 +                    NULL, &nvl, &err)) < 0) {
 742  741                          (void) fprintf(stderr, "%s: failed to get %s.%s: %s\n",
 743  742                              g_pname, pp->group, pp->prop, topo_strerror(err));
 744      -                        nvlist_free(f);
 745      -                        return;
      743 +                        goto out;
 746  744                  }
 747  745          }
 748  746  
 749  747          print_pgroup(thp, node, pp->group, NULL, NULL, 0);
 750  748          print_prop_nameval(thp, node, nvl);
 751      -        nvlist_free(nvl);
 752  749  
 753      -        nvlist_free(f);
      750 +out:
      751 +        nvlist_free(nvl);
 754  752  }
 755  753  
 756  754  static void
 757  755  print_props(topo_hdl_t *thp, tnode_t *node)
 758  756  {
 759  757          int i, err;
 760  758          nvlist_t *nvl;
 761  759          struct prop_args *pp;
 762  760  
 763  761          if (pcnt == 0)
↓ open down ↓ 549 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX