rtemsbsd/nfs: Add support to mount NFSv2

- NFSv2 requires userland RPC calls to determine the version of
  NFS and the FH. This is passed to the kernel.

- Port more libc/rpc.

Update #4475
This commit is contained in:
Chris Johns 2021-08-31 18:46:37 +10:00
parent 882425fe54
commit 7e282d2506
13 changed files with 1006 additions and 109 deletions

View File

@ -60,7 +60,7 @@ pci = on
pf = on pf = on
regulator = on regulator = on
rpc = on rpc = on
rpc_user = off rpc_user = on
rtems = on rtems = on
tests = on tests = on
tty = on tty = on

View File

@ -1,6 +1,5 @@
NET_CFG_INTERFACE_0 = lo0 NET_CFG_INTERFACE_0 = lo0
NET_CFG_SELF_IP = 10.0.2.1 NET_CFG_SELF_IP = 192.168.0.10
NET_CFG_NETMASK = 255.255.0.0 NET_CFG_NETMASK = 255.255.0.0
NET_CFG_PEER_IP = 192.168.100.11 NET_CFG_PEER_IP = 192.168.0.20
NET_CFG_GATEWAY_IP = 192.168.100.11 NET_CFG_GATEWAY_IP = 192.168.0.1
NET_CFG_NFS_MOUNT_PATH = 192.168.100.11:/srv/nfs

View File

@ -191,20 +191,27 @@ authunix_create_default(void)
gid_t gid; gid_t gid;
gid_t *gids; gid_t *gids;
#ifndef __rtems__
ngids_max = sysconf(_SC_NGROUPS_MAX) + 1; ngids_max = sysconf(_SC_NGROUPS_MAX) + 1;
gids = malloc(sizeof(gid_t) * ngids_max); gids = malloc(sizeof(gid_t) * ngids_max);
if (gids == NULL) if (gids == NULL)
return (NULL); return (NULL);
#endif /* __rtems__ */
if (gethostname(machname, sizeof machname) == -1) if (gethostname(machname, sizeof machname) == -1)
abort(); abort();
machname[sizeof(machname) - 1] = 0; machname[sizeof(machname) - 1] = 0;
uid = geteuid(); uid = geteuid();
gid = getegid(); gid = getegid();
#ifndef __rtems__
if ((ngids = getgroups(ngids_max, gids)) < 0) if ((ngids = getgroups(ngids_max, gids)) < 0)
abort(); abort();
if (ngids > NGRPS) if (ngids > NGRPS)
ngids = NGRPS; ngids = NGRPS;
#else /* __rtems__ */
ngids = 0;
gids = NULL;
#endif /* __rtems__ */
/* XXX: interface problem; we should translate from uid_t and gid_t */ /* XXX: interface problem; we should translate from uid_t and gid_t */
auth = authunix_create(machname, uid, gid, ngids, gids); auth = authunix_create(machname, uid, gid, ngids, gids);
free(gids); free(gids);

View File

