* Link zp into dl. Can fail in the following cases : * - if zp has been unlinked. * - if the number of entries with the same hash (aka. colliding entries) * exceed the capacity of a leaf-block of fatzap and splitting of the * leaf-block does not help. */
| 789 | * leaf-block does not help. |
| 790 | */ |
| 791 | int |
| 792 | zfs_link_create(zfs_dirlock_t *dl, znode_t *zp, dmu_tx_t *tx, int flag) |
| 793 | { |
| 794 | znode_t *dzp = dl->dl_dzp; |
| 795 | zfsvfs_t *zfsvfs = ZTOZSB(zp); |
| 796 | uint64_t value; |
| 797 | int zp_is_dir = S_ISDIR(ZTOI(zp)->i_mode); |
| 798 | sa_bulk_attr_t bulk[5]; |
| 799 | uint64_t mtime[2], ctime[2]; |
| 800 | uint64_t links; |
| 801 | int count = 0; |
| 802 | int error; |
| 803 | |
| 804 | mutex_enter(&zp->z_lock); |
| 805 | |
| 806 | if (!(flag & ZRENAMING)) { |
| 807 | if (zp->z_unlinked) { /* no new links to unlinked zp */ |
| 808 | ASSERT(!(flag & (ZNEW | ZEXISTS))); |
| 809 | mutex_exit(&zp->z_lock); |
| 810 | return (SET_ERROR(ENOENT)); |
| 811 | } |
| 812 | if (!(flag & ZNEW)) { |
| 813 | /* |
| 814 | * ZNEW nodes come from zfs_mknode() where the link |
| 815 | * count has already been initialised |
| 816 | */ |
| 817 | inc_nlink(ZTOI(zp)); |
| 818 | links = ZTOI(zp)->i_nlink; |
| 819 | SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_LINKS(zfsvfs), |
| 820 | NULL, &links, sizeof (links)); |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | value = zfs_dirent(zp, zp->z_mode); |
| 825 | error = zap_add(ZTOZSB(zp)->z_os, dzp->z_id, dl->dl_name, 8, 1, |
| 826 | &value, tx); |
| 827 | |
| 828 | /* |
| 829 | * zap_add could fail to add the entry if it exceeds the capacity of the |
| 830 | * leaf-block and zap_leaf_split() failed to help. |
| 831 | * The caller of this routine is responsible for failing the transaction |
| 832 | * which will rollback the SA updates done above. |
| 833 | */ |
| 834 | if (error != 0) { |
| 835 | if (!(flag & ZRENAMING) && !(flag & ZNEW)) |
| 836 | drop_nlink(ZTOI(zp)); |
| 837 | mutex_exit(&zp->z_lock); |
| 838 | return (error); |
| 839 | } |
| 840 | |
| 841 | SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_PARENT(zfsvfs), NULL, |
| 842 | &dzp->z_id, sizeof (dzp->z_id)); |
| 843 | SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL, |
| 844 | &zp->z_pflags, sizeof (zp->z_pflags)); |
| 845 | |
| 846 | if (!(flag & ZNEW)) { |
| 847 | SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, |
| 848 | ctime, sizeof (ctime)); |
no test coverage detected