Print this page
3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero


   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.

  23  */
  24 

  25 /* Portions Copyright 2007 Jeremy Teo */
  26 
  27 #ifdef _KERNEL
  28 #include <sys/types.h>
  29 #include <sys/param.h>
  30 #include <sys/time.h>
  31 #include <sys/systm.h>
  32 #include <sys/sysmacros.h>
  33 #include <sys/resource.h>
  34 #include <sys/mntent.h>
  35 #include <sys/mkdev.h>
  36 #include <sys/u8_textprep.h>
  37 #include <sys/dsl_dataset.h>
  38 #include <sys/vfs.h>
  39 #include <sys/vfs_opreg.h>
  40 #include <sys/vnode.h>
  41 #include <sys/file.h>
  42 #include <sys/kmem.h>
  43 #include <sys/errno.h>
  44 #include <sys/unistd.h>


 789         }
 790 
 791         obj_type = zfsvfs->z_use_sa ? DMU_OT_SA : DMU_OT_ZNODE;
 792         bonuslen = (obj_type == DMU_OT_SA) ?
 793             DN_MAX_BONUSLEN : ZFS_OLD_ZNODE_PHYS_SIZE;
 794 
 795         /*
 796          * Create a new DMU object.
 797          */
 798         /*
 799          * There's currently no mechanism for pre-reading the blocks that will
 800          * be needed to allocate a new object, so we accept the small chance
 801          * that there will be an i/o error and we will fail one of the
 802          * assertions below.
 803          */
 804         if (vap->va_type == VDIR) {
 805                 if (zfsvfs->z_replay) {
 806                         err = zap_create_claim_norm(zfsvfs->z_os, obj,
 807                             zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
 808                             obj_type, bonuslen, tx);
 809                         ASSERT3U(err, ==, 0);
 810                 } else {
 811                         obj = zap_create_norm(zfsvfs->z_os,
 812                             zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
 813                             obj_type, bonuslen, tx);
 814                 }
 815         } else {
 816                 if (zfsvfs->z_replay) {
 817                         err = dmu_object_claim(zfsvfs->z_os, obj,
 818                             DMU_OT_PLAIN_FILE_CONTENTS, 0,
 819                             obj_type, bonuslen, tx);
 820                         ASSERT3U(err, ==, 0);
 821                 } else {
 822                         obj = dmu_object_alloc(zfsvfs->z_os,
 823                             DMU_OT_PLAIN_FILE_CONTENTS, 0,
 824                             obj_type, bonuslen, tx);
 825                 }
 826         }
 827 
 828         ZFS_OBJ_HOLD_ENTER(zfsvfs, obj);
 829         VERIFY(0 == sa_buf_hold(zfsvfs->z_os, obj, NULL, &db));
 830 
 831         /*
 832          * If this is the root, fix up the half-initialized parent pointer
 833          * to reference the just-allocated physical data area.
 834          */
 835         if (flag & IS_ROOT_NODE) {
 836                 dzp->z_id = obj;
 837         } else {
 838                 dzp_pflags = dzp->z_pflags;
 839         }
 840 


 982                 ASSERT(*zpp != NULL);
 983         } else {
 984                 /*
 985                  * If we are creating the root node, the "parent" we
 986                  * passed in is the znode for the root.
 987                  */
 988                 *zpp = dzp;
 989 
 990                 (*zpp)->z_sa_hdl = sa_hdl;
 991         }
 992 
 993         (*zpp)->z_pflags = pflags;
 994         (*zpp)->z_mode = mode;
 995 
 996         if (vap->va_mask & AT_XVATTR)
 997                 zfs_xvattr_set(*zpp, (xvattr_t *)vap, tx);
 998 
 999         if (obj_type == DMU_OT_ZNODE ||
1000             acl_ids->z_aclp->z_version < ZFS_ACL_VERSION_FUID) {
1001                 err = zfs_aclset_common(*zpp, acl_ids->z_aclp, cr, tx);
1002                 ASSERT3P(err, ==, 0);
1003         }
1004         ZFS_OBJ_HOLD_EXIT(zfsvfs, obj);
1005 }
1006 
1007 /*
1008  * zfs_xvattr_set only updates the in-core attributes
1009  * it is assumed the caller will be doing an sa_bulk_update
1010  * to push the changes out
1011  */
1012 void
1013 zfs_xvattr_set(znode_t *zp, xvattr_t *xvap, dmu_tx_t *tx)
1014 {
1015         xoptattr_t *xoap;
1016 
1017         xoap = xva_getxoptattr(xvap);
1018         ASSERT(xoap);
1019 
1020         if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) {
1021                 uint64_t times[2];
1022                 ZFS_TIME_ENCODE(&xoap->xoa_createtime, times);


1403 zfs_grow_blocksize(znode_t *zp, uint64_t size, dmu_tx_t *tx)
1404 {
1405         int             error;
1406         u_longlong_t    dummy;
1407 
1408         if (size <= zp->z_blksz)
1409                 return;
1410         /*
1411          * If the file size is already greater than the current blocksize,
1412          * we will not grow.  If there is more than one block in a file,
1413          * the blocksize cannot change.
1414          */
1415         if (zp->z_blksz && zp->z_size > zp->z_blksz)
1416                 return;
1417 
1418         error = dmu_object_set_blocksize(zp->z_zfsvfs->z_os, zp->z_id,
1419             size, 0, tx);
1420 
1421         if (error == ENOTSUP)
1422                 return;
1423         ASSERT3U(error, ==, 0);
1424 
1425         /* What blocksize did we actually get? */
1426         dmu_object_size_from_db(sa_get_db(zp->z_sa_hdl), &zp->z_blksz, &dummy);
1427 }
1428 
1429 /*
1430  * This is a dummy interface used when pvn_vplist_dirty() should *not*
1431  * be calling back into the fs for a putpage().  E.g.: when truncating
1432  * a file, the pages being "thrown away* don't need to be written out.
1433  */
1434 /* ARGSUSED */
1435 static int
1436 zfs_no_putpage(vnode_t *vp, page_t *pp, u_offset_t *offp, size_t *lenp,
1437     int flags, cred_t *cr)
1438 {
1439         ASSERT(0);
1440         return (0);
1441 }
1442 
1443 /*




   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2012 by Delphix. All rights reserved.
  24  */
  25 
  26 
  27 /* Portions Copyright 2007 Jeremy Teo */
  28 
  29 #ifdef _KERNEL
  30 #include <sys/types.h>
  31 #include <sys/param.h>
  32 #include <sys/time.h>
  33 #include <sys/systm.h>
  34 #include <sys/sysmacros.h>
  35 #include <sys/resource.h>
  36 #include <sys/mntent.h>
  37 #include <sys/mkdev.h>
  38 #include <sys/u8_textprep.h>
  39 #include <sys/dsl_dataset.h>
  40 #include <sys/vfs.h>
  41 #include <sys/vfs_opreg.h>
  42 #include <sys/vnode.h>
  43 #include <sys/file.h>
  44 #include <sys/kmem.h>
  45 #include <sys/errno.h>
  46 #include <sys/unistd.h>


 791         }
 792 
 793         obj_type = zfsvfs->z_use_sa ? DMU_OT_SA : DMU_OT_ZNODE;
 794         bonuslen = (obj_type == DMU_OT_SA) ?
 795             DN_MAX_BONUSLEN : ZFS_OLD_ZNODE_PHYS_SIZE;
 796 
 797         /*
 798          * Create a new DMU object.
 799          */
 800         /*
 801          * There's currently no mechanism for pre-reading the blocks that will
 802          * be needed to allocate a new object, so we accept the small chance
 803          * that there will be an i/o error and we will fail one of the
 804          * assertions below.
 805          */
 806         if (vap->va_type == VDIR) {
 807                 if (zfsvfs->z_replay) {
 808                         err = zap_create_claim_norm(zfsvfs->z_os, obj,
 809                             zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
 810                             obj_type, bonuslen, tx);
 811                         ASSERT0(err);
 812                 } else {
 813                         obj = zap_create_norm(zfsvfs->z_os,
 814                             zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
 815                             obj_type, bonuslen, tx);
 816                 }
 817         } else {
 818                 if (zfsvfs->z_replay) {
 819                         err = dmu_object_claim(zfsvfs->z_os, obj,
 820                             DMU_OT_PLAIN_FILE_CONTENTS, 0,
 821                             obj_type, bonuslen, tx);
 822                         ASSERT0(err);
 823                 } else {
 824                         obj = dmu_object_alloc(zfsvfs->z_os,
 825                             DMU_OT_PLAIN_FILE_CONTENTS, 0,
 826                             obj_type, bonuslen, tx);
 827                 }
 828         }
 829 
 830         ZFS_OBJ_HOLD_ENTER(zfsvfs, obj);
 831         VERIFY(0 == sa_buf_hold(zfsvfs->z_os, obj, NULL, &db));
 832 
 833         /*
 834          * If this is the root, fix up the half-initialized parent pointer
 835          * to reference the just-allocated physical data area.
 836          */
 837         if (flag & IS_ROOT_NODE) {
 838                 dzp->z_id = obj;
 839         } else {
 840                 dzp_pflags = dzp->z_pflags;
 841         }
 842 


 984                 ASSERT(*zpp != NULL);
 985         } else {
 986                 /*
 987                  * If we are creating the root node, the "parent" we
 988                  * passed in is the znode for the root.
 989                  */
 990                 *zpp = dzp;
 991 
 992                 (*zpp)->z_sa_hdl = sa_hdl;
 993         }
 994 
 995         (*zpp)->z_pflags = pflags;
 996         (*zpp)->z_mode = mode;
 997 
 998         if (vap->va_mask & AT_XVATTR)
 999                 zfs_xvattr_set(*zpp, (xvattr_t *)vap, tx);
