X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=liblttng-ust%2Flttng-ust-abi.c;h=ddadfc1d7f33c9a4fb9310976af296f33bdd66db;hb=refs%2Fheads%2Fstable-2.1;hp=529ff4385b5803c93b434c73b4da7e6c7bd0c75d;hpb=e58095efc3a51a505fc533e3e56b9b5ed8743a8b;p=lttng-ust.git diff --git a/liblttng-ust/lttng-ust-abi.c b/liblttng-ust/lttng-ust-abi.c index 529ff438..ddadfc1d 100644 --- a/liblttng-ust/lttng-ust-abi.c +++ b/liblttng-ust/lttng-ust-abi.c @@ -49,6 +49,8 @@ #include #include "lttng-tracer.h" +#define OBJ_NAME_LEN 16 + static int lttng_ust_abi_close_in_progress; static @@ -67,7 +69,9 @@ struct lttng_ust_obj { void *private_data; const struct lttng_ust_objd_ops *ops; int f_count; + int owner_ref; /* has ref from owner */ void *owner; + char name[OBJ_NAME_LEN]; } s; int freelist_next; /* offset freelist. end is -1. */ } u; @@ -85,7 +89,7 @@ static struct lttng_ust_objd_table objd_table = { static int objd_alloc(void *private_data, const struct lttng_ust_objd_ops *ops, - void *owner) + void *owner, const char *name) { struct lttng_ust_obj *obj; @@ -121,7 +125,10 @@ end: obj->u.s.ops = ops; obj->u.s.f_count = 2; /* count == 1 : object is allocated */ /* count == 2 : allocated + hold ref */ + obj->u.s.owner_ref = 1; /* One owner reference */ obj->u.s.owner = owner; + strncpy(obj->u.s.name, name, OBJ_NAME_LEN); + obj->u.s.name[OBJ_NAME_LEN - 1] = '\0'; return obj - objd_table.array; } @@ -179,7 +186,7 @@ void objd_ref(int id) obj->u.s.f_count++; } -int lttng_ust_objd_unref(int id) +int lttng_ust_objd_unref(int id, int is_owner) { struct lttng_ust_obj *obj = _objd_get(id); @@ -189,6 +196,13 @@ int lttng_ust_objd_unref(int id) ERR("Reference counting error\n"); return -EINVAL; } + if (is_owner) { + if (!obj->u.s.owner_ref) { + ERR("Error decrementing owner reference"); + return -EINVAL; + } + obj->u.s.owner_ref--; + } if ((--obj->u.s.f_count) == 1) { const struct lttng_ust_objd_ops *ops = objd_ops(id); @@ -204,8 +218,16 @@ void objd_table_destroy(void) { int i; - for (i = 0; i < objd_table.allocated_len; i++) - (void) lttng_ust_objd_unref(i); + for (i = 0; i < objd_table.allocated_len; i++) { + struct lttng_ust_obj *obj; + + obj = _objd_get(i); + if (!obj) + continue; + if (!obj->u.s.owner_ref) + continue; /* only unref owner ref. */ + (void) lttng_ust_objd_unref(i, 1); + } free(objd_table.array); objd_table.array = NULL; objd_table.len = 0; @@ -225,8 +247,10 @@ void lttng_ust_objd_table_owner_cleanup(void *owner) continue; if (!obj->u.s.owner) continue; /* skip root handles */ + if (!obj->u.s.owner_ref) + continue; /* only unref owner ref. */ if (obj->u.s.owner == owner) - (void) lttng_ust_objd_unref(i); + (void) lttng_ust_objd_unref(i, 1); } } @@ -254,7 +278,7 @@ int lttng_abi_create_root_handle(void) int root_handle; /* root handles have NULL owners */ - root_handle = objd_alloc(NULL, <tng_ops, NULL); + root_handle = objd_alloc(NULL, <tng_ops, NULL, "root"); return root_handle; } @@ -267,7 +291,7 @@ int lttng_abi_create_session(void *owner) session = lttng_session_create(); if (!session) return -ENOMEM; - session_objd = objd_alloc(session, <tng_session_ops, owner); + session_objd = objd_alloc(session, <tng_session_ops, owner, "session"); if (session_objd < 0) { ret = session_objd; goto objd_error; @@ -415,7 +439,7 @@ int lttng_abi_create_channel(int session_objd, transport_name = ""; return -EINVAL; } - chan_objd = objd_alloc(NULL, ops, owner); + chan_objd = objd_alloc(NULL, ops, owner, "channel"); if (chan_objd < 0) { ret = chan_objd; goto objd_error; @@ -456,7 +480,7 @@ chan_error: { int err; - err = lttng_ust_objd_unref(chan_objd); + err = lttng_ust_objd_unref(chan_objd, 1); assert(!err); } objd_error: @@ -568,7 +592,7 @@ int lttng_abi_tracepoint_list(void *owner) int list_objd, ret; struct lttng_ust_tracepoint_list *list; - list_objd = objd_alloc(NULL, <tng_tracepoint_list_ops, owner); + list_objd = objd_alloc(NULL, <tng_tracepoint_list_ops, owner, "tp_list"); if (list_objd < 0) { ret = list_objd; goto objd_error; @@ -593,7 +617,7 @@ alloc_error: { int err; - err = lttng_ust_objd_unref(list_objd); + err = lttng_ust_objd_unref(list_objd, 1); assert(!err); } objd_error: @@ -650,7 +674,8 @@ int lttng_abi_tracepoint_field_list(void *owner) int list_objd, ret; struct lttng_ust_field_list *list; - list_objd = objd_alloc(NULL, <tng_tracepoint_field_list_ops, owner); + list_objd = objd_alloc(NULL, <tng_tracepoint_field_list_ops, owner, + "tp_field_list"); if (list_objd < 0) { ret = list_objd; goto objd_error; @@ -675,7 +700,7 @@ alloc_error: { int err; - err = lttng_ust_objd_unref(list_objd); + err = lttng_ust_objd_unref(list_objd, 1); assert(!err); } objd_error: @@ -729,7 +754,7 @@ int lttng_abi_open_stream(int channel_objd, struct lttng_ust_stream *info, } priv->buf = buf; priv->lttng_chan = channel; - stream_objd = objd_alloc(priv, &lib_ring_buffer_objd_ops, owner); + stream_objd = objd_alloc(priv, &lib_ring_buffer_objd_ops, owner, "open_stream"); if (stream_objd < 0) { ret = stream_objd; goto objd_error; @@ -756,7 +781,7 @@ int lttng_abi_create_enabler(int channel_objd, int event_objd, ret; event_param->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0'; - event_objd = objd_alloc(NULL, <tng_enabler_ops, owner); + event_objd = objd_alloc(NULL, <tng_enabler_ops, owner, "enabler"); if (event_objd < 0) { ret = event_objd; goto objd_error; @@ -779,7 +804,7 @@ event_error: { int err; - err = lttng_ust_objd_unref(event_objd); + err = lttng_ust_objd_unref(event_objd, 1); assert(!err); } objd_error: @@ -896,7 +921,7 @@ int lttng_channel_release(int objd) struct lttng_channel *channel = objd_private(objd); if (channel) - return lttng_ust_objd_unref(channel->session->objd); + return lttng_ust_objd_unref(channel->session->objd, 0); return 0; } @@ -959,7 +984,7 @@ int lttng_rb_release(int objd) if (!lttng_ust_abi_close_in_progress) channel->ops->buffer_read_close(buf, channel->handle); - return lttng_ust_objd_unref(channel->objd); + return lttng_ust_objd_unref(channel->objd, 0); } return 0; } @@ -1024,7 +1049,7 @@ int lttng_enabler_release(int objd) struct lttng_enabler *enabler = objd_private(objd); if (enabler) - return lttng_ust_objd_unref(enabler->chan->objd); + return lttng_ust_objd_unref(enabler->chan->objd, 0); return 0; }