Skip to content

Commit ec71fea

Browse files
committed
Merge tag 'nfs-for-3.16-2' of git://git.linux-nfs.org/projects/trondmy/linux-nfs
Pull NFS client fixes from Trond Myklebust: "Highlights include: - Stable fix for a data corruption case due to incorrect cache validation - Fix a couple of false positive cache invalidations - Fix NFSv4 security negotiation issues" * tag 'nfs-for-3.16-2' of git://git.linux-nfs.org/projects/trondmy/linux-nfs: NFSv4: test SECINFO RPC_AUTH_GSS pseudoflavors for support NFS Return -EPERM if no supported or matching SECINFO flavor NFS check the return of nfs4_negotiate_security in nfs4_submount NFS: Don't mark the data cache as invalid if it has been flushed NFS: Clear NFS_INO_REVAL_PAGECACHE when we update the file size nfs: Fix cache_validity check in nfs_write_pageuptodate()
2 parents 456febd + 66b0686 commit ec71fea

File tree

6 files changed

+104
-83
lines changed

6 files changed

+104
-83
lines changed

fs/nfs/inode.c

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,17 @@ int nfs_sync_mapping(struct address_space *mapping)
147147
return ret;
148148
}
149149

150+
static void nfs_set_cache_invalid(struct inode *inode, unsigned long flags)
151+
{
152+
struct nfs_inode *nfsi = NFS_I(inode);
153+
154+
if (inode->i_mapping->nrpages == 0)
155+
flags &= ~NFS_INO_INVALID_DATA;
156+
nfsi->cache_validity |= flags;
157+
if (flags & NFS_INO_INVALID_DATA)
158+
nfs_fscache_invalidate(inode);
159+
}
160+
150161
/*
151162
* Invalidate the local caches
152163
*/
@@ -162,17 +173,16 @@ static void nfs_zap_caches_locked(struct inode *inode)
162173

163174
memset(NFS_I(inode)->cookieverf, 0, sizeof(NFS_I(inode)->cookieverf));
164175
if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) {
165-
nfs_fscache_invalidate(inode);
166-
nfsi->cache_validity |= NFS_INO_INVALID_ATTR
176+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR
167177
| NFS_INO_INVALID_DATA
168178
| NFS_INO_INVALID_ACCESS
169179
| NFS_INO_INVALID_ACL
170-
| NFS_INO_REVAL_PAGECACHE;
180+
| NFS_INO_REVAL_PAGECACHE);
171181
} else
172-
nfsi->cache_validity |= NFS_INO_INVALID_ATTR
182+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR
173183
| NFS_INO_INVALID_ACCESS
174184
| NFS_INO_INVALID_ACL
175-
| NFS_INO_REVAL_PAGECACHE;
185+
| NFS_INO_REVAL_PAGECACHE);
176186
nfs_zap_label_cache_locked(nfsi);
177187
}
178188

@@ -187,8 +197,7 @@ void nfs_zap_mapping(struct inode *inode, struct address_space *mapping)
187197
{
188198
if (mapping->nrpages != 0) {
189199
spin_lock(&inode->i_lock);
190-
NFS_I(inode)->cache_validity |= NFS_INO_INVALID_DATA;
191-
nfs_fscache_invalidate(inode);
200+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
192201
spin_unlock(&inode->i_lock);
193202
}
194203
}
@@ -209,7 +218,7 @@ EXPORT_SYMBOL_GPL(nfs_zap_acl_cache);
209218
void nfs_invalidate_atime(struct inode *inode)
210219
{
211220
spin_lock(&inode->i_lock);
212-
NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATIME;
221+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATIME);
213222
spin_unlock(&inode->i_lock);
214223
}
215224
EXPORT_SYMBOL_GPL(nfs_invalidate_atime);
@@ -369,7 +378,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, st
369378
inode->i_mode = fattr->mode;
370379
if ((fattr->valid & NFS_ATTR_FATTR_MODE) == 0
371380
&& nfs_server_capable(inode, NFS_CAP_MODE))
372-
nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
381+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
373382
/* Why so? Because we want revalidate for devices/FIFOs, and
374383
* that's precisely what we have in nfs_file_inode_operations.
375384
*/
@@ -415,36 +424,36 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, st
415424
if (fattr->valid & NFS_ATTR_FATTR_ATIME)
416425
inode->i_atime = fattr->atime;
417426
else if (nfs_server_capable(inode, NFS_CAP_ATIME))
418-
nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
427+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
419428
if (fattr->valid & NFS_ATTR_FATTR_MTIME)
420429
inode->i_mtime = fattr->mtime;
421430
else if (nfs_server_capable(inode, NFS_CAP_MTIME))
422-
nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
431+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
423432
if (fattr->valid & NFS_ATTR_FATTR_CTIME)
424433
inode->i_ctime = fattr->ctime;
425434
else if (nfs_server_capable(inode, NFS_CAP_CTIME))
426-
nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
435+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
427436
if (fattr->valid & NFS_ATTR_FATTR_CHANGE)
428437
inode->i_version = fattr->change_attr;
429438
else if (nfs_server_capable(inode, NFS_CAP_CHANGE_ATTR))
430-
nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
439+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
431440
if (fattr->valid & NFS_ATTR_FATTR_SIZE)
432441
inode->i_size = nfs_size_to_loff_t(fattr->size);
433442
else
434-
nfsi->cache_validity |= NFS_INO_INVALID_ATTR
435-
| NFS_INO_REVAL_PAGECACHE;
443+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR
444+
| NFS_INO_REVAL_PAGECACHE);
436445
if (fattr->valid & NFS_ATTR_FATTR_NLINK)
437446
set_nlink(inode, fattr->nlink);
438447
else if (nfs_server_capable(inode, NFS_CAP_NLINK))
439-
nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
448+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
440449
if (fattr->valid & NFS_ATTR_FATTR_OWNER)
441450
inode->i_uid = fattr->uid;
442451
else if (nfs_server_capable(inode, NFS_CAP_OWNER))
443-
nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
452+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
444453
if (fattr->valid & NFS_ATTR_FATTR_GROUP)
445454
inode->i_gid = fattr->gid;
446455
else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
447-
nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
456+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR);
448457
if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
449458
inode->i_blocks = fattr->du.nfs2.blocks;
450459
if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) {
@@ -550,6 +559,9 @@ static int nfs_vmtruncate(struct inode * inode, loff_t offset)
550559

551560
spin_lock(&inode->i_lock);
552561
i_size_write(inode, offset);
562+
/* Optimisation */
563+
if (offset == 0)
564+
NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_DATA;
553565
spin_unlock(&inode->i_lock);
554566

555567
truncate_pagecache(inode, offset);
@@ -578,7 +590,8 @@ void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr)
578590
inode->i_uid = attr->ia_uid;
579591
if ((attr->ia_valid & ATTR_GID) != 0)
580592
inode->i_gid = attr->ia_gid;
581-
NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
593+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ACCESS
594+
| NFS_INO_INVALID_ACL);
582595
spin_unlock(&inode->i_lock);
583596
}
584597
if ((attr->ia_valid & ATTR_SIZE) != 0) {
@@ -1101,7 +1114,7 @@ static unsigned long nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr
11011114
&& inode->i_version == fattr->pre_change_attr) {
11021115
inode->i_version = fattr->change_attr;
11031116
if (S_ISDIR(inode->i_mode))
1104-
nfsi->cache_validity |= NFS_INO_INVALID_DATA;
1117+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
11051118
ret |= NFS_INO_INVALID_ATTR;
11061119
}
11071120
/* If we have atomic WCC data, we may update some attributes */
@@ -1117,7 +1130,7 @@ static unsigned long nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr
11171130
&& timespec_equal(&inode->i_mtime, &fattr->pre_mtime)) {
11181131
memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
11191132
if (S_ISDIR(inode->i_mode))
1120-
nfsi->cache_validity |= NFS_INO_INVALID_DATA;
1133+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
11211134
ret |= NFS_INO_INVALID_ATTR;
11221135
}
11231136
if ((fattr->valid & NFS_ATTR_FATTR_PRESIZE)
@@ -1128,9 +1141,6 @@ static unsigned long nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr
11281141
ret |= NFS_INO_INVALID_ATTR;
11291142
}
11301143

1131-
if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
1132-
nfs_fscache_invalidate(inode);
1133-
11341144
return ret;
11351145
}
11361146

@@ -1189,7 +1199,7 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
11891199
invalid |= NFS_INO_INVALID_ATIME;
11901200

11911201
if (invalid != 0)
1192-
nfsi->cache_validity |= invalid;
1202+
nfs_set_cache_invalid(inode, invalid);
11931203

11941204
nfsi->read_cache_jiffies = fattr->time_start;
11951205
return 0;
@@ -1402,13 +1412,11 @@ EXPORT_SYMBOL_GPL(nfs_refresh_inode);
14021412

14031413
static int nfs_post_op_update_inode_locked(struct inode *inode, struct nfs_fattr *fattr)
14041414
{
1405-
struct nfs_inode *nfsi = NFS_I(inode);
1415+
unsigned long invalid = NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
14061416

1407-
nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
1408-
if (S_ISDIR(inode->i_mode)) {
1409-
nfsi->cache_validity |= NFS_INO_INVALID_DATA;
1410-
nfs_fscache_invalidate(inode);
1411-
}
1417+
if (S_ISDIR(inode->i_mode))
1418+
invalid |= NFS_INO_INVALID_DATA;
1419+
nfs_set_cache_invalid(inode, invalid);
14121420
if ((fattr->valid & NFS_ATTR_FATTR) == 0)
14131421
return 0;
14141422
return nfs_refresh_inode_locked(inode, fattr);
@@ -1601,6 +1609,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
16011609
if ((nfsi->npages == 0) || new_isize > cur_isize) {
16021610
i_size_write(inode, new_isize);
16031611
invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
1612+
invalid &= ~NFS_INO_REVAL_PAGECACHE;
16041613
}
16051614
dprintk("NFS: isize change on server for file %s/%ld "
16061615
"(%Ld to %Ld)\n",
@@ -1702,10 +1711,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
17021711
invalid &= ~NFS_INO_INVALID_DATA;
17031712
if (!NFS_PROTO(inode)->have_delegation(inode, FMODE_READ) ||
17041713
(save_cache_validity & NFS_INO_REVAL_FORCED))
1705-
nfsi->cache_validity |= invalid;
1706-
1707-
if (invalid & NFS_INO_INVALID_DATA)
1708-
nfs_fscache_invalidate(inode);
1714+
nfs_set_cache_invalid(inode, invalid);
17091715

17101716
return 0;
17111717
out_err:

fs/nfs/nfs4_fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ int nfs_atomic_open(struct inode *, struct dentry *, struct file *,
230230
extern struct file_system_type nfs4_fs_type;
231231

232232
/* nfs4namespace.c */
233-
struct rpc_clnt *nfs4_create_sec_client(struct rpc_clnt *, struct inode *, struct qstr *);
233+
struct rpc_clnt *nfs4_negotiate_security(struct rpc_clnt *, struct inode *, struct qstr *);
234234
struct vfsmount *nfs4_submount(struct nfs_server *, struct dentry *,
235235
struct nfs_fh *, struct nfs_fattr *);
236236
int nfs4_replace_transport(struct nfs_server *server,

fs/nfs/nfs4namespace.c

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,22 @@ static size_t nfs_parse_server_name(char *string, size_t len,
139139
* @server: NFS server struct
140140
* @flavors: List of security tuples returned by SECINFO procedure
141141
*
142-
* Return the pseudoflavor of the first security mechanism in
143-
* "flavors" that is locally supported. Return RPC_AUTH_UNIX if
144-
* no matching flavor is found in the array. The "flavors" array
142+
* Return an rpc client that uses the first security mechanism in
143+
* "flavors" that is locally supported. The "flavors" array
145144
* is searched in the order returned from the server, per RFC 3530
146-
* recommendation.
145+
* recommendation and each flavor is checked for membership in the
146+
* sec= mount option list if it exists.
147+
*
148+
* Return -EPERM if no matching flavor is found in the array.
149+
*
150+
* Please call rpc_shutdown_client() when you are done with this rpc client.
151+
*
147152
*/
148-
static rpc_authflavor_t nfs_find_best_sec(struct nfs_server *server,
153+
static struct rpc_clnt *nfs_find_best_sec(struct rpc_clnt *clnt,
154+
struct nfs_server *server,
149155
struct nfs4_secinfo_flavors *flavors)
150156
{
151-
rpc_authflavor_t pseudoflavor;
157+
rpc_authflavor_t pflavor;
152158
struct nfs4_secinfo4 *secinfo;
153159
unsigned int i;
154160

@@ -159,62 +165,73 @@ static rpc_authflavor_t nfs_find_best_sec(struct nfs_server *server,
159165
case RPC_AUTH_NULL:
160166
case RPC_AUTH_UNIX:
161167
case RPC_AUTH_GSS:
162-
pseudoflavor = rpcauth_get_pseudoflavor(secinfo->flavor,
168+
pflavor = rpcauth_get_pseudoflavor(secinfo->flavor,
163169
&secinfo->flavor_info);
164-
/* make sure pseudoflavor matches sec= mount opt */
165-
if (pseudoflavor != RPC_AUTH_MAXFLAVOR &&
166-
nfs_auth_info_match(&server->auth_info,
167-
pseudoflavor))
168-
return pseudoflavor;
169-
break;
170+
/* does the pseudoflavor match a sec= mount opt? */
171+
if (pflavor != RPC_AUTH_MAXFLAVOR &&
172+
nfs_auth_info_match(&server->auth_info, pflavor)) {
173+
struct rpc_clnt *new;
174+
struct rpc_cred *cred;
175+
176+
/* Cloning creates an rpc_auth for the flavor */
177+
new = rpc_clone_client_set_auth(clnt, pflavor);
178+
if (IS_ERR(new))
179+
continue;
180+
/**
181+
* Check that the user actually can use the
182+
* flavor. This is mostly for RPC_AUTH_GSS
183+
* where cr_init obtains a gss context
184+
*/
185+
cred = rpcauth_lookupcred(new->cl_auth, 0);
186+
if (IS_ERR(cred)) {
187+
rpc_shutdown_client(new);
188+
continue;
189+
}
190+
put_rpccred(cred);
191+
return new;
192+
}
170193
}
171194
}
172-
173-
/* if there were any sec= options then nothing matched */
174-
if (server->auth_info.flavor_len > 0)
175-
return -EPERM;
176-
177-
return RPC_AUTH_UNIX;
195+
return ERR_PTR(-EPERM);
178196
}
179197

180-
static rpc_authflavor_t nfs4_negotiate_security(struct inode *inode, struct qstr *name)
198+
/**
199+
* nfs4_negotiate_security - in response to an NFS4ERR_WRONGSEC on lookup,
200+
* return an rpc_clnt that uses the best available security flavor with
201+
* respect to the secinfo flavor list and the sec= mount options.
202+
*
203+
* @clnt: RPC client to clone
204+
* @inode: directory inode
205+
* @name: lookup name
206+
*
207+
* Please call rpc_shutdown_client() when you are done with this rpc client.
208+
*/
209+
struct rpc_clnt *
210+
nfs4_negotiate_security(struct rpc_clnt *clnt, struct inode *inode,
211+
struct qstr *name)
181212
{
182213
struct page *page;
183214
struct nfs4_secinfo_flavors *flavors;
184-
rpc_authflavor_t flavor;
215+
struct rpc_clnt *new;
185216
int err;
186217

187218
page = alloc_page(GFP_KERNEL);
188219
if (!page)
189-
return -ENOMEM;
220+
return ERR_PTR(-ENOMEM);
221+
190222
flavors = page_address(page);
191223

192224
err = nfs4_proc_secinfo(inode, name, flavors);
193225
if (err < 0) {
194-
flavor = err;
226+
new = ERR_PTR(err);
195227
goto out;
196228
}
197229

198-
flavor = nfs_find_best_sec(NFS_SERVER(inode), flavors);
230+
new = nfs_find_best_sec(clnt, NFS_SERVER(inode), flavors);
199231

200232
out:
201233
put_page(page);
202-
return flavor;
203-
}
204-
205-
/*
206-
* Please call rpc_shutdown_client() when you are done with this client.
207-
*/
208-
struct rpc_clnt *nfs4_create_sec_client(struct rpc_clnt *clnt, struct inode *inode,
209-
struct qstr *name)
210-
{
211-
rpc_authflavor_t flavor;
212-
213-
flavor = nfs4_negotiate_security(inode, name);
214-
if ((int)flavor < 0)
215-
return ERR_PTR((int)flavor);
216-
217-
return rpc_clone_client_set_auth(clnt, flavor);
234+
return new;
218235
}
219236

220237
static struct vfsmount *try_location(struct nfs_clone_mount *mountdata,
@@ -397,11 +414,6 @@ struct vfsmount *nfs4_submount(struct nfs_server *server, struct dentry *dentry,
397414

398415
if (client->cl_auth->au_flavor != flavor)
399416
flavor = client->cl_auth->au_flavor;
400-
else {
401-
rpc_authflavor_t new = nfs4_negotiate_security(dir, name);
402-
if ((int)new >= 0)
403-
flavor = new;
404-
}
405417
mnt = nfs_do_submount(dentry, fh, fattr, flavor);
406418
out:
407419
rpc_shutdown_client(client);

fs/nfs/nfs4proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3247,7 +3247,7 @@ static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir,
32473247
err = -EPERM;
32483248
if (client != *clnt)
32493249
goto out;
3250-
client = nfs4_create_sec_client(client, dir, name);
3250+
client = nfs4_negotiate_security(client, dir, name);
32513251
if (IS_ERR(client))
32523252
return PTR_ERR(client);
32533253

fs/nfs/write.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,12 +934,14 @@ static bool nfs_write_pageuptodate(struct page *page, struct inode *inode)
934934

935935
if (nfs_have_delegated_attributes(inode))
936936
goto out;
937-
if (nfsi->cache_validity & (NFS_INO_INVALID_DATA|NFS_INO_REVAL_PAGECACHE))
937+
if (nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
938938
return false;
939939
smp_rmb();
940940
if (test_bit(NFS_INO_INVALIDATING, &nfsi->flags))
941941
return false;
942942
out:
943+
if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
944+
return false;
943945
return PageUptodate(page) != 0;
944946
}
945947

net/sunrpc/auth.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ rpcauth_lookupcred(struct rpc_auth *auth, int flags)
592592
put_group_info(acred.group_info);
593593
return ret;
594594
}
595+
EXPORT_SYMBOL_GPL(rpcauth_lookupcred);
595596

596597
void
597598
rpcauth_init_cred(struct rpc_cred *cred, const struct auth_cred *acred,

0 commit comments

Comments
 (0)