fix xobj_iterate bug, add lock free versions of xobj_check, is_Free
authorFilippos Giannakos <philipgian@grnet.gr>
Mon, 12 Nov 2012 12:36:52 +0000 (14:36 +0200)
committerFilippos Giannakos <philipgian@grnet.gr>
Mon, 12 Nov 2012 13:00:20 +0000 (15:00 +0200)
also fix xseg tool verify

xseg/peers/user/xseg-tool.c
xseg/sys/user/Makefile
xseg/xtypes/xobj.c
xseg/xtypes/xobj.h
xseg/xtypes/xobj_exports.h

index 25721ba..1dfd049 100644 (file)
@@ -1238,28 +1238,22 @@ int cmd_verify(enum req_action action)
        }
 
        struct xobject_h *obj_h = xseg->request_h;
-       void *container = XPTR(&obj_h->container);
-       xhash_t *allocated = XPTR_TAKE(obj_h->allocated, container);
-       xhash_iter_t it;
-       xhash_iter_init(allocated, &it);
-       xhashidx key, val;
+       struct xobject_iter it;
+       xobj_iter_init(obj_h, &it);
+
+       struct xseg_request *req;
        xlock_acquire(&obj_h->lock, srcport);
-       while (xhash_iterate(allocated, &it, &key, &val)){
-               void *mem = XPTR_TAKE(val, container);
-               struct xseg_request *req = mem, *t;
-               for (i = 0; i < xheap_get_chunk_size(mem)/obj_h->obj_size; i++) {
-                       t = req + i;
-                       struct xobject *obj = (struct xobject *)t;
-                       //FIXME. obj->magic is not touched by req->serial...
-                       /* if (obj->magic != MAGIC_REQ && t->src_portno == portno){ */
-                       if (isDangling(t)){
-                               if (action == REPORT)
-                                       report_request(t);
-                               else if (action == FAIL)
-                                       finish_req(t, action);
-                               else if (action == COMPLETE)
-                                       finish_req(t, COMPLETE);
-                       }
+       while (xobj_iterate(obj_h, &it, (void **)&req)){
+               //FIXME this will not work cause obj->magic - req->serial is not
+               //touched when a request is get
+               /* if (obj->magic != MAGIC_REQ && t->src_portno == portno){ */
+               if (isDangling(req) && !__xobj_isFree(obj_h, req)){
+                       if (action == REPORT)
+                               report_request(req);
+                       else if (action == FAIL)
+                               finish_req(req, action);
+                       else if (action == COMPLETE)
+                               finish_req(req, COMPLETE);
                }
        }
        xlock_release(&obj_h->lock);
index b45a7a3..94080f6 100644 (file)
@@ -78,7 +78,8 @@ libxseg.map: $(BASE)/xtypes/xq_exports.h $(BASE)/xseg/xseg_exports.h \
                $(BASE)/xtypes/xpool_exports.h $(BASE)/xtypes/xhash_exports.h\
                $(BASE)/xtypes/xobj_exports.h
        cat $(BASE)/xtypes/xq_exports.h $(BASE)/xseg/xseg_exports.h \
-               $(BASE)/xtypes/xpool_exports.h $(BASE)/xtypes/xhash_exports.h | ./make_symbol_map.sh > $@
+               $(BASE)/xtypes/xpool_exports.h $(BASE)/xtypes/xhash_exports.h \
+               $(BASE)/xtypes/xobj_exports.h | ./make_symbol_map.sh > $@
 
 libxseg.so.$(MAJOR).$(MINOR): xseg.pic.o xseg_user.o libxseg.map \
                                 xq/xq.pic.o xpool/xpool.pic.o xhash/xhash.pic.o \
index 4910aa8..3f9cd51 100644 (file)
@@ -179,7 +179,7 @@ int xobj_iterate(struct xobject_h *obj_h, struct xobject_iter *it, void **obj)
                r = xhash_iterate(allocated, &it->xhash_it, &key, &val);
                if (!r)
                        return 0;
-               it->chunk = (void *)key;
+               it->chunk = XPTR_TAKE(key, container);
                it->cnt = 0;
        }
 
@@ -191,16 +191,11 @@ int xobj_iterate(struct xobject_h *obj_h, struct xobject_iter *it, void **obj)
 
 }
 
-/* TODO implement lock free versions */
-int xobj_check(struct xobject_h *obj_h, void *ptr)
+int __xobj_check(struct xobject_h *obj_h, void *ptr)
 {
-       int r = 0;
        void *container = XPTR(&obj_h->container);
        xhash_iter_t it;
        uint64_t i, nr_objs;
-
-       xlock_acquire(&obj_h->lock, 1);
-
        xhash_t *allocated = XPTR_TAKE(obj_h->allocated, container);
        xhash_iter_init(allocated, &it);
        xhashidx key, val;
@@ -212,39 +207,49 @@ int xobj_check(struct xobject_h *obj_h, void *ptr)
                        obj = (void *) ((unsigned long) mem +
                                        (unsigned long) i * obj_h->obj_size);
                        if (obj == ptr) {
-                               r = 1;
-                               goto out;
+                               return 1;
                        }
                }
        }
-out:
-       xlock_release(&obj_h->lock);
+       return 0;
+}
 
+int xobj_check(struct xobject_h *obj_h, void *ptr)
+{
+       int r;
+       xlock_acquire(&obj_h->lock, 1);
+       r = __xobj_check(obj_h, ptr);
+       xlock_release(&obj_h->lock);
        return r;
 }
 
-int xobj_isFree(struct xobject_h *obj_h, void *ptr)
+int __xobj_isFree(struct xobject_h *obj_h, void *ptr)
 {
        int r = 0;
        void *container = XPTR(&obj_h->container);
        xptr node;
        struct xobject *obj;
 
-       xlock_acquire(&obj_h->lock, 1);
 
        node = obj_h->list;
        while (node){
                obj = XPTR_TAKE(node, container);
                if (obj == ptr){
-                       r = 1;
-                       goto out;
+                       return 1;
                }
                node = obj->next;
        }
 
-out:
-       xlock_release(&obj_h->lock);
 
+       return 0;
+}
+
+int xobj_isFree(struct xobject_h *obj_h, void *ptr)
+{
+       int r;
+       xlock_acquire(&obj_h->lock, 1);
+       r = __xobj_isFree(obj_h, ptr);
+       xlock_release(&obj_h->lock);
        return r;
 }
 
index 3ad4565..c5cc1cb 100644 (file)
@@ -44,11 +44,14 @@ int xobj_alloc_obj(struct xobject_h * obj_h, uint64_t nr);
 int xobj_handler_init(struct xobject_h *obj_h, void *container,
                uint32_t magic, uint64_t size, struct xheap *heap);
 
-void xobj_init_iter(struct xobject_h *obj_h, struct xobject_iter *it);
+void xobj_iter_init(struct xobject_h *obj_h, struct xobject_iter *it);
 int xobj_iterate(struct xobject_h *obj_h, struct xobject_iter *it, void **obj);
 int xobj_check(struct xobject_h *obj_h, void *obj);
 int xobj_isFree(struct xobject_h *obj_h, void *obj);
 
+int __xobj_check(struct xobject_h *obj_h, void *obj);
+int __xobj_isFree(struct xobject_h *obj_h, void *obj);
+
 //TODO 
 //xobj_handler_destroy()
 //releases allocated pages
index bd4feac..bfe6128 100644 (file)
@@ -1,3 +1,9 @@
 EXPORT_SYMBOL(xobj_get_obj);
 EXPORT_SYMBOL(xobj_put_obj);
 EXPORT_SYMBOL(xobj_handler_init);
+EXPORT_SYMBOL(xobj_iter_init);
+EXPORT_SYMBOL(xobj_iterate);
+EXPORT_SYMBOL(__xobj_check);
+EXPORT_SYMBOL(xobj_check);
+EXPORT_SYMBOL(__xobj_isFree);
+EXPORT_SYMBOL(xobj_isFree);