From 5e603d14ad9fed2a4b4217f9da39760237418982 Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Sun, 11 Mar 2012 10:55:03 -0700 Subject: [PATCH] Add NP_ASSERT macro and use that everywhere 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. --- diod/diod.c | 1 - diod/exp.c | 5 ++--- diod/fid.c | 5 ++--- diod/ioctx.c | 13 ++++++------- diod/ops.c | 3 +-- libdiod/Makefile.am | 3 +-- libdiod/diod_auth.c | 9 ++++----- libdiod/diod_log.c | 10 +--------- libdiod/diod_log.h | 3 --- libdiod/diod_pthread.h | 25 ------------------------- libdiod/diod_rdma.c | 1 - libdiod/diod_sock.c | 3 +-- libnpclient/fsys.c | 1 - libnpclient/mtfsys.c | 3 +-- libnpclient/pool.c | 1 - libnpclient/readdir.c | 3 +-- libnpfs/conn.c | 7 +++---- libnpfs/ctl.c | 11 +++++------ libnpfs/fcall.c | 3 +-- libnpfs/fdtrans.c | 3 +-- libnpfs/fidpool.c | 15 +++++++-------- libnpfs/fmt.c | 1 - libnpfs/np.c | 11 +++++------ libnpfs/npfs.h | 2 ++ libnpfs/npstring.c | 3 +-- libnpfs/rdmatrans.c | 1 - libnpfs/srv.c | 36 ++++++++++++++++++++++++++++-------- libnpfs/user.c | 5 ++--- libnpfs/xpthread.h | 12 ++++++------ utils/diodcat.c | 3 +-- utils/diodload.c | 1 - utils/diodmount.c | 15 +++++++-------- utils/dtop.c | 3 +-- utils/opt.c | 19 +++++++++++-------- 34 files changed, 101 insertions(+), 139 deletions(-) delete mode 100644 libdiod/diod_pthread.h diff --git a/diod/diod.c b/diod/diod.c index f3f4431c..ede21835 100644 --- a/diod/diod.c +++ b/diod/diod.c @@ -49,7 +49,6 @@ #include #include #include -#include #include "9p.h" #include "npfs.h" diff --git a/diod/exp.c b/diod/exp.c index 861a6772..b7575d55 100644 --- a/diod/exp.c +++ b/diod/exp.c @@ -42,7 +42,6 @@ #include #include #include -#include #include #include "9p.h" @@ -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; @@ -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); diff --git a/diod/fid.c b/diod/fid.c index 4aa63cdb..f6b57a0c 100644 --- a/diod/fid.c +++ b/diod/fid.c @@ -45,7 +45,6 @@ #include #include #include -#include #include #include "9p.h" @@ -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; @@ -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; diff --git a/diod/ioctx.c b/diod/ioctx.c index 9c35fcca..53f7a0d4 100644 --- a/diod/ioctx.c +++ b/diod/ioctx.c @@ -45,7 +45,6 @@ #include #include #include -#include #include #include "9p.h" @@ -53,10 +52,10 @@ #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" @@ -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) { @@ -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); @@ -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; @@ -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; } } @@ -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); diff --git a/diod/ops.c b/diod/ops.c index 7e10a740..16b63f4b 100644 --- a/diod/ops.c +++ b/diod/ops.c @@ -79,7 +79,6 @@ #include #include #include -#include #include #include "9p.h" @@ -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; diff --git a/libdiod/Makefile.am b/libdiod/Makefile.am index d96d0334..4810e141 100644 --- a/libdiod/Makefile.am +++ b/libdiod/Makefile.am @@ -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 diff --git a/libdiod/diod_auth.c b/libdiod/diod_auth.c index 327fd2a6..eb7c1229 100644 --- a/libdiod/diod_auth.c +++ b/libdiod/diod_auth.c @@ -53,7 +53,6 @@ #include #include #include -#include #if HAVE_LIBMUNGE #define GPL_LICENSED 1 #include @@ -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); @@ -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 : ""); @@ -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); @@ -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); diff --git a/libdiod/diod_log.c b/libdiod/diod_log.c index 62025be2..d915b9c4 100644 --- a/libdiod/diod_log.c +++ b/libdiod/diod_log.c @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include "diod_log.h" @@ -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 */ diff --git a/libdiod/diod_log.h b/libdiod/diod_log.h index c597c9c2..b328cfdd 100644 --- a/libdiod/diod_log.h +++ b/libdiod/diod_log.h @@ -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 */ diff --git a/libdiod/diod_pthread.h b/libdiod/diod_pthread.h deleted file mode 100644 index 9c686aa1..00000000 --- a/libdiod/diod_pthread.h +++ /dev/null @@ -1,25 +0,0 @@ -/* pthread wrappers */ -#define xpthread_mutex_lock(a) do { \ - int pthread_mutex_lock_result = pthread_mutex_lock(a); \ - ASSERT (pthread_mutex_lock_result == 0); \ -} while (0) -#define xpthread_mutex_unlock(a) do { \ - int pthread_mutex_unlock_result = pthread_mutex_unlock(a); \ - ASSERT (pthread_mutex_unlock_result == 0); \ -} while (0) -#define xpthread_cond_wait(a,b) do { \ - int pthread_cond_wait_result = pthread_cond_wait(a,b); \ - ASSERT (pthread_cond_wait_result == 0); \ -} while (0) -#define xpthread_cond_timedwait(a,b,c) do { \ - int pthread_cond_timedwait_result = pthread_cond_timedwait(a,b,c); \ - ASSERT (pthread_cond_timedwait_result == 0); \ -} while (0) -#define xpthread_cond_broadcast(a) do { \ - int pthread_cond_broadcast_result = pthread_cond_broadcast(a); \ - ASSERT (pthread_cond_broadcast_result == 0); \ -} while (0) -#define xpthread_cond_signal(a) do { \ - int pthread_cond_signal_result = pthread_cond_signal(a); \ - ASSERT (pthread_cond_signal_result == 0); \ -} while (0) diff --git a/libdiod/diod_rdma.c b/libdiod/diod_rdma.c index b0b5c620..a755c3b7 100644 --- a/libdiod/diod_rdma.c +++ b/libdiod/diod_rdma.c @@ -46,7 +46,6 @@ #include #include #include -#include #include #include diff --git a/libdiod/diod_sock.c b/libdiod/diod_sock.c index 093445a9..0211d4a4 100644 --- a/libdiod/diod_sock.c +++ b/libdiod/diod_sock.c @@ -48,7 +48,6 @@ #endif #include #include -#include #include "9p.h" #include "npfs.h" @@ -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; diff --git a/libnpclient/fsys.c b/libnpclient/fsys.c index a8b35c3a..17d45d5e 100644 --- a/libnpclient/fsys.c +++ b/libnpclient/fsys.c @@ -34,7 +34,6 @@ #include #include #include -#include #include #include diff --git a/libnpclient/mtfsys.c b/libnpclient/mtfsys.c index b8d0dacd..e008aeba 100644 --- a/libnpclient/mtfsys.c +++ b/libnpclient/mtfsys.c @@ -34,7 +34,6 @@ #include #include #include -#include #include #include @@ -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; diff --git a/libnpclient/pool.c b/libnpclient/pool.c index d5e754ca..167abdbe 100644 --- a/libnpclient/pool.c +++ b/libnpclient/pool.c @@ -33,7 +33,6 @@ #include #include #include -#include #include "9p.h" #include "npfs.h" diff --git a/libnpclient/readdir.c b/libnpclient/readdir.c index 44b577ba..df8cfdac 100644 --- a/libnpclient/readdir.c +++ b/libnpclient/readdir.c @@ -39,7 +39,6 @@ #include #include #include -#include #include #include "9p.h" @@ -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: diff --git a/libnpfs/conn.c b/libnpfs/conn.c index 11f833af..531de310 100644 --- a/libnpfs/conn.c +++ b/libnpfs/conn.c @@ -33,7 +33,6 @@ #include #include #include -#include #include "9p.h" #include "npfs.h" @@ -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); @@ -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); diff --git a/libnpfs/ctl.c b/libnpfs/ctl.c index 7644f385..be00cdcf 100644 --- a/libnpfs/ctl.c +++ b/libnpfs/ctl.c @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -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))) @@ -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; @@ -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); diff --git a/libnpfs/fcall.c b/libnpfs/fcall.c index 05e6f1b7..e9715ac0 100644 --- a/libnpfs/fcall.c +++ b/libnpfs/fcall.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include "9p.h" #include "npfs.h" @@ -123,7 +122,7 @@ np_auth(Npreq *req, Npfcall *tc) np_logerr (srv, "%s: startauth", a); goto error; } - assert((aqid.type & P9_QTAUTH)); + NP_ASSERT((aqid.type & P9_QTAUTH)); if (!(rc = np_create_rauth(&aqid))) { np_uerror(ENOMEM); np_logerr (srv, "%s: creating response", a); diff --git a/libnpfs/fdtrans.c b/libnpfs/fdtrans.c index fd5669f4..6b4fde33 100644 --- a/libnpfs/fdtrans.c +++ b/libnpfs/fdtrans.c @@ -30,7 +30,6 @@ #include #include #include -#include #include "9p.h" #include "npfs.h" #include "npfsimpl.h" @@ -101,7 +100,7 @@ np_fdtrans_recv(Npfcall **fcp, u32 msize, void *a) int n, size, len; if (fdt->fc) { - assert (fdt->fc_msize >= msize); + NP_ASSERT (fdt->fc_msize >= msize); fc = fdt->fc; len = fdt->fc->size; fdt->fc = NULL; diff --git a/libnpfs/fidpool.c b/libnpfs/fidpool.c index c053ba05..2f2371de 100644 --- a/libnpfs/fidpool.c +++ b/libnpfs/fidpool.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include "9p.h" @@ -49,8 +48,8 @@ _destroy_fid (Npfid *f) Npsrv *srv; Npfid *next; - assert (f != NULL); - assert (f->magic == FID_MAGIC); + NP_ASSERT(f != NULL); + NP_ASSERT(f->magic == FID_MAGIC); srv = f->conn->srv; next = f->next; @@ -146,7 +145,7 @@ np_fidpool_count(Npfidpool *pool) xpthread_mutex_lock(&pool->lock); for(i = 0; i < pool->size; i++) { for (f = pool->htable[i]; f != NULL; f = f->next) { - assert (f->magic == FID_MAGIC); + NP_ASSERT(f->magic == FID_MAGIC); count++; } } @@ -264,8 +263,8 @@ np_fid_create (Npconn *conn, u32 fid) Npfid * np_fid_incref (Npfid *f) { - assert (f != NULL); - assert (f->magic == FID_MAGIC); + NP_ASSERT(f != NULL); + NP_ASSERT(f->magic == FID_MAGIC); xpthread_mutex_lock (&f->lock); f->refcount++; @@ -283,8 +282,8 @@ np_fid_decref (Npfid **fp) Npfid *f = *fp; int refcount; - assert (f != NULL); - assert (f->magic == FID_MAGIC); + NP_ASSERT(f != NULL); + NP_ASSERT(f->magic == FID_MAGIC); xpthread_mutex_lock (&f->lock); refcount = --f->refcount; diff --git a/libnpfs/fmt.c b/libnpfs/fmt.c index 134a50e2..78513461 100644 --- a/libnpfs/fmt.c +++ b/libnpfs/fmt.c @@ -32,7 +32,6 @@ #include #include #include -#include #include #include "9p.h" diff --git a/libnpfs/np.c b/libnpfs/np.c index 7a3d3d19..064c988b 100644 --- a/libnpfs/np.c +++ b/libnpfs/np.c @@ -29,7 +29,6 @@ #include #include #include -#include #include "9p.h" #include "npfs.h" #include "npfsimpl.h" @@ -274,7 +273,7 @@ np_create_common_static(struct cbuf *bufp, u32 size, u8 id, Npfcall *fc; size += sizeof(fc->size) + sizeof(fc->type) + sizeof (fc->tag); - assert (buflen >= sizeof(Npfcall) + size); + NP_ASSERT (buflen >= sizeof(Npfcall) + size); fc = buf; fc->pkt = (u8 *) fc + sizeof(*fc); @@ -453,7 +452,7 @@ np_create_twalk(u32 fid, u32 newfid, u16 nwname, char **wnames) struct cbuf *bufp = &buffer; Npfcall *fc; - assert (nwname <= P9_MAXWELEM); + NP_ASSERT (nwname <= P9_MAXWELEM); for(i = 0; i < nwname; i++) size += sizeof(u16) + strlen(wnames[i]); if (!(fc = np_create_common(bufp, size, P9_TWALK))) @@ -475,7 +474,7 @@ np_create_rwalk(int nwqid, Npqid *wqids) struct cbuf *bufp = &buffer; Npfcall *fc; - assert (nwqid <= P9_MAXWELEM); + NP_ASSERT (nwqid <= P9_MAXWELEM); if (!(fc = np_create_common(bufp, size, P9_RWALK))) return NULL; buf_put_int16(bufp, nwqid, &fc->u.rwalk.nwqid); @@ -540,7 +539,7 @@ np_set_rread_count(Npfcall *fc, u32 count) struct cbuf buffer; struct cbuf *bufp = &buffer; - assert(count <= fc->u.rread.count); + NP_ASSERT (count <= fc->u.rread.count); buf_init(bufp, (char *) fc->pkt, size); buf_put_int32(bufp, size, &fc->size); buf_init(bufp, (char *) fc->pkt + 7, size - 7); @@ -1092,7 +1091,7 @@ np_finalize_rreaddir(Npfcall *fc, u32 count) struct cbuf buffer; struct cbuf *bufp = &buffer; - assert(count <= fc->u.rreaddir.count); + NP_ASSERT (count <= fc->u.rreaddir.count); buf_init(bufp, (char *) fc->pkt, size); buf_put_int32(bufp, size, &fc->size); diff --git a/libnpfs/npfs.h b/libnpfs/npfs.h index b4bbd5d9..e7a85658 100644 --- a/libnpfs/npfs.h +++ b/libnpfs/npfs.h @@ -356,6 +356,8 @@ void np_logmsg(Npsrv *srv, const char *fmt, ...) void np_tpool_incref(Nptpool *); void np_tpool_decref(Nptpool *); int np_decode_tpools_str (char *s, Npstats *stats); +void np_assfail (char *ass, char *file, int line); +#define NP_ASSERT(exp) if ((exp)) ; else np_assfail(#exp, __FILE__, __LINE__ ) /* conn.c */ Npconn *np_conn_create(Npsrv *, Nptrans *, char *); diff --git a/libnpfs/npstring.c b/libnpfs/npstring.c index 7de493d3..cfabbba8 100644 --- a/libnpfs/npstring.c +++ b/libnpfs/npstring.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include "9p.h" @@ -143,7 +142,7 @@ spf (char *s, int len, const char *fmt, ...) len -= n; s += n; - assert (len > 0); + NP_ASSERT (len > 0); va_start (ap, fmt); vsnprintf (s, len, fmt, ap); /* ignore overflow */ diff --git a/libnpfs/rdmatrans.c b/libnpfs/rdmatrans.c index 97174b95..1b831690 100644 --- a/libnpfs/rdmatrans.c +++ b/libnpfs/rdmatrans.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include "9p.h" diff --git a/libnpfs/srv.c b/libnpfs/srv.c index 2369f6d8..acde7170 100644 --- a/libnpfs/srv.c +++ b/libnpfs/srv.c @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -50,6 +50,9 @@ static void np_srv_add_workreq(Nptpool *tp, Npreq *req); static char *_ctl_get_conns (char *name, void *a); static char *_ctl_get_tpools (char *name, void *a); +/* Ugly hack so NP_ASSERT can get to registsered srv->logmsg */ +static Npsrv *np_assert_srv = NULL; + Npsrv* np_srv_create(int nwthread, int flags) { @@ -79,6 +82,7 @@ np_srv_create(int nwthread, int flags) if (!(srv->tpool = np_tpool_create (srv, "default"))) goto error; np_tpool_incref (srv->tpool); + np_assert_srv = srv; return srv; error: if (srv) @@ -93,6 +97,7 @@ np_srv_destroy(Npsrv *srv) np_tpool_cleanup (srv); np_usercache_destroy (srv); np_ctl_finalize (srv); + np_assert_srv = NULL; free (srv); } @@ -313,7 +318,7 @@ np_tpool_select (Npreq *req) Npsrv *srv = req->conn->srv; Nptpool *tp = NULL; - assert (srv->tpool != NULL); + NP_ASSERT (srv->tpool != NULL); if (!req->fid || req->fid->tpool) return; @@ -331,7 +336,7 @@ np_tpool_select (Npreq *req) if (!tp) { tp = np_tpool_create(srv, req->fid->aname); if (tp) { - assert (srv->tpool); /* default tpool */ + NP_ASSERT (srv->tpool); /* default tpool */ tp->next = srv->tpool->next; srv->tpool->next = tp; } else @@ -603,7 +608,7 @@ np_process_request(Npreq *req, Nptpool *tp) rc = np_attach(req, tc); break; case P9_TFLUSH: - assert (0); /* handled in receive path */ + NP_ASSERT (0); /* handled in receive path */ break; case P9_TWALK: rc = np_walk(req, tc); @@ -625,7 +630,7 @@ np_process_request(Npreq *req, Nptpool *tp) rc = np_remove(req, tc); break; default: - assert (0); /* handled in np_deserialize */ + NP_ASSERT (0); /* handled in np_deserialize */ break; } @@ -651,7 +656,7 @@ np_postprocess_request(Npreq *req, Npfcall *rc) Npfcall *tc = req->tcall; int ecode = np_rerror(); - assert (tc != NULL); + NP_ASSERT (tc != NULL); /* If an in-progress op was interrupted with a signal due to a flush, * fix up the fid accounting and suppress reply. @@ -746,7 +751,7 @@ np_wthread_proc(void *a) void np_req_respond(Npreq *req, Npfcall *rc) { - assert (rc != NULL); + NP_ASSERT (rc != NULL); xpthread_mutex_lock(&req->lock); req->rcall = rc; @@ -818,7 +823,7 @@ void np_req_unref(Npreq *req) { xpthread_mutex_lock(&req->lock); - assert(req->refcount > 0); + NP_ASSERT (req->refcount > 0); req->refcount--; if (req->refcount) { xpthread_mutex_unlock(&req->lock); @@ -879,6 +884,21 @@ np_logerr(Npsrv *srv, const char *fmt, ...) } } +void +np_assfail (char *ass, char *file, int line) +{ + Npsrv *srv = np_assert_srv; + + if (srv && srv->logmsg) + np_logmsg (srv, "assertion failure: %s:%d: %s", + file, line, ass); + else + fprintf (stderr, "assertion failure: %s:%d: %s", + file, line, ass); + if (raise (SIGABRT) < 0) + exit (1); +} + static char * _ctl_get_conns (char *name, void *a) { diff --git a/libnpfs/user.c b/libnpfs/user.c index ad5b0650..eee31352 100644 --- a/libnpfs/user.c +++ b/libnpfs/user.c @@ -40,7 +40,6 @@ #include #endif #include -#include #include "9p.h" #include "npfs.h" @@ -148,7 +147,7 @@ np_usercache_create (Npsrv *srv) { Npusercache *uc; - assert (srv->usercache == NULL); + NP_ASSERT (srv->usercache == NULL); if (!(uc = malloc (sizeof (*uc)))) { np_uerror (ENOMEM); return -1; @@ -172,7 +171,7 @@ np_usercache_destroy (Npsrv *srv) Npusercache *uc; Npuser *u; - assert (srv->usercache != NULL); + NP_ASSERT (srv->usercache != NULL); uc = srv->usercache; u = uc->users; diff --git a/libnpfs/xpthread.h b/libnpfs/xpthread.h index 0c3d4ab3..9169d798 100644 --- a/libnpfs/xpthread.h +++ b/libnpfs/xpthread.h @@ -1,25 +1,25 @@ /* pthread wrappers */ #define xpthread_mutex_lock(a) do { \ int pthread_mutex_lock_result = pthread_mutex_lock(a); \ - assert (pthread_mutex_lock_result == 0); \ + NP_ASSERT (pthread_mutex_lock_result == 0); \ } while (0) #define xpthread_mutex_unlock(a) do { \ int pthread_mutex_unlock_result = pthread_mutex_unlock(a); \ - assert (pthread_mutex_unlock_result == 0); \ + NP_ASSERT (pthread_mutex_unlock_result == 0); \ } while (0) #define xpthread_cond_wait(a,b) do { \ int pthread_cond_wait_result = pthread_cond_wait(a,b); \ - assert (pthread_cond_wait_result == 0); \ + NP_ASSERT (pthread_cond_wait_result == 0); \ } while (0) #define xpthread_cond_timedwait(a,b,c) do { \ int pthread_cond_timedwait_result = pthread_cond_timedwait(a,b,c); \ - assert (pthread_cond_timedwait_result == 0); \ + NP_ASSERT (pthread_cond_timedwait_result == 0); \ } while (0) #define xpthread_cond_broadcast(a) do { \ int pthread_cond_broadcast_result = pthread_cond_broadcast(a); \ - assert (pthread_cond_broadcast_result == 0); \ + NP_ASSERT (pthread_cond_broadcast_result == 0); \ } while (0) #define xpthread_cond_signal(a) do { \ int pthread_cond_signal_result = pthread_cond_signal(a); \ - assert (pthread_cond_signal_result == 0); \ + NP_ASSERT (pthread_cond_signal_result == 0); \ } while (0) diff --git a/utils/diodcat.c b/utils/diodcat.c index 819f95ff..523267d6 100644 --- a/utils/diodcat.c +++ b/utils/diodcat.c @@ -41,7 +41,6 @@ #include #include #include -#include #include #include "9p.h" @@ -169,7 +168,7 @@ cat9 (Npcfid *root, char *path) errn (np_rerror (), "open %s", path); goto done; } - ASSERT (fid->iounit > 0); /* libnpclient invariant */ + NP_ASSERT (fid->iounit > 0); /* libnpclient invariant */ if (!(buf = malloc (fid->iounit))) { msg ("out of memory"); goto done; diff --git a/utils/diodload.c b/utils/diodload.c index 3c1b9d3d..934344b0 100644 --- a/utils/diodload.c +++ b/utils/diodload.c @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include diff --git a/utils/diodmount.c b/utils/diodmount.c index 7c148ad3..453f3231 100644 --- a/utils/diodmount.c +++ b/utils/diodmount.c @@ -50,7 +50,6 @@ #include #include #include -#include #ifndef PATH_MAX #define PATH_MAX 1024 @@ -245,15 +244,15 @@ main (int argc, char *argv[]) opt_addf (o, "wfdno=%d", wfd); } - ASSERT (opt_find (o, "trans=fd")); - ASSERT (opt_scanf (o, "msize=%d", &i)); - ASSERT (opt_find (o, "version=9p2000.L")); - ASSERT (opt_scanf (o, "debug=%d", &i) || opt_scanf (o, "debug=%x", &i)); - ASSERT (opt_scanf (o, "wfdno=%d", &i) && opt_scanf (o, "rfdno=%d", &i)); - ASSERT ((opt_find (o, "access=user") && opt_find(o, "uname=root")) + NP_ASSERT (opt_find (o, "trans=fd")); + NP_ASSERT (opt_scanf (o, "msize=%d", &i)); + NP_ASSERT (opt_find (o, "version=9p2000.L")); + NP_ASSERT (opt_scanf (o, "debug=%d", &i) || opt_scanf (o, "debug=%x", &i)); + NP_ASSERT (opt_scanf (o, "wfdno=%d", &i) && opt_scanf (o, "rfdno=%d", &i)); + NP_ASSERT ((opt_find (o, "access=user") && opt_find(o, "uname=root")) || (opt_scanf (o, "access=%d", &i) && opt_find(o, "uname"))); - ASSERT (!opt_find (o, "port")); + NP_ASSERT (!opt_find (o, "port")); _diod_mount (o, rfd, wfd, nspec ? nspec : spec, dir, vopt, fopt, nopt); diff --git a/utils/dtop.c b/utils/dtop.c index 755cc7da..ba0690fc 100644 --- a/utils/dtop.c +++ b/utils/dtop.c @@ -43,7 +43,6 @@ #include #include #include -#include #include #include #include @@ -53,11 +52,11 @@ #include "9p.h" #include "npfs.h" #include "npclient.h" +#include "xpthread.h" #include "list.h" #include "hostlist.h" #include "diod_log.h" -#include "diod_pthread.h" #include "diod_sock.h" #include "diod_auth.h" #include "sample.h" diff --git a/utils/opt.c b/utils/opt.c index 9574c66c..5429365f 100644 --- a/utils/opt.c +++ b/utils/opt.c @@ -32,7 +32,10 @@ #include #include #include -#include +#include + +#include "9p.h" +#include "npfs.h" #include "diod_log.h" @@ -49,7 +52,7 @@ struct opt_struct { void opt_destroy (Opt o) { - ASSERT (o->magic == OPT_MAGIC); + NP_ASSERT (o->magic == OPT_MAGIC); if (o->list) list_destroy (o->list); free (o); @@ -78,7 +81,7 @@ opt_csv (Opt o) int strsize = 1; int n; - ASSERT (o->magic == OPT_MAGIC); + NP_ASSERT (o->magic == OPT_MAGIC); if (!(itr = list_iterator_create (o->list))) msg_exit ("out of memory"); while ((item = list_next (itr))) @@ -122,7 +125,7 @@ opt_addf (Opt o, const char *fmt, ...) char *saveptr = NULL; int error; - ASSERT (o->magic == OPT_MAGIC); + NP_ASSERT (o->magic == OPT_MAGIC); va_start (ap, fmt); error = vasprintf (&csv, fmt, ap); va_end (ap); @@ -157,7 +160,7 @@ opt_find (Opt o, char *key) { char *s; - ASSERT (o->magic == OPT_MAGIC); + NP_ASSERT (o->magic == OPT_MAGIC); if (strchr (key, '=')) s = list_find_first (o->list, (ListFindF)_match_keyval, key); @@ -172,7 +175,7 @@ opt_find (Opt o, char *key) int opt_delete (Opt o, char *key) { - ASSERT (o->magic == OPT_MAGIC); + NP_ASSERT (o->magic == OPT_MAGIC); return list_delete_all (o->list, (ListFindF)_match_key, key); } @@ -184,7 +187,7 @@ opt_vscanf (Opt o, const char *fmt, va_list ap) char *item; int ret = 0; - ASSERT (o->magic == OPT_MAGIC); + NP_ASSERT (o->magic == OPT_MAGIC); if (!(itr = list_iterator_create (o->list))) msg_exit ("out of memory"); @@ -224,7 +227,7 @@ opt_check_allowed_csv (Opt o, const char *csv) char *item, *cpy, *p; int ret = 0; - ASSERT (o->magic == OPT_MAGIC); + NP_ASSERT (o->magic == OPT_MAGIC); allow = opt_create (); opt_addf (allow, "%s", csv);