Skip to content

Commit f296bfd

Browse files
committed
Merge tag 'nfs-for-5.12-2' of git://git.linux-nfs.org/projects/anna/linux-nfs
Pull NFS client bugfixes from Anna Schumaker: "These are mostly fixes for issues discovered at the recent NFS bakeathon: - Fix PNFS_FLEXFILE_LAYOUT kconfig so it is possible to build into the kernel - Correct size calculationn for create reply length - Set memalloc_nofs_save() for sync tasks to prevent deadlocks - Don't revalidate directory permissions on lookup failure - Don't clear inode cache when lookup fails - Change functions to use nfs_set_cache_invalid() for proper delegation handling - Fix return value of _nfs4_get_security_label() - Return an error when attempting to remove system.nfs4_acl" * tag 'nfs-for-5.12-2' of git://git.linux-nfs.org/projects/anna/linux-nfs: nfs: we don't support removing system.nfs4_acl NFSv4.2: fix return value of _nfs4_get_security_label() NFS: Fix open coded versions of nfs_set_cache_invalid() in NFSv4 NFS: Fix open coded versions of nfs_set_cache_invalid() NFS: Clean up function nfs_mark_dir_for_revalidate() NFS: Don't gratuitously clear the inode cache when lookup failed NFS: Don't revalidate the directory permissions on a lookup failure SUNRPC: Set memalloc_nofs_save() for sync tasks NFS: Correct size calculation for create reply length nfs: fix PNFS_FLEXFILE_LAYOUT Kconfig default
2 parents b6b8aa2 + 4f8be1f commit f296bfd

10 files changed

Lines changed: 76 additions & 61 deletions

File tree

fs/nfs/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ config PNFS_BLOCK
127127
config PNFS_FLEXFILE_LAYOUT
128128
tristate
129129
depends on NFS_V4_1 && NFS_V3
130-
default m
130+
default NFS_V4
131131

132132
config NFS_V4_1_IMPLEMENTATION_ID_DOMAIN
133133
string "NFSv4.1 Implementation ID Domain"

fs/nfs/dir.c

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ static struct nfs_open_dir_context *alloc_nfs_open_dir_context(struct inode *dir
8181
spin_lock(&dir->i_lock);
8282
if (list_empty(&nfsi->open_files) &&
8383
(nfsi->cache_validity & NFS_INO_DATA_INVAL_DEFER))
84-
nfsi->cache_validity |= NFS_INO_INVALID_DATA |
85-
NFS_INO_REVAL_FORCED;
84+
nfs_set_cache_invalid(dir,
85+
NFS_INO_INVALID_DATA |
86+
NFS_INO_REVAL_FORCED);
8687
list_add(&ctx->list, &nfsi->open_files);
8788
spin_unlock(&dir->i_lock);
8889
return ctx;
@@ -1401,6 +1402,13 @@ int nfs_lookup_verify_inode(struct inode *inode, unsigned int flags)
14011402
goto out;
14021403
}
14031404

