Skip to content

Commit bca7947

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
NFS: Fix the type of struct nfs_fattr->mode
There is no point in using anything other than umode_t, since we copy the content pretty much directly into inode->i_mode. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent 1ca277d commit bca7947

5 files changed

Lines changed: 38 additions & 47 deletions

File tree

‎fs/nfs/getroot.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ int nfs4_path_walk(struct nfs_server *server,
156156
return ret;
157157
}
158158

159-
if (fattr.type != NFDIR) {
159+
if (!S_ISDIR(fattr.mode)) {
160160
printk(KERN_ERR "nfs4_get_root:"
161161
" getroot encountered non-directory\n");
162162
return -ENOTDIR;
@@ -213,7 +213,7 @@ int nfs4_path_walk(struct nfs_server *server,
213213
return ret;
214214
}
215215

216-
if (fattr.type != NFDIR) {
216+
if (!S_ISDIR(fattr.mode)) {
217217
printk(KERN_ERR "nfs4_get_root:"
218218
" lookupfh encountered non-directory\n");
219219
return -ENOTDIR;

‎fs/nfs/nfs2xdr.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ xdr_decode_time(__be32 *p, struct timespec *timep)
120120
static __be32 *
121121
xdr_decode_fattr(__be32 *p, struct nfs_fattr *fattr)
122122
{
123-
u32 rdev;
124-
fattr->type = (enum nfs_ftype) ntohl(*p++);
123+
u32 rdev, type;
124+
type = ntohl(*p++);
125125
fattr->mode = ntohl(*p++);
126126
fattr->nlink = ntohl(*p++);
127127
fattr->uid = ntohl(*p++);
@@ -138,8 +138,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_fattr *fattr)
138138
p = xdr_decode_time(p, &fattr->ctime);
139139
fattr->valid |= NFS_ATTR_FATTR_V2;
140140
fattr->rdev = new_decode_dev(rdev);
141-
if (fattr->type == NFCHR && rdev == NFS2_FIFO_DEV) {
142-
fattr->type = NFFIFO;
141+
if (type == NFCHR && rdev == NFS2_FIFO_DEV) {
143142
fattr->mode = (fattr->mode & ~S_IFMT) | S_IFIFO;
144143
fattr->rdev = 0;
145144
}

‎fs/nfs/nfs3xdr.c‎

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,15 @@
9191
/*
9292
* Map file type to S_IFMT bits
9393
*/
94-
static struct {
95-
unsigned int mode;
96-
unsigned int nfs2type;
97-
} nfs_type2fmt[] = {
98-
{ 0, NFNON },
99-
{ S_IFREG, NFREG },
100-
{ S_IFDIR, NFDIR },
101-
{ S_IFBLK, NFBLK },
102-
{ S_IFCHR, NFCHR },
103-
{ S_IFLNK, NFLNK },
104-
{ S_IFSOCK, NFSOCK },
105-
{ S_IFIFO, NFFIFO },
106-
{ 0, NFBAD }
94+
static const umode_t nfs_type2fmt[] = {
95+
[NF3BAD] = 0,
96+
[NF3REG] = S_IFREG,
97+
[NF3DIR] = S_IFDIR,
98+
[NF3BLK] = S_IFBLK,
99+
[NF3CHR] = S_IFCHR,
100+
[NF3LNK] = S_IFLNK,
101+
[NF3SOCK] = S_IFSOCK,
102+
[NF3FIFO] = S_IFIFO,
107103
};
108104

109105
/*
@@ -148,13 +144,12 @@ static __be32 *
148144
xdr_decode_fattr(__be32 *p, struct nfs_fattr *fattr)
149145
{
150146
unsigned int type, major, minor;
151-
int fmode;
147+
umode_t fmode;
152148

153149
type = ntohl(*p++);
154-
if (type >= NF3BAD)
155-
type = NF3BAD;
156-
fmode = nfs_type2fmt[type].mode;
157-
fattr->type = nfs_type2fmt[type].nfs2type;
150+
if (type > NF3FIFO)
151+
type = NF3NON;
152+
fmode = nfs_type2fmt[type];
158153
fattr->mode = (ntohl(*p++) & ~S_IFMT) | fmode;
159154
fattr->nlink = ntohl(*p++);
160155
fattr->uid = ntohl(*p++);

‎fs/nfs/nfs4xdr.c‎

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -522,20 +522,17 @@ static int nfs4_stat_to_errno(int);
522522
decode_lookup_maxsz + \
523523
decode_fs_locations_maxsz)
524524

525-
static struct {
526-
unsigned int mode;
527-
unsigned int nfs2type;
528-
} nfs_type2fmt[] = {
529-
{ 0, NFNON },
530-
{ S_IFREG, NFREG },
531-
{ S_IFDIR, NFDIR },
532-
{ S_IFBLK, NFBLK },
533-
{ S_IFCHR, NFCHR },
534-
{ S_IFLNK, NFLNK },
535-
{ S_IFSOCK, NFSOCK },
536-
{ S_IFIFO, NFFIFO },
537-
{ 0, NFNON },
538-
{ 0, NFNON },
525+
static const umode_t nfs_type2fmt[] = {
526+
[NF4BAD] = 0,
527+
[NF4REG] = S_IFREG,
528+
[NF4DIR] = S_IFDIR,
529+
[NF4BLK] = S_IFBLK,
530+
[NF4CHR] = S_IFCHR,
531+
[NF4LNK] = S_IFLNK,
532+
[NF4SOCK] = S_IFSOCK,
533+
[NF4FIFO] = S_IFIFO,
534+
[NF4ATTRDIR] = 0,
535+
[NF4NAMEDATTR] = 0,
539536
};
540537

541538
struct compound_hdr {
@@ -2173,7 +2170,7 @@ static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *
21732170
}
21742171
bitmap[0] &= ~FATTR4_WORD0_TYPE;
21752172
}
2176-
dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type].nfs2type);
2173+
dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
21772174
return 0;
21782175
}
21792176

@@ -2580,17 +2577,18 @@ static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32
25802577
return status;
25812578
}
25822579

2583-
static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2580+
static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
25842581
{
2582+
uint32_t tmp;
25852583
__be32 *p;
25862584

25872585
*mode = 0;
25882586
if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
25892587
return -EIO;
25902588
if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
25912589
READ_BUF(4);
2592-
READ32(*mode);
2593-
*mode &= ~S_IFMT;
2590+
READ32(tmp);
2591+
*mode = tmp & ~S_IFMT;
25942592
bitmap[1] &= ~FATTR4_WORD1_MODE;
25952593
}
25962594
dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
@@ -2994,7 +2992,8 @@ static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, cons
29942992
uint32_t attrlen,
29952993
bitmap[2] = {0},
29962994
type;
2997-
int status, fmode = 0;
2995+
int status;
2996+
umode_t fmode = 0;
29982997
uint64_t fileid;
29992998

30002999
if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
@@ -3008,8 +3007,7 @@ static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, cons
30083007

30093008
if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
30103009
goto xdr_error;
3011-
fattr->type = nfs_type2fmt[type].nfs2type;
3012-
fattr->mode = nfs_type2fmt[type].mode;
3010+
fattr->mode = nfs_type2fmt[type];
30133011

30143012
if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
30153013
goto xdr_error;

‎include/linux/nfs_xdr.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ static inline int nfs_fsid_equal(const struct nfs_fsid *a, const struct nfs_fsid
2828

2929
struct nfs_fattr {
3030
unsigned int valid; /* which fields are valid */
31-
enum nfs_ftype type; /* always use NFSv2 types */
32-
__u32 mode;
31+
umode_t mode;
3332
__u32 nlink;
3433
__u32 uid;
3534
__u32 gid;

0 commit comments

Comments
 (0)