Ulrich wrote: 
>On 17 Mar 2009 at 22:33, shyam_i...@dell.com wrote:

>> The issue is caused because child is trying to free up the session
and 
>> connections that the parent had setup.

>Hi!

>Not knowing the source, I wonder: Parent and child (both processes?)
have their own copy of memory, so each one can free within its own copy
of memory. 
>If they are calling some external process to free something, it's most
likely a race condition, because the "server" should only allow to free
anything
>exactly one.


Yes. You are right. There was actually a race condition because of the
event loop being stopped twice.

Looks like I got a patch with the real scenario affecting the bug.
Please note I am marking the attempt by the parent to stop the event
loop when it has already stopped as an internal error. 
I am not sure if we are supposed to log the error but yet this
serializing the stopping of event loop will fix the issue of freeing
twice.

I think we don't have to call stop_event_loop if event_loop is already
stopped.

Signed-off-by: Shyam Iyer <shyam_i...@dell.com>
Tested-by: Paniraja KM <paniraja...@dell.com>

diff -Naru open-iscsi-2.0-870.3/usr/iscsistart.c
open-iscsi-2.0-870.3-fix-race/usr/iscsistart.c
--- open-iscsi-2.0-870.3/usr/iscsistart.c       2009-02-23
03:02:46.000000000 +0530
+++ open-iscsi-2.0-870.3-fix-race/usr/iscsistart.c      2009-03-18
17:16:21.000000000 +0530
@@ -111,6 +111,15 @@
        int rc;
 
        memset(&req, 0, sizeof(req));
+       req.command = MGMT_IPC_CHECK_EVENTLOOP;
+       rc = do_iscsid(&req, &rsp);
+       if (rc) {
+               iscsid_handle_error(rc);
+               log_error("event_loop already stopped\n");
+               return rc;
+       }
+
+       memset(&req, 0, sizeof(req));
        req.command = MGMT_IPC_IMMEDIATE_STOP;
        rc = do_iscsid(&req, &rsp);
        if (rc) {
@@ -387,7 +396,6 @@
        event_loop(ipc, control_fd, mgmt_ipc_fd, -1);
        ipc->ctldev_close();
        mgmt_ipc_close(mgmt_ipc_fd);
-       free_initiator();
        sysfs_cleanup();
 
        log_debug(1, "iscsi child done");
diff -Naru open-iscsi-2.0-870.3/usr/mgmt_ipc.c
open-iscsi-2.0-870.3-fix-race/usr/mgmt_ipc.c
--- open-iscsi-2.0-870.3/usr/mgmt_ipc.c 2009-02-23 03:02:46.000000000
+0530
+++ open-iscsi-2.0-870.3-fix-race/usr/mgmt_ipc.c        2009-03-18
17:16:32.000000000 +0530
@@ -339,6 +339,13 @@
 {
        return mgmt_ipc_notify_common(qtask,
iscsi_discovery_del_portal);
 }
+static mgmt_ipc_err_e
+mgmt_ipc_check_eventloop(queue_task_t *qtask)
+{
+       if(!leave_event_loop)
+               return MGMT_IPC_ERR_INTERNAL;
+       return MGMT_IPC_OK;
+}
 
 static int
 mgmt_peeruser(int sock, char *user)
@@ -526,6 +533,7 @@
 [MGMT_IPC_NOTIFY_DEL_NODE]     = mgmt_ipc_notify_del_node,
 [MGMT_IPC_NOTIFY_ADD_PORTAL]   = mgmt_ipc_notify_add_portal,
 [MGMT_IPC_NOTIFY_DEL_PORTAL]   = mgmt_ipc_notify_del_portal,
+[MGMT_IPC_CHECK_EVENTLOOP]     = mgmt_ipc_check_eventloop,
 };
 
 static void
diff -Naru open-iscsi-2.0-870.3/usr/mgmt_ipc.h
open-iscsi-2.0-870.3-fix-race/usr/mgmt_ipc.h
--- open-iscsi-2.0-870.3/usr/mgmt_ipc.h 2009-02-23 03:02:46.000000000
+0530
+++ open-iscsi-2.0-870.3-fix-race/usr/mgmt_ipc.h        2009-03-18
17:16:37.000000000 +0530
@@ -70,6 +70,7 @@
        MGMT_IPC_NOTIFY_DEL_NODE        = 18,
        MGMT_IPC_NOTIFY_ADD_PORTAL      = 19,
        MGMT_IPC_NOTIFY_DEL_PORTAL      = 20,
+       MGMT_IPC_CHECK_EVENTLOOP        = 21,
 
        __MGMT_IPC_MAX_COMMAND
 } iscsiadm_cmd_e;

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-iscsi@googlegroups.com
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/open-iscsi
-~----------~----~----~----~------~----~------~--~---

Attachment: fix_event_loop_race
Description: fix_event_loop_race

Reply via email to