From 56224ea316165af86d3db983464e40e1b5b2ac63 Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 27 Jun 2012 22:03:32 +0000 Subject: Refactor nfs_socket.c/.h logic; Those files are not gone git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4878 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/fs/nfs/Make.defs | 2 +- nuttx/fs/nfs/nfs.h | 3 + nuttx/fs/nfs/nfs_socket.c | 203 ---------------------------------------------- nuttx/fs/nfs/nfs_socket.h | 69 ---------------- nuttx/fs/nfs/nfs_util.c | 73 ++++++++++++++++- nuttx/fs/nfs/nfs_vfsops.c | 47 +++++++++-- nuttx/fs/nfs/rpc_clnt.c | 2 +- 7 files changed, 119 insertions(+), 280 deletions(-) delete mode 100644 nuttx/fs/nfs/nfs_socket.c delete mode 100644 nuttx/fs/nfs/nfs_socket.h diff --git a/nuttx/fs/nfs/Make.defs b/nuttx/fs/nfs/Make.defs index c3c323bc3..fc4682f85 100644 --- a/nuttx/fs/nfs/Make.defs +++ b/nuttx/fs/nfs/Make.defs @@ -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 diff --git a/nuttx/fs/nfs/nfs.h b/nuttx/fs/nfs/nfs.h index dfff4a96d..af24357a4 100644 --- a/nuttx/fs/nfs/nfs.h +++ b/nuttx/fs/nfs/nfs.h @@ -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, diff --git a/nuttx/fs/nfs/nfs_socket.c b/nuttx/fs/nfs/nfs_socket.c deleted file mode 100644 index b0159372e..000000000 --- a/nuttx/fs/nfs/nfs_socket.c +++ /dev/null @@ -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 - * Gregory Nutt - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#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; -} diff --git a/nuttx/fs/nfs/nfs_socket.h b/nuttx/fs/nfs/nfs_socket.h deleted file mode 100644 index 32485b310..000000000 --- a/nuttx/fs/nfs/nfs_socket.h +++ /dev/null @@ -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 - * - * 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 */ diff --git a/nuttx/fs/nfs/nfs_util.c b/nuttx/fs/nfs/nfs_util.c index 8ab3e974e..33c5f0a89 100644 --- a/nuttx/fs/nfs/nfs_util.c +++ b/nuttx/fs/nfs/nfs_util.c @@ -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 * diff --git a/nuttx/fs/nfs/nfs_vfsops.c b/nuttx/fs/nfs/nfs_vfsops.c index 12c4705dd..3cd5a47dc 100644 --- a/nuttx/fs/nfs/nfs_vfsops.c +++ b/nuttx/fs/nfs/nfs_vfsops.c @@ -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 */ diff --git a/nuttx/fs/nfs/rpc_clnt.c b/nuttx/fs/nfs/rpc_clnt.c index 08855647c..0e2a394ba 100644 --- a/nuttx/fs/nfs/rpc_clnt.c +++ b/nuttx/fs/nfs/rpc_clnt.c @@ -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. -- cgit v1.2.3