[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
some nfs clean up's I found
From: |
James A Morrison |
Subject: |
some nfs clean up's I found |
Date: |
Sat, 9 Nov 2002 17:23:02 -0500 (EST) |
Hi,
I was cleaning up my home directory and found an old patch. So I updated
the patch, took out some bad stuff andhere it is.. I tested this by attaching
the translator to a node, and doing an ls on the attached filesystem.
The clean ups are fairly obvious, I've mostly only added some more error
checking.
James A. Morrison
2002-11-09 James A. Morrison <ja2morri@uwaterloo.ca>
* ops.c (netfs_attempt_mkfile): Use asprintf instead of sprintf.
(netfs_attempt_unlink): Likewise.
(netfs_report_access): Pass !ERR to process_returned_stat as similar
calls to process_returned_stat do.
* nfs.c (xdr_decode_fhandle): Check the return value of lookup_fhandle.
* cache.c (lookup_fhandle): Return an error_t.
* nfs.h: Make lookup_fhandle return an error_t.
Index: cache.c
===================================================================
RCS file: /cvsroot/hurd/hurd/nfs/cache.c,v
retrieving revision 1.16
diff -u -p -r1.16 cache.c
--- cache.c 29 Sep 2002 15:11:59 -0000 1.16
+++ cache.c 9 Nov 2002 15:51:07 -0000
@@ -50,9 +50,10 @@ hash (int *data, size_t len)
hash table. Whichever course, a new reference is generated and the
node is returned in *NPP; the lock on the node, (*NPP)->LOCK, is
held. */
-void
+error_t
lookup_fhandle (void *p, size_t len, struct node **npp)
{
+ error_t err = 0;
struct node *np;
struct netnode *nn;
int h;
@@ -70,12 +71,13 @@ lookup_fhandle (void *p, size_t len, str
spin_unlock (&netfs_node_refcnt_lock);
mutex_lock (&np->lock);
*npp = np;
- return;
+ return 0;
}
/* Could not find it */
nn = malloc (sizeof (struct netnode));
- assert (nn);
+ if (!nn)
+ return errno;
nn->handle.size = len;
memcpy (nn->handle.data, p, len);
@@ -85,16 +87,21 @@ lookup_fhandle (void *p, size_t len, str
nn->dead_name = 0;
np = netfs_make_node (nn);
- mutex_lock (&np->lock);
- nn->hnext = nodehash[h];
- if (nn->hnext)
- nn->hnext->nn->hprevp = &nn->hnext;
- nn->hprevp = &nodehash[h];
- nodehash[h] = np;
+ if (np)
+ {
+ mutex_lock (&np->lock);
+ nn->hnext = nodehash[h];
+ if (nn->hnext)
+ nn->hnext->nn->hprevp = &nn->hnext;
+ nn->hprevp = &nodehash[h];
+ *npp = nodehash[h] = np;
+ }
+ else
+ err = errno;
spin_unlock (&netfs_node_refcnt_lock);
-
- *npp = np;
+
+ return err;
}
/* Package holding args to forked_node_delete. */
Index: nfs.c
===================================================================
RCS file: /cvsroot/hurd/hurd/nfs/nfs.c,v
retrieving revision 1.27
diff -u -p -r1.27 nfs.c
--- nfs.c 29 Sep 2002 15:11:59 -0000 1.27
+++ nfs.c 9 Nov 2002 15:51:08 -0000
@@ -390,7 +390,8 @@ xdr_decode_fhandle (int *p, struct node
p++;
}
/* Enter into cache. */
- lookup_fhandle (p, len, npp);
+ err = lookup_fhandle (p, len, npp);
+ assert_perror (err);
return p + len / sizeof (int);
}
Index: nfs.h
===================================================================
RCS file: /cvsroot/hurd/hurd/nfs/nfs.h,v
retrieving revision 1.18
diff -u -p -r1.18 nfs.h
--- nfs.h 29 Dec 2001 00:40:09 -0000 1.18
+++ nfs.h 9 Nov 2002 15:51:09 -0000
@@ -1,5 +1,5 @@
/* Data structures and global variables for NFS client
- Copyright (C) 1994,95,96,97,99,2001 Free Software Foundation, Inc.
+ Copyright (C) 1994,95,96,97,99,2001,02 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -191,7 +191,7 @@ void timeout_service_thread (void);
void rpc_receive_thread (void);
/* cache.c */
-void lookup_fhandle (void *, size_t, struct node **);
+error_t lookup_fhandle (void *, size_t, struct node **);
int *recache_handle (int *, struct node *);
/* name-cache.c */
Index: ops.c
===================================================================
RCS file: /cvsroot/hurd/hurd/nfs/ops.c,v
retrieving revision 1.44
diff -u -p -r1.44 ops.c
--- ops.c 29 Sep 2002 15:11:59 -0000 1.44
+++ ops.c 9 Nov 2002 15:51:13 -0000
@@ -1111,20 +1111,17 @@ netfs_attempt_mkfile (struct iouser *cre
char *name;
static int n = 0;
- /* This is the best we can do. */
-
- name = malloc (50);
- if (! name)
- return ENOMEM;
-
do
{
- sprintf (name, ".nfstmpgnu.%d", n++);
+ if (asprintf (&name, ".nfstmpgnu.%d", n++) < 0)
+ return errno;
err = netfs_attempt_create_file (cred, dir, name, mode, newnp);
if (err == EEXIST)
- mutex_lock (&dir->lock); /* XXX is this right? does create need this
- and drop this on error? Doesn't look
- like it. */
+ {
+ mutex_lock (&dir->lock); /* Relock the directory so we can try to
+ create another file. */
+ free (name);
+ }
}
while (err == EEXIST);
@@ -1274,18 +1271,17 @@ netfs_attempt_unlink (struct iouser *cre
mutex_unlock (&dir->lock);
- newname = malloc (50);
- if (! newname)
- {
- mutex_lock (&dir->lock);
- netfs_nrele (np); /* XXX Is this the correct thing to do? */
- return ENOMEM;
- }
-
do
{
- sprintf (newname, ".nfs%txgnu.%d", (ptrdiff_t) np, n++);
+ if (asprintf (&newname, ".nfs%txgnu.%d", (ptrdiff_t) np, n++) < 0)
+ {
+ mutex_lock (&dir->lock);
+ netfs_nrele (np); /* XXX Is this the correct thing to do? */
+ return errno;
+ }
err = netfs_attempt_link (cred, dir, np, newname, 1);
+ if (err == EEXIST)
+ free (newname);
}
while (err == EEXIST);
@@ -1532,9 +1528,7 @@ netfs_report_access (struct iouser *cred
{
err = nfs_error_trans (ntohl (*p));
p++;
- p = process_returned_stat (np, p, 0); /* XXX Should this be
- protected by the
- if (!err) ? */
+ p = process_returned_stat (np, p, !err);
if (!err)
{
ret = ntohl (*p);
- some nfs clean up's I found,
James A Morrison <=