Skip to content

Commit d8b2607

Browse files
neilbrownJ. Bruce Fields
authored andcommitted
NFSD: simplify struct nfsfh
Most of the fields in 'struct knfsd_fh' are 2 levels deep (a union and a struct) and are accessed using macros like: #define fh_FOO fh_base.fh_new.fb_FOO This patch makes the union and struct anonymous, so that "fh_FOO" can be a name directly within 'struct knfsd_fh' and the #defines aren't needed. The file handle as a whole is sometimes accessed as "fh_base" or "fh_base.fh_pad", neither of which are particularly helpful names. As the struct holding the filehandle is now anonymous, we cannot use the name of that, so we union it with 'fh_raw' and use that where the raw filehandle is needed. fh_raw also ensure the structure is large enough for the largest possible filehandle. fh_raw is a 'char' array, removing any need to cast it for memcpy etc. SVCFH_fmt() is simplified using the "%ph" printk format. This changes the appearance of filehandles in dprintk() debugging, making them a little more precise. Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: NeilBrown <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent c645a88 commit d8b2607

File tree

11 files changed

+35
-60
lines changed

11 files changed

+35
-60
lines changed

fs/nfsd/flexfilelayout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ nfsd4_ff_proc_layoutget(struct inode *inode, const struct svc_fh *fhp,
6161
goto out_error;
6262

6363
fl->fh.size = fhp->fh_handle.fh_size;
64-
memcpy(fl->fh.data, &fhp->fh_handle.fh_base, fl->fh.size);
64+
memcpy(fl->fh.data, &fhp->fh_handle.fh_raw, fl->fh.size);
6565

6666
/* Give whole file layout segments */
6767
seg->offset = 0;

fs/nfsd/lockd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp,
3535
/* must initialize before using! but maxsize doesn't matter */
3636
fh_init(&fh,0);
3737
fh.fh_handle.fh_size = f->size;
38-
memcpy((char*)&fh.fh_handle.fh_base, f->data, f->size);
38+
memcpy(&fh.fh_handle.fh_raw, f->data, f->size);
3939
fh.fh_export = NULL;
4040

4141
access = (mode == O_WRONLY) ? NFSD_MAY_WRITE : NFSD_MAY_READ;

fs/nfsd/nfs3xdr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ svcxdr_decode_nfs_fh3(struct xdr_stream *xdr, struct svc_fh *fhp)
9292
return false;
9393
fh_init(fhp, NFS3_FHSIZE);
9494
fhp->fh_handle.fh_size = size;
95-
memcpy(&fhp->fh_handle.fh_base, p, size);
95+
memcpy(&fhp->fh_handle.fh_raw, p, size);
9696

9797
return true;
9898
}
@@ -131,7 +131,7 @@ svcxdr_encode_nfs_fh3(struct xdr_stream *xdr, const struct svc_fh *fhp)
131131
*p++ = cpu_to_be32(size);
132132
if (size)
133133
p[XDR_QUADLEN(size) - 1] = 0;
134-
memcpy(p, &fhp->fh_handle.fh_base, size);
134+
memcpy(p, &fhp->fh_handle.fh_raw, size);
135135

136136
return true;
137137
}

fs/nfsd/nfs4callback.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static void encode_nfs_fh4(struct xdr_stream *xdr, const struct knfsd_fh *fh)
121121

122122
BUG_ON(length > NFS4_FHSIZE);
123123
p = xdr_reserve_space(xdr, 4 + length);
124-
xdr_encode_opaque(p, &fh->fh_base, length);
124+
xdr_encode_opaque(p, &fh->fh_raw, length);
125125
}
126126

