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 /* Portions Copyright 2010 Robert Milkowski */
27
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/vfs.h>
35 #include <sys/vfs_opreg.h>
36 #include <sys/vnode.h>
37 #include <sys/file.h>
38 #include <sys/stat.h>
39 #include <sys/kmem.h>
40 #include <sys/taskq.h>
41 #include <sys/uio.h>
42 #include <sys/vmsystm.h>
43 #include <sys/atomic.h>
44 #include <sys/vm.h>
1624 */
1625 obj = zp->z_id;
1626 tx = dmu_tx_create(zfsvfs->z_os);
1627 dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
1628 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
1629 zfs_sa_upgrade_txholds(tx, zp);
1630 zfs_sa_upgrade_txholds(tx, dzp);
1631 if (may_delete_now) {
1632 toobig =
1633 zp->z_size > zp->z_blksz * DMU_MAX_DELETEBLKCNT;
1634 /* if the file is too big, only hold_free a token amount */
1635 dmu_tx_hold_free(tx, zp->z_id, 0,
1636 (toobig ? DMU_MAX_ACCESS : DMU_OBJECT_END));
1637 }
1638
1639 /* are there any extended attributes? */
1640 error = sa_lookup(zp->z_sa_hdl, SA_ZPL_XATTR(zfsvfs),
1641 &xattr_obj, sizeof (xattr_obj));
1642 if (error == 0 && xattr_obj) {
1643 error = zfs_zget(zfsvfs, xattr_obj, &xzp);
1644 ASSERT3U(error, ==, 0);
1645 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
1646 dmu_tx_hold_sa(tx, xzp->z_sa_hdl, B_FALSE);
1647 }
1648
1649 mutex_enter(&zp->z_lock);
1650 if ((acl_obj = zfs_external_acl(zp)) != 0 && may_delete_now)
1651 dmu_tx_hold_free(tx, acl_obj, 0, DMU_OBJECT_END);
1652 mutex_exit(&zp->z_lock);
1653
1654 /* charge as an update -- would be nice not to charge at all */
1655 dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
1656
1657 error = dmu_tx_assign(tx, TXG_NOWAIT);
1658 if (error) {
1659 zfs_dirent_unlock(dl);
1660 VN_RELE(vp);
1661 if (xzp)
1662 VN_RELE(ZTOV(xzp));
1663 if (error == ERESTART) {
1664 dmu_tx_wait(tx);
1702
1703 if (delete_now) {
1704 if (xattr_obj_unlinked) {
1705 ASSERT3U(xzp->z_links, ==, 2);
1706 mutex_enter(&xzp->z_lock);
1707 xzp->z_unlinked = 1;
1708 xzp->z_links = 0;
1709 error = sa_update(xzp->z_sa_hdl, SA_ZPL_LINKS(zfsvfs),
1710 &xzp->z_links, sizeof (xzp->z_links), tx);
1711 ASSERT3U(error, ==, 0);
1712 mutex_exit(&xzp->z_lock);
1713 zfs_unlinked_add(xzp, tx);
1714
1715 if (zp->z_is_sa)
1716 error = sa_remove(zp->z_sa_hdl,
1717 SA_ZPL_XATTR(zfsvfs), tx);
1718 else
1719 error = sa_update(zp->z_sa_hdl,
1720 SA_ZPL_XATTR(zfsvfs), &null_xattr,
1721 sizeof (uint64_t), tx);
1722 ASSERT3U(error, ==, 0);
1723 }
1724 mutex_enter(&vp->v_lock);
1725 vp->v_count--;
1726 ASSERT3U(vp->v_count, ==, 0);
1727 mutex_exit(&vp->v_lock);
1728 mutex_exit(&zp->z_lock);
1729 zfs_znode_delete(zp, tx);
1730 } else if (unlinked) {
1731 mutex_exit(&zp->z_lock);
1732 zfs_unlinked_add(zp, tx);
1733 }
1734
1735 txtype = TX_REMOVE;
1736 if (flags & FIGNORECASE)
1737 txtype |= TX_CI;
1738 zfs_log_remove(zilog, tx, txtype, dzp, name, obj);
1739
1740 dmu_tx_commit(tx);
1741 out:
1742 if (realnmp)
1743 pn_free(realnmp);
1744
1745 zfs_dirent_unlock(dl);
1746
3079 }
3080 if (!(mask & AT_MODE)) {
3081 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs),
3082 NULL, &new_mode, sizeof (new_mode));
3083 new_mode = zp->z_mode;
3084 }
3085 err = zfs_acl_chown_setattr(zp);
3086 ASSERT(err == 0);
3087 if (attrzp) {
3088 err = zfs_acl_chown_setattr(attrzp);
3089 ASSERT(err == 0);
3090 }
3091 }
3092
3093 if (mask & AT_MODE) {
3094 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs), NULL,
3095 &new_mode, sizeof (new_mode));
3096 zp->z_mode = new_mode;
3097 ASSERT3U((uintptr_t)aclp, !=, NULL);
3098 err = zfs_aclset_common(zp, aclp, cr, tx);
3099 ASSERT3U(err, ==, 0);
3100 if (zp->z_acl_cached)
3101 zfs_acl_free(zp->z_acl_cached);
3102 zp->z_acl_cached = aclp;
3103 aclp = NULL;
3104 }
3105
3106
3107 if (mask & AT_ATIME) {
3108 ZFS_TIME_ENCODE(&vap->va_atime, zp->z_atime);
3109 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zfsvfs), NULL,
3110 &zp->z_atime, sizeof (zp->z_atime));
3111 }
3112
3113 if (mask & AT_MTIME) {
3114 ZFS_TIME_ENCODE(&vap->va_mtime, mtime);
3115 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL,
3116 mtime, sizeof (mtime));
3117 }
3118
3119 /* XXX - shouldn't this be done *before* the ATIME/MTIME checks? */
3602 if (error == ERESTART) {
3603 dmu_tx_wait(tx);
3604 dmu_tx_abort(tx);
3605 goto top;
3606 }
3607 dmu_tx_abort(tx);
3608 ZFS_EXIT(zfsvfs);
3609 return (error);
3610 }
3611
3612 if (tzp) /* Attempt to remove the existing target */
3613 error = zfs_link_destroy(tdl, tzp, tx, zflg, NULL);
3614
3615 if (error == 0) {
3616 error = zfs_link_create(tdl, szp, tx, ZRENAMING);
3617 if (error == 0) {
3618 szp->z_pflags |= ZFS_AV_MODIFIED;
3619
3620 error = sa_update(szp->z_sa_hdl, SA_ZPL_FLAGS(zfsvfs),
3621 (void *)&szp->z_pflags, sizeof (uint64_t), tx);
3622 ASSERT3U(error, ==, 0);
3623
3624 error = zfs_link_destroy(sdl, szp, tx, ZRENAMING, NULL);
3625 if (error == 0) {
3626 zfs_log_rename(zilog, tx, TX_RENAME |
3627 (flags & FIGNORECASE ? TX_CI : 0), sdzp,
3628 sdl->dl_name, tdzp, tdl->dl_name, szp);
3629
3630 /*
3631 * Update path information for the target vnode
3632 */
3633 vn_renamepath(tdvp, ZTOV(szp), tnm,
3634 strlen(tnm));
3635 } else {
3636 /*
3637 * At this point, we have successfully created
3638 * the target name, but have failed to remove
3639 * the source name. Since the create was done
3640 * with the ZRENAMING flag, there are
3641 * complications; for one, the link count is
3642 * wrong. The easiest way to deal with this
|
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
28
29 /* Portions Copyright 2007 Jeremy Teo */
30 /* Portions Copyright 2010 Robert Milkowski */
31
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/time.h>
35 #include <sys/systm.h>
36 #include <sys/sysmacros.h>
37 #include <sys/resource.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/stat.h>
43 #include <sys/kmem.h>
44 #include <sys/taskq.h>
45 #include <sys/uio.h>
46 #include <sys/vmsystm.h>
47 #include <sys/atomic.h>
48 #include <sys/vm.h>
1628 */
1629 obj = zp->z_id;
1630 tx = dmu_tx_create(zfsvfs->z_os);
1631 dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
1632 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
1633 zfs_sa_upgrade_txholds(tx, zp);
1634 zfs_sa_upgrade_txholds(tx, dzp);
1635 if (may_delete_now) {
1636 toobig =
1637 zp->z_size > zp->z_blksz * DMU_MAX_DELETEBLKCNT;
1638 /* if the file is too big, only hold_free a token amount */
1639 dmu_tx_hold_free(tx, zp->z_id, 0,
1640 (toobig ? DMU_MAX_ACCESS : DMU_OBJECT_END));
1641 }
1642
1643 /* are there any extended attributes? */
1644 error = sa_lookup(zp->z_sa_hdl, SA_ZPL_XATTR(zfsvfs),
1645 &xattr_obj, sizeof (xattr_obj));
1646 if (error == 0 && xattr_obj) {
1647 error = zfs_zget(zfsvfs, xattr_obj, &xzp);
1648 ASSERT0(error);
1649 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
1650 dmu_tx_hold_sa(tx, xzp->z_sa_hdl, B_FALSE);
1651 }
1652
1653 mutex_enter(&zp->z_lock);
1654 if ((acl_obj = zfs_external_acl(zp)) != 0 && may_delete_now)
1655 dmu_tx_hold_free(tx, acl_obj, 0, DMU_OBJECT_END);
1656 mutex_exit(&zp->z_lock);
1657
1658 /* charge as an update -- would be nice not to charge at all */
1659 dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
1660
1661 error = dmu_tx_assign(tx, TXG_NOWAIT);
1662 if (error) {
1663 zfs_dirent_unlock(dl);
1664 VN_RELE(vp);
1665 if (xzp)
1666 VN_RELE(ZTOV(xzp));
1667 if (error == ERESTART) {
1668 dmu_tx_wait(tx);
1706
1707 if (delete_now) {
1708 if (xattr_obj_unlinked) {
1709 ASSERT3U(xzp->z_links, ==, 2);
1710 mutex_enter(&xzp->z_lock);
1711 xzp->z_unlinked = 1;
1712 xzp->z_links = 0;
1713 error = sa_update(xzp->z_sa_hdl, SA_ZPL_LINKS(zfsvfs),
1714 &xzp->z_links, sizeof (xzp->z_links), tx);
1715 ASSERT3U(error, ==, 0);
1716 mutex_exit(&xzp->z_lock);
1717 zfs_unlinked_add(xzp, tx);
1718
1719 if (zp->z_is_sa)
1720 error = sa_remove(zp->z_sa_hdl,
1721 SA_ZPL_XATTR(zfsvfs), tx);
1722 else
1723 error = sa_update(zp->z_sa_hdl,
1724 SA_ZPL_XATTR(zfsvfs), &null_xattr,
1725 sizeof (uint64_t), tx);
1726 ASSERT0(error);
1727 }
1728 mutex_enter(&vp->v_lock);
1729 vp->v_count--;
1730 ASSERT0(vp->v_count);
1731 mutex_exit(&vp->v_lock);
1732 mutex_exit(&zp->z_lock);
1733 zfs_znode_delete(zp, tx);
1734 } else if (unlinked) {
1735 mutex_exit(&zp->z_lock);
1736 zfs_unlinked_add(zp, tx);
1737 }
1738
1739 txtype = TX_REMOVE;
1740 if (flags & FIGNORECASE)
1741 txtype |= TX_CI;
1742 zfs_log_remove(zilog, tx, txtype, dzp, name, obj);
1743
1744 dmu_tx_commit(tx);
1745 out:
1746 if (realnmp)
1747 pn_free(realnmp);
1748
1749 zfs_dirent_unlock(dl);
1750
3083 }
3084 if (!(mask & AT_MODE)) {
3085 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs),
3086 NULL, &new_mode, sizeof (new_mode));
3087 new_mode = zp->z_mode;
3088 }
3089 err = zfs_acl_chown_setattr(zp);
3090 ASSERT(err == 0);
3091 if (attrzp) {
3092 err = zfs_acl_chown_setattr(attrzp);
3093 ASSERT(err == 0);
3094 }
3095 }
3096
3097 if (mask & AT_MODE) {
3098 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs), NULL,
3099 &new_mode, sizeof (new_mode));
3100 zp->z_mode = new_mode;
3101 ASSERT3U((uintptr_t)aclp, !=, NULL);
3102 err = zfs_aclset_common(zp, aclp, cr, tx);
3103 ASSERT0(err);
3104 if (zp->z_acl_cached)
3105 zfs_acl_free(zp->z_acl_cached);
3106 zp->z_acl_cached = aclp;
3107 aclp = NULL;
3108 }
3109
3110
3111 if (mask & AT_ATIME) {
3112 ZFS_TIME_ENCODE(&vap->va_atime, zp->z_atime);
3113 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zfsvfs), NULL,
3114 &zp->z_atime, sizeof (zp->z_atime));
3115 }
3116
3117 if (mask & AT_MTIME) {
3118 ZFS_TIME_ENCODE(&vap->va_mtime, mtime);
3119 SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL,
3120 mtime, sizeof (mtime));
3121 }
3122
3123 /* XXX - shouldn't this be done *before* the ATIME/MTIME checks? */
3606 if (error == ERESTART) {
3607 dmu_tx_wait(tx);
3608 dmu_tx_abort(tx);
3609 goto top;
3610 }
3611 dmu_tx_abort(tx);
3612 ZFS_EXIT(zfsvfs);
3613 return (error);
3614 }
3615
3616 if (tzp) /* Attempt to remove the existing target */
3617 error = zfs_link_destroy(tdl, tzp, tx, zflg, NULL);
3618
3619 if (error == 0) {
3620 error = zfs_link_create(tdl, szp, tx, ZRENAMING);
3621 if (error == 0) {
3622 szp->z_pflags |= ZFS_AV_MODIFIED;
3623
3624 error = sa_update(szp->z_sa_hdl, SA_ZPL_FLAGS(zfsvfs),
3625 (void *)&szp->z_pflags, sizeof (uint64_t), tx);
3626 ASSERT0(error);
3627
3628 error = zfs_link_destroy(sdl, szp, tx, ZRENAMING, NULL);
3629 if (error == 0) {
3630 zfs_log_rename(zilog, tx, TX_RENAME |
3631 (flags & FIGNORECASE ? TX_CI : 0), sdzp,
3632 sdl->dl_name, tdzp, tdl->dl_name, szp);
3633
3634 /*
3635 * Update path information for the target vnode
3636 */
3637 vn_renamepath(tdvp, ZTOV(szp), tnm,
3638 strlen(tnm));
3639 } else {
3640 /*
3641 * At this point, we have successfully created
3642 * the target name, but have failed to remove
3643 * the source name. Since the create was done
3644 * with the ZRENAMING flag, there are
3645 * complications; for one, the link count is
3646 * wrong. The easiest way to deal with this
|