@ -67,6 +67,12 @@ __FBSDID("$FreeBSD$");
#include "mt_misc.h" #include "mt_misc.h"
#ifdef __rtems__
#undef thr_sigsetmask
#define thr_sigsetmask(_a, _b, _c)
#define cond_signal(_a)
#define sigfillset(_a)
#endif /* __rtems__ */
#ifdef _FREEFALL_CONFIG #ifdef _FREEFALL_CONFIG
/* /*
* Disable RPC exponential back-off for FreeBSD.org systems. * Disable RPC exponential back-off for FreeBSD.org systems.
@ -204,10 +210,12 @@ clnt_dg_create(int fd, const struct netbuf *svcaddr, rpcprog_t program,
thr_sigsetmask(SIG_SETMASK, &(mask), NULL); thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
goto err1; goto err1;
} else { } else {
#ifndef __rtems__
int i; int i;
for (i = 0; i < dtbsize; i++) for (i = 0; i < dtbsize; i++)
cond_init(&dg_cv[i], 0, (void *) 0); cond_init(&dg_cv[i], 0, (void *) 0);
#endif /* __rtems__ */
} }
} }
@ -345,8 +353,10 @@ clnt_dg_call(CLIENT *cl, rpcproc_t proc, xdrproc_t xargs, void *argsp,
sigfillset(&newmask); sigfillset(&newmask);
thr_sigsetmask(SIG_SETMASK, &newmask, &mask); thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
mutex_lock(&clnt_fd_lock); mutex_lock(&clnt_fd_lock);
#ifndef __rtems__
while (dg_fd_locks[cu->cu_fd]) while (dg_fd_locks[cu->cu_fd])
cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock); cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock);
#endif /* __rtems__ */
if (__isthreaded) if (__isthreaded)
rpc_lock_value = 1; rpc_lock_value = 1;
else else
@ -630,8 +640,10 @@ clnt_dg_freeres(CLIENT *cl, xdrproc_t xdr_res, void *res_ptr)
sigfillset(&newmask); sigfillset(&newmask);
thr_sigsetmask(SIG_SETMASK, &newmask, &mask); thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
mutex_lock(&clnt_fd_lock); mutex_lock(&clnt_fd_lock);
#ifndef __rtems__
while (dg_fd_locks[cu->cu_fd]) while (dg_fd_locks[cu->cu_fd])
cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock); cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock);
#endif /* __rtems__ */
xdrs->x_op = XDR_FREE; xdrs->x_op = XDR_FREE;
dummy = (*xdr_res)(xdrs, res_ptr); dummy = (*xdr_res)(xdrs, res_ptr);
mutex_unlock(&clnt_fd_lock); mutex_unlock(&clnt_fd_lock);
@ -658,8 +670,10 @@ clnt_dg_control(CLIENT *cl, u_int request, void *info)
sigfillset(&newmask); sigfillset(&newmask);
thr_sigsetmask(SIG_SETMASK, &newmask, &mask); thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
mutex_lock(&clnt_fd_lock); mutex_lock(&clnt_fd_lock);
#ifndef __rtems__
while (dg_fd_locks[cu->cu_fd]) while (dg_fd_locks[cu->cu_fd])
cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock); cond_wait(&dg_cv[cu->cu_fd], &clnt_fd_lock);
#endif * __rtems__ */
if (__isthreaded) if (__isthreaded)
rpc_lock_value = 1; rpc_lock_value = 1;
else else
@ -800,8 +814,10 @@ clnt_dg_destroy(CLIENT *cl)
sigfillset(&newmask); sigfillset(&newmask);
thr_sigsetmask(SIG_SETMASK, &newmask, &mask); thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
mutex_lock(&clnt_fd_lock); mutex_lock(&clnt_fd_lock);
#ifndef __rtems__
while (dg_fd_locks[cu_fd]) while (dg_fd_locks[cu_fd])
cond_wait(&dg_cv[cu_fd], &clnt_fd_lock); cond_wait(&dg_cv[cu_fd], &clnt_fd_lock);
#endif * __rtems__ */
if (cu->cu_closeit) if (cu->cu_closeit)
(void)_close(cu_fd); (void)_close(cu_fd);
if (cu->cu_kq >= 0) if (cu->cu_kq >= 0)
@ -852,4 +868,3 @@ time_not_ok(struct timeval *t)
return (t->tv_sec < -1 || t->tv_sec > 100000000 || return (t->tv_sec < -1 || t->tv_sec > 100000000 ||
t->tv_usec < -1 || t->tv_usec > 1000000); t->tv_usec < -1 || t->tv_usec > 1000000);
} }

View File