127127
/*

fs/nfsd/nfs4proc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
519519

520520
fh_put(&cstate->current_fh);
521521
cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
522-
memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval,
522+
memcpy(&cstate->current_fh.fh_handle.fh_raw, putfh->pf_fhval,
523523
putfh->pf_fhlen);
524524
ret = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS);
525525
#ifdef CONFIG_NFSD_V4_2_INTER_SSC
@@ -1383,7 +1383,7 @@ nfsd4_setup_inter_ssc(struct svc_rqst *rqstp,
13831383
s_fh = &cstate->save_fh;
13841384

13851385
copy->c_fh.size = s_fh->fh_handle.fh_size;
1386-
memcpy(copy->c_fh.data, &s_fh->fh_handle.fh_base, copy->c_fh.size);
1386+
memcpy(copy->c_fh.data, &s_fh->fh_handle.fh_raw, copy->c_fh.size);
13871387
copy->stateid.seqid = cpu_to_be32(s_stid->si_generation);
13881388
memcpy(copy->stateid.other, (void *)&s_stid->si_opaque,
13891389
sizeof(stateid_opaque_t));

fs/nfsd/nfs4state.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ static int delegation_blocked(struct knfsd_fh *fh)
10101010
}
10111011
spin_unlock(&blocked_delegations_lock);
10121012
}
1013-
hash = jhash(&fh->fh_base, fh->fh_size, 0);
1013+
hash = jhash(&fh->fh_raw, fh->fh_size, 0);
10141014
if (test_bit(hash&255, bd->set[0]) &&
10151015
test_bit((hash>>8)&255, bd->set[0]) &&
10161016
test_bit((hash>>16)&255, bd->set[0]))
@@ -1029,7 +1029,7 @@ static void block_delegations(struct knfsd_fh *fh)
10291029
u32 hash;
10301030
struct bloom_pair *bd = &blocked_delegations;
10311031

1032-
hash = jhash(&fh->fh_base, fh->fh_size, 0);
1032+
hash = jhash(&fh->fh_raw, fh->fh_size, 0);
10331033

10341034
spin_lock(&blocked_delegations_lock);
10351035
__set_bit(hash&255, bd->set[bd->new]);

fs/nfsd/nfs4xdr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3110,7 +3110,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
31103110
p = xdr_reserve_space(xdr, fhp->fh_handle.fh_size + 4);
31113111
if (!p)
31123112
goto out_resource;
3113-
p = xdr_encode_opaque(p, &fhp->fh_handle.fh_base,
3113+
p = xdr_encode_opaque(p, &fhp->fh_handle.fh_raw,
31143114
fhp->fh_handle.fh_size);
31153115
}
31163116
if (bmval0 & FATTR4_WORD0_FILEID) {
@@ -3667,7 +3667,7 @@ nfsd4_encode_getfh(struct nfsd4_compoundres *resp, __be32 nfserr, struct svc_fh
36673667
p = xdr_reserve_space(xdr, len + 4);
36683668
if (!p)
36693669
return nfserr_resource;
3670-
p = xdr_encode_opaque(p, &fhp->fh_handle.fh_base, len);
3670+
p = xdr_encode_opaque(p, &fhp->fh_handle.fh_raw, len);
36713671
return 0;
36723672
}
36733673

fs/nfsd/nfsctl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,12 @@ static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
395395
auth_domain_put(dom);
396396
if (len)
397397
return len;
398-
398+
399399
mesg = buf;
400400
len = SIMPLE_TRANSACTION_LIMIT;
401-
qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size);
401+
qword_addhex(&mesg, &len, fh.fh_raw, fh.fh_size);
402402
mesg[-1] = '\n';
403-
return mesg - buf;
403+
return mesg - buf;
404404
}
405405

406406
/*

fs/nfsd/nfsfh.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -640,16 +640,11 @@ fh_put(struct svc_fh *fhp)
640640
char * SVCFH_fmt(struct svc_fh *fhp)
641641
{
642642
struct knfsd_fh *fh = &fhp->fh_handle;
643+
static char buf[2+1+1+64*3+1];
643644

644-
static char buf[80];
645-
sprintf(buf, "%d: %08x %08x %08x %08x %08x %08x",
646-
fh->fh_size,
647-
fh->fh_base.fh_pad[0],
648-
fh->fh_base.fh_pad[1],
649-
fh->fh_base.fh_pad[2],
650-
fh->fh_base.fh_pad[3],
651-
fh->fh_base.fh_pad[4],
652-
fh->fh_base.fh_pad[5]);
645+
if (fh->fh_size < 0 || fh->fh_size> 64)
646+
return "bad-fh";
647+
sprintf(buf, "%d: %*ph", fh->fh_size, fh->fh_size, fh->fh_raw);
653648
return buf;
654649
}
655650

fs/nfsd/nfsfh.h

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -43,44 +43,24 @@
4343
* filesystems must not use the values '0' or '0xff'. 'See enum fid_type'
4444
* in include/linux/exportfs.h for currently registered values.
4545
*/
46-
struct nfs_fhbase_new {
47-
union {
48-
struct {
49-
u8 fb_version_aux; /* == 1 */
50-
u8 fb_auth_type_aux;
51-
u8 fb_fsid_type_aux;
52-
u8 fb_fileid_type_aux;
53-
u32 fb_auth[1];
54-
/* u32 fb_fsid[0]; floating */
55-
/* u32 fb_fileid[0]; floating */
56-
};
57-
struct {
58-
u8 fb_version; /* == 1 */
59-
u8 fb_auth_type;
60-
u8 fb_fsid_type;
61-
u8 fb_fileid_type;
62-
u32 fb_auth_flex[]; /* flexible-array member */
63-
};
64-
};
65-
};
6646

6747
struct knfsd_fh {
68-
unsigned int fh_size; /* significant for NFSv3.
69-
* Points to the current size while building
70-
* a new file handle
48+
unsigned int fh_size; /*
49+
* Points to the current size while
50+
* building a new file handle.
7151
*/
7252
union {
73-
u32 fh_pad[NFS4_FHSIZE/4];
74-
struct nfs_fhbase_new fh_new;
75-
} fh_base;
53+
char fh_raw[NFS4_FHSIZE];
54+
struct {
55+
u8 fh_version; /* == 1 */
56+
u8 fh_auth_type; /* deprecated */
57+
u8 fh_fsid_type;
58+
u8 fh_fileid_type;
59+
u32 fh_fsid[]; /* flexible-array member */
60+
};
61+
};
7662
};
7763

78-
#define fh_version fh_base.fh_new.fb_version
79-
#define fh_fsid_type fh_base.fh_new.fb_fsid_type
80-
#define fh_auth_type fh_base.fh_new.fb_auth_type
81-
#define fh_fileid_type fh_base.fh_new.fb_fileid_type
82-
#define fh_fsid fh_base.fh_new.fb_auth_flex
83-
8464
static inline __u32 ino_t_to_u32(ino_t ino)
8565
{
8666
return (__u32) ino;
@@ -255,7 +235,7 @@ static inline void
255235
fh_copy_shallow(struct knfsd_fh *dst, struct knfsd_fh *src)
256236
{
257237
dst->fh_size = src->fh_size;
258-
memcpy(&dst->fh_base, &src->fh_base, src->fh_size);
238+
memcpy(&dst->fh_raw, &src->fh_raw, src->fh_size);
259239
}
260240

261241
static __inline__ struct svc_fh *
@@ -270,7 +250,7 @@ static inline bool fh_match(struct knfsd_fh *fh1, struct knfsd_fh *fh2)
270250
{
271251
if (fh1->fh_size != fh2->fh_size)
272252
return false;
273-
if (memcmp(fh1->fh_base.fh_pad, fh2->fh_base.fh_pad, fh1->fh_size) != 0)
253+
if (memcmp(fh1->fh_raw, fh2->fh_raw, fh1->fh_size) != 0)
274254
return false;
275255
return true;
276256
}
@@ -294,7 +274,7 @@ static inline bool fh_fsid_match(struct knfsd_fh *fh1, struct knfsd_fh *fh2)
294274
*/
295275
static inline u32 knfsd_fh_hash(const struct knfsd_fh *fh)
296276
{
297-
return ~crc32_le(0xFFFFFFFF, (unsigned char *)&fh->fh_base, fh->fh_size);
277+
return ~crc32_le(0xFFFFFFFF, fh->fh_raw, fh->fh_size);
298278
}
299279
#else
300280
static inline u32 knfsd_fh_hash(const struct knfsd_fh *fh)

fs/nfsd/nfsxdr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ svcxdr_decode_fhandle(struct xdr_stream *xdr, struct svc_fh *fhp)
6464
if (!p)
6565
return false;
6666
fh_init(fhp, NFS_FHSIZE);
67-
memcpy(&fhp->fh_handle.fh_base, p, NFS_FHSIZE);
67+
memcpy(&fhp->fh_handle.fh_raw, p, NFS_FHSIZE);
6868
fhp->fh_handle.fh_size = NFS_FHSIZE;
6969

7070
return true;
@@ -78,7 +78,7 @@ svcxdr_encode_fhandle(struct xdr_stream *xdr, const struct svc_fh *fhp)
7878
p = xdr_reserve_space(xdr, NFS_FHSIZE);
7979
if (!p)
8080
return false;
81-
memcpy(p, &fhp->fh_handle.fh_base, NFS_FHSIZE);
81+
memcpy(p, &fhp->fh_handle.fh_raw, NFS_FHSIZE);
8282

8383
return true;
8484
}

0 commit comments

Comments
 (0)