1405+
static void nfs_mark_dir_for_revalidate(struct inode *inode)
1406+
{
1407+
spin_lock(&inode->i_lock);
1408+
nfs_set_cache_invalid(inode, NFS_INO_REVAL_PAGECACHE);
1409+
spin_unlock(&inode->i_lock);
1410+
}
1411+
14041412
/*
14051413
* We judge how long we want to trust negative
14061414
* dentries by looking at the parent inode mtime.
@@ -1435,19 +1443,14 @@ nfs_lookup_revalidate_done(struct inode *dir, struct dentry *dentry,
14351443
__func__, dentry);
14361444
return 1;
14371445
case 0:
1438-
nfs_mark_for_revalidate(dir);
1439-
if (inode && S_ISDIR(inode->i_mode)) {
1440-
/* Purge readdir caches. */
1441-
nfs_zap_caches(inode);
1442-
/*
1443-
* We can't d_drop the root of a disconnected tree:
1444-
* its d_hash is on the s_anon list and d_drop() would hide
1445-
* it from shrink_dcache_for_unmount(), leading to busy
1446-
* inodes on unmount and further oopses.
1447-
*/
1448-
if (IS_ROOT(dentry))
1449-
return 1;
1450-
}
1446+
/*
1447+
* We can't d_drop the root of a disconnected tree:
1448+
* its d_hash is on the s_anon list and d_drop() would hide
1449+
* it from shrink_dcache_for_unmount(), leading to busy
1450+
* inodes on unmount and further oopses.
1451+
*/
1452+
if (inode && IS_ROOT(dentry))
1453+
return 1;
14511454
dfprintk(LOOKUPCACHE, "NFS: %s(%pd2) is invalid\n",
14521455
__func__, dentry);
14531456
return 0;
@@ -1525,6 +1528,13 @@ nfs_lookup_revalidate_dentry(struct inode *dir, struct dentry *dentry,
15251528
nfs_free_fattr(fattr);
15261529
nfs_free_fhandle(fhandle);
15271530
nfs4_label_free(label);
1531+
1532+
/*
1533+
* If the lookup failed despite the dentry change attribute being
1534+
* a match, then we should revalidate the directory cache.
1535+
*/
1536+
if (!ret && nfs_verify_change_attribute(dir, dentry->d_time))
1537+
nfs_mark_dir_for_revalidate(dir);
15281538
return nfs_lookup_revalidate_done(dir, dentry, inode, ret);
15291539
}
15301540

@@ -1567,7 +1577,7 @@ nfs_do_lookup_revalidate(struct inode *dir, struct dentry *dentry,
15671577
error = nfs_lookup_verify_inode(inode, flags);
15681578
if (error) {
15691579
if (error == -ESTALE)
1570-
nfs_zap_caches(dir);
1580+
nfs_mark_dir_for_revalidate(dir);
15711581
goto out_bad;
15721582
}
15731583
nfs_advise_use_readdirplus(dir);
@@ -1691,10 +1701,9 @@ static void nfs_drop_nlink(struct inode *inode)
16911701
if (inode->i_nlink > 0)
16921702
drop_nlink(inode);
16931703
NFS_I(inode)->attr_gencount = nfs_inc_attr_generation_counter();
1694-
NFS_I(inode)->cache_validity |= NFS_INO_INVALID_CHANGE
1695-
| NFS_INO_INVALID_CTIME
1696-
| NFS_INO_INVALID_OTHER
1697-
| NFS_INO_REVAL_FORCED;
1704+
nfs_set_cache_invalid(
1705+
inode, NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_CTIME |
1706+
NFS_INO_INVALID_OTHER | NFS_INO_REVAL_FORCED);
16981707
spin_unlock(&inode->i_lock);
16991708
}
17001709