1000 
1001         if (obj_type == DMU_OT_ZNODE ||
1002             acl_ids->z_aclp->z_version < ZFS_ACL_VERSION_FUID) {
1003                 err = zfs_aclset_common(*zpp, acl_ids->z_aclp, cr, tx);
1004                 ASSERT0(err);
1005         }
1006         ZFS_OBJ_HOLD_EXIT(zfsvfs, obj);
1007 }
1008 
1009 /*
1010  * zfs_xvattr_set only updates the in-core attributes
1011  * it is assumed the caller will be doing an sa_bulk_update
1012  * to push the changes out
1013  */
1014 void
1015 zfs_xvattr_set(znode_t *zp, xvattr_t *xvap, dmu_tx_t *tx)
1016 {
1017         xoptattr_t *xoap;
1018 
1019         xoap = xva_getxoptattr(xvap);
1020         ASSERT(xoap);
1021 
1022         if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) {
1023                 uint64_t times[2];
1024                 ZFS_TIME_ENCODE(&xoap->xoa_createtime, times);


1405 zfs_grow_blocksize(znode_t *zp, uint64_t size, dmu_tx_t *tx)
1406 {
1407         int             error;
1408         u_longlong_t    dummy;
1409 
1410         if (size <= zp->z_blksz)
1411                 return;
1412         /*
1413          * If the file size is already greater than the current blocksize,
1414          * we will not grow.  If there is more than one block in a file,
1415          * the blocksize cannot change.
1416          */
1417         if (zp->z_blksz && zp->z_size > zp->z_blksz)
1418                 return;
1419 
1420         error = dmu_object_set_blocksize(zp->z_zfsvfs->z_os, zp->z_id,
1421             size, 0, tx);
1422 
1423         if (error == ENOTSUP)
1424                 return;
1425         ASSERT0(error);
1426 
1427         /* What blocksize did we actually get? */
1428         dmu_object_size_from_db(sa_get_db(zp->z_sa_hdl), &zp->z_blksz, &dummy);
1429 }
1430 
1431 /*
1432  * This is a dummy interface used when pvn_vplist_dirty() should *not*
1433  * be calling back into the fs for a putpage().  E.g.: when truncating
1434  * a file, the pages being "thrown away* don't need to be written out.
1435  */
1436 /* ARGSUSED */
1437 static int
1438 zfs_no_putpage(vnode_t *vp, page_t *pp, u_offset_t *offp, size_t *lenp,
1439     int flags, cred_t *cr)
1440 {
1441         ASSERT(0);
1442         return (0);
1443 }
1444 
1445 /*