Skip to content

Commit

Permalink
Don't float puffs_kargs needlessly around after mount, saves
Browse files Browse the repository at this point in the history
a couple k of memory (and there was much rejoycing!)
  • Loading branch information
pooka committed Jul 19, 2007
1 parent 74579bd commit 96540a2
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 43 deletions.
16 changes: 8 additions & 8 deletions lib/libpuffs/flush.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: flush.c,v 1.10 2007/06/06 01:55:01 pooka Exp $ */
/* $NetBSD: flush.c,v 1.11 2007/07/19 12:52:28 pooka Exp $ */

/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
Expand Down Expand Up @@ -27,7 +27,7 @@

#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: flush.c,v 1.10 2007/06/06 01:55:01 pooka Exp $");
__RCSID("$NetBSD: flush.c,v 1.11 2007/07/19 12:52:28 pooka Exp $");
#endif /* !lint */

/*
Expand Down Expand Up @@ -61,7 +61,7 @@ puffs_inval_namecache_dir(struct puffs_usermount *pu, void *cookie)
pf.pf_op = PUFFS_INVAL_NAMECACHE_DIR;
pf.pf_cookie = cookie;

return ioctl(pu->pu_kargs.pa_fd, PUFFSFLUSHOP, &pf);
return ioctl(pu->pu_fd, PUFFSFLUSHOP, &pf);
}

int
Expand All @@ -72,7 +72,7 @@ puffs_inval_namecache_all(struct puffs_usermount *pu)
pf.pf_op = PUFFS_INVAL_NAMECACHE_ALL;
pf.pf_cookie = NULL;

return ioctl(pu->pu_kargs.pa_fd, PUFFSFLUSHOP, &pf);
return ioctl(pu->pu_fd, PUFFSFLUSHOP, &pf);
}

int
Expand All @@ -85,7 +85,7 @@ puffs_inval_pagecache_node(struct puffs_usermount *pu, void *cookie)
pf.pf_start = 0;
pf.pf_end = 0;

return ioctl(pu->pu_kargs.pa_fd, PUFFSFLUSHOP, &pf);
return ioctl(pu->pu_fd, PUFFSFLUSHOP, &pf);
}

int
Expand All @@ -99,7 +99,7 @@ puffs_inval_pagecache_node_range(struct puffs_usermount *pu, void *cookie,
pf.pf_start = start;
pf.pf_end = end;

return ioctl(pu->pu_kargs.pa_fd, PUFFSFLUSHOP, &pf);
return ioctl(pu->pu_fd, PUFFSFLUSHOP, &pf);
}

int
Expand All @@ -112,7 +112,7 @@ puffs_flush_pagecache_node(struct puffs_usermount *pu, void *cookie)
pf.pf_start = 0;
pf.pf_end = 0;

return ioctl(pu->pu_kargs.pa_fd, PUFFSFLUSHOP, &pf);
return ioctl(pu->pu_fd, PUFFSFLUSHOP, &pf);
}

int
Expand All @@ -126,5 +126,5 @@ puffs_flush_pagecache_node_range(struct puffs_usermount *pu, void *cookie,
pf.pf_start = start;
pf.pf_end = end;

return ioctl(pu->pu_kargs.pa_fd, PUFFSFLUSHOP, &pf);
return ioctl(pu->pu_fd, PUFFSFLUSHOP, &pf);
}
60 changes: 36 additions & 24 deletions lib/libpuffs/puffs.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: puffs.c,v 1.59 2007/07/19 07:54:46 pooka Exp $ */
/* $NetBSD: puffs.c,v 1.60 2007/07/19 12:52:28 pooka Exp $ */

/*
* Copyright (c) 2005, 2006, 2007 Antti Kantee. All Rights Reserved.
Expand Down Expand Up @@ -31,7 +31,7 @@

#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: puffs.c,v 1.59 2007/07/19 07:54:46 pooka Exp $");
__RCSID("$NetBSD: puffs.c,v 1.60 2007/07/19 12:52:28 pooka Exp $");
#endif /* !lint */

#include <sys/param.h>
Expand Down Expand Up @@ -106,7 +106,7 @@ int
puffs_getselectable(struct puffs_usermount *pu)
{

return pu->pu_kargs.pa_fd;
return pu->pu_fd;
}

int
Expand All @@ -120,7 +120,7 @@ puffs_setblockingmode(struct puffs_usermount *pu, int mode)
}

x = mode;
rv = ioctl(pu->pu_kargs.pa_fd, FIONBIO, &x);
rv = ioctl(pu->pu_fd, FIONBIO, &x);

if (rv == 0) {
if (mode == PUFFSDEV_BLOCK)
Expand Down Expand Up @@ -178,11 +178,13 @@ void
puffs_setrootinfo(struct puffs_usermount *pu, enum vtype vt,
vsize_t vsize, dev_t rdev)
{
struct puffs_kargs *pargs = &pu->pu_kargs;
struct puffs_kargs *pargs = pu->pu_kargp;

if (puffs_getstate(pu) != PUFFS_STATE_BEFOREMOUNT)
if (puffs_getstate(pu) != PUFFS_STATE_BEFOREMOUNT) {
warnx("puffs_setrootinfo: call has effect only "
"before mount\n");
return;
}

pargs->pa_root_vtype = vt;
pargs->pa_root_vsize = vsize;
Expand All @@ -200,7 +202,7 @@ size_t
puffs_getmaxreqlen(struct puffs_usermount *pu)
{

return pu->pu_kargs.pa_maxreqlen;
return pu->pu_maxreqlen;
}

void
Expand All @@ -211,7 +213,7 @@ puffs_setmaxreqlen(struct puffs_usermount *pu, size_t reqlen)
warnx("puffs_setmaxreqlen: call has effect only "
"before mount\n");

pu->pu_kargs.pa_maxreqlen = reqlen;
pu->pu_kargp->pa_maxreqlen = reqlen;
}

void
Expand All @@ -221,8 +223,8 @@ puffs_setfhsize(struct puffs_usermount *pu, size_t fhsize, int flags)
if (puffs_getstate(pu) != PUFFS_STATE_BEFOREMOUNT)
warnx("puffs_setfhsize: call has effect only before mount\n");

pu->pu_kargs.pa_fhsize = fhsize;
pu->pu_kargs.pa_fhflags = flags;
pu->pu_kargp->pa_fhsize = fhsize;
pu->pu_kargp->pa_fhflags = flags;
}

void
Expand All @@ -232,7 +234,7 @@ puffs_setncookiehash(struct puffs_usermount *pu, int nhash)
if (puffs_getstate(pu) != PUFFS_STATE_BEFOREMOUNT)
warnx("puffs_setfhsize: call has effect only before mount\n");

pu->pu_kargs.pa_nhashbuckets = nhash;
pu->pu_kargp->pa_nhashbuckets = nhash;
}

void
Expand Down Expand Up @@ -308,6 +310,7 @@ int
puffs_mount(struct puffs_usermount *pu, const char *dir, int mntflags,
void *cookie)
{
int rv;

#if 1
/* XXXkludgehere */
Expand All @@ -316,16 +319,19 @@ puffs_mount(struct puffs_usermount *pu, const char *dir, int mntflags,
mntflags |= MNT_NOSUID | MNT_NODEV;
#endif

pu->pu_kargs.pa_root_cookie = cookie;
if (mount(MOUNT_PUFFS, dir, mntflags,
&pu->pu_kargs, sizeof(struct puffs_kargs)) == -1)
return -1;
if (ioctl(pu->pu_kargs.pa_fd, PUFFSREQSIZEOP,
&pu->pu_kargs.pa_maxreqlen) == -1)
return -1;
pu->pu_kargp->pa_root_cookie = cookie;
if ((rv = mount(MOUNT_PUFFS, dir, mntflags,
pu->pu_kargp, sizeof(struct puffs_kargs))) == -1)
goto out;
if ((rv = ioctl(pu->pu_fd, PUFFSREQSIZEOP, &pu->pu_maxreqlen)) == -1)
goto out;
PU_SETSTATE(pu, PUFFS_STATE_RUNNING);

return 0;
out:
free(pu->pu_kargp);
pu->pu_kargp = NULL;

return rv;
}

struct puffs_usermount *
Expand All @@ -334,7 +340,7 @@ _puffs_init(int develv, struct puffs_ops *pops, const char *mntfromname,
{
struct puffs_usermount *pu;
struct puffs_kargs *pargs;
int fd;
int sverrno, fd;

if (develv != PUFFS_DEVEL_LIBVERSION) {
warnx("puffs_init: mounting with lib version %d, need %d",
Expand All @@ -357,10 +363,14 @@ _puffs_init(int develv, struct puffs_ops *pops, const char *mntfromname,
goto failfree;
memset(pu, 0, sizeof(struct puffs_usermount));

pargs = &pu->pu_kargs;
pargs = pu->pu_kargp = malloc(sizeof(struct puffs_kargs));
if (pargs == NULL)
goto failfree;
memset(pargs, 0, sizeof(struct puffs_kargs));

pargs->pa_vers = PUFFSDEVELVERS | PUFFSVERSION;
pargs->pa_flags = PUFFS_FLAG_KERN(pflags);
pargs->pa_fd = fd;
pargs->pa_fd = pu->pu_fd = fd;
fillvnopmask(pops, pargs->pa_vnopmask);
(void)strlcpy(pargs->pa_typename, puffsname,
sizeof(pargs->pa_typename));
Expand Down Expand Up @@ -399,8 +409,10 @@ _puffs_init(int develv, struct puffs_ops *pops, const char *mntfromname,

failfree:
/* can't unmount() from here for obvious reasons */
sverrno = errno;
close(fd);
free(pu);
errno = sverrno;
return NULL;
}

Expand All @@ -416,8 +428,8 @@ puffs_exit(struct puffs_usermount *pu, int force)

force = 1; /* currently */

if (pu->pu_kargs.pa_fd)
close(pu->pu_kargs.pa_fd);
if (pu->pu_fd)
close(pu->pu_fd);

while ((pn = LIST_FIRST(&pu->pu_pnodelst)) != NULL)
puffs_pn_put(pn);
Expand Down
8 changes: 6 additions & 2 deletions lib/libpuffs/puffs_priv.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: puffs_priv.h,v 1.17 2007/07/07 21:13:42 pooka Exp $ */
/* $NetBSD: puffs_priv.h,v 1.18 2007/07/19 12:52:28 pooka Exp $ */

/*
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
Expand Down Expand Up @@ -85,7 +85,9 @@ struct puffs_fctrl_io {
*/
struct puffs_usermount {
struct puffs_ops pu_ops;
struct puffs_kargs pu_kargs;

int pu_fd;
size_t pu_maxreqlen;

uint32_t pu_flags;
size_t pu_cc_stacksize;
Expand Down Expand Up @@ -117,6 +119,8 @@ struct puffs_usermount {
struct timespec pu_ml_timeout;
struct timespec *pu_ml_timep;

struct puffs_kargs *pu_kargp;

void *pu_privdata;
};

Expand Down
10 changes: 4 additions & 6 deletions lib/libpuffs/requests.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: requests.c,v 1.8 2007/06/06 01:55:01 pooka Exp $ */
/* $NetBSD: requests.c,v 1.9 2007/07/19 12:52:28 pooka Exp $ */

/*
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
Expand Down Expand Up @@ -27,7 +27,7 @@

#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: requests.c,v 1.8 2007/06/06 01:55:01 pooka Exp $");
__RCSID("$NetBSD: requests.c,v 1.9 2007/07/19 12:52:28 pooka Exp $");
#endif /* !lint */

#include <sys/types.h>
Expand Down Expand Up @@ -76,8 +76,7 @@ puffs_req_loadget(struct puffs_getreq *pgr)
/* reset */
pgr->pgr_phg = pgr->pgr_phg_orig;

if (ioctl(pgr->pgr_pu->pu_kargs.pa_fd,
PUFFSGETOP, &pgr->pgr_phg) == -1)
if (ioctl(pgr->pgr_pu->pu_fd, PUFFSGETOP, &pgr->pgr_phg) == -1)
return -1;

pgr->pgr_nextpreq = pgr->pgr_phg.phg_buf;
Expand Down Expand Up @@ -183,8 +182,7 @@ puffs_req_putput(struct puffs_putreq *ppr)
{

if (ppr->ppr_php.php_nops)
if (ioctl(ppr->ppr_pu->pu_kargs.pa_fd,
PUFFSPUTOP, &ppr->ppr_php) == -1)
if (ioctl(ppr->ppr_pu->pu_fd, PUFFSPUTOP, &ppr->ppr_php) == -1)
return -1;

return 0;
Expand Down
6 changes: 3 additions & 3 deletions lib/libpuffs/suspend.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: suspend.c,v 1.4 2007/06/06 01:55:01 pooka Exp $ */
/* $NetBSD: suspend.c,v 1.5 2007/07/19 12:52:28 pooka Exp $ */

/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
Expand Down Expand Up @@ -27,7 +27,7 @@

#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: suspend.c,v 1.4 2007/06/06 01:55:01 pooka Exp $");
__RCSID("$NetBSD: suspend.c,v 1.5 2007/07/19 12:52:28 pooka Exp $");
#endif /* !lint */

/*
Expand All @@ -46,5 +46,5 @@ int
puffs_fs_suspend(struct puffs_usermount *pu)
{

return ioctl(pu->pu_kargs.pa_fd, PUFFSSUSPENDOP);
return ioctl(pu->pu_fd, PUFFSSUSPENDOP);
}

0 comments on commit 96540a2

Please sign in to comment.