···963963 mutex_unlock(&dentry->d_inode->i_mutex);964964}965965966966+/*967967+ * Gathered writes: If another process is currently writing to the file,968968+ * there's a high chance this is another nfsd (triggered by a bulk write969969+ * from a client's biod). Rather than syncing the file with each write970970+ * request, we sleep for 10 msec.971971+ *972972+ * I don't know if this roughly approximates C. Juszak's idea of973973+ * gathered writes, but it's a nice and simple solution (IMHO), and it974974+ * seems to work:-)975975+ *976976+ * Note: we do this only in the NFSv2 case, since v3 and higher have a977977+ * better tool (separate unstable writes and commits) for solving this978978+ * problem.979979+ */980980+static int wait_for_concurrent_writes(struct file *file)981981+{982982+ struct inode *inode = file->f_path.dentry->d_inode;983983+ static ino_t last_ino;984984+ static dev_t last_dev;985985+ int err = 0;986986+987987+ if (atomic_read(&inode->i_writecount) > 1988988+ || (last_ino == inode->i_ino && last_dev == inode->i_sb->s_dev)) {989989+ dprintk("nfsd: write defer %d\n", task_pid_nr(current));990990+ msleep(10);991991+ dprintk("nfsd: write resume %d\n", task_pid_nr(current));992992+ }993993+994994+ if (inode->i_state & I_DIRTY) {995995+ dprintk("nfsd: write sync %d\n", task_pid_nr(current));996996+ err = nfsd_sync(file);997997+ }998998+ last_ino = inode->i_ino;999999+ last_dev = inode->i_sb->s_dev;10001000+ return err;10011001+}10021002+9661003static __be329671004nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,9681005 loff_t offset, struct kvec *vec, int vlen,···10631026 if (host_err >= 0 && (inode->i_mode & (S_ISUID | S_ISGID)))10641027 kill_suid(dentry);1065102810661066- if (host_err >= 0 && stable && use_wgather) {10671067- static ino_t last_ino;10681068- static dev_t last_dev;10691069-10701070- /*10711071- * Gathered writes: If another process is currently10721072- * writing to the file, there's a high chance10731073- * this is another nfsd (triggered by a bulk write10741074- * from a client's biod). Rather than syncing the10751075- * file with each write request, we sleep for 10 msec.10761076- *10771077- * I don't know if this roughly approximates10781078- * C. Juszak's idea of gathered writes, but it's a10791079- * nice and simple solution (IMHO), and it seems to10801080- * work:-)10811081- */10821082- if (atomic_read(&inode->i_writecount) > 110831083- || (last_ino == inode->i_ino && last_dev == inode->i_sb->s_dev)) {10841084- dprintk("nfsd: write defer %d\n", task_pid_nr(current));10851085- msleep(10);10861086- dprintk("nfsd: write resume %d\n", task_pid_nr(current));10871087- }10881088-10891089- if (inode->i_state & I_DIRTY) {10901090- dprintk("nfsd: write sync %d\n", task_pid_nr(current));10911091- host_err=nfsd_sync(file);10921092- }10931093- last_ino = inode->i_ino;10941094- last_dev = inode->i_sb->s_dev;10951095- }10291029+ if (host_err >= 0 && stable && use_wgather)10301030+ host_err = wait_for_concurrent_writes(file);1096103110971032 dprintk("nfsd: write complete host_err=%d\n", host_err);10981033 if (host_err >= 0)