@ -398,6 +398,11 @@ clnt_tli_create(int fd, const struct netconfig *nconf,
goto err1; /* borrow errors from clnt_dg/vc creates */ goto err1; /* borrow errors from clnt_dg/vc creates */
if (nconf) { if (nconf) {
cl->cl_netid = strdup(nconf->nc_netid); cl->cl_netid = strdup(nconf->nc_netid);
#ifdef __rtems__
if (nconf->nc_device == NULL)
cl->cl_tp = "";
else
#endif /* __rtems__ */
cl->cl_tp = strdup(nconf->nc_device); cl->cl_tp = strdup(nconf->nc_device);
} else { } else {
cl->cl_netid = ""; cl->cl_netid = "";

View File

@ -85,6 +85,14 @@ __FBSDID("$FreeBSD$");
#include "rpc_com.h" #include "rpc_com.h"
#include "mt_misc.h" #include "mt_misc.h"
#ifdef __rtems__
#undef thr_sigsetmask
#define thr_sigsetmask(_a, _b, _c)
#define cond_signal(_a)
#define sigfillset(_a)
#define _sendmsg sendmsg
#define _recvmsg recvmsg
#endif /* __rtems__ */
#define MCALL_MSG_SIZE 24 #define MCALL_MSG_SIZE 24
struct cmessage { struct cmessage {
@ -219,10 +227,12 @@ clnt_vc_create(int fd, const struct netbuf *raddr, const rpcprog_t prog,
thr_sigsetmask(SIG_SETMASK, &(mask), NULL); thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
goto err; goto err;
} else { } else {
#ifndef __rtems__
int i; int i;
for (i = 0; i < dtbsize; i++) for (i = 0; i < dtbsize; i++)
cond_init(&vc_cv[i], 0, (void *) 0); cond_init(&vc_cv[i], 0, (void *) 0);
#endif /* __rtems__ */
} }
} else } else
assert(vc_cv != (cond_t *) NULL); assert(vc_cv != (cond_t *) NULL);
@ -336,8 +346,10 @@ clnt_vc_call(CLIENT *cl, rpcproc_t proc, xdrproc_t xdr_args, void *args_ptr,
sigfillset(&newmask); sigfillset(&newmask);
thr_sigsetmask(SIG_SETMASK, &newmask, &mask); thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
mutex_lock(&clnt_fd_lock); mutex_lock(&clnt_fd_lock);
#ifndef __rtems__
while (vc_fd_locks[ct->ct_fd]) while (vc_fd_locks[ct->ct_fd])
cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock); cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
#endif /* __rtems__ */
if (__isthreaded) if (__isthreaded)
rpc_lock_value = 1; rpc_lock_value = 1;
else else
@ -489,8 +501,10 @@ clnt_vc_freeres(CLIENT *cl, xdrproc_t xdr_res, void *res_ptr)
sigfillset(&newmask); sigfillset(&newmask);
thr_sigsetmask(SIG_SETMASK, &newmask, &mask); thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
mutex_lock(&clnt_fd_lock); mutex_lock(&clnt_fd_lock);
#ifndef __rtems__
while (vc_fd_locks[ct->ct_fd]) while (vc_fd_locks[ct->ct_fd])
cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock); cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
#endif /* __rtems__ */
xdrs->x_op = XDR_FREE; xdrs->x_op = XDR_FREE;
dummy = (*xdr_res)(xdrs, res_ptr); dummy = (*xdr_res)(xdrs, res_ptr);
mutex_unlock(&clnt_fd_lock); mutex_unlock(&clnt_fd_lock);
@ -536,8 +550,10 @@ clnt_vc_control(CLIENT *cl, u_int request, void *info)
sigfillset(&newmask); sigfillset(&newmask);
thr_sigsetmask(SIG_SETMASK, &newmask, &mask); thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
mutex_lock(&clnt_fd_lock); mutex_lock(&clnt_fd_lock);
#ifndef __rtems__
while (vc_fd_locks[ct->ct_fd]) while (vc_fd_locks[ct->ct_fd])
cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock); cond_wait(&vc_cv[ct->ct_fd], &clnt_fd_lock);
#endif /* __rtems__ */
if (__isthreaded) if (__isthreaded)
rpc_lock_value = 1; rpc_lock_value = 1;
else else
@ -653,8 +669,10 @@ clnt_vc_destroy(CLIENT *cl)
sigfillset(&newmask); sigfillset(&newmask);
thr_sigsetmask(SIG_SETMASK, &newmask, &mask); thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
mutex_lock(&clnt_fd_lock); mutex_lock(&clnt_fd_lock);
#ifndef __rtems__
while (vc_fd_locks[ct_fd]) while (vc_fd_locks[ct_fd])
cond_wait(&vc_cv[ct_fd], &clnt_fd_lock); cond_wait(&vc_cv[ct_fd], &clnt_fd_lock);
#endif /* __rtems__ */
if (ct->ct_closeit && ct->ct_fd != -1) { if (ct->ct_closeit && ct->ct_fd != -1) {
(void)_close(ct->ct_fd); (void)_close(ct->ct_fd);
} }

View File

@ -63,7 +63,45 @@ __FBSDID("$FreeBSD$");
* used to specify the network transport to be used. * used to specify the network transport to be used.
*/ */
#ifdef __rtems__
#undef fopen
#undef fgets
#undef fclose
static const char *internal_netconfig[] = {
"udp6 tpi_clts v inet6 udp - -\n",
"tcp6 tpi_cots_ord v inet6 tcp - -\n",
"udp tpi_clts v inet udp - -\n",
"tcp tpi_cots_ord v inet tcp - -\n",
"rawip tpi_raw - inet - - -\n",
"local tpi_cots_ord - loopback - - -\n",
NULL
};
static int netconfig_next;
static FILE*
nc_fopen(const char* name, const char* mode) {
netconfig_next = 0;
return (FILE*) &netconfig_next;
}
static int
nc_fclose(FILE *stream) {
return 0;
}
static char *
nc_fgets(char * str, int size, FILE *stream) {
int l;
const char *p = internal_netconfig[netconfig_next];;
if (p == NULL)
return NULL;
l = strlen(p);
size = l < size ? l : size;
memcpy(str, p, size);
++netconfig_next;
return str;
}
#define fopen nc_fopen
#define fgets nc_fgets
#define fclose nc_fclose
#endif /* __rtems__ */
/* /*
* netconfig errors * netconfig errors
*/ */

View File

@ -122,9 +122,11 @@ __rpc_dtbsize(void)
if (tbsize) { if (tbsize) {
return (tbsize); return (tbsize);
} }
#ifndef __rtems__
if (getrlimit(RLIMIT_NOFILE, &rl) == 0) { if (getrlimit(RLIMIT_NOFILE, &rl) == 0) {
return (tbsize = (int)rl.rlim_max); return (tbsize = (int)rl.rlim_max);
} }
#endif /* __rtems__ */
/* /*
* Something wrong. I'll try to save face by returning a * Something wrong. I'll try to save face by returning a
* pessimistic number. * pessimistic number.

View File

@ -361,7 +361,11 @@ getclnthandle(const char *host, const struct netconfig *nconf, char **targaddr)
return (client); return (client);
} }
} else { } else {
#ifndef __rtems__
if (getaddrinfo(host, "sunrpc", &hints, &res) != 0) { if (getaddrinfo(host, "sunrpc", &hints, &res) != 0) {
#else /* __rtems__ */
if (getaddrinfo(host, "111", &hints, &res) != 0) {
#endif /* __rtems__ */
rpc_createerr.cf_stat = RPC_UNKNOWNHOST; rpc_createerr.cf_stat = RPC_UNKNOWNHOST;
return NULL; return NULL;
} }

File diff suppressed because it is too large Load Diff

View File

