1. Why listening for events stop working after releasing host id and
acquiring it again on the same lockspace?
events are tied directly into the lockspace.
2. Is this the right behavior?
yes
3. Assuming this is the right behavior, why the listener does not
fail? I think it is
expected that the event fds would close or fail so the listener can release
the resources.
For example, when I restart sanlock, the listener fails with:
sanlock.SanlockException: (1, 'Unable to get events', 'Operation not
permitted')
So a similar failure is expected in this case.
4. Do we have an event fd leak until the listener reg_end() the fd?
Thanks, you found a bug there. I wasn't closing the event fds when the
lockspace was removed. The listener will now get a poll error on its
registered fd if the lockspace is removed. I'll push out this fix:
diff --git a/src/lockspace.c b/src/lockspace.c
index 352287ec5f65..8309d25a11f5 100644
--- a/src/lockspace.c
+++ b/src/lockspace.c
@@ -451,6 +451,20 @@ static int corrupt_result(int result)
}
}
+static void close_event_fds(struct space *sp)
+{
+ int i;
+
+ pthread_mutex_lock(&sp->mutex);
+ for (i = 0; i < MAX_EVENT_FDS; i++) {
+ if (sp->event_fds[i] == -1)
+ continue;
+
+ close(sp->event_fds[i]);
+ sp->event_fds[i] = -1;
+ }
+}
+
/*
* This thread must not be stopped unless all pids that may be using any
* resources in it are dead/gone. (The USED flag in the lockspace represents
@@ -671,6 +685,8 @@ static void *lockspace_thread(void *arg_in)
purge_resource_orphans(sp->space_name);
+ close_event_fds(sp);
+
close_task_aio(&task);
return NULL;
}