@@ -1706,7 +1715,7 @@ static void nfs_dentry_iput(struct dentry *dentry, struct inode *inode)
17061715
{
17071716
if (S_ISDIR(inode->i_mode))
17081717
/* drop any readdir cache as it could easily be old */
1709-
NFS_I(inode)->cache_validity |= NFS_INO_INVALID_DATA;
1718+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
17101719

17111720
if (dentry->d_flags & DCACHE_NFSFS_RENAMED) {
17121721
nfs_complete_unlink(dentry, inode);
@@ -2064,7 +2073,6 @@ nfs_add_or_obtain(struct dentry *dentry, struct nfs_fh *fhandle,
20642073
dput(parent);
20652074
return d;
20662075
out_error:
2067-
nfs_mark_for_revalidate(dir);
20682076
d = ERR_PTR(error);
20692077
goto out;
20702078
}
@@ -2473,9 +2481,9 @@ int nfs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
24732481
if (error == 0) {
24742482
spin_lock(&old_inode->i_lock);
24752483
NFS_I(old_inode)->attr_gencount = nfs_inc_attr_generation_counter();
2476-
NFS_I(old_inode)->cache_validity |= NFS_INO_INVALID_CHANGE
2477-
| NFS_INO_INVALID_CTIME
2478-
| NFS_INO_REVAL_FORCED;
2484+
nfs_set_cache_invalid(old_inode, NFS_INO_INVALID_CHANGE |
2485+
NFS_INO_INVALID_CTIME |
2486+
NFS_INO_REVAL_FORCED);
24792487
spin_unlock(&old_inode->i_lock);
24802488
}
24812489
out:

fs/nfs/inode.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static bool nfs_has_xattr_cache(const struct nfs_inode *nfsi)
207207
}
208208
#endif
209209

210-
static void nfs_set_cache_invalid(struct inode *inode, unsigned long flags)
210+
void nfs_set_cache_invalid(struct inode *inode, unsigned long flags)
211211
{
212212
struct nfs_inode *nfsi = NFS_I(inode);
213213
bool have_delegation = NFS_PROTO(inode)->have_delegation(inode, FMODE_READ);
@@ -229,6 +229,7 @@ static void nfs_set_cache_invalid(struct inode *inode, unsigned long flags)
229229
if (flags & NFS_INO_INVALID_DATA)
230230
nfs_fscache_invalidate(inode);
231231
}
232+
EXPORT_SYMBOL_GPL(nfs_set_cache_invalid);
232233

233234
/*
234235
* Invalidate the local caches
@@ -1067,8 +1068,8 @@ void nfs_inode_attach_open_context(struct nfs_open_context *ctx)
10671068
spin_lock(&inode->i_lock);
10681069
if (list_empty(&nfsi->open_files) &&
10691070
(nfsi->cache_validity & NFS_INO_DATA_INVAL_DEFER))
1070-
nfsi->cache_validity |= NFS_INO_INVALID_DATA |
1071-
NFS_INO_REVAL_FORCED;
1071+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA |
1072+
NFS_INO_REVAL_FORCED);
10721073
list_add_tail_rcu(&ctx->list, &nfsi->open_files);
10731074
spin_unlock(&inode->i_lock);
10741075
}

fs/nfs/internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ extern int nfs_write_inode(struct inode *, struct writeback_control *);
411411
extern int nfs_drop_inode(struct inode *);
412412
extern void nfs_clear_inode(struct inode *);
413413
extern void nfs_evict_inode(struct inode *);
414-
void nfs_zap_acl_cache(struct inode *inode);
414+
extern void nfs_zap_acl_cache(struct inode *inode);
415+
extern void nfs_set_cache_invalid(struct inode *inode, unsigned long flags);
415416
extern bool nfs_check_cache_invalid(struct inode *, unsigned long);
416417
extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);
417418
extern int nfs_wait_atomic_killable(atomic_t *p, unsigned int mode);

fs/nfs/nfs3xdr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#define NFS3_pagepad_sz (1) /* Page padding */
3737
#define NFS3_fhandle_sz (1+16)
3838
#define NFS3_fh_sz (NFS3_fhandle_sz) /* shorthand */
39+
#define NFS3_post_op_fh_sz (1+NFS3_fh_sz)
3940
#define NFS3_sattr_sz (15)
4041
#define NFS3_filename_sz (1+(NFS3_MAXNAMLEN>>2))
4142
#define NFS3_path_sz (1+(NFS3_MAXPATHLEN>>2))
@@ -73,7 +74,7 @@
7374
#define NFS3_readlinkres_sz (1+NFS3_post_op_attr_sz+1+NFS3_pagepad_sz)
7475
#define NFS3_readres_sz (1+NFS3_post_op_attr_sz+3+NFS3_pagepad_sz)
7576
#define NFS3_writeres_sz (1+NFS3_wcc_data_sz+4)
76-
#define NFS3_createres_sz (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
77+
#define NFS3_createres_sz (1+NFS3_post_op_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
7778
#define NFS3_renameres_sz (1+(2 * NFS3_wcc_data_sz))
7879
#define NFS3_linkres_sz (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
7980
#define NFS3_readdirres_sz (1+NFS3_post_op_attr_sz+2+NFS3_pagepad_sz)

fs/nfs/nfs42proc.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,15 @@ static ssize_t _nfs42_proc_copy(struct file *src,
357357
truncate_pagecache_range(dst_inode, pos_dst,
358358
pos_dst + res->write_res.count);
359359
spin_lock(&dst_inode->i_lock);
360-
NFS_I(dst_inode)->cache_validity |= (NFS_INO_REVAL_PAGECACHE |
361-
NFS_INO_REVAL_FORCED | NFS_INO_INVALID_SIZE |
362-
NFS_INO_INVALID_ATTR | NFS_INO_INVALID_DATA);
360+
nfs_set_cache_invalid(
361+
dst_inode, NFS_INO_REVAL_PAGECACHE | NFS_INO_REVAL_FORCED |
362+
NFS_INO_INVALID_SIZE | NFS_INO_INVALID_ATTR |
363+
NFS_INO_INVALID_DATA);
363364
spin_unlock(&dst_inode->i_lock);
364365
spin_lock(&src_inode->i_lock);
365-
NFS_I(src_inode)->cache_validity |= (NFS_INO_REVAL_PAGECACHE |
366-
NFS_INO_REVAL_FORCED | NFS_INO_INVALID_ATIME);
366+
nfs_set_cache_invalid(src_inode, NFS_INO_REVAL_PAGECACHE |
367+
NFS_INO_REVAL_FORCED |
368+
NFS_INO_INVALID_ATIME);
367369
spin_unlock(&src_inode->i_lock);
368370
status = res->write_res.count;
369371
out:

fs/nfs/nfs4proc.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,14 +1169,14 @@ int nfs4_call_sync(struct rpc_clnt *clnt,
11691169
static void
11701170
nfs4_inc_nlink_locked(struct inode *inode)
11711171
{
1172-
NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER;
1172+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER);
11731173
inc_nlink(inode);
11741174
}
11751175

11761176
static void
11771177
nfs4_dec_nlink_locked(struct inode *inode)
11781178
{
1179-
NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER;
1179+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER);
11801180
drop_nlink(inode);
11811181
}
11821182

@@ -1187,35 +1187,31 @@ nfs4_update_changeattr_locked(struct inode *inode,
11871187
{
11881188
struct nfs_inode *nfsi = NFS_I(inode);
11891189

1190-
nfsi->cache_validity |= NFS_INO_INVALID_CTIME
1191-
| NFS_INO_INVALID_MTIME
1192-
| cache_validity;
1190+
cache_validity |= NFS_INO_INVALID_CTIME | NFS_INO_INVALID_MTIME;
11931191

11941192
if (cinfo->atomic && cinfo->before == inode_peek_iversion_raw(inode)) {
11951193
nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE;
11961194
nfsi->attrtimeo_timestamp = jiffies;
11971195
} else {
11981196
if (S_ISDIR(inode->i_mode)) {
1199-
nfsi->cache_validity |= NFS_INO_INVALID_DATA;
1197+
cache_validity |= NFS_INO_INVALID_DATA;
12001198
nfs_force_lookup_revalidate(inode);
12011199
} else {
12021200
if (!NFS_PROTO(inode)->have_delegation(inode,
12031201
FMODE_READ))
1204-
nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE;
1202+
cache_validity |= NFS_INO_REVAL_PAGECACHE;
12051203
}
12061204

12071205
if (cinfo->before != inode_peek_iversion_raw(inode))
1208-
nfsi->cache_validity |= NFS_INO_INVALID_ACCESS |
1209-
NFS_INO_INVALID_ACL |
1210-
NFS_INO_INVALID_XATTR;
1206+
cache_validity |= NFS_INO_INVALID_ACCESS |
1207+
NFS_INO_INVALID_ACL |
1208+
NFS_INO_INVALID_XATTR;
12111209
}
12121210
inode_set_iversion_raw(inode, cinfo->after);
12131211
nfsi->read_cache_jiffies = timestamp;
12141212
nfsi->attr_gencount = nfs_inc_attr_generation_counter();
1213+
nfs_set_cache_invalid(inode, cache_validity);
12151214
nfsi->cache_validity &= ~NFS_INO_INVALID_CHANGE;
1216-
1217-
if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
1218-
nfs_fscache_invalidate(inode);
12191215
}
12201216

12211217
void
@@ -5893,6 +5889,9 @@ static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t bufl
58935889
unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE);
58945890
int ret, i;
58955891

5892+
/* You can't remove system.nfs4_acl: */
5893+
if (buflen == 0)
5894+
return -EINVAL;
58965895
if (!nfs4_server_supports_acls(server))
58975896
return -EOPNOTSUPP;
58985897
if (npages > ARRAY_SIZE(pages))
@@ -5915,9 +5914,9 @@ static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t bufl
59155914
* so mark the attribute cache invalid.
59165915
*/
59175916
spin_lock(&inode->i_lock);
5918-
NFS_I(inode)->cache_validity |= NFS_INO_INVALID_CHANGE
5919-
| NFS_INO_INVALID_CTIME
5920-
| NFS_INO_REVAL_FORCED;
5917+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE |
5918+
NFS_INO_INVALID_CTIME |
5919+
NFS_INO_REVAL_FORCED);
59215920
spin_unlock(&inode->i_lock);
59225921
nfs_access_zap_cache(inode);
59235922
nfs_zap_acl_cache(inode);
@@ -5969,7 +5968,7 @@ static int _nfs4_get_security_label(struct inode *inode, void *buf,
59695968
return ret;
59705969
if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL))
59715970
return -ENOENT;
5972-
return 0;
5971+
return label.len;
59735972
}
59745973