@ -185,7 +185,7 @@ rtems_bsd_vfs_vnode_componentname(struct componentname *cnd, struct vnode *vp,
name[namemax] = '\0'; name[namemax] = '\0';
namelen = namemax; namelen = namemax;
tvp = vp; tvp = vp;
error = vn_vptocnp(&tvp, NULL, name, &namelen); error = vn_vptocnp(&tvp, cred, name, &namelen);
if (error == 0) { if (error == 0) {
name = &name[namelen]; name = &name[namelen];
namelen = namemax - namelen; namelen = namemax - namelen;

View File

@ -53,6 +53,7 @@
#define TEST_NAME "LIBBSD NFS 1" #define TEST_NAME "LIBBSD NFS 1"
#define TEST_STATE_USER_INPUT 1 #define TEST_STATE_USER_INPUT 1
#define TEST_WAIT_FOR_LINK NET_CFG_INTERFACE_0
static const char *test_top = "test-nfs01"; static const char *test_top = "test-nfs01";
@ -323,10 +324,12 @@ test_path_eval(const char *base, int depth)
static void static void
test_nfs(const char *base) test_nfs(const char *base)
{ {
test_printer_data pd;
test_path_eval(base, 5); test_path_eval(base, 5);
#if NFS_TREE_WALK
test_printer_data pd;
memset(&pd, 0, sizeof(pd)); memset(&pd, 0, sizeof(pd));
test_walk_tree(base, test_walk_tree_printer, &pd); test_walk_tree(base, test_walk_tree_printer, &pd);
#endif
} }
static void static void

View File

@ -287,40 +287,80 @@ class Builder(builder.ModuleManager):
if not os.path.exists(bld.env.NET_CONFIG): if not os.path.exists(bld.env.NET_CONFIG):
bld.fatal('network configuraiton \'%s\' not found' % bld.fatal('network configuraiton \'%s\' not found' %
(bld.env.NET_CONFIG)) (bld.env.NET_CONFIG))
tags = [ net_cfg = {
'NET_CFG_INTERFACE_0', 'NET_CFG_SELF_IP', 'NET_CFG_NETMASK', 'NET_CFG_INTERFACE_0': { 'mandatory': True, },
'NET_CFG_PEER_IP', 'NET_CFG_GATEWAY_IP', 'NET_CFG_NFS_MOUNT_PATH', 'NET_CFG_SELF_IP': { 'mandatory': True },
'NET_CFG_NFS_MOUNT_OPTIONS' 'NET_CFG_NETMASK': { 'mandatory': True },
] 'NET_CFG_PEER_IP': { 'mandatory': True },
'NET_CFG_GATEWAY_IP': { 'manditory': True },
'NET_CFG_NFS_MOUNT_PATH': { 'mandatory': False,
'default': '@NET_CFG_PEER_IP@/rtems' },
'NET_CFG_NFS_MOUNT_OPTIONS': { 'mandatory': False,
'default': 'nfsv4,minorversion=1' }
}
tags = list(net_cfg.keys())
config_inc = bld.path.find_node('config.inc')
try:
config_inc_lines = open(config_inc.abspath()).readlines()
except:
bld.fatal('network configuraiton \'%s\' read failed' %
(config_inc.abspath()))
for l in config_inc_lines:
if l.strip().startswith('NET_CFG_'):
ls = l.split('=', 1)
if len(ls) == 2:
lhs = ls[0].strip()
rhs = ls[1].strip()
if lhs in tags:
net_cfg[lhs]['default'] = rhs
try: try:
net_cfg_lines = open(bld.env.NET_CONFIG).readlines() net_cfg_lines = open(bld.env.NET_CONFIG).readlines()
except: except:
bld.fatal('network configuraiton \'%s\' read failed' % bld.fatal('network configuraiton \'%s\' read failed' %
(bld.env.NET_CONFIG)) (bld.env.NET_CONFIG))
lc = 0 lc = 0
sed = 'sed '
for l in net_cfg_lines: for l in net_cfg_lines:
lc += 1 lc += 1
if l.strip().startswith('NET_CFG_'): if l.strip().startswith('NET_CFG_'):
ls = l.split('=') ls = l.split('=', 1)
if len(ls) != 2: if len(ls) != 2:
bld.fatal('network configuraiton \'%s\' ' + \ bld.fatal('network configuraiton \'%s\' ' + \
'parse error: %d: %s' % (bld.env.NET_CONFIG, lc, l)) 'parse error: %d: %s' % (bld.env.NET_CONFIG, lc, l))
lhs = ls[0].strip() lhs = ls[0].strip()
rhs = ls[1].strip() rhs = ls[1].strip()
for tag in tags: if lhs in tags:
if lhs == tag: net_cfg[lhs]['value'] = rhs
transpose = [(':', '\:'), ('/', '\/')] for tag in net_cfg:
trhs = '' if 'value' not in net_cfg[tag]:
for c in rhs: if net_cfg[tag]['mandatory']:
for t in transpose: bld.fatal('network configuraiton \'%s\' ' + \
if c == t[0]: 'entry not found: %s' % (bld.env.NET_CONFIG, tag))
trhs += t[1] net_cfg[tag]['value'] = net_cfg[tag]['default']
c = None updated = True
break while updated:
if c is not None: updated = False
trhs += c for tag in net_cfg:
sed += "-e 's/@%s@/%s/' " % (tag, trhs) for rtag in net_cfg:
if tag != rtag and 'value' in net_cfg[rtag]:
pattern = re.escape('@' + tag + '@')
repl = net_cfg[tag]['value']
value = re.sub(pattern, repl, net_cfg[rtag]['value'])
if value != net_cfg[rtag]['value']:
updated = True
net_cfg[rtag]['value'] = value
transpose = [(':', '\:'), ('/', '\/')]
sed = 'sed '
for tag in net_cfg:
tv = ''
for c in net_cfg[tag]['value']:
for t in transpose:
if c == t[0]:
tv += t[1]
c = None
break
if c is not None:
tv += c
sed += "-e 's/@%s@/%s/' " % (tag, tv)
bld(target="testsuite/include/rtems/bsd/test/network-config.h", bld(target="testsuite/include/rtems/bsd/test/network-config.h",
source="testsuite/include/rtems/bsd/test/network-config.h.in", source="testsuite/include/rtems/bsd/test/network-config.h.in",
rule=sed + " < ${SRC} > ${TGT}", rule=sed + " < ${SRC} > ${TGT}",