| 643 | } |
| 644 | |
| 645 | void |
| 646 | zfs_rmnode(znode_t *zp) |
| 647 | { |
| 648 | zfsvfs_t *zfsvfs = ZTOZSB(zp); |
| 649 | objset_t *os = zfsvfs->z_os; |
| 650 | znode_t *xzp = NULL; |
| 651 | dmu_tx_t *tx; |
| 652 | uint64_t acl_obj; |
| 653 | uint64_t xattr_obj; |
| 654 | uint64_t links; |
| 655 | int error; |
| 656 | |
| 657 | ASSERT(ZTOI(zp)->i_nlink == 0); |
| 658 | ASSERT(atomic_read(&ZTOI(zp)->i_count) == 0); |
| 659 | |
| 660 | /* |
| 661 | * If this is an attribute directory, purge its contents. |
| 662 | */ |
| 663 | if (S_ISDIR(ZTOI(zp)->i_mode) && (zp->z_pflags & ZFS_XATTR)) { |
| 664 | if (zfs_purgedir(zp) != 0) { |
| 665 | /* |
| 666 | * Not enough space to delete some xattrs. |
| 667 | * Leave it in the unlinked set. |
| 668 | */ |
| 669 | zfs_znode_dmu_fini(zp); |
| 670 | |
| 671 | return; |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | /* |
| 676 | * Free up all the data in the file. We don't do this for directories |
| 677 | * because we need truncate and remove to be in the same tx, like in |
| 678 | * zfs_znode_delete(). Otherwise, if we crash here we'll end up with |
| 679 | * an inconsistent truncated zap object in the delete queue. Note a |
| 680 | * truncated file is harmless since it only contains user data. |
| 681 | */ |
| 682 | if (S_ISREG(ZTOI(zp)->i_mode)) { |
| 683 | error = dmu_free_long_range(os, zp->z_id, 0, DMU_OBJECT_END); |
| 684 | if (error) { |
| 685 | /* |
| 686 | * Not enough space or we were interrupted by unmount. |
| 687 | * Leave the file in the unlinked set. |
| 688 | */ |
| 689 | zfs_znode_dmu_fini(zp); |
| 690 | return; |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | /* |
| 695 | * If the file has extended attributes, we're going to unlink |
| 696 | * the xattr dir. |
| 697 | */ |
| 698 | error = sa_lookup(zp->z_sa_hdl, SA_ZPL_XATTR(zfsvfs), |
| 699 | &xattr_obj, sizeof (xattr_obj)); |
| 700 | if (error == 0 && xattr_obj) { |
| 701 | error = zfs_zget(zfsvfs, xattr_obj, &xzp); |
| 702 | ASSERT(error == 0); |
no test coverage detected