Print this page
4095 minor cleanup up libshare

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libshare/common/libsharecore.c
          +++ new/usr/src/lib/libshare/common/libsharecore.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) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
       24 + * Copyright (c) 2013 RackTop Systems.
  24   25   */
  25   26  
  26   27  /*
  27   28   * core library for common functions across all config store types
  28   29   * and file systems to be exported. This includes legacy dfstab/sharetab
  29   30   * parsing. Need to eliminate XML where possible.
  30   31   */
  31   32  
  32   33  #include <stdio.h>
  33   34  #include <string.h>
↓ open down ↓ 49 lines elided ↑ open up ↑
  83   84      char *group;
  84   85      char *origline;
  85   86      int lineno;
  86   87  } xfs_sharelist_t;
  87   88  static void parse_dfstab(sa_handle_t, char *, xmlNodePtr);
  88   89  extern char *_sa_get_token(char *);
  89   90  static void dfs_free_list(xfs_sharelist_t *);
  90   91  /* prototypes */
  91   92  void getlegacyconfig(sa_handle_t, char *, xmlNodePtr *);
  92   93  extern sa_share_t _sa_add_share(sa_group_t, char *, int, int *, uint64_t);
  93      -extern sa_group_t _sa_create_group(sa_handle_impl_t, char *);
       94 +extern sa_group_t _sa_create_group(sa_handle_t, char *);
  94   95  static void outdfstab(FILE *, xfs_sharelist_t *);
  95   96  extern int _sa_remove_optionset(sa_optionset_t);
  96   97  extern int set_node_share(void *, char *, char *);
  97   98  extern void set_node_attr(void *, char *, char *);
  98   99  
  99  100  /*
 100  101   * sablocksigs(*sigs)
 101  102   *
 102  103   * block important signals for a critical region. Arg is a pointer to
 103  104   * a sigset_t that is used later for the unblock.
↓ open down ↓ 630 lines elided ↑ open up ↑
 734  735          return (ret);
 735  736  }
 736  737  
 737  738  /*
 738  739   * sa_is_security(optname, proto)
 739  740   *
 740  741   * Check to see if optname is a security (named optionset) specific
 741  742   * property for the specified protocol.
 742  743   */
 743  744  
 744      -int
      745 +boolean_t
 745  746  sa_is_security(char *optname, char *proto)
 746  747  {
 747      -        int ret = 0;
      748 +        int ret = B_FALSE;
 748  749          if (proto != NULL)
 749  750                  ret = sa_proto_security_prop(proto, optname);
 750  751          return (ret);
 751  752  }
 752  753  
 753  754  /*
 754  755   * add_syntax_comment(root, line, err, todfstab)
 755  756   *
 756  757   * Add a comment to the document indicating a syntax error. If
 757  758   * todfstab is set, write it back to the dfstab file as well.
↓ open down ↓ 10 lines elided ↑ open up ↑
 768  769          if (todfstab)
 769  770                  sa_comment_line(line, err);
 770  771  }
 771  772  
 772  773  /*
 773  774   * sa_is_share(object)
 774  775   *
 775  776   * returns true of the object is of type "share".
 776  777   */
 777  778  
 778      -int
      779 +boolean_t
 779  780  sa_is_share(void *object)
 780  781  {
 781  782          if (object != NULL) {
 782  783                  if (strcmp((char *)((xmlNodePtr)object)->name, "share") == 0)
 783      -                return (1);
      784 +                return (B_TRUE);
 784  785          }
 785      -        return (0);
      786 +        return (B_FALSE);
 786  787  }
 787  788  /*
 788  789   * sa_is_resource(object)
 789  790   *
 790  791   * returns true of the object is of type "share".
 791  792   */
 792  793  
 793      -int
      794 +boolean_t
 794  795  sa_is_resource(void *object)
 795  796  {
 796  797          if (object != NULL) {
 797  798                  if (strcmp((char *)((xmlNodePtr)object)->name, "resource") == 0)
 798      -                        return (1);
      799 +                        return (B_TRUE);
 799  800          }
 800      -        return (0);
      801 +        return (B_FALSE);
 801  802  }
 802  803  
 803  804  /*
 804  805   * _sa_remove_property(property)
 805  806   *
 806  807   * remove a property only from the document.
 807  808   */
 808  809  
 809  810  static void
 810  811  _sa_remove_property(sa_property_t property)