59755974
static int nfs4_get_security_label(struct inode *inode, void *buf,

fs/nfs/unlink.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,9 @@ nfs_sillyrename(struct inode *dir, struct dentry *dentry)
500500
nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
501501
spin_lock(&inode->i_lock);
502502
NFS_I(inode)->attr_gencount = nfs_inc_attr_generation_counter();
503-
NFS_I(inode)->cache_validity |= NFS_INO_INVALID_CHANGE
504-
| NFS_INO_INVALID_CTIME
505-
| NFS_INO_REVAL_FORCED;
503+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE |
504+
NFS_INO_INVALID_CTIME |
505+
NFS_INO_REVAL_FORCED);
506506
spin_unlock(&inode->i_lock);
507507
d_move(dentry, sdentry);
508508
break;

fs/nfs/write.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,9 @@ static void nfs_set_pageerror(struct address_space *mapping)
303303
nfs_zap_mapping(mapping->host, mapping);
304304
/* Force file size revalidation */
305305
spin_lock(&inode->i_lock);
306-
NFS_I(inode)->cache_validity |= NFS_INO_REVAL_FORCED |
307-
NFS_INO_REVAL_PAGECACHE |
308-
NFS_INO_INVALID_SIZE;
306+
nfs_set_cache_invalid(inode, NFS_INO_REVAL_FORCED |
307+
NFS_INO_REVAL_PAGECACHE |
308+
NFS_INO_INVALID_SIZE);
309309
spin_unlock(&inode->i_lock);
310310
}
311311

@@ -1604,7 +1604,7 @@ static int nfs_writeback_done(struct rpc_task *task,
16041604
/* Deal with the suid/sgid bit corner case */
16051605
if (nfs_should_remove_suid(inode)) {
16061606
spin_lock(&inode->i_lock);
1607-
NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER;
1607+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER);
16081608
spin_unlock(&inode->i_lock);
16091609
}
16101610
return 0;

net/sunrpc/sched.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,8 +963,11 @@ void rpc_execute(struct rpc_task *task)
963963

964964
rpc_set_active(task);
965965
rpc_make_runnable(rpciod_workqueue, task);
966-
if (!is_async)
966+
if (!is_async) {
967+
unsigned int pflags = memalloc_nofs_save();
967968
__rpc_execute(task);
969+
memalloc_nofs_restore(pflags);
970+
}
968971
}
969972

970973
static void rpc_async_schedule(struct work_struct *work)

0 commit comments

Comments
 (0)