public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Marty Leisner" <mleisner@eng.mc.xerox.com>
To: linux-kernel@vger.kernel.org
Cc: leisner@rochester.rr.com
Subject: Re: kernel threads and close method in a device driver
Date: Fri, 20 Apr 2001 14:54:53 -0400	[thread overview]
Message-ID: <200104201854.OAA06769@mailhost.eng.mc.xerox.com> (raw)


I ment to send this correspondence to the list.
It seems to be working much better now -- but is this
CLONE_FILES flag correct?

Is there a device to look at which does a kernel_thread on open,
and kills the thread on close (I'd like to see an example).

Thanks for the help...

Marty

- ------- Forwarded Message

To: Andi Kleen <ak@suse.de>
Subject: Re: kernel threads and close method in a device driver 
In-Reply-To: Your message of "Tue, 17 Apr 2001 23:43:39 +0200."
             <20010417234339.A18288@gruyere.muc.suse.de> 
Date: Wed, 18 Apr 2001 10:49:04 -0400
From: "Marty Leisner" <mleisner@eng.mc.xerox.com>

In message <20010417234339.A18288@gruyere.muc.suse.de>,   you write:
>On Tue, Apr 17, 2001 at 05:04:28PM -0400, Marty Leisner wrote:
>> 	open device
>> 	do IOCTL (spinning a kernel thread and doing initialization)
>> 
>> There is currently an IOCTL which short-circuits to the close method.
>> Turns out it seems necessary to do this IOCTL -- close never gets 
>> invoked.
>
>Call daemonize() in the kernel thread.
>
>-Andi

It seemed like daemonize was a good idea (after thinking about it,
it makes a lot of sense...there are multiple instances of the file
open...[I'm not used to opening files NOT in user space ;-))]

daemonize wasn't in 2.2.12 (I copied it from 2.2.18):

static void daemonize(void)
{  
        struct fs_struct *fs;

        /*
         * If we were started as result of loading a module, close all of the
         * user space pages.  We don't need them, and if we didn't close them
         * they would be locked into memory.
         */                
        printk("want to daemonize");
        exit_mm(current);

        current->session = 1;
        current->pgrp = 1;

        /* Become as one with the init task */

        exit_fs(current);       /* current->fs->count--; */
        fs = init_task.fs;
        current->fs = fs;
        atomic_inc(&fs->count);
}

This seems reasonable, get rid of your files and inherit init's

However, 
:1 mleisner@piquin; lsof -p 630
COMMAND   PID     USER   FD   TYPE DEVICE SIZE NODE NAME
aicCtrlTh 630 mleisner  cwd    DIR    3,1 1024    2 /
aicCtrlTh 630 mleisner  rtd    DIR    3,1 1024    2 /
aicCtrlTh 630 mleisner    0u   CHR  136,0         2 /dev/pts/0
aicCtrlTh 630 mleisner    1u   CHR  136,0         2 /dev/pts/0
aicCtrlTh 630 mleisner    2u   CHR  136,0         2 /dev/pts/0
aicCtrlTh 630 mleisner    3u   CHR   43,0      8034 /dev/aicdrv

which is the original file handles from the application...

Any hints?  I played around with the CLONE_FILES flag on thread_creation,
and at least now I can get through to close (I have to look at the thread kill strategy).

But now I have (after an open, create thread, close cycle)
bash3 :3 mleisner@piquin; lsof -p 584
COMMAND   PID     USER   FD   TYPE DEVICE SIZE NODE NAME
aicCtrlTh 584 mleisner  cwd    DIR    3,1 1024    2 /
aicCtrlTh 584 mleisner  rtd    DIR    3,1 1024    2 /
aicCtrlTh 584 mleisner    0u   CHR  136,0         2 /dev/pts/0
aicCtrlTh 584 mleisner    1u   CHR  136,0         2 /dev/pts/0
aicCtrlTh 584 mleisner    2u   CHR  136,0         2 /dev/pts/0
bash3 :3 mleisner@piquin; lsmod
Module                  Size  Used by
aicdrv                 18104   0 
nfs                    29656   1  (autoclean)
nfsd                  144060   8  (autoclean)
lockd                  30984   1  (autoclean) [nfs nfsd]
sunrpc                 52516   1  (autoclean) [nfs nfsd lockd]
fa311                   4404   1  (autoclean)

marty
mleisner@eng.mc.xerox.com

- ------- End of Forwarded Message



             reply	other threads:[~2001-04-20 18:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-20 18:54 Marty Leisner [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-04-17 21:04 kernel threads and close method in a device driver Marty Leisner
2001-04-17 21:37 ` Alan Cox
2001-04-17 21:43 ` Andi Kleen
2001-04-17 23:32 ` David Woodhouse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200104201854.OAA06769@mailhost.eng.mc.xerox.com \
    --to=mleisner@eng.mc.xerox.com \
    --cc=leisner@rochester.rr.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox