From 37b9bbbdef38f07e4c35346fc1b335ae9af86905 Mon Sep 17 00:00:00 2001 From: zhangyuan7 Date: Sun, 26 Aug 2018 13:11:24 -0600 Subject: [PATCH] fs/nfs: Update nfs mount to VER3 --- fs/nfs/nfs_proto.h | 9 ++++++--- fs/nfs/nfs_vfsops.c | 14 ++++++++++++-- fs/nfs/rpc.h | 33 +++++++++++++++++++++++---------- fs/nfs/rpc_clnt.c | 11 ++++++----- 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/fs/nfs/nfs_proto.h b/fs/nfs/nfs_proto.h index 282706f21a..488f8a7dbb 100644 --- a/fs/nfs/nfs_proto.h +++ b/fs/nfs/nfs_proto.h @@ -1,7 +1,7 @@ /**************************************************************************** * fs/nfs/nfs_proto.h * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2018 Gregory Nutt. All rights reserved. * Copyright (C) 2012 Jose Pablo Rojas Vargas. All rights reserved. * Author: Jose Pablo Rojas Vargas * Gregory Nutt @@ -112,7 +112,7 @@ #define NFSERR_AUTHERR 0x40000000 /* Mark an authentication error */ #define NFSERR_RETERR 0x80000000 /* Mark an error return for V3 */ -/* Sizes in bytes of various nfs rpc components */ +/* Sizes in bytes of various NFS RPC components */ #define NFSX_UNSIGNED 4 @@ -159,7 +159,6 @@ #define NFSPROC_NOOP 22 #define NFS_NPROCS 23 - /* Constants used by the Version 3 protocol for various RPCs */ #define NFSV3SATTRTIME_DONTCHANGE 0 @@ -562,6 +561,10 @@ struct READDIR3resok uint32_t reply[1]; /* Variable length reply begins here */ }; +#define SIZEOF_READDIR3resok(n) \ + (sizeof(uint32_t) + sizeof(struct nfs_fattr) + \ + NFSX_V3COOKIEVERF + sizeof(uint32_t) + (n)) + struct FS3args { struct file_handle fsroot; diff --git a/fs/nfs/nfs_vfsops.c b/fs/nfs/nfs_vfsops.c index 41fbfc46ff..85840c981f 100644 --- a/fs/nfs/nfs_vfsops.c +++ b/fs/nfs/nfs_vfsops.c @@ -182,6 +182,7 @@ static int nfs_stat(struct inode *mountpt, FAR const char *relpath, /**************************************************************************** * Public Data ****************************************************************************/ + /* nfs vfs operations. */ const struct mountpt_operations nfs_operations = @@ -1414,6 +1415,7 @@ static int nfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir) struct nfsmount *nmp; struct file_handle fhandle; struct nfs_fattr obj_attributes; + uint32_t readsize; uint32_t tmp; uint32_t *ptr; uint8_t *name; @@ -1470,8 +1472,15 @@ static int nfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir) /* Number of directory entries (We currently only process one entry at a time) */ - *ptr = txdr_unsigned(nmp->nm_readdirsize); - reqlen += sizeof(uint32_t); + readsize = nmp->nm_readdirsize; + tmp = SIZEOF_rpc_reply_readdir(readsize); + if (tmp > nmp->nm_buflen) + { + readsize -= (tmp - nmp->nm_buflen); + } + + *ptr = txdr_unsigned(readsize); + reqlen += sizeof(uint32_t); /* And read the directory */ @@ -1949,6 +1958,7 @@ static int nfs_bind(FAR struct inode *blkdriver, FAR const void *data, nmp->nm_mounted = true; nmp->nm_so = nmp->nm_rpcclnt->rc_so; + nmp->nm_fhsize = nmp->nm_rpcclnt->rc_fhsize; memcpy(&nmp->nm_fh, &nmp->nm_rpcclnt->rc_fh, sizeof(nfsfh_t)); /* Get the file attributes */ diff --git a/fs/nfs/rpc.h b/fs/nfs/rpc.h index 27366557d4..d3924745f3 100644 --- a/fs/nfs/rpc.h +++ b/fs/nfs/rpc.h @@ -202,22 +202,27 @@ struct call_args_umount char rpath[90]; }; -struct call_result_mount -{ - uint32_t status; - nfsfh_t fhandle; -}; - -/* Generic RPC call headers */ - enum auth_flavor { AUTH_NONE = 0, AUTH_SYS = 1, - AUTH_SHORT = 2 + AUTH_SHORT = 2, + AUTH_DES = 3, + AUTH_MAX + /* and more to be defined */ }; +struct call_result_mount +{ + uint32_t status; + struct file_handle fhandle; + uint32_t authlen; + uint32_t autolist[AUTH_MAX]; +}; + +/* Generic RPC call headers */ + struct rpc_auth_info { uint32_t authtype; /* auth type */ @@ -396,7 +401,10 @@ struct rpc_reply_read uint32_t status; struct READ3resok read; /* Variable length */ }; -#define SIZEOF_rpc_reply_read(n) (sizeof(struct rpc_reply_header) + sizeof(uint32_t) + SIZEOF_READ3resok(n)) + +#define SIZEOF_rpc_reply_read(n) \ + (sizeof(struct rpc_reply_header) + sizeof(uint32_t) + \ + SIZEOF_READ3resok(n)) struct rpc_reply_remove { @@ -433,6 +441,10 @@ struct rpc_reply_readdir struct READDIR3resok readdir; }; +#define SIZEOF_rpc_reply_readdir(n) \ + (sizeof(struct rpc_reply_header) + sizeof(uint32_t) + \ + SIZEOF_READDIR3resok(n)) + struct rpc_reply_fsinfo { struct rpc_reply_header rh; @@ -464,6 +476,7 @@ struct rpc_reply_setattr struct rpcclnt { nfsfh_t rc_fh; /* File handle of the root directory */ + uint8_t rc_fhsize; /* File size of the root directory */ char *rc_path; /* Server's path of the mounted directory */ struct sockaddr *rc_name; diff --git a/fs/nfs/rpc_clnt.c b/fs/nfs/rpc_clnt.c index f34c332a8a..800c85c1be 100644 --- a/fs/nfs/rpc_clnt.c +++ b/fs/nfs/rpc_clnt.c @@ -475,7 +475,7 @@ int rpcclnt_connect(struct rpcclnt *rpc) */ request.sdata.pmap.prog = txdr_unsigned(RPCPROG_MNT); - request.sdata.pmap.vers = txdr_unsigned(RPCMNT_VER1); + request.sdata.pmap.vers = txdr_unsigned(RPCMNT_VER3); request.sdata.pmap.proc = txdr_unsigned(IPPROTO_UDP); request.sdata.pmap.port = 0; @@ -504,7 +504,7 @@ int rpcclnt_connect(struct rpcclnt *rpc) strncpy(request.mountd.mount.rpath, rpc->rc_path, 90); request.mountd.mount.len = txdr_unsigned(sizeof(request.mountd.mount.rpath)); - error = rpcclnt_request(rpc, RPCMNT_MOUNT, RPCPROG_MNT, RPCMNT_VER1, + error = rpcclnt_request(rpc, RPCMNT_MOUNT, RPCPROG_MNT, RPCMNT_VER3, (FAR void *)&request.mountd, sizeof(struct call_args_mount), (FAR void *)&response.mdata, sizeof(struct rpc_reply_mount)); if (error != 0) @@ -520,7 +520,8 @@ int rpcclnt_connect(struct rpcclnt *rpc) goto bad; } - memcpy(&rpc->rc_fh, &response.mdata.mount.fhandle, sizeof(nfsfh_t)); + rpc->rc_fhsize = fxdr_unsigned(uint32_t, response.mdata.mount.fhandle.length); + memcpy(&rpc->rc_fh, &response.mdata.mount.fhandle.handle, rpc->rc_fhsize); /* Do the RPC to get a dynamic bounding with the server using PMAP. * NFS port in the socket. @@ -630,7 +631,7 @@ int rpcclnt_umount(struct rpcclnt *rpc) } request.sdata.pmap.prog = txdr_unsigned(RPCPROG_MNT); - request.sdata.pmap.vers = txdr_unsigned(RPCMNT_VER1); + request.sdata.pmap.vers = txdr_unsigned(RPCMNT_VER3); request.sdata.pmap.proc = txdr_unsigned(IPPROTO_UDP); request.sdata.pmap.port = 0; @@ -659,7 +660,7 @@ int rpcclnt_umount(struct rpcclnt *rpc) strncpy(request.mountd.umount.rpath, rpc->rc_path, 92); request.mountd.umount.len = txdr_unsigned(sizeof(request.mountd.umount.rpath)); - error = rpcclnt_request(rpc, RPCMNT_UMOUNT, RPCPROG_MNT, RPCMNT_VER1, + error = rpcclnt_request(rpc, RPCMNT_UMOUNT, RPCPROG_MNT, RPCMNT_VER3, (FAR void *)&request.mountd, sizeof(struct call_args_umount), (FAR void *)&response.mdata, sizeof(struct rpc_reply_umount)); if (error != 0)