[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: diskfs_make_node
From: |
Neal H Walfield |
Subject: |
Re: diskfs_make_node |
Date: |
Sat, 17 Nov 2001 00:15:00 +0100 |
User-agent: |
Gnus/5.090004 (Oort Gnus v0.04) Emacs/21.1 |
> Those void functions you changed to error_t can never fail, so I don't see
> the point. The actual diskfs_make_node changes seem ok.
They can never fail today, however, I thought it made the interface a
bit more consistent. I guess, however, you are right, there is no
need.
Here is revised patch:
libdiskfs:
2001-11-16 Neal H Walfield <neal@cs.uml.edu>
* diskfs.h (diskfs_make_node): Change the prototype. The node
is now returned in a local argument and the function itself
returns an error_t.
* node-make.c (diskfs_make_node): Up date to new semantics.
Do more through error checking.
ext2fs:
2001-11-16 Neal H Walfield <neal@cs.uml.edu>
* inode.c (diskfs_cached_lookup): Implement the new semantics
of diskfs_make_node and check the result.
Only use the contents of NP if it was successfully read from
disk.
isofs:
2001-11-16 Neal H Walfield <neal@cs.uml.edu>
* inode.c (diskfs_cached_lookup): Implement the new semantics
of diskfs_make_node.
(load_inode): Likewise.
tmpfs:
2001-11-16 Neal H Walfield <neal@cs.uml.edu>
* node.c (diskfs_cached_lookup): Implement the new semantics
of diskfs_make_node and check the result.
ufs:
2001-11-16 Neal H Walfield <neal@cs.uml.edu>
* inode.c (diskfs_cached_lookup): Implement the new semantics
of diskfs_make_node and check the result.
Check the return of malloc.
Index: libdiskfs/diskfs.h
===================================================================
RCS file: /cvsroot/hurd/hurd/libdiskfs/diskfs.h,v
retrieving revision 1.92
diff -u -p -r1.92 diskfs.h
--- libdiskfs/diskfs.h 2001/08/20 22:44:13 1.92
+++ libdiskfs/diskfs.h 2001/11/16 23:08:29
@@ -654,7 +654,7 @@ diskfs_notice_filechange (struct node *n
/* Create a new node structure with DS as its physical disknode.
The new node will have one hard reference and no light references. */
-struct node *diskfs_make_node (struct disknode *dn);
+error_t diskfs_make_node (struct disknode *dn, struct node **np);
/* The library also exports the following functions; they are not generally
Index: libdiskfs/node-make.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libdiskfs/node-make.c,v
retrieving revision 1.15
diff -u -p -r1.15 node-make.c
--- libdiskfs/node-make.c 1998/08/10 17:42:39 1.15
+++ libdiskfs/node-make.c 2001/11/16 23:08:29
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1994, 1995, 1996 Free Software Foundation
+ Copyright (C) 1994, 1995, 1996, 2001 Free Software Foundation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -21,10 +21,15 @@
/* Create a and return new node structure with DN as its physical disknode.
The node will have one hard reference and no light references. */
-struct node *
-diskfs_make_node (struct disknode *dn)
+error_t
+diskfs_make_node (struct disknode *dn, struct node **npp)
{
- struct node *np = malloc (sizeof (struct node));
+ error_t err;
+ struct node *np;
+
+ *npp = np = malloc (sizeof (struct node));
+ if (! np)
+ return ENOMEM;
np->dn = dn;
np->dn_set_ctime = 0;
@@ -44,7 +49,6 @@ diskfs_make_node (struct disknode *dn)
fshelp_transbox_init (&np->transbox, &np->lock, np);
iohelp_initialize_conch (&np->conch, &np->lock);
fshelp_lock_init (&np->userlock);
-
- return np;
+ return 0;
}
Index: ext2fs/inode.c
===================================================================
RCS file: /cvsroot/hurd/hurd/ext2fs/inode.c,v
retrieving revision 1.58
diff -u -p -r1.58 inode.c
--- ext2fs/inode.c 2001/08/17 00:30:08 1.58
+++ ext2fs/inode.c 2001/11/16 23:08:25
@@ -94,7 +94,14 @@ diskfs_cached_lookup (int inum, struct n
pokel_init (&dn->indir_pokel, diskfs_disk_pager, disk_image);
/* Create the new node. */
- np = diskfs_make_node (dn);
+ err = diskfs_make_node (dn, &np);
+ if (err)
+ {
+ pokel_finalize (&dn->indir_pokel);
+ spin_unlock (&diskfs_node_refcnt_lock);
+ return err;
+ }
+
np->cache_id = inum;
mutex_lock (&np->lock);
@@ -111,7 +118,7 @@ diskfs_cached_lookup (int inum, struct n
/* Get the contents of NP off disk. */
err = read_node (np);
- if (!diskfs_check_readonly () && !np->dn_stat.st_gen)
+ if (!err && !diskfs_check_readonly () && !np->dn_stat.st_gen)
{
spin_lock (&generation_lock);
if (++next_generation < diskfs_mtime->seconds)
Index: isofs/inode.c
===================================================================
RCS file: /cvsroot/hurd/hurd/isofs/inode.c,v
retrieving revision 1.14
diff -u -p -r1.14 inode.c
--- isofs/inode.c 2001/02/20 19:37:28 1.14
+++ isofs/inode.c 2001/11/16 23:08:26
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+ Copyright (C) 1997, 1998, 2001 Free Software Foundation, Inc.
Written by Thomas Bushnell, n/BSG.
This file is part of the GNU Hurd.
@@ -198,13 +198,13 @@ diskfs_cached_lookup (int id, struct nod
dn->fileinfo = 0;
dn->dr = c->dr;
dn->file_start = c->file_start;
- np = diskfs_make_node (dn);
- if (!np)
+ err = diskfs_make_node (dn, &np);
+ if (err)
{
free (dn);
spin_unlock (&diskfs_node_refcnt_lock);
release_rrip (&rr);
- return ENOMEM;
+ return err;
}
np->cache_id = id + 1; /* see above for rationale for increment */
mutex_lock (&np->lock);
@@ -357,12 +357,12 @@ load_inode (struct node **npp, struct di
dn->dr = record;
dn->file_start = file_start;
- np = diskfs_make_node (dn);
- if (!np)
+ err = diskfs_make_node (dn, &np);
+ if (err)
{
free (dn);
spin_unlock (&diskfs_node_refcnt_lock);
- return ENOMEM;
+ return err;
}
mutex_lock (&np->lock);
Index: tmpfs/node.c
===================================================================
RCS file: /cvsroot/hurd/hurd/tmpfs/node.c,v
retrieving revision 1.9
diff -u -p -r1.9 node.c
--- tmpfs/node.c 2001/10/01 01:05:06 1.9
+++ tmpfs/node.c 2001/11/16 23:08:35
@@ -156,6 +156,7 @@ recompute_blocks (struct node *np)
error_t
diskfs_cached_lookup (int inum, struct node **npp)
{
+ error_t err;
struct disknode *dn = (void *) inum;
struct node *np;
@@ -174,7 +175,10 @@ diskfs_cached_lookup (int inum, struct n
{
struct stat *st;
- np = diskfs_make_node (dn);
+ err = diskfs_make_node (dn, &np);
+ if (err)
+ return err;
+
np->cache_id = (ino_t) dn;
spin_lock (&diskfs_node_refcnt_lock);
Index: ufs/inode.c
===================================================================
RCS file: /cvsroot/hurd/hurd/ufs/inode.c,v
retrieving revision 1.57
diff -u -p -r1.57 inode.c
--- ufs/inode.c 2001/08/10 04:43:01 1.57
+++ ufs/inode.c 2001/11/16 23:08:37
@@ -67,6 +67,11 @@ diskfs_cached_lookup (int inum, struct n
}
dn = malloc (sizeof (struct disknode));
+ if (! dn)
+ {
+ spin_unlock (&diskfs_node_refcnt_lock);
+ return ENOMEM;
+ }
dn->number = inum;
dn->dirents = 0;
@@ -76,7 +81,13 @@ diskfs_cached_lookup (int inum, struct n
dn->dirty = 0;
dn->fileinfo = 0;
- np = diskfs_make_node (dn);
+ err = diskfs_make_node (dn, &np);
+ if (err)
+ {
+ spin_unlock (&diskfs_node_refcnt_lock);
+ return ENOMEM;
+ }
+
np->cache_id = inum;
mutex_lock (&np->lock);