usr/src/uts/common/fs/zfs/zfs_vnops.c
changeset 6992 20c04e18c58c
parent 6976 cae5f06df471
child 7294 c9c31ef4c960
equal deleted inserted replaced
6991:c0faefde7d97 6992:20c04e18c58c
  1302 		/*
  1302 		/*
  1303 		 * Truncate regular files if requested.
  1303 		 * Truncate regular files if requested.
  1304 		 */
  1304 		 */
  1305 		if ((ZTOV(zp)->v_type == VREG) &&
  1305 		if ((ZTOV(zp)->v_type == VREG) &&
  1306 		    (vap->va_mask & AT_SIZE) && (vap->va_size == 0)) {
  1306 		    (vap->va_mask & AT_SIZE) && (vap->va_size == 0)) {
       
  1307 			/* we can't hold any locks when calling zfs_freesp() */
       
  1308 			zfs_dirent_unlock(dl);
       
  1309 			dl = NULL;
  1307 			error = zfs_freesp(zp, 0, 0, mode, TRUE);
  1310 			error = zfs_freesp(zp, 0, 0, mode, TRUE);
  1308 			if (error == ERESTART &&
       
  1309 			    zfsvfs->z_assign == TXG_NOWAIT) {
       
  1310 				/* NB: we already did dmu_tx_wait() */
       
  1311 				zfs_dirent_unlock(dl);
       
  1312 				VN_RELE(ZTOV(zp));
       
  1313 				goto top;
       
  1314 			}
       
  1315 
       
  1316 			if (error == 0) {
  1311 			if (error == 0) {
  1317 				vnevent_create(ZTOV(zp), ct);
  1312 				vnevent_create(ZTOV(zp), ct);
  1318 			}
  1313 			}
  1319 		}
  1314 		}
  1320 	}
  1315 	}
  1377 	zilog_t		*zilog;
  1372 	zilog_t		*zilog;
  1378 	uint64_t	acl_obj, xattr_obj;
  1373 	uint64_t	acl_obj, xattr_obj;
  1379 	zfs_dirlock_t	*dl;
  1374 	zfs_dirlock_t	*dl;
  1380 	dmu_tx_t	*tx;
  1375 	dmu_tx_t	*tx;
  1381 	boolean_t	may_delete_now, delete_now = FALSE;
  1376 	boolean_t	may_delete_now, delete_now = FALSE;
  1382 	boolean_t	unlinked;
  1377 	boolean_t	unlinked, toobig = FALSE;
  1383 	uint64_t	txtype;
  1378 	uint64_t	txtype;
  1384 	pathname_t	*realnmp = NULL;
  1379 	pathname_t	*realnmp = NULL;
  1385 	pathname_t	realnm;
  1380 	pathname_t	realnm;
  1386 	int		error;
  1381 	int		error;
  1387 	int		zflg = ZEXISTS;
  1382 	int		zflg = ZEXISTS;
  1440 	 * allow for either case.
  1435 	 * allow for either case.
  1441 	 */
  1436 	 */
  1442 	tx = dmu_tx_create(zfsvfs->z_os);
  1437 	tx = dmu_tx_create(zfsvfs->z_os);
  1443 	dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
  1438 	dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
  1444 	dmu_tx_hold_bonus(tx, zp->z_id);
  1439 	dmu_tx_hold_bonus(tx, zp->z_id);
  1445 	if (may_delete_now)
  1440 	if (may_delete_now) {
  1446 		dmu_tx_hold_free(tx, zp->z_id, 0, DMU_OBJECT_END);
  1441 		toobig =
       
  1442 		    zp->z_phys->zp_size > zp->z_blksz * DMU_MAX_DELETEBLKCNT;
       
  1443 		/* if the file is too big, only hold_free a token amount */
       
  1444 		dmu_tx_hold_free(tx, zp->z_id, 0,
       
  1445 		    (toobig ? DMU_MAX_ACCESS : DMU_OBJECT_END));
       
  1446 	}
  1447 
  1447 
  1448 	/* are there any extended attributes? */
  1448 	/* are there any extended attributes? */
  1449 	if ((xattr_obj = zp->z_phys->zp_xattr) != 0) {
  1449 	if ((xattr_obj = zp->z_phys->zp_xattr) != 0) {
  1450 		/* XXX - do we need this if we are deleting? */
  1450 		/* XXX - do we need this if we are deleting? */
  1451 		dmu_tx_hold_bonus(tx, xattr_obj);
  1451 		dmu_tx_hold_bonus(tx, xattr_obj);
  1485 		goto out;
  1485 		goto out;
  1486 	}
  1486 	}
  1487 
  1487 
  1488 	if (unlinked) {
  1488 	if (unlinked) {
  1489 		mutex_enter(&vp->v_lock);
  1489 		mutex_enter(&vp->v_lock);
  1490 		delete_now = may_delete_now &&
  1490 		delete_now = may_delete_now && !toobig &&
  1491 		    vp->v_count == 1 && !vn_has_cached_data(vp) &&
  1491 		    vp->v_count == 1 && !vn_has_cached_data(vp) &&
  1492 		    zp->z_phys->zp_xattr == xattr_obj &&
  1492 		    zp->z_phys->zp_xattr == xattr_obj &&
  1493 		    zp->z_phys->zp_acl.z_acl_extern_obj == acl_obj;
  1493 		    zp->z_phys->zp_acl.z_acl_extern_obj == acl_obj;
  1494 		mutex_exit(&vp->v_lock);
  1494 		mutex_exit(&vp->v_lock);
  1495 	}
  1495 	}
  1531 	zfs_dirent_unlock(dl);
  1531 	zfs_dirent_unlock(dl);
  1532 
  1532 
  1533 	if (!delete_now) {
  1533 	if (!delete_now) {
  1534 		VN_RELE(vp);
  1534 		VN_RELE(vp);
  1535 	} else if (xzp) {
  1535 	} else if (xzp) {
  1536 		/* this rele delayed to prevent nesting transactions */
  1536 		/* this rele is delayed to prevent nesting transactions */
  1537 		VN_RELE(ZTOV(xzp));
  1537 		VN_RELE(ZTOV(xzp));
  1538 	}
  1538 	}
  1539 
  1539 
  1540 	ZFS_EXIT(zfsvfs);
  1540 	ZFS_EXIT(zfsvfs);
  1541 	return (error);
  1541 	return (error);
  2449 		 * XXX - Note, we are not providing any open
  2449 		 * XXX - Note, we are not providing any open
  2450 		 * mode flags here (like FNDELAY), so we may
  2450 		 * mode flags here (like FNDELAY), so we may
  2451 		 * block if there are locks present... this
  2451 		 * block if there are locks present... this
  2452 		 * should be addressed in openat().
  2452 		 * should be addressed in openat().
  2453 		 */
  2453 		 */
  2454 		do {
  2454 		/* XXX - would it be OK to generate a log record here? */
  2455 			err = zfs_freesp(zp, vap->va_size, 0, 0, FALSE);
  2455 		err = zfs_freesp(zp, vap->va_size, 0, 0, FALSE);
  2456 			/* NB: we already did dmu_tx_wait() if necessary */
       
  2457 		} while (err == ERESTART && zfsvfs->z_assign == TXG_NOWAIT);
       
  2458 		if (err) {
  2456 		if (err) {
  2459 			ZFS_EXIT(zfsvfs);
  2457 			ZFS_EXIT(zfsvfs);
  2460 			return (err);
  2458 			return (err);
  2461 		}
  2459 		}
  2462 	}
  2460 	}
  2723 		ZFS_TIME_ENCODE(&vap->va_atime, pzp->zp_atime);
  2721 		ZFS_TIME_ENCODE(&vap->va_atime, pzp->zp_atime);
  2724 
  2722 
  2725 	if (mask & AT_MTIME)
  2723 	if (mask & AT_MTIME)
  2726 		ZFS_TIME_ENCODE(&vap->va_mtime, pzp->zp_mtime);
  2724 		ZFS_TIME_ENCODE(&vap->va_mtime, pzp->zp_mtime);
  2727 
  2725 
       
  2726 	/* XXX - shouldn't this be done *before* the ATIME/MTIME checks? */
  2728 	if (mask & AT_SIZE)
  2727 	if (mask & AT_SIZE)
  2729 		zfs_time_stamper_locked(zp, CONTENT_MODIFIED, tx);
  2728 		zfs_time_stamper_locked(zp, CONTENT_MODIFIED, tx);
  2730 	else if (mask != 0)
  2729 	else if (mask != 0)
  2731 		zfs_time_stamper_locked(zp, STATE_CHANGED, tx);
  2730 		zfs_time_stamper_locked(zp, STATE_CHANGED, tx);
  2732 	/*
  2731 	/*
  4234 	int		error;
  4233 	int		error;
  4235 
  4234 
  4236 	ZFS_ENTER(zfsvfs);
  4235 	ZFS_ENTER(zfsvfs);
  4237 	ZFS_VERIFY_ZP(zp);
  4236 	ZFS_VERIFY_ZP(zp);
  4238 
  4237 
  4239 top:
       
  4240 	if (cmd != F_FREESP) {
  4238 	if (cmd != F_FREESP) {
  4241 		ZFS_EXIT(zfsvfs);
  4239 		ZFS_EXIT(zfsvfs);
  4242 		return (EINVAL);
  4240 		return (EINVAL);
  4243 	}
  4241 	}
  4244 
  4242 
  4253 	}
  4251 	}
  4254 
  4252 
  4255 	off = bfp->l_start;
  4253 	off = bfp->l_start;
  4256 	len = bfp->l_len; /* 0 means from off to end of file */
  4254 	len = bfp->l_len; /* 0 means from off to end of file */
  4257 
  4255 
  4258 	do {
  4256 	error = zfs_freesp(zp, off, len, flag, TRUE);
  4259 		error = zfs_freesp(zp, off, len, flag, TRUE);
       
  4260 		/* NB: we already did dmu_tx_wait() if necessary */
       
  4261 	} while (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT);
       
  4262 
  4257 
  4263 	ZFS_EXIT(zfsvfs);
  4258 	ZFS_EXIT(zfsvfs);
  4264 	return (error);
  4259 	return (error);
  4265 }
  4260 }
  4266 
  4261