9
0
Fork 0

Refactor nfs_socket.c/.h logic; Those files are not gone

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4878 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2012-06-27 22:03:32 +00:00
parent e69ec941d6
commit 0c12af00bb
7 changed files with 119 additions and 280 deletions

View File

@ -42,7 +42,7 @@ CSRCS +=
# Files required for NFS RPC
ASRCS +=
CSRCS += rpc_clnt.c nfs_socket.c nfs_util.c nfs_vfsops.c
CSRCS += rpc_clnt.c nfs_util.c nfs_vfsops.c
# Argument for dependency checking

View File

@ -124,6 +124,9 @@ EXTERN void nfs_semtake(FAR struct nfsmount *nmp);
EXTERN void nfs_semgive(FAR struct nfsmount *nmp);
EXTERN int nfs_checkmount(FAR struct nfsmount *nmp);
EXTERN int nfs_fsinfo(FAR struct nfsmount *nmp);
EXTERN int nfs_request(struct nfsmount *nmp, int procnum,
FAR void *request, size_t reqlen,
FAR void *response, size_t resplen);
EXTERN int nfs_lookup(FAR struct nfsmount *nmp, FAR const char *filename,
FAR struct file_handle *fhandle,
FAR struct nfs_fattr *obj_attributes,

View File

@ -1,203 +0,0 @@
/****************************************************************************
* fs/nfs/nfs_socket.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2012 Jose Pablo Rojas Vargas. All rights reserved.
* Author: Jose Pablo Rojas Vargas <jrojas@nx-engineering.com>
* Gregory Nutt <gnutt@nuttx.org>
*
* Leveraged from OpenBSD:
*
* copyright (c) 2004
* the regents of the university of michigan
* all rights reserved
*
* permission is granted to use, copy, create derivative works and redistribute
* this software and such derivative works for any purpose, so long as the name
* of the university of michigan is not used in any advertising or publicity
* pertaining to the use or distribution of this software without specific,
* written prior authorization. if the above copyright notice or any other
* identification of the university of michigan is included in any copy of any
* portion of this software, then the disclaimer below must also be included.
*
* this software is provided as is, without representation from the university
* of michigan as to its fitness for any purpose, and without warranty by the
* university of michigan of any kind, either express or implied, including
* without limitation the implied warranties of merchantability and fitness for
* a particular purpose. the regents of the university of michigan shall not be
* liable for any damages, including special, indirect, incidental, or
* consequential damages, with respect to any claim arising out of or in
* connection with the use of the software, even if it has been or is hereafter
* advised of the possibility of such damages.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <sys/socket.h>
#include <queue.h>
#include <time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <debug.h>
#include <nuttx/kmalloc.h>
#include "nfs_proto.h"
#include "nfs_mount.h"
#include "nfs.h"
#include "rpc.h"
#include "xdr_subs.h"
#include "nfs_socket.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Variables
****************************************************************************/
/****************************************************************************
* Public Variables
****************************************************************************/
uint32_t nfs_true;
uint32_t nfs_false;
uint32_t nfs_xdrneg1;
struct nfsstats nfsstats;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nfs_init
****************************************************************************/
void nfs_init(void)
{
nfs_true = txdr_unsigned(TRUE);
nfs_false = txdr_unsigned(FALSE);
nfs_xdrneg1 = txdr_unsigned(-1);
rpcclnt_init();
}
/****************************************************************************
* Name: nfs_connect
****************************************************************************/
int nfs_connect(struct nfsmount *nmp)
{
struct rpcclnt *rpc;
if (nmp == NULL)
{
return EFAULT;
}
/* Create an instance of the rpc state structure */
rpc = (struct rpcclnt *)kzalloc(sizeof(struct rpcclnt));
if (!rpc)
{
fdbg("ERROR: Failed to allocate rpc structure\n");
return ENOMEM;
}
fvdbg("Connecting\n");
/* Translate nfsmnt flags -> rpcclnt flags */
rpc->rc_path = nmp->nm_path;
rpc->rc_name = &nmp->nm_nam;
rpc->rc_sotype = nmp->nm_sotype;
rpc->rc_retry = nmp->nm_retry;
nmp->nm_rpcclnt = rpc;
return rpcclnt_connect(rpc);
}
/****************************************************************************
* Name: nfs_disconnect
*
* Description:
* NFS disconnect. Clean up and unlink.
*
****************************************************************************/
void nfs_disconnect(struct nfsmount *nmp)
{
rpcclnt_disconnect(nmp->nm_rpcclnt);
}
int nfs_request(struct nfsmount *nmp, int procnum,
FAR void *request, size_t reqlen,
FAR void *response, size_t resplen)
{
struct rpcclnt *clnt = nmp->nm_rpcclnt;
struct nfs_reply_header replyh;
int trylater_delay;
int error;
tryagain:
error = rpcclnt_request(clnt, procnum, NFS_PROG, NFS_VER3,
request, reqlen, response, resplen);
if (error != 0)
{
fdbg("ERROR: rpcclnt_request failed: %d\n", error);
return error;
}
memcpy(&replyh, response, sizeof(struct nfs_reply_header));
if (replyh.nfs_status != 0)
{
if (fxdr_unsigned(uint32_t, replyh.nfs_status) > 32)
{
error = EOPNOTSUPP;
}
else
{
/* NFS_ERRORS are the same as NuttX errno values */
error = fxdr_unsigned(uint32_t, replyh.nfs_status);
}
return error;
}
if (replyh.rpc_verfi.authtype != 0)
{
error = fxdr_unsigned(int, replyh.rpc_verfi.authtype);
if (error == EAGAIN)
{
error = 0;
trylater_delay *= NFS_TIMEOUTMUL;
if (trylater_delay > NFS_MAXTIMEO)
{
trylater_delay = NFS_MAXTIMEO;
}
goto tryagain;
}
fdbg("ERROR: NFS error %d from server\n", error);
return error;
}
fvdbg("NFS_SUCCESS\n");
return OK;
}

View File

@ -1,69 +0,0 @@
/****************************************************************************
* fs/nfs/nfs_socket.h
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2012 Jose Pablo Rojas Vargas. All rights reserved.
* Author: Jose Pablo Rojas Vargas <jrojas@nx-engineering.com>
*
* Leveraged from OpenBSD:
*
* copyright (c) 2004
* the regents of the university of michigan
* all rights reserved
*
* permission is granted to use, copy, create derivative works and redistribute
* this software and such derivative works for any purpose, so long as the name
* of the university of michigan is not used in any advertising or publicity
* pertaining to the use or distribution of this software without specific,
* written prior authorization. if the above copyright notice or any other
* identification of the university of michigan is included in any copy of any
* portion of this software, then the disclaimer below must also be included.
*
* this software is provided as is, without representation from the university
* of michigan as to its fitness for any purpose, and without warranty by the
* university of michigan of any kind, either express or implied, including
* without limitation the implied warranties of merchantability and fitness for
* a particular purpose. the regents of the university of michigan shall not be
* liable for any damages, including special, indirect, incidental, or
* consequential damages, with respect to any claim arising out of or in
* connection with the use of the software, even if it has been or is hereafter
* advised of the possibility of such damages.
*
****************************************************************************/
#ifndef __FS_NFS_NFS_SOCKET_H
#define __FS_NFS_NFS_SOCKET_H
/****************************************************************************
* Included Files
****************************************************************************/
/****************************************************************************
* Pre-processor definitions
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C" {
#else
#define EXTERN extern
#endif
EXTERN void nfs_init(void);
EXTERN int nfs_connect(struct nfsmount *nmp);
EXTERN void nfs_disconnect(struct nfsmount *nmp);
EXTERN int nfs_request(struct nfsmount *nmp, int procnum,
FAR void *request, size_t reqlen,
FAR void *response, size_t resplen);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __FS_NFS_NFS_SOCKET_H */

View File

@ -58,7 +58,6 @@
#include "nfs_proto.h"
#include "nfs_mount.h"
#include "nfs_node.h"
#include "nfs_socket.h"
#include "xdr_subs.h"
/****************************************************************************
@ -196,6 +195,78 @@ int nfs_checkmount(struct nfsmount *nmp)
return 0;
}
/****************************************************************************
* Name: nfs_request
*
* Desciption:
* Perform the NFS request. On successful receipt, it verifies the NFS level of the
* returned values.
*
* Return Value:
* Zero on success; a positive errno value on failure.
*
****************************************************************************/
int nfs_request(struct nfsmount *nmp, int procnum,
FAR void *request, size_t reqlen,
FAR void *response, size_t resplen)
{
struct rpcclnt *clnt = nmp->nm_rpcclnt;
struct nfs_reply_header replyh;
int trylater_delay;
int error;
tryagain:
error = rpcclnt_request(clnt, procnum, NFS_PROG, NFS_VER3,
request, reqlen, response, resplen);
if (error != 0)
{
fdbg("ERROR: rpcclnt_request failed: %d\n", error);
return error;
}
memcpy(&replyh, response, sizeof(struct nfs_reply_header));
if (replyh.nfs_status != 0)
{
if (fxdr_unsigned(uint32_t, replyh.nfs_status) > 32)
{
error = EOPNOTSUPP;
}
else
{
/* NFS_ERRORS are the same as NuttX errno values */
error = fxdr_unsigned(uint32_t, replyh.nfs_status);
}
return error;
}
if (replyh.rpc_verfi.authtype != 0)
{
error = fxdr_unsigned(int, replyh.rpc_verfi.authtype);
if (error == EAGAIN)
{
error = 0;
trylater_delay *= NFS_TIMEOUTMUL;
if (trylater_delay > NFS_MAXTIMEO)
{
trylater_delay = NFS_MAXTIMEO;
}
goto tryagain;
}
fdbg("ERROR: NFS error %d from server\n", error);
return error;
}
fvdbg("NFS_SUCCESS\n");
return OK;
}
/****************************************************************************
* Name: nfs_lookup
*

View File

@ -81,7 +81,6 @@
#include "nfs_node.h"
#include "nfs_mount.h"
#include "xdr_subs.h"
#include "nfs_socket.h"
/****************************************************************************
* Pre-processor Definitions
@ -103,6 +102,18 @@
# error "Length of cookie verify in fs_dirent_s is incorrect"
#endif
/****************************************************************************
* Public Variables
****************************************************************************/
uint32_t nfs_true;
uint32_t nfs_false;
uint32_t nfs_xdrneg1;
#ifdef CONFIG_NFS_STATISTICS
struct nfsstats nfsstats;
#endif
/****************************************************************************
* Private Type Definitions
****************************************************************************/
@ -947,6 +958,7 @@ static ssize_t nfs_write(FAR struct file *filep, const char *buffer,
/* Now loop until we send the entire user buffer */
writesize = 0;
for (byteswritten = 0; byteswritten < buflen; )
{
/* Make sure that the attempted write size does not exceed the RPC maximum */
@ -1578,6 +1590,7 @@ static int nfs_bind(FAR struct inode *blkdriver, FAR const void *data,
{
FAR struct nfs_args *argp = (FAR struct nfs_args *)data;
FAR struct nfsmount *nmp;
struct rpcclnt *rpc;
struct rpc_call_fs getattr;
struct rpc_reply_getattr resok;
struct nfs_mount_parameters nprmt;
@ -1643,7 +1656,11 @@ static int nfs_bind(FAR struct inode *blkdriver, FAR const void *data,
/* Initialize NFS */
nfs_init();
nfs_true = txdr_unsigned(TRUE);
nfs_false = txdr_unsigned(FALSE);
nfs_xdrneg1 = txdr_unsigned(-1);
rpcclnt_init();
/* Set initial values of other fields */
@ -1665,7 +1682,27 @@ static int nfs_bind(FAR struct inode *blkdriver, FAR const void *data,
{
/* Connection-less... connect now */
error = nfs_connect(nmp);
/* Create an instance of the rpc state structure */
rpc = (struct rpcclnt *)kzalloc(sizeof(struct rpcclnt));
if (!rpc)
{
fdbg("ERROR: Failed to allocate rpc structure\n");
return ENOMEM;
}
fvdbg("Connecting\n");
/* Translate nfsmnt flags -> rpcclnt flags */
rpc->rc_path = nmp->nm_path;
rpc->rc_name = &nmp->nm_nam;
rpc->rc_sotype = nmp->nm_sotype;
rpc->rc_retry = nmp->nm_retry;
nmp->nm_rpcclnt = rpc;
error = rpcclnt_connect(nmp->nm_rpcclnt);
if (error != OK)
{
fdbg("ERROR: nfs_connect failed: %d\n", error);
@ -1708,7 +1745,7 @@ bad:
{
/* Disconnect from the server */
nfs_disconnect(nmp);
rpcclnt_disconnect(nmp->nm_rpcclnt);
/* Free connection-related resources */
@ -1772,7 +1809,7 @@ int nfs_unbind(FAR void *handle, FAR struct inode **blkdriver)
/* Disconnect from the server */
nfs_disconnect(nmp);
rpcclnt_disconnect(nmp->nm_rpcclnt);
/* And free any allocated resources */

View File

@ -682,7 +682,7 @@ bad:
* Name: rpcclnt_request
*
* Description:
* Perform the RPC reqquest. Logic formats the RPC CALL message and calls
* Perform the RPC request. Logic formats the RPC CALL message and calls
* rpcclnt_send to send the RPC CALL message. It then calls rpcclnt_reply()
* to get the response. It may attempt to re-send the CALL message on
* certain errors.