1
1

* gc.c: Make getid(), nothingisopen() and free() methods

optional.  Eliminate trivial implementations.
(vfs_getid): New function - safe wrapper around getid().  Use
it everywhere.
(vfs_ncs_getid): Remove dead code, inprove readability.
Этот коммит содержится в:
Pavel Roskin 2003-11-08 23:53:00 +00:00
родитель 12d78ba8df
Коммит 4eab382dba
9 изменённых файлов: 53 добавлений и 108 удалений

Просмотреть файл

@ -1,3 +1,11 @@
2003-11-08 Pavel Roskin <proski@gnu.org>
* gc.c: Make getid(), nothingisopen() and free() methods
optional. Eliminate trivial implementations.
(vfs_getid): New function - safe wrapper around getid(). Use
it everywhere.
(vfs_ncs_getid): Remove dead code, inprove readability.
2003-11-07 Pavel Roskin <proski@gnu.org>
* vfs.c: Split garbage collection code into ...

Просмотреть файл

@ -440,7 +440,7 @@ vfs_s_stamp_me (struct vfs_class *me, struct vfs_s_super *psup,
parent = g_new (struct vfs_stamping, 1);
parent->v = v;
parent->next = 0;
parent->id = (*v->getid) (v, fs_name, &(parent->parent));
parent->id = vfs_getid (v, fs_name, &(parent->parent));
}
vfs_add_noncurrent_stamps (me, (vfsid) psup, parent);
}
@ -863,7 +863,7 @@ vfs_s_close (void *fh)
parent = g_new (struct vfs_stamping, 1);
parent->v = v;
parent->next = 0;
parent->id = (*v->getid) (v, FH_SUPER->name, &(parent->parent));
parent->id = vfs_getid (v, FH_SUPER->name, &(parent->parent));
}
vfs_add_noncurrent_stamps (me, (vfsid) (FH_SUPER), parent);
}
@ -1071,7 +1071,7 @@ vfs_s_getid (struct vfs_class *me, const char *path, struct vfs_stamping **paren
return (vfsid) -1;
g_free(p);
v = vfs_get_class (archive->name);
id = (*v->getid) (v, archive->name, &par);
id = vfs_getid (v, archive->name, &par);
if (id != (vfsid)-1){
*parent = g_new (struct vfs_stamping, 1);
(*parent)->v = v;

Просмотреть файл

@ -478,7 +478,7 @@ extfs_get_path_mangle (const char *inname, struct archive **archive,
parent = g_new (struct vfs_stamping, 1);
parent->v = v;
parent->next = 0;
parent->id = (*v->getid) (v, archive_name, &(parent->parent));
parent->id = vfs_getid (v, archive_name, &(parent->parent));
}
vfs_add_noncurrent_stamps (&vfs_extfs_ops, (vfsid) parc, parent);
}
@ -769,7 +769,7 @@ extfs_close (void *data)
parent->v = v;
parent->next = 0;
parent->id =
(*v->getid) (v, file->archive->name, &(parent->parent));
vfs_getid (v, file->archive->name, &(parent->parent));
}
vfs_add_noncurrent_stamps (&vfs_extfs_ops, (vfsid) (file->archive),
parent);
@ -1136,7 +1136,7 @@ static vfsid extfs_getid (struct vfs_class *me, const char *path, struct vfs_sta
g_free(p);
if (archive->name){
v = vfs_get_class (archive->name);
id = (*v->getid) (v, archive->name, &par);
id = vfs_getid (v, archive->name, &par);
if (id != (vfsid)-1) {
*parent = g_new (struct vfs_stamping, 1);
(*parent)->v = v;

Просмотреть файл

@ -144,6 +144,22 @@ vfs_rmstamp (struct vfs_class *v, vfsid id, int removeparents)
}
/* Wrapper around getid methods */
vfsid
vfs_getid (struct vfs_class *vclass, const char *path,
struct vfs_stamping **parent)
{
vfsid id = (vfsid) - 1;
*parent = NULL;
if (vclass->getid)
id = (*vclass->getid) (vclass, path, parent);
return id;
}
/* Same as vfs_getid, but append slash to the path if needed */
vfsid
vfs_ncs_getid (struct vfs_class *nvfs, const char *dir,
struct vfs_stamping **par)
@ -152,7 +168,7 @@ vfs_ncs_getid (struct vfs_class *nvfs, const char *dir,
char *dir1;
dir1 = concat_dir_and_file (dir, "");
nvfsid = (*nvfs->getid) (nvfs, dir1, par);
nvfsid = vfs_getid (nvfs, dir1, par);
g_free (dir1);
return nvfsid;
}
@ -219,7 +235,7 @@ _vfs_add_noncurrent_stamps (struct vfs_class *oldvfs, vfsid oldvfsid,
f = is_parent (oldvfs, oldvfsid, par);
vfs_rm_parents (par);
if ((nvfs == oldvfs && nvfsid == oldvfsid) || oldvfsid == (vfsid *) - 1
if ((nvfs == oldvfs && nvfsid == oldvfsid) || oldvfsid == (vfsid) - 1
|| f) {
return;
}
@ -232,7 +248,7 @@ _vfs_add_noncurrent_stamps (struct vfs_class *oldvfs, vfsid oldvfsid,
if ((n2vfs == oldvfs && n2vfsid == oldvfsid) || f)
return;
} else {
n2vfs = (struct vfs_class *) -1;
n2vfs = NULL;
n2vfsid = (vfsid) - 1;
}
@ -244,36 +260,22 @@ _vfs_add_noncurrent_stamps (struct vfs_class *oldvfs, vfsid oldvfsid,
if ((n3vfs == oldvfs && n3vfsid == oldvfsid) || f)
return;
} else {
n3vfs = (struct vfs_class *) -1;
n3vfs = NULL;
n3vfsid = (vfsid) - 1;
}
if ((*oldvfs->nothingisopen) (oldvfsid)) {
#if 0 /* need setctl for this */
if (oldvfs == &vfs_extfs_ops
&& ((extfs_archive *) oldvfsid)->name == 0) {
/* Free the resources immediatly when we leave a mtools fs
('cd a:') instead of waiting for the vfs-timeout */
(oldvfs->free) (oldvfsid);
} else
#endif
vfs_addstamp (oldvfs, oldvfsid, parent);
for (stamp = parent; stamp != NULL; stamp = stamp->parent) {
if ((stamp->v == nvfs && stamp->id == nvfsid)
|| (stamp->v == n2vfs && stamp->id == n2vfsid)
|| (stamp->v == n3vfs && stamp->id == n3vfsid)
|| stamp->id == (vfsid) - 1
|| !(*stamp->v->nothingisopen) (stamp->id))
break;
#if 0
if (stamp->v == &vfs_extfs_ops
&& ((extfs_archive *) stamp->id)->name == 0) {
(stamp->v->free) (stamp->id);
vfs_rmstamp (stamp->v, stamp->id, 0);
} else
#endif
vfs_addstamp (stamp->v, stamp->id, stamp->parent);
}
if (!oldvfs->nothingisopen || !(*oldvfs->nothingisopen) (oldvfsid))
return;
vfs_addstamp (oldvfs, oldvfsid, parent);
for (stamp = parent; stamp != NULL; stamp = stamp->parent) {
if ((stamp->v == nvfs && stamp->id == nvfsid)
|| (stamp->v == n2vfs && stamp->id == n2vfsid)
|| (stamp->v == n3vfs && stamp->id == n3vfsid)
|| stamp->id == (vfsid) - 1 || !stamp->v->nothingisopen
|| !(*stamp->v->nothingisopen) (stamp->id))
break;
vfs_addstamp (stamp->v, stamp->id, stamp->parent);
}
}
@ -335,7 +337,8 @@ vfs_expire (int now)
for (stamp = stamps; stamp != NULL;) {
if (now || (timeoutcmp (&stamp->time, &time))) {
st = stamp->next;
(*stamp->v->free) (stamp->id);
if (stamp->v->free)
(*stamp->v->free) (stamp->id);
vfs_rmstamp (stamp->v, stamp->id, 0);
stamp = st;
} else
@ -384,7 +387,8 @@ vfs_gc_done (void)
struct vfs_stamping *stamp, *st;
for (stamp = stamps, stamps = 0; stamp != NULL;) {
(*stamp->v->free) (stamp->id);
if (stamp->v->free)
(*stamp->v->free) (stamp->id);
st = stamp->next;
g_free (stamp);
stamp = st;

Просмотреть файл

@ -20,6 +20,8 @@ void vfs_timeout_handler (void);
void vfs_expire (int);
int vfs_timeouts (void);
void vfs_release_path (const char *dir);
vfsid vfs_getid (struct vfs_class *vclass, const char *path,
struct vfs_stamping **parent);
vfsid vfs_ncs_getid (struct vfs_class *nvfs, const char *dir,
struct vfs_stamping **par);
void vfs_gc_done (void);

Просмотреть файл

@ -230,24 +230,6 @@ local_rmdir (struct vfs_class *me, char *path)
return rmdir (path);
}
static vfsid
local_getid (struct vfs_class *me, const char *path, struct vfs_stamping **parent)
{
*parent = NULL;
return (vfsid) -1; /* We do not free local fs stuff at all */
}
static int
local_nothingisopen (vfsid id)
{
return 0;
}
static void
local_free (vfsid id)
{
}
static char *
local_getlocalcopy (struct vfs_class *me, const char *path)
{
@ -311,9 +293,6 @@ init_localfs (void)
vfs_local_ops.ferrno = local_errno;
vfs_local_ops.lseek = local_lseek;
vfs_local_ops.mknod = local_mknod;
vfs_local_ops.getid = local_getid;
vfs_local_ops.nothingisopen = local_nothingisopen;
vfs_local_ops.free = local_free;
vfs_local_ops.getlocalcopy = local_getlocalcopy;
vfs_local_ops.ungetlocalcopy = local_ungetlocalcopy;
vfs_local_ops.mkdir = local_mkdir;

Просмотреть файл

@ -1071,29 +1071,6 @@ mcfs_link (struct vfs_class *me, char *p1, char *p2)
return mcfs_rpc_two_paths (MC_LINK, p1, p2);
}
/* We do not free anything right now: we free resources when we run
* out of them
*/
static vfsid
mcfs_getid (struct vfs_class *me, const char *p, struct vfs_stamping **parent)
{
*parent = NULL;
return (vfsid) - 1;
}
static int
mcfs_nothingisopen (vfsid id)
{
return 0;
}
static void
mcfs_free (vfsid id)
{
/* FIXME: Should not be empty */
}
/* Gives up on a socket and reopnes the connection, the child own the socket
* now
*/
@ -1178,9 +1155,6 @@ init_mcfs (void)
vfs_mcfs_ops.ferrno = mcfs_errno;
vfs_mcfs_ops.lseek = mcfs_lseek;
vfs_mcfs_ops.mknod = mcfs_mknod;
vfs_mcfs_ops.getid = mcfs_getid;
vfs_mcfs_ops.nothingisopen = mcfs_nothingisopen;
vfs_mcfs_ops.free = mcfs_free;
vfs_mcfs_ops.mkdir = mcfs_mkdir;
vfs_mcfs_ops.rmdir = mcfs_rmdir;
vfs_mcfs_ops.setctl = mcfs_setctl;

Просмотреть файл

@ -242,7 +242,7 @@ sfs_getid (struct vfs_class *me, const char *path, struct vfs_stamping **parent)
/* ... and learn whoever was the parent system */
v = vfs_split (path2, NULL, NULL);
id = (*v->getid) (v, path2, &par);
id = vfs_getid (v, path2, &par);
g_free (path2);
}

Просмотреть файл

@ -1670,30 +1670,10 @@ smbfs_link (struct vfs_class *me, char *p1, char *p2)
return -1;
}
/* We do not free anything right now: we free resources when we run
* out of them
*/
static vfsid
smbfs_getid (struct vfs_class *me, const char *p, struct vfs_stamping **parent)
{
*parent = NULL;
DEBUG (3, ("smbfs_getid(p:%s)\n", p));
return (vfsid) - 1;
}
static int
smbfs_nothingisopen (vfsid id)
{
DEBUG (3, ("smbfs_nothingisopen(%p)\n", id));
return 0;
}
static void
smbfs_free (vfsid id)
{
DEBUG (3, ("smbfs_free(%p)\n", id));
/* FIXME: Should not be empty */
smbfs_auth_free_all ();
}
@ -1926,8 +1906,6 @@ init_smbfs (void)
vfs_smbfs_ops.ferrno = smbfs_errno;
vfs_smbfs_ops.lseek = smbfs_lseek;
vfs_smbfs_ops.mknod = smbfs_mknod;
vfs_smbfs_ops.getid = smbfs_getid;
vfs_smbfs_ops.nothingisopen = smbfs_nothingisopen;
vfs_smbfs_ops.free = smbfs_free;
vfs_smbfs_ops.mkdir = smbfs_mkdir;
vfs_smbfs_ops.rmdir = smbfs_rmdir;