* COW writes may allocate delalloc space or convert unwritten COW
         * extents, so we need to make sure to take the lock exclusively here.
         */
-       if (xfs_is_cow_inode(ip) && is_write) {
-               /*
-                * FIXME: It could still overwrite on unshared extents and not
-                * need allocation.
-                */
-               if (flags & IOMAP_NOWAIT)
-                       return -EAGAIN;
+       if (xfs_is_cow_inode(ip) && is_write)
                mode = XFS_ILOCK_EXCL;
-       }
 
        /*
         * Extents not yet cached requires exclusive access, don't block.  This
        if (offset + length > i_size_read(inode))
                iomap_flags |= IOMAP_F_DIRTY;
 
-       /*
-        * Lock the inode in the manner required for the specified operation and
-        * check for as many conditions that would result in blocking as
-        * possible. This removes most of the non-blocking checks from the
-        * mapping code below.
-        */
        error = xfs_ilock_for_iomap(ip, flags, &lockmode);
        if (error)
                return error;
        if (error)
                goto out_unlock;
 
-       /*
-        * Break shared extents if necessary. Checks for non-blocking IO have
-        * been done up front, so we don't need to do them here.
-        */
        if (imap_needs_cow(ip, flags, &imap, nimaps)) {
+               error = -EAGAIN;
+               if (flags & IOMAP_NOWAIT)
+                       goto out_unlock;
+
                /* may drop and re-acquire the ilock */
                error = xfs_reflink_allocate_cow(ip, &imap, &cmap, &shared,
                                &lockmode, flags & IOMAP_DIRECT);