if (error)
                goto out_trans_cancel;
 
-       error = xfs_dir_ialloc(&tp, dp, mode, 1, 0, prid, &ip);
+       error = xfs_dir_ialloc(&tp, dp, mode, 0, 0, prid, &ip);
        if (error)
                goto out_trans_cancel;
 
 }
 
 /*
- * This is called when the inode's link count goes to 0 or we are creating a
- * tmpfile via O_TMPFILE. In the case of a tmpfile, @ignore_linkcount will be
- * set to true as the link count is dropped to zero by the VFS after we've
- * created the file successfully, so we have to add it to the unlinked list
- * while the link count is non-zero.
+ * This is called when the inode's link count has gone to 0 or we are creating
+ * a tmpfile via O_TMPFILE.  The inode @ip must have nlink == 0.
  *
  * We place the on-disk inode on a list in the AGI.  It will be pulled from this
  * list when the inode is freed.
        short                   bucket_index = agino % XFS_AGI_UNLINKED_BUCKETS;
        int                     error;
 
+       ASSERT(VFS_I(ip)->i_nlink == 0);
        ASSERT(VFS_I(ip)->i_mode != 0);
        trace_xfs_iunlink(ip);
 
 
        /*
         * Prepare the tmpfile inode as if it were created through the VFS.
-        * Otherwise, the link increment paths will complain about nlink 0->1.
-        * Drop the link count as done by d_tmpfile(), complete the inode setup
-        * and flag it as linkable.
+        * Complete the inode setup and flag it as linkable.  nlink is already
+        * zero, so we can skip the drop_nlink.
         */
-       drop_nlink(VFS_I(tmpfile));
        xfs_setup_iops(tmpfile);
        xfs_finish_inode_setup(tmpfile);
        VFS_I(tmpfile)->i_state |= I_LINKABLE;
 
 
        xfs_setup_iops(ip);
 
-       if (tmpfile)
+       if (tmpfile) {
+               /*
+                * The VFS requires that any inode fed to d_tmpfile must have
+                * nlink == 1 so that it can decrement the nlink in d_tmpfile.
+                * However, we created the temp file with nlink == 0 because
+                * we're not allowed to put an inode with nlink > 0 on the
+                * unlinked list.  Therefore we have to set nlink to 1 so that
+                * d_tmpfile can immediately set it back to zero.
+                */
+               set_nlink(inode, 1);
                d_tmpfile(dentry, inode);
-       else
+       } else
                d_instantiate(dentry, inode);
 
        xfs_finish_inode_setup(ip);