Print this page
3743 zfs needs a refcount audit
Submitted by:   Will Andrews <willa@spectralogic.com>
Submitted by:   Justin Gibbs <justing@spectralogic.com>
Reviewed by:    Matthew Ahrens <mahrens@delphix.com>
Reviewed by:    Eric Schrock <eric.schrock@delphix.com>
Reviewed by:    George Wilson <george.wilson@delphix.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/zfs/zap.c
          +++ new/usr/src/uts/common/fs/zfs/zap.c
↓ open down ↓ 287 lines elided ↑ open up ↑
 288  288                  /*
 289  289                   * read the nextblk for the sake of i/o error checking,
 290  290                   * so that zap_table_load() will catch errors for
 291  291                   * zap_table_store.
 292  292                   */
 293  293                  blk = (idx*2) >> (bs-3);
 294  294  
 295  295                  err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
 296  296                      (tbl->zt_nextblk + blk) << bs, FTAG, &db,
 297  297                      DMU_READ_NO_PREFETCH);
 298      -                dmu_buf_rele(db, FTAG);
      298 +                if (err == 0)
      299 +                        dmu_buf_rele(db, FTAG);
 299  300          }
 300  301          return (err);
 301  302  }
 302  303  
 303  304  /*
 304  305   * Routines for growing the ptrtbl.
 305  306   */
 306  307  
 307  308  static void
 308  309  zap_ptrtbl_transfer(const uint64_t *src, uint64_t *dst, int n)
↓ open down ↓ 676 lines elided ↑ open up ↑
 985  986          return (err);
 986  987  }
 987  988  
 988  989  int
 989  990  zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx)
 990  991  {
 991  992          zap_cursor_t zc;
 992  993          zap_attribute_t za;
 993  994          int err;
 994  995  
      996 +        err = 0;
 995  997          for (zap_cursor_init(&zc, os, fromobj);
 996  998              zap_cursor_retrieve(&zc, &za) == 0;
 997  999              (void) zap_cursor_advance(&zc)) {
 998      -                if (za.za_integer_length != 8 || za.za_num_integers != 1)
 999      -                        return (SET_ERROR(EINVAL));
     1000 +                if (za.za_integer_length != 8 || za.za_num_integers != 1) {
     1001 +                        err = SET_ERROR(EINVAL);
     1002 +                        break;
     1003 +                }
1000 1004                  err = zap_add(os, intoobj, za.za_name,
1001 1005                      8, 1, &za.za_first_integer, tx);
1002 1006                  if (err)
1003      -                        return (err);
     1007 +                        break;
1004 1008          }
1005 1009          zap_cursor_fini(&zc);
1006      -        return (0);
     1010 +        return (err);
1007 1011  }
1008 1012  
1009 1013  int
1010 1014  zap_join_key(objset_t *os, uint64_t fromobj, uint64_t intoobj,
1011 1015      uint64_t value, dmu_tx_t *tx)
1012 1016  {
1013 1017          zap_cursor_t zc;
1014 1018          zap_attribute_t za;
1015 1019          int err;
1016 1020  
     1021 +        err = 0;
1017 1022          for (zap_cursor_init(&zc, os, fromobj);
1018 1023              zap_cursor_retrieve(&zc, &za) == 0;
1019 1024              (void) zap_cursor_advance(&zc)) {
1020      -                if (za.za_integer_length != 8 || za.za_num_integers != 1)
1021      -                        return (SET_ERROR(EINVAL));
     1025 +                if (za.za_integer_length != 8 || za.za_num_integers != 1) {
     1026 +                        err = SET_ERROR(EINVAL);
     1027 +                        break;
     1028 +                }
1022 1029                  err = zap_add(os, intoobj, za.za_name,
1023 1030                      8, 1, &value, tx);
1024 1031                  if (err)
1025      -                        return (err);
     1032 +                        break;
1026 1033          }
1027 1034          zap_cursor_fini(&zc);
1028      -        return (0);
     1035 +        return (err);
1029 1036  }
1030 1037  
1031 1038  int
1032 1039  zap_join_increment(objset_t *os, uint64_t fromobj, uint64_t intoobj,
1033 1040      dmu_tx_t *tx)
1034 1041  {
1035 1042          zap_cursor_t zc;
1036 1043          zap_attribute_t za;
1037 1044          int err;
1038 1045  
     1046 +        err = 0;
1039 1047          for (zap_cursor_init(&zc, os, fromobj);
1040 1048              zap_cursor_retrieve(&zc, &za) == 0;
1041 1049              (void) zap_cursor_advance(&zc)) {
1042 1050                  uint64_t delta = 0;
1043 1051  
1044      -                if (za.za_integer_length != 8 || za.za_num_integers != 1)
1045      -                        return (SET_ERROR(EINVAL));
     1052 +                if (za.za_integer_length != 8 || za.za_num_integers != 1) {
     1053 +                        err = SET_ERROR(EINVAL);
     1054 +                        break;
     1055 +                }
1046 1056  
1047 1057                  err = zap_lookup(os, intoobj, za.za_name, 8, 1, &delta);
1048 1058                  if (err != 0 && err != ENOENT)
1049      -                        return (err);
     1059 +                        break;
1050 1060                  delta += za.za_first_integer;
1051 1061                  err = zap_update(os, intoobj, za.za_name, 8, 1, &delta, tx);
1052 1062                  if (err)
1053      -                        return (err);
     1063 +                        break;
1054 1064          }
1055 1065          zap_cursor_fini(&zc);
1056      -        return (0);
     1066 +        return (err);
1057 1067  }
1058 1068  
1059 1069  int
1060 1070  zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx)
1061 1071  {
1062 1072          char name[20];
1063 1073  
1064 1074          (void) snprintf(name, sizeof (name), "%llx", (longlong_t)value);
1065 1075          return (zap_add(os, obj, name, 8, 1, &value, tx));
1066 1076  }
↓ open down ↓ 312 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX