Skip to content

Commit

Permalink
Add NP_ASSERT macro and use that everywhere
Browse files Browse the repository at this point in the history
Removed ASSERT macro in libdiod and added NP_ASSERT macro in libnpfs.
Now all server code will log assert messages to the configured
log destination rather than lose them in some cases.
  • Loading branch information
garlick committed Mar 11, 2012
1 parent db36a11 commit 5e603d1
Show file tree
Hide file tree
Showing 34 changed files with 101 additions and 139 deletions.
1 change: 0 additions & 1 deletion diod/diod.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
#include <string.h>
#include <signal.h>
#include <pthread.h>
#include <assert.h>

#include "9p.h"
#include "npfs.h"
Expand Down
5 changes: 2 additions & 3 deletions diod/exp.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include <dirent.h>
#include <fcntl.h>
#include <utime.h>
#include <assert.h>
#include <stdarg.h>

#include "9p.h"
Expand Down Expand Up @@ -161,7 +160,7 @@ diod_match_exports (char *path, Npconn *conn, Npuser *user, int *xfp)
Export *x;
int res = 0; /* DENIED */

ASSERT (exports != NULL);
NP_ASSERT (exports != NULL);
if (strstr (path, "/..") != NULL) {
np_uerror (EPERM);
goto done;
Expand Down Expand Up @@ -256,7 +255,7 @@ diod_get_exports (char *name, void *a)
char *s = NULL;
char *ret = NULL;

ASSERT (exports != NULL);
NP_ASSERT (exports != NULL);

if (!(seen = list_create (NULL))) {
np_uerror (ENOMEM);
Expand Down
5 changes: 2 additions & 3 deletions diod/fid.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include <dirent.h>
#include <fcntl.h>
#include <utime.h>
#include <assert.h>
#include <stdarg.h>

#include "9p.h"
Expand All @@ -68,7 +67,7 @@ diod_fidalloc (Npfid *fid, Npstr *ns)
{
Fid *f = malloc (sizeof (*f));

ASSERT (fid->aux == NULL);
NP_ASSERT (fid->aux == NULL);
if (f) {
f->flags = 0;
f->ioctx = NULL;
Expand All @@ -91,7 +90,7 @@ diod_fidclone (Npfid *newfid, Npfid *fid)
Fid *f = fid->aux;
Fid *nf = malloc (sizeof (*f));

ASSERT (newfid->aux == NULL);
NP_ASSERT (newfid->aux == NULL);
if (nf) {
nf->flags = f->flags;
nf->ioctx = NULL;
Expand Down
13 changes: 6 additions & 7 deletions diod/ioctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,17 @@
#include <dirent.h>
#include <fcntl.h>
#include <utime.h>
#include <assert.h>
#include <stdarg.h>

#include "9p.h"
#include "npfs.h"
#include "list.h"
#include "hash.h"
#include "hostlist.h"
#include "xpthread.h"

#include "diod_conf.h"
#include "diod_log.h"
#include "diod_pthread.h"

#include "ioctx.h"
#include "fid.h"
Expand Down Expand Up @@ -196,7 +195,7 @@ ioctx_open (Npfid *fid, u32 flags, u32 mode)
&& (flags & 3) == O_RDONLY);
int maxmmap = diod_conf_get_maxmmap ();

ASSERT (f->ioctx == NULL);
NP_ASSERT (f->ioctx == NULL);

xpthread_mutex_lock (&f->path->lock);
if (sharable) {
Expand Down Expand Up @@ -374,7 +373,7 @@ ioctx_qid (IOCtx ioctx)
static void
_path_free (Path path)
{
ASSERT (path->ioctx == NULL);
NP_ASSERT (path->ioctx == NULL);
if (path->s)
free (path->s);
pthread_mutex_destroy (&path->lock);
Expand Down Expand Up @@ -420,7 +419,7 @@ _path_alloc (Npsrv *srv, char *s, int len)
path_incref (path);
free (s);
} else {
ASSERT (errno == 0);
NP_ASSERT (errno == 0);
if (!(path = malloc (sizeof (*path)))) {
free (s);
goto error;
Expand All @@ -431,7 +430,7 @@ _path_alloc (Npsrv *srv, char *s, int len)
path->len = len;
path->ioctx = NULL;
if (!hash_insert (pp->hash, path->s, path)) {
ASSERT (errno == ENOMEM);
NP_ASSERT (errno == ENOMEM);
goto error;
}
}
Expand Down Expand Up @@ -514,7 +513,7 @@ ppool_fini (Npsrv *srv)
if (pp) {
if (pp->hash) {
/* issue 99: this triggers when shutting down with active clients */
/*ASSERT (hash_is_empty (pp->hash));*/
/*NP_ASSERT (hash_is_empty (pp->hash));*/
hash_destroy (pp->hash);
}
pthread_mutex_destroy (&pp->lock);
Expand Down
3 changes: 1 addition & 2 deletions diod/ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
#include <dirent.h>
#include <fcntl.h>
#include <utime.h>
#include <assert.h>
#include <stdarg.h>

#include "9p.h"
Expand Down Expand Up @@ -207,7 +206,7 @@ diod_ustat2qid (struct stat *st, Npqid *qid)
static void
_dirent2qid (struct dirent *d, Npqid *qid)
{
ASSERT (d->d_type != DT_UNKNOWN);
NP_ASSERT (d->d_type != DT_UNKNOWN);
qid->path = d->d_ino;
qid->version = 0;
qid->type = 0;
Expand Down
3 changes: 1 addition & 2 deletions libdiod/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ libdiod_a_SOURCES = \
diod_conf.c \
diod_conf.h \
diod_sock.c \
diod_sock.h \
diod_pthread.h
diod_sock.h

if RDMATRANS
libdiod_a_SOURCES += diod_rdma.c diod_rdma.h
Expand Down
9 changes: 4 additions & 5 deletions libdiod/diod_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
#include <pwd.h>
#include <grp.h>
#include <errno.h>
#include <assert.h>
#if HAVE_LIBMUNGE
#define GPL_LICENSED 1
#include <munge.h>
Expand Down Expand Up @@ -127,7 +126,7 @@ _da_create (void)
static void
_da_destroy (da_t da)
{
ASSERT (da->magic == DIOD_AUTH_MAGIC);
NP_ASSERT (da->magic == DIOD_AUTH_MAGIC);
da->magic = 0;
if (da->datastr)
free (da->datastr);
Expand Down Expand Up @@ -181,7 +180,7 @@ checkauth(Npfid *fid, Npfid *afid, char *aname)
goto done;
}
da = afid->aux;
ASSERT (da->magic == DIOD_AUTH_MAGIC);
NP_ASSERT (da->magic == DIOD_AUTH_MAGIC);

snprintf (a, sizeof(a), "checkauth(%s@%s:%s)", fid->user->uname,
np_conn_get_client_id (fid->conn), aname ? aname : "<NULL>");
Expand All @@ -197,7 +196,7 @@ checkauth(Npfid *fid, Npfid *afid, char *aname)
err ("%s: munge cred decode: %s", a, munge_strerror (da->mungerr));
goto done;
}
ASSERT (afid->user->uid == fid->user->uid); /* enforced in np_attach */
NP_ASSERT (afid->user->uid == fid->user->uid); /* enforced in np_attach */
if (afid->user->uid != da->mungeuid) {
np_uerror (EPERM);
err ("%s: munge cred uid mismatch: %d", a, da->mungeuid);
Expand Down Expand Up @@ -232,7 +231,7 @@ writeafid(Npfid *afid, u64 offset, u32 count, u8 *data)
goto done;
}
da = afid->aux;
ASSERT (da->magic == DIOD_AUTH_MAGIC);
NP_ASSERT (da->magic == DIOD_AUTH_MAGIC);

if (offset == 0 && !da->datastr) {
da->datastr = malloc (count + 1);
Expand Down
10 changes: 1 addition & 9 deletions libdiod/diod_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <signal.h>

#include "diod_log.h"

Expand Down Expand Up @@ -315,14 +315,6 @@ msg (const char *fmt, ...)
va_end (ap);
}

void
msg_assfail (char *ass, char *file, int line)
{
msg ("%s::%d: assertion failure: %s", file, line, ass);
assert (0);
}


/*
* vi:tabstop=4 shiftwidth=4 expandtab
*/
3 changes: 0 additions & 3 deletions libdiod/diod_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ void msg_exit (const char *fmt, ...)
void msg (const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));

void msg_assfail (char *ass, char *file, int line);

#define ASSERT(exp) if ((exp)) ; else msg_assfail(#exp, __FILE__, __LINE__ )
/*
* vi:tabstop=4 shiftwidth=4 expandtab
*/
25 changes: 0 additions & 25 deletions libdiod/diod_pthread.h

This file was deleted.

1 change: 0 additions & 1 deletion libdiod/diod_rdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#include <sys/time.h>
#include <poll.h>
#include <pthread.h>
#include <assert.h>
#include <infiniband/verbs.h>
#include <rdma/rdma_cma.h>

Expand Down
3 changes: 1 addition & 2 deletions libdiod/diod_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#endif
#include <poll.h>
#include <pthread.h>
#include <assert.h>

#include "9p.h"
#include "npfs.h"
Expand Down Expand Up @@ -234,7 +233,7 @@ diod_sock_listen_hostports (List l, struct pollfd **fdsp, int *nfdsp,
goto done;
}
port = strchr (host, ':');
ASSERT (port != NULL);
NP_ASSERT (port != NULL);
*port++ = '\0';
if (nport)
port = nport;
Expand Down
1 change: 0 additions & 1 deletion libnpclient/fsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <pthread.h>
#include <errno.h>
#include <sys/socket.h>
#include <assert.h>
#include <stdint.h>
#include <inttypes.h>

Expand Down
3 changes: 1 addition & 2 deletions libnpclient/mtfsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <pthread.h>
#include <sys/socket.h>
#include <errno.h>
#include <assert.h>
#include <stdint.h>
#include <inttypes.h>

Expand Down Expand Up @@ -170,7 +169,7 @@ npc_decref_fsys(Npcfsys *fs)
return;
}

assert(fs->wfd<0 && fs->trans==NULL);
NP_ASSERT(fs->wfd<0 && fs->trans==NULL);
if (fs->tagpool) {
npc_destroy_pool(fs->tagpool);
fs->tagpool = NULL;
Expand Down
1 change: 0 additions & 1 deletion libnpclient/pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <errno.h>
#include <stdint.h>
#include <inttypes.h>
#include <assert.h>

#include "9p.h"
#include "npfs.h"
Expand Down
3 changes: 1 addition & 2 deletions libnpclient/readdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <stdint.h>
#include <inttypes.h>
#include <libgen.h>
#include <assert.h>
#include <sys/param.h>

#include "9p.h"
Expand All @@ -59,7 +58,7 @@ npc_readdir (Npcfid *fid, u64 offset, char *data, u32 count)
}
if (fid->fsys->rpc(fid->fsys, tc, &rc) < 0)
goto done;
assert (rc->u.rreaddir.count <= count);
NP_ASSERT(rc->u.rreaddir.count <= count);
memcpy (data, rc->u.rreaddir.data, rc->u.rreaddir.count);
ret = rc->u.rreaddir.count;
done:
Expand Down
7 changes: 3 additions & 4 deletions libnpfs/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <assert.h>

#include "9p.h"
#include "npfs.h"
Expand Down Expand Up @@ -96,7 +95,7 @@ void
np_conn_decref(Npconn *conn)
{
xpthread_mutex_lock(&conn->lock);
assert(conn->refcount > 0);
NP_ASSERT(conn->refcount > 0);
conn->refcount--;
xpthread_mutex_unlock(&conn->lock);
xpthread_cond_signal(&conn->refcond);
Expand All @@ -107,8 +106,8 @@ np_conn_destroy(Npconn *conn)
{
int n;

assert(conn != NULL);
assert(conn->refcount == 0);
NP_ASSERT(conn != NULL);
NP_ASSERT(conn->refcount == 0);
/* issue 83: remove from srv->conns before destroying fidpool
*/
np_srv_remove_conn (conn->srv, conn);
Expand Down
11 changes: 5 additions & 6 deletions libnpfs/ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <pthread.h>
#include <errno.h>
#include <fcntl.h>
#include <assert.h>
#include <sys/time.h>
#include <unistd.h>
#include <dirent.h>
Expand Down Expand Up @@ -301,7 +300,7 @@ np_ctl_attach(Npfid *fid, Npfid *afid, char *aname)
Npsrv *srv = fid->conn->srv;
Npfile *root = srv->ctlroot;

assert (aname && !strcmp (aname, "ctl"));
NP_ASSERT(aname && !strcmp (aname, "ctl"));
if (!root)
goto error;
if (!(f = _alloc_fid (root)))
Expand All @@ -325,9 +324,9 @@ np_ctl_clone(Npfid *fid, Npfid *newfid)
Fid *f = fid->aux;
Fid *nf;

assert (f != NULL);
assert (f->file != NULL);
assert (f->file->name != NULL);
NP_ASSERT(f != NULL);
NP_ASSERT(f->file != NULL);
NP_ASSERT(f->file->name != NULL);
if (!(nf = _alloc_fid (f->file))) {
np_uerror (ENOMEM);
return 0;
Expand Down Expand Up @@ -396,7 +395,7 @@ np_ctl_lopen(Npfid *fid, u32 mode)
np_uerror (EACCES);
goto done;
}
assert (f->data == NULL);
NP_ASSERT(f->data == NULL);

if (!(rc = np_create_rlopen (&f->file->qid, 0))) {
np_uerror (ENOMEM);
Expand Down
Loading

0 comments on commit 5e603d1

Please sign in to comment.