aboutsummaryrefslogtreecommitdiffstats
path: root/plpnfsd
diff options
context:
space:
mode:
authorFritz Elfert <felfert@to.com>1999-07-04 11:59:42 +0000
committerFritz Elfert <felfert@to.com>1999-07-04 11:59:42 +0000
commitf2d9bc87bc87b4ef3cdee081c65ad1c248804edd (patch)
treefebc5b563533b56b9768d1d176fc8c8325d6ab8d /plpnfsd
parent7c656c8b37fd4733ff6a389de95e3ab7110f586b (diff)
downloadplptools-f2d9bc87bc87b4ef3cdee081c65ad1c248804edd.tar.gz
plptools-f2d9bc87bc87b4ef3cdee081c65ad1c248804edd.tar.bz2
plptools-f2d9bc87bc87b4ef3cdee081c65ad1c248804edd.zip
logging via syslog, more error-handling.
Diffstat (limited to 'plpnfsd')
-rw-r--r--plpnfsd/Makefile.am6
-rw-r--r--plpnfsd/main.cc84
-rw-r--r--plpnfsd/mp_inode.c18
-rw-r--r--plpnfsd/mp_main.c89
-rw-r--r--plpnfsd/mp_mount.c113
-rw-r--r--plpnfsd/mp_pfs_ops.c153
-rw-r--r--plpnfsd/rfsv_api.h1
7 files changed, 202 insertions, 262 deletions
diff --git a/plpnfsd/Makefile.am b/plpnfsd/Makefile.am
index dce43ce..7c519c1 100644
--- a/plpnfsd/Makefile.am
+++ b/plpnfsd/Makefile.am
@@ -1,8 +1,12 @@
INCLUDES=-I../lib
sbin_PROGRAMS = plpnfsd
-plpnfsd_LDADD = ../lib/.libs/libplp.so
+plpnfsd_LDADD = ../lib/libplp.la
plpnfsd_SOURCES = mp_main.c mp_mount.c nfs_prot_svc.c nfs_prot_xdr.c \
mp_pfs_ops.c mp_inode.c main.cc
EXTRA_plpnfsd_SOURCES = mount_aix.c
+EXTRA_DIST = rfsv_api.h
+
+install-exec-hook:
+ chmod u+s $(sbindir)/plpnfsd
diff --git a/plpnfsd/main.cc b/plpnfsd/main.cc
index 6924dca..c63ec36 100644
--- a/plpnfsd/main.cc
+++ b/plpnfsd/main.cc
@@ -23,6 +23,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
+#include <signal.h>
#include "defs.h"
#include "bool.h"
@@ -34,18 +35,13 @@ extern "C" {
#include "rfsv_api.h"
}
-static rfsv32 *a = 0L;
-static ppsocket *skt = 0L;
+static rfsv32 *a;
long rfsv_isalive() {
- if (!a)
- return 0;
return (a->getStatus() == 0);
}
long rfsv_dir(const char *file, dentry **e) {
- if (!a)
- return -1;
bufferArray entries;
dentry *tmp;
long ret = a->dir(&(*file), &entries);
@@ -66,14 +62,10 @@ long rfsv_dir(const char *file, dentry **e) {
}
long rfsv_dircount(const char *file, long *count) {
- if (!a)
- return -1;
return a->dircount(&(*file), &(*count));
}
long rfsv_rmdir(const char *name) {
- if (!a)
- return -1;
return a->rmdir(name);
}
@@ -84,20 +76,14 @@ long rfsv_mkdir(const char *file) {
}
long rfsv_remove(const char *file) {
- if (!a)
- return -1;
return a->remove(file);
}
long rfsv_fclose(long handle) {
- if (!a)
- return -1;
return a->fclose(handle);
}
long rfsv_fopen(long attr, const char *file, long *handle) {
- if (!a)
- return -1;
long ph;
long ret = a->fopen(attr, file, ph);
*handle = ph;
@@ -105,8 +91,6 @@ long rfsv_fopen(long attr, const char *file, long *handle) {
}
long rfsv_fcreate(long attr, const char *file, long *handle) {
- if (!a)
- return -1;
long ph;
long ret = a->fcreatefile(attr, file, ph);
*handle = ph;
@@ -114,8 +98,6 @@ long rfsv_fcreate(long attr, const char *file, long *handle) {
}
long rfsv_read(char *buf, long offset, long len, long handle) {
- if (!a)
- return -1;
long ret = a->fseek(handle, offset, rfsv32::PSI_SEEK_SET);
if (ret >= 0)
ret = a->fread(handle, buf, len);
@@ -123,8 +105,6 @@ long rfsv_read(char *buf, long offset, long len, long handle) {
}
long rfsv_write(char *buf, long offset, long len, long handle) {
- if (!a)
- return -1;
long ret = a->fseek(handle, offset, rfsv32::PSI_SEEK_SET);
if (ret >= 0)
ret = a->fwrite(handle, buf, len);
@@ -132,14 +112,10 @@ long rfsv_write(char *buf, long offset, long len, long handle) {
}
long rfsv_setmtime(const char *name, long time) {
- if (!a)
- return -1;
return a->fsetmtime(name, time);
}
long rfsv_setsize(const char *name, long size) {
- if (!a)
- return -1;
long ph;
long ret = a->fopen(rfsv32::PSI_OMODE_READ_WRITE, name, ph);
if (!ret) {
@@ -150,20 +126,14 @@ long rfsv_setsize(const char *name, long size) {
}
long rfsv_setattr(const char *name, long sattr, long dattr) {
- if (!a)
- return -1;
return a->fsetattr(name, dattr, sattr);
}
long rfsv_getattr(const char *name, long *attr, long *size, long *time) {
- if (!a)
- return -1;
return a->fgeteattr(&(*name), &(*attr), &(*size), &(*time));
}
long rfsv_statdev(char letter) {
- if (!a)
- return -1;
long vfree, vtotal, vattr, vuniqueid;
int devnum = letter - 'A';
char *name;
@@ -173,14 +143,10 @@ long rfsv_statdev(char letter) {
}
long rfsv_rename(const char *oldname, const char *newname) {
- if (!a)
- return -1;
return a->rename(oldname, newname);
}
long rfsv_drivelist(int *cnt, device **dlist) {
- if (!a)
- return -1;
*dlist = NULL;
long devbits;
long ret;
@@ -209,26 +175,38 @@ long rfsv_drivelist(int *cnt, device **dlist) {
return ret;
}
-void rfsv_startup()
+void usage()
{
- bool res;
+ cerr << "usage: plpnfsd [-v] [-V] [-p port] [-d mountdir] [-u user]\n";
+ exit(1);
+}
- if (a) {
- delete a;
- a = 0L;
- }
- if (skt) {
- delete skt;
- skt = 0L;
+int main(int argc, char**argv) {
+ ppsocket *skt;
+ char *user = 0L;
+ char *mdir = DDIR;
+ int sockNum = DPORT;
+ int verbose = 0;
+
+ for (int i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "-p") && i + 1 < argc) {
+ sockNum = atoi(argv[++i]);
+ } else if (!strcmp(argv[i], "-d") && i + 1 < argc) {
+ mdir = argv[++i];
+ } else if (!strcmp(argv[i], "-u") && i + 1 < argc) {
+ user = argv[++i];
+ } else if (!strcmp(argv[i], "-v")) {
+ verbose++;
+ } else if (!strcmp(argv[i], "-V")) {
+ cout << "plpnfsd version " << VERSION << endl;
+ exit(0);
+ } else
+ usage();
}
+
+ signal(SIGPIPE, SIG_IGN);
skt = new ppsocket();
- skt->startup();
- res = skt->connect(NULL, DPORT);
+ skt->connect(NULL, sockNum);
a = new rfsv32(skt);
-}
-
-int main(int argc, char**argv) {
- char *mp_args[] = { "mp_main", "-v", "-dir", "/mnt/psion", NULL };
- mp_main(4, mp_args);
- return 0;
+ return mp_main(verbose, mdir, user);
}
diff --git a/plpnfsd/mp_inode.c b/plpnfsd/mp_inode.c
index 0f9051c..c355a3e 100644
--- a/plpnfsd/mp_inode.c
+++ b/plpnfsd/mp_inode.c
@@ -46,7 +46,7 @@ int i;
if (i == ptr->inode)
break;
if (!ptr) {
- printf("Inode %d not found (aborting)\n", i);
+ errorlog("Inode %d not found (aborting)\n", i);
abort();
}
return ptr;
@@ -88,7 +88,7 @@ char *name;
if (!ptr)
ptr = newinode(name, nextinode++);
if (debug > 1)
- printf("\tget_nam(``%s'') returns %08x->inode = %d\n",
+ debuglog("get_nam(``%s'') returns %08x->inode = %d\n",
name, (unsigned int) ptr, ptr->inode);
return ptr;
}
@@ -123,7 +123,7 @@ char *old, *new;
int idx = hash(old);
if (debug)
- printf("re_nam: %s->%s\n", old, new);
+ debuglog("re_nam: %s->%s\n", old, new);
for (nampp = &namtab[idx]; *nampp; nampp = &(*nampp)->nextnam)
if (!strcmp(old, (*nampp)->name))
break;
@@ -132,7 +132,7 @@ char *old, *new;
optr = *nampp;
if (debug)
- printf("re_nam: %d\n", optr->inode);
+ debuglog("re_nam: %d\n", optr->inode);
*nampp = optr->nextnam;
/* delete it from the other hashtab too */
@@ -141,14 +141,14 @@ char *old, *new;
if (optr == (*numpp))
break;
if (!*numpp) {
- printf("Entry in one hashtab only (aborting)\n");
+ errorlog("Entry in one hashtab only (aborting)\n");
abort();
}
*numpp = optr->nextnum;
nptr = newinode(new, optr->inode);
if (debug)
- printf("re_nam: new entry created\n");
+ debuglog("re_nam: new entry created\n");
free(optr->name);
free(optr);
@@ -164,7 +164,7 @@ unsigned inode;
struct cache *cp;
if (debug)
- printf("search_cache %d\n", inode);
+ debuglog("search_cache %d\n", inode);
for (cp = root; cp; cp = cp->next)
if (cp->inode == inode)
return cp;
@@ -180,7 +180,7 @@ fattr *fp;
struct cache *cp;
if (debug)
- printf("add_cache %d\n", inode);
+ debuglog("add_cache %d\n", inode);
cp = (struct cache *) malloc(sizeof(*cp));
cp->inode = inode;
cp->attr = *fp;
@@ -246,7 +246,7 @@ unsigned inode;
struct cache *cp, **cpp;
if (debug)
- printf("rem_cache %d\n", inode);
+ debuglog("rem_cache %d\n", inode);
for (cpp = root; (cp = *cpp); cpp = &cp->next)
if (cp->inode == inode)
break;
diff --git a/plpnfsd/mp_main.c b/plpnfsd/mp_main.c
index e1dabb2..e6eb067 100644
--- a/plpnfsd/mp_main.c
+++ b/plpnfsd/mp_main.c
@@ -3,6 +3,9 @@
#include <signal.h>
#include <fcntl.h>
#include <pwd.h>
+#include <stdarg.h>
+#include <syslog.h>
+#include <errno.h>
#include "nfs_prot.h"
#include "mp.h"
#include "defs.h"
@@ -24,10 +27,7 @@
extern void nfs_program_2();
-static char
-*user, *dir = DDIR;
-
-int gmtoffset, debug, exiting, query_cache = 0;
+int debug, exiting, query_cache = 0;
fattr root_fattr =
{
@@ -53,9 +53,52 @@ int usec;
#endif /* hpux */
int
-mp_main(ac, av)
-int ac;
-char *av[];
+debuglog(char *fmt, ...)
+{
+ va_list ap;
+ char *buf;
+
+ if (!debug)
+ return 0;
+ buf = (char *)malloc(1024);
+ va_start(ap, fmt);
+ vsnprintf(buf, 1024, fmt, ap);
+ syslog(LOG_DEBUG, buf);
+ free(buf);
+ va_end(ap);
+ return 0;
+}
+
+int
+errorlog(char *fmt, ...)
+{
+ va_list ap;
+ char *buf = (char *)malloc(1024);
+
+ va_start(ap, fmt);
+ vsnprintf(buf, 1024, fmt, ap);
+ va_end(ap);
+ syslog(LOG_ERR, buf);
+ free(buf);
+ return 0;
+}
+
+int
+infolog(char *fmt, ...)
+{
+ va_list ap;
+ char *buf = (char *)malloc(1024);
+
+ va_start(ap, fmt);
+ vsnprintf(buf, 1024, fmt, ap);
+ syslog(LOG_INFO, buf);
+ free(buf);
+ va_end(ap);
+ return 0;
+}
+
+int
+mp_main(int verbose, char *dir, char *user)
{
struct passwd *pw;
struct timeval tv;
@@ -69,29 +112,6 @@ char *av[];
if (!(user = (char *) getenv("USER")))
user = (char *) getenv("logname");
-
- while (ac > 1) {
- if (!strcmp(av[1], "-v")) {
- debug++;
- } else if (!strcmp(av[1], "-dir")) {
- dir = av[2];
- ac--;
- av++;
- } else if (!strcmp(av[1], "-user") || !strcmp(av[1], "-u")) {
- user = av[2];
- ac--;
- av++;
- } else {
- printf("p3nfsd version %s\n", VERSION);
- printf("Usage: p3nfsd [-dir directory] [-user username]\n");
- printf(" [-wakeup] [-v] [-]\n");
- printf("Defaults: -dir %s -user %s\n", dir, user);
- return 1;
- }
- ac--;
- av++;
- }
-
if (user && *user) {
if (!(pw = getpwnam(user))) {
fprintf(stderr, "User %s not found.\n", user);
@@ -110,15 +130,9 @@ char *av[];
endpwent();
gettimeofday(&tv, &tz);
-#ifndef __SVR4
- gmtoffset = -tz.tz_minuteswest * 60;
-#else
- tzset();
- gmtoffset = -timezone;
-#endif
printf("plpnfsd: version %s, mounting on %s\n", VERSION, dir);
-
+ debug = verbose;
/* Check if mountdir is empty (or else you can overmount e.g /etc)
It is done here, because exit hangs, if hardware flowcontrol is
@@ -136,6 +150,7 @@ char *av[];
fprintf(stderr, "Sorry, directory %s is not empty, exiting.\n", dir);
return 1;
}
+ openlog("plpnfsd", LOG_PID|LOG_CONS, LOG_DAEMON);
rp = get_nam("");
inode2fh(rp->inode, root_fh.data);
root_fattr.fileid = rp->inode;
diff --git a/plpnfsd/mp_mount.c b/plpnfsd/mp_mount.c
index e58a3e0..ccce338 100644
--- a/plpnfsd/mp_mount.c
+++ b/plpnfsd/mp_mount.c
@@ -107,7 +107,6 @@ extern int _rpc_dtablesize();
#define mntent mnttab
#endif
-
static char *mntdir; /* where we mounted the psion */
#ifdef __STDC__
@@ -118,14 +117,14 @@ static void
usr1_handler SIGARG
{
debug = (debug + 1) & 3;
- printf("Set debug level to %d\n", debug);
+ infolog("Set debug level to %d\n", debug);
};
static void
hup_handler SIGARG
{
if (debug > 1)
- printf("Got HUP signal\n");
+ debuglog("Got HUP signal\n");
exiting = 5;
};
@@ -145,44 +144,40 @@ doexit()
#endif
exiting--;
-
- if (debug)
- printf("Doing exit\n");
+ debuglog("Doing exit\n");
#ifdef _IBMR2
if (stat(mntdir, &statb)) {
- perror("stat");
+ errorlog("stat %s: %m\n", mntdir);
return;
}
- if (debug)
- printf("Next call: uvmount(%d, 0)\n", statb.st_vfs);
+ debuglog("Next call: uvmount(%d, 0)\n", statb.st_vfs);
if (uvmount(statb.st_vfs, 0)) {
- perror("uvmount");
+ errorlog("uvmount: %m\n");
return;
}
#else
if (umount(mntdir)) {
- perror(mntdir);
+ errorlog("umount %s: %m\n", mntdir);
return;
}
#endif
#ifndef DONT_UPDATE_MTAB
- if (debug)
- printf("unmount succeeded, trying to fix mtab.\n");
+ debuglog("unmount succeeded, trying to fix mtab.\n");
if (!(fpout = setmntent(MTAB_TMP, "w"))) {
- perror(MTAB_TMP);
+ errorlog("%s: %m\n", MTAB_TMP);
return;
}
if (!(fpin = setmntent(MTAB_PATH, "r"))) {
endmntent(fpout);
unlink(MTAB_TMP);
- perror(MTAB_PATH);
+ errorlog("%s: %m\n", MTAB_PATH);
exit(0);
}
if (fstat(fileno(fpin), &statb))
- perror("fstat");
+ errorlog("fstat: %m\n");
else
fchmod(fileno(fpout), statb.st_mode);
@@ -199,14 +194,13 @@ doexit()
endmntent(fpout);
if (rename(MTAB_TMP, MTAB_PATH)) {
- perror(MTAB_PATH);
+ errorlog("%s: %m\n", MTAB_PATH);
unlink(MTAB_TMP);
}
#else
- if (debug)
- printf("no mtab fixing needed\n");
+ debuglog("no mtab fixing needed\n");
#endif
- fprintf(stderr, "plpnfsd: exiting.\n");
+ infolog("plpnfsd: terminating.\n");
exit(0);
}
@@ -243,7 +237,7 @@ mount_and_run(char *dir, void (*proc)(), nfs_fh *root_fh)
/* Create udp socket */
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *) &bufsiz, sizeof(bufsiz)))
- perror("setsockopt");
+ errorlog("setsockopt: %m\n");
/* Bind it to a reserved port */
sain.sin_family = AF_INET;
@@ -254,19 +248,18 @@ mount_and_run(char *dir, void (*proc)(), nfs_fh *root_fh)
break;
}
if (port <= IPPORT_RESERVED / 2) {
- perror("bind to reserved port");
+ errorlog("bind to reserved port: %m\n");
exit(1);
}
if ((nfsxprt = svcudp_create(sock)) == 0) {
- perror("svcudp_create");
+ errorlog("svcudp_create: %m\n");
exit(1);
}
if (!svc_register(nfsxprt, NFS_PROGRAM, NFS_VERSION, proc, 0)) {
- perror("svc_register");
+ errorlog("svc_register: %m\n");
exit(1);
}
- if (debug)
- printf("created svc PROG=%d, VER=%d port=%d\n",
+ debuglog("created svc PROG=%d, VER=%d port=%d\n",
NFS_PROGRAM, NFS_VERSION, port);
@@ -278,7 +271,7 @@ mount_and_run(char *dir, void (*proc)(), nfs_fh *root_fh)
*/
ksock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (ksock < 0) {
- perror("Cannot create kernel socket.");
+ errorlog("Cannot create kernel socket: %m\n");
exit(1);
}
kaddr.sin_family = AF_INET;
@@ -289,7 +282,7 @@ mount_and_run(char *dir, void (*proc)(), nfs_fh *root_fh)
break;
}
if (kport <= IPPORT_RESERVED / 2) {
- perror("bind to reserved port");
+ errorlog("bind to reserved port: %m\n");
exit(1);
}
nfs_mount_data.version = NFS_MOUNT_VERSION;
@@ -309,7 +302,7 @@ mount_and_run(char *dir, void (*proc)(), nfs_fh *root_fh)
strcpy(nfs_mount_data.hostname, PSIONHOSTNAME);
if (connect(ksock, (struct sockaddr *) &nfs_mount_data.addr, sizeof(nfs_mount_data.addr)) < 0) {
- perror("Cannot connect to plpnfsd");
+ errorlog("Cannot connect to plpnfsd: %m\n");
exit(1);
}
mount_flags = MS_MGC_VAL; /* | MS_SYNC | MS_RDONLY | MS_NOEXEC | MS_NODEV | MS_NOSUID */
@@ -324,8 +317,7 @@ mount_and_run(char *dir, void (*proc)(), nfs_fh *root_fh)
struct netconfig *nc = getnetconfigent("udp");
if (!nc) {
extern int errno;
- fprintf(stderr, "getnetconfigent \"udp\": (errno %d) ", errno);
- perror("");
+ errorlog("getnetconfigent \"udp\": (errno %d) %m\n", errno);
exit(1);
}
knc.knc_semantics = nc->nc_semantics;
@@ -334,16 +326,14 @@ mount_and_run(char *dir, void (*proc)(), nfs_fh *root_fh)
if (stat(nc->nc_device, &stb)) {
extern int errno;
- fprintf(stderr, "stat \"%s\": (errno %d) ", nc->nc_device, errno);
- perror("");
+ errorlog("stat \"%s\": (errno %d) %m\n", nc->nc_device, errno);
exit(1);
}
knc.knc_rdev = stb.st_rdev;
/*freenetconfigent(nc) has the struct been allocated, or is it static ?!? */
- if (debug)
- printf("%d,%s,%s,%lx (1,inet,udp,0x002c0029)\n", (int) knc.knc_semantics,
+ debuglog("%d,%s,%s,%lx (1,inet,udp,0x002c0029)\n", (int) knc.knc_semantics,
knc.knc_protofmly, knc.knc_proto, knc.knc_rdev);
myaddr.maxlen = myaddr.len = sizeof(sain);
@@ -442,11 +432,10 @@ mount_and_run(char *dir, void (*proc)(), nfs_fh *root_fh)
case 0:
break;
case -1:
- perror("fork");
+ errorlog("fork: %m\n");
exit(1);
default:
- if (debug)
- printf("Going to mount...\n");
+ debuglog("Going to mount...\n");
#if defined(__sgi) || (defined(sun) && defined(__SVR4))
if (mount("", dir, MS_DATA, "nfs", &nfs_args, sizeof(nfs_args)))
@@ -476,10 +465,7 @@ mount_and_run(char *dir, void (*proc)(), nfs_fh *root_fh)
#endif
{
- extern int errno;
-
- fprintf(stderr, "nfs mount %s: (errno %d) ", dir, errno);
- perror("");
+ errorlog("nfs mount %s: %m\n", dir);
kill(pid, SIGTERM);
exit(0);
} else {
@@ -490,8 +476,7 @@ mount_and_run(char *dir, void (*proc)(), nfs_fh *root_fh)
char tim[32];
#endif
- if (debug)
- printf("Mount succeded, making mtab entry.\n");
+ debuglog("Mount succeded, making mtab entry.\n");
#if defined(sun) && defined(__SVR4) /*gec */
mnt.mnt_special = nfshost;
@@ -511,7 +496,7 @@ mount_and_run(char *dir, void (*proc)(), nfs_fh *root_fh)
if ((mfp = setmntent(MTAB_PATH, "a")))
addmntent(mfp, &mnt);
else
- perror(MTAB_PATH);
+ errorlog("%s: %m\n", MTAB_PATH);
endmntent(mfp);
#endif /* !DONT_UPDATE_MTAB */
}
@@ -519,8 +504,7 @@ mount_and_run(char *dir, void (*proc)(), nfs_fh *root_fh)
}
/*** Third part: let's go */
- printf("plpnfsd: to stop the server do \"ls %s/exit\". (pid %d)\n",
- mntdir, (int) getpid());
+ infolog("to stop the server do \"ls %s/exit\".\n", mntdir);
#if defined(sun) && !defined(__SVR4)
dtbsize = _rpc_dtablesize();
@@ -535,6 +519,7 @@ mount_and_run(char *dir, void (*proc)(), nfs_fh *root_fh)
*/
signal(SIGUSR1, usr1_handler);
signal(SIGHUP, hup_handler);
+ signal(SIGPIPE, SIG_IGN);
for (;;) {
fd_set readfd;
@@ -572,38 +557,30 @@ mount_and_run(char *dir, void (*proc)(), nfs_fh *root_fh)
for (cp = attrcache; cp; cp = cp->next)
for (dcp = cp->dcache; dcp; dcp = dcp->next)
if (dcp->towrite) {
- if (debug)
- printf("\twaiting for block %d in %s to write (%d)\n",
+ debuglog("waiting for block %d in %s to write (%d)\n",
dcp->offset, get_num(cp->inode)->name, dcp->towrite);
if (++dcp->towrite <= MAXWRITE)
doclean = 0; /* Wait with cleaning */
}
+ ret = rfsv_isalive();
+ if (isalive) {
+ if (!ret) {
+ debuglog("Disconnected...\n");
+ doclean = 1;
+ }
+ } else {
+ if (ret)
+ debuglog("Connected...\n");
+ }
+ isalive = ret;
if (doclean) {
for (cp = attrcache; cp; cp = cp->next)
for (dcp = cp->dcache; dcp; dcp = dcp->next)
if (dcp->towrite)
- printf("PLPNFSD WARNING: file %s block at %d not written\n",
+ errorlog("PLPNFSD WARNING: file %s block at %d not written\n",
get_num(cp->inode)->name, dcp->offset);
clean_cache(&attrcache);
query_cache = 0; /* clear the GETDENTS "cache". */
}
- ret = rfsv_isalive();
- if (isalive) {
- if (!ret) {
- if (debug)
- printf("Disconnected...\n");
- rfsv_startup();
- }
- } else {
- if (ret) {
- if (debug)
- printf("Connected...\n");
- } else {
- if (debug)
- printf("Try connecting...\n");
- rfsv_startup();
- }
- }
- isalive = ret;
}
}
diff --git a/plpnfsd/mp_pfs_ops.c b/plpnfsd/mp_pfs_ops.c
index 0967587..e3212da 100644
--- a/plpnfsd/mp_pfs_ops.c
+++ b/plpnfsd/mp_pfs_ops.c
@@ -32,9 +32,8 @@ create_it(createargs *ca, int isdir)
long phandle;
int rfsv_ret;
- if (debug)
- printf("\tcreate: in %s %s (%#o, %d)\n",
- name, ca->where.name, ca->attributes.mode, isdir);
+ debuglog("create: in %s %s (%#o, %d)\n",
+ name, ca->where.name, ca->attributes.mode, isdir);
name = build_path(name, ca->where.name);
@@ -74,7 +73,8 @@ create_it(createargs *ca, int isdir)
rem_cache(&attrcache, dirinode->inode);
rem_cache(&attrcache, inode->inode);
- add_cache(&attrcache, inode->inode, fp);
+ if (rfsv_isalive())
+ add_cache(&attrcache, inode->inode, fp);
return &res;
}
@@ -236,7 +236,6 @@ query_devices()
if (query_cache)
return 0;
- query_cache = 1;
for (dp = devices; dp; dp = np) {
np = dp->next;
free(dp->name);
@@ -245,6 +244,7 @@ query_devices()
devices = 0;
if (rfsv_drivelist(&link_count, &devices))
return 1;
+ query_cache = 1;
root_fattr.nlink = link_count;
return 0;
}
@@ -256,8 +256,7 @@ mp_dircount(p_inode *inode, long *count)
long ret;
*count = 0;
- if (debug)
- printf("\tdircount: dir\n");
+ debuglog("dircount: dir\n");
if ((ret = rfsv_dir(dirname(inode->name), &e)))
return ret;
while (e) {
@@ -271,7 +270,8 @@ mp_dircount(p_inode *inode, long *count)
free(e->name);
if (!search_cache(attrcache, ni)) {
dpattr2attr(e->attr, e->size, e->time, &fp, ni);
- add_cache(&attrcache, ni, &fp);
+ if (rfsv_isalive())
+ add_cache(&attrcache, ni, &fp);
}
o = e;
e = e->next;
@@ -294,13 +294,11 @@ nfsproc_getattr_2(struct nfs_fh *fh)
long dcount;
int l;
- if (debug)
- printf("\tgetattr:'%s',%d\n", inode->name, inode->inode);
+ debuglog("getattr:'%s',%d\n", inode->name, inode->inode);
res.status = NFS_OK;
if ((cp = search_cache(attrcache, inode->inode))) {
- if (debug)
- printf("\t\tgetattr: cache hit\n");
+ debuglog("getattr: cache hit\n");
*fp = cp->attr; /* gotcha */
if (fp->type == NFDIR) {
if (mp_dircount(inode, &dcount)) {
@@ -318,28 +316,24 @@ nfsproc_getattr_2(struct nfs_fh *fh)
if (inode->inode == root_fattr.fileid) {
/* It's the root inode */
- if (debug)
- printf("\t\tgetattr:root inode (%#o)\n", root_fattr.mode);
+ debuglog("getattr:root inode (%#o)\n", root_fattr.mode);
if (query_devices()) /* root inode is always there */
root_fattr.nlink = 2;
*fp = root_fattr;
} else if (l == 2 && inode->name[1] == ':') {
- if (debug)
- printf("\tgetattr:device\n");
+ debuglog("getattr:device\n");
res.status = NO_PSION;
if (!query_devices()) {
device *dp;
for (dp = devices; dp; dp = dp->next) {
- if (debug)
- printf("\tcmp '%c', '%s'\n", dp->letter,
+ debuglog("cmp '%c', '%s'\n", dp->letter,
inode->name);
if (dp->letter == inode->name[0])
break;
}
- if (debug)
- printf("\tdevice: %s exists\n", (dp)?"":"not");
+ debuglog("device: %s exists\n", (dp)?"":"not");
if (dp) {
res.status = NFS_OK;
*fp = root_fattr;
@@ -357,8 +351,7 @@ nfsproc_getattr_2(struct nfs_fh *fh)
}
}
} else {
- if (debug)
- printf("\tgetattr:fileordir\n");
+ debuglog("getattr:fileordir\n");
/* It's a normal file/dir */
if (rfsv_getattr(inode->name, &pattr, &psize, &ptime)) {
res.status = rfsv_isalive() ? NFSERR_NOENT : NO_PSION;
@@ -375,7 +368,8 @@ nfsproc_getattr_2(struct nfs_fh *fh)
fp->nlink = dcount + 2;
}
}
- add_cache(&attrcache, inode->inode, fp);
+ if (rfsv_isalive())
+ add_cache(&attrcache, inode->inode, fp);
return &res;
}
@@ -388,13 +382,11 @@ nfsproc_lookup_2(diropargs *da)
char *fp = res.diropres_u.diropres.file.data;
if (!inode) {
- if (debug)
- printf("lookup: stale fh\n");
+ debuglog("lookup: stale fh\n");
res.status = NO_PSION;
return &res;
}
- if (debug)
- printf("\tlookup: in '%s'(%d) searching '%s'\n",
+ debuglog("lookup: in '%s'(%d) searching '%s'\n",
inode->name, inode->inode, da->name);
if (inode->inode == root_fattr.fileid && !strcmp(da->name, "exit")) {
@@ -404,7 +396,7 @@ nfsproc_lookup_2(diropargs *da)
}
if (inode->inode == root_fattr.fileid && !strcmp(da->name, "debug")) {
debug = (debug + 1) & 3; /* debug level of 0,1,2 & 3 */
- printf("Set debug level to %d\n", debug);
+ debuglog("Set debug level to %d\n", debug);
res.status = NFSERR_EXIST;
return &res;
}
@@ -486,8 +478,7 @@ nfsproc_readdir_2(readdirargs *ra)
int searchinode;
if (!inode) {
- if (debug)
- printf("readdir: stale fh\n");
+ debuglog("readdir: stale fh\n");
res.status = NO_PSION;
return &res;
}
@@ -500,8 +491,7 @@ nfsproc_readdir_2(readdirargs *ra)
*cp = 0;
searchinode = *(int *) ra->cookie;
- if (debug)
- printf("\treaddir: %s, cookie:%x, count:%d\n",
+ debuglog("readdir: %s, cookie:%x, count:%d\n",
inode->name, searchinode, ra->count);
/* . & .. */
@@ -522,8 +512,7 @@ nfsproc_readdir_2(readdirargs *ra)
}
} else {
dentry *e = NULL;
- if (debug)
- printf("\tnfsdir: dir\n");
+ debuglog("nfsdir: dir\n");
if (rfsv_dir(dirname(inode->name), &e)) {
res.status = rfsv_isalive() ? NFSERR_NOENT : NO_PSION;
return &res;
@@ -538,7 +527,8 @@ nfsproc_readdir_2(readdirargs *ra)
addentry(ra, &cp, &searchinode, ni, (char *) bp);
free(e->name);
dpattr2attr(e->attr, e->size, e->time, &fp, ni);
- add_cache(&attrcache, ni, &fp);
+ if (rfsv_isalive())
+ add_cache(&attrcache, ni, &fp);
o = e;
e = e->next;
free(o);
@@ -558,13 +548,11 @@ nfsproc_setattr_2(sattrargs *sa)
fattr *fp;
if (!inode) {
- if (debug)
- printf("setattr: stale fh\n");
+ debuglog("setattr: stale fh\n");
res.status = NO_PSION;
return &res;
}
- if (debug)
- printf("\tsetattr %s called\n", inode->name);
+ debuglog("setattr %s called\n", inode->name);
res = *nfsproc_getattr_2(&sa->file);
if (res.status != NFS_OK)
return &res;
@@ -573,15 +561,15 @@ nfsproc_setattr_2(sattrargs *sa)
if ((fp->type == NFREG) &&
(sa->attributes.size != -1) &&
(sa->attributes.size != fp->size)) {
- if (debug)
- printf("\t\tsetattr truncating to %d bytes\n", sa->attributes.size);
+ debuglog("setattr truncating to %d bytes\n", sa->attributes.size);
if (rfsv_setsize(inode->name, sa->attributes.size) != 0) {
res.status = rfsv_isalive() ? NFSERR_ROFS : NO_PSION;
return &res;
}
fp->size = sa->attributes.size;
rem_cache(&attrcache, inode->inode);
- add_cache(&attrcache, inode->inode, fp);
+ if (rfsv_isalive())
+ add_cache(&attrcache, inode->inode, fp);
}
if ((sa->attributes.mtime.seconds != fp->mtime.seconds) &&
(sa->attributes.mtime.seconds != -1)) {
@@ -591,7 +579,8 @@ nfsproc_setattr_2(sattrargs *sa)
}
fp->mtime.seconds = fp->atime.seconds = sa->attributes.mtime.seconds;
rem_cache(&attrcache, inode->inode);
- add_cache(&attrcache, inode->inode, fp);
+ if (rfsv_isalive())
+ add_cache(&attrcache, inode->inode, fp);
}
if ((sa->attributes.mode != fp->mode) &&
(sa->attributes.mode != -1)) {
@@ -603,7 +592,8 @@ nfsproc_setattr_2(sattrargs *sa)
}
fp->mode = sa->attributes.mode;
rem_cache(&attrcache, inode->inode);
- add_cache(&attrcache, inode->inode, fp);
+ if (rfsv_isalive())
+ add_cache(&attrcache, inode->inode, fp);
}
res.status = NFS_OK;
return &res;
@@ -617,13 +607,11 @@ remove_it(diropargs *da, int isdir)
long rfsv_res;
if (!inode) {
- if (debug)
- printf("setattr: stale fh\n");
+ debuglog("setattr: stale fh\n");
res = NO_PSION;
return &res;
}
- if (debug)
- printf("\tremove_it: in %s: %s (%d)\n", inode->name, da->name, isdir);
+ debuglog("remove_it: in %s: %s (%d)\n", inode->name, da->name, isdir);
if (isdir)
rfsv_res = rfsv_rmdir(build_path(inode->name, da->name));
@@ -659,8 +647,7 @@ nfsproc_rename_2(renameargs *ra)
char ldata[300], *old, c;
if (!from || !to) {
- if (debug)
- printf("rename: stale fh\n");
+ debuglog("rename: stale fh\n");
res = NO_PSION;
return &res;
}
@@ -669,8 +656,7 @@ nfsproc_rename_2(renameargs *ra)
c = *ldata + 1;
old = build_path(from->name, ra->from.name);
- if (debug)
- printf("\tRename: %s -> %s\n", old, ldata + 1);
+ debuglog("Rename: %s -> %s\n", old, ldata + 1);
res = NFS_OK;
if (rfsv_rename(old, ldata + 1)) {
res = (rfsv_isalive()) ? NFSERR_ACCES : NO_PSION;
@@ -694,8 +680,7 @@ nfsproc_statfs_2(struct nfs_fh *fh)
statfsokres *rp;
device *dp;
- if (debug)
- printf("\tstatfs..\n");
+ debuglog("statfs..\n");
rp = &res.statfsres_u.reply;
rp->tsize = PBUFSIZE;
@@ -743,18 +728,15 @@ nfsproc_read_2(struct readargs *ra)
int len;
if (!inode) {
- if (debug)
- printf("read: stale fh\n");
+ debuglog("read: stale fh\n");
res.status = NO_PSION;
return &res;
}
- if (debug)
- printf("\tread: %s off:%d count:%d\n", inode->name, ra->offset, ra->count);
+ debuglog("read: %s off:%d count:%d\n", inode->name, ra->offset, ra->count);
cp = search_cache(attrcache, inode->inode);
if (cp && (dcp = search_dcache(cp, ra->offset, ra->count))) {
- if (debug)
- printf("\tread: dcache hit\n");
+ debuglog("read: dcache hit\n");
res.readres_u.reply.attributes = cp->attr;
bcopy(dcp->data, res.readres_u.reply.data.data_val, ra->count);
res.readres_u.reply.data.data_len = ra->count;
@@ -769,7 +751,7 @@ nfsproc_read_2(struct readargs *ra)
if (rfsv_read(rop, ra->offset,
ra->count, phandle) < 0) {
rfsv_fclose(phandle);
- res.status = NO_PSION;
+ res.status = rfsv_isalive() ? NFSERR_NOENT : NO_PSION;
return &res;
}
rfsv_fclose(phandle);
@@ -785,7 +767,7 @@ nfsproc_read_2(struct readargs *ra)
if (fp->size < ra->offset)
len = 0;
if (debug > 1)
- printf("Read: filesize %d read %d @ %d\n", fp->size, len, ra->offset);
+ debuglog("Read: filesize %d read %d @ %d\n", fp->size, len, ra->offset);
res.readres_u.reply.data.data_len = len;
res.readres_u.reply.data.data_val = (char *) rop;
@@ -836,12 +818,10 @@ addwritecache(struct cache *cp, int doff, int dlen, unsigned char *dp)
changed = 1;
}
if (doff >= dcp->offset && doff + dlen <= dcp->offset + dcp->len) {
- if (debug)
- printf("\twrite: full cache hit\n");
+ debuglog("write: full cache hit\n");
return !changed;
}
- if (debug)
- printf("\twrite: partial cache hit (off %d len %d)\n", dcp->offset, dcp->len);
+ debuglog("write: partial cache hit (off %d len %d)\n", dcp->offset, dcp->len);
/* Do we have some data below the cached area... */
if (doff < dcp->offset)
@@ -886,13 +866,11 @@ nfsproc_write_2(writeargs *wa)
int len, dlen, doff;
if (!inode) {
- if (debug)
- printf("write: stale fh\n");
+ debuglog("write: stale fh\n");
res.status = NO_PSION;
return &res;
}
- if (debug)
- printf("\twrite:%s off:%d l:%d\n", inode->name, wa->offset, wa->data.data_len);
+ debuglog("write:%s off:%d l:%d\n", inode->name, wa->offset, wa->data.data_len);
dlen = wa->data.data_len;
doff = wa->offset;
@@ -924,7 +902,7 @@ nfsproc_write_2(writeargs *wa)
for (;;) {
if (debug > 2)
for (dcp = cp->dcache; dcp; dcp = dcp->next)
- printf("\t\tCheck: %d=%d,%d,%d>=%d\n",
+ debuglog("Check: %d=%d,%d,%d>=%d\n",
inode->inode, cp->inode, dcp->towrite,
cp->actual_size, dcp->offset);
for (dcp = cp->dcache; dcp; dcp = dcp->next)
@@ -933,20 +911,17 @@ nfsproc_write_2(writeargs *wa)
if (!dcp) /* Can't write any blocks */
break;
- if (debug)
- printf("\twriting off: %d, len: %d, act: %d\n",
+ debuglog("writing off: %d, len: %d, act: %d\n",
dcp->offset, dcp->len, cp->actual_size);
if (rfsv_fopen(0x200, inode->name, &phandle) != 0) {
- if (debug)
- printf("write: open failed\n");
+ debuglog("write: open failed\n");
res.status = rfsv_isalive() ? NFSERR_NOSPC : NO_PSION;
return &res;
}
if (rfsv_write(dcp->data, dcp->offset, dcp->len, phandle) != dcp->len) {
rfsv_fclose(phandle);
- if (debug)
- printf("write: dump failed\n");
+ debuglog("write: dump failed\n");
res.status = rfsv_isalive() ? NFSERR_NOSPC : NO_PSION;
return &res;
}
@@ -955,12 +930,10 @@ nfsproc_write_2(writeargs *wa)
len = dcp->offset + dcp->len;
if (len > cp->actual_size)
cp->actual_size = len;
- if (debug)
- printf("\twritten: new length: %d\n", cp->actual_size);
+ debuglog("written: new length: %d\n", cp->actual_size);
}
- if (debug)
- printf("\twrite -> ISOK (%d, %d %d)\n",
+ debuglog("write -> ISOK (%d, %d %d)\n",
res.attrstat_u.attributes.size,
res.attrstat_u.attributes.fileid,
res.attrstat_u.attributes.fsid);
@@ -973,8 +946,7 @@ void *
nfsproc_writecache_2()
{
static char res;
- if (debug)
- printf("writecache???\n");
+ debuglog("writecache???\n");
res = (char) NFSERR_FBIG;
return (void *) &res;
}
@@ -983,8 +955,7 @@ void *
nfsproc_null_2()
{
static char res;
- if (debug)
- printf("null.\n");
+ debuglog("null.\n");
res = (char) NFSERR_FBIG;
return (void *) &res;
}
@@ -993,8 +964,7 @@ void *
nfsproc_root_2()
{
static char res;
- if (debug)
- printf("root????\n");
+ debuglog("root????\n");
res = (char) NFSERR_FBIG;
return (void *) &res;
}
@@ -1009,8 +979,7 @@ nfsproc_link_2(linkargs *la)
{
static nfsstat res;
- if (debug)
- printf("link..\n");
+ debuglog("link..\n");
res = NFSERR_ACCES;
return &res;
}
@@ -1021,8 +990,7 @@ nfsproc_readlink_2(struct nfs_fh *fh)
{
static readlinkres res;
- if (debug)
- printf("readlink...\n");
+ debuglog("readlink...\n");
res.status = NFSERR_ACCES;
return &res;
}
@@ -1033,8 +1001,7 @@ nfsproc_symlink_2(symlinkargs *sa)
{
static nfsstat res;
- if (debug)
- printf("symlink..\n");
+ debuglog("symlink..\n");
res = NFSERR_ACCES;
return &res;
}
diff --git a/plpnfsd/rfsv_api.h b/plpnfsd/rfsv_api.h
index 3633b53..f5377e3 100644
--- a/plpnfsd/rfsv_api.h
+++ b/plpnfsd/rfsv_api.h
@@ -26,6 +26,5 @@ extern long rfsv_drivelist(int *cnt, device **devlist);
extern long rfsv_dircount(const char *name, long *count);
extern long rfsv_statdev(char letter);
extern long rfsv_isalive();
-extern void rfsv_startup();
#endif