@@ -2319,8 +2319,10 @@ int nfs_unlink(struct inode *dir, struct dentry *dentry)
spin_unlock(&dentry->d_lock);
/* Start asynchronous writeout of the inode */
write_inode_now(d_inode(dentry), 0);
- error = nfs_sillyrename(dir, dentry);
- goto out;
+ if (!(NFS_I(d_inode(dentry))->flags & NFS_INO_PRESERVE_UNLINKED)) {
+ error = nfs_sillyrename(dir, dentry);
+ goto out;
+ }
}
if (!d_unhashed(dentry)) {
__d_drop(dentry);
@@ -2727,6 +2727,8 @@ static int _nfs4_proc_open(struct nfs4_opendata *data,
nfs4_sequence_free_slot(&o_res->seq_res);
nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, NULL);
}
+ if (o_res->rflags & NFS4_OPEN_RESULT_PRESERVE_UNLINKED)
+ set_bit(NFS_INO_PRESERVE_UNLINKED, &NFS_I(dir)->flags);
return 0;
}
@@ -297,6 +297,7 @@ struct nfs4_copy_state {
#define NFS_INO_LAYOUTCOMMITTING (10) /* layoutcommit inflight */
#define NFS_INO_LAYOUTSTATS (11) /* layoutstats inflight */
#define NFS_INO_ODIRECT (12) /* I/O setting is O_DIRECT */
+#define NFS_INO_PRESERVE_UNLINKED (13) /* preserve file if removed while open */
static inline struct nfs_inode *NFS_I(const struct inode *inode)
{
@@ -46,6 +46,7 @@
#define NFS4_OPEN_RESULT_CONFIRM 0x0002
#define NFS4_OPEN_RESULT_LOCKTYPE_POSIX 0x0004
#define NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK 0x0020
+#define NFS4_OPEN_RESULT_PRESERVE_UNLINKED 0x0008
#define NFS4_SHARE_ACCESS_MASK 0x000F
#define NFS4_SHARE_ACCESS_READ 0x0001