Add NFS rewinddir support; fixe some NFS warnings

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4844 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2012-06-14 21:54:50 +00:00
parent b356619d7c
commit bf1542f7ab
4 changed files with 78 additions and 38 deletions

View File

@ -47,39 +47,32 @@
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include "nfs_mount.h" #include "nfs_mount.h"
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#if MSEC_PER_TICK <= 5 #define NFS_TICKINTVL MSEC_PER_TICK /* Smallest that we can get */
# define NFS_TICKINTVL 5 /* Desired time for a tick (msec) */ #define NFS_TICKS 1 /* Number of system ticks */
# define NFS_TICKS (CLOCKS_PER_SEC * NFS_TICKINTVL + 500) / 1000 #define NFS_HZ CLOCKS_PER_SEC /* Ticks/sec */
# define NFS_HZ (CLOCKS_PER_SEC / NFS_TICKS) /* Ticks/sec */ #define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */
#else #define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */
# define NFS_TICKINTVL MSEC_PER_TICK /* Smallest that we can get */ #define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */
# define NFS_TICKS 1 /* Number of system ticks */ #define NFS_TIMEOUTMUL 2 /* Timeout/Delay multiplier */
# define NFS_HZ CLOCKS_PER_SEC /* Ticks/sec */ #define NFS_MAXREXMIT 100 /* Stop counting after this many */
#endif #define NFS_RETRANS 10 /* Num of retrans for soft mounts */
#define NFS_WSIZE 8192 /* Def. write data size <= 8192 */
#define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */ #define NFS_RSIZE 8192 /* Def. read data size <= 8192 */
#define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */ #define NFS_READDIRSIZE 8192 /* Def. readdir size */
#define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */
#define NFS_TIMEOUTMUL 2 /* Timeout/Delay multiplier */
#define NFS_MAXREXMIT 100 /* Stop counting after this many */
#define NFS_RETRANS 10 /* Num of retrans for soft mounts */
#define NFS_WSIZE 8192 /* Def. write data size <= 8192 */
#define NFS_RSIZE 8192 /* Def. read data size <= 8192 */
#define NFS_READDIRSIZE 8192 /* Def. readdir size */
#define NFS_NPROCS 23 #define NFS_NPROCS 23
/* Ideally, NFS_DIRBLKSIZ should be bigger, but I've seen servers with /* Ideally, NFS_DIRBLKSIZ should be bigger, but I've seen servers with
* broken NFS/ethernet drivers that won't work with anything bigger (Linux..) * broken NFS/ethernet drivers that won't work with anything bigger (Linux..)
*/ */
#define NFS_DIRBLKSIZ 1024 /* Must be a multiple of DIRBLKSIZ */ #define NFS_DIRBLKSIZ 1024 /* Must be a multiple of DIRBLKSIZ */
/* Increment NFS statistics */ /* Increment NFS statistics */

View File

