+ error = sa_lookup(zp->z_sa_hdl, SA_ZPL_PARENT(
+ ZTOZSB(zp)), &parent, sizeof (parent));
+ if (error)
+ return (error);
+
+ /*
+ * Cache the lookup on the parent file znode as
+ * zp->z_xattr_parent and hold a reference. This
+ * effectively pins the parent in memory until all
+ * child xattr znodes have been destroyed and
+ * release their references in zfs_inode_destroy().
+ */
+ error = zfs_zget(ZTOZSB(zp), parent, &check_zp);
+ if (error)
+ return (error);
+
+ rw_enter(&zp->z_xattr_lock, RW_WRITER);
+ if (zp->z_xattr_parent == NULL)
+ zp->z_xattr_parent = check_zp;
+ rw_exit(&zp->z_xattr_lock);
+ }