Re: [announce] HVCS for inclusion in 2.6 tree

From: Andrew Morton
Date: Thu Jul 22 2004 - 18:21:17 EST


Ryan Arnold <rsa@xxxxxxxxxx> wrote:
>
> hvcs_to_mainline_draft2.patch text/x-patch (80516 bytes)
>
> +int khvcsd(void *unused)
> +{
> + struct hvcs_struct *hvcsd = NULL;
> + struct list_head *element;
> + struct list_head *safe_temp;
> + int hvcs_todo_mask;
> +
> + daemonize("khvcsd");
> +
> + allow_signal(SIGTERM);
> +
> + do {
> + wait_queue_t wait = __WAITQUEUE_INITIALIZER(wait, current);
> + hvcs_todo_mask = 0;
> + hvcs_kicked = 0;
> + wmb();
> + list_for_each_safe(element, safe_temp, &hvcs_structs) {
> + hvcsd = list_entry(element, struct hvcs_struct, next);
> + hvcs_todo_mask |= hvcs_io(hvcsd);
> + }
> +
> + /* If any of the hvcs adapters want to try a write or quick read
> + * don't schedule(), yield a smidgen then execute the hvcs_io
> + * thread again for those that want the write. */
> + if (hvcs_todo_mask & (HVCS_TRY_WRITE | HVCS_QUICK_READ)) {
> + yield();
> + continue;
> + }
> +
> + add_wait_queue(&hvcs_wait_queue, &wait);
> + set_current_state(TASK_INTERRUPTIBLE);
> + if (!hvcs_kicked)
> + schedule();
> + set_current_state(TASK_RUNNING);
> + remove_wait_queue(&hvcs_wait_queue, &wait);
> +
> + } while (!signal_pending(current));
> +
> + complete_and_exit(&hvcs_exited,0);
> +}
>

I'm not a big fan of using signals for in-kernel IPC. (What happens if
root accidentally does `kill -TERM $(pidof khvcsd)', btw?) And daemonize()
is deprecated.

It should be possible to use the kthread infrastructure here - it does most
of this stuff for you. Use kthread_stop() in the killer and
kthread_should_stop() within khvcsd(). kthread_stop() is synchronous, so
you don't need to do the complete() stuff here.

It should not be necessary to re-add to the wait queue head on each pass
around the loop.

khvcsd() can have static scope.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/