↓ open down ↓ 700 lines elided ↑ open up ↑
1511 1512                          }
1512 1513                  } else {
1513 1514                          if (sa_zfs_is_shared(handle, tmplist->path)) {
1514 1515                                  group = sa_get_group(handle, "zfs");
1515 1516                                  if (group == NULL) {
1516 1517                                          group = sa_create_group(handle,
1517 1518                                              "zfs", &err);
1518 1519                                          if (group == NULL &&
1519 1520                                              err == SA_NO_PERMISSION) {
1520 1521                                                  group = _sa_create_group(
1521      -                                                    (sa_handle_impl_t)
1522      -                                                    handle,
1523      -                                                    "zfs");
     1522 +                                                    handle, "zfs");
1524 1523                                          }
1525 1524                                          if (group != NULL) {
1526 1525                                                  (void) sa_create_optionset(
1527 1526                                                      group, tmplist->fstype);
1528 1527                                                  (void) sa_set_group_attr(group,
1529 1528                                                      "zfs", "true");
1530 1529                                          }
1531 1530                                  }
1532 1531                                  if (group != NULL) {
1533 1532                                          share = _sa_add_share(group,
↓ open down ↓ 34 lines elided ↑ open up ↑
1568 1567          dfs_free_list(list);
1569 1568          return (legacy);
1570 1569  }
1571 1570  
1572 1571  /*
1573 1572   * Get the transient shares from the sharetab (or other) file.  since
1574 1573   * these are transient, they only appear in the working file and not
1575 1574   * in a repository.
1576 1575   */
1577 1576  int
1578      -gettransients(sa_handle_impl_t ihandle, xmlNodePtr *root)
     1577 +gettransients(sa_handle_t handle, xmlNodePtr *root)
1579 1578  {
1580 1579          int legacy = 0;
1581 1580          int numproto;
1582 1581          char **protocols = NULL;
1583 1582          int i;
1584 1583  
1585 1584          if (root != NULL) {
1586 1585                  if (*root == NULL)
1587 1586                          *root = xmlNewNode(NULL, (xmlChar *)"sharecfg");
1588 1587                  if (*root != NULL) {
1589      -                        legacy = parse_sharetab(ihandle);
     1588 +                        legacy = parse_sharetab(handle);
1590 1589                          numproto = sa_get_protocols(&protocols);
1591 1590                          for (i = 0; i < numproto; i++)
1592 1591                                  legacy |= sa_proto_get_transients(
1593      -                                    (sa_handle_t)ihandle, protocols[i]);
     1592 +                                    handle, protocols[i]);
1594 1593                          if (protocols != NULL)
1595 1594                                  free(protocols);
1596 1595                  }
1597 1596          }
1598 1597          return (legacy);
1599 1598  }
1600 1599  
1601 1600  /*
1602 1601   * sa_has_prop(optionset, prop)
1603 1602   *
↓ open down ↓ 478 lines elided ↑ open up ↑
2082 2081   * sa_update_sharetab_ts(handle)
2083 2082   *
2084 2083   * Update the internal timestamp of when sharetab was last
2085 2084   * changed. This needs to be public for ZFS to get at it.
2086 2085   */
2087 2086  
2088 2087  void
2089 2088  sa_update_sharetab_ts(sa_handle_t handle)
2090 2089  {
2091 2090          struct stat st;
2092      -        sa_handle_impl_t implhandle = (sa_handle_impl_t)handle;
2093 2091  
2094      -        if (implhandle != NULL && stat(SA_LEGACY_SHARETAB, &st) == 0)
2095      -                implhandle->tssharetab = TSTAMP(st.st_mtim);
     2092 +        if (handle != NULL && stat(SA_LEGACY_SHARETAB, &st) == 0)
     2093 +                handle->tssharetab = TSTAMP(st.st_mtim);
2096 2094  }
2097 2095  
2098 2096  /*
2099 2097   * sa_update_sharetab(share, proto)
2100 2098   *
2101 2099   * Update the sharetab file with info from the specified share.
2102 2100   * This could be an update or add.
2103 2101   */
2104 2102  
2105 2103  int
↓ open down ↓ 62 lines elided ↑ open up ↑
2168 2166  
2169 2167  /*
2170 2168   * sa_needs_refresh(handle)
2171 2169   *
2172 2170   * Returns B_TRUE if the internal cache needs to be refreshed do to a
2173 2171   * change by another process.  B_FALSE returned otherwise.
2174 2172   */
2175 2173  boolean_t
2176 2174  sa_needs_refresh(sa_handle_t handle)
2177 2175  {
2178      -        sa_handle_impl_t implhandle = (sa_handle_impl_t)handle;
2179 2176          struct stat st;
2180 2177          char *str;
2181 2178          uint64_t tstamp;
2182 2179          scf_simple_prop_t *prop;
2183 2180  
2184 2181          if (handle == NULL)
2185 2182                  return (B_TRUE);
2186 2183  
2187 2184          /*
2188 2185           * If sharetab has changed, then there was an external
2189 2186           * change. Check sharetab first since it is updated by ZFS as
2190 2187           * well as sharemgr.  This is where external ZFS changes are
2191 2188           * caught.
2192 2189           */
2193 2190          if (stat(SA_LEGACY_SHARETAB, &st) == 0 &&
2194      -            TSTAMP(st.st_mtim) != implhandle->tssharetab)
     2191 +            TSTAMP(st.st_mtim) != handle->tssharetab)
2195 2192                  return (B_TRUE);
2196 2193  
2197 2194          /*
2198 2195           * If sharetab wasn't changed, check whether there were any
2199 2196           * SMF transactions that modified the config but didn't
2200 2197           * initiate a share.  This is less common but does happen.
2201 2198           */
2202      -        prop = scf_simple_prop_get(implhandle->scfhandle->handle,
     2199 +        prop = scf_simple_prop_get(handle->scfhandle->handle,
2203 2200              (const char *)SA_SVC_FMRI_BASE ":default", "state",
2204 2201              "lastupdate");
2205 2202          if (prop != NULL) {
2206 2203                  str = scf_simple_prop_next_astring(prop);
2207 2204                  if (str != NULL)
2208 2205                          tstamp = strtoull(str, NULL, 0);
2209 2206                  else
2210 2207                          tstamp = 0;
2211 2208                  scf_simple_prop_free(prop);
2212      -                if (tstamp != implhandle->tstrans)
     2209 +                if (tstamp != handle->tstrans)
2213 2210                          return (B_TRUE);
2214 2211          }
2215 2212  
2216 2213          return (B_FALSE);
2217 2214  }
2218 2215  
2219 2216  /*
2220 2217   * sa_fix_resource_name(path)
2221 2218   *
2222 2219   * Convert invalid characters in a resource name (SMB share name)
↓ open down ↓ 63 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX