Skip to content

Commit 8b4bdcf

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
NFS: Store the file system "fsid" value in the NFS super block.
This should enable us to detect if we are crossing a mountpoint in the case where the server is exporting "nohide" mounts. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent 8b512d9 commit 8b4bdcf

9 files changed

Lines changed: 30 additions & 15 deletions

File tree

‎fs/nfs/idmap.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#include <linux/workqueue.h>
4848
#include <linux/sunrpc/rpc_pipe_fs.h>
4949

50-
#include <linux/nfs_fs_sb.h>
5150
#include <linux/nfs_fs.h>
5251

5352
#include <linux/nfs_idmap.h>

‎fs/nfs/inode.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ nfs_get_root(struct super_block *sb, struct nfs_fh *rootfh, struct nfs_fsinfo *f
236236
return ERR_PTR(error);
237237
}
238238

239+
server->fsid = fsinfo->fattr->fsid;
239240
return nfs_fhget(sb, rootfh, fsinfo->fattr);
240241
}
241242

@@ -1493,6 +1494,7 @@ int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr)
14931494
*/
14941495
static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
14951496
{
1497+
struct nfs_server *server;
14961498
struct nfs_inode *nfsi = NFS_I(inode);
14971499
loff_t cur_isize, new_isize;
14981500
unsigned int invalid = 0;
@@ -1511,6 +1513,12 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
15111513
if ((inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT))
15121514
goto out_changed;
15131515

1516+
server = NFS_SERVER(inode);
1517+
/* Update the fsid if and only if this is the root directory */
1518+
if (inode == inode->i_sb->s_root->d_inode
1519+
&& !nfs_fsid_equal(&server->fsid, &fattr->fsid))
1520+
server->fsid = fattr->fsid;
1521+
15141522
/*
15151523
* Update the read time so we don't revalidate too often.
15161524
*/

‎fs/nfs/nfs2xdr.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ xdr_decode_fattr(u32 *p, struct nfs_fattr *fattr)
131131
fattr->du.nfs2.blocksize = ntohl(*p++);
132132
rdev = ntohl(*p++);
133133
fattr->du.nfs2.blocks = ntohl(*p++);
134-
fattr->fsid_u.nfs3 = ntohl(*p++);
134+
fattr->fsid.major = ntohl(*p++);
135+
fattr->fsid.minor = 0;
135136
fattr->fileid = ntohl(*p++);
136137
p = xdr_decode_time(p, &fattr->atime);
137138
p = xdr_decode_time(p, &fattr->mtime);

‎fs/nfs/nfs3xdr.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ xdr_decode_fattr(u32 *p, struct nfs_fattr *fattr)
166166
if (MAJOR(fattr->rdev) != major || MINOR(fattr->rdev) != minor)
167167
fattr->rdev = 0;
168168

169-
p = xdr_decode_hyper(p, &fattr->fsid_u.nfs3);
169+
p = xdr_decode_hyper(p, &fattr->fsid.major);
170+
fattr->fsid.minor = 0;
170171
p = xdr_decode_hyper(p, &fattr->fileid);
171172
p = xdr_decode_time3(p, &fattr->atime);
172173
p = xdr_decode_time3(p, &fattr->mtime);

‎fs/nfs/nfs4xdr.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,7 +2217,7 @@ static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap,
22172217
return 0;
22182218
}
22192219

2220-
static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fsid *fsid)
2220+
static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
22212221
{
22222222
uint32_t *p;
22232223

@@ -2863,7 +2863,7 @@ static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, cons
28632863
goto xdr_error;
28642864
if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
28652865
goto xdr_error;
2866-
if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid_u.nfs4)) != 0)
2866+
if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
28672867
goto xdr_error;
28682868
if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
28692869
goto xdr_error;

‎include/linux/nfs_fs.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#include <linux/rwsem.h>
1717
#include <linux/wait.h>
1818

19-
#include <linux/nfs_fs_sb.h>
20-
2119
#include <linux/sunrpc/debug.h>
2220
#include <linux/sunrpc/auth.h>
2321
#include <linux/sunrpc/clnt.h>
@@ -27,6 +25,9 @@
2725
#include <linux/nfs3.h>
2826
#include <linux/nfs4.h>
2927
#include <linux/nfs_xdr.h>
28+
29+
#include <linux/nfs_fs_sb.h>
30+
3031
#include <linux/rwsem.h>
3132
#include <linux/mempool.h>
3233

‎include/linux/nfs_fs_sb.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct nfs_server {
3535
char * hostname; /* remote hostname */
3636
struct nfs_fh fh;
3737
struct sockaddr_in addr;
38+
struct nfs_fsid fsid;
3839
unsigned long mount_time; /* when this fs was mounted */
3940
#ifdef CONFIG_NFS_V4
4041
/* Our own IP address, as a null-terminated string.

‎include/linux/nfs_page.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <linux/list.h>
1414
#include <linux/pagemap.h>
1515
#include <linux/wait.h>
16-
#include <linux/nfs_fs_sb.h>
1716
#include <linux/sunrpc/auth.h>
1817
#include <linux/nfs_xdr.h>
1918

‎include/linux/nfs_xdr.h‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,19 @@
1414
#define NFS_DEF_FILE_IO_SIZE (4096U)
1515
#define NFS_MIN_FILE_IO_SIZE (1024U)
1616

17-
struct nfs4_fsid {
18-
__u64 major;
19-
__u64 minor;
17+
struct nfs_fsid {
18+
uint64_t major;
19+
uint64_t minor;
2020
};
2121

22+
/*
23+
* Helper for checking equality between 2 fsids.
24+
*/
25+
static inline int nfs_fsid_equal(const struct nfs_fsid *a, const struct nfs_fsid *b)
26+
{
27+
return a->major == b->major && a->minor == b->minor;
28+
}
29+
2230
struct nfs_fattr {
2331
unsigned short valid; /* which fields are valid */
2432
__u64 pre_size; /* pre_op_attr.size */
@@ -40,10 +48,7 @@ struct nfs_fattr {
4048
} nfs3;
4149
} du;
4250
dev_t rdev;
43-
union {
44-
__u64 nfs3; /* also nfs2 */
45-
struct nfs4_fsid nfs4;
46-
} fsid_u;
51+
struct nfs_fsid fsid;
4752
__u64 fileid;
4853
struct timespec atime;
4954
struct timespec mtime;

0 commit comments

Comments
 (0)