@ -77,8 +77,8 @@ struct nfsmount
bool nm_mounted; /* true: The file system is ready */ bool nm_mounted; /* true: The file system is ready */
uint8_t nm_fhsize; /* Size of root file handle (host order) */ uint8_t nm_fhsize; /* Size of root file handle (host order) */
uint8_t nm_sotype; /* Type of socket */ uint8_t nm_sotype; /* Type of socket */
uint8_t nm_timeo; /* Init timer */
uint8_t nm_retry; /* Max retries */ uint8_t nm_retry; /* Max retries */
uint16_t nm_timeo; /* Timeout value (in system clock ticks) */
uint16_t nm_rsize; /* Max size of read RPC */ uint16_t nm_rsize; /* Max size of read RPC */
uint16_t nm_wsize; /* Max size of write RPC */ uint16_t nm_wsize; /* Max size of write RPC */
uint16_t nm_readdirsize; /* Size of a readdir RPC */ uint16_t nm_readdirsize; /* Size of a readdir RPC */
@ -130,7 +130,7 @@ struct nfsmount
struct nfs_mount_parameters struct nfs_mount_parameters
{ {
uint8_t timeo; /* Init timer */ uint8_t timeo; /* Timeout value (in deciseconds) */
uint8_t retry; /* Max retries */ uint8_t retry; /* Max retries */
uint16_t rsize; /* Max size of read RPC */ uint16_t rsize; /* Max size of read RPC */
uint16_t wsize; /* Max size of write RPC */ uint16_t wsize; /* Max size of write RPC */

View File

@ -125,6 +125,10 @@ static ssize_t nfs_write(FAR struct file *filep, const char *buffer,
static int nfs_opendir(struct inode *mountpt, const char *relpath, static int nfs_opendir(struct inode *mountpt, const char *relpath,
struct fs_dirent_s *dir); struct fs_dirent_s *dir);
static int nfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir); static int nfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir);
static int nfs_rewinddir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
static void nfs_decode_args(FAR struct nfs_mount_parameters *nprmt,
FAR struct nfs_args *argp);
static int nfs_bind(FAR struct inode *blkdriver, const void *data, static int nfs_bind(FAR struct inode *blkdriver, const void *data,
void **handle); void **handle);
static int nfs_unbind(void *handle, FAR struct inode **blkdriver); static int nfs_unbind(void *handle, FAR struct inode **blkdriver);
@ -156,7 +160,7 @@ const struct mountpt_operations nfs_operations =
nfs_opendir, /* opendir */ nfs_opendir, /* opendir */
NULL, /* closedir */ NULL, /* closedir */
nfs_readdir, /* readdir */ nfs_readdir, /* readdir */
NULL, /* rewinddir */ nfs_rewinddir, /* rewinddir */
nfs_bind, /* bind */ nfs_bind, /* bind */
nfs_unbind, /* unbind */ nfs_unbind, /* unbind */
@ -365,7 +369,8 @@ static int nfs_filecreate(FAR struct nfsmount *nmp, struct nfsnode *np,
* Name: nfs_fileopen * Name: nfs_fileopen
* *
* Description: * Description:
* Truncate an open file to zero length. * Truncate an open file to zero length. This is part of the file open
* logic.
* *
* Returned Value: * Returned Value:
* 0 on success; a positive errno value on failure. * 0 on success; a positive errno value on failure.
@ -1389,6 +1394,36 @@ errout_with_semaphore:
return -error; return -error;
} }
/****************************************************************************
* Name: nfs_rewinddir
*
* Description:
* Reset the directory traveral logic to the first entry in the open
* directory.
*
* Returned Value:
* 0 on success; a negated errno value on failure.
*
****************************************************************************/
static int nfs_rewinddir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir)
{
fvdbg("Entry\n");
/* Sanity checks */
DEBUGASSERT(mountpt != NULL && dir != NULL);
/* Reset the NFS-specific portions of dirent structure, retaining only the
* file handle.
*/
memset(&dir->u.nfs.nfs_verifier, 0, DIRENT_NFS_VERFLEN);
dir->u.nfs.nfs_cookie[0] = 0;
dir->u.nfs.nfs_cookie[1] = 0;
return OK;
}
/**************************************************************************** /****************************************************************************
* Name: nfs_decode_args * Name: nfs_decode_args
* *
@ -1397,25 +1432,29 @@ errout_with_semaphore:
* *
****************************************************************************/ ****************************************************************************/
void nfs_decode_args(struct nfs_mount_parameters *nprmt, struct nfs_args *argp) static void nfs_decode_args(FAR struct nfs_mount_parameters *nprmt,
FAR struct nfs_args *argp)
{ {
int maxio; int maxio;
/* Update flags atomically. Don't change the lock bits. */ /* Get the selected timeout value */
if ((argp->flags & NFSMNT_TIMEO) != 0 && argp->timeo > 0) if ((argp->flags & NFSMNT_TIMEO) != 0 && argp->timeo > 0)
{ {
nprmt->timeo = (argp->timeo * NFS_HZ + 5) / 10; uint32_t tmp = ((uint32_t)argp->timeo * NFS_HZ + 5) / 10;
if (nprmt->timeo < NFS_MINTIMEO) if (tmp < NFS_MINTIMEO)
{ {
nprmt->timeo = NFS_MINTIMEO; tmp = NFS_MINTIMEO;
} }
else if (nprmt->timeo > NFS_MAXTIMEO) else if (tmp > NFS_MAXTIMEO)
{ {
nprmt->timeo = NFS_MAXTIMEO; tmp = NFS_MAXTIMEO;
} }
nprmt->timeo = tmp;
} }
/* Get the selected retransmission count */
if ((argp->flags & NFSMNT_RETRANS) != 0 && argp->retrans > 1) if ((argp->flags & NFSMNT_RETRANS) != 0 && argp->retrans > 1)
{ {
if (argp->retrans < NFS_MAXREXMIT) if (argp->retrans < NFS_MAXREXMIT)
@ -1433,6 +1472,8 @@ void nfs_decode_args(struct nfs_mount_parameters *nprmt, struct nfs_args *argp)
nprmt->retry = NFS_MAXREXMIT + 1; /* Past clip limit */ nprmt->retry = NFS_MAXREXMIT + 1; /* Past clip limit */
} }
/* Get the maximum amount of data that can be transferred in one packet */
if ((argp->sotype == SOCK_DGRAM) != 0) if ((argp->sotype == SOCK_DGRAM) != 0)
{ {
maxio = NFS_MAXDGRAMDATA; maxio = NFS_MAXDGRAMDATA;
@ -1443,6 +1484,8 @@ void nfs_decode_args(struct nfs_mount_parameters *nprmt, struct nfs_args *argp)
maxio = NFS_MAXDATA; maxio = NFS_MAXDATA;
} }
/* Get the maximum amount of data that can be transferred in one write transfer */
if ((argp->flags & NFSMNT_WSIZE) != 0 && argp->wsize > 0) if ((argp->flags & NFSMNT_WSIZE) != 0 && argp->wsize > 0)
{ {
nprmt->wsize = argp->wsize; nprmt->wsize = argp->wsize;
@ -1466,6 +1509,8 @@ void nfs_decode_args(struct nfs_mount_parameters *nprmt, struct nfs_args *argp)
nprmt->wsize = MAXBSIZE; nprmt->wsize = MAXBSIZE;
} }
/* Get the maximum amount of data that can be transferred in one read transfer */
if ((argp->flags & NFSMNT_RSIZE) != 0 && argp->rsize > 0) if ((argp->flags & NFSMNT_RSIZE) != 0 && argp->rsize > 0)
{ {
nprmt->rsize = argp->rsize; nprmt->rsize = argp->rsize;
@ -1489,6 +1534,8 @@ void nfs_decode_args(struct nfs_mount_parameters *nprmt, struct nfs_args *argp)
nprmt->rsize = MAXBSIZE; nprmt->rsize = MAXBSIZE;
} }
/* Get the maximum amount of data that can be transferred in directory transfer */
if ((argp->flags & NFSMNT_READDIRSIZE) != 0 && argp->readdirsize > 0) if ((argp->flags & NFSMNT_READDIRSIZE) != 0 && argp->readdirsize > 0)
{ {
nprmt->readdirsize = argp->readdirsize; nprmt->readdirsize = argp->readdirsize;
@ -1515,11 +1562,11 @@ void nfs_decode_args(struct nfs_mount_parameters *nprmt, struct nfs_args *argp)
/**************************************************************************** /****************************************************************************
* Name: nfs_bind * Name: nfs_bind
* *
* Description: This implements a portion of the mount operation. This * Description:
* function allocates and initializes the mountpoint private data and * This implements a portion of the mount operation. This function allocates
* binds the blockdriver inode to the filesystem private data. The final * and initializes the mountpoint private data and gets mount information
* binding of the private data (containing the blockdriver) to the * from the NFS server. The final binding of the private data (containing
* mountpoint is performed by mount(). * NFS server mount information) to the mountpoint is performed by mount().
* *
* Returned Value: * Returned Value:
* 0 on success; a negated errno value on failure. * 0 on success; a negated errno value on failure.

View File

@ -75,7 +75,7 @@ struct nfs_args
uint8_t addrlen; /* Length of address */ uint8_t addrlen; /* Length of address */
uint8_t sotype; /* Socket type */ uint8_t sotype; /* Socket type */
uint8_t flags; /* Flags, determines if following are valid: */ uint8_t flags; /* Flags, determines if following are valid: */
uint8_t timeo; /* Initial timeout in .1 secs (with NFSMNT_TIMEO) */ uint8_t timeo; /* Time value in deciseconds (with NFSMNT_TIMEO) */
uint8_t retrans; /* Times to retry send (with NFSMNT_RETRANS) */ uint8_t retrans; /* Times to retry send (with NFSMNT_RETRANS) */
uint16_t wsize; /* Write size in bytes (with NFSMNT_WSIZE) */ uint16_t wsize; /* Write size in bytes (with NFSMNT_WSIZE) */
uint16_t rsize; /* Read size in bytes (with NFSMNT_RSIZE) */ uint16_t rsize; /* Read size in bytes (with NFSMNT_RSIZE) */